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
|
|
20
|
/**
|
21
|
*
|
22
|
*/
|
23
|
public $formula = NULL;
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function construct() {
|
29
|
parent::construct();
|
30
|
|
31
|
if (!empty($this->definition['formula'])) {
|
32
|
$this->formula = $this->definition['formula'];
|
33
|
}
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
*
|
38
|
*/
|
39
|
public function get_formula() {
|
40
|
return str_replace('***table***', $this->table_alias, $this->formula);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Build the summary query based on a formula
|
45
|
*/
|
46
|
public function summary_query() {
|
47
|
$this->ensure_my_table();
|
48
|
// Now that our table is secure, get our formula.
|
49
|
$formula = $this->get_formula();
|
50
|
|
51
|
// Add the field.
|
52
|
$this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field);
|
53
|
$this->query->set_count_field(NULL, $formula, $this->field);
|
54
|
|
55
|
return $this->summary_basics(FALSE);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Build the query based upon the formula
|
60
|
*/
|
61
|
public function query($group_by = FALSE) {
|
62
|
$this->ensure_my_table();
|
63
|
// Now that our table is secure, get our formula.
|
64
|
$placeholder = $this->placeholder();
|
65
|
$formula = $this->get_formula() . ' = ' . $placeholder;
|
66
|
$placeholders = array(
|
67
|
$placeholder => $this->argument,
|
68
|
);
|
69
|
$this->query->add_where(0, $formula, $placeholders, 'formula');
|
70
|
}
|
71
|
|
72
|
}
|