You are here

function workflow_transition_add_role in Workflow 6

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_transition_add_role()
  2. 5 workflow.module \workflow_transition_add_role()
  3. 6.2 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 606
Support workflows made up of arbitrary states.

Code

function workflow_transition_add_role($from, $to, $role) {
  $transition = array(
    'sid' => $from,
    'target_sid' => $to,
    'roles' => $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;
      $transition['roles'] = implode(',', $roles);
      $transition['tid'] = $tid;
      drupal_write_record('workflow_transitions', $transition, 'tid');
    }
  }
  else {
    drupal_write_record('workflow_transitions', $transition);
  }
}