Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
restriction.php
1<?php
3
10
16abstract class Restriction
17{
18
24 public static $easeSort = 100;
25
30 public static function getClassTitle()
31 {
33 }
34
39 public static function getClassDescription()
40 {
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 {
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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static extractParams(Entity $entity)
static prepareParamsValues(array $paramsValues, $entityId=0)
static checkByEntity(Entity $entity, array $restrictionParams, $mode, $serviceId=0)
static check($params, array $restrictionParams, $serviceId=0)
static save(array $fields, $restrictionId=0)
static prepareData(array $servicesIds)