public function buildModel() { $dictonary = new Dictionary(); $roles = $dictonary->taskRoles(); $states = $dictonary->taskStates(); $model = array($roles->CREATOR[0] => array($states->CREATED[0] => array($states->CANCELED[0]), $states->ON_REVIEW[0] => array($states->CANCELED[0], $states->RETURNED[0], $states->COMPLETED[0])), $roles->EXECUTOR[0] => array($states->CREATED[0] => array($states->RUNNING[0]), $states->RUNNING[0] => array($states->ON_REVIEW[0]), $states->RETURNED[0] => array($states->RUNNING[0]))); return $model; }
private function buildControlsModel($roles, Dictionary $dictionary, Task $task, TaskManager $manager) { $buttons = array(); if (in_array($dictionary->taskRoles()->CREATOR[0], $roles)) { $url = $this->router->getUrlByRoute('task_edit', array('id' => $task->getId()), false); $buttons[] = array('caption' => 'Править', 'url' => $url); } $states = $dictionary->taskStates(); $statesList = $states->getList(); $statesList[$states->COMPLETED[0]] = 'Завершить задвчу'; $statesList[$states->ON_REVIEW[0]] = 'Отправить на рассмотрение'; $statesList[$states->CANCELED[0]] = 'Отменить'; $statesList[$states->RETURNED[0]] = 'Вернуть на доработку'; $statesList[$states->RUNNING[0]] = 'Начать выполнение'; $model = $manager->buildModel(); foreach ($roles as $role) { if (!array_key_exists($role, $model)) { continue; } if (!array_key_exists($task->getState(), $model[$role])) { continue; } foreach ($model[$role][$task->getState()] as $rule) { $url = $this->router->getUrlByRoute('task_change_state', array('id' => $task->getId(), 'state' => $rule), false); $buttons[] = array('caption' => $statesList[$rule], 'url' => $url); } } return $buttons; }