You are here

function avatar_selection_roles_page in Avatar Selection 7

Same name and namespace in other branches
  1. 5.2 avatar_selection.module \avatar_selection_roles_page()
  2. 6 avatar_selection.admin.inc \avatar_selection_roles_page()

Returns appropriate avatar set by role or og for configuration.

1 string reference to 'avatar_selection_roles_page'
avatar_selection_menu in ./avatar_selection.module
Implements hook_menu().

File

./avatar_selection.admin.inc, line 292
Administrative page callbacks for the avatar_selection module.

Code

function avatar_selection_roles_page($op = NULL) {
  $output = '';

  // Display the form where appropriate.
  if (isset($op) && ($op == 'role' || $op == 'og')) {
    $output = array();
    $output['avatar_selection_edit_form'] = drupal_get_form('avatar_selection_edit_form');
  }
  else {
    $avs_access = array();
    $og_access = array();
    $avs_access[0] = 0;
    $og_access[0] = 0;

    // Get the list of access roles and initialise the count to 0.
    $roles = avatar_selection_handler_filter_role();
    foreach ($roles as $rid => $role_name) {
      $avs_access[$rid] = 0;
    }

    // Get the list of organic groups and initialise the count to 0.
    if (module_exists('og')) {
      $ogroups = avatar_selection_og_options();
      foreach ($ogroups as $ogid => $ogroup_name) {
        $og_access[$ogid] = 0;
      }
    }

    // Get the total number of avatars available on the system.
    $total_count = 0;
    $total_count = db_select('avatar_selection', 'avs')
      ->fields('avs', array(
      'fid',
    ))
      ->countQuery()
      ->execute()
      ->fetchField();
    $output .= '<p>' . t('There is a total of %count avatars configured.', array(
      '%count' => $total_count,
    )) . '</p>';

    // Get the count of avatars per role.
    $result = db_query("SELECT avsr.rid, count(*) AS count FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid GROUP BY avsr.rid");
    foreach ($result as $avatar) {
      if (empty($avatar->rid)) {
        $avs_access[0] += $avatar->count;
      }
      else {
        $avs_access[$avatar->rid] += $avatar->count;
      }
    }

    // Get the count of avatars per organic group.
    $result = db_query("SELECT avso.ogid, count(*) AS count FROM {avatar_selection} avs LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid GROUP BY avso.ogid");
    foreach ($result as $avatar) {
      if (empty($avatar->ogid)) {
        $og_access[0] += $avatar->count;
      }
      else {
        $og_access[$avatar->ogid] += $avatar->count;
      }
    }

    // Format the user roles table.
    $avs_rows = array();
    $header = array(
      t('User Role'),
      t('Number of Avatars'),
      t('Operations'),
    );
    $edit = l(t('edit'), 'admin/config/people/avatar_selection/edit/role/0');
    $avs_rows[] = array(
      t('Available to all roles'),
      $avs_access[0],
      $edit,
    );
    foreach ($roles as $rid => $role_name) {
      $edit = l(t('edit'), 'admin/config/people/avatar_selection/edit/role/' . $rid);
      $avs_rows[] = array(
        $role_name,
        $avs_access[$rid],
        $edit,
      );
    }
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $avs_rows,
    ));

    // Format the organic groups table.
    if (module_exists('og')) {
      $og_rows = array();
      $header = array(
        t('Organic Group'),
        t('Number of Avatars'),
        t('Operations'),
      );
      $edit = l(t('edit'), 'admin/config/people/avatar_selection/edit/og/0');
      $og_rows[] = array(
        t('Available to all groups'),
        $og_access[0],
        $edit,
      );
      foreach ($ogroups as $ogid => $ogroup_name) {
        $edit = l(t('edit'), 'admin/config/people/avatar_selection/edit/og/' . $ogid);
        $og_rows[] = array(
          $ogroup_name,
          $og_access[$ogid],
          $edit,
        );
      }
      $output .= theme('table', array(
        'header' => $header,
        'rows' => $og_rows,
      ));
    }
  }
  return $output;
}