Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PinCollection.php
1<?php
2
4
5use Bitrix\Im\Model\EO_LinkPin_Collection;
7use Bitrix\Im\V2\Common\SidebarFilterProcessorTrait;
18
24{
25 use SidebarFilterProcessorTrait;
26
27 public static function find(
28 array $filter,
29 array $order = ['ID' => 'DESC'],
30 ?int $limit = null,
31 ?Context $context = null
32 ): self
33 {
34 $context = $context ?? Locator::getContext();
35
36 $pinOrder = ['ID' => 'DESC'];
37
38 if (isset($order['ID']))
39 {
40 $pinOrder['ID'] = $order['ID'];
41 }
42
43 $query = LinkPinTable::query()
44 ->setSelect(['ID', 'CHAT_ID', 'AUTHOR_ID', 'DATE_CREATE', 'MESSAGE_ID'])
45 ->setOrder($pinOrder)
46 ;
47 if (isset($limit))
48 {
49 $query->setLimit($limit);
50 }
51
52 static::processFilters($query, $filter, $pinOrder);
53
54 return static::initByEntityCollection($query->fetchCollection());
55 }
56
57 public static function initByEntityCollection(EO_LinkPin_Collection $entityCollection): self
58 {
59 $pinCollection = new static();
60
61 foreach ($entityCollection as $entity)
62 {
63 $pinCollection[] = PinItem::initByEntity($entity);
64 }
65
66 return $pinCollection;
67 }
68
69 public static function getCollectionElementClass(): string
70 {
71 return PinItem::class;
72 }
73
74 public static function getRestEntityName(): string
75 {
76 return 'pins';
77 }
78
79 protected static function processFilters(Query $query, array $filter, array $order): void
80 {
81 static::processSidebarFilters($query, $filter, $order);
82 }
83}