- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/search/wordchain.php
- Класс: BitrixSaleLocationSearchWordChainTable
- Вызов: WordChainTable::reInitData
static function reInitData($parameters = array())
{
static::createTables();
$offset = 0;
$stat = array();
$types = array();
$typeSort = array();
$res = LocationTypeTable::getList(array('select' => array('ID', 'CODE', 'SORT')));
$allowedTypes = array('REGION', 'SUBREGION', 'CITY', 'VILLAGE', 'STREET');
while($item = $res->fetch())
{
if(in_array($item['CODE'], $allowedTypes))
$types[$item['CODE']] = $item['ID'];
$typeSort[$item['ID']] = $item['SORT'];
}
$typesBack = array_flip($types);
//print_r($types);
//_print_r($typeSort);
$wordChain = array();
$pathChain = array();
//_dump_r('GO!');
$prevDepth = 0;
while(true)
{
$res = LocationLocationTable::getList(array(
'select' => array(
'ID',
'TYPE_ID',
'LNAME' => 'NAME.NAME',
'DEPTH_LEVEL',
'SORT'
),
'filter' => array(
'=TYPE_ID' => array_values($types),
'=NAME.LANGUAGE_ID' => LANGUAGE_ID
),
'order' => array(
'LEFT_MARGIN' => 'asc'
),
'limit' => self::STEP_SIZE,
'offset' => $offset
));
$cnt = 0;
while($item = $res->fetch())
{
if($item['DEPTH_LEVEL'] < $prevDepth)
{
//print('DROP to '.$item['DEPTH_LEVEL'].'
');
// drop chain to DEPTH_LEVEL inclusively
$newWC = array();
$newPC = array();
foreach($wordChain as $dl => $name)
{
if($dl >= $item['DEPTH_LEVEL'])
break;
$newWC[$dl] = $name;
}
$wordChain = $newWC;
foreach($pathChain as $dl => $id)
{
if($dl >= $item['DEPTH_LEVEL'])
break;
$newPC[$dl] = $id;
}
$pathChain = $newPC;
}
$wordChain[$item['DEPTH_LEVEL']] = $item['LNAME'];
$pathChain[$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']);
$prevDepth = $item['DEPTH_LEVEL'];
//print($item['DEPTH_LEVEL'].' - '.implode(' ', WordStatTable::parseQuery(implode(' ', $wordChain))).'
');
$parsed = WordStatTable::parseQuery(implode(' ', $wordChain));
$wordMap = array();
$i = 1;
foreach($parsed as $word)
{
$wordMap['W_'.$i] = $word;
$i++;
}
$pathMap = array();
foreach($pathChain as $elem)
$pathMap[$typesBack[$elem['TYPE']].'_ID'] = $elem['ID'];
$data = array_merge($wordMap, $pathMap, array(
'LOCATION_ID' => $item['ID'],
'TYPE_ID' => $item['TYPE_ID'],
'TYPE_SORT' => $typeSort[$item['TYPE_ID']],
'SORT' => $item['SORT'],
'WORD_COUNT' => count($wordMap)
));
//print('');
//print('');
try
{
static::add($data);
}
catch(Exception $e)
{
_dump_r('Cant add '.implode(' ', $wordChain).' ('.count($wordMap).')
');
// duplicate or smth
}
$cnt++;
}
if(!$cnt)
break;
$offset += self::STEP_SIZE;
}
}