Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
section.php
1<?php
8
9class Section extends Base
10{
11 protected $property = null;
12 protected $iblock = null;
13 protected $parent = null;
14 protected $sections = null;
15 protected $catalog = null;
16
20 public function __construct($id)
21 {
22 parent::__construct($id);
23 $this->fieldMap = array(
24 "name" => "NAME",
25 "previewtext" => "DESCRIPTION",
26 "detailtext" => "DESCRIPTION",
27 "code" => "CODE",
28 //not accessible from template engine
29 "ID" => "ID",
30 "IBLOCK_ID" => "IBLOCK_ID",
31 "IBLOCK_SECTION_ID" => "IBLOCK_SECTION_ID",
32 );
33 }
34
42 public function resolve($entity)
43 {
44 if ($entity === "property")
45 {
46 if (!$this->property && $this->loadFromDatabase())
47 {
48 if ($this->fields["IBLOCK_ID"] > 0)
49 {
50 $this->property = new SectionProperty($this->id);
51 $this->property->setIblockId($this->fields["IBLOCK_ID"]);
52 }
53 }
54
55 if ($this->property)
56 return $this->property;
57 }
58 elseif ($entity === "iblock")
59 {
60 if (!$this->iblock && $this->loadFromDatabase())
61 {
62 if ($this->fields["IBLOCK_ID"] > 0)
63 $this->iblock = new Iblock($this->fields["IBLOCK_ID"]);
64 }
65
66 if ($this->iblock)
67 return $this->iblock;
68 }
69 elseif ($entity === "parent")
70 {
71 if (!$this->parent && $this->loadFromDatabase())
72 {
73 if ($this->fields["IBLOCK_SECTION_ID"] > 0)
74 $this->parent = new Section($this->fields["IBLOCK_SECTION_ID"]);
75 else
76 return $this->resolve("iblock");
77 }
78
79 if ($this->parent)
80 return $this->parent;
81 }
82 elseif ($entity === "sections")
83 {
84 if (!$this->sections && $this->loadFromDatabase())
85 {
86 if ($this->fields["IBLOCK_SECTION_ID"] > 0)
87 $this->sections = new SectionPath($this->fields["IBLOCK_SECTION_ID"]);
88 }
89
90 if ($this->sections)
91 return $this->sections;
92 }
93 elseif ($entity === "catalog")
94 {
95 if (!$this->catalog && $this->loadFromDatabase())
96 {
97 if (\Bitrix\Main\Loader::includeModule('catalog'))
98 $this->catalog = new ElementCatalog(0);
99 }
100
101 if ($this->catalog)
102 return $this->catalog;
103 }
104 return parent::resolve($entity);
105 }
106
114 public function setFields(array $fields)
115 {
116 parent::setFields($fields);
117 if (
118 is_array($this->fields)
119 && $this->fields["IBLOCK_ID"] > 0
120 )
121 {
122 $properties = array();
123 foreach ($this->fields as $id => $value)
124 {
125 if (mb_substr($id, 0, 3) === "UF_")
126 $properties[$id] = $value;
127 }
128 $this->property = new SectionProperty($this->id);
129 $this->property->setIblockId($this->fields["IBLOCK_ID"]);
130 $this->property->setFields($properties);
131
132 $this->iblock = new Iblock($fields["IBLOCK_ID"]);
133
134 if (
135 isset($fields["IBLOCK_SECTION_ID"])
136 && $fields["IBLOCK_SECTION_ID"] > 0
137 )
138 {
139 $this->parent = new Section($fields["IBLOCK_SECTION_ID"]);
140 $this->sections = new SectionPath($fields["IBLOCK_SECTION_ID"]);
141 }
142
143 if (\Bitrix\Main\Loader::includeModule('catalog'))
144 $this->catalog = new ElementCatalog($this->id);
145 }
146 }
147
154 protected function loadFromDatabase()
155 {
156 if (!isset($this->fields))
157 {
158 $sectionList = \Bitrix\Iblock\SectionTable::getList(array(
159 "select" => array_values($this->fieldMap),
160 "filter" => array("=ID" => $this->id),
161 ));
162 $this->fields = $sectionList->fetch();
163 }
164 return is_array($this->fields);
165 }
166}