1C-Bitrix 25.700.0
productpropertybase.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\Access\ActionDictionary;
6use Bitrix\Catalog\CatalogIblockTable;
7use Bitrix\Iblock\PropertyTable;
8use Bitrix\Main\Error;
9use Bitrix\Main\Result;
10
11abstract class ProductPropertyBase extends Controller
12{
16 protected function getCatalogIds(): array
17 {
18 $catalogIds = [];
20 'select' => [
21 'IBLOCK_ID'
22 ],
23 'cache' => [
24 'ttl' => 86400,
25 ],
26 ]);
27 while ($row = $iterator->fetch())
28 {
29 $catalogIds[] = (int)$row['IBLOCK_ID'];
30 }
31 unset($row, $iterator);
32
33 return $catalogIds;
34 }
35
40 protected function isIblockCatalog(int $iblockId): bool
41 {
42 return in_array($iblockId, $this->getCatalogIds(), true);
43 }
44
50 {
51 $result = new Result();
52
53 if (!\CIBlockRights::UserHasRightTo($iblockId, $iblockId, self::IBLOCK_EDIT))
54 {
55 $result->addError(new Error('Access Denied'));
56 }
57
58 return $result;
59 }
60
65 protected function checkProperty(int $propertyId): Result
66 {
67 $result = new Result();
68 $property = $this->getPropertyById($propertyId);
69 if (!$property)
70 {
71 $result->addError($this->getErrorEntityNotExists());
72
73 return $result;
74 }
75
76 if (!$this->isIblockCatalog((int)$property['IBLOCK_ID']))
77 {
79
80 return $result;
81 }
82
83 return $result;
84 }
85
91 {
92 $result = new Result();
93
94 $newPropertyId = (int)$fields['PROPERTY_ID'];
95 $checkPropertyResult = $this->checkProperty($newPropertyId);
96 if (!$checkPropertyResult->isSuccess())
97 {
98 $result->addErrors($checkPropertyResult->getErrors());
99
100 return $result;
101 }
102
103 $newProperty = $this->getPropertyById($newPropertyId);
104 if (!$newProperty)
105 {
106 $result->addError($this->getErrorEntityNotExists());
107
108 return $result;
109 }
110
111 $iblockPermissionsCheckResult = $this->checkIblockModifyPermission($newProperty['IBLOCK_ID']);
112 if (!$iblockPermissionsCheckResult->isSuccess())
113 {
114 $result->addErrors($iblockPermissionsCheckResult->getErrors());
115
116 return $result;
117 }
118
119 return $result;
120 }
121
125 protected function checkReadPermissionEntity()
126 {
127 $result = new Result();
128
129 if (!($this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)))
130 {
131 $result->addError(new Error('Access Denied'));
132 }
133
134 return $result;
135 }
136
140 protected function checkModifyPermissionEntity()
141 {
142 return $this->checkReadPermissionEntity();
143 }
144
149 protected function getPropertyById(int $id): ?array
150 {
151 if ($id <= 0)
152 {
153 return null;
154 }
155
156 return PropertyTable::getRow([
157 'select' => ['*'],
158 'filter' => [
159 '=ID' => $id,
160 ],
161 'cache' => [
162 'ttl' => 86400,
163 ],
164 ]);
165 }
166
168 {
169 return new Error('The specified property does not belong to a product catalog');
170 }
171
172 protected function getErrorPropertyInvalidType(): Error
173 {
174 return new Error('Invalid property type specified');
175 }
176
178 {
179 return new Error('Invalid property field values');
180 }
181}
Определения error.php:15
static getList(array $parameters=array())
Определения datamanager.php:431
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501