1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
listfields.php
См. документацию.
1<?php
3
5{
6 protected $iblock_id = 0;
7 protected $form_id = "";
9 protected $fields = array();
10
12 {
13 if($iblock_id > 0)
14 {
15 $this->iblock_id = intval($iblock_id);
16 $this->form_id = "form_element_".$this->iblock_id;
17 $this->fields = $this->_read_form_settings($this->form_id);
18 }
19 else
20 {
21 $this->iblock_id = 0;
22 $this->form_id = "";
23 $this->fields = array();
24 }
25
26 if(!count($this->fields) || !isset($this->fields["NAME"]))
27 {
28 $this->fields["NAME"] = new CListElementField($this->iblock_id, "NAME", GetMessage("LISTS_LIST_NAME_FIELD_DEFAULT_LABEL"), (count($this->fields)+1)*10);
29 }
30 }
31
36 public function GetByID($field_id)
37 {
38 if(isset($this->fields[$field_id]))
39 return $this->fields[$field_id];
40 else
41 return null;
42 }
43
44 public function GetFields()
45 {
46 return array_keys($this->fields);
47 }
48
49 public function GetArrayByID($field_id)
50 {
51 if(isset($this->fields[$field_id]))
52 {
54 $obField = $this->fields[$field_id];
55 $result = $obField->GetArray();
56 }
57 else
58 {
59 $result = array();
60 }
61
62 $result["IBLOCK_ID"] = $this->iblock_id;
63
64 return $result;
65 }
66
67 public function DeleteField($field_id)
68 {
69 if($field_id != "NAME" && isset($this->fields[$field_id]))
70 {
72 $obField = $this->fields[$field_id];
73 $obField->Delete();
74 unset($this->fields[$field_id]);
75
76 $this->_save_form_settings($this->form_id);
77 }
78 return true;
79 }
80
81 public function AddField($arFields)
82 {
83 $new_field_id = false;
84 $newField = null;
85
87 {
88 if(!isset($this->fields[$arFields["TYPE"]]))
89 {
90 $newField = CListElementField::Add($this->iblock_id, $arFields);
91 }
92 }
94 {
95 $newField = CListPropertyField::Add($this->iblock_id, $arFields);
96 }
97
98 if(is_object($newField))
99 {
100 if(isset($arFields["SETTINGS"]))
101 $newField->SetSettings($arFields["SETTINGS"]);
102
103 $new_field_id = $newField->GetID();
104 $this->fields[$new_field_id] = $newField;
105
106 $this->_resort();
107 $this->_save_form_settings($this->form_id);
108 }
109
110 return $new_field_id;
111 }
112
113 public function UpdateField($field_id, $arFields)
114 {
115 $new_field_id = false;
116 $newField = null;
117
118 if(isset($this->fields[$field_id]))
119 {
121 $obField = $this->fields[$field_id];
122
123 if(isset($arFields["TYPE"]) && ($arFields["TYPE"] != $obField->GetTypeID()))
124 {
125 if(CListFieldTypeList::IsField($obField->GetTypeID()))
126 {
128 {
129 $newField = $obField->Update($arFields);
130 }
131 else
132 {
133 $obField->Delete();
134 $newField = CListPropertyField::Add($this->iblock_id, $arFields);
135 }
136 }
137 else
138 {
140 {
141 $newField = $obField->Update($arFields);
142 }
143 else
144 {
145 $obField->Delete();
146 $newField = CListElementField::Add($this->iblock_id, $arFields);
147 }
148 }
149 }
150 else
151 {
152 $newField = $obField->Update($arFields);
153 }
154 }
155
156 if(is_object($newField))
157 {
158 if(isset($arFields["SETTINGS"]))
159 $newField->SetSettings($arFields["SETTINGS"]);
160
161 unset($this->fields[$field_id]);
162 $new_field_id = $newField->GetID();
163 $this->fields[$new_field_id] = $newField;
164
165 $this->_resort();
166 $this->_save_form_settings($this->form_id);
167 }
168
169 return $new_field_id;
170 }
171
172 protected function _save_form_settings($form_id)
173 {
174 if($form_id && $this->iblock_id)
175 {
176 $arFormLayout = array();
177 $arFormLayout[] = "edit1--#--".CIBlock::GetArrayByID($this->iblock_id, "ELEMENT_NAME");
178 foreach($this->fields as $field_id => $sort)
179 {
181 $obField = $this->fields[$field_id];
182 $arFormLayout[] =
183 $obField->GetID()
184 ."--#--"
185 .($obField->IsRequired()? "*": "")
186 .str_replace("-", "", $obField->GetLabel())
187 ;
188 }
189 $tab1 = implode("--,--", $arFormLayout);
190
191 $arFormLayout = array();
192 $arFormLayout[] = "edit2--#--".CIBlock::GetArrayByID($this->iblock_id, "SECTION_NAME");
193 $arFormLayout[] = "SECTIONS--#--".CIBlock::GetArrayByID($this->iblock_id, "SECTION_NAME");
194 $tab2 = implode("--,--", $arFormLayout);
195
196 global $USER;
197 if (is_object($USER) && ((get_class($USER) === 'CUser') || ($USER instanceof CUser)))
198 CUserOptions::DeleteOption("form", $form_id); //This clears custom user settings
199 CUserOptions::SetOption("form", $form_id, array("tabs" => $tab1."--;--".$tab2."--;--"), true);
200 }
201 }
202
203 protected function _read_form_settings($form_id)
204 {
205 if(!$form_id)
206 return null;
207
208 global $DB;
209 $cache = Bitrix\Main\Data\Cache::createInstance();
210 $cacheId = CACHED_b_lists_field_prefix . $this->iblock_id;
211 $needClearCache = false;
212
213 $dbFields = false;
214 if (
215 (CACHED_b_lists_field !== false)
216 && $cache->initCache(CACHED_b_lists_field, $cacheId, 'b_lists_field')
217 )
218 {
219 $dbFields = $cache->getVars();
220 }
221
222 if ($dbFields === false)
223 {
224 $dbFields = [];
225 //read list meta from module table
226 $rsFields = $DB->Query("
227 SELECT * FROM b_lists_field
228 WHERE IBLOCK_ID = ".$this->iblock_id."
229 ");
230 while ($arField = $rsFields->Fetch())
231 {
232 $dbFields[$arField["FIELD_ID"]] = $arField;
233 }
234
235 if (CACHED_b_lists_field !== false)
236 {
237 $cache->startDataCache(CACHED_b_lists_field);
238 $cache->endDataCache($dbFields);
239 }
240 }
241
242 $fields = array();
243 $customTabs = CUserOptions::GetOption("form", $form_id);
244
245 //read list meta from interface settings
246 if($customTabs && $customTabs["tabs"])
247 {
248 $sort = 10;
249 $arTabs = explode("--;--", $customTabs["tabs"]);
250 foreach($arTabs as $customFields)
251 {
252 if($customFields)
253 {
254 $arCustomFields = explode("--,--", $customFields);
255 array_shift($arCustomFields);
256 foreach($arCustomFields as $customField)
257 {
258 list($FIELD_ID, $customName) = explode("--#--", $customField);
259 if($FIELD_ID != "SECTIONS")
260 {
261 $customName = ltrim($customName, "* -\xa0");
262
263 if(CListFieldTypeList::IsField($FIELD_ID))
264 $obField = $fields[$FIELD_ID] = new CListElementField($this->iblock_id, $FIELD_ID, $customName, $sort);
265 else
266 $obField = $fields[$FIELD_ID] = new CListPropertyField($this->iblock_id, $FIELD_ID, $customName, $sort);
267
268 //check if property was deleted from admin interface
269 if(!is_array($obField->GetArray()))
270 {
271 unset($fields[$FIELD_ID]);
272 }
273 else
274 {
275 $sort += 10;
276 unset($dbFields[$FIELD_ID]);
277 }
278 }
279 }
280 }
281 }
282 //There were some fields "deleted" from interface
283 foreach($dbFields as $FIELD_ID => $arField)
284 {
285 $DB->Query("
286 DELETE FROM b_lists_field
287 WHERE IBLOCK_ID = ".$this->iblock_id."
288 AND FIELD_ID = '".$DB->ForSQL($FIELD_ID)."'
289 ");
290 $needClearCache = true;
291 }
292 }
293 else//or from module metadata
294 {
295 foreach($dbFields as $FIELD_ID => $arField)
296 {
297 if(CListFieldTypeList::IsField($FIELD_ID))
298 $obField = $fields[$FIELD_ID] = new CListElementField($this->iblock_id, $FIELD_ID, $arField["NAME"], $arField["SORT"]);
299 else
300 $obField = $fields[$FIELD_ID] = new CListPropertyField($this->iblock_id, $FIELD_ID, $arField["NAME"], $arField["SORT"]);
301 //check if property was deleted from admin interface
302 if(!is_array($obField->GetArray()))
303 {
304 unset($fields[$FIELD_ID]);
305 $DB->Query("
306 DELETE FROM b_lists_field
307 WHERE IBLOCK_ID = ".$this->iblock_id."
308 AND FIELD_ID = '".$DB->ForSQL($FIELD_ID)."'
309 ");
310 $needClearCache = true;
311 }
312 }
313 }
314
315 if ($needClearCache && (CACHED_b_lists_field !== false))
316 {
317 $cache->clean($cacheId, 'b_lists_field');
318 }
319
320 return $fields;
321 }
322
328 function Order($a, $b)
329 {
330 $a_sort = $a->GetSort();
331 $b_sort = $b->GetSort();
332
333 if($a_sort < $b_sort)
334 return -1;
335 elseif($a_sort > $b_sort)
336 return 1;
337 else
338 {
339 $a_name = $a->GetLabel();
340 $b_name = $b->GetLabel();
341
342 if($a_name < $b_name)
343 return -1;
344 elseif($a_name > $b_name)
345 return 1;
346 else
347 return 0;
348 }
349 }
350
351 protected function _resort()
352 {
353 uasort($this->fields, array('CListFieldList', 'Order'));
354 $sort = 10;
355 foreach($this->fields as $field_id => $obField)
356 {
358 $obField->SetSort($sort);
359 $sort += 10;
360 }
361 }
362
363 static function DeleteFields($iblock_id)
364 {
365 global $DB;
366 $iblock_id = intval($iblock_id);
367 $DB->Query("
368 DELETE FROM b_lists_field
369 WHERE IBLOCK_ID = ".$iblock_id."
370 ");
371
372 if (CACHED_b_lists_field !== false)
373 {
374 $cache = \Bitrix\Main\Data\Cache::createInstance();
375 $cache->clean(CACHED_b_lists_field_prefix . $iblock_id, 'b_lists_field');
376 }
377
378 $rsOptions = CUserOptions::GetList(array("ID" => "ASC"), array(
379 "CATEGORY" => "form",
380 "NAME" => "form_element_".$iblock_id,
381 ));
382 while($arOption = $rsOptions->Fetch())
383 {
384 CUserOptions::DeleteOption(
385 $arOption["CATEGORY"],
386 $arOption["NAME"],
387 $arOption["COMMON"] == "Y",
388 $arOption["USER_ID"]
389 );
390 }
391 }
392}
393
394?>
Определения listfield.php:229
static Add($iblock_id, $arFields)
Определения listfield.php:328
Определения listfields.php:5
$iblock_id
Определения listfields.php:6
$form_id
Определения listfields.php:7
AddField($arFields)
Определения listfields.php:81
_read_form_settings($form_id)
Определения listfields.php:203
static DeleteFields($iblock_id)
Определения listfields.php:363
GetFields()
Определения listfields.php:44
Order($a, $b)
Определения listfields.php:328
$fields
Определения listfields.php:9
__construct($iblock_id)
Определения listfields.php:11
GetByID($field_id)
Определения listfields.php:36
static IsField($type_id)
Определения listfieldtypes.php:26
static IsExists($type_id)
Определения listfieldtypes.php:11
static Add($iblock_id, $arFields)
Определения listfield.php:538
static DeleteOption($category, $name, $bCommon=false, $user_id=false)
Определения user_options.php:247
static SetOption($category, $name, $value, $bCommon=false, $user_id=false)
Определения user_options.php:163
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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
else $a
Определения template.php:137
$arCustomFields
Определения settings_admin_form.php:66