1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
task.php
См. документацию.
1<?php
2
9namespace Bitrix\Socialnetwork\Integration\Tasks;
10
11use Bitrix\Main\Application;
12use Bitrix\Main\DB\SqlExpression;
13use Bitrix\Main\Loader;
14use Bitrix\Main\UserCounterTable;
15use Bitrix\Socialnetwork\Livefeed\Provider;
16use Bitrix\Main\Event;
17use Bitrix\Main\EventResult;
18use Bitrix\Socialnetwork\LogCommentTable;
19use Bitrix\Socialnetwork\LogTable;
20
21class Task
22{
23 public static function onTaskUpdateViewed(Event $event): EventResult
24 {
25 $result = new EventResult(EventResult::UNDEFINED, [], 'socialnetwork');
26
27 $taskId = (int)$event->getParameter('taskId');
28 $userId = (int)$event->getParameter('userId');
29
30 if ($taskId <= 0 || $userId <= 0)
31 {
32 return $result;
33 }
34
35 if ($event->getParameter('isRealView'))
36 {
37 $liveFeedEntity = Provider::init([
38 'ENTITY_TYPE' => Provider::DATA_ENTITY_TYPE_TASKS_TASK,
39 'ENTITY_ID' => $taskId,
40 ]);
41 if ($liveFeedEntity)
42 {
43 $liveFeedEntity->setContentView(['user_id' => $userId]);
44 self::updateUserCounter([
45 'userId' => $userId,
46 'logId' => $liveFeedEntity->getLogId(),
47 ]);
48 }
49 }
50
51 return new EventResult(EventResult::SUCCESS, [], 'socialnetwork');
52 }
53
54 private static function updateUserCounter(array $params = []): void
55 {
56 $logId = (int)($params['logId'] ?? 0);
57 $userId = (int)($params['userId'] ?? 0);
59
60 if (
61 $logId <= 0
62 || $userId <= 0
63 )
64 {
65 return;
66 }
67
68 UserCounterTable::delete([
69 'USER_ID' => $userId,
70 'SITE_ID' => SITE_ID,
71 'CODE' => '**L' . $logId,
72 ]);
73
74 $query = new \Bitrix\Main\Entity\Query(UserCounterTable::getEntity());
75 $query->addFilter('=USER_ID', $userId);
76 $query->addFilter('=SITE_ID', $siteId);
77 $query->addSelect('CODE');
78
79 $query->registerRuntimeField(
80 'comment',
81 new \Bitrix\Main\Entity\ReferenceField('LC',
83 [
84 '=ref.LOG_ID' => new SqlExpression('?i', $logId),
85 ],
86 [ 'join_type' => 'INNER' ]
87 )
88 );
89
90 $helper = Application::getConnection()->getSqlHelper();
91 $expression = $helper->getConcatFunction(
92 $helper->convertToDbString('**LC'),
93 $helper->convertToDbString('%s')
94 );
95 $query->whereExpr("%s = {$expression}", [ 'CODE', 'comment.ID' ]);
96 $res = $query->exec();
97
98 while ($counterFields = $res->fetch())
99 {
100 UserCounterTable::delete([
101 'USER_ID' => $userId,
102 'SITE_ID' => $siteId,
103 'CODE' => $counterFields['CODE'],
104 ]);
105 }
106
107 // to send pushes only
108 UserCounterTable::update([
109 'USER_ID' => $userId,
110 'SITE_ID' => $siteId,
111 'CODE' => '**',
112 ], [
113 'SENT' => 0,
114 ]);
115 }
116
118 {
119 $result = new EventResult(
120 EventResult::UNDEFINED,
121 [],
122 'socialnetwork'
123 );
124
125 $taskId = (int)$event->getParameter('taskId');
126 $userId = (int)$event->getParameter('userId');
127 $option = (int)$event->getParameter('option');
128 $added = $event->getParameter('added');
129
130 if (
131 $taskId <= 0
132 || $userId <= 0
133 || $option !== \Bitrix\Tasks\Internals\UserOption\Option::MUTED
134 || !Loader::includeModule('tasks')
135 )
136 {
137 return $result;
138 }
139
140 $logId = 0;
141 $provider = new \Bitrix\Socialnetwork\Livefeed\TasksTask();
143 'filter' => [
144 '@EVENT_ID' => $provider->getEventId(),
145 '=SOURCE_ID' => $taskId
146 ],
147 'select' => [ 'ID' ]
148 ]);
149 if ($logFields = $res->fetch())
150 {
151 $logId = (int)$logFields['ID'];
152 }
153 if ($logId <= 0)
154 {
155 return $result;
156 }
157
158 $followDate = false;
159 if (!$added)
160 {
161 \CSocNetLogFollow::delete($userId, 'L'.$logId);
162 $followDate = ConvertTimeStamp(time() + \CTimeZone::getOffset(), 'FULL', SITE_ID); // compromise, we cannot get it from $logFields because it can have not updated value yet
163 }
164
165 \CSocNetLogFollow::set($userId, 'L'.$logId, ($added ? 'N' : 'Y'), $followDate);
166
167 return new EventResult(
168 EventResult::SUCCESS,
169 [],
170 'socialnetwork'
171 );
172 }
173}
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения event.php:5
static getEntity()
Определения datamanager.php:65
static getList(array $parameters=array())
Определения datamanager.php:431
static onTaskUserOptionChanged(Event $event)
Определения task.php:117
static onTaskUpdateViewed(Event $event)
Определения task.php:23
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$siteId
Определения ajax.php:8
Определения ufield.php:9
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$option
Определения options.php:1711
const SITE_ID
Определения sonet_set_content_view.php:12