You are here

function role_expire_handler_field_all::pre_render in Role Expire 7

Run before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

array $values: An array of all objects returned from the query.

Overrides views_handler_field::pre_render

File

./role_expire.views.inc, line 201
Role Expire Views hooks

Class

role_expire_handler_field_all
Class role_expire_handler_field_all.

Code

function pre_render(&$values) {
  $uids = array();
  $this->items = array();
  foreach ($values as $result) {
    $uids[] = $this
      ->get_value($result, NULL, TRUE);
  }
  if ($uids) {
    $format = $this->options['date_format'];
    if (in_array($format, $this
      ->supported_date_types())) {
      $custom_format = $this->options['custom_date_format'];
    }
    else {
      $custom_format = '';
    }
    $result = db_query("SELECT e.uid, e.rid, e.expiry_timestamp, r.name FROM {role_expire} e INNER JOIN {role} r ON r.rid = e.rid WHERE e.uid IN (:uids) ORDER BY r.name", array(
      ':uids' => $uids,
    ));
    foreach ($result as $role) {
      $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
      $expirationDate = format_date(check_plain($role->expiry_timestamp), $format, $custom_format, $timezone);
      $this->items[$role->uid][$role->rid]['role'] = check_plain($role->name) . ' (' . $expirationDate . ')';
      $this->items[$role->uid][$role->rid]['rid'] = $role->rid . ' (' . $expirationDate . ')';
    }
  }
}