Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
productpropertybase.php
1
<?php
2
3
namespace
Bitrix\Catalog\Controller
;
4
5
6
use
Bitrix\Catalog\Access\ActionDictionary
;
7
use
Bitrix\Catalog\CatalogIblockTable
;
8
use
Bitrix\Iblock\PropertyTable
;
9
use
Bitrix\Main\Error
;
10
use
Bitrix\Main\Result
;
11
use
Bitrix\Main\Type\Collection
;
12
13
abstract
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
}
Bitrix\Catalog\Access\ActionDictionary
Definition
ActionDictionary.php:17
Bitrix\Catalog\CatalogIblockTable
Definition
catalogiblock.php:41
Bitrix\Catalog\Controller\ProductPropertyBase
Definition
productpropertybase.php:14
Bitrix\Catalog\Controller\ProductPropertyBase\checkModifyPermissionEntity
checkModifyPermissionEntity()
Definition
productpropertybase.php:124
Bitrix\Catalog\Controller\ProductPropertyBase\checkReadPermissionEntity
checkReadPermissionEntity()
Definition
productpropertybase.php:109
Bitrix\Catalog\Controller\ProductPropertyBase\checkIblockModifyPermission
checkIblockModifyPermission(int $iblockId)
Definition
productpropertybase.php:44
Bitrix\Catalog\Controller\ProductPropertyBase\checkProperty
checkProperty(int $propertyId)
Definition
productpropertybase.php:60
Bitrix\Catalog\Controller\ProductPropertyBase\checkFieldsBeforeModify
checkFieldsBeforeModify(array $fields)
Definition
productpropertybase.php:83
Bitrix\Catalog\Controller\ProductPropertyBase\getPropertyById
getPropertyById(int $id)
Definition
productpropertybase.php:133
Bitrix\Catalog\Controller\ProductPropertyBase\isIblockCatalog
isIblockCatalog(int $iblockId)
Definition
productpropertybase.php:35
Bitrix\Catalog\Controller\ProductPropertyBase\getCatalogIds
getCatalogIds()
Definition
productpropertybase.php:18
Bitrix\Iblock\PropertyTable
Definition
propertytable.php:60
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\ORM\Objectify\Collection
Definition
collection.php:33
Bitrix\Catalog\Controller
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
catalog
lib
controller
productpropertybase.php
Создано системой
1.10.0