Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
item.php
1<?
2
4
6
7class Item implements \JsonSerializable
8{
9 protected $id = '';
10 protected $entityId = '';
11 protected $entityType;
12 protected $tabs = [];
13
15 protected $title;
16
18 protected $subtitle;
19
21 protected $supertitle;
22
24 protected $caption;
25
27 protected $avatar;
28
30 protected $textColor;
31
33 protected $link;
34
36 protected $linkTitle;
37 protected $badges;
38
39 protected $selected = false;
40 protected $searchable = true;
41 protected $saveable = true;
42 protected $deselectable = true;
43 protected $hidden = false;
44
45 protected $children;
46 protected $nodeOptions;
47 protected $tagOptions;
48 protected $customData;
49 protected $captionOptions;
50 protected $badgesOptions;
51 protected $avatarOptions;
52
53 protected $sort;
54 protected $contextSort;
55 protected $globalSort;
56
57 protected $dialog;
58 protected $availableInRecentTab = true;
59
60 public function __construct(array $options)
61 {
62 $id = $options['id'] ?? null;
63 if ((is_string($id) && $id !== '') || is_int($id))
64 {
65 $this->id = $id;
66 }
67
68 $entityId = $options['entityId'] ?? null;
69 if (is_string($entityId) && $entityId !== '')
70 {
71 $this->entityId = strtolower($entityId);
72 }
73
74 $entityType = $options['entityType'] ?? null;
75 if (is_string($entityType) && $entityType !== '')
76 {
77 $this->entityType = $entityType;
78 }
79
80 $this->addTab($options['tabs'] ?? null);
81
82 $this->setTitle($options['title'] ?? null);
83 $this->setSubtitle($options['subtitle'] ?? null);
84 $this->setSupertitle($options['supertitle'] ?? null);
85 $this->setCaption($options['caption'] ?? null);
86
87 if (isset($options['captionOptions']) && is_array($options['captionOptions']))
88 {
89 $this->setCaptionOptions($options['captionOptions']);
90 }
91
92 if (isset($options['avatar']) && is_string($options['avatar']))
93 {
94 $this->setAvatar($options['avatar']);
95 }
96
97 if (isset($options['avatarOptions']) && is_array($options['avatarOptions']))
98 {
99 $this->setAvatarOptions($options['avatarOptions']);
100 }
101
102 if (isset($options['textColor']) && is_string($options['textColor']))
103 {
104 $this->setTextColor($options['textColor']);
105 }
106
107 if (isset($options['link']) && is_string($options['link']))
108 {
109 $this->setLink($options['link']);
110 }
111
112 $this->setLinkTitle($options['linkTitle'] ?? null);
113
114 if (isset($options['badges']) && is_array($options['badges']))
115 {
116 $this->addBadges($options['badges']);
117 }
118
119 if (isset($options['badgesOptions']) && is_array($options['badgesOptions']))
120 {
121 $this->setBadgesOptions($options['badgesOptions']);
122 }
123
124 if (isset($options['searchable']) && is_bool($options['searchable']))
125 {
126 $this->setSearchable($options['searchable']);
127 }
128
129 if (isset($options['selected']) && is_bool($options['selected']))
130 {
131 $this->setSelected($options['selected']);
132 }
133
134 if (isset($options['saveable']) && is_bool($options['saveable']))
135 {
136 $this->setSaveable($options['saveable']);
137 }
138
139 if (isset($options['deselectable']) && is_bool($options['deselectable']))
140 {
141 $this->setDeselectable($options['deselectable']);
142 }
143
144 if (isset($options['hidden']) && is_bool($options['hidden']))
145 {
146 $this->setHidden($options['hidden']);
147 }
148
149 if (isset($options['sort']) && is_int($options['sort']))
150 {
151 $this->setSort($options['sort']);
152 }
153
154 if (isset($options['availableInRecentTab']) && is_bool($options['availableInRecentTab']))
155 {
156 $this->setAvailableInRecentTab($options['availableInRecentTab']);
157 }
158
159 if (isset($options['customData']) && is_array($options['customData']))
160 {
161 $this->setCustomData($options['customData']);
162 }
163
164 if (isset($options['nodeOptions']) && is_array($options['nodeOptions']))
165 {
166 $this->setNodeOptions($options['nodeOptions']);
167 }
168
169 if (isset($options['tagOptions']) && is_array($options['tagOptions']))
170 {
171 $this->setTagOptions($options['tagOptions']);
172 }
173
174 if (!empty($options['children']) && is_array($options['children']))
175 {
176 $this->addChildren($options['children']);
177 }
178 }
179
180 public function getId()
181 {
182 return $this->id;
183 }
184
185 public function getEntityId(): string
186 {
187 return $this->entityId;
188 }
189
190 public function getEntityType(): ?string
191 {
192 return $this->entityType;
193 }
194
195 public function setEntityType(string $type): self
196 {
197 if (is_string($type) || $type === null)
198 {
199 $this->entityType = $type;
200 }
201
202 return $this;
203 }
204
205 public function getTitle(): string
206 {
207 return $this->getTitleNode() && !$this->getTitleNode()->isNullable() ? $this->getTitleNode()->getText() : '';
208 }
209
210 public function getTitleNode(): ?TextNode
211 {
212 return $this->title;
213 }
214
215 public function setTitle($title): self
216 {
217 if (TextNode::isValidText($title) || $title === null)
218 {
219 $this->title = $title === null ? null : new TextNode($title);
220 }
221
222 return $this;
223 }
224
225 public function getSubtitle(): ?string
226 {
227 return $this->getSubtitleNode() ? $this->getSubtitleNode()->getText() : null;
228 }
229
230 public function getSubtitleNode(): ?TextNode
231 {
232 return $this->subtitle;
233 }
234
235 public function setSubtitle($subtitle): self
236 {
238 {
239 $this->subtitle = $subtitle === null ? null : new TextNode($subtitle);
240 }
241
242 return $this;
243 }
244
245 public function getSupertitle(): ?string
246 {
247 return $this->getSupertitleNode() ? $this->getSupertitleNode()->getText() : null;
248 }
249
250 public function getSupertitleNode(): ?TextNode
251 {
252 return $this->supertitle;
253 }
254
255 public function setSupertitle($supertitle): self
256 {
258 {
259 $this->supertitle = $supertitle === null ? null : new TextNode($supertitle);
260 }
261
262 return $this;
263 }
264
265 public function getCaption(): ?string
266 {
267 return $this->getCaptionNode() ? $this->getCaptionNode()->getText() : null;
268 }
269
270 public function getCaptionNode(): ?TextNode
271 {
272 return $this->caption;
273 }
274
275 public function setCaption($caption): self
276 {
277 if (TextNode::isValidText($caption) || $caption === null)
278 {
279 $this->caption = $caption === null ? null : new TextNode($caption);
280 }
281
282 return $this;
283 }
284
285 public function setCaptionOptions(array $captionOptions): self
286 {
287 $this->getCaptionOptions()->setValues($captionOptions);
288
289 return $this;
290 }
291
295 public function getCaptionOptions(): Dictionary
296 {
297 if ($this->captionOptions === null)
298 {
299 $this->captionOptions = new Dictionary();
300 }
301
303 }
304
305 public function getAvatar(): ?string
306 {
307 return $this->avatar;
308 }
309
310 public function setAvatar(?string $avatar): self
311 {
312 if (is_string($avatar) || $avatar === null)
313 {
314 $this->avatar = $avatar;
315 }
316
317 return $this;
318 }
319
320 public function setAvatarOptions(array $avatarOptions): self
321 {
322 $this->getAvatarOptions()->setValues($avatarOptions);
323
324 return $this;
325 }
326
330 public function getAvatarOptions(): Dictionary
331 {
332 if ($this->avatarOptions === null)
333 {
334 $this->avatarOptions = new Dictionary();
335 }
336
338 }
339
340 public function getTextColor(): ?string
341 {
342 return $this->textColor;
343 }
344
345 public function setTextColor(?string $textColor): self
346 {
347 if (is_string($textColor) || $textColor === null)
348 {
349 $this->textColor = $textColor;
350 }
351
352 return $this;
353 }
354
355 public function getLink(): ?string
356 {
357 return $this->link;
358 }
359
360 public function setLink(?string $link): self
361 {
362 if (is_string($link) || $link === null)
363 {
364 $this->link = $link;
365 }
366
367 return $this;
368 }
369
370 public function getLinkTitle(): ?string
371 {
372 return $this->getLinkTitleNode() ? $this->getLinkTitleNode()->getText() : null;
373 }
374
375 public function getLinkTitleNode(): ?TextNode
376 {
377 return $this->linkTitle;
378 }
379
380 public function setLinkTitle($linkTitle): self
381 {
383 {
384 $this->linkTitle = $linkTitle === null ? null : new TextNode($linkTitle);
385 }
386
387 return $this;
388 }
389
390 public function getBadges(): ?array
391 {
392 return $this->badges;
393 }
394
395 public function addBadges(array $badges): self
396 {
397 foreach ($badges as $badge)
398 {
399 if (is_array($badge) && !empty($badge))
400 {
401 $this->badges[] = $badge;
402 }
403 }
404
405 return $this;
406 }
407
408 public function setBadges(array $badges): self
409 {
410 $this->badges = [];
411 $this->addBadges($badges);
412
413 return $this;
414 }
415
416 public function setBadgesOptions(array $badgesOptions): self
417 {
418 $this->getBadgesOptions()->setValues($badgesOptions);
419
420 return $this;
421 }
422
426 public function getBadgesOptions(): Dictionary
427 {
428 if ($this->badgesOptions === null)
429 {
430 $this->badgesOptions = new Dictionary();
431 }
432
434 }
435
436 public function getTabs(): array
437 {
438 return $this->tabs;
439 }
440
441 public function addTab($tabId): self
442 {
443 if (is_string($tabId) && !empty($tabId))
444 {
445 $this->tabs[] = $tabId;
446 }
447 else if (is_array($tabId))
448 {
449 $this->tabs = array_merge($this->tabs, $tabId);
450 }
451
452 return $this;
453 }
454
455 public function getChildren(): ItemCollection
456 {
457 if ($this->children === null)
458 {
459 $this->children = new ItemCollection();
460 }
461
462 return $this->children;
463 }
464
465 public function addChildren(array $children): self
466 {
467 foreach ($children as $childOptions)
468 {
469 unset($childOptions['tabs']);
470
471 $child = new Item($childOptions);
472 $this->addChild($child);
473 }
474
475 return $this;
476 }
477
478 public function addChild(Item $item): self
479 {
480 $success = $this->getChildren()->add($item);
481 if ($success && $this->getDialog())
482 {
483 $this->getDialog()->handleItemAdd($item);
484 }
485
486 return $this;
487 }
488
489 public function setNodeOptions(array $nodeOptions): self
490 {
491 $this->getNodeOptions()->setValues($nodeOptions);
492
493 return $this;
494 }
495
496 public function getNodeOptions(): Dictionary
497 {
498 if ($this->nodeOptions === null)
499 {
500 $this->nodeOptions = new Dictionary();
501 }
502
503 return $this->nodeOptions;
504 }
505
506 public function setTagOptions(array $nodeOptions): self
507 {
508 $this->getTagOptions()->setValues($nodeOptions);
509
510 return $this;
511 }
512
513 public function getTagOptions(): Dictionary
514 {
515 if ($this->tagOptions === null)
516 {
517 $this->tagOptions = new Dictionary();
518 }
519
520 return $this->tagOptions;
521 }
522
523 public function isSelected(): bool
524 {
525 return $this->selected;
526 }
527
528 public function setSelected(bool $flag = true): self
529 {
530 $this->selected = $flag;
531
532 return $this;
533 }
534
535 public function isSearchable(): bool
536 {
537 return $this->searchable;
538 }
539
540 public function setSearchable(bool $flag = true): self
541 {
542 $this->searchable = $flag;
543
544 return $this;
545 }
546
547 public function isSaveable(): bool
548 {
549 return $this->saveable;
550 }
551
552 public function setSaveable(bool $flag = true): self
553 {
554 $this->saveable = $flag;
555
556 return $this;
557 }
558
559 public function isDeselectable(): bool
560 {
561 return $this->deselectable;
562 }
563
564 public function setDeselectable(bool $flag = true): self
565 {
566 $this->deselectable = $flag;
567
568 return $this;
569 }
570
571 public function isHidden(): bool
572 {
573 return $this->hidden;
574 }
575
576 public function setHidden(bool $flag = true): self
577 {
578 $this->hidden = $flag;
579
580 return $this;
581 }
582
583 public function isAvailableInRecentTab(): bool
584 {
586 }
587
588 public function setAvailableInRecentTab(bool $flag = true): self
589 {
590 $this->availableInRecentTab = $flag;
591
592 return $this;
593 }
594
595 public function setCustomData(array $customData): self
596 {
597 $this->getCustomData()->setValues($customData);
598
599 return $this;
600 }
601
605 public function getCustomData(): Dictionary
606 {
607 if ($this->customData === null)
608 {
609 $this->customData = new Dictionary();
610 }
611
612 return $this->customData;
613 }
614
615 public function setSort(?int $sort): self
616 {
617 $this->sort = $sort;
618
619 return $this;
620 }
621
622 public function getSort(): ?int
623 {
624 return $this->sort;
625 }
626
627 public function setContextSort(?int $sort): self
628 {
629 $this->contextSort = $sort;
630
631 return $this;
632 }
633
634 public function getContextSort(): ?int
635 {
636 return $this->contextSort;
637 }
638
639 public function setGlobalSort(?int $sort): self
640 {
641 $this->globalSort = $sort;
642
643 return $this;
644 }
645
646 public function getGlobalSort(): ?int
647 {
648 return $this->globalSort;
649 }
650
651 public function setDialog(Dialog $dialog): self
652 {
653 $this->dialog = $dialog;
654
655 return $this;
656 }
657
658 public function getDialog(): ?Dialog
659 {
660 return $this->dialog;
661 }
662
663 public function toArray(): array
664 {
665 return $this->serializeRecursive($this);
666 }
667
668 private function serializeRecursive($data)
669 {
670 if ($data instanceof \JsonSerializable)
671 {
672 $data = $data->jsonSerialize();
673 }
674
675 if (is_array($data) || $data instanceof \Traversable)
676 {
677 foreach ($data as $key => $item)
678 {
679 $data[$key] = $this->serializeRecursive($item);
680 }
681 }
682
683 return $data;
684 }
685
686 public function jsonSerialize()
687 {
688 $json = [
689 'id' => $this->getId(),
690 'entityId' => $this->getEntityId(),
691 'title' => $this->getTitleNode() !== null ? $this->getTitleNode()->jsonSerialize() : '',
692 ];
693
694 if ($this->getSubtitleNode() !== null)
695 {
696 $json['subtitle'] = $this->getSubtitleNode()->jsonSerialize();
697 }
698
699 if ($this->getSupertitleNode() !== null)
700 {
701 $json['supertitle'] = $this->getSupertitleNode()->jsonSerialize();
702 }
703
704 if ($this->getCaptionNode() !== null)
705 {
706 $json['caption'] = $this->getCaptionNode()->jsonSerialize();
707 }
708
709 if ($this->getLinkTitleNode() !== null)
710 {
711 $json['linkTitle'] = $this->getLinkTitleNode()->jsonSerialize();
712 }
713
714 if ($this->isSelected())
715 {
716 $json['selected'] = true;
717 }
718
719 if (!$this->isSearchable())
720 {
721 $json['searchable'] = false;
722 }
723
724 if (!$this->isSaveable())
725 {
726 $json['saveable'] = false;
727 }
728
729 if (!$this->isDeselectable())
730 {
731 $json['deselectable'] = false;
732 }
733
734 if ($this->isHidden())
735 {
736 $json['hidden'] = true;
737 }
738
739 if ($this->avatarOptions !== null && $this->getAvatarOptions()->count() > 0)
740 {
741 $json['avatarOptions'] = $this->getAvatarOptions()->getValues();
742 }
743
744 if ($this->captionOptions !== null && $this->getCaptionOptions()->count() > 0)
745 {
746 $json['captionOptions'] = $this->getCaptionOptions()->getValues();
747 }
748
749 if ($this->badgesOptions !== null && $this->getBadgesOptions()->count() > 0)
750 {
751 $json['badgesOptions'] = $this->getBadgesOptions()->getValues();
752 }
753
754 if ($this->customData !== null && $this->getCustomData()->count() > 0)
755 {
756 $json['customData'] = $this->getCustomData()->getValues();
757 }
758
759 if ($this->nodeOptions !== null && $this->getNodeOptions()->count() > 0)
760 {
761 $json['nodeOptions'] = $this->getNodeOptions()->getValues();
762 }
763
764 if ($this->tagOptions !== null && $this->getTagOptions()->count() > 0)
765 {
766 $json['tagOptions'] = $this->getTagOptions()->getValues();
767 }
768
769 if ($this->children !== null && $this->getChildren()->count() > 0)
770 {
771 $json['children'] = $this->getChildren();
772 }
773
774 if (!empty($this->getTabs()))
775 {
776 $json['tabs'] = $this->getTabs();
777 }
778
779 if (!empty($this->getBadges()))
780 {
781 $json['badges'] = $this->getBadges();
782 }
783
784 foreach ([
785 'entityType',
786 'avatar',
787 'textColor',
788 'link',
789 'contextSort',
790 'globalSort',
791 'sort'
792 ] as $field)
793 {
794 if ($this->{'get'.$field}() !== null)
795 {
796 $json[$field] = $this->{'get'.$field}();
797 }
798 }
799
800 return $json;
801 }
802}
setSaveable(bool $flag=true)
Definition item.php:552
__construct(array $options)
Definition item.php:60
setNodeOptions(array $nodeOptions)
Definition item.php:489
setDeselectable(bool $flag=true)
Definition item.php:564
setEntityType(string $type)
Definition item.php:195
setLink(?string $link)
Definition item.php:360
setDialog(Dialog $dialog)
Definition item.php:651
setTextColor(?string $textColor)
Definition item.php:345
setBadges(array $badges)
Definition item.php:408
setBadgesOptions(array $badgesOptions)
Definition item.php:416
addBadges(array $badges)
Definition item.php:395
setHidden(bool $flag=true)
Definition item.php:576
setAvatarOptions(array $avatarOptions)
Definition item.php:320
setSupertitle($supertitle)
Definition item.php:255
setCaptionOptions(array $captionOptions)
Definition item.php:285
setSearchable(bool $flag=true)
Definition item.php:540
addChildren(array $children)
Definition item.php:465
setSelected(bool $flag=true)
Definition item.php:528
setAvailableInRecentTab(bool $flag=true)
Definition item.php:588
setAvatar(?string $avatar)
Definition item.php:310
setCustomData(array $customData)
Definition item.php:595
setTagOptions(array $nodeOptions)
Definition item.php:506