views_handler_field_ncs_last_comment_name.inc

  1. 3.x modules/comment/views_handler_field_ncs_last_comment_name.inc
  2. 2.x modules/comment/views_handler_field_ncs_last_comment_name.inc

File

modules/comment/views_handler_field_ncs_last_comment_name.inc
View source
  1. <?php
  2. /**
  3. * Field handler to present the name of the last comment poster
  4. */
  5. class views_handler_field_ncs_last_comment_name extends views_handler_field {
  6. function query() {
  7. // last_comment_name only contains data if the user is anonymous. So we
  8. // have to join in a specially related user table.
  9. $this->ensure_my_table();
  10. // join 'users' to this table via vid
  11. $join = new views_join();
  12. $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
  13. $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0'));
  14. // ncs_user alias so this can work with the sort handler, below.
  15. // $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
  16. $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
  17. $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
  18. $this->user_field = $this->query->add_field($this->user_table, 'name');
  19. $this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid');
  20. }
  21. function option_definition() {
  22. $options = parent::option_definition();
  23. $options['link_to_user'] = array('default' => TRUE);
  24. return $options;
  25. }
  26. function render($values) {
  27. if (!empty($this->options['link_to_user'])) {
  28. $account = new stdClass();
  29. $account->name = $values->{$this->field_alias};
  30. $account->uid = $values->{$this->uid};
  31. return theme('username', $account);
  32. }
  33. else {
  34. return check_plain($values->{$this->field_alias});
  35. }
  36. }
  37. }