You are here

function og_role_watchdog_report in Role Watchdog 7

Same name and namespace in other branches
  1. 6.2 modules/og_role_watchdog/og_role_watchdog.pages.inc \og_role_watchdog_report()
  2. 6 modules/og_role_watchdog/og_role_watchdog.pages.inc \og_role_watchdog_report()
  3. 7.2 modules/og_role_watchdog/og_role_watchdog.pages.inc \og_role_watchdog_report()
2 string references to 'og_role_watchdog_report'
og_role_watchdog_menu in modules/og_role_watchdog/og_role_watchdog.module
og_role_watchdog_menu_alter in modules/og_role_watchdog/og_role_watchdog.module
Implementation of hook_menu_alter

File

modules/og_role_watchdog/og_role_watchdog.pages.inc, line 140
User page callbacks for the role_watchdog module.

Code

function og_role_watchdog_report($node = NULL) {
  $output = '';
  $rows = array();
  $roles = user_roles();
  $header = array(
    array(
      'data' => t('Admin'),
      'style' => 'width: 20%;',
    ),
    array(
      'data' => t('Date'),
      'style' => 'width: 20%;',
    ),
    array(
      'data' => t('Group'),
      'style' => 'width: 15%;',
    ),
    array(
      'data' => t('Role'),
      'style' => 'width: 15%;',
    ),
    array(
      'data' => t('Change'),
      'style' => 'width: 15%;',
    ),
    array(
      'data' => t('User'),
      'style' => 'width: 15%;',
    ),
  );
  $query = db_select('role_watchdog', 'rw');
  $query
    ->innerJoin('users', 'u', 'rw.aid = u.uid');
  $query
    ->innerJoin('users', 'u2', 'rw.uid = u2.uid');
  $query
    ->addField('u2', 'name', 'admin');
  $query
    ->addField('rw', 'uid', 'adminid');
  $query
    ->addField('rw', 'aid', 'uid');
  if ($node) {
    $query
      ->join('og_role_watchdog', 'orw', 'orw.hid = rw.hid');
    list($id, $vid, $bundle_name) = entity_extract_ids('node', $node);
    $group = og_get_group('node', $id);
    $query
      ->condition('orw.gid', $group->gid);
    unset($header[2]);
  }
  else {
    $query
      ->leftJoin('og_role_watchdog', 'orw', 'orw.hid = rw.hid');
  }
  $query
    ->addField('orw', 'rid', 'orid');
  $result = $query
    ->extend('PagerDefault')
    ->limit(variable_get('role_watchdog_pager', 50))
    ->fields('rw', array(
    'hid',
    'action',
    'rid',
    'aid',
    'stamp',
  ))
    ->fields('u', array(
    'name',
  ))
    ->fields('orw', array(
    'gid',
  ))
    ->orderBy('rw.stamp', 'DESC')
    ->execute()
    ->fetchAllAssoc('hid');
  $actions = array(
    t('removed from'),
    t('added to'),
    t('requested by'),
    t('approved for'),
    t('blocked'),
    t('unblocked'),
    t('rejected for'),
  );
  $view_profile = user_access('access user profiles');
  foreach ($result as $hid => $row) {
    list($group_name, $role) = _og_role_watchdog_row_group_name($row->gid, $row->rid, $row->orid, $roles);
    $row_data = array(
      $view_profile ? l($row->admin, 'user/' . $row->adminid) : $row->admin,
      format_date($row->stamp),
      $group_name,
      $role,
      $actions[$row->action],
      $view_profile ? l($row->name, 'user/' . $row->uid) : $row->name,
    );
    if ($node) {
      unset($row_data[2]);
    }
    $rows[] = $row_data;
  }
  if (sizeof($rows)) {
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'style' => 'width: 99%;',
      ),
    ));
    $output .= theme('pager', array(
      'tags' => NULL,
    ));
  }
  return $output ? $output : t('No role grants made.');
}