15 private const ELEMENTS_LIMIT = 20;
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)
74 $filter = $this->getQueryFilter($query);
78 foreach ($elements as $element)
91 private function getQueryFilter(
string $query): array
94 '*SEARCHABLE_CONTENT' => $query,
98 protected function getElements(array $additionalFilter = []): array
102 $filter = $this->getDefaultFilter();
103 if (!empty($additionalFilter))
105 $filter = array_merge($filter, $additionalFilter);
108 $navParams = [
'nTopCount' => self::ELEMENTS_LIMIT];
121 $elementData = \CIBlockElement::GetList(
128 while ($element = $elementData->fetch())
130 if (empty($element[
'PREVIEW_PICTURE']))
132 $element[
'PREVIEW_PICTURE'] = $this->getElementImage($element);
134 $elements[] = $element;
144 'id' => $element[
'ID'] ??
null,
146 'title' => $element[
'NAME'] ??
null,
147 'subtitle' => $element[
'ID'] ??
null,
148 'description' => $element[
'DETAIL_TEXT'] ??
null,
149 'avatar' => $element[
'PREVIEW_PICTURE'] ??
null,
151 'xmlId' => $element[
'XML_ID'] ??
null,
155 return new Item($itemParams);
158 private function getElementImage(array $element): ?string
160 $iblockId = $element[
'IBLOCK_ID'] ??
null;
166 $photoPropertyId = $this->getMorePhotoPropertyId($iblockId);
167 if (!$photoPropertyId)
173 'ID' => $photoPropertyId,
175 $result = \CIBlockElement::GetProperty($iblockId, $element[
'ID'],
'sort',
'asc', $propertyFilter)->Fetch();
177 if (empty($result[
'VALUE']))
182 if (is_array($result[
'VALUE']))
184 $imageId = (int)$result[
'VALUE'][0];
188 $imageId = (int)$result[
'VALUE'];
191 return $this->getImageSource($imageId);
194 private function getDefaultFilter()
197 'CHECK_PERMISSIONS' =>
'Y',
198 'MIN_PERMISSION' =>
'R',
201 $iblockId = (int)($this->
getOption(
'iblockId', 0));
202 if (!empty($iblockId))
204 $filter[
'IBLOCK_ID'] = $iblockId;
210 private function getMorePhotoPropertyId(
int $iblockId): ?int
212 $iterator = PropertyTable::getList([
215 '=IBLOCK_ID' => $iblockId,
216 '=CODE' => \CIBlockPropertyTools::CODE_MORE_PHOTO,
220 if ($row = $iterator->fetch())
222 return (
int)$row[
'ID'];
228 private function getImageSource(
int $id): ?string
235 $file = \CFile::GetFileArray($id);
241 return Tools::getImageSrc($file,
false) ?:
null;
$GLOBALS['____1444769544']