F
F
faragly2015-06-29 13:05:39
PHP
faragly, 2015-06-29 13:05:39

How to make a complex getList request in 1C-Bitrix?

Hello! There are highloadblock elements, the infoblock element id is stored in the UF_ELEMENT_ID field. The next question is how to make a complex getList request for a selection from a highloadblock so that I can immediately get some fields (name, properties) of the linked infoblock element? The selection is currently being made

use Bitrix\Highloadblock as HL;
Bitrix\Main\Loader::includeModule('highloadblock');

$hlblock = HL\HighloadBlockTable::getById($hlBlockId)->fetch(); // $hlBlockId = 11
$entity = HL\HighloadBlockTable::compileEntity($hlblock);
$dataClass = $entity->getDataClass();
$result = $dataClass::getList([
  "select" => array('*'), //выбираем все поля
]);
$arCache = [];
while($arElement = $result->fetch())
{
  // тут у меня каждый элемент обрабатывается, делаю запрос и кэширую, чтобы обращаться 1 раз
  if (!array_key_exists($arElement["UF_ELEMENT_ID"], $arCache))
  {
    $res = CIBlockElement::GetByID($arElement["UF_ELEMENT_ID"]);
    $arCache[$arElement["UF_ELEMENT_ID"]] = $res->Fetch();
  }
  // тут собираю все в один массив
}

Is it possible to bring all this into one getList?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Maksimenko, 2015-07-14
@faragly

Something like this, if you need infoblock fields:

use Bitrix\Main\Application;
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Loader;

Loader::includeModule('highloadblock');
Loader::includeModule('iblock');

$hlBlockId = 2;

$hlblock = HighloadBlockTable::getById($hlBlockId)->fetch();

/** @var \Bitrix\Main\Entity\Base $entity */
$entity = HighloadBlockTable::compileEntity($hlblock);

/** @var \Bitrix\Main\Entity\DataManager $dataClass */
$dataClass = $entity->getDataClass();

Application::getConnection()->startTracker();

$result = $dataClass::getList([
    'select' => array(
        'UF_ELEMENT_ID',
        'NAME' => 'ELEMENT.NAME',
        'CODE' => 'ELEMENT.CODE',
        'DETAIL_PICTURE' => 'ELEMENT.DETAIL_PICTURE',
    ),
    'runtime' => array(
        'ELEMENT' => array(
            'data_type' => '\Bitrix\Iblock\ElementTable',
            'reference' => array(
                '=this.UF_ELEMENT_ID' => 'ref.ID'
            ),
            'join_type' => 'inner'
        ),
    ),
    'limit' => 10,
]);

// Можно смотреть сформированный запрос
echo '<pre>', $result->getTrackerQuery()->getSql(), '</pre>';

while ($row = $result->fetch()) {
    echo '<pre>';print_r($row);echo '</pre>';
}

Property is a little more complicated.
PS some examples using ORM D7

A
Artyom, 2015-07-01
@At0m1c

Write the data to an array and then use the GetList() method. Remove from the GetByID() loop, don't do that.

while($arElement = $result->fetch()) {
   $arElements[] = $arElement;
}
$res = CIBlockElement::GetList(...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question