Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PermissionDictionary.php
1<?php
10
12use Bitrix\Crm\Service\Container;
13use Bitrix\Crm\Category\DealCategory;
19
21{
22 public const VALUE_VARIATION_ALL = -1;
23
25 public const CATALOG_STORE_MODIFY = 2;
26 public const CATALOG_STORE_VIEW = 3;
28
29 public const CATALOG_RESERVE_DEAL = 101;
30 public const CATALOG_STORE_RESERVE = 102;
31
32 public const CATALOG_STORE_DOCUMENT = 200;
33 public const CATALOG_STORE_DOCUMENT_VIEW = 201;
39
40 public const CATALOG_SETTINGS_ACCESS = 301;
41 public const CATALOG_SETTINGS_EDIT_RIGHTS = 302;
46 public const CATALOG_RESERVE_SETTINGS = 307;
47 public const CATALOG_VAT_MODIFY = 308;
48 public const CATALOG_MEASURE_MODIFY = 309;
49 public const CATALOG_PRICE_GROUP_MODIFY = 310;
50 public const CATALOG_IMPORT_EDIT = 311;
51 public const CATALOG_EXPORT_EDIT = 312;
52
53 public const CATALOG_PRODUCT_VIEW = 400;
54 public const CATALOG_PRODUCT_READ = 401;
55 public const CATALOG_PRODUCT_ADD = 402;
56 public const CATALOG_PRODUCT_EDIT = 403;
57 public const CATALOG_PRODUCT_DELETE = 404;
61 public const CATALOG_PRODUCT_SET_DISCOUNT = 408;
63 public const CATALOG_EXPORT_EXECUTION = 414;
64 public const CATALOG_IMPORT_EXECUTION = 415;
66
68 protected static $stores;
69
71 protected static $dynamicTypes;
72
74 protected static $storeAnalitycs;
75
77 protected static $priceEntities;
78
80 protected static $dealCategories;
81
82 public static function getPermission($permissionId): array
83 {
84 $permission = parent::getPermission($permissionId);
85 $storePermissions = [
88 ];
89
90 $permissionId = (int)$permissionId;
91 if (in_array($permissionId, $storePermissions, true))
92 {
93 $permission['type'] = Permission\PermissionDictionary::TYPE_MULTIVARIABLES;
94 $permission['enableSearch'] = true;
95 $permission['variables'] = self::getStoreVariables();
96 $permission['hintTitle'] = Loc::getMessage('CATALOG_STORE_VIEW_DESCRIPTION_HINT');
97 }
98 elseif ($permissionId === self::CATALOG_RESERVE_DEAL)
99 {
100 $permission['type'] = Permission\PermissionDictionary::TYPE_MULTIVARIABLES;
101 $permission['variables'] = self::getDealCategoryVariables();
102 $permission['showAvatars'] = false;
103 $permission['compactView'] = true;
104 $permission['hintTitle'] = Loc::getMessage('CATALOG_RESERVE_DEAL_DESCRIPTION_HINT');
105 }
106 elseif (
107 $permissionId === self::CATALOG_PRODUCT_EDIT_ENTITY_PRICE
108 || $permissionId === self::CATALOG_PRODUCT_SET_DISCOUNT
109 )
110 {
111 $permission['type'] = Permission\PermissionDictionary::TYPE_MULTIVARIABLES;
112 $permission['variables'] = self::getPriceSelectorVariables();
113 $permission['showAvatars'] = false;
114 $permission['compactView'] = true;
115 }
116 elseif ($permissionId === self::CATALOG_STORE_ANALYTIC_VIEW)
117 {
118 $permission['type'] = Permission\PermissionDictionary::TYPE_MULTIVARIABLES;
119 $permission['variables'] = self::getStoreAnalyticVariables();
120 $permission['showAvatars'] = false;
121 $permission['compactView'] = true;
122 }
123
124 if ($permission['type'] === Permission\PermissionDictionary::TYPE_MULTIVARIABLES)
125 {
126 $permission['allSelectedCode'] = static::VALUE_VARIATION_ALL;
127 }
128
129 return $permission;
130 }
131
132 public static function getDefaultPermissionValue($permissionId): int
133 {
134 $permission = static::getPermission($permissionId);
135 if ($permission['type'] === static::TYPE_MULTIVARIABLES)
136 {
137 return static::VALUE_VARIATION_ALL;
138 }
139
140 return static::VALUE_YES;
141 }
142
143 public static function getStoreDocumentPermissionRules(array $permissions, array $documents = null): array
144 {
145 $result = [];
146
147 if ($documents === null)
148 {
149 $documents = [
156 ];
157 }
158
159 foreach ($documents as $document)
160 {
161 foreach ($permissions as $permissionId)
162 {
163 $result[] = self::getStoreDocumentPermissionId($permissionId, $document);
164 }
165 }
166
167 return $result;
168 }
169
170
171 public static function getStoreDocumentPermission($permissionId, $documentCode): array
172 {
173 $permission = self::getPermission($permissionId);
174 $permission['id'] = self::getStoreDocumentPermissionId($permissionId, $documentCode);
175
176 // personal langs
177 $fields = [
178 'title' => self::getName($permissionId) . '_' . $documentCode,
179 'hint' => self::HINT_PREFIX . self::getName($permissionId) . '_' . $documentCode,
180 ];
181 foreach ($fields as $field => $langMessage)
182 {
183 $fieldValue = Loc::getMessage($langMessage);
184 if ($fieldValue)
185 {
186 $permission[$field] = $fieldValue;
187 }
188 }
189
190 return $permission;
191 }
192
193 public static function getStoreDocumentPermissionId($permissionId, $documentCode): string
194 {
195 return "{$permissionId}_{$documentCode}";
196 }
197
198 public static function getStoreVariables(): array
199 {
200 if (static::$stores !== null)
201 {
202 return static::$stores;
203 }
204
205 $items = [];
206 $stores = StoreTable::getList([
207 'select' => ['ID', 'TITLE', 'ADDRESS'],
208 'cache' => [
209 'ttl' => 3600
210 ]
211 ]);
212
213 while ($store = $stores->fetch())
214 {
215 $title = $store['TITLE'];
216 if ($title === '')
217 {
218 $title = $store['ADDRESS'];
219 }
220 $items[] = [
221 'id' => $store['ID'],
222 'title' => htmlspecialcharsbx($title),
223 'entityId' => 'store',
224 ];
225 }
226
227 static::$stores = $items;
228
229 return static::$stores;
230 }
231
232 public static function getDealCategoryVariables(): array
233 {
234 if (static::$dealCategories !== null)
235 {
236 return static::$dealCategories;
237 }
238
239 if (!Loader::includeModule('crm'))
240 {
241 static::$dealCategories = [];
242
243 return static::$dealCategories;
244 }
245
246 $items = [];
247 $dealCategories = DealCategory::getSelectListItems();
248 foreach ($dealCategories as $key => $dealCategory)
249 {
250 $items[] = [
251 'id' => $key,
252 'title' => htmlspecialcharsbx($dealCategory),
253 'avatar' => null,
254 ];
255 }
256
257 static::$dealCategories = $items;
258
259 return static::$dealCategories;
260 }
261
273
274 public static function getPriceSelectorVariables()
275 {
276 if (static::$priceEntities !== null)
277 {
278 return static::$priceEntities;
279 }
280
281 static::$priceEntities = [];
282 if (!Loader::includeModule('crm'))
283 {
284 return static::$priceEntities;
285 }
286
287 $items = [
288 \CCrmOwnerType::Deal => 'deal',
289 \CCrmOwnerType::Lead => 'lead',
290 \CCrmOwnerType::SmartInvoice => 'invoice',
291 \CCrmOwnerType::Quote => 'quote',
292 \CCrmOwnerType::Order => 'order',
293 ];
294
295 foreach ($items as $crmItem => $entityId)
296 {
297 static::$priceEntities[] = [
298 'id' => $crmItem,
299 'title' => \CCrmOwnerType::GetDescription($crmItem),
300 'entityId' => $entityId,
301 ];
302 }
303
304 static::$priceEntities = array_merge(static::$priceEntities, self::getDynamicTypeVariables());
305
306 return static::$priceEntities;
307 }
308
309 private static function getDynamicTypeVariables(): array
310 {
311 if (static::$dynamicTypes !== null)
312 {
313 return static::$dynamicTypes;
314 }
315
316 if (!Loader::includeModule('crm'))
317 {
318 static::$dynamicTypes = [];
319
320 return static::$dynamicTypes;
321 }
322
323 $items = [];
324 $types = Container::getInstance()
325 ->getDynamicTypesMap()
326 ->load()
327 ->getTypes()
328 ;
329
330 foreach ($types as $type)
331 {
332 $items[] = [
333 'id' => $type->getEntityTypeId(),
334 'title' => $type->getTitle(),
335 'supertitle' => Loc::getMessage('CRM_DYNAMIC_TYPE_NAME'),
336 ];
337 }
338
339 static::$dynamicTypes = $items;
340
341 return static::$dynamicTypes;
342 }
343 public static function getStoreAnalyticVariables(): array
344 {
345 if (static::$storeAnalitycs !== null)
346 {
347 return static::$storeAnalitycs;
348 }
349
350 $items = [];
351 if (Loader::includeModule('report'))
352 {
354 foreach ($dashboards as $dashboard)
355 {
356 $items[] = [
357 'id' => $dashboard->getAccessBoardId(),
358 'title' => $dashboard->getBoardTitle(),
359 ];
360 }
361 }
362
363 static::$storeAnalitycs = $items;
364
365 return static::$storeAnalitycs;
366 }
367}
static getStoreDocumentPermissionId($permissionId, $documentCode)
static getStoreDocumentPermissionRules(array $permissions, array $documents=null)
static getStoreDocumentPermission($permissionId, $documentCode)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29