1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CalendarCollection.php
См. документацию.
1<?php
2
4
8use Bitrix\Im\V2\Common\SidebarFilterProcessorTrait;
19
25{
26 use SidebarFilterProcessorTrait;
27 use ContextCustomer;
28
29 protected ?EntityCollection $entities = null;
30
31 public static function find(
34 ?int $limit = null,
35 ?Context $context = null
36 ): self
37 {
38 if (!Loader::includeModule('calendar'))
39 {
40 return new static();
41 }
42
43 $context = $context ?? Locator::getContext();
44
45 $calendarOrder = ['ID' => 'DESC'];
46
47 if (isset($order['ID']))
48 {
49 $calendarOrder['ID'] = $order['ID'];
50 }
51
52 $query = LinkCalendarTable::query();
53 $query
54 ->setSelect(['*'])
55 ->setOrder($calendarOrder)
56 ;
57 if (isset($limit))
58 {
59 $query->setLimit($limit);
60 }
61 static::processFilters($query, $filter, $calendarOrder);
62
63 $links = new static($query->fetchCollection());
64 $links->setContext($context);
65
66 return $links->fillEntities();
67 }
68
69 public function getEntities(): EntityCollection
70 {
71 if (isset($this->entities))
72 {
73 return $this->entities;
74 }
75 $this->entities = \Bitrix\Im\V2\Entity\Calendar\CalendarCollection::getByIds($this->getEntityIds(), $this->getContext());
76
77 return $this->entities;
78 }
79
80 public function fillEntities(): self
81 {
82 $entities = $this->getEntities();
83
84 foreach ($this as $link)
85 {
86 $id = $link->getEntityId();
87
88 if (!isset($id) || ($entities->getById($id) === null))
89 {
90 continue;
91 }
92
93 $link->setEntity($entities->getById($id));
94 }
95
96 return $this;
97 }
98
99 public function save(bool $isGroupSave = false): Result
100 {
101 return parent::save(false);
102 }
103
104 protected static function processFilters(Query $query, array $filter, array $order): void
105 {
106 static::processSidebarFilters($query, $filter, $order);
107
108 if (isset($filter['CALENDAR_DATE_FROM']))
109 {
110 $query->where('CALENDAR_DATE_FROM', '>=', $filter['CALENDAR_DATE_FROM']);
111 }
112
113 if (isset($filter['CALENDAR_DATE_TO']))
114 {
115 $query->where('CALENDAR_DATE_TO', '<=', $filter['CALENDAR_DATE_TO']);
116 }
117
118 if (isset($filter['SEARCH_TITLE']))
119 {
120 $query->withSearchByTitle($filter['SEARCH_TITLE']);
121 }
122
123 // temporary
124 $query->registerRuntimeField(
125 new Reference(
126 'CALENDAR',
127 EventTable::class,
128 Join::on('this.CALENDAR_ID', 'ref.ID'),
129 ['join_type' => Join::TYPE_INNER]
130 )
131 );
132 }
133
134 public static function getCollectionElementClass(): string
135 {
136 return CalendarItem::class;
137 }
138
139 public static function getByMessages(MessageCollection $messages): self
140 {
141 $calendarCollection = LinkCalendarTable::query()
142 ->setSelect(['*'])
143 ->whereIn('MESSAGE_ID', $messages->getIds())
144 ->fetchCollection()
145 ;
146
147 return new static($calendarCollection);
148 }
149}
static getByIds(array $ids, ?Context $context=null)
Определения CalendarCollection.php:31
Определения result.php:20
Определения loader.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$filter
Определения iblock_catalog_list.php:54
$context
Определения csv_new_setup.php:223
trait ContextCustomer
Определения ContextCustomer.php:12
Определения culture.php:9
Определения chain.php:3
$order
Определения payment.php:8
$messages
Определения template.php:8