You are here

function workflow_permissions in Workflow 5

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_permissions()

View workflow permissions by role

Parameters

$wid: The ID of the workflow

1 call to workflow_permissions()
workflow_edit_page in ./workflow.module
Menu callback to edit a workflow's properties.

File

./workflow.module, line 722

Code

function workflow_permissions($wid) {
  $name = workflow_get_name($wid);
  $all = array();
  $roles = array(
    'author' => t('author'),
  ) + user_roles();
  foreach ($roles as $role => $value) {
    $all[$role]['name'] = $value;
  }
  $result = db_query("SELECT t.roles, s1.state AS state_name, s2.state AS target_state_name " . "FROM {workflow_transitions} t " . "INNER JOIN {workflow_states} s1 ON s1.sid = t.sid " . "INNER JOIN {workflow_states} s2 ON s2.sid = t.target_sid " . "WHERE s1.wid = %d " . "ORDER BY s1.weight ASC , s1.state ASC , s2.weight ASC , s2.state ASC", $wid);
  while ($data = db_fetch_object($result)) {
    foreach (explode(',', $data->roles) as $role) {
      $all[$role]['transitions'][] = array(
        $data->state_name,
        WORKFLOW_ARROW,
        $data->target_state_name,
      );
    }
  }
  $output = '';
  $header = array(
    t('From'),
    '',
    t('To'),
  );
  foreach ($all as $role => $value) {
    $output .= '<h3>' . t("%role may do these transitions:", array(
      '%role' => $value['name'],
    )) . '</h3>';
    if ($value['transitions']) {
      $output .= theme('table', $header, $value['transitions']) . '<p></p>';
    }
    else {
      $output .= '<table><tbody><tr class="even"><td>' . t('None') . '</td><td></tr></tbody></table><p></p>';
    }
  }
  return $output;
}