1 <?php
2
3 namespace Docoflow\Entity;
4
5 use Exception;
6 use Docoflow\Traits\Entity;
7 use Docolight\Support\Collection;
8 use Docoflow\Traits\BulkValidator;
9
10 11 12 13 14
15 class Step extends Collection
16 {
17 use Entity, BulkValidator;
18
19 20 21 22 23
24 protected $groups;
25
26 27 28 29 30
31 public function rebuild()
32 {
33 $steps = new static();
34
35 foreach ($this as $step) {
36 $step = fluent($step);
37
38 if (! $stepId = $step->{'$id'}) {
39 throw new Exception("Step doesn't have an id.");
40 }
41
42 $steps[$stepId] = $step;
43 $steps[$stepId]->groups = new Group();
44 }
45
46 return $steps;
47 }
48
49 50 51 52 53 54 55 56
57 public function pushGroup($groupId, $group)
58 {
59 if (! $this->groups) {
60 $this->groups = new Group;
61 }
62
63 $this->groups->offsetSet($groupId, $group);
64 }
65
66 67 68 69 70 71 72
73 public function hasGroup($groupId)
74 {
75 return ($this->groups instanceof Group) ? $this->groups->has($groupId) : false;
76 }
77
78 79 80 81 82 83 84
85 public function getGroup($groupId)
86 {
87 return ($this->groups instanceof Group) ? $this->groups->offsetGet($groupId) : null;
88 }
89 }
90