5 * Definition of views_handler_field_ncs_last_comment_name.
9 * Field handler to present the name of the last comment poster.
11 * @ingroup views_field_handlers
13 class views_handler_field_ncs_last_comment_name extends views_handler_field {
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'));
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);
27 $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
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');
33 function option_definition() {
34 $options = parent::option_definition();
36 $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
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(
51 return $this->sanitize_value($this->get_value($values));