You are here

function workbench_access_editors in Workbench Access 7

Display the editors for a section.

If no group specified, then show a list of active groups, otherwise, load the proper form to edit the members of the group.

Parameters

$access_type: The type of access requested (e.g.g taxonomy).

$access_type_id: The id for this specific access (here, a taxnomy term tid).

$type: The page type being displayed (editor or role).

Return value

An editing form or a list of section editors.

See also

workbench_access_editor_form()

1 call to workbench_access_editors()
workbench_access_roles in ./workbench_access.admin.inc
Display the roles for a section.
1 string reference to 'workbench_access_editors'
workbench_access_menu in ./workbench_access.module
Implements hook_menu().

File

./workbench_access.admin.inc, line 533
Workbench Access admin file.

Code

function workbench_access_editors($access_type = NULL, $access_type_id = NULL, $type = 'editor') {
  if (is_null($access_type) || is_null($access_type_id)) {

    // Set proper breadcrumb trails.
    if ($type == 'editor') {
      $breadcrumb[] = l(t('Workbench Access'), 'admin/config/workbench/access');
      workbench_access_breadcrumb($breadcrumb);
    }

    // Ensure that we have configured access controls.
    if (!($active = workbench_access_get_active_tree())) {
      return workbench_access_configuration_needed_message();
    }
    $active['access_scheme']['access_id'] = $access_type_id;
    $active_keys = array_keys($active['active']);
    if ($type == 'role') {
      $output = '<h2>' . t('Editorial assignments by role') . '</h2>';
    }
    elseif ($type == 'editor') {
      $output = '<h2>' . t('Editorial assignments by editor') . '</h2>';
    }
    $output .= '<p>' . t('The following sections are currently active.');
    if (user_access('administer workbench access')) {
      $output .= ' ' . t('You may <a href="!url">enable or disable sections</a>.', array(
        '!url' => url('admin/config/workbench/access/sections'),
      )) . '</p>';
    }
    $rows = array();
    foreach ($active['tree'] as $access_id => $section) {
      if (!isset($active['active'][$access_id])) {
        continue;
      }

      // Nest the children so the user understands the hierarchy.
      if ($section['depth'] == 0 || !isset($active['active'][$section['parent']])) {
        $parent = $section['name'];
      }
      $row = array(
        str_repeat('-', $section['depth']) . ' ' . l($section['name'], 'admin/config/workbench/access/' . "{$type}s/" . $active['access_scheme']['access_type'] . '/' . $access_id),
      );
      $roles = workbench_access_get_roles('access workbench access by role');
      if (empty($roles)) {
        if (user_access('administer permissions')) {
          return t('To continue, at least one role must be have the <a href="!url">Allow all members of this role to be assigned to Workbench Access sections</a> permission', array(
            '!url' => url('admin/people/permissions', array(
              'fragment' => 'module-workbench_access',
            )),
          ));
        }
        else {
          return t('There are no roles who have permission to edit sections. Please contact a site administrator.');
        }
      }
      if ($type == 'editor') {
        if (!isset($roles[DRUPAL_AUTHENTICATED_RID])) {
          $count = db_query("SELECT COUNT(DISTINCT wau.uid) FROM {workbench_access_user} wau\n            INNER JOIN {users_roles} ur ON wau.uid = ur.uid\n            WHERE wau.access_scheme = :access_scheme AND wau.access_id = :access_id\n            AND ur.rid IN (:rids)", array(
            ':access_scheme' => $active['access_scheme']['access_type'],
            ':access_id' => $access_id,
            ':rids' => array_keys($roles),
          ))
            ->fetchField();
        }
        else {
          $count = db_query("SELECT COUNT(DISTINCT wau.uid) FROM {workbench_access_user} wau\n            WHERE wau.access_scheme = :access_scheme AND wau.access_id = :access_id", array(
            ':access_scheme' => $active['access_scheme']['access_type'],
            ':access_id' => $access_id,
          ))
            ->fetchField();
        }
        $row[] = l(format_plural($count, '1 editor', '@count editors'), 'admin/config/workbench/access/editors/' . $active['access_scheme']['access_type'] . '/' . $access_id);
      }
      else {
        $count2 = db_query("SELECT COUNT(DISTINCT war.rid) FROM {workbench_access_role} war\n          WHERE war.access_scheme = :access_scheme AND war.access_id = :access_id\n          AND war.rid IN (:rids)", array(
          ':access_scheme' => $active['access_scheme']['access_type'],
          ':access_id' => $access_id,
          ':rids' => array_keys($roles),
        ))
          ->fetchField();
        $row[] = l(format_plural($count2, '1 role', '@count roles'), 'admin/config/workbench/access/roles/' . $active['access_scheme']['access_type'] . '/' . $access_id);
      }
      $rows[] = $row;
    }
    $header = array(
      t('Section'),
      t('@types', array(
        '@type' => $type,
      )),
    );
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
    $build['content']['#markup'] = $output;
    return $build;
  }
  return drupal_get_form('workbench_access_editor_form', $access_type, $access_type_id);
}