17 if (!($arFields[
'RESULT'] ??
null) || !Loader::includeModule(
"iblock"))
22 $departmentIBlockId = (int)\
Bitrix\Main\
Config\Option::get(
'intranet',
'iblock_structure', 0);
23 if ($departmentIBlockId <= 0)
28 if(!empty($arFields[
'UF_DEPARTMENT']))
30 $arFieldsDepartments =
31 is_array($arFields[
'UF_DEPARTMENT']) ? $arFields[
'UF_DEPARTMENT'] : [$arFields[
'UF_DEPARTMENT']]
34 self::$storedData = self::getAffectedDepartments($arFieldsDepartments, $departmentIBlockId);
47 (!isset($arFields[
'UF_DEPARTMENT']) && !isset($arFields[
'ACTIVE']))
48 || empty($arFields[
'ID'])
49 || !Loader::includeModule(
"iblock")
55 $departmentIBlockId = (int)\
Bitrix\Main\
Config\Option::get(
'intranet',
'iblock_structure', 0);
56 if ($departmentIBlockId <= 0)
61 $user = \CUser::GetByID($arFields[
'ID'])->Fetch();
63 if (!isset($user[
'UF_DEPARTMENT']))
67 elseif (is_array($user[
'UF_DEPARTMENT']))
69 $oldDepartments = $user[
'UF_DEPARTMENT'];
73 $oldDepartments = [$user[
'UF_DEPARTMENT']];
76 if (is_array($arFields[
'UF_DEPARTMENT']))
78 $newDepartments = $arFields[
'UF_DEPARTMENT'];
82 $newDepartments = [$arFields[
'UF_DEPARTMENT']];
85 if (!self::isUserDepartmentsUpdated($oldDepartments, $newDepartments))
90 $departments = array_unique(
97 self::$storedData = self::getAffectedDepartments($departments, $departmentIBlockId);
100 private static function isUserDepartmentsUpdated(array $oldValue, array $newValue): bool
102 return self::convertArrayValuesToInteger($oldValue) !== self::convertArrayValuesToInteger($newValue);
105 private static function convertArrayValuesToInteger(array $array): array
107 return array_map(
static function($value){
118 if (empty(self::$storedData) || !($arFields[
'RESULT'] ??
null) ||!Loader::includeModule(
"iblock"))
132 if ($userId <= 0 || !\
Bitrix\Main\Loader::includeModule(
"iblock"))
137 $user = \CUser::GetByID($userId)->Fetch();
139 $departmentIBlockId = (int)\
Bitrix\Main\
Config\Option::get(
'intranet',
'iblock_structure', 0);
140 if ($departmentIBlockId > 0 && !empty($user[
'UF_DEPARTMENT']))
142 self::$storedData = self::getAffectedDepartments($user[
'UF_DEPARTMENT'], $departmentIBlockId);
152 if (!Loader::includeModule(
"iblock") || \CUser::GetByID($userId)->Fetch())
167 empty($arFields[
'IBLOCK_ID'])
168 || empty($arFields[
'IBLOCK_SECTION_ID'])
169 || !Loader::includeModule(
"iblock")
170 || !self::isDepartmentIBlock($arFields[
'IBLOCK_ID'])
176 self::$storedData = self::getAffectedDepartments($arFields[
'IBLOCK_SECTION_ID'], $arFields[
'IBLOCK_ID']);
188 empty($arFields[
'ID'])
189 ||empty($arFields[
'IBLOCK_ID'])
190 || empty($arFields[
'IBLOCK_SECTION_ID'])
191 || !Loader::includeModule(
"iblock")
192 || !self::isDepartmentIBlock($arFields[
'IBLOCK_ID'])
198 $updatingDepartment = \CIBlockSection::GetByID($arFields[
'ID'])->Fetch();
199 if (($arFields[
'IBLOCK_SECTION_ID']) === $updatingDepartment[
'IBLOCK_SECTION_ID'])
204 $departments = array_unique(
206 [$arFields[
'IBLOCK_SECTION_ID']],
207 [$updatingDepartment[
'IBLOCK_SECTION_ID']],
211 self::$storedData = self::getAffectedDepartments($departments, $arFields[
'IBLOCK_ID']);
220 if (empty(self::$storedData) || !($arFields[
'RESULT'] ??
null) || !Loader::includeModule(
"iblock"))
233 private static function getAffectedDepartments($departments,
int $departmentIBlockId): array
235 if (!is_array($departments))
237 $departments = [$departments];
240 $affectedDepartments = [];
242 foreach ($departments as $departmentId)
244 $result = \CIBlockSection::GetNavChain($departmentIBlockId, $departmentId, [
'ID'],
true);
245 foreach ($result as $affectedDepartment)
247 if(!in_array($affectedDepartment, $affectedDepartments))
249 $affectedDepartments[] = $affectedDepartment;
254 return $affectedDepartments;
260 private static function prepareBatchOfMessagesData(): array
263 foreach (self::$storedData as $affectedDepartment)
265 if (!empty($affectedDepartment[
'ID']))
269 'entityId' => $affectedDepartment[
'ID'],
274 if(self::DO_UPDATE_ALL_EVENTS)
288 private static function isDepartmentIBlock(
int $IBlockId): bool
290 $departmentIBlockId = (int)\
Bitrix\Main\
Config\Option::get(
'intranet',
'iblock_structure', 0);
292 return $departmentIBlockId > 0 && $departmentIBlockId === $IBlockId;