A
A
avshivtseva2019-08-16 16:08:29
1C-Bitrix
avshivtseva, 2019-08-16 16:08:29

How to display the name of the Highload property instead of ID?

Hello!
Can you please tell me how to display the property name instead of ID?
There is a HighloadBlock, one of the fields has the type "Binding to elements of highload blocks". I display a list of elements, and in this list the record ID from another highload block is displayed, but the Name is needed.

Array(
    [ID] => 1
    [UF_NAME] => Насосный агрегат ВГ 11-11А
    [UF_PRICE] => 8728.82
    [UF_VOLUME] => 2
    [UF_ORGANIZATION] => 1
)

Instead of [UF_ORGANIZATION] => 1 you need a name!
Here is the output code:
use Bitrix\Highloadblock\HighloadBlockTable as HL;

if (CModule::IncludeModule('highloadblock')) {   

$hlblock_id = 1; // ID вашего Highload-блока
$hlblock   = HL::getById( $hlblock_id )->fetch(); // получаем объект вашего HL блока
$entity   = HL::compileEntity( $hlblock );  // получаем рабочую сущность
$entity_data_class = $entity->getDataClass(); // получаем экземпляр класса
$entity_table_name = $hlblock['TABLE_NAME']; // присваиваем переменной название HL таблицы
$sTableID = 'tbl_'.$entity_table_name; // добавляем префикс и окончательно формируем название

$arFilter = array("UF_ORGANIZATION" => 1); // зададим фильтр по ID организации
$arSelect = array('*'); // выбираем все поля
$arOrder = array("ID"=>"ASC"); // сортировка будет по возрастанию ID статей
 
  
// подготавливаем данные
$rsData = $entity_data_class::getList(array(
    "select" => $arSelect,
    //"filter" => $arFilter,
    "limit" => '5', //ограничим выборку пятью элементами
    "order" => $arOrder
));

$result = new CDBResult($rsData);
   
// выполняем запрос. Передаем в него наши данные и название таблицы, которое мы получили в самом начале
//$rsData = new CDBResult($rsData, $sTableID); // записываем в переменную объект CDBResult

while($arRes = $result->Fetch()){
    echo "<pre>"; print_r($arRes); echo "</pre>";   
        //$rsGender = CUserFieldEnum::GetList(array("UF_NAME_ORG"), array("ID" => $arRes["UF_ORGANIZATION"]));
   //echo "<pre>"; print_r($rsGender); echo "</pre>";   
   }
}

If you draw a conclusion through CUserFieldEnum, then it displays such an object
CDBResult Object(
    [result] => 
    [arResult] => Array
        (
        )

    [arReplacedAliases] => 
    [arResultAdd] => 
    [bNavStart] => 
    [bShowAll] => 
    [NavNum] => 
    [NavPageCount] => 
    [NavPageNomer] => 
    [NavPageSize] => 
    [NavShowAll] => 
    [NavRecordCount] => 
    [bFirstPrintNav] => 1
    [PAGEN] => 
    [SIZEN] => 
    [SESS_SIZEN] => 
    [SESS_ALL] => 
    [SESS_PAGEN] => 
    [add_anchor] => 
    [bPostNavigation] => 
    [bFromArray] => 1
    [bFromLimited] => 
    [sSessInitAdd] => 
    [nPageWindow] => 5
    [nSelectedCount] => 0
    [arGetNextCache] => 
    [bDescPageNumbering] => 
    [arUserFields] => 
    [usedUserFields] => 
    [SqlTraceIndex] => 
    [DB] => 
    [NavRecordCountChangeDisable] => 
    [is_filtered] => 
    [nStartPage] => 0
    [nEndPage] => 0
    [resultObject] => 
)

what to do with it next?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
serginhold, 2019-08-16
@serginhold

look at what is in getMap(), perhaps there is already a ReferenceField,
but if not, then you can join it yourself

::getList([
    'runtime' => [
        'ELEMENT' => new Main\Entity\ReferenceField(
                'ELEMENT',
                ElementTable::class,
                [    // СМОТРИ ДОКУ ПО ORM: JOIN
                    '=this.UF_ORGANIZATION' => 'ref.ID',
                ],
                ['join_type' => 'INNER']
            ),
    ],
    'select' => [
        'ORGANIZATION_NAME' => 'ELEMENT.NAME',
    ]
])

K
Kudis, 2019-08-16
@kudis

No need to complicate)))

use Bitrix\Highloadblock\HighloadBlockTable as HL;

$sTableName = "hl_table_name";
$arFilter = ["UF_ORGANIZATION" => 1];
$arSelect = ["*"];
$arOrder = ["ID" => "ASC"];
$iLimit = 5;

CModule::IncludeModule("highloadblock");

$obHlBlock = HL::getList(["filter" => ["TABLE_NAME" => $sTableName]]);
if ($obHlData = $obHlBlock->fetch()) {

    $obEntity = HL::compileEntity($obHlData);
    $sEntityDataClass = $obEntity->getDataClass();

    $obRes = $sEntityDataClass::getList([
        "filter" => $arFilter,
        "select" => $arSelect,
        "order" => $arOrder,
        "limit" => $iLimit
    ]);
    while ($arRes = $obRes->fetch()) {
        echo "<pre>".print_r($arRes, true)."</pre>";
    }
}

so everything will work, just do not use the id of the highload, but use the name of the table - then, on projects with more than one, the developer will come in handy)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question