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

File

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