Esempio n. 1
0
 /**
  * Validates that a transition between requested states can be done on an element
  * NOTE: DOES NOT VALIDATE FIELDS @see performAction
  * @param $actionName
  * @param $newStatus
  * @param $newState
  * @return bool
  */
 public function validateAction($actionName, $newState, $newStatus)
 {
     $element = $this->element;
     if (!$this->workflow->isGlobalAction($actionName)) {
         $availableActions = $this->getAvailableActions();
         //check the action is available
         if (!array_key_exists($actionName, $availableActions)) {
             $this->error = "Workflow::validateTransition, Action [{$actionName}] not available for element [{$element->getId()}] with status [{$this->getElementStatus()}]";
             Logger::debug($this->error);
             return false;
         }
         $actionToTake = $availableActions[$actionName];
         if ($this->actionHasTransition($actionToTake)) {
             //check that the new state is correct for the action taken
             if (!array_key_exists($newState, $actionToTake['transitionTo'])) {
                 $this->error = "Workflow::validateTransition, State [{$newState}] not a valid transition state for action [{$actionName}] from status [{$this->getElementStatus()}]";
                 Logger::debug($this->error);
                 return false;
             }
             $availableNewStatuses = $actionToTake['transitionTo'][$newState];
             //check that the new status is valid for the action taken
             if (!in_array($newStatus, $availableNewStatuses)) {
                 $this->error = "Workflow::validateTransition, Status [{$newState}] not a valid transition status for action [{$actionName}] from status [{$this->getElementStatus()}]";
                 Logger::debug($this->error);
                 return false;
             }
         }
     }
     return true;
 }
Esempio n. 2
0
 public function getNoteTitle($actionName, $formData)
 {
     $config = $this->workflow->getActionConfig($actionName);
     if (!empty($config['note_title'])) {
         return $config['note_title'];
     }
     if ($this->workflow->isGlobalAction($actionName) || $formData['oldStatus'] === $formData['newStatus']) {
         return $this->getActionLabel($actionName);
     }
     return $this->getStatusLabel($formData['oldStatus']) . ' ->' . $this->getStatusLabel($formData['newStatus']);
 }