function workflow_allowable_transitions in Workflow 5
Same name and namespace in other branches
- 5.2 workflow.module \workflow_allowable_transitions()
- 6.2 workflow.module \workflow_allowable_transitions()
- 6 workflow.module \workflow_allowable_transitions()
- 7 workflow.module \workflow_allowable_transitions()
Get allowable transitions for a given workflow state.
Parameters
$sid: The ID of the state in question.
$dir: The direction of the transition: 'to' or 'from' the state denoted by $sid. When set to 'to' all the allowable states that may be moved to are returned; when set to 'from' all the allowable states that may move to the current state are returned.
mixed $roles: Array of ints (and possibly the string 'author') representing the user's roles. If the string 'ALL' is passed (instead of an array) the role constraint is ignored (this is the default for backwards compatibility).
Return value
Associative array of states (sid=>name pairs), excluding current state.
2 calls to workflow_allowable_transitions()
- workflow_actions_page in ./
workflow.module - workflow_field_choices in ./
workflow.module - Get the states one can move to for a given node.
File
- ./
workflow.module, line 1677
Code
function workflow_allowable_transitions($sid, $dir = 'to', $roles = 'ALL') {
$transitions = array();
$field = $dir == 'to' ? 'target_sid' : 'sid';
$field_where = $dir != 'to' ? 'target_sid' : 'sid';
$result = db_query("(SELECT t.tid, t.%s as state_id, s.state as state_name, s.weight as state_weight FROM " . "{workflow_transitions} t INNER JOIN {workflow_states} s ON s.sid = " . "t.%s WHERE t.%s = %d) " . "UNION " . "(SELECT s.sid as tid, s.sid as state_id, s.state as state_name, s.weight as state_weight FROM " . "{workflow_states} s WHERE s.sid = %d) " . "ORDER BY state_weight", $field, $field, $field_where, $sid, $sid);
while ($t = db_fetch_object($result)) {
if ($roles == 'ALL' || $t->tid == $t->state_id || workflow_transition_allowed($t->tid, $roles)) {
//$state_id = str_pad($t->state_id, 5, '0', STR_PAD_LEFT);
$state_id = $t->state_id;
$transitions[$state_id] = $t->state_name;
}
}
return $transitions;
}