Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ListsToGetFilter.php
1<?php
2
4
8
10{
11 public const ALLOWABLE_FIELDS = [
12 'ID',
13 'NAME',
14 'TIMESTAMP_X',
15 'DATE_CREATE',
16 'WORKFLOW_STATE',
17 'FIND', // SEARCHABLE_CONTENT
18 'SEARCHABLE_CONTENT',
19 'CREATED_BY',
20 'IBLOCK_TYPE',
21 ];
22
23 protected array $computedFilter = [
24 'state' => null
25 ];
26
27 public function setField(string $fieldId, $value, string $operator = ''): static
28 {
29 if ($fieldId === 'FIND' || $fieldId === 'SEARCHABLE_CONTENT')
30 {
31 return $this->setSearchableContent($value);
32 }
33
34 if ($fieldId === 'WORKFLOW_STATE')
35 {
36 return $this->setWorkflowState($value);
37 }
38
39 return parent::setField($fieldId, $value, $operator);
40 }
41
42 public function getFieldValue(string $fieldId)
43 {
44 if ($fieldId === 'WORKFLOW_STATE')
45 {
46 return $this->computedFilter['state'];
47 }
48
49 return parent::getFieldValue($fieldId);
50 }
51
52 public function setSearchableContent(string $value): static
53 {
54 if ($value !== '')
55 {
56 $this->filter['?SEARCHABLE_CONTENT'] = $value;
57 $this->keyMatching['SEARCHABLE_CONTENT'] = '?SEARCHABLE_CONTENT';
58 }
59
60 return $this;
61 }
62
63 public function setWorkflowState(string $state): static
64 {
65 if ($state === 'R' || $state === 'C')
66 {
67 $this->computedFilter['state'] = $state;
68 $this->keyMatching['WORKFLOW_STATE'] = 'WORKFLOW_STATE';
69 }
70
71 return $this;
72 }
73
74 public function setCreatedBy(int $userId): static
75 {
76 if ($userId >= 0)
77 {
78 $this->setField('CREATED_BY', (string)$userId, '=');
79 }
80
81 return $this;
82 }
83
84 public function setIBlockType(string $iBlockType): static
85 {
86 if (!empty($iBlockType))
87 {
88 $this->setField('IBLOCK_TYPE', $iBlockType, '=');
89 }
90
91 return $this;
92 }
93
94 protected function execComputedFilter(): void
95 {
96 if ($this->computedFilter['state'] !== null)
97 {
98 $this->execWorkflowStateFilter();
99 }
100 }
101
102 private function execWorkflowStateFilter(): void
103 {
104 $state = $this->computedFilter['state'];
105
106 if (Loader::includeModule('bizproc') && in_array($state, ['R', 'C'], true))
107 {
108 $query =
109 WorkflowInstanceTable::query()
110 ->setDistinct()
111 ->setSelect(['DOCUMENT_ID'])
112 ->where('MODULE_ID', 'lists')
113 ->where('ENTITY', \BizprocDocument::class)
114 ;
115 if ($this->hasField('CREATED_BY'))
116 {
117 $query->where('STARTED_BY',$this->getFieldValue('CREATED_BY'));
118 }
119
120 $activeWorkflow = array_column($query->exec()->fetchAll(), 'DOCUMENT_ID');
121
122 if ($state === 'R')
123 {
124 $this->filter['=ID'] = $activeWorkflow;
125 $this->keyMatching['ID'] = '=ID';
126 }
127
128 if ($state === 'C')
129 {
130 $this->filter['!=ID'] = $activeWorkflow;
131 $this->keyMatching['ID'] = '!=ID';
132 }
133 }
134 }
135}
hasField(string $fieldId)
Definition Filter.php:45
setField(string $fieldId, $value, string $operator='')