Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
section.php
1<?php
2namespace Bitrix\Iblock\Model;
3
7
8class Section
9{
10 private static $entityInstance = [];
11
17 final public static function compileEntityByIblock($iblock)
18 {
19 $iblockId = static::resolveIblockId($iblock);
20
21 if ($iblockId <= 0)
22 {
23 return null;
24 }
25
26 if (!isset(self::$entityInstance[$iblockId]))
27 {
28 $className = 'Section'.$iblockId.'Table';
29 $entityName = "\\Bitrix\\Iblock\\".$className;
30 $referenceName = 'Bitrix\Iblock\Section'.$iblockId;
31 $entity = '
32 namespace Bitrix\Iblock;
33 class '.$className.' extends \Bitrix\Iblock\SectionTable
34 {
35 public static function getUfId()
36 {
37 return "IBLOCK_'.$iblockId.'_SECTION";
38 }
39
40 public static function getMap()
41 {
42 $fields = parent::getMap();
43 $fields["PARENT_SECTION"] = array(
44 "data_type" => "'.$referenceName.'",
45 "reference" => array("=this.IBLOCK_SECTION_ID" => "ref.ID"),
46 );
47 return $fields;
48 }
49
50 public static function setDefaultScope($query)
51 {
52 return $query->where("IBLOCK_ID", '.$iblockId.');
53 }
54 }';
55 eval($entity);
56 self::$entityInstance[$iblockId] = $entityName;
57 }
58
59 return self::$entityInstance[$iblockId];
60 }
61
70 protected static function resolveIblockId($iblock): ?int
71 {
72 $iblockId = null;
73
74 if ($iblock instanceof Iblock)
75 {
76 $iblockId = $iblock->getId();
77 }
78 elseif (is_string($iblock))
79 {
80 $row = IblockTable::query()
81 ->addSelect('ID')
82 ->where('API_CODE', $iblock)
83 ->fetch();
84
85 if (!empty($row))
86 {
87 $iblockId = (int)$row['ID'];
88 }
89 }
90
91 if (empty($iblockId) && is_numeric($iblock))
92 {
93 $iblockId = (int)$iblock;
94 }
95
96 return $iblockId;
97 }
98}
static compileEntityByIblock($iblock)
Definition section.php:17
static resolveIblockId($iblock)
Definition section.php:70