Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
8
9abstract class Base
10{
11 protected $id;
12 protected $code;
13 protected $name = '';
14 protected $description = '';
15 protected $className = __CLASS__;
16 protected $params = array();
17 protected $rights = array (
18 Manager::RIGHTS_ADMIN_IDX => 'N',
19 Manager::RIGHTS_MANAGER_IDX => 'N',
20 Manager::RIGHTS_CLIENT_IDX => 'N'
21 );
22 protected $deliveryId = 0;
23 protected $initial = '';
24 protected $active = false;
25 protected $sort = 100;
26 protected $value = null;
27 protected $currency = '';
28 protected $operatingCurrency = '';
29
30 abstract public static function getClassTitle();
31
32 public function __construct($id, array $initParams, $currency, $value = null, array $additionalParams = array())
33 {
34 if ($id == '')
35 {
36 throw new ArgumentNullException('id');
37 }
38
39 $initParams['CODE'] ??= '';
40 $initParams['NAME'] ??= '';
41 $initParams['DESCRIPTION'] ??= null;
42 $initParams['PARAMS'] ??= [];
43 if (!is_array($initParams['PARAMS']))
44 {
45 $initParams['PARAMS'] = [];
46 }
47 $initParams['DELIVERY_ID'] ??= null;
48 $initParams['INIT_VALUE'] ??= null;
49 $initParams['ACTIVE'] = (string)($initParams['ACTIVE'] ?? 'N');
50 $initParams['SORT'] ??= null;
51
52 $this->id = $id;
53 $this->code = $initParams['CODE'];
54 $this->name = $initParams['NAME'];
55 $this->description = $initParams['DESCRIPTION'];
56 $this->className = $initParams['CLASS_NAME'];
57 $this->params = $initParams['PARAMS'];
58 $this->rights = $initParams['RIGHTS'];
59 $this->deliveryId = $initParams['DELIVERY_ID'];
60 $this->initial = $initParams['INIT_VALUE'];
61 $this->active = $initParams['ACTIVE'];
62 $this->sort = $initParams['SORT'];
63
64 $this->currency = $currency;
65 $this->operatingCurrency = $currency;
66
67 if ($value !== null)
68 {
69 $this->setValue($value);
70 }
71 elseif ($this->initial !== null)
72 {
73 $this->setValue($this->initial);
74 }
75 }
76
77 public function setValue($value)
78 {
79 $this->value = $value;
80 }
81
82 public function getName()
83 {
84 return $this->name;
85 }
86
87 public function getDescription()
88 {
89 return $this->description;
90 }
91
92 public function getValue()
93 {
94 return $this->value;
95 }
96
97 public function getEditControl($prefix = '', $value = false)
98 {
99 if($prefix <> '')
100 $name = $prefix;
101 else
102 $name = $this->id;
103
104 if(!$value)
105 $value = $this->value;
106
107 return Input\Manager::getEditHtml($name, $this->params, $value);
108 }
109
110 public function getViewControl()
111 {
112 return Input\Manager::getViewHtml($this->params, $this->value);
113 }
114
121 public function getPrice()
122 {
123 $result = false;
124
125 if(isset($this->params['PRICE']))
126 $result = $this->convertToOperatingCurrency($this->params['PRICE']);
127
128 return $result;
129 }
130
131 protected function convertToOtherCurrency($value, $currency)
132 {
133 $result = floatval($value);
134
135 if($result <= 0)
136 return $value;
137
138 if($this->currency == '' || $currency == '')
139 return $value;
140
141 if($this->currency == $currency)
142 return $value;
143
144 static $rates = null;
145
146 if($rates === null)
147 {
148 if(\Bitrix\Main\Loader::includeModule('currency'))
149 $rates = new \CCurrencyRates;
150 else
151 $rates = false;
152 }
153
154 if($rates)
155 $result = $rates->convertCurrency($result, $this->currency, $currency);
156 else
157 $result = $value;
158
159 return $result;
160 }
161
162 protected function convertToOperatingCurrency($value)
163 {
164 return $this->convertToOtherCurrency($value, $this->operatingCurrency);
165 }
166
167 public static function prepareParamsToSave(array $params)
168 {
169 return $params;
170 }
171
172 public function canUserEditValue()
173 {
174 return $this->rights[Manager::RIGHTS_CLIENT_IDX] == 'Y';
175 }
176
177 public function canManagerEditValue()
178 {
179 return $this->rights[Manager::RIGHTS_MANAGER_IDX] == 'Y';
180 }
181
182 public function getAdminDefaultControl($prefix = '', $value = false)
183 {
184 return $this->getEditControl($prefix, $value);
185 }
186
187 public static function getAdminParamsControl($name, array $params, $currency = '')
188 {
189 return false;
190 }
191
192 public function isStore()
193 {
194 return $this->className == '\Bitrix\Sale\Delivery\ExtraServices\Store';
195 }
196
197 public function getParams()
198 {
199 return $this->params;
200 }
201
202 public static function isInner()
203 {
204 return false;
205 }
206
207 public function setOperatingCurrency($currency)
208 {
209 $this->operatingCurrency = $currency;
210 }
211
212 public function getOperatingCurrency()
213 {
214 return $this->operatingCurrency;
215 }
216
217 public function getCode()
218 {
219 return $this->code;
220 }
221
222 public function getId()
223 {
224 return $this->id;
225 }
226
227 public function getCostShipment(Shipment $shipment = null)
228 {
229 return $this->getCost();
230 }
231
237 public function getCost()
238 {
239 return 0;
240 }
241
242 public static function isEmbeddedOnly()
243 {
244 return false;
245 }
246
247 public function getPriceShipment(Shipment $shipment = null)
248 {
249 return $this->getPrice();
250 }
251
255 public function getDisplayValue(): ?string
256 {
257 return is_null($this->value) ? null : (string)$this->value;
258 }
259
263 public function getInitial()
264 {
265 return $this->initial;
266 }
267}
getEditControl($prefix='', $value=false)
Definition base.php:97
convertToOtherCurrency($value, $currency)
Definition base.php:131
getAdminDefaultControl($prefix='', $value=false)
Definition base.php:182
static getAdminParamsControl($name, array $params, $currency='')
Definition base.php:187
getPriceShipment(Shipment $shipment=null)
Definition base.php:247
static prepareParamsToSave(array $params)
Definition base.php:167
__construct($id, array $initParams, $currency, $value=null, array $additionalParams=array())
Definition base.php:32
getCostShipment(Shipment $shipment=null)
Definition base.php:227