<?php
use Bitrix\Iblock\SectionTable;
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\Loader;
use Bitrix\Main\SystemException;
if (!Loader::includeModule('iblock')) {
throw new SystemException(
'Ошибка подключения модуля информационных блоков'
);
}
$elementId = 100;
$element = ElementTable::getRow([
'select' => [
'IBLOCK_SECTION_ID',
],
'filter' => [
'=ID' => $elementId,
],
]);
if ($element !== null) {
$parentSections = [];
$parentSectionIterator = SectionTable::getList([
'select' => [
'SECTION_ID' => 'SECTION_SECTION.ID',
'IBLOCK_SECTION_ID' => 'SECTION_SECTION.IBLOCK_SECTION_ID',
],
'filter' => [
'=ID' => $element['IBLOCK_SECTION_ID'],
],
'runtime' => [
'SECTION_SECTION' => [
'data_type' => '\Bitrix\Iblock\SectionTable',
'reference' => [
'=this.IBLOCK_ID' => 'ref.IBLOCK_ID',
'>=this.LEFT_MARGIN' => 'ref.LEFT_MARGIN',
'<=this.RIGHT_MARGIN' => 'ref.RIGHT_MARGIN',
],
'join_type' => 'inner'
],
],
]);
while ($parentSection = $parentSectionIterator->fetch()) {
$parentSections[$parentSection['SECTION_ID']] = $parentSection;
}
echo '<pre>';print_r($parentSections);echo '</pre>';
} else {
throw new SystemException(
sprintf('Элемент с ID "%d" не найден', $elementId)
);
}
1 комментарий
Хм. Прикольно