Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionaccesscontroller.php
1<?php
2
4
11
13{
14 public static array $cache = [];
15
16 private const ITEM_TYPE = 'SECTION';
17 private const USER_TYPE = 'USER';
18
19 protected function loadItem(int $itemId = null): ?AccessibleItem
20 {
21 $key = self::ITEM_TYPE . '_' . $itemId;
22 if (!array_key_exists($key, static::$cache))
23 {
25 $section = (new Section())->getById($itemId);
26
27 $sectionModel = SectionModel::createFromId($itemId);
28 if ($section instanceof \Bitrix\Calendar\Core\Section\Section)
29 {
30 $owner = $section->getOwner();
31 $ownerId = $owner ? $owner->getId() : 0;
32 $sectionModel
33 ->setType($section->getType())
34 ->setOwnerId($ownerId)
35 ;
36 }
37
38 static::$cache[$key] = $sectionModel;
39 }
40
41 return static::$cache[$key];
42 }
43
44 protected function loadUser(int $userId): AccessibleUser
45 {
46 $key = self::USER_TYPE . '_' . $userId;
47 if (!array_key_exists($key, static::$cache))
48 {
49 static::$cache[$key] = UserModel::createFromId($userId);
50 }
51
52 return static::$cache[$key];
53 }
54}