コード例 #1
0
 public function taskStateChange(User $user, $taskId, $newState)
 {
     $this->task = $this->dataRepository->find($taskId);
     $roles = $this->dataRepository->getRolesInTask($taskId, $user->getId());
     $currentState = $this->task->getState();
     $model = $this->buildModel();
     foreach ($roles as $role) {
         if (array_key_exists($role['role'], $model)) {
             if (array_key_exists($currentState, $model[$role['role']])) {
                 if (in_array($newState, $model[$role['role']][$currentState])) {
                     $this->accessOpened = true;
                     break;
                 }
             }
         }
     }
     if (!$this->accessHasOpened()) {
         return;
     }
     $this->task->setState($newState);
     $states = (new Dictionary())->taskStates();
     switch ($newState) {
         case $states->RUNNING[0]:
             if (!$this->task->getDateAccept()) {
                 $this->task->setDateAccept(new \DateTime());
             }
             break;
         case $states->CANCELED[0]:
             $this->task->setDateCancel(new \DateTime());
             break;
         case $states->COMPLETED[0]:
             $this->task->setDateComplete(new \DateTime());
             break;
         default:
             break;
     }
     $this->wasChanged = true;
 }
コード例 #2
0
 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;
 }