00001 <?php
00002
00008 class views_handler_field_ncs_last_comment_name extends views_handler_field {
00009 function query() {
00010
00011
00012 $this->ensure_my_table();
00013
00014 $join = new views_join();
00015 $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
00016 $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0'));
00017
00018
00019
00020 $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
00021
00022 $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
00023
00024 $this->user_field = $this->query->add_field($this->user_table, 'name');
00025 $this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid');
00026 }
00027
00028 function option_definition() {
00029 $options = parent::option_definition();
00030
00031 $options['link_to_user'] = array('default' => TRUE);
00032
00033 return $options;
00034 }
00035
00036 function render($values) {
00037 if (!empty($this->options['link_to_user'])) {
00038 $account = new stdClass();
00039 $account->name = $this->get_value($values);
00040 $account->uid = $values->{$this->uid};
00041 return theme('username', array(
00042 'account' => $account
00043 ));
00044 }
00045 else {
00046 return $this->sanitize_value($this->get_value($values));
00047 }
00048 }
00049 }