function workflow_permissions in Workflow 5.2
Same name and namespace in other branches
- 5 workflow.module \workflow_permissions()
View workflow permissions by role
Parameters
$wid: The ID of the workflow
1 call to workflow_permissions()
- workflow_edit_form in ./
workflow.module - Menu callback to edit a workflow's properties.
File
- ./
workflow.module, line 951
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 AND s1.status = 1 " . "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(
check_plain(t($data->state_name)),
WORKFLOW_ARROW,
check_plain(t($data->target_state_name)),
);
}
}
$output = '';
$header = array(
t('From'),
'',
t('To'),
);
foreach ($all as $role => $value) {
if ($role == 'author') {
$output .= '<h3>' . t("The author of the post may do these transitions:") . '</h3>';
}
else {
$output .= '<h3>' . t("The role %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;
}