Projet

Général

Profil

Paste
Télécharger (4,57 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_query.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * @defgroup views_query_plugins Views query plugins
10
 * @{
11
 * A Views query plugin builds SQL to execute using the Drupal database API.
12
 *
13
 * @see hook_views_plugins()
14
 */
15

    
16
/**
17
 * The base query class, which is the underlying layer in a View.
18
 */
19
class views_plugin_query extends views_plugin {
20

    
21
  /**
22
   * A pager plugin that should be provided by the display.
23
   *
24
   * @var views_plugin_pager
25
   */
26
  public $pager = NULL;
27

    
28
  /**
29
   * Constructor; Create the basic query object and fill with default values.
30
   */
31
  public function init($base_table, $base_field, $options) {
32
    $this->base_table = $base_table;
33
    $this->base_field = $base_field;
34
    $this->unpack_options($this->options, $options);
35
  }
36

    
37
  /**
38
   * Generate a query and a countquery from all of the information supplied
39
   * to the object.
40
   *
41
   * @param bool $get_count
42
   *   Provide a countquery if this is TRUE, otherwise provide a normal query.
43
   *
44
   * @return SelectQuery
45
   *   A SelectQuery object.
46
   */
47
  public function query($get_count = FALSE) {
48
  }
49

    
50
  /**
51
   * Let modules modify the query just prior to finalizing it.
52
   *
53
   * @param view $view
54
   *   The view which is executed.
55
   */
56
  public function alter(&$view) {
57
  }
58

    
59
  /**
60
   * Builds the necessary info to execute the query.
61
   *
62
   * @param view $view
63
   *   The view which is executed.
64
   */
65
  public function build(&$view) {
66
  }
67

    
68
  /**
69
   * Executes the query and fills the associated view object with according
70
   * values.
71
   *
72
   * Values to set: $view->result, $view->total_rows, $view->execute_time,
73
   * $view->pager['current_page'].
74
   *
75
   * $view->result should contain an array of objects. The array must use a
76
   * numeric index starting at 0.
77
   *
78
   * @param view $view
79
   *   The view which is executed.
80
   */
81
  public function execute(&$view) {
82
  }
83

    
84
  /**
85
   * Add a signature to the query, if such a thing is feasible.
86
   *
87
   * This signature is something that can be used when perusing query logs to
88
   * discern where particular queries might be coming from.
89
   *
90
   * @param view $view
91
   *   The view which is executed.
92
   */
93
  public function add_signature(&$view) {
94
  }
95

    
96
  /**
97
   * Get aggregation info for group by queries.
98
   *
99
   * If NULL, aggregation is not allowed.
100
   */
101
  public function get_aggregation_info() {
102
  }
103

    
104
  /**
105
   * Add settings for the ui.
106
   */
107
  public function options_form(&$form, &$form_state) {
108
    parent::options_form($form, $form_state);
109
  }
110

    
111
  /**
112
   * {@inheritdoc}
113
   */
114
  public function options_validate(&$form, &$form_state) {
115
  }
116

    
117
  /**
118
   * {@inheritdoc}
119
   */
120
  public function options_submit(&$form, &$form_state) {
121
  }
122

    
123
  /**
124
   * {@inheritdoc}
125
   */
126
  public function summary_title() {
127
    return t('Settings');
128
  }
129

    
130
  /**
131
   * Set a LIMIT on the query, specifying a maximum number of results.
132
   */
133
  public function set_limit($limit) {
134
    $this->limit = $limit;
135
  }
136

    
137
  /**
138
   * Set an OFFSET on the query, specifying a number of results to skip
139
   */
140
  public function set_offset($offset) {
141
    $this->offset = $offset;
142
  }
143

    
144
  /**
145
   * Render the pager, if necessary.
146
   */
147
  public function render_pager($exposed_input) {
148
    if (!empty($this->pager) && $this->pager->use_pager()) {
149
      return $this->pager->render($exposed_input);
150
    }
151

    
152
    return '';
153
  }
154

    
155
  /**
156
   * Create a new grouping for the WHERE or HAVING clause.
157
   *
158
   * @param string $type
159
   *   Either 'AND' or 'OR'. All items within this group will be added
160
   *   to the WHERE clause with this logical operator.
161
   * @param string $group
162
   *   An ID to use for this group. If unspecified, an ID will be generated.
163
   * @param string $where
164
   *   'where' or 'having'.
165
   *
166
   * @return string
167
   *   The group ID generated.
168
   */
169
  public function set_where_group($type = 'AND', $group = NULL, $where = 'where') {
170
    // Set an alias.
171
    $groups = &$this->$where;
172

    
173
    if (!isset($group)) {
174
      $group = empty($groups) ? 1 : max(array_keys($groups)) + 1;
175
    }
176

    
177
    // Create an empty group
178
    if (empty($groups[$group])) {
179
      $groups[$group] = array('conditions' => array(), 'args' => array());
180
    }
181

    
182
    $groups[$group]['type'] = strtoupper($type);
183
    return $group;
184
  }
185

    
186
  /**
187
   * Control how all WHERE and HAVING groups are put together.
188
   *
189
   * @param string $type
190
   *   Either 'AND' or 'OR'.
191
   */
192
  public function set_group_operator($type = 'AND') {
193
    $this->group_operator = strtoupper($type);
194
  }
195

    
196
  /**
197
   * Returns the according entity objects for the given query results.
198
   */
199
  public function get_result_entities($results, $relationship = NULL) {
200
    return FALSE;
201
  }
202

    
203
}
204

    
205
/**
206
 * @}
207
 */