Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
highloadblock.php
1<?php
2
4
5abstract class Highloadblock extends Base
6{
7 private static array $dictionary = [];
8
9 private static array $reverseDictionary = [];
10
11 public static function clearCache(): void
12 {
13 parent::clearCache();
14
15 $className = get_called_class();
16 if (isset(self::$dictionary[$className]))
17 {
18 unset(self::$dictionary[$className]);
19 }
20 if (isset(self::$reverseDictionary[$className]))
21 {
22 unset(self::$reverseDictionary[$className]);
23 }
24 unset($className);
25 }
26
27 protected static function getXmlIdListById(int $hlblockId, array $idList): array
28 {
29 $className = get_called_class();
30 if (!isset(self::$dictionary[$className]))
31 {
32 self::$dictionary[$className] = [];
33 }
34
35 $result = [];
36
37 $needList = [];
38 foreach ($idList as $id)
39 {
40 if (isset(self::$dictionary[$className][$id]))
41 {
42 if (self::$dictionary[$className][$id] !== false)
43 {
44 $result[$id] = self::$dictionary[$className][$id];
45 }
46 }
47 else
48 {
49 $needList[] = $id;
50 }
51 }
52 unset($id);
53
54 if (!empty($needList))
55 {
56 $list = Type\HighloadBlock::getXmlIdById($hlblockId, $needList);
57 foreach ($needList as $id)
58 {
59 self::$dictionary[$className][$id] = $list[$id] ?? false;
60 if (self::$dictionary[$className][$id] !== false)
61 {
62 $result[$id] = self::$dictionary[$className][$id];
63 }
64 }
65 unset($id, $list);
66 }
67 unset($needList);
68 unset($className);
69
70 return $result;
71 }
72
73 protected static function getXmlIdById(int $hlblockId, int $id): ?string
74 {
75 $list = static::getXmlIdListById($hlblockId, [$id]);
76
77 return $list[$id] ?? null;
78 }
79
80 protected static function getIdListByXmlId(int $hlblockId, array $xmlIdList): array
81 {
82 $className = get_called_class();
83 if (!isset(self::$reverseDictionary[$className]))
84 {
85 self::$reverseDictionary[$className] = [];
86 }
87
88 $result = [];
89
90 $needList = [];
91 foreach ($xmlIdList as $xmlId)
92 {
93 if (isset(self::$reverseDictionary[$className][$xmlId]))
94 {
95 if (self::$reverseDictionary[$className][$xmlId] !== false)
96 {
97 $result[$xmlId] = self::$reverseDictionary[$className][$xmlId];
98 }
99 }
100 else
101 {
102 $needList[] = $xmlId;
103 }
104 }
105 unset($id);
106
107 if (!empty($needList))
108 {
109 $list = Type\HighloadBlock::getIdByXmlId($hlblockId, $needList);
110 foreach ($needList as $xmlId)
111 {
112 self::$reverseDictionary[$className][$xmlId] = $list[$xmlId] ?? false;
113 if (self::$reverseDictionary[$className][$xmlId] !== false)
114 {
115 $result[$xmlId] = self::$reverseDictionary[$className][$xmlId];
116 }
117 }
118 unset($xmlId);
119 }
120 unset($needList);
121 unset($className);
122
123 return $result;
124 }
125
126 protected static function getIdByXmlId(int $hlblockId, string $xmlId): ?int
127 {
128 $list = static::getIdListByXmlId($hlblockId, [$xmlId]);
129
130 return $list[$xmlId] ?? null;
131 }
132}
static getXmlIdById(int $hlblockId, int $id)
static getIdByXmlId(int $hlblockId, string $xmlId)
static getIdListByXmlId(int $hlblockId, array $xmlIdList)
static getXmlIdListById(int $hlblockId, array $idList)