60 lines
1.5 KiB
PHP

<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
/** @var CBitrixComponent $this */
/** @var array $arParams */
/** @var array $arResult */
/** @var string $componentPath */
/** @var string $componentName */
/** @var string $componentTemplate */
/** @global CDatabase $DB */
/** @global CUser $USER */
/** @global CMain $APPLICATION */
use Bitrix\Main\Context,
Bitrix\Main\Type\DateTime,
Bitrix\Main\Loader,
Bitrix\Iblock;
if($this->StartResultCache(60*60*24, md5(var_export($_POST, true))))
{
if(CModule::IncludeModule('iblock'))
{
$sanitizer = new CBXSanitizer;
$arResult = [
'SECTIONS' => [],
];
$query = sanitize_string($sanitizer->SanitizeHtml($_REQUEST['search']), true, true, true);
$arResult['SEARCH'] = $query;
$sort = Array("SORT" => "ASC", "NAME" => "ASC");
$filter = Array("ACTIVE" => "Y", "IBLOCK_ID" => 19);
$options = false;
$sec_res = CIBlockSection::GetList($sort, $filter, false, [], false);
while ($section = $sec_res->GetNext())
{
$section['ITEMS'] = [];
$filter = array_merge($filter, [ "SECTION_ID" => $section['ID'] ]);
if(!empty($query))
{
$filter = array_merge($filter, [ "SEARCHABLE_CONTENT" => "%".$query."%" ]);
}
$res = CIBlockElement::GetList($sort, $filter, false, $options);
while ($element = $res->GetNextElement())
{
$ar_res = $element->GetFields();
$section['ITEMS'][] = $ar_res;
}
if(count($section['ITEMS']) > 0)
{
$arResult['SECTIONS'][] = $section;
}
}
$this->IncludeComponentTemplate();
}
}