uc_roles_handler_field_rid.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @file
  4. * Views handler: Role ID field.
  5. */
  6. /**
  7. * Returns a role id rendered as a role name to display in the View.
  8. */
  9. class uc_roles_handler_field_rid extends views_handler_field {
  10. /**
  11. * Overrides views_handler_field::pre_render().
  12. */
  13. function pre_render(&$values) {
  14. $roles = array();
  15. $this->items = array();
  16. // Get all the unique role ids into the keys of $roles. Initializing into
  17. // array_keys helps prevent us from having a list where the same rid appears
  18. // over and over and over.
  19. foreach ($values as $result) {
  20. $roles[$this->get_value($result, NULL, TRUE)] = FALSE;
  21. }
  22. if ($roles) {
  23. $result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (:rids) ORDER BY r.name",
  24. array(':rids' => array_keys($roles)));
  25. foreach ($result as $role) {
  26. $this->items[$role->rid]['role'] = check_plain($role->name);
  27. $this->items[$role->rid]['rid'] = $role->rid;
  28. }
  29. }
  30. }
  31. /**
  32. * Overrides views_handler_field::render().
  33. */
  34. function render($values) {
  35. // Return the role name corresponding to the role ID.
  36. // @todo: Should we be using this->get_value() here?
  37. $rid = $values->uc_roles_expirations_rid;
  38. if ($rid) {
  39. $role = $this->items[$rid]['role'];
  40. if (!empty($role)) {
  41. return $role;
  42. }
  43. }
  44. }
  45. }