Answer the question
In order to leave comments, you need to log in
How to use D7 to work with locations?
Let's say I want to map some additional data set to standard 2.0 locations
. I have 2 (well, 2.5 at most) ideas about this.
The first is to create a hayloidblock with additional data where in UF_LOCATION_ID to store the location id, and in the remaining fields the data I need. For the sake of simplicity, this will only be a character code for now, and since CODE is taken from locations, I will store it in XML_ID.
Then I have a head-to-head solution:
/*
* Возвращает дочерние локации по 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);
}
#
Answer the question
In order to leave comments, you need to log in
If I understood you correctly, then you need to use runtime, here is a small example, only using query instead of getList, but the meaning is the same
$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'
],
])
;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question