/** * Rebuild a barely new group to a readable array. * * @param \Docoflow\Entity\Step &$steps * * @return \Docoflow\Entity\Group */ public function rebuild(Step &$steps) { $groups = new static(); foreach ($this as $group) { $group = fluent($group); if (!($groupId = $group->{'$id'})) { throw new Exception("Group doesn't have an id."); } if (!($assignedStep = $group->{'$step'})) { throw new Exception("Group doesn't have any assigned step id."); } if ($steps->has($assignedStep)) { if ($steps->get($assignedStep)->groups->has($groupId)) { throw new Exception("Group id [{$groupId}] has been assigned before and it can't be overriden."); } $group->verificator = new Verificator(); $groups->offsetSet($groupId, $group); $steps->pushGroup($groupId, $group); $steps->get($assignedStep)->groups->offsetSet($groupId, $group); } else { throw new Exception("Assigned step [{$assignedStep}] doesn't exist."); } } return $groups; }
/** * Rebuild a barely new group to a readable array. * * @param \Docoflow\Entity\Step &$steps */ public function rebuild(Step &$steps) { foreach ($this as $verificator) { $verificator = fluent($verificator); if (!($assignedGroup = $verificator->{'$group'})) { throw new Exception("Verificator hasn't assigned to any group."); } if ($steps->hasGroup($assignedGroup)) { $verificatorStep = $steps->getGroup($assignedGroup)->{'$step'}; $steps->get($verificatorStep)->groups->get($assignedGroup)->verificator->push($verificator); } else { throw new Exception("Assigned group [{$assignedGroup}] doent't exist."); } } }
/** * Get a single step. Let's say you have 4 steps in this workflow. You can call the 4th step entity by call: * * ```php * Flo::fetch($id)->step(4); * ``` * * @param int $step Step you want to return * * @return null|\Docoflow\Models\WorkflowStep */ public function step($step) { if (!$this->bootstrapped->steps) { $this->makeInternalSteps(); } return $this->steps ? $this->steps->offsetExists((int) $step - 1) ? $this->steps->offsetGet((int) $step - 1) : null : null; }
/** * Prepare data before saving * * @return \Docoflow\Docoflow */ public function prepare() { if (!$this->step) { throw new Exception('Cannot create workflow, steps are empty.'); } $steps = $this->step->rebuild(); if (!$this->group) { throw new Exception('Cannot create workflow, groups are empty.'); } $this->group->rebuild($steps); if (!$this->verificator) { throw new Exception('Cannot create workflow, verificators are empty.'); } $this->verificator->rebuild($steps); $this->prepared = $steps; return $this; }