Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productpropertybase.php
1<?php
2
4
5
12
13abstract class ProductPropertyBase extends Controller
14{
18 protected function getCatalogIds(): array
19 {
20 static $catalogIds = null;
21
22 if (is_null($catalogIds))
23 {
24 $catalogIds = array_column(CatalogIblockTable::getList(['select' => ['IBLOCK_ID']])->fetchAll(), 'IBLOCK_ID');
25 Collection::normalizeArrayValuesByInt($catalogIds);
26 }
27
28 return $catalogIds;
29 }
30
35 protected function isIblockCatalog(int $iblockId): bool
36 {
37 return in_array($iblockId, $this->getCatalogIds(), true);
38 }
39
44 protected function checkIblockModifyPermission(int $iblockId): Result
45 {
46 $result = new Result();
47
48 if (!\CIBlockRights::UserHasRightTo($iblockId, $iblockId, self::IBLOCK_EDIT))
49 {
50 $result->addError(new Error('Access Denied'));
51 }
52
53 return $result;
54 }
55
60 protected function checkProperty(int $propertyId): Result
61 {
62 $result = new Result();
63 $property = $this->getPropertyById($propertyId);
64 if (!$property)
65 {
66 $result->addError(new Error('The specified property does not exist'));
67 return $result;
68 }
69
70 if (!$this->isIblockCatalog((int)$property['IBLOCK_ID']))
71 {
72 $result->addError(new Error('The specified property does not belong to a product catalog'));
73 return $result;
74 }
75
76 return $result;
77 }
78
83 protected function checkFieldsBeforeModify(array $fields): Result
84 {
85 $result = new Result();
86
87 $newPropertyId = (int)$fields['PROPERTY_ID'];
88 $checkPropertyResult = $this->checkProperty($newPropertyId);
89 if (!$checkPropertyResult->isSuccess())
90 {
91 $result->addErrors($checkPropertyResult->getErrors());
92 return $result;
93 }
94
95 $newProperty = $this->getPropertyById($newPropertyId);
96 $iblockPermissionsCheckResult = $this->checkIblockModifyPermission($newProperty['IBLOCK_ID']);
97 if (!$iblockPermissionsCheckResult->isSuccess())
98 {
99 $result->addErrors($iblockPermissionsCheckResult->getErrors());
100 return $result;
101 }
102
103 return $result;
104 }
105
109 protected function checkReadPermissionEntity()
110 {
111 $r = new Result();
112
113 if (!($this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)))
114 {
115 $r->addError(new Error('Access Denied'));
116 }
117
118 return $r;
119 }
120
124 protected function checkModifyPermissionEntity()
125 {
126 return $this->checkReadPermissionEntity();
127 }
128
133 protected function getPropertyById(int $id)
134 {
135 static $map = [];
136
137 if (!isset($map[$id]))
138 {
139 $map[$id] = PropertyTable::getById($id)->fetch();
140 }
141
142 return $map[$id];
143 }
144}
static getList(array $parameters=array())