Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ReactionCollection.php
1<?php
2
4
7use Bitrix\Im\V2\Common\ContextCustomer;
14
20{
21 use ContextCustomer;
22
23 public static function getCollectionElementClass(): string
24 {
25 return ReactionItem::class;
26 }
27
28 public static function find(array $filter, array $order, ?int $limit = null, ?Context $context = null): self
29 {
30 $reactionOrder = ['ID' => 'DESC'];
31
32 if (isset($order['ID']))
33 {
34 $reactionOrder['ID'] = $order['ID'];
35 }
36
37 $query = ReactionTable::query()
38 ->setSelect(['ID', 'CHAT_ID', 'MESSAGE_ID', 'USER_ID', 'DATE_CREATE', 'REACTION'])
39 ;
40
41 if ($reactionOrder['ID'] !== 'DESC')
42 {
43 $query->setOrder($reactionOrder);
44 }
45
46 if (isset($limit))
47 {
48 $query->setLimit($limit);
49 }
50
51 static::processFilters($query, $filter, $reactionOrder);
52
53 return new static($query->fetchCollection());
54 }
55
56 public function getPopupData(array $excludedList = []): PopupData
57 {
58 return new PopupData([new UserPopupItem($this->getUserIds())], $excludedList);
59 }
60
61 public static function getRestEntityName(): string
62 {
63 return 'reactions';
64 }
65
66 public function toRestFormat(array $option = []): array
67 {
68 $rest = [];
69
70 foreach ($this as $reaction)
71 {
72 $rest[] = $reaction->toRestFormat($option);
73 }
74
75 return $rest;
76 }
77
78 protected static function processFilters(Query $query, array $filter, array $order): void
79 {
80 if (isset($filter['LAST_ID']))
81 {
82 $operator = $order['ID'] === 'DESC' ? '<' : '>';
83 $query->where('ID', $operator, $filter['LAST_ID']);
84 }
85
86 if (isset($filter['REACTION']))
87 {
88 $query->where('REACTION', $filter['REACTION']);
89 }
90
91 if (isset($filter['MESSAGE_ID']))
92 {
93 $query->where('MESSAGE_ID', $filter['MESSAGE_ID']);
94 }
95 }
96
100 private function getUserIds(): array
101 {
102 $userIds = [];
103
104 foreach ($this as $reaction)
105 {
106 $userIds[$reaction->getUserId()] = $reaction->getUserId();
107 }
108
109 return $userIds;
110 }
111}
static find(array $filter, array $order, ?int $limit=null, ?Context $context=null)
static processFilters(Query $query, array $filter, array $order)