/** * Create transitions from database. * * @param Workflow $workflow The current workflow. * * @throws DefinitionException If a target step is defined which does not exiss. * * @return void */ private function createTransitions(Workflow $workflow) { $collection = TransitionModel::findByWorkflow($workflow->getConfigValue('id')); if (!$collection) { return; } while ($collection->next()) { /** @var TransitionModel $model */ $model = $collection->current(); $transition = new Transition($model->name, $model->label, array_merge($collection->row(), array(Definition::SOURCE => Definition::SOURCE_DATABASE))); if (!isset($this->steps[$model->stepTo])) { throw new DefinitionException(sprintf('Transition "%s" refers to step "%s" which does not exists.', $transition->getName(), $model->stepTo)); } $transition->setStepTo($this->steps[$model->stepTo]); if ($model->limitPermission) { $transition->setPermission(Permission::fromString($model->permission)); } $workflow->addTransition($transition); $event = new CreateTransitionEvent($transition); $this->getServiceContainer()->getEventDispatcher()->dispatch($event::NAME, $event); $this->transitions[$model->id] = $transition; } }
/** * Get the workflow model. * * @param \DataContainer $dataContainer The data container driver. * * @return \Model|\Model\Collection * * @throws \Exception If relation could not be resolved. */ protected function getWorkflowModel($dataContainer) { $transitionModel = TransitionModel::findByPk($dataContainer->activeRecord->pid); $workflowModel = $transitionModel->getRelated('pid'); return $workflowModel; }
/** * Get all transitions. * * @param \DataContainer $dataContainer The data container. * * @return array */ public function getTransitions($dataContainer) { $options = array(); if ($dataContainer->activeRecord) { $collection = TransitionModel::findBy('pid', $dataContainer->activeRecord->id); if ($collection) { while ($collection->next()) { $stepTo = $collection->getRelated('stepTo'); $options[$collection->id] = sprintf('%s [%s] --> %s [%s]', $collection->label, $collection->name, $stepTo->label, $stepTo->name); } } } return $options; }