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