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