Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / handlers / views_handler_argument_formula.inc @ a6e869e4

1
<?php
2

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

    
8
/**
9
 * Abstract argument handler for simple formulae.
10
 *
11
 * Child classes of this object should implement summary_argument, at least.
12
 *
13
 * Definition terms:
14
 * - formula: The formula to use for this handler.
15
 *
16
 * @ingroup views_argument_handlers
17
 */
18
class views_handler_argument_formula extends views_handler_argument {
19
  var $formula = NULL;
20
  /**
21
   * Constructor
22
   */
23
  function construct() {
24
    parent::construct();
25

    
26
    if (!empty($this->definition['formula'])) {
27
      $this->formula = $this->definition['formula'];
28
    }
29
  }
30

    
31
  function get_formula() {
32
    return str_replace('***table***', $this->table_alias, $this->formula);
33
  }
34

    
35
  /**
36
   * Build the summary query based on a formula
37
   */
38
  function summary_query() {
39
    $this->ensure_my_table();
40
    // Now that our table is secure, get our formula.
41
    $formula = $this->get_formula();
42

    
43
    // Add the field.
44
    $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field);
45
    $this->query->set_count_field(NULL, $formula, $this->field);
46

    
47
    return $this->summary_basics(FALSE);
48
  }
49

    
50
  /**
51
   * Build the query based upon the formula
52
   */
53
  function query($group_by = FALSE) {
54
    $this->ensure_my_table();
55
    // Now that our table is secure, get our formula.
56
    $placeholder = $this->placeholder();
57
    $formula = $this->get_formula() .' = ' . $placeholder;
58
    $placeholders = array(
59
      $placeholder => $this->argument,
60
    );
61
    $this->query->add_where(0, $formula, $placeholders, 'formula');
62
  }
63
}