- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/dataloader/landing.php
- Класс: BitrixLandingDataLoaderLanding
- Вызов: Landing::getElementListData
public function getElementListData()
{
$this->seo->clear();
$needPreviewPicture = false;
$needPreviewText = false;
$needLink = true;//always
// select
$select = $this->getPreparedSelectFields();
if (empty($select))
{
return [];
}
// filter
$filter = $this->getInternalFilter();
$contextFilter = $this->getOptionsValue('context_filter');
$cache = $this->getOptionsValue('cache');
if (empty($filter))
{
$filter = [];
}
if (isset($contextFilter['SITE_ID']))
{
$filter['SITE_ID'] = $contextFilter['SITE_ID'];
}
if (isset($contextFilter['LANDING_ACTIVE']))
{
$filter['=ACTIVE'] = $contextFilter['LANDING_ACTIVE'];
}
$filter['==AREAS.ID'] = null;
// select, order
$order = [];
$select[] = 'ID';
$rawOrder = $this->getOrder();
if (isset($rawOrder['by']) && isset($rawOrder['order']))
{
$order[$rawOrder['by']] = $rawOrder['order'];
if (!in_array($rawOrder['by'], $select))
{
$select[] = $rawOrder['by'];
}
}
foreach ($select as $i => $code)
{
if ($code == 'IMAGE')
{
$needPreviewPicture = true;
unset($select[$i]);
}
else if ($code == 'DESCRIPTION')
{
$needPreviewText = true;
unset($select[$i]);
}
else if ($code == 'LINK')
{
$needLink = true;
unset($select[$i]);
}
}
// limit
$limit = $this->getLimit();
if ($limit <= 0)
{
$limit = 10;
}
$searchContent = [];
$query = $this->getSearchQuery();
if ($query)
{
if ($cache instanceof CPHPCache)
{
$cache->abortDataCache();
}
if (mb_strlen($query) < 3)
{
return [];
}
// search in blocks
$blockFilter = [];
if (isset($filter['SITE_ID']))
{
$blockFilter['LANDING.SITE_ID'] = $filter['SITE_ID'];
}
$blocks = Block::search(
$query,
$blockFilter,
['LID', 'ID', 'SEARCH_CONTENT']
);
$landingBlocksIds = [];
foreach ($blocks as $block)
{
$searchContent[$block['LID']] = $this->getSearchSnippet($query, $block['SEARCH_CONTENT']);
if (!$searchContent[$block['LID']])
{
unset($searchContent[$block['LID']]);
}
$landingBlocksIds[] = $block['LID'];
}
// merge filter with search query
$filter[] = [
'LOGIC' => 'OR',
'TITLE' => '%' . $query . '%',
'*%SEARCH_CONTENT' => $query,
'ID' => $landingBlocksIds ? $landingBlocksIds : [-1]
];
}
// get data
$result = [];
$res = LandingCore::getList([
'select' => $select,
'filter' => $filter,
'order' => $order,
'limit' => $limit
]);
while ($row = $res->fetch())
{
Cache::register($row['ID']);
$result[$row['ID']] = [
'TITLE' => htmlspecialcharsbx($row['TITLE'])
];
}
// get meta data
$metaData = [];
if (
$needPreviewPicture ||
$needPreviewText
)
{
$metaData = $this->getMetadata(
array_keys($result)
);
}
// and feel result data with meta data
foreach ($result as $id => &$item)
{
if (
$needPreviewPicture &&
isset($metaData[$id]['IMAGE'])
)
{
$item['IMAGE'] = [
'src' => $metaData[$id]['IMAGE'],
'alt' => $item['TITLE'] ?? ''
];
}
if ($needPreviewText)
{
if (isset($searchContent[$id]))
{
$item['DESCRIPTION'] = htmlspecialcharsbx($searchContent[$id]);
}
else if (isset($metaData[$id]['DESCRIPTION']))
{
$item['DESCRIPTION'] = htmlspecialcharsbx($metaData[$id]['DESCRIPTION']);
}
}
if ($needLink)
{
$item['LINK'] = '#landing' . $id;
}
if ($query)
{
$item['_GET'] = [
'q' => $query
];
}
}
return array_values($result);
}