Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
task.php
1<?php
2
10
19
20class Task
21{
22 public static function onTaskUpdateViewed(Event $event): EventResult
23 {
24 $result = new EventResult(EventResult::UNDEFINED, [], 'socialnetwork');
25
26 $taskId = (int)$event->getParameter('taskId');
27 $userId = (int)$event->getParameter('userId');
28
29 if ($taskId <= 0 || $userId <= 0)
30 {
31 return $result;
32 }
33
34 if ($event->getParameter('isRealView'))
35 {
36 $liveFeedEntity = Provider::init([
37 'ENTITY_TYPE' => Provider::DATA_ENTITY_TYPE_TASKS_TASK,
38 'ENTITY_ID' => $taskId,
39 ]);
40 if ($liveFeedEntity)
41 {
42 $liveFeedEntity->setContentView(['user_id' => $userId]);
43 self::updateUserCounter([
44 'userId' => $userId,
45 'logId' => $liveFeedEntity->getLogId(),
46 ]);
47 }
48 }
49
50 return new EventResult(EventResult::SUCCESS, [], 'socialnetwork');
51 }
52
53 private static function updateUserCounter(array $params = []): void
54 {
55 $logId = (int)($params['logId'] ?? 0);
56 $userId = (int)($params['userId'] ?? 0);
57 $siteId = SITE_ID;
58
59 if (
60 $logId <= 0
61 || $userId <= 0
62 )
63 {
64 return;
65 }
66
67 UserCounterTable::delete([
68 'USER_ID' => $userId,
69 'SITE_ID' => SITE_ID,
70 'CODE' => '**L' . $logId,
71 ]);
72
73 $query = new \Bitrix\Main\Entity\Query(UserCounterTable::getEntity());
74 $query->addFilter('=USER_ID', $userId);
75 $query->addFilter('=SITE_ID', $siteId);
76 $query->addSelect('CODE');
77
78 $query->registerRuntimeField(
79 'comment',
80 new \Bitrix\Main\Entity\ReferenceField('LC',
82 [
83 '=ref.LOG_ID' => new SqlExpression('?i', $logId),
84 ],
85 [ 'join_type' => 'INNER' ]
86 )
87 );
88
89 $query->whereExpr("%s = CONCAT('**LC', %s)", [ 'CODE', 'comment.ID' ]);
90 $res = $query->exec();
91
92 while ($counterFields = $res->fetch())
93 {
94 UserCounterTable::delete([
95 'USER_ID' => $userId,
96 'SITE_ID' => $siteId,
97 'CODE' => $counterFields['CODE'],
98 ]);
99 }
100
101 // to send pushes only
102 UserCounterTable::update([
103 'USER_ID' => $userId,
104 'SITE_ID' => $siteId,
105 'CODE' => '**',
106 ], [
107 'SENT' => 0,
108 ]);
109 }
110
111 public static function onTaskUserOptionChanged(Event $event): EventResult
112 {
113 $result = new EventResult(
114 EventResult::UNDEFINED,
115 [],
116 'socialnetwork'
117 );
118
119 $taskId = (int)$event->getParameter('taskId');
120 $userId = (int)$event->getParameter('userId');
121 $option = (int)$event->getParameter('option');
122 $added = $event->getParameter('added');
123
124 if (
125 $taskId <= 0
126 || $userId <= 0
127 || $option !== \Bitrix\Tasks\Internals\UserOption\Option::MUTED
128 || !Loader::includeModule('tasks')
129 )
130 {
131 return $result;
132 }
133
134 $logId = 0;
135 $provider = new \Bitrix\Socialnetwork\Livefeed\TasksTask();
136 $res = LogTable::getList([
137 'filter' => [
138 '@EVENT_ID' => $provider->getEventId(),
139 '=SOURCE_ID' => $taskId
140 ],
141 'select' => [ 'ID' ]
142 ]);
143 if ($logFields = $res->fetch())
144 {
145 $logId = (int)$logFields['ID'];
146 }
147 if ($logId <= 0)
148 {
149 return $result;
150 }
151
152 $followDate = false;
153 if (!$added)
154 {
155 \CSocNetLogFollow::delete($userId, 'L'.$logId);
156 $followDate = ConvertTimeStamp(time() + \CTimeZone::getOffset(), 'FULL', SITE_ID); // compromise, we cannot get it from $logFields because it can have not updated value yet
157 }
158
159 \CSocNetLogFollow::set($userId, 'L'.$logId, ($added ? 'N' : 'Y'), $followDate);
160
161 return new EventResult(
162 EventResult::SUCCESS,
163 [],
164 'socialnetwork'
165 );
166 }
167}
168
getParameter($key)
Definition event.php:80
static getList(array $parameters=array())
static onTaskUserOptionChanged(Event $event)
Definition task.php:111
static onTaskUpdateViewed(Event $event)
Definition task.php:22