1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
openeventadded.php
См. документацию.
1<?php
2
4
6use Bitrix\Calendar\Core\Event\Event as CalendarEvent;
16
21final class OpenEventAdded extends Stepper
22{
23 private const LIMIT = 100;
24 protected static $moduleId = Common::CALENDAR_MODULE_ID;
25
26 public function execute(array &$option): bool
27 {
29 $offset = (int)($option['offset'] ?? 0);
30 $eventId = (int)($outerParams[0] ?? 0);
31
33 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
35 $calendarEvent = $mapperFactory->getEvent()->getById($eventId);
36
37 if (!$calendarEvent)
38 {
39 return self::FINISH_EXECUTION;
40 }
41
42 $userIds = $this->getAffectedUserIds($calendarEvent, $offset);
43
44 if (empty($userIds))
45 {
46 return self::FINISH_EXECUTION;
47 }
48
49 $this
50 ->upCounter(event: $calendarEvent, userIds: $userIds)
51 ->setOptions(options: $option, offset: $offset)
52 ;
53
54 return self::CONTINUE_EXECUTION;
55 }
56
57 private function getAffectedUserIds(CalendarEvent $event, int $offset): array
58 {
60 $eventCategory = $event->getEventOption()->getCategory();
61
62 try
63 {
64 $categoryId = $eventCategory->getId();
65
66 $userIds = $eventCategory->getClosed()
67 ? $this->getChannelUsers(categoryId: $categoryId, offset: $offset)
68 : $this->getAllUsers(offset: $offset)
69 ;
70
71 $categoryBanProvider = new CategoryBanProvider(0);
72 $usersWhoBannedTheCategory = $categoryBanProvider->getUsersWhoBannedTheCategory($userIds, $categoryId);
73
74 return array_filter($userIds, static fn(int $userId) => !$usersWhoBannedTheCategory[$userId]);
75 }
76 catch (\Exception $exception)
77 {
78 (new Logger())->log($exception);
79 }
80
81 return [];
82 }
83
84 private function upCounter(CalendarEvent $event, array $userIds): self
85 {
86 (new Processor\OpenEvent())->upCounter(userIds: $userIds, event: $event);
87
88 return $this;
89 }
90
91 private function setOptions(array &$options, int $offset): self
92 {
93 $options['offset'] = $offset + $this->getLimit();
94
95 return $this;
96 }
97
98 private function getAllUsers(int $offset): array
99 {
100 $userIds = [];
101
102 $query = UserTable::query()
103 ->setSelect(['ID'])
104 ->where('ACTIVE', 'Y')
105 ->where('IS_REAL_USER', 'Y')
106 ->where('UF_DEPARTMENT', '!=', false)
107 ->setOffset($offset)
108 ->setLimit($this->getLimit())
109 ->exec()
110 ;
111
112 while ($item = $query->fetch())
113 {
114 $userIds[] = (int)$item['ID'];
115 }
116
117 return $userIds;
118 }
119
120 private function getChannelUsers(int $categoryId, int $offset): array
121 {
122 $userIds = [];
123
125 ->setSelect(['USER_ID'])
126 ->where('CATEGORY_ID', '=', $categoryId)
127 ->addOrder('USER_ID')
128 ->setLimit($this->getLimit())
129 ->setOffset($offset)
130 ->exec()
131 ;
132
133 while ($item = $query->fetch())
134 {
135 $userIds[] = (int)$item['USER_ID'];
136 }
137
138 return $userIds;
139 }
140
141 private function getLimit(): int
142 {
143 $limit = \COption::GetOptionString('calendar', 'calendarCounterStepperLimit', '');
144
145 return $limit === ''
146 ? self::LIMIT
147 : (int)$limit
148 ;
149 }
150}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getOuterParams()
Определения stepper.php:212
execute(array &$option)
Определения user.php:48
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$event
Определения prolog_after.php:141
$option
Определения options.php:1711