- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/publicaction/utils.php
- Класс: BitrixLandingPublicActionUtils
- Вызов: Utils::catalogSearch
static function catalogSearch($query = null, $type = self::TYPE_CATALOG_ALL, $iblock = null, $siteId = null)
{
$publicResult = new PublicActionResult();
if (!$iblock)
{
BitrixLandingHook::setEditMode(true);
$settings = BitrixLandingHookPageSettings::getDataForSite(
$siteId
);
$iblockId = $settings['IBLOCK_ID'];
}
else
{
$iblockId = $iblock;
}
if (!Loader::includeModule('iblock'))
{
$publicResult->setResult([]);
return $publicResult;
}
$data = [];
// make some magic
$filter = [
'IBLOCK_ID' => $iblockId,
array_merge(
['LOGIC' => 'AND'],
array_map(function($fragment) {
return ['%NAME' => trim($fragment)];
}, explode(' ', trim($query)))
)
];
// search in all catalog or in element
if (
$type === self::TYPE_CATALOG_ALL ||
$type === self::TYPE_CATALOG_ELEMENT)
{
$order = [];
$groupBy = false;
$navParams = ['nTopCount' => 50];
$select = [
'ID', 'NAME', 'IBLOCK_SECTION_ID', 'DETAIL_PICTURE'
];
$result = CIBlockElement::getList(
$order, $filter, $groupBy, $navParams, $select
);
while ($item = $result->fetch())
{
$chain = [];
static::makeCatalogEntityNavChain(
$item['IBLOCK_SECTION_ID'],
$chain
);
$data[] = [
'name' => $item['NAME'],
'id' => $item['ID'],
'image' => CFile::getPath($item['DETAIL_PICTURE']),
'type' => self::TYPE_CATALOG,
'subType' => self::TYPE_CATALOG_ELEMENT,
'chain' => $chain
];
}
}
// search in all catalog or in section
if (
$type === self::TYPE_CATALOG_ALL ||
$type === self::TYPE_CATALOG_SECTION
)
{
$order = [];
$select = [
'ID', 'NAME', 'IBLOCK_SECTION_ID', 'DETAIL_PICTURE'
];
$filter = [
'IBLOCK_ID' => $iblockId, '%NAME' => trim($query)
];
$count = false;
$sectResult = CIBlockSection::GetList($order, $filter, $count, $select);
while ($item = $sectResult->Fetch())
{
$chain = [];
static::makeCatalogEntityNavChain(
$item['IBLOCK_SECTION_ID'],
$chain
);
$data[] = [
'name' => trim($item['NAME']),
'id' => $item['ID'],
'image' => '',
'type' => self::TYPE_CATALOG,
'subType' => self::TYPE_CATALOG_SECTION,
'chain' => !empty($chain) ? $chain : ['/']
];
}
}
$publicResult->setResult($data);
return $publicResult;
}