/** * Get the list of transitions currently available for a given state * * @param WorkflowState $state State object to get transitions for * @param Internship $i Internship object that this state applies to * @return Array Array of available transitions */ public static function getTransitionsFromState(WorkflowState $state, Internship $i) { $stateName = $state->getName(); // Strip namespace from state name by matching the last word character in the path preg_match('/\\w*$/', $stateName, $matches); $stateName = $matches[0]; $transitions = self::getAllTransitions(); // Get all transitions $outgoingTrans = array(); // Filter the list of all transitions by finding the transitions which have this state // in their list of potential source states foreach ($transitions as $t) { // Set the actual source state $t->setSourceState($state); if (is_array($t->getSourceState()) && in_array($stateName, $t->getSourceState()) && $t->isApplicable($i)) { $outgoingTrans[] = $t; } else { if (($t->getSourceState() == $stateName || $t->getSourceState() == '*') && $t->isApplicable($i)) { $outgoingTrans[] = $t; } } } uasort($outgoingTrans, array('self', 'sortTransitions')); return $outgoingTrans; }
/** * Sets the WorkflowState of this internship. * * @param WorkflowState $state */ public function setState(WorkflowState $state) { $this->state = $state->getClassName(); }