Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logentry.php
1<?php
2
4
12
13class LogEntry extends Base
14{
15 public function configureActions()
16 {
17 return [
18 'getPinData' => [
19 '+prefilters' => [
20 new ActionFilter\Token(static function () {
21 $requestParams = \Bitrix\Main\Context::getCurrent()->getRequest()->getPost('params');
22
23 return (
24 is_array($requestParams)
25 && isset($requestParams['logId'])
26 ? (string)$requestParams['logId']
27 : ''
28 );
29 }),
30 ],
31 ],
32 ];
33 }
34
35 public function getHiddenDestinationsAction(array $params = []): ?array
36 {
37 $logId = (int)($params['logId'] ?? 0);
38 $createdById = (int)($params['createdById'] ?? 0);
39 $destinationLimit = (int)($params['destinationLimit'] ?? 100);
40
41 $pathToUser = ($params['pathToUser'] ?? '');
42 $pathToWorkgroup = ($params['pathToWorkgroup'] ?? '');
43 $pathToDepartment = ($params['pathToDepartment'] ?? '');
44 $nameTemplate = ($params['nameTemplate'] ?? \CSite::getNameFormat());
45 $showLogin = ($params['showLogin'] ?? (ModuleManager::isModuleInstalled('intranet') ? 'Y' : 'N'));
46
47 if ($logId <= 0)
48 {
49 $this->addError(new Error('Empty Log ID.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_EMPTY_LOG_ID'));
50 return null;
51 }
52
53 if (!Loader::includeModule('socialnetwork'))
54 {
55 $this->addError(new Error('Cannot include Socialnetwork module.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_MODULE_NOT_INSTALLED'));
56 return null;
57 }
58
59 \CSocNetTools::initGlobalExtranetArrays();
60
61 $extranetInstalled = Loader::includeModule("extranet");
62 $currentExtranetUser = ($extranetInstalled && !\CExtranet::isIntranetUser());
63 $extranetAdmin = ($extranetInstalled && \CExtranet::isExtranetAdmin());
64 $visibleUserIdList = $availableExtranetUserIdList = false;
65
66 if ($currentExtranetUser)
67 {
68 $visibleUserIdList = \CExtranet::getMyGroupsUsersSimple(SITE_ID);
69 }
70 elseif (
71 $extranetInstalled
72 && !$extranetAdmin
73 )
74 {
75 $availableExtranetUserIdList = \CExtranet::getMyGroupsUsersSimple(\CExtranet::getExtranetSiteID());
76 }
77
78 $rightsList = [];
79 $skipGetRights = false;
80
81 $res = GetModuleEvents('socialnetwork', 'OnBeforeSocNetLogEntryGetRights');
82 while ($event = $res->fetch())
83 {
84 if (ExecuteModuleEventEx(
85 $event,
86 [
87 [ 'LOG_ID' => $logId ],
88 &$rightsList
89 ]
90 ) === false
91 )
92 {
93 $skipGetRights = true;
94 break;
95 }
96 }
97
98 if (!$skipGetRights)
99 {
100 $res = \CSocNetLogRights::getList([], [ 'LOG_ID' => $logId ]);
101 while ($rightFields = $res->fetch())
102 {
103 $rightsList[] = $rightFields['GROUP_CODE'];
104 }
105 }
106
107 $destinationParams = [
108 'PATH_TO_USER' => $pathToUser,
109 'PATH_TO_GROUP' => $pathToWorkgroup,
110 'PATH_TO_CONPANY_DEPARTMENT' => $pathToDepartment,
111 'NAME_TEMPLATE' => $nameTemplate,
112 'SHOW_LOGIN' => $showLogin,
113 'DESTINATION_LIMIT' => 100,
114 'CHECK_PERMISSIONS_DEST' => 'N'
115 ];
116
117 if ($createdById > 0)
118 {
119 $destinationParams["CREATED_BY"] = $createdById;
120 }
121
122 $moreCount = 0;
123 $destinationList = \CSocNetLogTools::formatDestinationFromRights($rightsList, $destinationParams, $moreCount);
124 $hiddenDestinationsCount = 0;
125
126 $availableWorkgroupsIdList = \CSocNetLogTools::getAvailableGroups();
127
128 foreach($destinationList as $key => $destinationFields)
129 {
130 if (
131 isset($destinationFields['TYPE'], $destinationFields['ID'])
132 && (
133 (
134 $destinationFields['TYPE'] === 'SG'
135 && !in_array((int)$destinationFields['ID'], $availableWorkgroupsIdList)
136 )
137 || (
138 in_array($destinationFields['TYPE'], ['CRMCOMPANY', 'CRMLEAD', 'CRMCONTACT', 'CRMDEAL'])
139 && Loader::includeModule('crm')
140 && !\Bitrix\Crm\Security\EntityAuthorization::checkReadPermission(
141 \CCrmLiveFeedEntity::resolveEntityTypeID($destinationFields['TYPE']),
142 $destinationFields['ID']
143 )
144 )
145 || (
146 in_array($destinationFields['TYPE'], ['DR', 'D'])
147 && $currentExtranetUser
148 )
149 || (
150 $destinationFields['TYPE'] === 'U'
151 && is_array($visibleUserIdList)
152 && !in_array((int)$destinationFields['ID'], $visibleUserIdList)
153 )
154 || (
155 $destinationFields['TYPE'] === 'U'
156 && isset($destinationFields['IS_EXTRANET'])
157 && $destinationFields['IS_EXTRANET'] === 'Y'
158 && is_array($availableExtranetUserIdList)
159 && !in_array((int)$destinationFields['ID'], $availableExtranetUserIdList)
160 )
161 )
162 )
163 {
164 unset($destinationList[$key]);
165 $hiddenDestinationsCount++;
166 }
167 }
168
169 return [
170 'destinationList' => array_slice($destinationList, $destinationLimit),
171 'hiddenDestinationsCount' => $hiddenDestinationsCount
172 ];
173 }
174
175 public function pinAction(array $params = []): ?array
176 {
177 $logId = (int)($params['logId'] ?? 0);
178
179 if ($logId <= 0)
180 {
181 $this->addError(new Error('Empty Log ID.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_EMPTY_LOG_ID'));
182 return null;
183 }
184
185 if (!Loader::includeModule('socialnetwork'))
186 {
187 $this->addError(new Error('Cannot include Socialnetwork module.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_MODULE_NOT_INSTALLED'));
188 return null;
189 }
190
192 'logId' => $logId,
193 'userId' => (int)$this->getCurrentUser()->getId(),
194 ]);
195
196 return [
197 'success' => true
198 ];
199 }
200
201 public function unpinAction(array $params = []): ?array
202 {
203 $logId = (int)($params['logId'] ?? 0);
204
205 if ($logId <= 0)
206 {
207 $this->addError(new Error('Empty Log ID.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_EMPTY_LOG_ID'));
208 return null;
209 }
210
211 if (!Loader::includeModule('socialnetwork'))
212 {
213 $this->addError(new Error('Cannot include Socialnetwork module.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_MODULE_NOT_INSTALLED'));
214 return null;
215 }
216
217 LogPinnedTable::delete([
218 'LOG_ID' => $logId,
219 'USER_ID' => (int)$this->getCurrentUser()->getId(),
220 ]);
221
222 return [
223 'success' => true
224 ];
225 }
226
227 public function getPinDataAction(array $params = []): ?array
228 {
229 $logId = (isset($params['logId']) ? (int)$params['logId'] : 0);
230
231 if ($logId <= 0)
232 {
233 $this->addError(new Error('Empty Log ID.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_EMPTY_LOG_ID'));
234 return null;
235 }
236
237 $res = LogTable::getList([
238 'filter' => [
239 '=ID' => $logId
240 ],
241 'select' => [ 'ID', 'ENTITY_ID', 'EVENT_ID', 'SOURCE_ID', 'RATING_TYPE_ID', 'RATING_ENTITY_ID' ]
242 ]);
243 if (!($logEntryFields = $res->fetch()))
244 {
245 $this->addError(new Error('Log entry not found.', 'SONET_CONTROLLER_LIVEFEED_LOGENTRY_NOT_FOUND'));
246 return null;
247 }
248
249 $contentId = \Bitrix\Socialnetwork\Livefeed\Provider::getContentId($logEntryFields);
250 if (!$contentId)
251 {
252 $this->addError(new Error('Content entity not found.', 'SONET_CONTROLLER_LIVEFEED_CONTENT_NOT_FOUND'));
253 return null;
254 }
255
256 if (empty($contentId['ENTITY_TYPE']))
257 {
258 $this->addError(new Error('Content entity not found.', 'SONET_CONTROLLER_LIVEFEED_CONTENT_NOT_FOUND'));
259 return null;
260 }
261
262 $postProvider = \Bitrix\Socialnetwork\Livefeed\Provider::init([
263 'ENTITY_TYPE' => $contentId['ENTITY_TYPE'],
264 'ENTITY_ID' => $contentId['ENTITY_ID'],
265 'LOG_ID' => $logEntryFields['ID']
266 ]);
267
268 return [
269 'TITLE' => htmlspecialcharsEx($postProvider->getPinnedTitle()),
270 'DESCRIPTION' => htmlspecialcharsEx($postProvider->getPinnedDescription())
271 ];
272 }
273}
274
static getList(array $parameters=array())
Definition logentry.php:14
getPinDataAction(array $params=[])
Definition logentry.php:227
pinAction(array $params=[])
Definition logentry.php:175
unpinAction(array $params=[])
Definition logentry.php:201
configureActions()
Definition logentry.php:15
getHiddenDestinationsAction(array $params=[])
Definition logentry.php:35
static set(array $params=[])
Definition logpinned.php:60