1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblocksection.php
См. документацию.
1<?php
3
5{
14 public static function GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt = false, $arSelect = array(), $arNavStartParams=false)
15 {
17
18 if (!is_array($arOrder))
19 $arOrder = array();
20 if (!is_array($arFilter))
21 $arFilter = array();
22 if (!is_array($arSelect))
23 $arSelect = array();
24 foreach (array_keys($arSelect) as $index)
25 {
26 if (!is_string($arSelect[$index]))
27 {
28 unset($arSelect[$index]);
29 }
30 }
31
32 $iblockId = null;
33 if (isset($arFilter['IBLOCK_ID']) && is_numeric($arFilter['IBLOCK_ID']))
34 {
35 $iblockId = (int)$arFilter['IBLOCK_ID'];
36 if ($iblockId <= 0)
37 {
38 $iblockId = null;
39 }
40 }
41 $iblockFilterExist = $iblockId !== null;
42
43 $needUfManager = self::checkUfFields($arOrder, $arFilter, $arSelect);
44
45 if ($needUfManager && !$iblockFilterExist)
46 {
47 trigger_error("Parameters of the CIBlockSection::GetList contains user fields, but arFilter has no IBLOCK_ID field.", E_USER_WARNING);
48 }
49 if ($needUfManager)
50 {
51 $userFieldsSelect = $arSelect;
52 if (!in_array("UF_*", $userFieldsSelect))
53 {
54 if (!empty($arOrder) && is_array($arOrder))
55 {
56 foreach (array_keys($arOrder) as $userFieldName)
57 {
58 if (!in_array($userFieldName, $userFieldsSelect))
59 $userFieldsSelect[] = $userFieldName;
60 }
61 unset($userFieldName);
62 }
63 }
64
65 $obUserFieldsSql = new CUserTypeSQL;
66 $obUserFieldsSql->SetEntity("IBLOCK_".$arFilter["IBLOCK_ID"]."_SECTION", "BS.ID");
67 $obUserFieldsSql->SetSelect($userFieldsSelect);
68 $obUserFieldsSql->SetFilter($arFilter);
69 $obUserFieldsSql->SetOrder($arOrder);
70
71 unset($userFieldsSelect);
72 }
73
74 $useSubsections = !(isset($arFilter["ELEMENT_SUBSECTIONS"]) && $arFilter["ELEMENT_SUBSECTIONS"]=="N");
75 $allElements = (isset($arFilter['CNT_ALL']) && $arFilter['CNT_ALL'] == 'Y');
76 $activeElements = (isset($arFilter['CNT_ACTIVE']) && $arFilter['CNT_ACTIVE'] == 'Y');
77
78 $arJoinProps = array();
79 $bJoinFlatProp = false;
80
82
83 $bCheckPermissions = !(isset($arFilter["CHECK_PERMISSIONS"]) && $arFilter["CHECK_PERMISSIONS"] === "N");
84 $bIsAdmin = is_object($USER) && $USER->IsAdmin();
85 $permissionsBy = null;
86 if ($bCheckPermissions && isset($arFilter['PERMISSIONS_BY']))
87 {
88 $permissionsBy = (int)$arFilter['PERMISSIONS_BY'];
89 if ($permissionsBy < 0)
90 $permissionsBy = null;
91 }
92 if($bCheckPermissions && ($permissionsBy !== null || !$bIsAdmin))
93 {
94 $arFilter["MIN_PERMISSION"] ??= CIBlockRights::PUBLIC_READ;
95 $arSqlSearch[] = self::_check_rights_sql($arFilter["MIN_PERMISSION"], $permissionsBy);
96 }
97 unset($permissionsBy);
98
99 if (!empty($arFilter["PROPERTY"]) && is_array($arFilter["PROPERTY"]))
100 {
101 $val = $arFilter["PROPERTY"];
102 foreach($val as $propID=>$propVAL)
103 {
104 $res = CIBlock::MkOperationFilter($propID);
105 $propID = $res["FIELD"];
106 $cOperationType = $res["OPERATION"];
107 if($db_prop = CIBlockProperty::GetPropertyArray($propID, CIBlock::_MergeIBArrays($arFilter["IBLOCK_ID"], $arFilter["IBLOCK_CODE"])))
108 {
109 $bSave = false;
110 $separateSingle = (
112 && $db_prop["MULTIPLE"] == "N"
113 );
114
115 $iPropCnt = -1;
116 if (isset($arJoinProps[$db_prop["ID"]]))
117 {
118 $iPropCnt = $arJoinProps[$db_prop["ID"]]["iPropCnt"];
119 }
120 elseif(!$separateSingle)
121 {
122 $bSave = true;
123 $iPropCnt = count($arJoinProps);
124 }
125
126 if(!is_array($propVAL))
127 $propVAL = Array($propVAL);
128
129 if($db_prop["PROPERTY_TYPE"]=="N" || $db_prop["PROPERTY_TYPE"]=="G" || $db_prop["PROPERTY_TYPE"]=="E")
130 {
131 if($separateSingle)
132 {
133 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "number", $cOperationType);
134 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
135 }
136 else
137 {
138 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE_NUM", $propVAL, "number", $cOperationType);
139 }
140 }
141 else
142 {
143 if($separateSingle)
144 {
145 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "string", $cOperationType);
146 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
147 }
148 else
149 {
150 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE", $propVAL, "string", $cOperationType);
151 }
152 }
153
154 if($r != '')
155 {
156 if($bSave)
157 {
158 $db_prop["iPropCnt"] = $iPropCnt;
159 $arJoinProps[$db_prop["ID"]] = $db_prop;
160 }
161 $arSqlSearch[] = $r;
162 }
163 }
164 }
165 }
166
167 $strSqlSearch = "";
168 foreach($arSqlSearch as $r)
169 if($r <> '')
170 $strSqlSearch .= "\n\t\t\t\tAND (".$r.") ";
171
172 if(isset($obUserFieldsSql))
173 {
174 $r = $obUserFieldsSql->GetFilter();
175 if($r <> '')
176 $strSqlSearch .= "\n\t\t\t\tAND (".$r.") ";
177 }
178
179 $strProp1 = "";
180 foreach($arJoinProps as $propID=>$db_prop)
181 {
182 if($db_prop["VERSION"]==2)
183 $strTable = "b_iblock_element_prop_m".$db_prop["IBLOCK_ID"];
184 else
185 $strTable = "b_iblock_element_property";
186 $i = $db_prop["iPropCnt"];
187 $strProp1 .= "
188 LEFT JOIN b_iblock_property FP".$i." ON FP".$i.".IBLOCK_ID=B.ID AND
189 ".((int)$propID>0?" FP".$i.".ID=".(int)$propID." ":" FP".$i.".CODE='".$DB->ForSQL($propID, 200)."' ")."
190 LEFT JOIN ".$strTable." FPV".$i." ON FP".$i.".ID=FPV".$i.".IBLOCK_PROPERTY_ID AND FPV".$i.".IBLOCK_ELEMENT_ID=BE.ID ";
191 }
192 if($bJoinFlatProp)
193 $strProp1 .= "
194 LEFT JOIN b_iblock_element_prop_s".$bJoinFlatProp." FPS ON FPS.IBLOCK_ELEMENT_ID = BE.ID
195 ";
196
198 "ID" => "BS.ID",
199 "CODE" => "BS.CODE",
200 "XML_ID" => "BS.XML_ID",
201 "EXTERNAL_ID" => "BS.XML_ID",
202 "IBLOCK_ID" => "BS.IBLOCK_ID",
203 "IBLOCK_SECTION_ID" => "BS.IBLOCK_SECTION_ID",
204 "TIMESTAMP_X" => $DB->DateToCharFunction("BS.TIMESTAMP_X"),
205 "TIMESTAMP_X_UNIX" => 'UNIX_TIMESTAMP(BS.TIMESTAMP_X)',
206 "SORT" => "BS.SORT",
207 "NAME" => "BS.NAME",
208 "ACTIVE" => "BS.ACTIVE",
209 "GLOBAL_ACTIVE" => "BS.GLOBAL_ACTIVE",
210 "PICTURE" => "BS.PICTURE",
211 "DESCRIPTION" => "BS.DESCRIPTION",
212 "DESCRIPTION_TYPE" => "BS.DESCRIPTION_TYPE",
213 "LEFT_MARGIN" => "BS.LEFT_MARGIN",
214 "RIGHT_MARGIN" => "BS.RIGHT_MARGIN",
215 "DEPTH_LEVEL" => "BS.DEPTH_LEVEL",
216 "SEARCHABLE_CONTENT" => "BS.SEARCHABLE_CONTENT",
217 "MODIFIED_BY" => "BS.MODIFIED_BY",
218 "DATE_CREATE" => $DB->DateToCharFunction("BS.DATE_CREATE"),
219 "DATE_CREATE_UNIX" => 'UNIX_TIMESTAMP(BS.DATE_CREATE)',
220 "CREATED_BY" => "BS.CREATED_BY",
221 "DETAIL_PICTURE" => "BS.DETAIL_PICTURE",
222 "TMP_ID" => "BS.TMP_ID",
223
224 "LIST_PAGE_URL" => "B.LIST_PAGE_URL",
225 "SECTION_PAGE_URL" => "B.SECTION_PAGE_URL",
226 "IBLOCK_TYPE_ID" => "B.IBLOCK_TYPE_ID",
227 "IBLOCK_CODE" => "B.CODE",
228 "IBLOCK_EXTERNAL_ID" => "B.XML_ID",
229 "SOCNET_GROUP_ID" => "BS.SOCNET_GROUP_ID",
230 );
231
232 $arSqlSelect = array();
233 foreach($arSelect as $field)
234 {
235 $field = mb_strtoupper($field);
236 if(isset($arFields[$field]))
237 $arSqlSelect[$field] = $arFields[$field]." AS ".$field;
238 }
239
240 if(isset($arSqlSelect['DESCRIPTION']))
241 $arSqlSelect["DESCRIPTION_TYPE"] = $arFields["DESCRIPTION_TYPE"]." AS DESCRIPTION_TYPE";
242
243 if(isset($arSqlSelect['LIST_PAGE_URL']) || isset($arSqlSelect['SECTION_PAGE_URL']))
244 {
245 $arSqlSelect["ID"] = $arFields["ID"]." AS ID";
246 $arSqlSelect["CODE"] = $arFields["CODE"]." AS CODE";
247 $arSqlSelect["EXTERNAL_ID"] = $arFields["EXTERNAL_ID"]." AS EXTERNAL_ID";
248 $arSqlSelect["IBLOCK_TYPE_ID"] = $arFields["IBLOCK_TYPE_ID"]." AS IBLOCK_TYPE_ID";
249 $arSqlSelect["IBLOCK_ID"] = $arFields["IBLOCK_ID"]." AS IBLOCK_ID";
250 $arSqlSelect["IBLOCK_CODE"] = $arFields["IBLOCK_CODE"]." AS IBLOCK_CODE";
251 $arSqlSelect["IBLOCK_EXTERNAL_ID"] = $arFields["IBLOCK_EXTERNAL_ID"]." AS IBLOCK_EXTERNAL_ID";
252 $arSqlSelect["GLOBAL_ACTIVE"] = $arFields["GLOBAL_ACTIVE"]." AS GLOBAL_ACTIVE";
253 //$arr["LANG_DIR"],
254 }
255
256 $additionalSelect = array();
257 $arSqlOrder = array();
258 foreach($arOrder as $by=>$order)
259 {
260 $by = mb_strtolower($by);
261 if(isset($arSqlOrder[$by]))
262 continue;
263 $order = mb_strtolower($order);
264 if($order!="asc")
265 $order = "desc";
266
267 switch ($by)
268 {
269 case "id":
270 $arSqlOrder[$by] = " BS.ID ".$order." ";
271 $additionalSelect["ID"] = $arFields["ID"]." AS ID";
272 break;
273 case "section":
274 $arSqlOrder[$by] = " BS.IBLOCK_SECTION_ID ".$order." ";
275 $additionalSelect["IBLOCK_SECTION_ID"] = $arFields["IBLOCK_SECTION_ID"]." AS IBLOCK_SECTION_ID";
276 break;
277 case "name":
278 $arSqlOrder[$by] = " BS.NAME ".$order." ";
279 $additionalSelect["NAME"] = $arFields["NAME"]." AS NAME";
280 break;
281 case "code":
282 $arSqlOrder[$by] = " BS.CODE ".$order." ";
283 $additionalSelect["CODE"] = $arFields["CODE"]." AS CODE";
284 break;
285 case "external_id":
286 case "xml_id":
287 $arSqlOrder[$by] = " BS.XML_ID ".$order." ";
288 $additionalSelect["XML_ID"] = $arFields["XML_ID"]." AS XML_ID";
289 break;
290 case "active":
291 $arSqlOrder[$by] = " BS.ACTIVE ".$order." ";
292 $additionalSelect["ACTIVE"] = $arFields["ACTIVE"]." AS ACTIVE";
293 break;
294 case "left_margin":
295 $arSqlOrder[$by] = " BS.LEFT_MARGIN ".$order." ";
296 $additionalSelect["LEFT_MARGIN"] = $arFields["LEFT_MARGIN"]." AS LEFT_MARGIN";
297 break;
298 case "depth_level":
299 $arSqlOrder[$by] = " BS.DEPTH_LEVEL ".$order." ";
300 $additionalSelect["DEPTH_LEVEL"] = $arFields["DEPTH_LEVEL"]." AS DEPTH_LEVEL";
301 break;
302 case "sort":
303 $arSqlOrder[$by] = " BS.SORT ".$order." ";
304 $additionalSelect["SORT"] = $arFields["SORT"]." AS SORT";
305 break;
306 case "created":
307 $arSqlOrder[$by] = " BS.DATE_CREATE ".$order." ";
308 $additionalSelect["DATE_CREATE"] = $arFields["DATE_CREATE"]." AS DATE_CREATE";
309 break;
310 case "created_by":
311 $arSqlOrder[$by] = " BS.CREATED_BY ".$order." ";
312 $additionalSelect["CREATED_BY"] = $arFields["CREATED_BY"]." AS CREATED_BY";
313 break;
314 case "modified_by":
315 $arSqlOrder[$by] = " BS.MODIFIED_BY ".$order." ";
316 $additionalSelect["MODIFIED_BY"] = $arFields["MODIFIED_BY"]." AS MODIFIED_BY";
317 break;
318 default:
319 if ($bIncCnt && $by == "element_cnt")
320 {
321 $arSqlOrder[$by] = " ELEMENT_CNT ".$order." ";
322 }
323 elseif (isset($obUserFieldsSql) && $s = $obUserFieldsSql->GetOrder($by))
324 {
325 $arSqlOrder[$by] = " ".$s." ".$order." ";
326 }
327 else
328 {
329 $by = "timestamp_x";
330 $arSqlOrder[$by] = " BS.TIMESTAMP_X ".$order." ";
331 $additionalSelect["TIMESTAMP_X_SORT"] = "BS.TIMESTAMP_X AS TSX_TMP";
332 }
333 }
334 }
335 if (!empty($additionalSelect) && !empty($arSqlSelect))
336 {
337 foreach ($additionalSelect as $key => $value)
338 $arSqlSelect[$key] = $value;
339 }
340
341 if(!empty($arSqlSelect))
342 $sSelect = implode(",\n", $arSqlSelect);
343 else
344 $sSelect = "
345 BS.*,
346 B.LIST_PAGE_URL,
347 B.SECTION_PAGE_URL,
348 B.IBLOCK_TYPE_ID,
349 B.CODE as IBLOCK_CODE,
350 B.XML_ID as IBLOCK_EXTERNAL_ID,
351 BS.XML_ID as EXTERNAL_ID,
352 ".$DB->DateToCharFunction("BS.TIMESTAMP_X")." as TIMESTAMP_X,
353 ".$DB->DateToCharFunction("BS.DATE_CREATE")." as DATE_CREATE
354 ";
355
356 if(!$bIncCnt)
357 {
358 $strSelect = $sSelect.(isset($obUserFieldsSql)? $obUserFieldsSql->GetSelect(): "");
359 $strSql = "
360 FROM b_iblock_section BS
361 INNER JOIN b_iblock B ON BS.IBLOCK_ID = B.ID
362 ".(isset($obUserFieldsSql)? $obUserFieldsSql->GetJoin("BS.ID"): "")."
363 ".($strProp1 <> ''?
364 " INNER JOIN b_iblock_section BSTEMP ON BSTEMP.IBLOCK_ID = BS.IBLOCK_ID
365 LEFT JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID
366 LEFT JOIN b_iblock_element BE ON (BSE.IBLOCK_ELEMENT_ID=BE.ID
367 AND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )
368 AND BE.IBLOCK_ID = BS.IBLOCK_ID
369 ".($allElements ?" OR BE.WF_NEW='Y' ":"").")
370 ".($activeElements ?
371 " AND BE.ACTIVE='Y'
372 AND (BE.ACTIVE_TO >= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_TO IS NULL)
373 AND (BE.ACTIVE_FROM <= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_FROM IS NULL)"
374 :"").")
375 ".$strProp1." "
376 :"")."
377 WHERE 1=1
378 ".($strProp1 <> ''?
379 " AND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN
380 AND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN "
381 :""
382 )."
383 ".$strSqlSearch."
384 ";
385 $strGroupBy = "";
386 }
387 else
388 {
389 $strSelect = $sSelect.",COUNT(DISTINCT BE.ID) as ELEMENT_CNT".(isset($obUserFieldsSql)? $obUserFieldsSql->GetSelect(): "");
390 $strSql = "
391 FROM b_iblock_section BS
392 INNER JOIN b_iblock B ON BS.IBLOCK_ID = B.ID
393 ".(isset($obUserFieldsSql)? $obUserFieldsSql->GetJoin("BS.ID"): "")."
394 ".(!$useSubsections ?
395 " LEFT JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BS.ID "
396 :
397 " INNER JOIN b_iblock_section BSTEMP ON BSTEMP.IBLOCK_ID = BS.IBLOCK_ID
398 LEFT JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID "
399 )."
400 LEFT JOIN b_iblock_element BE ON (BSE.IBLOCK_ELEMENT_ID=BE.ID
401 AND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )
402 AND BE.IBLOCK_ID = BS.IBLOCK_ID
403 ".($allElements ?" OR BE.WF_NEW='Y' ":"").")
404 ".($activeElements?
405 " AND BE.ACTIVE='Y'
406 AND (BE.ACTIVE_TO >= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_TO IS NULL)
407 AND (BE.ACTIVE_FROM <= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_FROM IS NULL)"
408 :"").")
409 ".$strProp1."
410 WHERE 1=1
411 ".(!$useSubsections
412 ?
413 " "
414 :
415 " AND BSTEMP.IBLOCK_ID = BS.IBLOCK_ID
416 AND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN
417 AND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN
418 ".($activeElements ? "AND BSTEMP.GLOBAL_ACTIVE = 'Y'": "")."
419 "
420 )."
421 ".$strSqlSearch."
422 ";
423 $strGroupBy = "GROUP BY BS.ID, B.ID";
424 }
425
426 if(!empty($arSqlOrder))
427 $strSqlOrder = "\n\t\t\t\tORDER BY ".implode(", ", $arSqlOrder);
428 else
429 $strSqlOrder = "";
430
431 if(is_array($arNavStartParams))
432 {
433 $nTopCount = (int)($arNavStartParams['nTopCount'] ?? 0);
434 if($nTopCount > 0)
435 {
436 $res = $DB->Query($DB->TopSql(
437 "SELECT DISTINCT ".$strSelect.$strSql.$strGroupBy.$strSqlOrder,
438 $nTopCount
439 ));
440 if($iblockFilterExist)
441 {
442 $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("IBLOCK_".$arFilter["IBLOCK_ID"]."_SECTION"));
443 }
444 }
445 else
446 {
447 $res_cnt = $DB->Query("SELECT COUNT(DISTINCT BS.ID) as C ".$strSql);
448 $res_cnt = $res_cnt->Fetch();
449 $res = new CDBResult();
450 if($iblockFilterExist)
451 {
452 $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("IBLOCK_".$arFilter["IBLOCK_ID"]."_SECTION"));
453 }
454 $res->NavQuery("SELECT DISTINCT ".$strSelect.$strSql.$strGroupBy.$strSqlOrder, $res_cnt["C"], $arNavStartParams);
455 }
456 }
457 else
458 {
459 $res = $DB->Query("SELECT DISTINCT ".$strSelect.$strSql.$strGroupBy.$strSqlOrder);
460 if($iblockFilterExist)
461 {
462 $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("IBLOCK_".$arFilter["IBLOCK_ID"]."_SECTION"));
463 }
464 }
465
466 $res = new CIBlockResult($res);
467 if($iblockFilterExist)
468 {
469 $res->SetIBlockTag($arFilter["IBLOCK_ID"]);
470 }
471
472 return $res;
473 }
474
475 // Update list of sections w/o any events
477 protected function UpdateList($arFields, $arFilter = array())
478 {
479 global $DB, $USER;
480
481 $strUpdate = $DB->PrepareUpdate("b_iblock_section", $arFields, "iblock", false, "BS");
482 if ($strUpdate == "")
483 return false;
484
485 if(isset($arFilter["IBLOCK_ID"]) && $arFilter["IBLOCK_ID"] > 0)
486 {
487 $obUserFieldsSql = new CUserTypeSQL;
488 $obUserFieldsSql->SetEntity("IBLOCK_".$arFilter["IBLOCK_ID"]."_SECTION", "BS.ID");
489 $obUserFieldsSql->SetFilter($arFilter);
490 }
491 else
492 {
493 foreach($arFilter as $key => $val)
494 {
495 $res = CIBlock::MkOperationFilter($key);
496 if(preg_match("/^UF_/", $res["FIELD"]))
497 {
498 trigger_error("arFilter parameter of the CIBlockSection::GetList contains user fields, but has no IBLOCK_ID field.", E_USER_WARNING);
499 break;
500 }
501 }
502 }
503
504 $arJoinProps = array();
505 $bJoinFlatProp = false;
506
507 $arSqlSearch = CIBlockSection::GetFilter($arFilter);
508
509 $bCheckPermissions = !array_key_exists("CHECK_PERMISSIONS", $arFilter) || $arFilter["CHECK_PERMISSIONS"]!=="N";
510 $bIsAdmin = is_object($USER) && $USER->IsAdmin();
511 $permissionsBy = null;
512 if ($bCheckPermissions && isset($arFilter['PERMISSIONS_BY']))
513 {
514 $permissionsBy = (int)$arFilter['PERMISSIONS_BY'];
515 if ($permissionsBy < 0)
516 $permissionsBy = null;
517 }
518 if($bCheckPermissions && ($permissionsBy !== null || !$bIsAdmin))
519 {
520 $arFilter["MIN_PERMISSION"] ??= CIBlockRights::PUBLIC_READ;
521 $arSqlSearch[] = self::_check_rights_sql($arFilter["MIN_PERMISSION"], $permissionsBy);
522 }
523 unset($permissionsBy);
524
525 if(array_key_exists("PROPERTY", $arFilter))
526 {
527 $val = $arFilter["PROPERTY"];
528 foreach($val as $propID=>$propVAL)
529 {
530 $res = CIBlock::MkOperationFilter($propID);
531 $propID = $res["FIELD"];
532 $cOperationType = $res["OPERATION"];
533 if($db_prop = CIBlockProperty::GetPropertyArray($propID, CIBlock::_MergeIBArrays($arFilter["IBLOCK_ID"], $arFilter["IBLOCK_CODE"])))
534 {
535
536 $bSave = false;
537 if(array_key_exists($db_prop["ID"], $arJoinProps))
538 $iPropCnt = $arJoinProps[$db_prop["ID"]];
539 elseif($db_prop["VERSION"]!=2 || $db_prop["MULTIPLE"]=="Y")
540 {
541 $bSave = true;
542 $iPropCnt=count($arJoinProps);
543 }
544
545 if(!is_array($propVAL))
546 $propVAL = Array($propVAL);
547
548 if($db_prop["PROPERTY_TYPE"]=="N" || $db_prop["PROPERTY_TYPE"]=="G" || $db_prop["PROPERTY_TYPE"]=="E")
549 {
550 if($db_prop["VERSION"]==2 && $db_prop["MULTIPLE"]=="N")
551 {
552 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "number", $cOperationType);
553 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
554 }
555 else
556 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE_NUM", $propVAL, "number", $cOperationType);
557 }
558 else
559 {
560 if($db_prop["VERSION"]==2 && $db_prop["MULTIPLE"]=="N")
561 {
562 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "string", $cOperationType);
563 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
564 }
565 else
566 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE", $propVAL, "string", $cOperationType);
567 }
568
569 if($r <> '')
570 {
571 if($bSave)
572 {
573 $db_prop["iPropCnt"] = $iPropCnt;
574 $arJoinProps[$db_prop["ID"]] = $db_prop;
575 }
576 $arSqlSearch[] = $r;
577 }
578 }
579 }
580 }
581
582 $strSqlSearch = "";
583 foreach($arSqlSearch as $r)
584 if($r <> '')
585 $strSqlSearch .= "\n\t\t\t\tAND (".$r.") ";
586
587 if(isset($obUserFieldsSql))
588 {
589 $r = $obUserFieldsSql->GetFilter();
590 if($r <> '')
591 $strSqlSearch .= "\n\t\t\t\tAND (".$r.") ";
592 }
593
594 $strProp1 = "";
595 foreach($arJoinProps as $propID=>$db_prop)
596 {
597 if($db_prop["VERSION"]==2)
598 $strTable = "b_iblock_element_prop_m".$db_prop["IBLOCK_ID"];
599 else
600 $strTable = "b_iblock_element_property";
601 $i = $db_prop["iPropCnt"];
602 $strProp1 .= "
603 LEFT JOIN b_iblock_property FP".$i." ON FP".$i.".IBLOCK_ID=B.ID AND
604 ".((int)$propID>0?" FP".$i.".ID=".(int)$propID." ":" FP".$i.".CODE='".$DB->ForSQL($propID, 200)."' ")."
605 LEFT JOIN ".$strTable." FPV".$i." ON FP".$i.".ID=FPV".$i.".IBLOCK_PROPERTY_ID AND FPV".$i.".IBLOCK_ELEMENT_ID=BE.ID ";
606 }
607 if($bJoinFlatProp)
608 $strProp1 .= "
609 LEFT JOIN b_iblock_element_prop_s".$bJoinFlatProp." FPS ON FPS.IBLOCK_ELEMENT_ID = BE.ID
610 ";
611
612 $strSql = "
613 UPDATE
614 b_iblock_section BS
615 INNER JOIN b_iblock B ON BS.IBLOCK_ID = B.ID
616 ".(isset($obUserFieldsSql)? $obUserFieldsSql->GetJoin("BS.ID"): "")."
617 ".($strProp1 <> ''?
618 " INNER JOIN b_iblock_section BSTEMP ON BSTEMP.IBLOCK_ID = BS.IBLOCK_ID
619 LEFT JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID
620 LEFT JOIN b_iblock_element BE ON (BSE.IBLOCK_ELEMENT_ID=BE.ID
621 AND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )
622 AND BE.IBLOCK_ID = BS.IBLOCK_ID
623 ".($arFilter["CNT_ALL"]=="Y"?" OR BE.WF_NEW='Y' ":"").")
624 ".($arFilter["CNT_ACTIVE"]=="Y"?
625 " AND BE.ACTIVE='Y'
626 AND (BE.ACTIVE_TO >= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_TO IS NULL)
627 AND (BE.ACTIVE_FROM <= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_FROM IS NULL)"
628 :"").")
629 ".$strProp1." "
630 :"")."
631 SET ".$strUpdate."
632 WHERE 1=1
633 ".($strProp1 <> ''?
634 " AND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN
635 AND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN "
636 :""
637 )."
638 ".$strSqlSearch."
639 ";
640
641 return $DB->Query($strSql);
642 }
643
650 private static function checkUfFields(array $order, array $filter, array $select): bool
651 {
652 $result = false;
653
654 $parsed = array();
655 if (!empty($select))
656 {
657 if (in_array('UF_*', $select))
658 {
659 $result = true;
660 }
661 else
662 {
663 foreach ($select as $field)
664 {
665 if (preg_match('/^UF_/', $field, $parsed))
666 {
667 $result = true;
668 break;
669 }
670 }
671 unset($field);
672 }
673 }
674 if (!$result && !empty($filter))
675 {
676 $filter = array_keys($filter);
677 foreach ($filter as $key)
678 {
680 if (preg_match('/^UF_/', $field['FIELD'], $parsed))
681 {
682 $result = true;
683 break;
684 }
685 }
686 unset($field, $key);
687 }
688 if (!$result && !empty($order))
689 {
690 $order = array_keys($order);
691 foreach ($order as $field)
692 {
693 if (preg_match('/^UF_/', $field, $parsed))
694 {
695 $result = true;
696 break;
697 }
698 }
699 unset($field);
700 }
701 unset($parced);
702
703 return $result;
704 }
705}
const PROPERTY_STORAGE_SEPARATE
Определения iblocktable.php:85
static MkOperationFilter($key)
Определения iblock.php:2522
static GetFilter($arFilter=Array())
Определения iblocksection.php:53
Определения dbresult.php:88
Определения iblockresult.php:3
Определения iblocksection.php:5
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt=false, $arSelect=array(), $arNavStartParams=false)
Определения iblocksection.php:14
UpdateList($arFields, $arFilter=array())
Определения iblocksection.php:477
Определения usertypesql.php:4
SetEntity($entity_id, $ID)
Определения usertypesql.php:16
$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
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</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
$arFilter
Определения user_search.php:106