14 protected const ENTITY_ID =
'iblock-property-element';
19 parent::__construct();
26 return $GLOBALS[
'USER']->isAuthorized();
33 $filter = !empty($ids) ? [
'ID' => $ids] : [];
37 $items[] = $this->
makeItem($element);
55 $recentItems = $dialog->
getRecentItems()->getEntityItems(self::ENTITY_ID);
56 $recentItemsCount = count($recentItems);
58 if ($recentItemsCount < self::ELEMENTS_LIMIT)
60 $elements = $this->
getElements([], self::ELEMENTS_LIMIT);
61 foreach ($elements as $element)
75 $filter = $this->getQueryFilter($query);
78 $elements = $this->
getElements($filter, self::ELEMENTS_LIMIT);
79 if (count($elements) === self::ELEMENTS_LIMIT)
83 foreach ($elements as $element)
96 private function getQueryFilter(
string $query): array
99 '*SEARCHABLE_CONTENT' => $query,
103 protected function getElements(array $additionalFilter = [], ?
int $limit =
null): array
107 $filter = $this->getDefaultFilter();
108 if (!empty($additionalFilter))
110 $filter = array_merge($filter, $additionalFilter);
116 $navParams = [
'nTopCount' => $limit];
130 $elementData = \CIBlockElement::GetList(
137 while ($element = $elementData->fetch())
139 if (empty($element[
'PREVIEW_PICTURE']))
141 $element[
'PREVIEW_PICTURE'] = $this->getElementImage($element);
143 $elements[] = $element;
153 'id' => $element[
'ID'] ??
null,
155 'title' => $element[
'NAME'] ??
null,
156 'subtitle' => $element[
'ID'] ??
null,
157 'description' => $element[
'DETAIL_TEXT'] ??
null,
158 'avatar' => $element[
'PREVIEW_PICTURE'] ??
null,
160 'xmlId' => $element[
'XML_ID'] ??
null,
164 return new Item($itemParams);
167 private function getElementImage(array $element): ?string
169 $iblockId = $element[
'IBLOCK_ID'] ??
null;
175 $photoPropertyId = $this->getMorePhotoPropertyId($iblockId);
176 if (!$photoPropertyId)
182 'ID' => $photoPropertyId,
184 $result = \CIBlockElement::GetProperty($iblockId, $element[
'ID'],
'sort',
'asc', $propertyFilter)->Fetch();
186 if (empty($result[
'VALUE']))
191 if (is_array($result[
'VALUE']))
193 $imageId = (int)$result[
'VALUE'][0];
197 $imageId = (int)$result[
'VALUE'];
200 return $this->getImageSource($imageId);
203 private function getDefaultFilter()
206 'CHECK_PERMISSIONS' =>
'Y',
207 'MIN_PERMISSION' =>
'R',
210 $iblockId = (int)($this->
getOption(
'iblockId', 0));
211 if (!empty($iblockId))
213 $filter[
'IBLOCK_ID'] = $iblockId;
219 private function getMorePhotoPropertyId(
int $iblockId): ?int
224 '=IBLOCK_ID' => $iblockId,
225 '=CODE' => \CIBlockPropertyTools::CODE_MORE_PHOTO,
229 if ($row = $iterator->fetch())
231 return (
int)$row[
'ID'];
237 private function getImageSource(
int $id): ?string
244 $file = \CFile::GetFileArray($id);
250 return Tools::getImageSrc($file,
false) ?:
null;
static getList(array $parameters=array())
$GLOBALS['____1444769544']