1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: shirshov |
5
|
|
|
* Date: 11.11.15 |
6
|
|
|
* Time: 16:17 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OldTown\Workflow\Util; |
10
|
|
|
|
11
|
|
|
use OldTown\PropertySet\PropertySetInterface; |
12
|
|
|
use OldTown\Workflow\ConditionInterface; |
13
|
|
|
use OldTown\Workflow\Exception\WorkflowException; |
14
|
|
|
use OldTown\Workflow\Spi\WorkflowEntryInterface; |
15
|
|
|
use OldTown\Workflow\Spi\WorkflowStoreInterface; |
16
|
|
|
use OldTown\Workflow\TransientVars\TransientVarsInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Simple utility condition that returns true if the current step's status is |
20
|
|
|
* the same as the required argument "status". Looks at ALL current steps unless |
21
|
|
|
* a stepId is given in the optional argument "stepId". |
22
|
|
|
* |
23
|
|
|
* @package OldTown\Workflow\Util |
24
|
|
|
*/ |
25
|
|
|
class StatusCondition implements ConditionInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param TransientVarsInterface $transientVars |
29
|
|
|
* @param array $args |
30
|
|
|
* @param PropertySetInterface $ps |
31
|
|
|
* @return bool |
32
|
|
|
* |
33
|
|
|
* @throws WorkflowException |
34
|
|
|
*/ |
35
|
|
|
public function passesCondition(TransientVarsInterface $transientVars, array $args = [], PropertySetInterface $ps) |
36
|
|
|
{ |
37
|
|
|
$status = $args['status']; |
38
|
|
|
$stepId = array_key_exists('stepId', $args) ? (int)$args['stepId'] : 0; |
39
|
|
|
|
40
|
|
|
/** @var WorkflowEntryInterface $entry */ |
41
|
|
|
$entry = $transientVars['entry']; |
42
|
|
|
|
43
|
|
|
/** @var WorkflowStoreInterface $store */ |
44
|
|
|
$store = $transientVars['store']; |
45
|
|
|
$currentSteps = $store->findCurrentSteps($entry->getId()); |
46
|
|
|
|
47
|
|
|
if ($stepId === 0) { |
48
|
|
|
foreach ($currentSteps as $step) { |
49
|
|
|
if ($status === $step->getStatus()) { |
50
|
|
|
return true; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} else { |
54
|
|
|
foreach ($currentSteps as $step) { |
55
|
|
|
if (($stepId === $step->getStepId()) |
56
|
|
|
&& ($status === $step->getStatus())) { |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|