Projet

Général

Profil

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

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

1
<?php
2

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

    
8
/**
9
 * Filter for new content.
10
 *
11
 * The handler is named history_user, because of compability reasons, the table
12
 * is history.
13
 *
14
 * @ingroup views_filter_handlers
15
 */
16
class views_handler_filter_history_user_timestamp extends views_handler_filter {
17

    
18
  /**
19
   * Don't display empty space where the operator would be.
20
   */
21
  public $no_operator = TRUE;
22

    
23
  /**
24
   * {@inheritdoc}
25
   */
26
  public function expose_form(&$form, &$form_state) {
27
    parent::expose_form($form, $form_state);
28
    // @todo There are better ways of excluding required and multiple (object flags)
29
    unset($form['expose']['required']);
30
    unset($form['expose']['multiple']);
31
    unset($form['expose']['remember']);
32
  }
33

    
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function value_form(&$form, &$form_state) {
38
    // Only present a checkbox for the exposed filter itself. There's no way
39
    // to tell the difference between not checked and the default value, so
40
    // specifying the default value via the views UI is meaningless.
41
    if (!empty($form_state['exposed'])) {
42
      if (isset($this->options['expose']['label'])) {
43
        $label = $this->options['expose']['label'];
44
      }
45
      else {
46
        $label = t('Has new content');
47
      }
48
      $form['value'] = array(
49
        '#type' => 'checkbox',
50
        '#title' => $label,
51
        '#default_value' => $this->value,
52
      );
53
    }
54
  }
55

    
56
  /**
57
   * {@inheritdoc}
58
   */
59
  public function query() {
60
    global $user;
61
    // This can only work if we're logged in.
62
    if (!$user || !$user->uid) {
63
      return;
64
    }
65

    
66
    // Don't filter if we're exposed and the checkbox isn't selected.
67
    if ((!empty($this->options['exposed'])) && empty($this->value)) {
68
      return;
69
    }
70

    
71
    // Hey, Drupal kills old history, so nodes that haven't been updated
72
    // since NODE_NEW_LIMIT are bzzzzzzzt outta here!
73
    $limit = REQUEST_TIME - NODE_NEW_LIMIT;
74

    
75
    $this->ensure_my_table();
76
    $field = "$this->table_alias.$this->real_field";
77
    $node = $this->query->ensure_table('node', $this->relationship);
78

    
79
    $clause = '';
80
    $clause2 = '';
81
    if (module_exists('comment')) {
82
      $ncs = $this->query->ensure_table('node_comment_statistics', $this->relationship);
83
      $clause = ("OR $ncs.last_comment_timestamp > (***CURRENT_TIME*** - $limit)");
84
      $clause2 = "OR $field < $ncs.last_comment_timestamp";
85
    }
86

    
87
    // NULL means a history record doesn't exist. That's clearly new content.
88
    // Unless it's very very old content. Everything in the query is already
89
    // type safe cause none of it is coming from outside here.
90
    $this->query->add_where_expression($this->options['group'], "($field IS NULL AND ($node.changed > (***CURRENT_TIME*** - $limit) $clause)) OR $field < $node.changed $clause2");
91
  }
92

    
93
  /**
94
   * {@inheritdoc}
95
   */
96
  public function admin_summary() {
97
    if (!empty($this->options['exposed'])) {
98
      return t('exposed');
99
    }
100
  }
101

    
102
}