Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Configuration.php
1<?php
3
15use Bitrix\Main\Entity\Query\Filter\ConditionTree;
23use Exception;
24
26{
27 public const DEFAULT_PRESET_NAME = 'default';
28 public const DEFAULT_PRESET_SETTING_NAME = 'default_configuration_preset';
29 protected const DEFAULT_SORT = 100;
30
31 public const USER_PRESET_SORT = 1000000;
32
33 public const NOTIFY_GROUP = 'notify';
34 public const GENERAL_GROUP = 'general';
35
36 protected const CACHE_TTL = 31536000; //one year
37 protected const CACHE_NAME = 'user_preset';
38 protected const CACHE_DIR = '/im/option/';
39
40 protected static $defaultPresetId = null;
41
42 public static function getDefaultPresetId(): int
43 {
44 if (self::$defaultPresetId)
45 {
47 }
48 $row =
49 OptionGroupTable::query()
50 ->addSelect('ID')
51 ->where('NAME', self::DEFAULT_PRESET_NAME)
52 ->fetch()
53 ;
54
55 if ($row['ID'])
56 {
57 self::$defaultPresetId = (int)$row['ID'];
58
60 }
61
63 }
64
65 public static function createDefaultPreset(): int
66 {
67 $defaultGroupId =
68 \Bitrix\Im\Model\OptionGroupTable::add([
70 'SORT' => 0,
71 'CREATE_BY_ID' => 0,
72 ])
73 ->getId()
74 ;
75
76 $generalDefaultSettings = General::getDefaultSettings();
77 General::setSettings($defaultGroupId, $generalDefaultSettings);
78
79 $notifySettings = Notification::getSimpleNotifySettings($generalDefaultSettings);
80 Notification::setSettings($defaultGroupId, $notifySettings);
81
82 if (Loader::includeModule('intranet'))
83 {
84 $topDepartmentId = Department::getTopDepartmentId();
85 OptionAccessTable::add([
86 'GROUP_ID' => $defaultGroupId,
87 'ACCESS_CODE' => $topDepartmentId ? 'DR' . $topDepartmentId : 'AU'
88 ]);
89 }
90
91 Option::set('im', self::DEFAULT_PRESET_SETTING_NAME, (int)$defaultGroupId);
92
93 return (int)$defaultGroupId;
94 }
95
108 public static function getUserPreset(int $userId): array
109 {
110 $preset = self::getUserPresetFromCache($userId);
111
112 if (!empty($preset))
113 {
114 $preset['notify']['settings'] =
115 array_replace_recursive(
117 ($preset['notify']['settings'] ?? [])
118 )
119 ;
120
121 $preset['general']['settings'] =
122 array_replace_recursive(
124 ($preset['general']['settings'] ?? [])
125 )
126 ;
127
128 return $preset;
129 }
130
131 $query = OptionGroupTable::query()
132 ->setSelect([
133 'ID',
134 'NAME',
135 'SORT',
136 'USER_ID',
137 'NOTIFY_GROUP_ID' => 'OPTION_USER.NOTIFY_GROUP_ID',
138 'GENERAL_GROUP_ID' => 'OPTION_USER.GENERAL_GROUP_ID'
139 ])
140 ->registerRuntimeField(
141 'OPTION_USER',
142 new Reference(
143 'OPTION_USER',
144 OptionUserTable::class,
145 Join::on('this.ID', 'ref.NOTIFY_GROUP_ID')
146 ->logic('or')
147 ->whereColumn('this.ID', 'ref.GENERAL_GROUP_ID'),
148 ['join_type' => Join::TYPE_INNER]
149 )
150 )
151 ->where('OPTION_USER.USER_ID', $userId)
152 ->setLimit(2)
153 ;
154
155 $rows = $query->fetchAll();
156
157 if (empty($rows))
158 {
159 $presetId = self::restoreBindings($userId);
160
161 if ($presetId === self::getDefaultPresetId())
162 {
163 $userPreset = self::getDefaultUserPreset();
164 }
165 else
166 {
167 $preset = self::getPreset($presetId);
168 $userPreset = [
169 'notify' => $preset,
170 'general' => $preset,
171 ];
172 }
173
174 self::setUserPresetInCache($userId, $userPreset);
175
176 return $userPreset;
177 }
178
179 $notifyPreset = [];
180 $generalPreset = [];
181 foreach ($rows as $preset)
182 {
183 if ((int)$preset['ID'] === (int)$preset['NOTIFY_GROUP_ID'])
184 {
185 $notifyPreset = [
186 'id' => $preset['ID'],
187 'name' => self::getPresetName($preset),
188 'sort' => $preset['SORT'],
189 'userId' => $preset['USER_ID'],
190 'settings' => Notification::getGroupSettings((int)$preset['ID'])
191 ];
192 }
193
194 if ((int)$preset['ID'] === (int)$preset['GENERAL_GROUP_ID'])
195 {
196 $generalPreset = [
197 'id' => $preset['ID'],
198 'name' => self::getPresetName($preset),
199 'sort' => $preset['SORT'],
200 'userId' => $preset['USER_ID'],
201 'settings' => General::getGroupSettings((int)$preset['ID'])
202 ];
203 }
204 }
205
206 //TODO extraordinary bag with not existing group from database
207 if (empty($notifyPreset))
208 {
209 $notifyPreset = self::getDefaultUserPreset()['notify'];
210 }
211 if (empty($generalPreset))
212 {
213 $generalPreset = self::getDefaultUserPreset()['general'];
214 }
215
216 $userPreset = [
217 'notify' => $notifyPreset,
218 'general' => $generalPreset
219 ];
220 self::setUserPresetInCache($userId, $userPreset);
221
222 return $userPreset;
223 }
224
234 public static function getPreset(int $id): array
235 {
236 $settings['notify'] = Notification::getGroupSettings($id);
237 $settings['general'] = General::getGroupSettings($id);
238
239 $row =
240 OptionGroupTable::query()
241 ->setSelect([
242 'NAME',
243 'SORT',
244 'USER_ID'
245 ])
246 ->where('ID', $id)
247 ->fetch()
248 ;
249
250 return [
251 'id' => $id,
252 'name' => $row['NAME'],
253 'sort' => (int)$row['SORT'],
254 'userId' => $row['USER_ID'],
255 'settings' => $settings,
256 ];
257 }
258
259 public static function getDefaultUserPreset(): array
260 {
261 $generalPreset = [
262 'settings' => General::getDefaultSettings(),
263 'id' => self::getDefaultPresetId(),
264 'sort' => 0,
265 'name' => self::getPresetName(['NAME' =>'default'])
266 ];
267
268 $notifyPreset = [
269 'settings' => Notification::getDefaultSettings(),
270 'id' => self::getDefaultPresetId(),
271 'sort' => 0,
272 'name' => self::getPresetName(['NAME' =>'default'])
273 ];
274
275 return [
276 'notify' => $notifyPreset,
277 'general' => $generalPreset
278 ];
279 }
280
288 public static function getUserPresetIds(int $userId): ?array
289 {
290 $ids =
291 OptionUserTable::query()
292 ->setSelect(['NOTIFY_GROUP_ID', 'GENERAL_GROUP_ID'])
293 ->where('USER_ID', $userId)
294 ->fetch()
295 ;
296
297 if ($ids === false)
298 {
299 return null;
300 }
301
302 return [
303 'notify' => (int)$ids['NOTIFY_GROUP_ID'],
304 'general' => (int)$ids['GENERAL_GROUP_ID']
305 ];
306 }
307
317 public static function getListAvailablePresets(int $userId): array
318 {
319 $query =
320 OptionGroupTable::query()
321 ->setSelect(['ID', 'NAME'])
322 ->registerRuntimeField(
323 'OPTION_ACCESS',
324 new Reference(
325 'OPTION_ACCESS',
326 OptionAccessTable::class,
327 Join::on('this.ID', 'ref.GROUP_ID'),
328 ['join_type' => Join::TYPE_INNER]
329 )
330 )
331 ->registerRuntimeField(
332 'USER_ACCESS',
333 new Reference(
334 'USER_ACCESS',
335 UserAccessTable::class,
336 Join::on('this.OPTION_ACCESS.ACCESS_CODE', 'ref.ACCESS_CODE'),
337 ['join_type' => Join::TYPE_INNER]
338 )
339 )
340 ->where('USER_ACCESS.USER_ID', $userId)
341 ;
342 $presets = [];
343 foreach ($query->exec() as $row)
344 {
345 $presets[] = [
346 'id' => $row['ID'],
347 'name' => self::getPresetName($row),
348 ];
349 }
350
351 return $presets;
352 }
353
363 public static function createUserPreset(int $userId, array $settings = []): int
364 {
365 $groupId = self::createPersonalGroup($userId);
366
367 if (empty($settings))
368 {
369 return $groupId;
370 }
371
372 Notification::setSettings($groupId, $settings['notify']);
373 General::setSettings($groupId, $settings['general']);
374
375 $bindingPresetToUser = [];
376 if (!empty($settings['notify']))
377 {
378 $bindingPresetToUser['NOTIFY_GROUP_ID'] = $groupId;
379 }
380 if (!empty($settings['general']))
381 {
382 $bindingPresetToUser['GENERAL_GROUP_ID'] = $groupId;
383 }
384
385 if (!empty($bindingPresetToUser))
386 {
387 OptionUserTable::update($userId, $bindingPresetToUser);
388 }
389
390
391 return $groupId;
392 }
393
401 public static function restoreBindings(int $userId): int
402 {
403 $userPreset = OptionGroupTable::query()
404 ->addSelect('ID')
405 ->where('USER_ID', $userId)
406 ->setLimit(1)
407 ->fetch()
408 ;
409
410 $presetId = $userPreset ? (int)$userPreset['ID'] : self::getDefaultPresetId();
411
412 $insertFields = [
413 'USER_ID' => $userId,
414 'GENERAL_GROUP_ID' => $presetId,
415 'NOTIFY_GROUP_ID' => $presetId
416 ];
417 $updateFields = [
418 'GENERAL_GROUP_ID' => $presetId,
419 'NOTIFY_GROUP_ID' => $presetId,
420 ];
421
422 OptionUserTable::merge($insertFields, $updateFields);
423
424 return $presetId;
425 }
426
445 public static function createSharedPreset(
446 array $accessCodes,
447 string $presetName,
448 int $creatorId,
449 array $settings = [],
450 int $sort = self::DEFAULT_SORT,
451 bool $force = false
452 ): ?int
453 {
454 if ($sort >= self::USER_PRESET_SORT)
455 {
456 return null;
457 }
458
459 $newGroupId = self::createSharedGroup($presetName, $accessCodes, $creatorId, $sort);
460
461 if (empty($settings))
462 {
463 return $newGroupId;
464 }
465
466 Notification::setSettings($newGroupId, $settings['notify']);
467 General::setSettings($newGroupId, $settings['general']);
468
469 $rowCandidates =
470 UserAccessTable::query()
471 ->addSelect('USER_ID')
472 ->registerRuntimeField(
473 'OPTION_USER_TABLE',
474 new Reference(
475 'OPTION_USER_TABLE',
476 OptionUserTable::class,
477 Join::on('this.USER_ID', 'ref.USER_ID'),
478 ['join_type' => Join::TYPE_INNER]
479 )
480 )
481 ->whereIn('ACCESS_CODE', $accessCodes)
482 ;
483 $candidates = [];
484 foreach ($rowCandidates->exec() as $rowCandidate)
485 {
486 $candidates[] = $rowCandidate['USER_ID'];
487 }
488
489 if ($force)
490 {
491 OptionUserTable::updateMulti(
492 $candidates,
493 [
494 'NOTIFY_GROUP_ID' => $newGroupId,
495 'GENERAL_GROUP_ID' => $newGroupId
496 ],
497 true
498 );
499
500 return $newGroupId;
501 }
502 //the priority of the group must be taken into account
503 self::updateGroupForUsers($newGroupId, $candidates, $sort, self::NOTIFY_GROUP);
504 self::updateGroupForUsers($newGroupId, $candidates, $sort, self::GENERAL_GROUP);
505 self::cleanUsersCache($candidates);
506
507 return $newGroupId;
508 }
509
515 public static function updateNameSharedPreset(int $presetId, int $modifyId, string $newName): void
516 {
517 OptionGroupTable::update(
518 $presetId,
519 [
520 'NAME' => $newName,
521 'MODIFY_BY_ID' => $modifyId
522 ]
523 );
524
525 $query =
526 OptionUserTable::query()
527 ->addSelect('USER_ID')
528 ->where(\Bitrix\Main\ORM\Query\Query::filter()
529 ->logic('or')
530 ->where('GENERAL_GROUP_ID', $presetId)
531 ->where('NOTIFY_GROUP_ID', $presetId)
532 )
533 ;
534 $usersId = [];
535 foreach($query->exec() as $row)
536 {
537 $usersId[] = (int)$row['USER_ID'];
538 }
539
540 self::cleanUsersCache($usersId);
541 }
542
550 public static function updatePresetSettings(int $presetId, int $modifyId, array $settings): void
551 {
552 Notification::updateGroupSettings($presetId, $settings['notify']);
553 General::updateGroupSettings($presetId, $settings['general']);
554
555 $query =
556 OptionUserTable::query()
557 ->addSelect('USER_ID')
558 ->where(\Bitrix\Main\ORM\Query\Query::filter()
559 ->logic('or')
560 ->where('GENERAL_GROUP_ID', $presetId)
561 ->where('NOTIFY_GROUP_ID', $presetId)
562 )
563 ;
564 $usersId = [];
565 foreach($query->exec() as $row)
566 {
567 $usersId[] = (int)$row['USER_ID'];
568 }
569
570 self::cleanUsersCache($usersId);
571
572 OptionGroupTable::update(
573 $presetId,
574 [
575 'MODIFY_BY_ID' => $modifyId
576 ]
577 );
578 }
579
585 public static function deletePreset(int $presetId): bool
586 {
587 if ($presetId === self::getDefaultPresetId())
588 {
589 return false;
590 }
591
592 self::replaceGroupForUsers($presetId, self::NOTIFY_GROUP);
593 self::replaceGroupForUsers($presetId, self::GENERAL_GROUP);
594
595 self::deleteGroup($presetId);
596
597 return true;
598 }
599
607 public static function setExistingPresetToUsers(int $presetId, array $userList, bool $force = false): void
608 {
609 //the priority of the group must be taken into account
610 if (!$force)
611 {
612 $sort =
613 OptionGroupTable::query()
614 ->addSelect('SORT')
615 ->where('ID', $presetId)
616 ->fetch()['SORT'];
617
618 $query =
619 OptionUserTable::query()
620 ->addSelect('USER_ID')
621 ->registerRuntimeField(
622 'OPTION_GROUP',
623 new Reference(
624 'OPTION_GROUP',
625 OptionGroupTable::class,
626 Join::on('this.GROUP_ID', 'ref.ID'),
627 ['join_type' => Join::TYPE_INNER]
628 )
629 )
630 ->whereIn('USER_ID', $userList)
631 ->where('OPTION_GROUP.SORT', '>=', (int)$sort)
632 ;
633
634 $users = [];
635 foreach ($query->exec() as $user)
636 {
637 $users = $user['USER_ID'];
638 }
639 $userList = $users;
640 }
641
642 OptionUserTable::updateMulti(
643 $userList,
644 [
645 'NOTIFY_GROUP_ID' => $presetId,
646 'GENERAL_GROUP_ID' => $presetId
647 ],
648 true
649 );
650
651 self::cleanUsersCache($userList);
652 }
653
659 public static function chooseExistingPreset(int $presetId, int $userId): void
660 {
661 OptionUserTable::update(
662 $userId,
663 [
664 'NOTIFY_GROUP_ID' => $presetId,
665 'GENERAL_GROUP_ID' => $presetId
666 ]
667 );
668
669 CacheManager::getUserCache($userId)->clearCache();
670 }
671
677 private static function replaceGroupForUsers(int $groupId, string $groupType): void
678 {
679 $rowUsers =
680 OptionUserTable::query()
681 ->addSelect('USER_ID')
682 ;
683
684 if ($groupType === self::NOTIFY_GROUP)
685 {
686 $rowUsers->where('NOTIFY_GROUP_ID', $groupId);
687 }
688 elseif ($groupType === self::GENERAL_GROUP)
689 {
690 $rowUsers->where('GENERAL_GROUP_ID', $groupId);
691 }
692
693 $usersId = [];
694 foreach ($rowUsers->exec() as $user)
695 {
696 $usersId[] = (int)$user['USER_ID'];
697 self::replaceGroupForUser((int)$user['USER_ID'], $groupId, $groupType);
698 }
699
700 self::cleanUsersCache($usersId);
701 }
702
703
710 private static function replaceGroupForUser(int $userId, int $groupId, string $groupType): void
711 {
712 $query =
713 OptionGroupTable::query()
714 ->addSelect('ID')
715 ->registerRuntimeField(
716 'OPTION_ACCESS',
717 new Reference(
718 'OPTION_ACCESS',
719 OptionAccessTable::class,
720 Join::on('this.ID', 'ref.GROUP_ID'),
721 ['join_type' => Join::TYPE_INNER]
722 )
723 )
724 ->registerRuntimeField(
725 'USER_ACCESS',
726 new Reference(
727 'USER_ACCESS',
728 UserAccessTable::class,
729 Join::on('this.OPTION_ACCESS.ACCESS_CODE', 'ref.ACCESS_CODE'),
730 ['join_type' => Join::TYPE_INNER]
731 )
732 )
733 ->registerRuntimeField(
734 'OPTION_USER',
735 new Reference(
736 'OPTION_USER',
737 OptionUserTable::class,
738 Join::on('this.USER_ACCESS.USER_ID', 'ref.USER_ID'),
739 ['join_type' => Join::TYPE_INNER]
740 )
741 )
742 ->registerRuntimeField(
743 'OPTION_STATE',
744 new Reference(
745 'OPTION_STATE',
746 OptionStateTable::class,
747 Join::on('this.ID', 'ref.GROUP_ID'),
748 ['join_type' => Join::TYPE_INNER]
749 )
750 )
751 ->where('OPTION_USER.USER_ID', $userId)
752 ->where('ID', '!=', $groupId)
753 ->where(Query::expr()->count('OPTION_STATE.NAME'), '>', 0)
754 ->setOrder(['SORT' => 'DESC', 'ID' => 'DESC'])
755 ->setLimit(1)
756 ;
757 $replacedGroup = $query->fetch()['ID'];
758
759 if ($groupType === self::NOTIFY_GROUP)
760 {
761 OptionUserTable::update($userId, ['NOTIFY_GROUP_ID' => $replacedGroup]);
762 }
763 elseif ($groupType === self::GENERAL_GROUP)
764 {
765 OptionUserTable::update($userId, ['GENERAL_GROUP_ID' => $replacedGroup]);
766 }
767 }
768
774 protected static function deleteGroup(int $groupId): void
775 {
776 $connection = Application::getConnection();
777
778 $connection->query(
779 "DELETE FROM b_im_option_state WHERE GROUP_ID = $groupId"
780 );
781
782 $connection->query(
783 "DELETE FROM b_im_option_access WHERE GROUP_ID = $groupId"
784 );
785
786 $connection->query(
787 "DELETE FROM b_im_option_group WHERE ID = $groupId"
788 );
789 }
790
798 protected static function createSharedGroup(
799 string $name,
800 array $accessCodes,
801 int $creator,
802 int $sort = self::DEFAULT_SORT
803 ): int
804 {
805 $newGroupId =
806 OptionGroupTable::add([
807 'NAME' => $name,
808 'SORT' => $sort,
809 'CREATE_BY_ID' => $creator
810 ])->getId()
811 ;
812
813 $rows = [];
814 foreach ($accessCodes as $accessCode)
815 {
816 $rows[] = [
817 'GROUP_ID' => $newGroupId,
818 'ACCESS_CODE' => $accessCode
819 ];
820 }
821 OptionAccessTable::addMulti($rows, true);
822
823 return $newGroupId;
824 }
825
834 protected static function createPersonalGroup(int $creator)
835 {
836 $userAccessCode =
837 UserAccessTable::query()
838 ->addSelect('ACCESS_CODE')
839 ->where('USER_ID', $creator)
840 ->whereLike('ACCESS_CODE', 'U%')
841 ->fetch()['ACCESS_CODE']
842 ;
843
844 $newGroupId =
845 OptionGroupTable::add([
846 'USER_ID' => $creator,
847 'SORT' => self::USER_PRESET_SORT,
848 'CREATE_BY_ID' => $creator
849 ])->getId()
850 ;
851 OptionAccessTable::add([
852 'GROUP_ID' => $newGroupId,
853 'ACCESS_CODE' => $userAccessCode
854 ]);
855
856 return $newGroupId;
857 }
858
864 private static function updateGroupForUsers(int $groupId, array $candidates, int $sort, string $groupType): void
865 {
866 $join = new ConditionTree();
867
868 if ($groupType === self::GENERAL_GROUP)
869 {
870 $join = Join::on('this.GENERAL_GROUP_ID', 'ref.ID');
871 }
872 elseif ($groupType === self::NOTIFY_GROUP)
873 {
874 $join = Join::on('this.NOTIFY_GROUP_ID', 'ref.ID');
875 }
876
877 $query =
878 OptionUserTable::query()
879 ->addSelect('USER_ID')
880 ->registerRuntimeField(
881 'OPTION_GROUP',
882 new Reference(
883 'OPTION_GROUP',
884 OptionGroupTable::class,
885 $join,
886 ['join_type' => Join::TYPE_INNER]
887 )
888 )
889 ->whereIn('USER_ID', $candidates)
890 ->where('OPTION_GROUP.SORT', '<=', $sort)
891 ;
892
893 $users = [];
894 foreach ($query->exec() as $row)
895 {
896 $users[] = $row["USER_ID"];
897 }
898
899
900 if ($groupType === self::GENERAL_GROUP)
901 {
902 OptionUserTable::updateMulti($users, ['GENERAL_GROUP_ID' => $groupId]);
903 }
904 elseif ($groupType === self::NOTIFY_GROUP)
905 {
906 OptionUserTable::updateMulti($users, ['NOTIFY_GROUP_ID' => $groupId]);
907 }
908 }
909
910 private static function getPresetName($preset): string
911 {
912 switch ($preset['NAME'])
913 {
914 case '':
915 return Loc::getMessage("IM_CONFIGURATION_PERSONAL_PRESET_NAME");
916 case 'default':
917 return Loc::getMessage("IM_CONFIGURATION_DEFAULT_PRESET_NAME");
918 default:
919 return $preset['NAME'];
920 }
921 }
922
923
924 public static function getUserPresetFromCache(int $userId): array
925 {
926 $result = [];
927 $userCache = CacheManager::getUserCache($userId);
928 $currentUserPresets = $userCache->getValue();
929
930 if (isset($currentUserPresets['notifyPreset']))
931 {
932 $notifyPresetCache = CacheManager::getPresetCache($currentUserPresets['notifyPreset']);
933 $notifyPreset = $notifyPresetCache->getValue();
934 if (!empty($notifyPreset))
935 {
936 $result['notify'] = [
937 'id' => $notifyPreset['id'],
938 'name' => $notifyPreset['name'],
939 'sort' => $notifyPreset['sort'],
940 'settings' => $notifyPreset['notify']
941 ];
942 }
943 }
944
945 if (isset($currentUserPresets['generalPreset']))
946 {
947 $generalPresetCache = CacheManager::getPresetCache($currentUserPresets['generalPreset']);
948 $generalPreset = $generalPresetCache->getValue();
949 if (!empty($generalPreset))
950 {
951 $result['general'] = [
952 'id' => $generalPreset['id'],
953 'name' => $generalPreset['name'],
954 'sort' => $generalPreset['sort'],
955 'settings' => $generalPreset['general']
956 ];
957 }
958 }
959
960 return $result;
961 }
962
963 private static function setUserPresetInCache(int $userId, array $preset): void
964 {
965 CacheManager::getUserCache($userId)->clearCache();
966 CacheManager::getPresetCache($preset['general']['id'])->clearCache();
967 CacheManager::getPresetCache($preset['notify']['id'])->clearCache();
968
969 CacheManager::getUserCache($userId)->setValue([
970 CacheManager::GENERAL_PRESET => $preset['general']['id'],
971 CacheManager::NOTIFY_PRESET => $preset['notify']['id'],
972 ]);
973
974 if ($preset['general']['id'] === $preset['notify']['id'])
975 {
976 CacheManager::getPresetCache($preset['general']['id'])->setValue([
977 'id' => $preset['general']['id'],
978 'name' => $preset['general']['name'],
979 'sort' => $preset['general']['sort'],
980 'general' => $preset['general']['settings'],
981 'notify' => $preset['notify']['settings'],
982 ]);
983
984 return;
985 }
986
987 CacheManager::getPresetCache($preset['general']['id'])->setValue([
988 'id' => $preset['general']['id'],
989 'name' => $preset['general']['name'],
990 'sort' => $preset['general']['sort'],
991 'general' => $preset['general']['settings'],
992 ]);
993
994 CacheManager::getPresetCache($preset['notify']['id'])->setValue([
995 'id' => $preset['notify']['id'],
996 'name' => $preset['notify']['name'],
997 'sort' => $preset['notify']['sort'],
998 'notify' => $preset['notify']['settings'],
999 ]);
1000 }
1001
1008 public static function cleanUsersCache(array $usersId): void
1009 {
1010 $cache = Cache::createInstance();
1011 foreach ($usersId as $userId)
1012 {
1013 $cacheName = self::CACHE_NAME."_$userId";
1014 $cache->clean($cacheName, self::CACHE_DIR);
1015 }
1016 }
1017
1024 public static function cleanUserCache(int $userId): void
1025 {
1026 $cache = Cache::createInstance();
1027 $cacheName = self::CACHE_NAME."_$userId";
1028 $cache->clean($cacheName, self::CACHE_DIR);
1029 }
1030
1036 public static function cleanAllCache(): void
1037 {
1038 $cache = Cache::createInstance();
1039 $cache->cleanDir(self::CACHE_DIR);
1040 }
1041
1042}
static chooseExistingPreset(int $presetId, int $userId)
static setExistingPresetToUsers(int $presetId, array $userList, bool $force=false)
static createUserPreset(int $userId, array $settings=[])
static createSharedGroup(string $name, array $accessCodes, int $creator, int $sort=self::DEFAULT_SORT)
static updateNameSharedPreset(int $presetId, int $modifyId, string $newName)
static updatePresetSettings(int $presetId, int $modifyId, array $settings)
static createSharedPreset(array $accessCodes, string $presetName, int $creatorId, array $settings=[], int $sort=self::DEFAULT_SORT, bool $force=false)
static updateGroupSettings(int $groupId, array $settings)
Definition General.php:445
static setSettings(int $groupId, array $settings=[], bool $forInitialize=false)
Definition General.php:149
static getGroupSettings(int $groupId)
Definition General.php:410
static updateGroupSettings(int $groupId, array $settings)
static setSettings(int $groupId, array $settings=[], bool $forInitialize=false)
static getSimpleNotifySettings(array $generalSettings)
static getConnection($name="")
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29