Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TaskCollection.php
1<?php
2
4
8use Bitrix\Tasks\Internals\SearchIndex;
9use Bitrix\Tasks\Provider\TaskList;
10use Bitrix\Tasks\Provider\TaskQuery;
11
17{
18 public const SELECT_FIELDS = [
19 'ID',
20 'TITLE',
21 'REAL_STATUS',
22 'DEADLINE',
23 'CREATED_BY',
24 'RESPONSIBLE_ID',
25 'CREATED_DATE',
26 'IM_CHAT_ID',
27 'IM_CHAT_MESSAGE_ID',
28 'IM_CHAT_CHAT_ID',
29 'IM_CHAT_AUTHOR_ID',
30 ];
31
32 public static function getCollectionElementClass(): string
33 {
34 return TaskItem::class;
35 }
36
37 public static function initByTaskQuery(TaskQuery $taskQuery): self
38 {
39 $tasksArray = (new TaskList())->getList($taskQuery);
40
41 $linkCollection = new static();
42
43 foreach ($tasksArray as $row)
44 {
45 $linkCollection->add(TaskItem::initByRow($row));
46 }
47
48 return $linkCollection;
49 }
50
51 public static function find(
52 array $filter,
53 array $order = ['ID' => 'DESC'],
54 ?int $limit = null,
55 ?Context $context = null
56 ): self
57 {
58 $context = $context ?? Locator::getContext();
59
60 $taskQuery = new TaskQuery($context->getUserId());
61
62 $taskOrder = [];
63 if (isset($order['ID']))
64 {
65 $taskOrder['IM_CHAT_ID'] = $order['ID'];
66 }
67
68 $taskFilter = static::processFilters($filter, $taskOrder);
69
70 $taskQuery
71 ->setSelect(static::SELECT_FIELDS)
72 ->setOrder($taskOrder)
73 ->setWhere($taskFilter)
74 ;
75
76 if (isset($limit))
77 {
78 $taskQuery->setLimit($limit);
79 }
80
81 return static::initByTaskQuery($taskQuery);
82 }
83
84 protected static function processFilters(array $filter, array $order): array
85 {
86 $result = [];
87
88 if (isset($filter['CHAT_ID']))
89 {
90 $result['IM_CHAT_CHAT_ID'] = (int)$filter['CHAT_ID'];
91 }
92 if (isset($filter['USER_ID']))
93 {
94 $usersIds = $filter['USER_ID'];
95 if (!empty($usersIds))
96 {
97 $result['::SUBFILTER-MEMBER'] = [
98 '::LOGIC' => 'OR',
99 'CREATED_BY' => $usersIds,
100 'RESPONSIBLE_ID' => $usersIds,
101 'ACCOMPLICE' => $usersIds,
102 'AUDITOR' => $usersIds,
103 ];
104 }
105 }
106 if (isset($filter['DATE_FROM']))
107 {
108 $result['>=CREATED_DATE'] = $filter['DATE_FROM'];
109 }
110 if (isset($filter['DATE_TO']))
111 {
112 $result['<=CREATED_DATE'] = $filter['DATE_TO'];
113 }
114 if (isset($filter['SEARCH_TASK_NAME']))
115 {
116 $result['::SUBFILTER-FULL_SEARCH_INDEX'] = [
117 '*FULL_SEARCH_INDEX' => SearchIndex::prepareStringToSearch($filter['SEARCH_TASK_NAME'])
118 ];
119 }
120 if (isset($filter['LAST_ID']))
121 {
122 $operator = '<';
123 if (isset($order['IM_CHAT_ID']) && $order['IM_CHAT_ID'] === 'ASC')
124 {
125 $operator = '>';
126 }
127 $result["{$operator}IM_CHAT_ID"] = (int)$filter['LAST_ID'];
128 }
129
130 return $result;
131 }
132}