|
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
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class WorkflowName |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Entity() |
|
16
|
|
|
* @ORM\Table(name="wf_entry") |
|
17
|
|
|
* @ORM\InheritanceType(value="SINGLE_TABLE") |
|
18
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
|
19
|
|
|
* |
|
20
|
|
|
* @package OldTown\Workflow\Spi\Doctrine |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractEntry implements EntryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @ORM\Id() |
|
26
|
|
|
* @ORM\Column(name="id", type="integer") |
|
27
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @ORM\Column(name="workflow_name", type="string", length=60) |
|
35
|
|
|
* |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $workflowName; |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\Column(name="state", type="integer") |
|
44
|
|
|
* |
|
45
|
|
|
* |
|
46
|
|
|
* @var integer |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $state; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @ORM\OneToMany(targetEntity="CurrentStep", mappedBy="entry") |
|
52
|
|
|
* |
|
53
|
|
|
* @var CurrentStepInterface[]|ArrayCollection |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $currentSteps; |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @ORM\OneToMany(targetEntity="HistoryStep", mappedBy="entry") |
|
60
|
|
|
* @ORM\OrderBy({"finishDate"="ASC"}) |
|
61
|
|
|
* |
|
62
|
|
|
* @var HistoryStepInterface[]|ArrayCollection |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $historySteps; |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->currentSteps = new ArrayCollection(); |
|
73
|
|
|
$this->historySteps = new ArrayCollection(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getId() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->id; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $id |
|
86
|
|
|
* |
|
87
|
|
|
* @return $this |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setId($id) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->id = (integer)$id; |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getWorkflowName() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->workflowName; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $workflowName |
|
106
|
|
|
* |
|
107
|
|
|
* @return $this |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setWorkflowName($workflowName) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->workflowName = (string)$workflowName; |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return integer |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getState() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->state; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param integer $state |
|
126
|
|
|
* |
|
127
|
|
|
* @return $this |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setState($state) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->state = (integer)$state; |
|
132
|
|
|
|
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Определяет иницилазирован ли процесс workflow |
|
138
|
|
|
* |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
|
public function isInitialized() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->state > 0; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return ArrayCollection|CurrentStepInterface[] |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getCurrentSteps() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->currentSteps; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param CurrentStepInterface $currentStep |
|
156
|
|
|
* |
|
157
|
|
|
* @return $this |
|
158
|
|
|
*/ |
|
159
|
|
|
public function addCurrentStep(CurrentStepInterface $currentStep) |
|
160
|
|
|
{ |
|
161
|
|
|
$currentStep->setEntry($this); |
|
162
|
|
|
if (!$this->getCurrentSteps()->contains($currentStep)) { |
|
163
|
|
|
$this->getCurrentSteps()->add($currentStep); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return ArrayCollection|HistoryStepInterface[] |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getHistorySteps() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->historySteps; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param HistoryStepInterface $historyStep |
|
182
|
|
|
* |
|
183
|
|
|
* @return $this |
|
184
|
|
|
*/ |
|
185
|
|
|
public function addHistoryStep(HistoryStepInterface $historyStep) |
|
186
|
|
|
{ |
|
187
|
|
|
$historyStep->setEntry($this); |
|
188
|
|
|
if (!$this->getHistorySteps()->contains($historyStep)) { |
|
189
|
|
|
$this->getHistorySteps()->add($historyStep); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
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.