views_handler_sort_ncs_last_comment_name.inc

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

Definition of views_handler_sort_ncs_last_comment_name.

File

modules/comment/views_handler_sort_ncs_last_comment_name.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_sort_ncs_last_comment_name.
  5. */
  6. /**
  7. * Sort handler to sort by last comment name which might be in 2 different
  8. * fields.
  9. *
  10. * @ingroup views_sort_handlers
  11. */
  12. class views_handler_sort_ncs_last_comment_name extends views_handler_sort {
  13. function query() {
  14. $this->ensure_my_table();
  15. $join = new views_join();
  16. $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
  17. // @todo this might be safer if we had an ensure_relationship rather than guessing
  18. // the table alias. Though if we did that we'd be guessing the relationship name
  19. // so that doesn't matter that much.
  20. // $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
  21. $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
  22. $this->user_field = $this->query->add_field($this->user_table, 'name');
  23. // Add the field.
  24. $this->query->add_orderby(NULL, "LOWER(COALESCE($this->user_table.name, $this->table_alias.$this->field))", $this->options['order'], $this->table_alias . '_' . $this->field);
  25. }
  26. }