1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usercontentview.php
См. документацию.
1<?php
2
9namespace Bitrix\Socialnetwork\Item;
10
11use Bitrix\Main\Config\Option;
12use Bitrix\Main\Entity\ExpressionField;
13use Bitrix\Main\Loader;
14use Bitrix\Main\ModuleManager;
15use Bitrix\Socialnetwork\Integration\Extranet\User;
16use Bitrix\Socialnetwork\UserContentViewTable;
17use Bitrix\Main\DB\SqlQueryException;
18use Bitrix\Socialnetwork\Livefeed;
19
21{
22 private static array $viewDataCache = [];
23
24 public static function getAvailability()
25 {
26 static $result = null;
27 if ($result !== null)
28 {
29 return $result;
30 }
31
32 $result = true;
33/*
34
35 if (!ModuleManager::isModuleInstalled('bitrix24'))
36 {
37 return $result;
38 }
39
40 if (Loader::includeModule('bitrix24'))
41 {
42 $result = (
43 !in_array(\CBitrix24::getLicenseType(), array('project'), true)
44 || \CBitrix24::isNfrLicense()
45 || \CBitrix24::isDemoLicense()
46 );
47 }
48*/
49 return $result;
50
51 }
52
53 public static function getViewData($params = [])
54 {
55 if (!is_array($params))
56 {
57 return false;
58 }
59
60 $contentId = ($params['contentId'] ?? false);
61 if (empty($contentId))
62 {
63 return false;
64 }
65
66 $result = [];
67
68 if (!is_array($contentId))
69 {
71 }
72
73 $cacheKey = self::generateViewDataCacheKey($contentId);
74
75 if (isset(self::$viewDataCache[$cacheKey]))
76 {
77 return self::$viewDataCache[$cacheKey];
78 }
79
80 $res = UserContentViewTable::getList([
81 'filter' => [
82 '@CONTENT_ID' => $contentId
83 ],
84 'select' => [ 'CNT', 'CONTENT_ID', 'RATING_TYPE_ID', 'RATING_ENTITY_ID' ],
85 'runtime' => [
86 new ExpressionField('CNT', 'COUNT(*)')
87 ],
88 'group' => [ 'CONTENT_ID' ]
89 ]);
90
91 while ($content = $res->fetch())
92 {
93 $result[$content['CONTENT_ID']] = $content;
94 }
95
96 self::$viewDataCache[$cacheKey] = $result;
97
98 return $result;
99 }
100
101 public static function getUserList(array $params = []): array
102 {
103 global $USER;
104
105 $result = [
106 'items' => [],
107 'hiddenCount' => 0
108 ];
109
110 $contentId = (!empty($params['contentId']) ? $params['contentId'] : false);
111 $pageNum = (!empty($params['page']) ? (int)$params['page'] : 1);
112 $pathToUserProfile = (!empty($params['pathToUserProfile']) ? $params['pathToUserProfile'] : '');
113 $pageSize = 10;
114
115 if (
117 && $pageNum <= 0
118 )
119 {
120 return $result;
121 }
122
123 $select = [
124 'USER_ID',
125 'DATE_VIEW',
126 'USER_NAME' => 'USER.NAME',
127 'USER_LAST_NAME' => 'USER.LAST_NAME',
128 'USER_SECOND_NAME' => 'USER.SECOND_NAME',
129 'USER_LOGIN' => 'USER.LOGIN',
130 'USER_PERSONAL_PHOTO' => 'USER.PERSONAL_PHOTO',
131 'USER_PERSONAL_GENDER' => 'USER.PERSONAL_GENDER'
132 ];
133
134 $extranetInstalled = $mailInstalled = false;
135 $extranetIdList = [];
136
137 if (ModuleManager::isModuleInstalled('extranet'))
138 {
139 $extranetInstalled = true;
140 $select['USER_UF_DEPARTMENT'] = "USER.UF_DEPARTMENT";
141 }
142
143 if (IsModuleInstalled('mail'))
144 {
145 $mailInstalled = true;
146 $select['USER_EXTERNAL_AUTH_ID'] = "USER.EXTERNAL_AUTH_ID";
147 }
148
149 $queryParams = [
150 'order' => [
151 'DATE_VIEW' => 'DESC'
152 ],
153 'filter' => [
154 '=CONTENT_ID' => $contentId
155 ],
156 'select' => $select
157 ];
158
159 if (!$extranetInstalled)
160 {
161 $queryParams['limit'] = $pageSize;
162 $queryParams['offset'] = ($pageNum - 1) * $pageSize;
163 }
164
165 $userList = [];
166 $timeZoneOffset = \CTimeZone::getOffset();
167
168 $res = UserContentViewTable::getList($queryParams);
169
170 while ($fields = $res->fetch())
171 {
172 $photoSrc = '';
173
174 if ((int)$fields['USER_PERSONAL_PHOTO'] <= 0)
175 {
176 switch ($fields['USER_PERSONAL_GENDER'])
177 {
178 case "M":
179 $suffix = "male";
180 break;
181 case "F":
182 $suffix = "female";
183 break;
184 default:
185 $suffix = "unknown";
186 }
187 $fields['USER_PERSONAL_PHOTO'] = Option::get('socialnetwork', 'default_user_picture_' . $suffix, false, SITE_ID);
188 }
189
190 if (
191 !empty($fields['USER_PERSONAL_PHOTO'])
192 && (int)$fields['USER_PERSONAL_PHOTO'] > 0
193 )
194 {
195 $file = \CFile::resizeImageGet(
196 $fields["USER_PERSONAL_PHOTO"],
197 [ 'width' => 58, 'height' => 58 ],
199 false,
200 false,
201 true
202 );
203 $photoSrc = $file["src"];
204 }
205
206 $userFields = [
207 'NAME' => $fields['USER_NAME'],
208 'LAST_NAME' => $fields['USER_LAST_NAME'],
209 'SECOND_NAME' => $fields['USER_SECOND_NAME'],
210 'LOGIN' => $fields['USER_LOGIN'],
211 ];
212
213 $userType = '';
214 if (
215 $mailInstalled
216 && $fields["USER_EXTERNAL_AUTH_ID"] === "email"
217 )
218 {
219 $userType = "mail";
220 }
221 elseif ($extranetInstalled)
222 {
223 if ((empty($fields["USER_UF_DEPARTMENT"]) || (int)$fields["USER_UF_DEPARTMENT"][0] <= 0))
224 {
225 $userType = "extranet";
226 $extranetIdList[] = $fields["USER_ID"];
227 }
228
229 if (User::isCollaber((int)$fields["USER_ID"]))
230 {
231 $userType = 'collaber';
232 }
233 }
234
235 $dateView = (
236 $fields['DATE_VIEW'] instanceof \Bitrix\Main\Type\DateTime
237 ? $fields['DATE_VIEW']->toString()
238 : ''
239 );
240
241 $userList[$fields['USER_ID']] = [
242 'ID' => $fields['USER_ID'],
243 'TYPE' => $userType,
245 "UID" => $fields["USER_ID"],
246 "user_id" => $fields["USER_ID"],
247 "USER_ID" => $fields["USER_ID"]
248 ])),
249 'PHOTO_SRC' => $photoSrc,
250 'FULL_NAME' => \CUser::formatName(\CSite::getNameFormat(), $userFields, true, true),
251 'DATE_VIEW' => $dateView,
252 'DATE_VIEW_FORMATTED' => (
253 !empty($dateView)
254 ? \CComponentUtil::getDateTimeFormatted(MakeTimeStamp($dateView), "FULL", $timeZoneOffset)
255 : ''
256 )
257 ];
258 }
259
260 $userId = $USER->getId();
261
262 $userIdToCheckList = [];
263 if (Loader::includeModule('extranet'))
264 {
265 $userIdToCheckList = (
266 \CExtranet::isIntranetUser(SITE_ID, $userId)
267 ? $extranetIdList
268 : array_keys($userList)
269 );
270 }
271
272 $isTaskContentId = str_contains($contentId, 'TASK');
273 if (!empty($userIdToCheckList))
274 {
275 $myGroupsUserList = \CExtranet::getMyGroupsUsersSimple(\CExtranet::getExtranetSiteID());
276
277 foreach ($userIdToCheckList as $userIdToCheck)
278 {
279 if (
280 !in_array($userIdToCheck, $myGroupsUserList)
281 && $userIdToCheck != $userId
282 )
283 {
284 if ($isTaskContentId)
285 {
286 $userList[$userIdToCheck]['PUBLIC_MODE'] = false;
287 }
288 else
289 {
290 unset($userList[$userIdToCheck]);
291 $result['hiddenCount']++;
292 }
293 }
294 }
295 }
296
297 if (!$extranetInstalled)
298 {
299 $result['items'] = $userList;
300 }
301 elseif ($pageNum <= ((count($userList) / $pageSize) + 1))
302 {
303 $res = new \CDBResult();
304 $res->initFromArray($userList);
305 $res->navStart($pageSize, false, $pageNum);
306
307 while($user = $res->fetch())
308 {
309 $result['items'][] = $user;
310 }
311 }
312 else
313 {
314 $result['items'] = [];
315 }
316
317 return $result;
318 }
319
320 public static function deleteNoDemand($userId = 0): bool
321 {
322 $userId = (int)$userId;
323 if ($userId <= 0)
324 {
325 return false;
326 }
327
328 $result = true;
329
330 try
331 {
332 \Bitrix\Main\Application::getConnection()->queryExecute("DELETE FROM ".UserContentViewTable::getTableName()." WHERE USER_ID = ".$userId);
333 }
334 catch (SqlQueryException $exception)
335 {
336 $result = false;
337 }
338
339 return $result;
340 }
341
342 public static function set(array $params = []): void
343 {
344 $xmlIdList = (
345 isset($params["xmlIdList"])
346 && is_array($params["xmlIdList"])
347 ? $params["xmlIdList"]
348 : []
349 );
350
351 $context = ($params['context'] ?? '');
352
353 $userId = (
354 isset($params['userId'])
355 && (int)$params['userId'] > 0
356 ? (int)$params['userId'] :
357 0
358 );
359
360 if (!empty($xmlIdList))
361 {
362 foreach ($xmlIdList as $val)
363 {
364 $xmlId = $val['xmlId'];
365 $save = (
366 !isset($val['save'])
367 || $val['save'] !== 'N'
368 );
369
370 [ $entityType, $entityId ] = self::parseXmlId($xmlId);
371
372 if (
373 !empty($entityType)
374 && $entityId > 0
375 )
376 {
378 'ENTITY_TYPE' => $entityType,
379 'ENTITY_ID' => $entityId,
380 ]);
381 if ($provider)
382 {
383 $hasPermissions = true;
384 if (
385 isset($val['checkAccess'])
386 && $val['checkAccess'] === true
387 )
388 {
389 $provider->setOption('checkAccess', true);
390 $provider->initSourceFields();
391
392 if (empty($provider->getSourceFields()))
393 {
394 $hasPermissions = false;
395 }
396 }
397
398 if ($hasPermissions)
399 {
400 $provider->setContentView([
401 'save' => $save,
402 ]);
403 }
404
405/*
406TODO: https://bitrix24.team/company/personal/user/15/tasks/task/view/167281/
407 $provider->deleteCounter([
408 'userId' => $this->getCurrentUser()->getId(),
409 'siteId' => SITE_ID
410 ]);
411*/
412 }
413 }
414 }
415
417 'userId' => $userId,
418 'context' => $context
419 ]);
420 }
421 }
422
423 public static function finalize($params = []): bool
424 {
425 $userId = (!empty($params['userId']) ? (int)$params['userId'] : 0);
426 $context = (!empty($params['context']) ? $params['context'] : '');
427
428 if (!$userId)
429 {
430 return false;
431 }
432
433 if (
434 $context !== 'forum.comments/mobile'
435 && ModuleManager::isModuleInstalled('tasks')
436 )
437 {
439 if (!empty($taskIdList))
440 {
441 $event = new \Bitrix\Main\Event(
442 'socialnetwork', 'onContentFinalizeView',
443 [
444 'userId' => $userId,
445 'commentsTaskIdList' => $taskIdList
446 ]
447 );
448 $event->send();
449 }
450 }
451
452 return true;
453 }
454
455 public static function parseXmlId(string $xmlId = ''): array
456 {
457 $tmp = explode('-', $xmlId, 2);
458 $entityType = trim($tmp[0]);
459 $entityId = (int)$tmp[1];
460
461 return [ $entityType, $entityId ];
462 }
463
464 private static function generateViewDataCacheKey(array $params): string
465 {
466 return md5(serialize($params));
467 }
468}
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getConnection($name="")
Определения application.php:638
static getUserList(array $params=[])
Определения usercontentview.php:101
static finalize($params=[])
Определения usercontentview.php:423
static getViewData($params=[])
Определения usercontentview.php:53
static deleteNoDemand($userId=0)
Определения usercontentview.php:320
static parseXmlId(string $xmlId='')
Определения usercontentview.php:455
static init(array $params)
Определения provider.php:279
static makePathFromTemplate($template, $arParams=array())
Определения component_engine.php:355
$content
Определения commerceml.php:144
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
$userList
Определения discount_coupon_list.php:276
</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
$save
Определения iblock_catalog_edit.php:365
$select
Определения iblock_catalog_list.php:194
global $USER
Определения csv_new_run.php:40
$pageSize
Определения csv_new_run.php:34
$context
Определения csv_new_setup.php:223
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
IsModuleInstalled($module_id)
Определения tools.php:5301
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$user
Определения mysql_to_pgsql.php:33
$entityId
Определения payment.php:4
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$val
Определения options.php:1793
$pathToUserProfile
Определения sonet_set_content_view.php:30
$xmlIdList
Определения sonet_set_content_view.php:17
$contentId
Определения sonet_set_content_view.php:27
const SITE_ID
Определения sonet_set_content_view.php:12
$fields
Определения yandex_run.php:501