1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CategoryMuteProvider.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\OpenEvents\Provider;
4
5use Bitrix\Calendar\Core\Common;
6use Bitrix\Calendar\OpenEvents\Internals\OpenEventCategoryMutedTable;
7use Bitrix\Main\Engine\CurrentUser;
8
10{
11 private int $userId;
12
13 public function __construct(?int $userId = null)
14 {
15 $this->userId = $userId ?? (int)CurrentUser::get()->getId();
16 }
17
18 public function isMuted(int $categoryId): bool
19 {
20 $mutes = $this->getByCategoryIds([$categoryId]);
21
22 return $mutes[$categoryId];
23 }
24
34 public function getByCategoryIds(array $categoryIds): array
35 {
36 if (empty($categoryIds))
37 {
38 return [];
39 }
40
42 ->setSelect(['USER_ID', 'CATEGORY_ID'])
43 ->whereIn('USER_ID', [Common::SYSTEM_USER_ID, $this->userId])
44 ->whereIn('CATEGORY_ID', $categoryIds)
45 ;
46
47 $mutedQueryResult = $mutedQuery->exec();
48
49 $mutedCategoryIds = [];
50 $defaultMutedCategoryIds = [];
51 while ($mute = $mutedQueryResult->fetchObject())
52 {
53 $userId = $mute->getUserId();
54 $categoryId = $mute->getCategoryId();
55 if ($userId === Common::SYSTEM_USER_ID)
56 {
57 $defaultMutedCategoryIds[$categoryId] = $categoryId;
58 }
59 else
60 {
61 $mutedCategoryIds[$categoryId] = $categoryId;
62 }
63 }
64
65 $mutes = array_map(static function(int $id) use ($defaultMutedCategoryIds, $mutedCategoryIds) {
66 $isMutedByDefault = isset($defaultMutedCategoryIds[$id]);
67 if ($isMutedByDefault)
68 {
69 $isUnmutedByUser = isset($mutedCategoryIds[$id]);
70 $isMuted = !$isUnmutedByUser;
71 }
72 else
73 {
74 $isMutedByUser = isset($mutedCategoryIds[$id]);
75 $isMuted = $isMutedByUser;
76 }
77
78 return $isMuted;
79 }, $categoryIds);
80
81 return array_combine($categoryIds, $mutes);
82 }
83}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804