Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectiontable.php
1<?php
2namespace Bitrix\Iblock;
3
7
8Loc::loadMessages(__FILE__);
9
61{
62 private static array $oldValues = [];
63
69 public static function getTableName()
70 {
71 return 'b_iblock_section';
72 }
73
79 public static function getMap()
80 {
81 return array(
82 'ID' => array(
83 'data_type' => 'integer',
84 'primary' => true,
85 'autocomplete' => true,
86 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_ID_FIELD'),
87 ),
88 'TIMESTAMP_X' => array(
89 'data_type' => 'datetime',
90 'required' => true,
91 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_TIMESTAMP_X_FIELD'),
92 ),
93 'MODIFIED_BY' => array(
94 'data_type' => 'integer',
95 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_MODIFIED_BY_FIELD'),
96 ),
97 'DATE_CREATE' => array(
98 'data_type' => 'datetime',
99 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_DATE_CREATE_FIELD'),
100 ),
101 'CREATED_BY' => array(
102 'data_type' => 'integer',
103 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_CREATED_BY_FIELD'),
104 ),
105 'IBLOCK_ID' => array(
106 'data_type' => 'integer',
107 'required' => true,
108 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_IBLOCK_ID_FIELD'),
109 ),
110 'IBLOCK_SECTION_ID' => array(
111 'data_type' => 'integer',
112 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_IBLOCK_SECTION_ID_FIELD'),
113 ),
114 'ACTIVE' => array(
115 'data_type' => 'boolean',
116 'values' => array('N', 'Y'),
117 'default_value' => 'Y',
118 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_ACTIVE_FIELD'),
119 ),
120 'GLOBAL_ACTIVE' => array(
121 'data_type' => 'boolean',
122 'values' => array('N', 'Y'),
123 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_GLOBAL_ACTIVE_FIELD'),
124 ),
125 'SORT' => array(
126 'data_type' => 'integer',
127 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_SORT_FIELD'),
128 ),
129 'NAME' => array(
130 'data_type' => 'string',
131 'required' => true,
132 'validation' => array(__CLASS__, 'validateName'),
133 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_NAME_FIELD'),
134 ),
135 'PICTURE' => array(
136 'data_type' => 'integer',
137 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_PICTURE_FIELD'),
138 ),
139 'LEFT_MARGIN' => array(
140 'data_type' => 'integer',
141 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_LEFT_MARGIN_FIELD'),
142 ),
143 'RIGHT_MARGIN' => array(
144 'data_type' => 'integer',
145 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_RIGHT_MARGIN_FIELD'),
146 ),
147 'DEPTH_LEVEL' => array(
148 'data_type' => 'integer',
149 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_DEPTH_LEVEL_FIELD'),
150 ),
151 'DESCRIPTION' => array(
152 'data_type' => 'text',
153 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_DESCRIPTION_FIELD'),
154 ),
155 'DESCRIPTION_TYPE' => array(
156 'data_type' => 'enum',
157 'required' => true,
158 'values' => array('text', 'html'),
159 'default_value' => 'text',
160 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_DESCRIPTION_TYPE_FIELD'),
161 ),
162 'SEARCHABLE_CONTENT' => array(
163 'data_type' => 'text',
164 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_SEARCHABLE_CONTENT_FIELD'),
165 ),
166 'CODE' => array(
167 'data_type' => 'string',
168 'validation' => array(__CLASS__, 'validateCode'),
169 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_CODE_FIELD'),
170 ),
171 'XML_ID' => array(
172 'data_type' => 'string',
173 'validation' => array(__CLASS__, 'validateXmlId'),
174 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_XML_ID_FIELD'),
175 ),
176 'TMP_ID' => array(
177 'data_type' => 'string',
178 'validation' => array(__CLASS__, 'validateTmpId'),
179 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_TMP_ID_FIELD'),
180 ),
181 'DETAIL_PICTURE' => array(
182 'data_type' => 'integer',
183 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_DETAIL_PICTURE_FIELD'),
184 ),
185 'SOCNET_GROUP_ID' => array(
186 'data_type' => 'integer',
187 'title' => Loc::getMessage('IBLOCK_SECTION_ENTITY_SOCNET_GROUP_ID_FIELD'),
188 ),
189 'IBLOCK' => array(
190 'data_type' => 'Bitrix\Iblock\Iblock',
191 'reference' => array('=this.IBLOCK_ID' => 'ref.ID'),
192 ),
193 'PARENT_SECTION' => array(
194 'data_type' => 'Bitrix\Iblock\Section',
195 'reference' => array('=this.IBLOCK_SECTION_ID' => 'ref.ID'),
196 ),
197 'CREATED_BY_USER' => array(
198 'data_type' => 'Bitrix\Main\User',
199 'reference' => array('=this.CREATED_BY' => 'ref.ID'),
200 ),
201 'MODIFIED_BY_USER' => array(
202 'data_type' => 'Bitrix\Main\User',
203 'reference' => array('=this.MODIFIED_BY' => 'ref.ID'),
204 ),
205 );
206 }
207
213 public static function validateName()
214 {
215 return array(
216 new ORM\Fields\Validators\LengthValidator(null, 255),
217 );
218 }
219
225 public static function validateCode()
226 {
227 return array(
228 new ORM\Fields\Validators\LengthValidator(null, 255),
229 );
230 }
231
237 public static function validateXmlId()
238 {
239 return array(
240 new ORM\Fields\Validators\LengthValidator(null, 255),
241 );
242 }
243
249 public static function validateTmpId()
250 {
251 return array(
252 new ORM\Fields\Validators\LengthValidator(null, 40),
253 );
254 }
255
256 public static function onAfterAdd(Event $event)
257 {
259 $section = $event->getParameter('object');
260 $section->fill(['IBLOCK_ID', 'IBLOCK_SECTION_ID', 'NAME', 'SORT']);
261
262 // clear tag cache
263 \CIBlock::clearIblockTagCache($section->getIblockId());
264
265 // recount tree
266 \CIBlockSection::recountTreeAfterAdd($section->collectValues());
267 }
268
269 public static function onUpdate(Event $event)
270 {
272 $section = $event->getParameter('object');
273
274 // save old fields
275 $row = static::getRow([
276 'select' => [
277 'ID',
278 'IBLOCK_ID',
279 'SORT',
280 'NAME',
281 'IBLOCK_SECTION_ID',
282 'LEFT_MARGIN',
283 'RIGHT_MARGIN',
284 'DEPTH_LEVEL',
285 'ACTIVE',
286 ],
287 'filter' => [
288 '=ID' => $section->getId(),
289 ],
290 ]);
291 self::$oldValues = $row !== null ? $row : [];
292 }
293
294 public static function onAfterUpdate(Event $event)
295 {
297 $section = $event->getParameter('object');
298 $section->fill(['IBLOCK_ID', 'IBLOCK_SECTION_ID', 'NAME', 'SORT', 'ACTIVE']);
299
300 // clear tag cache
301 \CIBlock::clearIblockTagCache($section->getIblockId());
302
303 // recount tree
304 \CIBlockSection::recountTreeAfterUpdate($section->collectValues(), self::$oldValues);
305 self::$oldValues = [];
306 }
307
308 public static function onDelete(Event $event)
309 {
310 $section = static::wakeUpObject($event->getParameter('id'));
311 $section->fill(['IBLOCK_ID']);
312
313 // clear tag cache
314 \CIBlock::clearIblockTagCache($section->getIblockId());
315 }
316
317 public static function onAfterDelete(Event $event)
318 {
319 // recount tree
320 $primary = $event->getParameter('id');
321 if (!is_array($primary))
322 {
323 $primary = ['ID' => $primary];
324 }
325 \CIBlockSection::recountTreeOnDelete($primary);
326 }
327}
static onDelete(Event $event)
static onAfterDelete(Event $event)
getParameter($key)
Definition event.php:80
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static onAfterUpdate(Event $event)
static onAfterAdd(Event $event)