Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
selectorprovider.php
1<?php
3
11
13{
18 protected static $searchPhrase = null;
19
25 public function __construct(array $options = [])
26 {
27 parent::__construct();
28 }
29
34 public function isAvailable(): bool
35 {
36 return true;
37 }
38
45 public static function getFolders(int $siteId, ?int $parentId = null): array
46 {
47 $data = [];
48 $filter = [];
49
50 if (self::$searchPhrase)
51 {
52 $filter['?TITLE'] = '%' . self::$searchPhrase . '%';
53 }
54 else
55 {
56 $filter['PARENT_ID'] = abs($parentId);
57 }
58
59 $folders = Site::getFolders($siteId, $filter);
60
61 foreach ($folders as $folder)
62 {
63 $data[$folder['ID']] = new Item([
64 'id' => -1 * $folder['ID'],
65 'entityId' => 'landing',
66 'entityType' => 'folder',
67 'title' => $folder['TITLE'],
68 'nodeOptions' => ['dynamic' => true]
69 ]);
70 }
71
72 return $data;
73 }
74
82 public static function getLandings(int $siteId, ?int $landingId = null, ?int $parentId = null): array
83 {
84 $data = [];
85 $landingFake = Landing::createInstance(0);
86 $filter = ['SITE_ID' => $siteId];
87
88 // search in folders first (if search mode)
89 if (self::$searchPhrase)
90 {
91 $folders = Site::getFolders($siteId, [
92 '?TITLE' => '%' . self::$searchPhrase . '%'
93 ]);
94 if ($folders)
95 {
96 $filterSub = ['LOGIC' => 'OR'];
97 $filterSub['?TITLE'] = '%' . self::$searchPhrase . '%';
98 $filterSub['FOLDER_ID'] = [];
99 foreach ($folders as $folder)
100 {
101 $filterSub['FOLDER_ID'][] = $folder['ID'];
102 }
103 $filter[] = $filterSub;
104 }
105 else
106 {
107 $filter['?TITLE'] = '%' . self::$searchPhrase . '%';
108 }
109 }
110 else
111 {
112 $filter['FOLDER_ID'] = abs($parentId);
113 }
114
115 $rows = [];
116 $res = Landing::getList([
117 'select' => [
118 'ID', 'TITLE', 'FOLDER_ID', 'SITE_ID',
119 'DOMAIN_ID' => 'SITE.DOMAIN_ID'
120 ],
121 'filter' => $filter,
122 'order' => [
123 'DATE_MODIFY' => 'desc'
124 ]
125 ]);
126 while ($row = $res->fetch())
127 {
128 $rows[$row['ID']] = $row;
129 }
130
131 if ($rows)
132 {
133 $urls = $landingFake->getPublicUrl(array_keys($rows));
134 }
135
136 foreach ($rows as $row)
137 {
138 $subtitle = null;
139 if (self::$searchPhrase && $row['FOLDER_ID'])
140 {
141 $subtitle = Folder::getBreadCrumbsString($row['FOLDER_ID'], ' / ', $row['SITE_ID']);
142 }
143 $data[$row['ID']] = new Item([
144 'id' => $row['ID'],
145 'selected' => $row['ID'] == $landingId,
146 'entityId' => 'landing',
147 'entityType' => 'landing',
148 'title' => $row['TITLE'],
149 'avatar' => $landingFake->getPreview($row['ID'], $row['DOMAIN_ID'] == 0, $urls[$row['ID']]),
150 'subtitle' => $subtitle ?: ''
151 ]);
152 }
153
154 return $data;
155 }
156
162 protected function getSiteIdFromDialog(Dialog $dialog): ?int
163 {
164 $entity = $dialog->getEntities()['landing'] ?? null;
165 if ($entity)
166 {
167 if ($siteId = $entity->getOptions()['siteId'] ?? null)
168 {
169 Type::setScope($entity->getOptions()['siteType']);
170 return $siteId;
171 }
172 }
173
174 return null;
175 }
176
182 protected function getLandingIdFromDialog(Dialog $dialog): ?int
183 {
184 $entity = $dialog->getEntities()['landing'] ?? null;
185 if ($entity)
186 {
187 if ($landingId = $entity->getOptions()['landingId'] ?? null)
188 {
189 return $landingId;
190 }
191 }
192
193 return null;
194 }
195
202 public function getChildren(Item $parentItem, Dialog $dialog): void
203 {
204 $this::$searchPhrase = null;
205 if ($siteId = $this->getSiteIdFromDialog($dialog))
206 {
207 $landingId = $this->getLandingIdFromDialog($dialog);
208 $dialog->addItems($this::getFolders($siteId, $parentItem->getId()));
209 $dialog->addItems($this::getLandings($siteId, $landingId, $parentItem->getId()));
210 }
211 }
212
219 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
220 {
221 $this::$searchPhrase = $searchQuery->getQuery();
222 if ($siteId = $this->getSiteIdFromDialog($dialog))
223 {
224 $dialog->addItems($this::getLandings($siteId));
225 }
226 $this::$searchPhrase = null;
227 }
228
234 public function getItems(array $ids) : array
235 {
236 return [];
237 }
238
244 public function getSelectedItems(array $ids) : array
245 {
246 return [];
247 }
248}
static getFolders(int $siteId, ?int $parentId=null)
getChildren(Item $parentItem, Dialog $dialog)
doSearch(SearchQuery $searchQuery, Dialog $dialog)
static getLandings(int $siteId, ?int $landingId=null, ?int $parentId=null)
static getBreadCrumbsString(int $folderId, string $glue, ?int $siteId=null)
Definition folder.php:208
static createInstance($id, array $params=array())
Definition landing.php:534
static getFolders(int $siteId, array $filter=[])
Definition site.php:1375
static getList(array $parameters=array())