Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | ||
3 | /** | |
4 | * @file | |
5 | * Definition of views_handler_field_ncs_last_comment_name. | |
6 | */ | |
7 | ||
8 | /** | |
9 | * Field handler to present the name of the last comment poster. | |
10 | * | |
11 | * @ingroup views_field_handlers | |
12 | */ | |
13 | class views_handler_field_ncs_last_comment_name extends views_handler_field { | |
14 | function query() { | |
15 | // last_comment_name only contains data if the user is anonymous. So we | |
16 | // have to join in a specially related user table. | |
17 | $this->ensure_my_table(); | |
18 | // join 'users' to this table via vid | |
19 | $join = new views_join(); | |
20 | $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid'); | |
21 | $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0')); | |
22 | ||
23 | // ncs_user alias so this can work with the sort handler, below. | |
24 | // $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship); | |
25 | $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join); | |
26 | ||
27 | $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field); | |
28 | ||
29 | $this->user_field = $this->query->add_field($this->user_table, 'name'); | |
30 | $this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid'); | |
31 | } | |
32 | ||
33 | function option_definition() { | |
34 | $options = parent::option_definition(); | |
35 | ||
36 | $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE); | |
37 | ||
38 | return $options; | |
39 | } | |
40 | ||
41 | function render($values) { | |
42 | if (!empty($this->options['link_to_user'])) { | |
43 | $account = new stdClass(); | |
44 | $account->name = $this->get_value($values); | |
45 | $account->uid = $values->{$this->uid}; | |
46 | return theme('username', array( | |
47 | 'account' => $account | |
48 | )); | |
49 | } | |
50 | else { | |
51 | return $this->sanitize_value($this->get_value($values)); | |
52 | } | |
53 | } | |
54 | } |