Answer the question
In order to leave comments, you need to log in
All elements from nested sections on D7?
There is a section in which there are more sections with elements. You need to display all elements by the ID of the parent element on D7.
$dbItems = \Bitrix\Iblock\ElementTable::getList(array(
'select' => array('ID', 'NAME', 'IBLOCK_ID'),
'filter' => array('IBLOCK_ID' => 8, 'IBLOCK_SECTION_ID ' => 5)
));
Answer the question
In order to leave comments, you need to log in
google what nested sets are, figure out how to get a section and all children, write a query in pure sql to b_iblock_section_element, join elements by IBLOCK_ELEMENT_ID to the result,
as you figure it out, transfer your query to orm D7
So it is possible:
$sectionId = 5;
$iblockId = 8;
$section = \Bitrix\Iblock\SectionTable::getByPrimary($sectionId, [
'filter' => ['IBLOCK_ID' => $iblockId],
'select' => ['LEFT_MARGIN', 'RIGHT_MARGIN'],
])->fetch();
$dbItems = \Bitrix\Iblock\ElementTable::getList([
'select' => ['ID', 'NAME', 'IBLOCK_ID'],
'filter' => [
'IBLOCK_ID' => $iblockId,
'>=IBLOCK_SECTION.LEFT_MARGIN' => $section['LEFT_MARGIN'],
'<=IBLOCK_SECTION.RIGHT_MARGIN' => $section['RIGHT_MARGIN'],
],
]);
$sectionId = 5;
$iblockId = 8;
$sectionsIds = getSubsections($sectionId, $iblockId);
$dbItems = \Bitrix\Iblock\ElementTable::getList([
'select' => ['ID', 'NAME', 'IBLOCK_ID'],
'filter' => [
'IBLOCK_ID' => $iblockId,
'IBLOCK_SECTION_ID' => $sectionsIds,
],
]);
function getSubsections(int $sectionId, int $iblockId): array
{
$sectionsIds = [];
$connection = \Bitrix\Main\Application::getConnection();
$sql = sprintf('SELECT cs.ID FROM %1$s AS ps
INNER JOIN %1$s AS cs
ON ps.LEFT_MARGIN <= cs.LEFT_MARGIN AND ps.RIGHT_MARGIN >= cs.RIGHT_MARGIN AND ps.IBLOCK_ID = cs.IBLOCK_ID
WHERE ps.ID = %2$d AND ps.IBLOCK_ID = %3$d',
\Bitrix\Iblock\SectionTable::getTableName(),
$sectionId,
$iblockId
);
$result = $connection->query($sql);
while ($section = $result->fetch()) {
$sectionsId[] = $section['ID'];
}
return $sectionsIds;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question