/*
* Возвращает дочерние локации по id родителя
*/
public function getChildrensById ($id,$key='ID') {
$res = \Bitrix\Sale\Location\LocationTable::getList(array(
'filter' => array(
'=ID' => intval($id),
'=CHILDREN.NAME.LANGUAGE_ID' => 'ru',
//'=CHILDREN.TYPE.NAME.LANGUAGE_ID' => LANGUAGE_ID,
),
'select' => array(
'_ID' => 'CHILDREN.ID',
'CODE' => 'CHILDREN.CODE',
'DEPTH_LEVEL' => 'CHILDREN.DEPTH_LEVEL',
'LATITUDE' => 'CHILDREN.LATITUDE',
'LONGITUDE' => 'CHILDREN.LONGITUDE',
'NAME_RU' => 'CHILDREN.NAME.NAME',
'TYPE_CODE' => 'CHILDREN.TYPE.CODE',
//'TYPE_NAME_RU' => 'CHILDREN.TYPE.NAME.NAME'
),
'order' => array(
'CHILDREN.NAME.NAME' => 'ASC'
)
));
$arLocations = [];
while($item = $res->fetch()) {
$item['ID'] = $item['_ID'];
$arLocations[$item[$key]] = $item;
}
$this->addExtData($arLocations);
return $arLocations;
}
#
/*
* Добавляет допданные из таблицы locode
*/
public function addExtData (&$arLocations) {
$IDs = array_column($arLocations,'ID');
$rsData = $this->locodes_data_class::getList(array(
'select' => ['UF_XML_ID','UF_LOCATION_ID'],
'filter' => ['UF_LOCATION_ID'=>$IDs]
));
$arRefExtData = [];
while ($arRow = $rsData->Fetch()) {
$arRefExtData[$arRow['UF_LOCATION_ID']] = [
'XML_ID' => $arRow['UF_XML_ID']
];
}
$arLocations = array_map(function ($arLoc) use ($arRefExtData) {
$arLoc = array_merge($arRefExtData[$arLoc['ID']],$arLoc);
return $arLoc;
},$arLocations);
}
#
$query = \Entities\Marketing\PostingTmpTable::query()
->registerRuntimeField('CONTACT', [
'data_type' => '\Bitrix\Sender\ContactTable',
'reference' => [
'=this.CONTACT_ID' => 'ref.ID',
],
])
->registerRuntimeField('PROPERTY', [
'data_type' => $hlBlockEntity,
'reference' => [
'=this.CONTACT.CODE' => 'ref.UF_EMAIL'
],
])
;
Как-то можно используя возможности D7 извлечь допданные сразу, в том же запросе, где извлекаются данные по локациям?
$res = \Bitrix\Sale\Location\LocationTable::getList([
'filter' => [
'=ID' => intval($id),
'=CHILDREN.NAME.LANGUAGE_ID' => 'ru',
],
'select' => [
'_ID' => 'CHILDREN.ID',
'CODE' => 'CHILDREN.CODE',
'DEPTH_LEVEL' => 'CHILDREN.DEPTH_LEVEL',
'LATITUDE' => 'CHILDREN.LATITUDE',
'LONGITUDE' => 'CHILDREN.LONGITUDE',
'NAME_RU' => 'CHILDREN.NAME.NAME',
'TYPE_CODE' => 'CHILDREN.TYPE.CODE',
'UF_XML_ID' => 'LOCODES.UF_XML_ID',
'UF_LOCATION_ID' => 'LOCODES.UF_LOCATION_ID',
],
'runtime' => [
new \Bitrix\Main\Entity\ReferenceField(
'LOCODES',
$this->locodes_data_class,
['=this.ID' => 'ref.UF_LOCATION_ID'],
['join_type' => 'LEFT']
)
],
'order' => [
'CHILDREN.NAME.NAME' => 'ASC'
]
]);