Projet

Général

Profil

Paste
Télécharger (1,92 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / comment / views_handler_field_ncs_last_comment_name.inc @ 5d12d676

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

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function query() {
19
    // 'last_comment_name' only contains data if the user is anonymous, so join
20
    // in a specially related user table.
21
    $this->ensure_my_table();
22
    // Join 'users' to this table via vid.
23
    $join = new views_join();
24
    $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
25
    $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0'));
26

    
27
    // 'ncs_user' alias so this can work with the sort handler, below.
28
    // $this->user_table = $this->query
29
    //   ->add_relationship(NULL, $join, 'users', $this->relationship);
30
    $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
31

    
32
    $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
33

    
34
    $this->user_field = $this->query->add_field($this->user_table, 'name');
35
    $this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid');
36
  }
37

    
38
  /**
39
   * {@inheritdoc}
40
   */
41
  public function option_definition() {
42
    $options = parent::option_definition();
43

    
44
    $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
45

    
46
    return $options;
47
  }
48

    
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function render($values) {
53
    if (!empty($this->options['link_to_user'])) {
54
      $account = new stdClass();
55
      $account->name = $this->get_value($values);
56
      $account->uid = $values->{$this->uid};
57
      return theme('username', array(
58
        'account' => $account
59
      ));
60
    }
61
    else {
62
      return $this->sanitize_value($this->get_value($values));
63
    }
64
  }
65

    
66
}