Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
IblockPropertyElementXmlProvider.php
1<?php
2
4
8
10{
11 protected const ENTITY_ID = 'iblock-property-element-xml';
12
13 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
14 {
15 $filter = [];
16
17 $query = $searchQuery->getQuery();
18 if ($query !== '')
19 {
20 $filter = $this->getQueryFilter($query);
21 }
22
23 $elements = $this->getElements($filter, self::ELEMENTS_LIMIT);
24 if (count($elements) === self::ELEMENTS_LIMIT)
25 {
26 $searchQuery->setCacheable(false);
27 }
28 foreach ($elements as $element)
29 {
30 $dialog->addItem(
31 $this->makeItem($element)
32 );
33 }
34 }
35
36 private function getQueryFilter(string $query): array
37 {
38 return [
39 [
40 'LOGIC' => 'OR',
41 '%XML_ID' => $query,
42 '*SEARCHABLE_CONTENT' => $query,
43 ],
44 ];
45 }
46
47 protected function makeItem(array $element, string $propertyType = ''): Item
48 {
49 $itemParams = [
50 'id' => $element['ID'] ?? null,
51 'entityId' => self::ENTITY_ID,
52 'title' => $element['NAME'] ?? null,
53 'subtitle' => $element['XML_ID'] ?? null,
54 'description' => $element['DETAIL_TEXT'] ?? null,
55 'avatar' => $element['PREVIEW_PICTURE'] ?? null,
56 'customData' => [
57 'xmlId' => $element['XML_ID'] ?? null,
58 ],
59 ];
60
61 return new Item($itemParams);
62 }
63}