1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
recalculatecounters.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Update;
4
5use Bitrix\Calendar\Internals\Counter\CounterService;
6use Bitrix\Calendar\Internals\Counter\Event\EventDictionary;
7use Bitrix\Calendar\Internals\Log\Logger;
8use Bitrix\Main\Update\Stepper;
9use Bitrix\Main\UserTable;
10
15final class ReCalculateCounters extends Stepper
16{
17 private const LIMIT = 50;
18 protected static $moduleId = 'calendar';
19
20 private int $lastId;
21 private array $users;
22
23 public function execute(array &$option): bool
24 {
25 $lastId = (int)($option['lastId'] ?? 0);
26
27 $this
28 ->setLastId($lastId)
29 ->fillUsers()
30 ;
31
32 if (!count($this->users))
33 {
34 return self::FINISH_EXECUTION;
35 }
36
37 $this
38 ->reCalculateCounters()
39 ->updateLastId()
40 ->setOptions($option);
41
42 return self::CONTINUE_EXECUTION;
43 }
44
45 private function fillUsers(): self
46 {
47 $this->users = [];
48
49 try
50 {
51 $this->users = $this->getAllUsers();
52 }
53 catch (\Exception $exception)
54 {
55 (new Logger())->log($exception);
56 }
57
58 return $this;
59 }
60
61 private function reCalculateCounters(): self
62 {
63 $userIds = [];
64 foreach ($this->users as $user)
65 {
66 $userId = (int)($user['ID'] ?? 0);
67 $userIds[] = $userId;
68 }
69
70 CounterService::addEvent(EventDictionary::EVENT_ATTENDEES_UPDATED, [
71 'user_ids' => $userIds,
72 ]);
73
74 return $this;
75 }
76
77 private function setLastId(int $id = 0): self
78 {
79 $this->lastId = $id;
80 return $this;
81 }
82
83 private function updateLastId(): self
84 {
85 $this->lastId = max(array_map(fn (array $user): int => (int)$user['ID'], $this->users));
86 return $this;
87 }
88
89 private function setOptions(array &$options): self
90 {
91 $options['lastId'] = $this->lastId;
92 return $this;
93 }
94
95 private function getAllUsers(): array
96 {
97 $query = UserTable::query()
98 ->setSelect(['ID'])
99 ->where('ID', '>', $this->lastId)
100 ->where('ACTIVE', 'Y')
101 ->where('IS_REAL_USER', 'Y')
102 ->where('UF_DEPARTMENT', '!=', false)
103 ->setLimit($this->getLimit());
104
105 return $query->exec()->fetchAll();
106 }
107
108 private function getLimit(): int
109 {
110 $limit = \COption::GetOptionString('calendar', 'calendarReCounterStepperLimit', '');
111
112 return $limit === ''
113 ? self::LIMIT
114 : (int)$limit
115 ;
116 }
117}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
if(!\Bitrix\Main\Loader::includeModule('clouds')) $lastId
Определения sync.php:68
$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
$user
Определения mysql_to_pgsql.php:33
</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
$option
Определения options.php:1711