You are here

function workflow_transition_add_role in Workflow 5

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_transition_add_role()
  2. 6.2 workflow.module \workflow_transition_add_role()
  3. 6 workflow.module \workflow_transition_add_role()

Add a role to the list of those allowed for a given transition. Add the transition if necessary.

Parameters

int $from:

int $to:

mixed $role: Int (role ID) or string ('author').

1 call to workflow_transition_add_role()
workflow_update_transitions in ./workflow.module
Update the transitions for a workflow.

File

./workflow.module, line 1027

Code

function workflow_transition_add_role($from, $to, $role) {
  $tid = workflow_get_transition_id($from, $to);
  if ($tid) {
    $roles = db_result(db_query("SELECT roles FROM {workflow_transitions} WHERE tid=%d", $tid));
    $roles = explode(',', $roles);
    if (array_search($role, $roles) === FALSE) {
      $roles[] = $role;
      db_query("UPDATE {workflow_transitions} SET roles='%s' WHERE tid=%d", implode(',', $roles), $tid);
    }
  }
  else {
    db_query("INSERT INTO {workflow_transitions} (tid, sid, target_sid, roles) VALUES (%d, %d, %d, '%s')", db_next_id('{workflow_transitions}_tid'), $from, $to, $role);
  }
}