1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
permissiondictionary.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\Access\Permission;
10
11use Bitrix\Main\Localization\Loc;
12
15{
16 public const
19
20 public const DELIMITER = '.';
21
22 public const TYPE_TOGGLER = 'toggler';
23 public const TYPE_VARIABLES = 'variables';
24 public const TYPE_MULTIVARIABLES = 'multivariables';
25 public const TYPE_DEPENDENT_VARIABLES = 'dependent_variables';
26
27 public const HINT_PREFIX = 'HINT_';
28 public const HINT_SUFFIX = '_MSGVER_1';
29
30 protected static $locLoaded = [];
31
38 public static function getType($permissionId): string
39 {
40 return static::TYPE_TOGGLER;
41 }
42
52 public static function getPermission($permissionId): array
53 {
54 $permission = [
55 'id' => $permissionId,
56 'type' => static::TYPE_TOGGLER,
57 'title' => '',
58 'hint' => ''
59 ];
60
61 static::loadLoc();
62 $name = self::getName($permissionId);
63 if (!$name)
64 {
65 return $permission;
66 }
67 $permission['title'] = Loc::getMessage($name) ?? '';
68 $permission['hint'] =
69 Loc::getMessage(self::HINT_PREFIX . $name)
70 ?? (Loc::getMessage(self::HINT_PREFIX . $name . self::HINT_SUFFIX) ?? '');
71
72 return $permission;
73 }
74
75 public static function getTitle($permissionId): string
76 {
77 static::loadLoc();
78 $name = self::getName($permissionId);
79 if (!$name)
80 {
81 return '';
82 }
83 return Loc::getMessage($name) ?? '';
84 }
85
86 public static function getList(): array
87 {
88 $class = new \ReflectionClass(static::class);
89 $permissions = $class->getConstants();
90
91 $res = [];
92 foreach ($permissions as $name => $id)
93 {
94 if (in_array($name, [
95 'VALUE_NO',
96 'VALUE_YES',
97 'DELIMITER',
98 'TYPE_VARIABLES',
99 'TYPE_MULTIVARIABLES',
100 'TYPE_DEPENDENT_VARIABLES',
101 'TYPE_TOGGLER',
102 'HINT_PREFIX'
103 ]))
104 {
105 continue;
106 }
107
108 $res[$id] = [
109 'NAME' => $name,
110 'LEVEL' => static::getLevel($id)
111 ];
112 }
113 return $res;
114 }
115
116 public static function getParentsPath(string $permissionId): ?string
117 {
118 $nodes = explode(static::DELIMITER, $permissionId);
119 $count = count($nodes);
120 if ($count < 2)
121 {
122 return null;
123 }
124 unset($nodes[$count-1]);
125 return implode(static::DELIMITER, $nodes);
126 }
127
128 public static function recursiveValidatePermission(array $permissions, $id)
129 {
130 if (!array_key_exists($id, $permissions))
131 {
132 return false;
133 }
134
135 if ($permissions[$id] == static::VALUE_NO)
136 {
137 return true;
138 }
139
140 $parentPath = static::getParentsPath($id);
141 if (!$parentPath)
142 {
143 return true;
144 }
145
146 if (!array_key_exists($parentPath, $permissions))
147 {
148 return false;
149 }
150
151 if ($permissions[$parentPath] == static::VALUE_NO)
152 {
153 return false;
154 }
155
156 return static::recursiveValidatePermission($permissions, $parentPath);
157 }
158
159 protected static function getLevel($id): int
160 {
161 $value = explode(static::DELIMITER, $id);
162 return count($value) - 1;
163 }
164
165 protected static function loadLoc()
166 {
167 if (!isset(static::$locLoaded[static::class]))
168 {
169 $r = new \ReflectionClass(static::class);
170 Loc::loadMessages($r->getFileName());
171 static::$locLoaded[static::class] = true;
172 }
173 }
174
175 protected static function getName($permissionId): ?string
176 {
177 $permissions = static::getList();
178 if (!array_key_exists($permissionId, $permissions))
179 {
180 return null;
181 }
182 return $permissions[$permissionId]['NAME'];
183 }
184}
$count
Определения admin_tab.php:4
static getParentsPath(string $permissionId)
Определения permissiondictionary.php:116
static recursiveValidatePermission(array $permissions, $id)
Определения permissiondictionary.php:128
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$name
Определения menu_edit.php:35
</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