Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
restriction.php
1
<?php
2
namespace
Bitrix\Sale\Services\Base
;
3
4
use
Bitrix\Main\Error
;
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Main\NotImplementedException
;
7
use
Bitrix\Main\Result
;
8
use
Bitrix\Sale\Internals\Entity
;
9
use
Bitrix\Sale\Internals\ServiceRestrictionTable
;
10
16
abstract
class
Restriction
17
{
18
24
public
static
$easeSort
= 100;
25
30
public
static
function
getClassTitle
()
31
{
32
throw
new
NotImplementedException
;
33
}
34
39
public
static
function
getClassDescription
()
40
{
41
throw
new
NotImplementedException
;
42
}
43
49
public
static
function
getOnApplyErrorMessage
(): string
50
{
51
$class = new \ReflectionClass(static::class);
52
53
return
Loc::getMessage
(
'SALE_BASE_RESTRICTION_ON_APPLY_ERROR_MSG'
, [
54
'#RSTR_CLASSNAME#'
=> $class->getName(),
55
]) ??
''
;
56
}
57
69
public
static
function
check
($params, array $restrictionParams, $serviceId = 0)
70
{
71
throw
new
NotImplementedException
;
72
}
73
84
public
static
function
checkByEntity
(
Entity
$entity, array $restrictionParams, $mode, $serviceId = 0)
85
{
86
$severity = static::getSeverity($mode);
87
88
if
($severity == RestrictionManager::SEVERITY_NONE)
89
return
RestrictionManager::SEVERITY_NONE;
90
91
$entityRestrictionParams = static::extractParams($entity);
92
$res = static::check($entityRestrictionParams, $restrictionParams, $serviceId);
93
return
$res ? RestrictionManager::SEVERITY_NONE : $severity;
94
}
95
105
public
static
function
validateRestriction
($fields)
106
{
107
return
new
Result
();
108
}
109
115
protected
static
function
extractParams
(
Entity
$entity)
116
{
117
throw
new
NotImplementedException
;
118
}
119
124
public
static
function
getParamsStructure
($entityId = 0)
125
{
126
return
array();
127
}
128
134
public
static
function
prepareParamsValues
(array $paramsValues, $entityId = 0)
135
{
136
return
$paramsValues;
137
}
138
145
public
static
function
save
(array $fields, $restrictionId = 0)
146
{
147
$fields[
"CLASS_NAME"
] =
'\\'
.get_called_class();
148
149
if
($restrictionId > 0)
150
{
151
$res = ServiceRestrictionTable::update($restrictionId, $fields);
152
}
153
else
154
{
155
$res = ServiceRestrictionTable::add($fields);
156
}
157
158
return
$res;
159
}
160
167
public
static
function
delete
($restrictionId, $entityId = 0)
168
{
169
return
ServiceRestrictionTable::delete($restrictionId);
170
}
171
176
public
static
function
getSeverity
($mode)
177
{
178
$result = RestrictionManager::SEVERITY_STRICT;
179
180
if
($mode == RestrictionManager::MODE_MANAGER)
181
return
RestrictionManager::SEVERITY_SOFT;
182
183
return
$result;
184
}
185
190
public
static
function
prepareData
(array $servicesIds)
191
{
192
return
true
;
193
}
194
198
public
static
function
isAvailable
()
199
{
200
return
true
;
201
}
202
214
public
static
function
getCode
(): string
215
{
216
$class = new \ReflectionClass(static::class);
217
if
(self::isBitrixNamespace($class->getNamespaceName()))
218
{
219
return
$class->getShortName();
220
}
221
222
return
$class->getName();
223
}
224
225
public
static
function
isMyCode
(
string
$code): bool
226
{
227
return
static::getCode() === $code;
228
}
229
230
private
static
function
isBitrixNamespace(
string
$namespace): bool
231
{
232
$vendorName = mb_substr($namespace, 0, 7);
233
234
return
($vendorName ===
'Bitrix'
|| $vendorName ===
'Bitrix\\'
);
235
}
236
237
/*
238
* Children can have also this method
239
* for performance purposes.
240
*
241
* @return int[]
242
* public static function filterServicesArray(Shipment $shipment, array $restrictionFields)
243
* {
244
* ...
245
* }
246
*/
247
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\NotImplementedException
Definition
exception.php:147
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Sale\Internals\ServiceRestrictionTable
Definition
servicerestriction.php:39
Bitrix\Sale\Services\Base\Restriction
Definition
restriction.php:17
Bitrix\Sale\Services\Base\Restriction\extractParams
static extractParams(Entity $entity)
Definition
restriction.php:115
Bitrix\Sale\Services\Base\Restriction\isMyCode
static isMyCode(string $code)
Definition
restriction.php:225
Bitrix\Sale\Services\Base\Restriction\prepareParamsValues
static prepareParamsValues(array $paramsValues, $entityId=0)
Definition
restriction.php:134
Bitrix\Sale\Services\Base\Restriction\checkByEntity
static checkByEntity(Entity $entity, array $restrictionParams, $mode, $serviceId=0)
Definition
restriction.php:84
Bitrix\Sale\Services\Base\Restriction\$easeSort
static $easeSort
Definition
restriction.php:24
Bitrix\Sale\Services\Base\Restriction\getCode
static getCode()
Definition
restriction.php:214
Bitrix\Sale\Services\Base\Restriction\check
static check($params, array $restrictionParams, $serviceId=0)
Definition
restriction.php:69
Bitrix\Sale\Services\Base\Restriction\getClassTitle
static getClassTitle()
Definition
restriction.php:30
Bitrix\Sale\Services\Base\Restriction\isAvailable
static isAvailable()
Definition
restriction.php:198
Bitrix\Sale\Services\Base\Restriction\save
static save(array $fields, $restrictionId=0)
Definition
restriction.php:145
Bitrix\Sale\Services\Base\Restriction\prepareData
static prepareData(array $servicesIds)
Definition
restriction.php:190
Bitrix\Sale\Services\Base\Restriction\getClassDescription
static getClassDescription()
Definition
restriction.php:39
Bitrix\Sale\Services\Base\Restriction\getOnApplyErrorMessage
static getOnApplyErrorMessage()
Definition
restriction.php:49
Bitrix\Sale\Services\Base\Restriction\getParamsStructure
static getParamsStructure($entityId=0)
Definition
restriction.php:124
Bitrix\Sale\Services\Base\Restriction\getSeverity
static getSeverity($mode)
Definition
restriction.php:176
Bitrix\Sale\Services\Base\Restriction\validateRestriction
static validateRestriction($fields)
Definition
restriction.php:105
Bitrix\Sale\Services\Base
Definition
concreteproductrestriction.php:3
modules
sale
lib
services
base
restriction.php
Создано системой
1.10.0