Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tradebindingrestriction.php
1<?php
3
9
10Loc::loadMessages(__FILE__);
11
17{
21 public static function getClassTitle()
22 {
23 return Loc::getMessage('SALE_SRV_RSTR_BY_TRADE_BINDING_NAME');
24 }
25
29 public static function getClassDescription()
30 {
31 return Loc::getMessage('SALE_SRV_RSTR_BY_TRADE_BINDING_DESC');
32 }
33
34 public static function getOnApplyErrorMessage(): string
35 {
36 return Loc::getMessage('SALE_SRV_RSTR_BY_TRADE_BINDING_ON_APPLY_ERROR_MSG');
37 }
38
48 public static function getParamsStructure($entityId = 0)
49 {
50 $result = array(
51 "TRADE_BINDING" => array(
52 "TYPE" => "ENUM",
53 'MULTIPLE' => 'Y',
54 "LABEL" => Loc::getMessage("SALE_SRV_RSTR_BY_TRADE_BINDING_LIST"),
55 "OPTIONS" => self::getTradePlatformList()
56 )
57 );
58
59 return $result;
60 }
61
70 protected static function getTradePlatformList()
71 {
72 Loader::includeModule('crm');
73
74 $result = [];
75
76 $dbRes = Sale\TradingPlatformTable::getList([
77 'select' => ['CODE', 'CLASS'],
78 'filter' => ['=ACTIVE' => 'Y'],
79 'cache' => ['ttl' => 36000]
80 ]);
81 while ($data = $dbRes->fetch())
82 {
83 $platformClassName = (string)$data['CLASS'];
84 if (class_exists($platformClassName))
85 {
87 $platform = $platformClassName::getInstanceByCode($data['CODE']);
88 if ($platform instanceof Sale\TradingPlatform\IRestriction)
89 {
90 $result[$platform->getId()] = $platform->getRealName();
91 }
92 }
93 }
94
95 return $result;
96 }
97
107 protected static function extractParams(Sale\Internals\Entity $entity)
108 {
109 $result = [];
110
112 $order = static::getOrder($entity);
113
114 if ($order === null)
115 {
116 return $result;
117 }
118
119 $collection = $order->getTradeBindingCollection();
120
122 foreach ($collection as $entity)
123 {
124 $tradeBinding = $entity->getTradePlatform();
125 if (
126 $tradeBinding
127 && !in_array($tradeBinding->getId(), $result)
128 )
129 {
130 $result[] = $tradeBinding->getId();
131 }
132 }
133
134 return $result;
135 }
136
141 protected static function getOrder(Sale\Internals\Entity $entity)
142 {
143 throw new NotImplementedException('Method '.__METHOD__.' must be overload');
144 }
145
152 public static function check($params, array $restrictionParams, $serviceId = 0)
153 {
154 if (is_array($restrictionParams) && isset($restrictionParams['TRADE_BINDING']))
155 {
156 $diff = array_diff($params, $restrictionParams['TRADE_BINDING']);
157 return empty($diff);
158 }
159
160 return true;
161 }
162
171 public static function isAvailable()
172 {
173 return (bool)static::getTradePlatformList();
174 }
175
176}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static extractParams(Entity $entity)
static check($params, array $restrictionParams, $serviceId=0)