Projet

Général

Profil

Paste
Télécharger (2,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / node / views_handler_field_history_user_timestamp.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_history_user_timestamp.
6
 */
7

    
8
/**
9
 * Field handler to display the marker for new content.
10
 *
11
 * The handler is named history_user, because of compability reasons, the table
12
 * is history.
13
 *
14
 * @ingroup views_field_handlers
15
 */
16
class views_handler_field_history_user_timestamp extends views_handler_field_node {
17

    
18
  /**
19
   * {@inheritdoc}
20
   */
21
  public function init(&$view, &$options) {
22
    parent::init($view, $options);
23
    global $user;
24
    if ($user->uid) {
25
      $this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
26
      $this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
27
      if (module_exists('comment') && !empty($this->options['comments'])) {
28
        $this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
29
      }
30
    }
31
  }
32

    
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function option_definition() {
37
    $options = parent::option_definition();
38

    
39
    $options['comments'] = array('default' => FALSE, 'bool' => TRUE);
40

    
41
    return $options;
42
  }
43

    
44
  /**
45
   * {@inheritdoc}
46
   */
47
  public function options_form(&$form, &$form_state) {
48
    parent::options_form($form, $form_state);
49
    if (module_exists('comment')) {
50
      $form['comments'] = array(
51
        '#type' => 'checkbox',
52
        '#title' => t('Check for new comments as well'),
53
        '#default_value' => !empty($this->options['comments']),
54
        '#fieldset' => 'more',
55
      );
56
    }
57
  }
58

    
59
  /**
60
   * {@inheritdoc}
61
   */
62
  public function query() {
63
    // Only add ourselves to the query if logged in.
64
    global $user;
65
    if (!$user->uid) {
66
      return;
67
    }
68
    parent::query();
69
  }
70

    
71
  /**
72
   * {@inheritdoc}
73
   */
74
  public function render($values) {
75
    // Let's default to 'read' state.
76
    // This code shadows node_mark, but it reads from the db directly and
77
    // we already have that info.
78
    $mark = MARK_READ;
79
    global $user;
80
    if ($user->uid) {
81
      $last_read = $this->get_value($values);
82
      $changed = $this->get_value($values, 'changed');
83

    
84
      $last_comment = module_exists('comment') && !empty($this->options['comments']) ? $this->get_value($values, 'last_comment') : 0;
85

    
86
      if (!$last_read && $changed > NODE_NEW_LIMIT) {
87
        $mark = MARK_NEW;
88
      }
89
      elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
90
        $mark = MARK_UPDATED;
91
      }
92
      elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
93
        $mark = MARK_UPDATED;
94
      }
95
      return $this->render_link(theme('mark', array('type' => $mark)), $values);
96
    }
97
  }
98

    
99
}