Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
CalendarCollection.php
1<?php
2
4
7use Bitrix\Im\V2\Common\ContextCustomer;
8use Bitrix\Im\V2\Common\SidebarFilterProcessorTrait;
14
20{
21 use SidebarFilterProcessorTrait;
22 use ContextCustomer;
23
24 public static function find(
25 array $filter,
26 array $order,
27 ?int $limit = null,
28 ?Context $context = null
29 ): self
30 {
31 $context = $context ?? Locator::getContext();
32
33 $calendarOrder = ['ID' => 'DESC'];
34
35 if (isset($order['ID']))
36 {
37 $calendarOrder['ID'] = $order['ID'];
38 }
39
40 $query = LinkCalendarTable::query();
41 $query
42 ->setSelect(['*'])
43 ->setOrder($calendarOrder)
44 ;
45 if (isset($limit))
46 {
47 $query->setLimit($limit);
48 }
49 static::processFilters($query, $filter, $calendarOrder);
50
51 $links = new static($query->fetchCollection());
52 $links->setContext($context);
53
54 return $links->fillCalendarData();
55 }
56
57 public function fillCalendarData(): self
58 {
59 $calendarIds = $this->getEntityIds();
60
61 $entities = \Bitrix\Im\V2\Entity\Calendar\CalendarCollection::initByIds($calendarIds, $this->getContext());
62
63 foreach ($this as $link)
64 {
65 if ($entities->getById($link->getEntityId()) !== null)
66 {
67 $link->setEntity($entities->getById($link->getEntityId()));
68 }
69 }
70
71 return $this;
72 }
73
74 public function save(bool $isGroupSave = false): Result
75 {
76 return parent::save(false);
77 }
78
79 protected static function processFilters(Query $query, array $filter, array $order): void
80 {
81 static::processSidebarFilters($query, $filter, $order);
82
83 if (isset($filter['CALENDAR_DATE_FROM']))
84 {
85 $query->where('CALENDAR_DATE_FROM', '>=', $filter['CALENDAR_DATE_FROM']);
86 }
87
88 if (isset($filter['CALENDAR_DATE_TO']))
89 {
90 $query->where('CALENDAR_DATE_TO', '<=', $filter['CALENDAR_DATE_TO']);
91 }
92
93 if (isset($filter['SEARCH_TITLE']))
94 {
95 $query->withSearchByTitle($filter['SEARCH_TITLE']);
96 }
97 }
98
99 public static function getCollectionElementClass(): string
100 {
101 return CalendarItem::class;
102 }
103}