Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ViewCollection.php
1<?php
2
4
5use Bitrix\Im\Model\EO_MessageViewed_Collection;
10
12{
13 public static function find(
14 array $filter,
15 array $order = ['ID' => 'ASC'],
16 ?int $limit = null,
17 ?Context $context = null
18 )
19 {
20 $viewOrder = ['ID' => 'ASC'];
21
22 if (isset($order['ID']))
23 {
24 $viewOrder['ID'] = $order['ID'];
25 }
26
27 $query = MessageViewedTable::query()->setSelect(['ID', 'USER_ID', 'MESSAGE_ID', 'DATE_CREATE']);
28 if ($viewOrder['ID'] === 'DESC')
29 {
30 $query->setOrder($viewOrder);
31 }
32 if (isset($limit))
33 {
34 $query->setLimit($limit);
35 }
36 static::processFilters($query, $filter, $viewOrder);
37
38 return (new static())->initByEntityCollection($query->fetchCollection());
39 }
40
41 public static function getRestEntityName(): string
42 {
43 return 'views';
44 }
45
46 private function initByEntityCollection(EO_MessageViewed_Collection $collection): self
47 {
48 foreach ($collection as $item)
49 {
50 $this[] = new ViewItem($item->getId(), $item->getMessageId(), $item->getUserId(), $item->getDateCreate());
51 }
52
53 return $this;
54 }
55
56 protected static function processFilters(Query $query, array $filter, array $order)
57 {
58 if (isset($filter['LAST_ID']))
59 {
60 $operator = $order['ID'] === 'DESC' ? '<' : '>';
61 $query->where('ID', $operator, $filter['LAST_ID']);
62 }
63 if (isset($filter['MESSAGE_ID']))
64 {
65 $query->where('MESSAGE_ID', (int)$filter['MESSAGE_ID']);
66 }
67 }
68}
static processFilters(Query $query, array $filter, array $order)
static find(array $filter, array $order=['ID'=> 'ASC'], ?int $limit=null, ?Context $context=null)