Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
resultitem.php
1<?php
2
3namespace Bitrix\Main\Search;
4
7
8final class ResultItem implements \JsonSerializable, \ArrayAccess
9{
11 private $id;
13 private $type;
15 private $title;
17 private $showLink;
19 private $module;
21 private $subTitle;
23 private $actions = [];
25 private $links = [];
27 private $attributes = [];
28
36 public function __construct($title, $showLink, $id = null)
37 {
38 $this
39 ->setTitle($title)
40 ->setShowLink($showLink)
41 ->setId($id)
42 ;
43 }
44
50 public function getId()
51 {
52 return $this->id;
53 }
54
61 public function setId($id)
62 {
63 $this->id = $id;
64
65 return $this;
66 }
67
74 public function getType()
75 {
76 return $this->type;
77 }
78
86 public function setType($type)
87 {
88 $this->type = $type;
89
90 return $this;
91 }
92
98 public function getTitle()
99 {
100 return $this->title;
101 }
102
109 public function setTitle($title)
110 {
111 $this->title = $title;
112
113 return $this;
114 }
115
121 public function getShowLink()
122 {
123 return $this->showLink;
124 }
125
132 public function setShowLink($showLink)
133 {
134 $this->showLink = $this->adjustLink($showLink);
135 $this->addLink('show', $this->showLink);
136
137 return $this;
138 }
139
146 protected function adjustLink($link)
147 {
148 if ($link instanceof Uri)
149 {
150 return $link;
151 }
152
153 return new Uri($link);
154 }
155
161 public function getModule()
162 {
163 return $this->module;
164 }
165
173 public function setModule($module)
174 {
175 $this->module = $module;
176
177 return $this;
178 }
179
186 public function getSubTitle()
187 {
188 return $this->subTitle;
189 }
190
198 public function setSubTitle($subTitle)
199 {
200 $this->subTitle = $subTitle;
201
202 return $this;
203 }
204
210 public function getActions()
211 {
212 return $this->actions;
213 }
214
220 public function getLinks()
221 {
222 return $this->links;
223 }
224
232 public function setLinks(array $links)
233 {
234 $adjustedLinks = [];
235 foreach ($links as $key => $link)
236 {
237 $adjustedLinks[$key] = $this->adjustLink($link);
238 }
239
240 $this->links = $adjustedLinks;
241
242 return $this;
243 }
244
252 public function addLink($name, $link)
253 {
254 $this->links[$name] = $this->adjustLink($link);
255
256 return $this;
257 }
258
263 public function getAttributes()
264 {
265 return $this->attributes;
266 }
267
274 public function setAttributes($attributes)
275 {
276 $this->attributes = $attributes;
277
278 return $this;
279 }
280
288 public function setAttribute($name, $value)
289 {
290 $this->attributes[$name] = $value;
291
292 return $this;
293 }
294
301 public function unsetAttribute($name)
302 {
303 unset($this->attributes[$name]);
304
305 return $this;
306 }
307
315 public function jsonSerialize(): array
316 {
317 return [
318 'id' => $this->getId(),
319 'type' => $this->getType(),
320 'title' => $this->getTitle(),
321 'module' => $this->getModule(),
322 'subTitle' => $this->getSubTitle(),
323 'actions' => $this->getActions(),
324 'links' => $this->getLinks(),
325 'attributes' => $this->getAttributes(),
326 ];
327 }
328
343 public function offsetExists($offset): bool
344 {
345 $data = $this->jsonSerialize();
346
347 return isset($data[$offset]) || array_key_exists($offset, $data);
348 }
349
361 #[\ReturnTypeWillChange]
362 public function offsetGet($offset)
363 {
364 $data = $this->jsonSerialize();
365
366 if (isset($data[$offset]) || array_key_exists($offset, $data))
367 {
368 return $data[$offset];
369 }
370
371 return null;
372 }
373
388 public function offsetSet($offset, $value): void
389 {
390 throw new NotSupportedException('ResultItem provides ArrayAccess only for reading');
391 }
392
404 public function offsetUnset($offset): void
405 {
406 throw new NotSupportedException('ResultItem provides ArrayAccess only for reading');
407 }
408}
__construct($title, $showLink, $id=null)