1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblocktype.php
См. документацию.
1<?php
2
5
20{
24 public string $LAST_ERROR = '';
53 public static function GetList($arOrder = array("SORT" => "ASC"), $arFilter = array())
54 {
56 global $DB;
58 global $CACHE_MANAGER;
59 $bLang = false;
60 $bNameSort = false;
61 $strSqlSearch = "1=1\n";
62
63 foreach ($arFilter as $key => $val)
64 {
65 if (!is_array($val) && $val == '')
66 continue;
67
68 switch(mb_strtoupper($key))
69 {
70 case "ID":
71 $strSqlSearch .= "AND UPPER(T.ID) LIKE UPPER('".$DB->ForSql($val)."')\n";
72 break;
73
74 case "=ID":
75 if(is_array($val))
76 {
77 if(!empty($val))
78 {
79 $sqlVal = array_map(array($DB, 'ForSQL'), $val);
80 $strSqlSearch .= "AND T.ID in ('".implode("', '", $sqlVal)."')\n";
81 }
82 }
83 else
84 {
85 $strSqlSearch .= "AND T.ID = '".$DB->ForSql($val)."'\n";
86 }
87 break;
88
89 case "NAME":
90 $strSqlSearch .= "AND UPPER(TL.NAME) LIKE UPPER('%".$DB->ForSql($val)."%')\n";
91 $bLang = true;
92 break;
93 case "LANGUAGE_ID":
94 $strSqlSearch .= "AND TL.LID = '".$DB->ForSql($val)."'\n";
95 $bLang = true;
96 break;
97 }
98 }
99
100 $strSqlOrder = '';
101 foreach ($arOrder as $by => $order)
102 {
103 $by = mb_strtoupper($by);
104 if ($by == "ID")
105 $by = "T.ID";
106 elseif ($by == "NAME")
107 {
108 $by = "TL.NAME";
109 $bLang = true;
110 $bNameSort = true;
111 }
112 else
113 $by = "T.SORT";
114
115 $order = mb_strtolower($order);
116 if ($order != "desc")
117 $order = "asc";
118
119 if ($strSqlOrder == '')
120 $strSqlOrder = " ORDER BY ";
121 else
122 $strSqlOrder .= ', ';
123
124 $strSqlOrder .= $by." ".$order;
125 }
126
127 $strSql = "
128 SELECT ".($bLang ? "DISTINCT" : "")." T.*".($bNameSort ? ",TL.NAME" : "")."
129 FROM b_iblock_type T
130 ".($bLang ? " LEFT JOIN b_iblock_type_lang TL ON TL.IBLOCK_TYPE_ID = T.ID " : "")."
131 WHERE ".$strSqlSearch.$strSqlOrder;
132
133 if (CACHED_b_iblock_type === false)
134 {
135 $res = $DB->Query($strSql);
136 }
137 else
138 {
139 if ($CACHE_MANAGER->Read(CACHED_b_iblock_type, $cache_id = "b_iblock_type".md5($strSql), "b_iblock_type"))
140 {
141 $arResult = $CACHE_MANAGER->Get($cache_id);
142 }
143 else
144 {
145 $arResult = array();
146 $res = $DB->Query($strSql);
147 while ($ar = $res->Fetch())
148 $arResult[] = $ar;
149
150 $CACHE_MANAGER->Set($cache_id, $arResult);
151 }
152 $res = new CDBResult;
153 $res->InitFromArray($arResult);
154 }
155 return $res;
156 }
157
164 protected static function _GetCache($ID)
165 {
167 global $DB;
169 global $CACHE_MANAGER;
170
171 $ID = trim((string)$ID);
172 if ($ID === '')
173 {
174 return false;
175 }
176
177 if ($CACHE_MANAGER->Read(CACHED_b_iblock_type, "b_iblock_type", Iblock\TypeTable::getTableName()))
178 {
179 $arIBlocks = $CACHE_MANAGER->Get("b_iblock_type");
180 }
181 else
182 {
183 $arIBlocks = [];
184 $rs = $DB->Query("SELECT * FROM b_iblock_type");
185 while ($ar = $rs->GetNext())
186 {
187 $ar["_lang"] = [];
188 $arIBlocks[$ar['ID']] = $ar;
189 }
190 $rs = $DB->Query("SELECT * FROM b_iblock_type_lang");
191 while ($ar = $rs->GetNext())
192 {
193 if (array_key_exists($ar['IBLOCK_TYPE_ID'], $arIBlocks))
194 {
195 $arIBlocks[$ar['IBLOCK_TYPE_ID']]["_lang"][$ar["LID"]] = $ar;
196 }
197 }
198 $CACHE_MANAGER->Set("b_iblock_type", $arIBlocks);
199 }
200
201 return $arIBlocks[$ID] ?? false;
202 }
203
220 public static function GetByID($ID)
221 {
222 if (CACHED_b_iblock_type === false)
223 {
225 [],
226 [
227 '=ID' => $ID,
228 ]
229 );
230 }
231 else
232 {
234 $res = new CDBResult;
235 if ($arResult !== false && isset($arResult["ID"]))
236 {
237 unset($arResult["_lang"]);
238 $res->InitFromArray([$arResult]);
239 }
240 else
241 {
242 $res->InitFromArray([]);
243 }
244
245 return $res;
246 }
247 }
248
274 public static function GetByIDLang($ID, $LID, $bFindAny = true)
275 {
277 global $DB;
278 $LID = $DB->ForSQL($LID, 2);
279
280 if (CACHED_b_iblock_type === false)
281 {
282 $strSql = "
283 SELECT BTL.*, BT.*
284 FROM b_iblock_type BT, b_iblock_type_lang BTL
285 WHERE BTL.IBLOCK_TYPE_ID = '".$DB->ForSQL($ID)."'
286 AND BTL.LID='".$LID."'
287 AND BT.ID=BTL.IBLOCK_TYPE_ID
288 ";
289 $res = $DB->Query($strSql);
290 if ($r = $res->GetNext())
291 return $r;
292 }
293 else
294 {
296 if ($arResult !== false && array_key_exists($LID, $arResult["_lang"]))
297 {
298 $res = $arResult["_lang"][$LID];
299 unset($arResult["_lang"]);
300 return array_merge($res, $arResult);
301 }
302 }
303
304 if (!$bFindAny)
305 return false;
306
307 $strSql = "
308 SELECT BTL.*, BT.*
309 FROM b_iblock_type BT, b_iblock_type_lang BTL, b_language L
310 WHERE BTL.IBLOCK_TYPE_ID = '".$DB->ForSQL($ID)."'
311 AND BTL.LID = L.LID
312 AND BT.ID=BTL.IBLOCK_TYPE_ID
313 ORDER BY L.DEF DESC, L.SORT
314 ";
315 $res = $DB->Query($strSql);
316 if ($r = $res->GetNext())
317 return $r;
318
319 return false;
320 }
321
329 public static function Delete($ID)
330 {
332 global $DB;
333
335
336 $iblocks = CIBlock::GetList(array(), array(
337 "=TYPE" => $ID,
338 ));
339 while ($iblock = $iblocks->Fetch())
340 {
341 if (!CIBlock::Delete($iblock["ID"]))
342 {
343 return false;
344 }
345 }
346
347 if (!$DB->Query("DELETE FROM b_iblock_type_lang WHERE IBLOCK_TYPE_ID='".$DB->ForSql($ID)."'", true))
348 {
349 return false;
350 }
351
352 return $DB->Query("DELETE FROM b_iblock_type WHERE ID='".$DB->ForSql($ID)."'", true);
353 }
354
363 public function CheckFields($arFields, $ID = false)
364 {
366 global $DB;
367 $this->LAST_ERROR = '';
368
369 if ($ID === false)
370 {
371 if (!isset($arFields["ID"]) || $arFields["ID"] == '')
372 {
373 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_TYPE_BAD_ID")."<br>";
374 }
375 elseif (preg_match("/[^A-Za-z0-9_]/", $arFields["ID"]))
376 {
377 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_TYPE_ID_HAS_WRONG_CHARS")."<br>";
378 }
379 else
380 {
381 $chk = $DB->Query("SELECT 'x' FROM b_iblock_type WHERE ID='".$DB->ForSQL($arFields["ID"])."'");
382 if ($chk->Fetch())
383 {
384 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_TYPE_DUBL_ID")."<br>";
385 return false;
386 }
387 }
388 if (empty($arFields["LANG"]) || !is_array($arFields["LANG"]))
389 {
390 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_TYPE_EMPTY_NAMES")."<br>";
391 return false;
392 }
393 }
394
395 if (!empty($arFields['LANG']) && is_array($arFields['LANG']))
396 {
397 foreach ($arFields["LANG"] as $lid => $arFieldsLang)
398 {
399 if ($arFieldsLang["NAME"] == '')
400 {
401 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_TYPE_BAD_NAME")." ".$lid.".<br>";
402 }
403 }
404 }
405
406 return $this->LAST_ERROR === '';
407 }
408
429 public function Add($arFields)
430 {
432 global $DB;
433
434 $arFields["SECTIONS"] = isset($arFields["SECTIONS"]) && $arFields["SECTIONS"] === "Y" ? "Y" : "N";
435 $arFields["IN_RSS"] = isset($arFields["IN_RSS"]) && $arFields["IN_RSS"] === "Y" ? "Y" : "N";
436
437 if (!$this->CheckFields($arFields))
438 {
439 return false;
440 }
441
442 $arInsert = $DB->PrepareInsert("b_iblock_type", $arFields);
443 $DB->Query("INSERT INTO b_iblock_type(".$arInsert[0].") VALUES(".$arInsert[1].")");
444
445 if (isset($arFields["LANG"]))
446 {
447 $this->SetLang($arFields["ID"], $arFields["LANG"]);
448 }
449
451
452 return $arFields["ID"];
453 }
454
464 public function Update($ID, $arFields)
465 {
467 global $DB;
468
469 $arFields["SECTIONS"] = $arFields["SECTIONS"] == "Y" ? "Y" : "N";
470 $arFields["IN_RSS"] = $arFields["IN_RSS"] == "Y" ? "Y" : "N";
471
472 if (!$this->CheckFields($arFields, $ID))
473 {
474 return false;
475 }
476
477 $str_update = $DB->PrepareUpdate("b_iblock_type", $arFields);
478 $DB->Query("UPDATE b_iblock_type SET ".$str_update." WHERE ID='".$DB->ForSQL($ID)."'");
479
480 if (isset($arFields["LANG"]))
481 {
482 $this->SetLang($ID, $arFields["LANG"]);
483 }
484
486
487 return true;
488 }
489
495 protected static function SetLang($ID, $arLang)
496 {
498 global $DB;
499
500 if (is_array($arLang))
501 {
502 $DB->Query("DELETE FROM b_iblock_type_lang WHERE IBLOCK_TYPE_ID='".$DB->ForSQL($ID)."'");
503 foreach ($arLang as $lid => $arFieldsLang)
504 {
505 $name = (string)($arFieldsLang['NAME'] ?? '');
506 $elementName = (string)($arFieldsLang['ELEMENT_NAME'] ?? '');
507 $sectionName = (string)($arFieldsLang['SECTION_NAME'] ?? '');
508 if ($name !== '' || $elementName !== '')
509 {
510 $DB->Query("
511 INSERT INTO b_iblock_type_lang(IBLOCK_TYPE_ID, LID, NAME, SECTION_NAME, ELEMENT_NAME)
512 SELECT
513 BT.ID,
514 L.LID,
515 '".$DB->ForSql($name, 100)."',
516 '".$DB->ForSql($sectionName, 100)."',
517 '".$DB->ForSql($elementName, 100)."'
518 FROM
519 b_iblock_type BT,
520 b_language L
521 WHERE
522 BT.ID = '".$DB->ForSQL($ID)."'
523 AND L.LID = '".$DB->ForSQL($lid)."'
524 ");
525 }
526 }
527 }
528 }
529
535 public function getLastError(): string
536 {
537 return $this->LAST_ERROR;
538 }
539}
$arResult
Определения generate_coupon.php:16
static cleanCache()
Определения type.php:177
static getTableName()
Определения type.php:45
Определения dbresult.php:88
Определения iblocktype.php:20
getLastError()
Определения iblocktype.php:535
CheckFields($arFields, $ID=false)
Определения iblocktype.php:363
static GetList($arOrder=array("SORT"=> "ASC"), $arFilter=array())
Определения iblocktype.php:53
static _GetCache($ID)
Определения iblocktype.php:164
static Delete($ID)
Определения iblocktype.php:329
static GetByID($ID)
Определения iblocktype.php:220
static SetLang($ID, $arLang)
Определения iblocktype.php:495
string $LAST_ERROR
Определения iblocktype.php:24
Add($arFields)
Определения iblocktype.php:429
Update($ID, $arFields)
Определения iblocktype.php:464
static GetByIDLang($ID, $LID, $bFindAny=true)
Определения iblocktype.php:274
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$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
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
global $DB
Определения cron_frame.php:29
$name
Определения menu_edit.php:35
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$val
Определения options.php:1793
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106