1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
option.php
См. документацию.
1<?php
3{
4 private $name = '';
5 private $value = /*.(array[string]string).*/ null;
6
13 public function __construct($name)
14 {
15 $this->name = $name;
16 }
17
25 public static function getOption($name)
26 {
27 $ob = new CBitrixCloudOption($name);
28 return $ob;
29 }
30
36 private function _read_db()
37 {
38 global $DB;
39 $result = /*.(array[string]string).*/ [];
40 $rs = $DB->Query("
41 select PARAM_KEY, PARAM_VALUE
42 from b_bitrixcloud_option
43 where NAME = '" . $DB->ForSQL($this->name) . "'
44 order by SORT
45 ");
46 while (is_array($ar = $rs->Fetch()))
47 {
48 $key = $ar['PARAM_KEY'];
49 $result[$key] = $ar['PARAM_VALUE'];
50 }
51 return $result;
52 }
53
59 private function _read_all_db()
60 {
61 global $DB;
62 $result = /*.(array[string][string]string).*/ [];
63 $rs = $DB->Query('
64 select NAME, PARAM_KEY, PARAM_VALUE
65 from b_bitrixcloud_option
66 order by NAME, SORT
67 ');
68 while (is_array($ar = $rs->Fetch()))
69 {
70 $name = $ar['NAME'];
71 $key = $ar['PARAM_KEY'];
72 $result[$name][$key] = $ar['PARAM_VALUE'];
73 }
74 return $result;
75 }
76
82 private function _delete_db()
83 {
84 global $DB;
85 $DB->Query("
86 delete
87 from b_bitrixcloud_option
88 where NAME = '" . $DB->ForSQL($this->name) . "'
89 ");
90 }
91
98 private function _write_db($value)
99 {
100 global $DB;
101 if (is_array($value))
102 {
103 $sort = 0;
104 foreach ($value as $key => $val)
105 {
106 $DB->Add('b_bitrixcloud_option', [
107 'NAME' => $this->name,
108 'SORT' => (string)$sort,
109 'PARAM_KEY' => $key,
110 'PARAM_VALUE' => $val,
111 ]);
112 $sort++;
113 }
114 }
115 }
116
123 private function _update_db($value)
124 {
125 global $DB;
126 if (!is_array($value))
127 {
128 $value = [];
129 }
130
131 reset($value);
132 $rs = $DB->Query("
133 select ID, SORT, PARAM_KEY, PARAM_VALUE
134 from b_bitrixcloud_option
135 where NAME = '" . $DB->ForSQL($this->name) . "'
136 order by ID
137 ");
138
139 $sort = 0;
140 foreach ($value as $key => $val)
141 {
142 if ($db_row = $rs->fetch())
143 {
144 if (
145 (string)$db_row['PARAM_VALUE'] !== (string)$val
146 || (string)$db_row['PARAM_KEY'] !== (string)$key
147 || (string)$db_row['SORT'] !== (string)$sort
148 )
149 {
150 $DB->Query("
151 UPDATE b_bitrixcloud_option SET
152 PARAM_KEY = '" . $DB->ForSql($key, 50) . "'
153 ,PARAM_VALUE = '" . $DB->ForSql($val, 200) . "'
154 ,SORT = " . $sort . '
155 WHERE ID = ' . $db_row['ID'] . '
156 ');
157 }
158 }
159 else
160 {
161 $DB->Add('b_bitrixcloud_option', [
162 'NAME' => $this->name,
163 'SORT' => (string)$sort,
164 'PARAM_KEY' => $key,
165 'PARAM_VALUE' => $val,
166 ]);
167 }
168 $sort++;
169 }
170
171 if ($db_row = $rs->fetch())
172 {
173 $DB->Query("
174 DELETE FROM b_bitrixcloud_option
175 WHERE NAME = '" . $DB->ForSql($this->name, 50) . "'
176 AND ID >= " . $db_row['ID'] . '
177 ');
178 }
179 }
180
186 public function isExists()
187 {
188 return (count($this->_read_db()) > 0);
189 }
190
196 public function getArrayValue()
197 {
198 global $CACHE_MANAGER;
199 if ($this->name === '')
200 {
201 return /*.(array[string]string).*/ [];
202 }
203
204 if (!isset($this->value))
205 {
206 if (CACHED_b_bitrixcloud_option <= 0)
207 {
208 $this->value = $this->_read_db();
209 }
210 else
211 {
212 if (!$CACHE_MANAGER->Read(CACHED_b_bitrixcloud_option, 'b_bitrixcloud_option'))
213 {
214 $arOptions = $this->_read_all_db();
215 $CACHE_MANAGER->Set('b_bitrixcloud_option', $arOptions);
216 }
217 else
218 {
219 $arOptions = $CACHE_MANAGER->Get('b_bitrixcloud_option');
220 }
221 if (array_key_exists($this->name, $arOptions))
222 {
223 $this->value = $arOptions[$this->name];
224 }
225 else
226 {
227 $this->value = /*.(array[string]string).*/ [];
228 }
229 }
230 }
231 return $this->value;
232 }
233
239 public function getStringValue()
240 {
241 $value = $this->getArrayValue();
242 return (string)current($value);
243 }
244
250 public function getIntegerValue()
251 {
252 $value = $this->getArrayValue();
253 return (integer)current($value);
254 }
255
261 public function setArrayValue($value)
262 {
263 global $CACHE_MANAGER;
264 if ($this->name !== '')
265 {
266 $stored = $this->getArrayValue();
267 if ($stored !== $value)
268 {
269 $this->value = null;
270 $this->_update_db($value);
271 if (CACHED_b_bitrixcloud_option !== false)
272 {
273 $CACHE_MANAGER->Clean('b_bitrixcloud_option');
274 }
275 }
276 }
277 }
278
284 public function setStringValue($value)
285 {
286 $this->setArrayValue([
287 '0' => $value,
288 ]);
289 }
290
295 public function delete()
296 {
297 $this->setArrayValue(/*.(array[string]string).*/ []);
298 }
299}
Определения option.php:3
setStringValue($value)
Определения option.php:284
getStringValue()
Определения option.php:239
__construct($name)
Определения option.php:13
setArrayValue($value)
Определения option.php:261
static getOption($name)
Определения option.php:25
isExists()
Определения option.php:186
getIntegerValue()
Определения option.php:250
getArrayValue()
Определения option.php:196
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
$arOptions
Определения structure.php:223
$name
Определения menu_edit.php:35
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
$rs
Определения action.php:82