1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AnchorCollection.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
13
26final class AnchorCollection extends Collection implements RestConvertible
27{
28 use GroupActionTrait;
29
30 public static function getCollectionElementClass(): string
31 {
32 return AnchorItem::class;
33 }
34
35 public static function find(array $filter, array $order = ['MESSAGE_ID' => 'desc'], ?int $limit = null, ?Context $context = null): self
36 {
37 $query = AnchorTable::query()
38 ->setSelect(['ID', 'CHAT_ID', 'MESSAGE_ID', 'USER_ID', 'FROM_USER_ID', 'TYPE', 'SUB_TYPE'])
39 ->setOrder($order)
40 ;
41
42 if (isset($limit))
43 {
44 $query->setLimit($limit);
45 }
46
47 self::processFilters($query, $filter);
48
49
50 return new self($query->fetchAll());
51 }
52
53 public static function getRestEntityName(): string
54 {
55 return 'anchors';
56 }
57
58 public function toRestFormat(array $option = []): ?array
59 {
60 $rest = [];
61
62 foreach ($this as $anchorItem)
63 {
65 $rest[] = $anchorItem->toRestFormat($option);
66 }
67
68 return $rest;
69 }
70
71 public function fillParents(array $map): void
72 {
73 foreach ($this as $anchorItem)
74 {
76 $parent = $map[$anchorItem->getChatId()] ?? null;
77 if (empty($parent))
78 {
79 continue;
80 }
81
82 $parentChatId = (int)($parent['PARENT_CHAT_ID'] ?? 0);
83 $parentMessageId = (int)($parent['PARENT_MESSAGE_ID'] ?? 0);
84
85 $anchorItem->setParentChatId($parentChatId);
86 $anchorItem->setParentMessageId($parentMessageId);
87 }
88 }
89
90 public function getCommonMessageId(): ?int
91 {
92 $messageIds = $this->getMessageIdList();
93 if (empty($messageIds))
94 {
95 return null;
96 }
97
98 $messageIds = array_unique($messageIds);
99 if (count($messageIds) === 1)
100 {
101 return array_shift($messageIds);
102 }
103
104 return null;
105 }
106
107 private static function processFilters(Query $query, array $filter): void
108 {
109 if (isset($filter['USER_ID']))
110 {
111 if (is_array($filter['USER_ID']) && !empty($filter['USER_ID']))
112 {
113 $query->whereIn('USER_ID', $filter['USER_ID']);
114 }
115 else
116 {
117 $query->where('USER_ID', $filter['USER_ID']);
118 }
119 }
120
121 if (isset($filter['FROM_USER_ID']))
122 {
123 $query->where('FROM_USER_ID', $filter['FROM_USER_ID']);
124 }
125
126 if (isset($filter['CHAT_ID']))
127 {
128 $query->where('CHAT_ID', $filter['CHAT_ID']);
129 }
130
131 if (isset($filter['MESSAGE_ID']))
132 {
133 if (is_array($filter['MESSAGE_ID']) && !empty($filter['MESSAGE_ID']))
134 {
135 $query->whereIn('MESSAGE_ID', $filter['MESSAGE_ID']);
136 }
137 else
138 {
139 $query->where('MESSAGE_ID', $filter['MESSAGE_ID']);
140 }
141 }
142
143 if (isset($filter['TYPE']))
144 {
145 $query->where('TYPE', $filter['TYPE']);
146 }
147 }
148}
static find(array $filter, array $order=['MESSAGE_ID'=> 'desc'], ?int $limit=null, ?Context $context=null)
Определения AnchorCollection.php:35
static getCollectionElementClass()
Определения AnchorCollection.php:30
</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
$map
Определения config.php:5
Определения culture.php:9
Определения chain.php:3
$order
Определения payment.php:8
$option
Определения options.php:1711