1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/workflow-doctrine |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\Spi\Doctrine\Entity; |
7
|
|
|
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
10
|
|
|
use DateTime; |
11
|
|
|
use Traversable; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class CurrentStep |
16
|
|
|
* |
17
|
|
|
* @package OldTown\Workflow\Spi\Doctrine\Entity |
18
|
|
|
* |
19
|
|
|
* @ORM\Entity(repositoryClass="\OldTown\Workflow\Spi\Doctrine\EntityRepository\StepRepository") |
20
|
|
|
* @ORM\Table( |
21
|
|
|
* name="wf_step", |
22
|
|
|
* indexes={ |
23
|
|
|
* @ORM\Index(name="owner", columns={"owner"}), |
24
|
|
|
* @ORM\Index(name="caller", columns={"caller"}) |
25
|
|
|
* } |
26
|
|
|
* ) |
27
|
|
|
* @ORM\InheritanceType(value="SINGLE_TABLE") |
28
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
29
|
|
|
* @ORM\DiscriminatorMap(value={"currentStep" = "CurrentStep", "historyStep"="HistoryStep"}) |
30
|
|
|
*/ |
31
|
|
|
abstract class AbstractStep implements StepInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @ORM\Id() |
35
|
|
|
* @ORM\Column(name="id", type="integer") |
36
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
37
|
|
|
* |
38
|
|
|
* @var integer |
39
|
|
|
*/ |
40
|
|
|
protected $id; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Column(name="action_Id", type="integer", nullable=true) |
44
|
|
|
* |
45
|
|
|
* @var integer |
46
|
|
|
*/ |
47
|
|
|
protected $actionId; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @ORM\Column(name="caller", type="string", length=35, nullable=true) |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $caller; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @ORM\Column(name="finish_date", type="datetime", nullable=true) |
58
|
|
|
* |
59
|
|
|
* @var DateTime |
60
|
|
|
*/ |
61
|
|
|
protected $finishDate; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @ORM\Column(name="start_date", type="datetime") |
65
|
|
|
* |
66
|
|
|
* @var DateTime |
67
|
|
|
*/ |
68
|
|
|
protected $startDate; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\Column(name="due_date", type="datetime", nullable=true) |
72
|
|
|
* |
73
|
|
|
* @var DateTime |
74
|
|
|
*/ |
75
|
|
|
protected $dueDate; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @ORM\Column(name="owner", type="string", length=35, nullable=true) |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
protected $owner; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @ORM\Column(name="status", type="string", length=40, nullable=true) |
86
|
|
|
* |
87
|
|
|
* @var string |
88
|
|
|
*/ |
89
|
|
|
protected $status; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @ORM\Column(name="step_id", type="integer") |
93
|
|
|
* |
94
|
|
|
* @var integer |
95
|
|
|
*/ |
96
|
|
|
protected $stepId; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* |
100
|
|
|
* @ORM\ManyToMany(targetEntity="AbstractStep") |
101
|
|
|
* @ORM\JoinTable( |
102
|
|
|
* name="wf_previous_step", |
103
|
|
|
* joinColumns={@ORM\JoinColumn(name="current_step_id", referencedColumnName="id")}, |
104
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="previous_step_id", referencedColumnName="id")} |
105
|
|
|
* ) |
106
|
|
|
* |
107
|
|
|
* @var ArrayCollection|AbstractStep[] |
108
|
|
|
*/ |
109
|
|
|
protected $previousSteps; |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
*/ |
115
|
|
|
public function __construct() |
116
|
|
|
{ |
117
|
|
|
$this->previousSteps = new ArrayCollection(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getId() |
125
|
|
|
{ |
126
|
|
|
return $this->id; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $id |
131
|
|
|
* |
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
|
|
public function setId($id) |
135
|
|
|
{ |
136
|
|
|
$this->id = $id; |
|
|
|
|
137
|
|
|
|
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return integer |
143
|
|
|
*/ |
144
|
|
|
public function getActionId() |
145
|
|
|
{ |
146
|
|
|
return $this->actionId; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param integer $actionId |
151
|
|
|
* |
152
|
|
|
* @return $this |
153
|
|
|
*/ |
154
|
|
|
public function setActionId($actionId = null) |
155
|
|
|
{ |
156
|
|
|
$this->actionId = null !== $actionId ? (integer)$actionId : $actionId; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getCaller() |
165
|
|
|
{ |
166
|
|
|
return $this->caller; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $caller |
171
|
|
|
* |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function setCaller($caller = null) |
175
|
|
|
{ |
176
|
|
|
$this->caller = null !== $caller ? (string)$caller : $caller; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return DateTime |
183
|
|
|
*/ |
184
|
|
|
public function getFinishDate() |
185
|
|
|
{ |
186
|
|
|
return $this->finishDate; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param DateTime $finishDate |
191
|
|
|
* |
192
|
|
|
* @return $this |
193
|
|
|
*/ |
194
|
|
|
public function setFinishDate(DateTime $finishDate = null) |
195
|
|
|
{ |
196
|
|
|
$this->finishDate = $finishDate; |
197
|
|
|
|
198
|
|
|
return $this; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return DateTime |
203
|
|
|
*/ |
204
|
|
|
public function getStartDate() |
205
|
|
|
{ |
206
|
|
|
return $this->startDate; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param DateTime $startDate |
211
|
|
|
* |
212
|
|
|
* @return $this |
213
|
|
|
*/ |
214
|
|
|
public function setStartDate(DateTime $startDate) |
215
|
|
|
{ |
216
|
|
|
$this->startDate = $startDate; |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return DateTime |
223
|
|
|
*/ |
224
|
|
|
public function getDueDate() |
225
|
|
|
{ |
226
|
|
|
return $this->dueDate; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @param DateTime $dueDate |
231
|
|
|
* |
232
|
|
|
* @return $this |
233
|
|
|
*/ |
234
|
|
|
public function setDueDate(DateTime $dueDate = null) |
235
|
|
|
{ |
236
|
|
|
$this->dueDate = $dueDate; |
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return string |
243
|
|
|
*/ |
244
|
|
|
public function getOwner() |
245
|
|
|
{ |
246
|
|
|
return $this->owner; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param string $owner |
251
|
|
|
* |
252
|
|
|
* @return $this |
253
|
|
|
*/ |
254
|
|
|
public function setOwner($owner) |
255
|
|
|
{ |
256
|
|
|
$this->owner = null !== $owner ? (string)$owner : $owner; |
257
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
|
|
public function getStatus() |
265
|
|
|
{ |
266
|
|
|
return $this->status; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param string $status |
271
|
|
|
* |
272
|
|
|
* @return $this |
273
|
|
|
*/ |
274
|
|
|
public function setStatus($status) |
275
|
|
|
{ |
276
|
|
|
$this->status = (string)$status; |
277
|
|
|
|
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @return string |
283
|
|
|
*/ |
284
|
|
|
public function getStepId() |
285
|
|
|
{ |
286
|
|
|
return $this->stepId; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @param string $stepId |
291
|
|
|
* |
292
|
|
|
* @return $this |
293
|
|
|
*/ |
294
|
|
|
public function setStepId($stepId) |
295
|
|
|
{ |
296
|
|
|
$this->stepId = (string)$stepId; |
|
|
|
|
297
|
|
|
|
298
|
|
|
return $this; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @return EntryInterface |
303
|
|
|
*/ |
304
|
|
|
abstract public function getEntry(); |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Возвращает id процесса |
308
|
|
|
* |
309
|
|
|
* @return integer |
310
|
|
|
*/ |
311
|
|
|
public function getEntryId() |
312
|
|
|
{ |
313
|
|
|
return $this->getEntry()->getId(); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Возвращает id предыдущхи шагов |
318
|
|
|
* |
319
|
|
|
*/ |
320
|
|
|
public function getPreviousStepIds() |
321
|
|
|
{ |
322
|
|
|
$previousStepIds = []; |
323
|
|
|
$previousSteps = $this->getPreviousSteps(); |
324
|
|
|
|
325
|
|
|
foreach ($previousSteps as $previousStep) { |
326
|
|
|
$id = $previousStep->getId(); |
327
|
|
|
$previousStepIds[$id] = $id; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
return $previousStepIds; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @return ArrayCollection|AbstractStep[] |
335
|
|
|
*/ |
336
|
|
|
public function getPreviousSteps() |
337
|
|
|
{ |
338
|
|
|
return $this->previousSteps; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param ArrayCollection|AbstractStep[] $previousSteps |
343
|
|
|
* |
344
|
|
|
* @return $this |
345
|
|
|
* |
346
|
|
|
* @throws Exception\InvalidArgumentException |
347
|
|
|
*/ |
348
|
|
|
public function setPreviousSteps($previousSteps) |
349
|
|
|
{ |
350
|
|
|
if (!is_array($previousSteps) && !$previousSteps instanceof Traversable) { |
351
|
|
|
$errMsg = 'previousSteps is not array'; |
352
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
foreach ($previousSteps as $previousStep) { |
356
|
|
|
if (!$previousStep instanceof AbstractStep) { |
357
|
|
|
$errMsg = sprintf('step not implement %s', AbstractStep::class); |
358
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
359
|
|
|
} |
360
|
|
|
if (!$this->previousSteps->contains($previousStep)) { |
361
|
|
|
$this->previousSteps->add($previousStep); |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
return $this; |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.