Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logfollow.php
1<?php
9
12
21{
28 public static function checkDestinationsFollowStatus($params = [])
29 {
30 $logId = (isset($params['logId']) ? (int)$params['logId'] : 0);
31 if ($logId <= 0)
32 {
33 return false;
34 }
35
36 $key = 'L' . $logId;
37
38 $destUserIdList = [];
39 $res = LogRightTable::getList([
40 'filter' => [
41 'LOG_ID' => $logId
42 ],
43 'select' => [ 'GROUP_CODE' ]
44 ]);
45 while ($logRight = $res->fetch())
46 {
47 if (preg_match('/^U(\d+)$/', $logRight['GROUP_CODE'], $matches))
48 {
49 $destUserIdList[] = $matches[1];
50 }
51 }
52
53 $defaultFollowValue = false;
54 $userFollowValue = [];
55
56 if (!empty($destUserIdList))
57 {
58 $defaultFollowValue = LogFollowTable::getDefaultValue([
59 'USER_ID' => false
60 ]);
61
62 $res = LogFollowTable::getList([
63 'filter' => [
64 '=CODE' => [ '**', $key ],
65 '@USER_ID' => $destUserIdList
66 ],
67 'select' => [ 'CODE', 'TYPE', 'USER_ID' ]
68 ]);
69 while($logFollow = $res->fetch())
70 {
71 if (!isset($userFollowValue[$logFollow['USER_ID']]))
72 {
73 $userFollowValue[$logFollow['USER_ID']] = [];
74 }
75 $userFollowValue[$logFollow['USER_ID']][$logFollow['CODE']] = $logFollow['TYPE'];
76 }
77 }
78
79 foreach($destUserIdList as $destUserId)
80 {
81 $subscribeTypeList = [];
82
83 if (
84 (
85 !isset($userFollowValue[$destUserId])
86 && $defaultFollowValue === 'N'
87 )
88 || (
89 isset($userFollowValue[$destUserId])
90 && !isset($userFollowValue[$destUserId][$key]) // && isset($userFollowValue[$destUserId]['**'])
91 && $userFollowValue[$destUserId]['**'] === 'N'
92 )
93 )
94 {
95 $subscribeTypeList[] = 'FOLLOW';
96 }
97
98 \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe([
99 'logId' => $logId,
100 'userId' => $destUserId,
101 'typeList' => $subscribeTypeList,
102 'followDate' => 'CURRENT'
103 ]);
104
105 }
106
107 return true;
108 }
109}
static checkDestinationsFollowStatus($params=[])
Definition logfollow.php:28
static getDefaultValue($params=array())
Definition logfollow.php:61