Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
WorkflowStateToGet.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Api\Data\WorkflowStateService
;
4
5
use
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable
;
6
use
Bitrix\Main\DB\SqlExpression
;
7
8
class
WorkflowStateToGet
9
{
10
private
array $select = [
'ID'
,
'MODULE_ID'
,
'DOCUMENT_ID'
,
'ENTITY'
];
11
private
int
$filterUserId = 0;
12
private
?
string
$filterPresetId;
13
private
?array $filterWorkflowIds;
14
private
int
$limit = 0;
15
private
int
$offset = 0;
16
private
bool
$isSelectAllFields =
false
;
17
18
private
bool
$countTotal =
false
;
19
20
public
function
setAdditionalSelectFields
(array $additionalSelect): static
21
{
22
$allowedFields = $this->getAllowedAdditionalFields();
23
24
foreach
($additionalSelect as $fieldId)
25
{
26
if
(in_array($fieldId, $allowedFields,
true
) && !in_array($fieldId, $this->select,
true
))
27
{
28
$this->select[] = $fieldId;
29
}
30
}
31
32
return
$this;
33
}
34
35
public
function
setSelectAllFields
(
bool
$flag =
true
): static
36
{
37
$this->isSelectAllFields = $flag;
38
39
return
$this;
40
}
41
42
public
function
setFilterUserId
(
int
$userId): static
43
{
44
$this->filterUserId = $userId;
45
46
return
$this;
47
}
48
49
public
function
getFilterUserId
(): int
50
{
51
return
$this->filterUserId;
52
}
53
54
public
function
setFilterPresetId
(
string
$presetId): static
55
{
56
if
(
WorkflowStateFilter::isDefined
($presetId))
57
{
58
$this->filterPresetId = $presetId;
59
}
60
61
return
$this;
62
}
63
64
public
function
getFilterPresetId
(): ?string
65
{
66
return
$this->filterPresetId;
67
}
68
69
public
function
setFilterWorkflowIds
(array $workflowIds): static
70
{
71
$this->filterWorkflowIds = $workflowIds;
72
73
return
$this;
74
}
75
76
public
function
getFilterWorkflowIds
(): ?array
77
{
78
return
$this->filterWorkflowIds;
79
}
80
81
public
function
setLimit
(
int
$limit): static
82
{
83
if
($limit >= 0)
84
{
85
$this->limit = $limit;
86
}
87
88
return
$this;
89
}
90
91
public
function
setOffset
(
int
$offset): static
92
{
93
if
($offset >= 0)
94
{
95
$this->offset = $offset;
96
}
97
98
return
$this;
99
}
100
101
public
function
countTotal
(
bool
$count =
true
): static
102
{
103
$this->
countTotal
= $count;
104
105
return
$this;
106
}
107
108
public
function
isCountingTotal
(): bool
109
{
110
return
$this->countTotal;
111
}
112
113
public
function
getSelect
(): array
114
{
115
if
($this->isSelectAllFields)
116
{
117
return
array_merge($this->select, $this->getAllowedAdditionalFields());
118
}
119
120
return
$this->select;
121
}
122
123
public
function
getOrmFilter
(): array
124
{
125
$filter = [
126
'=USER_ID'
=> $this->filterUserId,
127
];
128
129
if
(!empty($this->filterWorkflowIds))
130
{
131
$filter[
'@WORKFLOW_ID'
] = $this->filterWorkflowIds;
132
}
133
134
$filterPresetId = $this->filterPresetId ??
WorkflowStateFilter::PRESET_DEFAULT
;
135
136
if
($filterPresetId ===
WorkflowStateFilter::PRESET_STARTED
)
137
{
138
$filter[
'=IS_AUTHOR'
] = 1;
139
}
140
elseif ($filterPresetId ===
WorkflowStateFilter::PRESET_HAS_TASK
)
141
{
142
$filter[
'>TASK_STATUS'
] =
WorkflowUserTable::TASK_STATUS_NONE
;
143
}
144
elseif ($filterPresetId ===
WorkflowStateFilter::PRESET_ALL_COMPLETED
)
145
{
146
$filter[
'=WORKFLOW_STATUS'
] =
WorkflowUserTable::WORKFLOW_STATUS_COMPLETED
;
147
}
148
else
// ($filterPresetId === WorkflowStateFilter::PRESET_IN_WORK)
149
{
150
$filter[
'=WORKFLOW_STATUS'
] =
new
SqlExpression
(
'?i'
,
WorkflowUserTable::WORKFLOW_STATUS_ACTIVE
);
151
$filter[] = [
152
'LOGIC'
=>
'OR'
,
153
'=IS_AUTHOR'
=> 1,
154
'=TASK_STATUS'
=>
WorkflowUserTable::TASK_STATUS_ACTIVE
,
155
];
156
}
157
158
return
$filter;
159
}
160
161
public
function
getOrder
(): array
162
{
163
$filterPresetId = $this->filterPresetId ??
WorkflowStateFilter::PRESET_DEFAULT
;
164
165
if
(
166
$filterPresetId ===
WorkflowStateFilter::PRESET_ALL_COMPLETED
167
|| $filterPresetId ===
WorkflowStateFilter::PRESET_STARTED
168
)
169
{
170
return
[
'MODIFIED'
=>
'DESC'
];
171
}
172
173
return
[
'TASK_STATUS'
=>
'DESC'
,
'MODIFIED'
=>
'DESC'
];
174
}
175
176
public
function
getLimit
(): int
177
{
178
return
$this->limit;
179
}
180
181
public
function
getOffset
(): int
182
{
183
return
$this->offset;
184
}
185
186
private
function
getAllowedAdditionalFields(): array
187
{
188
return
[
189
'STARTED_BY'
,
190
'STARTED'
,
191
'MODIFIED'
,
192
'WORKFLOW_TEMPLATE_ID'
,
193
'TEMPLATE.NAME'
,
194
// 'DOCUMENT_ID_INT',
195
//'STATE',
196
'STATE_TITLE'
,
197
// 'STATE_PARAMETERS',
198
199
'TASKS.ID'
,
200
'TASKS.ACTIVITY'
,
201
'TASKS.MODIFIED'
,
202
'TASKS.OVERDUE_DATE'
,
203
'TASKS.NAME'
,
204
'TASKS.DESCRIPTION'
,
205
'TASKS.STATUS'
,
206
'TASKS.IS_INLINE'
,
207
'TASKS.DELEGATION_TYPE'
,
208
'TASKS.PARAMETERS'
,
209
210
'TASKS.TASK_USERS.USER_ID'
,
211
'TASKS.TASK_USERS.STATUS'
,
212
'TASKS.TASK_USERS.DATE_UPDATE'
,
213
'TASKS.TASK_USERS.ORIGINAL_USER_ID'
,
214
];
215
}
216
}
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateFilter\PRESET_HAS_TASK
const PRESET_HAS_TASK
Definition
WorkflowStateFilter.php:11
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateFilter\PRESET_DEFAULT
const PRESET_DEFAULT
Definition
WorkflowStateFilter.php:13
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateFilter\PRESET_ALL_COMPLETED
const PRESET_ALL_COMPLETED
Definition
WorkflowStateFilter.php:12
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateFilter\PRESET_STARTED
const PRESET_STARTED
Definition
WorkflowStateFilter.php:10
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateFilter\isDefined
static isDefined(string $presetId)
Definition
WorkflowStateFilter.php:38
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet
Definition
WorkflowStateToGet.php:9
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setFilterPresetId
setFilterPresetId(string $presetId)
Definition
WorkflowStateToGet.php:54
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\countTotal
countTotal(bool $count=true)
Definition
WorkflowStateToGet.php:101
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\isCountingTotal
isCountingTotal()
Definition
WorkflowStateToGet.php:108
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setFilterWorkflowIds
setFilterWorkflowIds(array $workflowIds)
Definition
WorkflowStateToGet.php:69
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setSelectAllFields
setSelectAllFields(bool $flag=true)
Definition
WorkflowStateToGet.php:35
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setLimit
setLimit(int $limit)
Definition
WorkflowStateToGet.php:81
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getOrder
getOrder()
Definition
WorkflowStateToGet.php:161
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setFilterUserId
setFilterUserId(int $userId)
Definition
WorkflowStateToGet.php:42
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getFilterWorkflowIds
getFilterWorkflowIds()
Definition
WorkflowStateToGet.php:76
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getFilterPresetId
getFilterPresetId()
Definition
WorkflowStateToGet.php:64
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setOffset
setOffset(int $offset)
Definition
WorkflowStateToGet.php:91
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getSelect
getSelect()
Definition
WorkflowStateToGet.php:113
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getOrmFilter
getOrmFilter()
Definition
WorkflowStateToGet.php:123
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\setAdditionalSelectFields
setAdditionalSelectFields(array $additionalSelect)
Definition
WorkflowStateToGet.php:20
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getLimit
getLimit()
Definition
WorkflowStateToGet.php:176
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getFilterUserId
getFilterUserId()
Definition
WorkflowStateToGet.php:49
Bitrix\Bizproc\Api\Data\WorkflowStateService\WorkflowStateToGet\getOffset
getOffset()
Definition
WorkflowStateToGet.php:181
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable
Definition
workflowusertable.php:30
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable\WORKFLOW_STATUS_ACTIVE
const WORKFLOW_STATUS_ACTIVE
Definition
workflowusertable.php:31
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable\TASK_STATUS_ACTIVE
const TASK_STATUS_ACTIVE
Definition
workflowusertable.php:36
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable\WORKFLOW_STATUS_COMPLETED
const WORKFLOW_STATUS_COMPLETED
Definition
workflowusertable.php:32
Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable\TASK_STATUS_NONE
const TASK_STATUS_NONE
Definition
workflowusertable.php:34
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Bizproc\Api\Data\WorkflowStateService
Definition
WorkflowStateFilter.php:3
modules
bizproc
lib
Api
Data
WorkflowStateService
WorkflowStateToGet.php
Создано системой
1.10.0