You are here

function uc_roles_handler_field_rid::pre_render in Ubercart 7.3

Overrides views_handler_field::pre_render().

Overrides views_handler_field::pre_render

File

uc_roles/views/uc_roles_handler_field_rid.inc, line 16
Views handler: Role ID field.

Class

uc_roles_handler_field_rid
Returns a role id rendered as a role name to display in the View.

Code

function pre_render(&$values) {
  $roles = array();
  $this->items = array();

  // Get all the unique role ids into the keys of $roles. Initializing into
  // array_keys helps prevent us from having a list where the same rid appears
  // over and over and over.
  foreach ($values as $result) {
    $roles[$this
      ->get_value($result, NULL, TRUE)] = FALSE;
  }
  if ($roles) {
    $result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (:rids) ORDER BY r.name", array(
      ':rids' => array_keys($roles),
    ));
    foreach ($result as $role) {
      $this->items[$role->rid]['role'] = check_plain($role->name);
      $this->items[$role->rid]['rid'] = $role->rid;
    }
  }
}