1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
TaskCollection.php
См. документацию.
1<?php
2
4
11use Bitrix\Tasks\Internals\SearchIndex;
12use Bitrix\Tasks\Provider\TaskList;
13use Bitrix\Tasks\Provider\TaskQuery;
14
20{
21 public const SELECT_FIELDS = [
22 'ID',
23 'TITLE',
24 'REAL_STATUS',
25 'DEADLINE',
26 'CREATED_BY',
27 'RESPONSIBLE_ID',
28 'CREATED_DATE',
29 'IM_CHAT_ID',
30 'IM_CHAT_MESSAGE_ID',
31 'IM_CHAT_CHAT_ID',
32 'IM_CHAT_AUTHOR_ID',
33 ];
34
35 protected ?EntityCollection $entities = null;
36
37 public static function getCollectionElementClass(): string
38 {
39 return TaskItem::class;
40 }
41
42 public static function initByTaskQuery(TaskQuery $taskQuery): self
43 {
44 $tasksArray = (new TaskList())->getList($taskQuery);
45
46 $linkCollection = new static();
47
48 foreach ($tasksArray as $row)
49 {
50 $linkCollection->add(TaskItem::initByRow($row));
51 }
52
53 return $linkCollection;
54 }
55
56 public static function find(
58 array $order = ['ID' => 'DESC'],
59 ?int $limit = null,
60 ?Context $context = null
61 ): self
62 {
63 $context = $context ?? Locator::getContext();
64
65 $taskQuery = new TaskQuery($context->getUserId());
66
67 $taskOrder = [];
68 if (isset($order['ID']))
69 {
70 $taskOrder['IM_CHAT_ID'] = $order['ID'];
71 }
72
73 $taskFilter = static::processFilters($filter, $taskOrder);
74
75 $taskQuery
76 ->setSelect(static::SELECT_FIELDS)
77 ->setOrder($taskOrder)
78 ->setWhere($taskFilter)
79 ;
80
81 if (isset($limit))
82 {
83 $taskQuery->setLimit($limit);
84 }
85
86 return static::initByTaskQuery($taskQuery);
87 }
88
89 protected static function processFilters(array $filter, array $order): array
90 {
91 $result = [];
92
93 if (isset($filter['CHAT_ID']))
94 {
95 $result['IM_CHAT_CHAT_ID'] = (int)$filter['CHAT_ID'];
96 }
97 if (isset($filter['USER_ID']))
98 {
99 $usersIds = $filter['USER_ID'];
100 if (!empty($usersIds))
101 {
102 $result['::SUBFILTER-MEMBER'] = [
103 '::LOGIC' => 'OR',
104 'CREATED_BY' => $usersIds,
105 'RESPONSIBLE_ID' => $usersIds,
106 'ACCOMPLICE' => $usersIds,
107 'AUDITOR' => $usersIds,
108 ];
109 }
110 }
111 if (isset($filter['DATE_FROM']))
112 {
113 $result['>=CREATED_DATE'] = $filter['DATE_FROM'];
114 }
115 if (isset($filter['DATE_TO']))
116 {
117 $result['<=CREATED_DATE'] = $filter['DATE_TO'];
118 }
119 if (isset($filter['SEARCH_TASK_NAME']))
120 {
121 $result['::SUBFILTER-FULL_SEARCH_INDEX'] = [
122 '*FULL_SEARCH_INDEX' => SearchIndex::prepareStringToSearch($filter['SEARCH_TASK_NAME'])
123 ];
124 }
125 if (isset($filter['LAST_ID']))
126 {
127 $operator = '<';
128 if (isset($order['IM_CHAT_ID']) && $order['IM_CHAT_ID'] === 'ASC')
129 {
130 $operator = '>';
131 }
132 $result["{$operator}IM_CHAT_ID"] = (int)$filter['LAST_ID'];
133 }
134
135 return $result;
136 }
137
138 public static function getByMessages(MessageCollection $messages): self
139 {
140 $chatTasks = LinkTaskTable::query()
141 ->setSelect(['ID', 'MESSAGE_ID', 'CHAT_ID', 'TASK_ID', 'AUTHOR_ID', 'DATE_CREATE'])
142 ->whereIn('MESSAGE_ID', $messages->getIds())
143 ->fetchCollection()
144 ;
145
146 return new static($chatTasks);
147 }
148
149 public function getEntities(): EntityCollection
150 {
151 if (isset($this->entities))
152 {
153 return $this->entities;
154 }
156
157 return $this->entities;
158 }
159
160 public function fillEntities(): self
161 {
162 $entities = $this->getEntities();
163
164 foreach ($this as $task)
165 {
166 $id = $task->getEntityId();
167 if (!isset($id) || ($entities->getById($id) === null))
168 {
169 continue;
170 }
171
172 $task->setEntity($entities->getById($id));
173 }
174
175 return $this;
176 }
177}
static getByIds(array $ids, ?Context $context=null)
Определения TaskCollection.php:35
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$context
Определения csv_new_setup.php:223
Определения culture.php:9
$order
Определения payment.php:8
$messages
Определения template.php:8