You are here

function workflow_allowable_transitions in Workflow 6.2

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_allowable_transitions()
  2. 5 workflow.module \workflow_allowable_transitions()
  3. 6 workflow.module \workflow_allowable_transitions()
  4. 7 workflow.module \workflow_allowable_transitions()

Get allowable transitions for a given workflow state. Typical use:

global $user; $possible = workflow_allowable_transitions($sid, 'to', $user->roles);

If the state ID corresponded to the state named "Draft", $possible now contains the states that the current user may move to from the Draft 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 => $state_name pairs), excluding current state.

1 call to workflow_allowable_transitions()
workflow_field_choices in ./workflow.module
Get the states current user can move to for a given node.

File

./workflow.module, line 976
Support workflows made up of arbitrary states.

Code

function workflow_allowable_transitions($sid, $dir = 'to', $roles = 'ALL') {
  $transitions = array();
  if ($dir == 'to') {
    $field = 'target_sid';
    $field_where = 'sid';
  }
  else {
    $field = 'sid';
    $field_where = 'target_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 AND s.status = 1 " . "ORDER BY state_weight) " . "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 AND s.status = 1) " . "ORDER BY state_weight, state_id", $field, $field, $field_where, $sid, $sid);
  while ($t = db_fetch_object($result)) {
    if ($roles == 'ALL' || $sid == $t->state_id || workflow_transition_allowed($t->tid, $roles)) {
      $transitions[$t->state_id] = check_plain(t($t->state_name));
    }
  }
  return $transitions;
}