Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/includes/view.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Provides the view object type and associated methods. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 | 5 |
* @defgroup views_objects Objects that represent a View or part of a view |
10 | 6 |
* @{ |
11 | 7 |
* These objects are the core of Views do the bulk of the direction and |
... | ... | |
13 | 9 |
*/ |
14 | 10 |
|
15 | 11 |
/** |
16 |
* An object to contain all of the data to generate a view, plus the member |
|
17 |
* functions to build the view query, execute the query and render the output. |
|
12 |
* An object to contain all of the data to generate a view. |
|
13 |
* |
|
14 |
* Also includes the member functions to build the view query, execute the |
|
15 |
* query and render the output. |
|
18 | 16 |
*/ |
19 | 17 |
class view extends views_db_object { |
20 |
var $db_table = 'views_view'; |
|
21 |
var $base_table = 'node'; |
|
22 |
var $base_field = 'nid'; |
|
18 |
|
|
19 |
/** |
|
20 |
* |
|
21 |
*/ |
|
22 |
public $db_table = 'views_view'; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
*/ |
|
27 |
public $base_table = 'node'; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
*/ |
|
32 |
public $base_field = 'nid'; |
|
23 | 33 |
|
24 | 34 |
/** |
25 | 35 |
* The name of the view. |
26 | 36 |
* |
27 | 37 |
* @var string |
28 | 38 |
*/ |
29 |
var $name = "";
|
|
39 |
public $name = "";
|
|
30 | 40 |
|
31 | 41 |
/** |
32 | 42 |
* The id of the view, which is used only for views in the database. |
33 | 43 |
* |
34 | 44 |
* @var number |
35 | 45 |
*/ |
36 |
var $vid;
|
|
46 |
public $vid;
|
|
37 | 47 |
|
38 | 48 |
/** |
39 | 49 |
* The description of the view, which is used only in the interface. |
40 | 50 |
* |
41 | 51 |
* @var string |
42 | 52 |
*/ |
43 |
var $description;
|
|
53 |
public $description;
|
|
44 | 54 |
|
45 | 55 |
/** |
46 | 56 |
* The "tags" of a view. |
... | ... | |
49 | 59 |
* |
50 | 60 |
* @var string |
51 | 61 |
*/ |
52 |
var $tag;
|
|
62 |
public $tag;
|
|
53 | 63 |
|
54 | 64 |
/** |
55 | 65 |
* The human readable name of the view. |
56 | 66 |
* |
57 | 67 |
* @var string |
58 | 68 |
*/ |
59 |
var $human_name;
|
|
69 |
public $human_name;
|
|
60 | 70 |
|
61 | 71 |
/** |
62 | 72 |
* The core version the view was created for. |
73 |
* |
|
63 | 74 |
* @var int |
64 | 75 |
*/ |
65 |
var $core;
|
|
76 |
public $core;
|
|
66 | 77 |
|
67 | 78 |
/** |
68 | 79 |
* The views-api version this view was created by. |
... | ... | |
71 | 82 |
* |
72 | 83 |
* @var string |
73 | 84 |
*/ |
74 |
var $api_version;
|
|
85 |
public $api_version;
|
|
75 | 86 |
|
76 | 87 |
/** |
77 | 88 |
* Is the view disabled. |
78 | 89 |
* |
79 |
* This value is used for exported view, to provide some default views which aren't enabled. |
|
90 |
* This value is used for exported view, to provide some default views which |
|
91 |
* aren't enabled. |
|
80 | 92 |
* |
81 | 93 |
* @var bool |
82 | 94 |
*/ |
83 |
var $disabled; |
|
95 |
public $disabled; |
|
96 |
|
|
97 |
/** |
|
98 |
* State variable. |
|
99 |
*/ |
|
100 |
public $built = FALSE; |
|
84 | 101 |
|
85 |
// State variables |
|
86 |
var $built = FALSE; |
|
87 |
var $executed = FALSE; |
|
88 |
var $editing = FALSE; |
|
102 |
/** |
|
103 |
* State variable. |
|
104 |
*/ |
|
105 |
public $executed = FALSE; |
|
106 |
|
|
107 |
/** |
|
108 |
* State variable. |
|
109 |
*/ |
|
110 |
public $editing = FALSE; |
|
89 | 111 |
|
90 |
var $args = array(); |
|
91 |
var $build_info = array(); |
|
112 |
/** |
|
113 |
* |
|
114 |
*/ |
|
115 |
public $args = array(); |
|
116 |
|
|
117 |
/** |
|
118 |
* |
|
119 |
*/ |
|
120 |
public $build_info = array(); |
|
92 | 121 |
|
93 |
var $use_ajax = FALSE; |
|
122 |
/** |
|
123 |
* |
|
124 |
*/ |
|
125 |
public $use_ajax = FALSE; |
|
94 | 126 |
|
95 | 127 |
/** |
96 | 128 |
* Where the results of a query will go. |
... | ... | |
99 | 131 |
* |
100 | 132 |
* @var array |
101 | 133 |
*/ |
102 |
var $result = array();
|
|
134 |
public $result = array();
|
|
103 | 135 |
|
104 | 136 |
// May be used to override the current pager info. |
105 |
var $current_page = NULL;
|
|
106 |
var $items_per_page = NULL;
|
|
107 |
var $offset = NULL;
|
|
108 |
var $total_rows = NULL;
|
|
109 |
|
|
110 |
// Places to put attached renderings:
|
|
111 |
var $attachment_before = '';
|
|
112 |
var $attachment_after = '';
|
|
113 |
|
|
114 |
// Exposed widget input |
|
115 |
var $exposed_data = array();
|
|
116 |
var $exposed_input = array();
|
|
137 |
public $current_page = NULL;
|
|
138 |
public $items_per_page = NULL;
|
|
139 |
public $offset = NULL;
|
|
140 |
public $total_rows = NULL;
|
|
141 |
|
|
142 |
// Places to put attached renderings.
|
|
143 |
public $attachment_before = '';
|
|
144 |
public $attachment_after = '';
|
|
145 |
|
|
146 |
// Exposed widget input.
|
|
147 |
public $exposed_data = array();
|
|
148 |
public $exposed_input = array();
|
|
117 | 149 |
// Exposed widget input directly from the $form_state['values']. |
118 |
var $exposed_raw_input = array();
|
|
150 |
public $exposed_raw_input = array();
|
|
119 | 151 |
|
120 | 152 |
// Used to store views that were previously running if we recurse. |
121 |
var $old_view = array();
|
|
153 |
public $old_view = array();
|
|
122 | 154 |
|
123 | 155 |
// To avoid recursion in views embedded into areas. |
124 |
var $parent_views = array();
|
|
156 |
public $parent_views = array();
|
|
125 | 157 |
|
126 | 158 |
// Is the current stored view runned as an attachment to another view. |
127 |
var $is_attachment = NULL;
|
|
159 |
public $is_attachment = NULL;
|
|
128 | 160 |
|
129 | 161 |
// Stores the next steps of form items to handle. |
130 | 162 |
// It's an array of stack items, which contain the form id, the type of form, |
131 | 163 |
// the view, the display and some additional arguments. |
132 | 164 |
// @see views_ui_add_form_to_stack() |
133 | 165 |
// var $stack; |
134 |
|
|
135 | 166 |
/** |
136 | 167 |
* Identifier of the current display. |
137 | 168 |
* |
138 | 169 |
* @var string |
139 | 170 |
*/ |
140 |
var $current_display;
|
|
171 |
public $current_display;
|
|
141 | 172 |
|
142 | 173 |
/** |
143 |
* Where the $query object will reside: |
|
174 |
* Where the $query object will reside:.
|
|
144 | 175 |
* |
145 | 176 |
* @var views_plugin_query |
146 | 177 |
*/ |
147 |
var $query = NULL;
|
|
178 |
public $query = NULL;
|
|
148 | 179 |
|
149 |
/**
|
|
180 |
/** |
|
150 | 181 |
* The current used display plugin. |
151 | 182 |
* |
152 | 183 |
* @var views_plugin_display |
153 | 184 |
*/ |
154 |
var $display_handler;
|
|
185 |
public $display_handler;
|
|
155 | 186 |
|
156 | 187 |
/** |
157 | 188 |
* Stores all display handlers of this view. |
158 | 189 |
* |
159 | 190 |
* @var array[views_display] |
160 | 191 |
*/ |
161 |
var $display;
|
|
192 |
public $display;
|
|
162 | 193 |
|
163 | 194 |
/** |
164 | 195 |
* The current used style plugin. |
165 | 196 |
* |
166 | 197 |
* @var views_plugin_style |
167 | 198 |
*/ |
168 |
var $style_plugin;
|
|
199 |
public $style_plugin;
|
|
169 | 200 |
|
170 | 201 |
/** |
171 | 202 |
* Stored the changed options of the style plugin. |
172 | 203 |
* |
173 | 204 |
* @deprecated Better use $view->style_plugin->options |
205 |
* |
|
174 | 206 |
* @var array |
175 | 207 |
*/ |
176 |
var $style_options;
|
|
208 |
public $style_options;
|
|
177 | 209 |
|
178 | 210 |
/** |
179 | 211 |
* Stores the current active row while rendering. |
180 | 212 |
* |
181 | 213 |
* @var int |
182 | 214 |
*/ |
183 |
var $row_index;
|
|
215 |
public $row_index;
|
|
184 | 216 |
|
185 |
/**
|
|
217 |
/** |
|
186 | 218 |
* Allow to override the url of the current view. |
187 | 219 |
* |
188 | 220 |
* @var string |
189 | 221 |
*/ |
190 |
var $override_url = NULL;
|
|
222 |
public $override_url = NULL;
|
|
191 | 223 |
|
192 | 224 |
/** |
193 | 225 |
* Allow to override the path used for generated urls. |
194 | 226 |
* |
195 | 227 |
* @var string |
196 | 228 |
*/ |
197 |
var $override_path = NULL;
|
|
229 |
public $override_path = NULL;
|
|
198 | 230 |
|
199 | 231 |
/** |
200 | 232 |
* Allow to override the used database which is used for this query. |
201 | 233 |
*/ |
202 |
var $base_database = NULL;
|
|
234 |
public $base_database = NULL;
|
|
203 | 235 |
|
204 | 236 |
/** |
205 | 237 |
* Here comes a list of the possible handler which are active on this view. |
... | ... | |
207 | 239 |
|
208 | 240 |
/** |
209 | 241 |
* Stores the field handlers which are initialized on this view. |
242 |
* |
|
210 | 243 |
* @var array[views_handler_field] |
211 | 244 |
*/ |
212 |
var $field;
|
|
245 |
public $field;
|
|
213 | 246 |
|
214 | 247 |
/** |
215 | 248 |
* Stores the argument handlers which are initialized on this view. |
249 |
* |
|
216 | 250 |
* @var array[views_handler_argument] |
217 | 251 |
*/ |
218 |
var $argument;
|
|
252 |
public $argument;
|
|
219 | 253 |
|
220 | 254 |
/** |
221 | 255 |
* Stores the sort handlers which are initialized on this view. |
256 |
* |
|
222 | 257 |
* @var array[views_handler_sort] |
223 | 258 |
*/ |
224 |
var $sort;
|
|
259 |
public $sort;
|
|
225 | 260 |
|
226 | 261 |
/** |
227 | 262 |
* Stores the filter handlers which are initialized on this view. |
263 |
* |
|
228 | 264 |
* @var array[views_handler_filter] |
229 | 265 |
*/ |
230 |
var $filter;
|
|
266 |
public $filter;
|
|
231 | 267 |
|
232 | 268 |
/** |
233 | 269 |
* Stores the relationship handlers which are initialized on this view. |
270 |
* |
|
234 | 271 |
* @var array[views_handler_relationship] |
235 | 272 |
*/ |
236 |
var $relationship;
|
|
273 |
public $relationship;
|
|
237 | 274 |
|
238 | 275 |
/** |
239 | 276 |
* Stores the area handlers for the header which are initialized on this view. |
277 |
* |
|
240 | 278 |
* @var array[views_handler_area] |
241 | 279 |
*/ |
242 |
var $header;
|
|
280 |
public $header;
|
|
243 | 281 |
|
244 | 282 |
/** |
245 | 283 |
* Stores the area handlers for the footer which are initialized on this view. |
284 |
* |
|
246 | 285 |
* @var array[views_handler_area] |
247 | 286 |
*/ |
248 |
var $footer;
|
|
287 |
public $footer;
|
|
249 | 288 |
|
250 | 289 |
/** |
251 |
* Stores the area handlers for the empty text which are initialized on this view. |
|
290 |
* The area handlers for the empty text which are initialized on this view. |
|
291 |
* |
|
252 | 292 |
* @var array[views_handler_area] |
253 | 293 |
*/ |
254 |
var $empty;
|
|
294 |
public $empty;
|
|
255 | 295 |
|
256 | 296 |
/** |
257 |
* Constructor
|
|
297 |
* Standard PHP constructor.
|
|
258 | 298 |
*/ |
259 |
function __construct() { |
|
299 |
public function __construct() {
|
|
260 | 300 |
parent::init(); |
261 |
// Make sure all of our sub objects are arrays. |
|
301 |
|
|
302 |
// Make sure all of the sub objects are arrays. |
|
262 | 303 |
foreach ($this->db_objects() as $object) { |
263 | 304 |
$this->$object = array(); |
264 | 305 |
} |
... | ... | |
267 | 308 |
/** |
268 | 309 |
* Perform automatic updates when loading or importing a view. |
269 | 310 |
* |
270 |
* Over time, some things about Views or Drupal data has changed. |
|
271 |
* this attempts to do some automatic updates that must happen
|
|
272 |
* to ensure older views will at least try to work.
|
|
311 |
* Over time, some things about Views or Drupal data has changed. this
|
|
312 |
* attempts to do some automatic updates that must happen to ensure older
|
|
313 |
* views will at least try to work. |
|
273 | 314 |
*/ |
274 |
function update() { |
|
315 |
public function update() {
|
|
275 | 316 |
// When views are converted automatically the base_table should be renamed |
276 | 317 |
// to have a working query. |
277 | 318 |
$this->base_table = views_move_table($this->base_table); |
278 | 319 |
} |
279 | 320 |
|
280 |
|
|
281 | 321 |
/** |
282 | 322 |
* Returns a list of the sub-object types used by this view. These types are |
283 | 323 |
* stored on the display, and are used in the build process. |
284 | 324 |
*/ |
285 |
function display_objects() { |
|
325 |
public function display_objects() {
|
|
286 | 326 |
return array('argument', 'field', 'sort', 'filter', 'relationship', 'header', 'footer', 'empty'); |
287 | 327 |
} |
288 | 328 |
|
... | ... | |
298 | 338 |
* Set the arguments that come to this view. Usually from the URL |
299 | 339 |
* but possibly from elsewhere. |
300 | 340 |
*/ |
301 |
function set_arguments($args) { |
|
341 |
public function set_arguments($args) {
|
|
302 | 342 |
$this->args = $args; |
303 | 343 |
} |
304 | 344 |
|
305 | 345 |
/** |
306 | 346 |
* Change/Set the current page for the pager. |
307 | 347 |
*/ |
308 |
function set_current_page($page) { |
|
348 |
public function set_current_page($page) {
|
|
309 | 349 |
$this->current_page = $page; |
310 | 350 |
|
311 | 351 |
// If the pager is already initialized, pass it through to the pager. |
312 | 352 |
if (!empty($this->query->pager)) { |
313 | 353 |
return $this->query->pager->set_current_page($page); |
314 | 354 |
} |
315 |
|
|
316 | 355 |
} |
317 | 356 |
|
318 | 357 |
/** |
319 | 358 |
* Get the current page from the pager. |
320 | 359 |
*/ |
321 |
function get_current_page() { |
|
360 |
public function get_current_page() {
|
|
322 | 361 |
// If the pager is already initialized, pass it through to the pager. |
323 | 362 |
if (!empty($this->query->pager)) { |
324 | 363 |
return $this->query->pager->get_current_page(); |
... | ... | |
332 | 371 |
/** |
333 | 372 |
* Get the items per page from the pager. |
334 | 373 |
*/ |
335 |
function get_items_per_page() { |
|
374 |
public function get_items_per_page() {
|
|
336 | 375 |
// If the pager is already initialized, pass it through to the pager. |
337 | 376 |
if (!empty($this->query->pager)) { |
338 | 377 |
return $this->query->pager->get_items_per_page(); |
... | ... | |
346 | 385 |
/** |
347 | 386 |
* Set the items per page on the pager. |
348 | 387 |
*/ |
349 |
function set_items_per_page($items_per_page) { |
|
388 |
public function set_items_per_page($items_per_page) {
|
|
350 | 389 |
$this->items_per_page = $items_per_page; |
351 | 390 |
|
352 | 391 |
// If the pager is already initialized, pass it through to the pager. |
... | ... | |
358 | 397 |
/** |
359 | 398 |
* Get the pager offset from the pager. |
360 | 399 |
*/ |
361 |
function get_offset() { |
|
400 |
public function get_offset() {
|
|
362 | 401 |
// If the pager is already initialized, pass it through to the pager. |
363 | 402 |
if (!empty($this->query->pager)) { |
364 | 403 |
return $this->query->pager->get_offset(); |
... | ... | |
372 | 411 |
/** |
373 | 412 |
* Set the offset on the pager. |
374 | 413 |
*/ |
375 |
function set_offset($offset) { |
|
414 |
public function set_offset($offset) {
|
|
376 | 415 |
$this->offset = $offset; |
377 | 416 |
|
378 | 417 |
// If the pager is already initialized, pass it through to the pager. |
... | ... | |
384 | 423 |
/** |
385 | 424 |
* Determine if the pager actually uses a pager. |
386 | 425 |
*/ |
387 |
function use_pager() { |
|
426 |
public function use_pager() {
|
|
388 | 427 |
if (!empty($this->query->pager)) { |
389 | 428 |
return $this->query->pager->use_pager(); |
390 | 429 |
} |
... | ... | |
395 | 434 |
* tablesorting and exposed filters will be fetched via an AJAX call |
396 | 435 |
* rather than a page refresh. |
397 | 436 |
*/ |
398 |
function set_use_ajax($use_ajax) { |
|
437 |
public function set_use_ajax($use_ajax) {
|
|
399 | 438 |
$this->use_ajax = $use_ajax; |
400 | 439 |
} |
401 | 440 |
|
... | ... | |
403 | 442 |
* Set the exposed filters input to an array. If unset they will be taken |
404 | 443 |
* from $_GET when the time comes. |
405 | 444 |
*/ |
406 |
function set_exposed_input($filters) { |
|
445 |
public function set_exposed_input($filters) {
|
|
407 | 446 |
$this->exposed_input = $filters; |
408 | 447 |
} |
409 | 448 |
|
410 | 449 |
/** |
411 | 450 |
* Figure out what the exposed input for this view is. |
412 | 451 |
*/ |
413 |
function get_exposed_input() { |
|
452 |
public function get_exposed_input() {
|
|
414 | 453 |
if (empty($this->exposed_input)) { |
415 | 454 |
$this->exposed_input = array(); |
416 | 455 |
|
... | ... | |
439 | 478 |
/** |
440 | 479 |
* Set the display for this view and initialize the display handler. |
441 | 480 |
*/ |
442 |
function init_display($reset = FALSE) { |
|
481 |
public function init_display($reset = FALSE) {
|
|
443 | 482 |
// The default display is always the first one in the list. |
444 | 483 |
if (isset($this->current_display)) { |
445 | 484 |
return TRUE; |
446 | 485 |
} |
447 | 486 |
|
448 |
// Instantiate all displays |
|
487 |
// Instantiate all displays.
|
|
449 | 488 |
foreach (array_keys($this->display) as $id) { |
450 | 489 |
// Correct for shallow cloning |
451 | 490 |
// Often we'll have a cloned view so we don't mess up each other's |
... | ... | |
481 | 520 |
/** |
482 | 521 |
* Get the first display that is accessible to the user. |
483 | 522 |
* |
484 |
* @param $displays |
|
523 |
* @param string|array $displays
|
|
485 | 524 |
* Either a single display id or an array of display ids. |
486 | 525 |
*/ |
487 |
function choose_display($displays) { |
|
526 |
public function choose_display($displays) {
|
|
488 | 527 |
if (!is_array($displays)) { |
489 | 528 |
return $displays; |
490 | 529 |
} |
... | ... | |
503 | 542 |
/** |
504 | 543 |
* Set the display as current. |
505 | 544 |
* |
506 |
* @param $display_id |
|
545 |
* @param string $display_id
|
|
507 | 546 |
* The id of the display to mark as current. |
508 | 547 |
*/ |
509 |
function set_display($display_id = NULL) { |
|
548 |
public function set_display($display_id = NULL) {
|
|
510 | 549 |
// If we have not already initialized the display, do so. But be careful. |
511 | 550 |
if (empty($this->current_display)) { |
512 | 551 |
$this->init_display(); |
... | ... | |
542 | 581 |
return FALSE; |
543 | 582 |
} |
544 | 583 |
|
545 |
// Set a shortcut |
|
584 |
// Set a shortcut.
|
|
546 | 585 |
$this->display_handler = &$this->display[$display_id]->handler; |
547 | 586 |
|
548 | 587 |
return TRUE; |
... | ... | |
554 | 593 |
* Note that arguments may have changed which style plugin we use, so |
555 | 594 |
* check the view object first, then ask the display handler. |
556 | 595 |
*/ |
557 |
function init_style() { |
|
596 |
public function init_style() {
|
|
558 | 597 |
if (isset($this->style_plugin)) { |
559 | 598 |
return is_object($this->style_plugin); |
560 | 599 |
} |
... | ... | |
570 | 609 |
return FALSE; |
571 | 610 |
} |
572 | 611 |
|
573 |
// init the new style handler with data.
|
|
612 |
// Init the new style handler with data..
|
|
574 | 613 |
$this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options); |
575 | 614 |
return TRUE; |
576 | 615 |
} |
... | ... | |
581 | 620 |
* This will try to add relationships automatically if it can, and will |
582 | 621 |
* remove the handlers if it cannot. |
583 | 622 |
*/ |
584 |
function fix_missing_relationships() { |
|
623 |
public function fix_missing_relationships() {
|
|
585 | 624 |
if (isset($this->relationships_fixed)) { |
586 | 625 |
return; |
587 | 626 |
} |
... | ... | |
665 | 704 |
/** |
666 | 705 |
* Acquire and attach all of the handlers. |
667 | 706 |
*/ |
668 |
function init_handlers() { |
|
707 |
public function init_handlers() {
|
|
669 | 708 |
if (empty($this->inited)) { |
670 | 709 |
$this->fix_missing_relationships(); |
671 | 710 |
foreach (views_object_types() as $key => $info) { |
... | ... | |
676 | 715 |
} |
677 | 716 |
|
678 | 717 |
/** |
679 |
* Initialize the pager |
|
718 |
* Initialize the pager.
|
|
680 | 719 |
* |
681 | 720 |
* Like style initialization, pager initialization is held until late |
682 | 721 |
* to allow for overrides. |
683 | 722 |
*/ |
684 |
function init_pager() { |
|
723 |
public function init_pager() {
|
|
685 | 724 |
if (empty($this->query->pager)) { |
686 | 725 |
// If the query doesn't exist, initialize it. |
687 | 726 |
if (empty($this->query)) { |
... | ... | |
709 | 748 |
* Create a list of base tables eligible for this view. Used primarily |
710 | 749 |
* for the UI. Display must be already initialized. |
711 | 750 |
*/ |
712 |
function get_base_tables() { |
|
751 |
public function get_base_tables() {
|
|
713 | 752 |
$base_tables = array( |
714 | 753 |
$this->base_table => TRUE, |
715 | 754 |
'#global' => TRUE, |
... | ... | |
724 | 763 |
/** |
725 | 764 |
* Run the pre_query() on all active handlers. |
726 | 765 |
*/ |
727 |
function _pre_query() { |
|
766 |
public function _pre_query() {
|
|
728 | 767 |
foreach (views_object_types() as $key => $info) { |
729 | 768 |
$handlers = &$this->$key; |
730 | 769 |
$position = 0; |
... | ... | |
739 | 778 |
/** |
740 | 779 |
* Run the post_execute() on all active handlers. |
741 | 780 |
*/ |
742 |
function _post_execute() { |
|
781 |
public function _post_execute() {
|
|
743 | 782 |
foreach (views_object_types() as $key => $info) { |
744 | 783 |
$handlers = &$this->$key; |
745 | 784 |
foreach ($handlers as $id => $handler) { |
... | ... | |
751 | 790 |
/** |
752 | 791 |
* Attach all of the handlers for each type. |
753 | 792 |
* |
754 |
* @param $key |
|
755 |
* One of 'argument', 'field', 'sort', 'filter', 'relationship' |
|
756 |
* @param $info |
|
793 |
* @param string $key
|
|
794 |
* One of 'argument', 'field', 'sort', 'filter', 'relationship'.
|
|
795 |
* @param array $info
|
|
757 | 796 |
* The $info from views_object_types for this object. |
758 | 797 |
*/ |
759 |
function _init_handler($key, $info) { |
|
798 |
public function _init_handler($key, $info) {
|
|
760 | 799 |
// Load the requested items from the display onto the object. |
761 | 800 |
$this->$key = &$this->display_handler->get_handlers($key); |
762 | 801 |
|
... | ... | |
774 | 813 |
/** |
775 | 814 |
* Build all the arguments. |
776 | 815 |
*/ |
777 |
function _build_arguments() { |
|
816 |
public function _build_arguments() {
|
|
778 | 817 |
// Initially, we want to build sorts and fields. This can change, though, |
779 | 818 |
// if we get a summary view. |
780 | 819 |
if (empty($this->argument)) { |
... | ... | |
816 | 855 |
} |
817 | 856 |
} |
818 | 857 |
|
819 |
// Set the argument, which will also validate that the argument can be set. |
|
858 |
// Set the argument, which will also validate that the argument can be |
|
859 |
// set. |
|
820 | 860 |
if (!$argument->set_argument($arg)) { |
821 | 861 |
$status = $argument->validate_fail($arg); |
822 | 862 |
break; |
... | ... | |
830 | 870 |
$argument->query($this->display_handler->use_group_by()); |
831 | 871 |
} |
832 | 872 |
|
833 |
// Add this argument's substitution |
|
873 |
// Add this argument's substitution.
|
|
834 | 874 |
$substitutions['%' . ($position + 1)] = $arg_title; |
835 | 875 |
$substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg)); |
836 | 876 |
|
... | ... | |
852 | 892 |
// Allow the argument to muck with this breadcrumb. |
853 | 893 |
$argument->set_breadcrumb($this->build_info['breadcrumb']); |
854 | 894 |
|
855 |
// Test to see if we should use this argument's title |
|
895 |
// Test to see if we should use this argument's title.
|
|
856 | 896 |
if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) { |
857 | 897 |
$title = $argument->options['title']; |
858 | 898 |
} |
... | ... | |
865 | 905 |
break; |
866 | 906 |
} |
867 | 907 |
|
868 |
// Be safe with references and loops:
|
|
908 |
// Be safe with references and loops.
|
|
869 | 909 |
unset($argument); |
870 | 910 |
} |
871 | 911 |
|
... | ... | |
883 | 923 |
/** |
884 | 924 |
* Do some common building initialization. |
885 | 925 |
*/ |
886 |
function init_query() { |
|
926 |
public function init_query() {
|
|
887 | 927 |
if (!empty($this->query)) { |
888 | 928 |
$class = get_class($this->query); |
889 | 929 |
if ($class && $class != 'stdClass') { |
... | ... | |
917 | 957 |
/** |
918 | 958 |
* Build the query for the view. |
919 | 959 |
*/ |
920 |
function build($display_id = NULL) { |
|
960 |
public function build($display_id = NULL) {
|
|
921 | 961 |
if (!empty($this->built)) { |
922 | 962 |
return; |
923 | 963 |
} |
... | ... | |
936 | 976 |
|
937 | 977 |
// Attempt to load from cache. |
938 | 978 |
// @todo Load a build_info from cache. |
939 |
|
|
940 | 979 |
$start = microtime(TRUE); |
941 | 980 |
// If that fails, let's build! |
942 | 981 |
$this->build_info = array( |
... | ... | |
950 | 989 |
// Call a module hook and see if it wants to present us with a |
951 | 990 |
// pre-built query or instruct us not to build the query for |
952 | 991 |
// some reason. |
953 |
// @todo: Implement this. Use the same mechanism Panels uses. |
|
954 |
|
|
992 |
// @todo Implement this. Use the same mechanism Panels uses. |
|
955 | 993 |
// Run through our handlers and ensure they have necessary information. |
956 | 994 |
$this->init_handlers(); |
957 | 995 |
|
... | ... | |
971 | 1009 |
$exposed_errors = count($errors_after) > count($errors_before); |
972 | 1010 |
if ($exposed_errors || !empty($this->build_info['abort'])) { |
973 | 1011 |
$this->built = TRUE; |
974 |
// Don't execute the query, but rendering will still be executed to display the empty text. |
|
1012 |
// Don't execute the query, but rendering will still be executed to |
|
1013 |
// display the empty text. |
|
975 | 1014 |
$this->executed = TRUE; |
976 | 1015 |
return empty($this->build_info['fail']); |
977 | 1016 |
} |
... | ... | |
985 | 1024 |
$filter_groups = $this->display_handler->get_option('filter_groups'); |
986 | 1025 |
if ($filter_groups) { |
987 | 1026 |
$this->query->set_group_operator($filter_groups['operator']); |
988 |
foreach($filter_groups['groups'] as $id => $operator) { |
|
1027 |
foreach ($filter_groups['groups'] as $id => $operator) {
|
|
989 | 1028 |
$this->query->set_where_group($operator, $id); |
990 | 1029 |
} |
991 | 1030 |
} |
... | ... | |
1030 | 1069 |
$this->_build('footer'); |
1031 | 1070 |
$this->_build('empty'); |
1032 | 1071 |
|
1033 |
// Allow display handler to affect the query:
|
|
1072 |
// Allow display handler to affect the query.
|
|
1034 | 1073 |
$this->display_handler->query($this->display_handler->use_group_by()); |
1035 | 1074 |
|
1036 |
// Allow style handler to affect the query:
|
|
1075 |
// Allow style handler to affect the query.
|
|
1037 | 1076 |
$this->style_plugin->query($this->display_handler->use_group_by()); |
1038 | 1077 |
|
1039 |
// Allow exposed form to affect the query:
|
|
1078 |
// Allow exposed form to affect the query.
|
|
1040 | 1079 |
if (isset($exposed_form)) { |
1041 | 1080 |
$exposed_form->query(); |
1042 | 1081 |
} |
... | ... | |
1057 | 1096 |
$this->built = TRUE; |
1058 | 1097 |
$this->build_time = microtime(TRUE) - $start; |
1059 | 1098 |
|
1060 |
// Attach displays |
|
1099 |
// Attach displays.
|
|
1061 | 1100 |
$this->attach_displays(); |
1062 | 1101 |
|
1063 | 1102 |
// Let modules modify the view just after building it. |
... | ... | |
1076 | 1115 |
* The type of handlers (filter etc.) which should be iterated over to |
1077 | 1116 |
* build the relationship and query information. |
1078 | 1117 |
*/ |
1079 |
function _build($key) { |
|
1118 |
public function _build($key) {
|
|
1080 | 1119 |
$handlers = &$this->$key; |
1081 | 1120 |
foreach ($handlers as $id => $data) { |
1082 | 1121 |
|
... | ... | |
1097 | 1136 |
} |
1098 | 1137 |
} |
1099 | 1138 |
$rc = $handlers[$id]->accept_exposed_input($this->exposed_data); |
1100 |
$handlers[$id]->store_exposed_input($this->exposed_data, $rc);
|
|
1139 |
$handlers[$id]->store_exposed_input($this->exposed_input, $rc);
|
|
1101 | 1140 |
if (!$rc) { |
1102 | 1141 |
continue; |
1103 | 1142 |
} |
... | ... | |
1119 | 1158 |
* Return whether the executing was successful, for example an argument |
1120 | 1159 |
* could stop the process. |
1121 | 1160 |
*/ |
1122 |
function execute($display_id = NULL) { |
|
1161 |
public function execute($display_id = NULL) {
|
|
1123 | 1162 |
if (empty($this->built)) { |
1124 | 1163 |
if (!$this->build($display_id)) { |
1125 | 1164 |
return FALSE; |
... | ... | |
1130 | 1169 |
return TRUE; |
1131 | 1170 |
} |
1132 | 1171 |
|
1133 |
// Don't allow to use deactivated displays, but display them on the live preview. |
|
1172 |
// Don't allow to use deactivated displays, but display them on the live |
|
1173 |
// preview. |
|
1134 | 1174 |
if (!$this->display[$this->current_display]->handler->get_option('enabled') && empty($this->live_preview)) { |
1135 | 1175 |
$this->build_info['fail'] = TRUE; |
1136 | 1176 |
return FALSE; |
... | ... | |
1150 | 1190 |
$cache = $this->display_handler->get_plugin('cache'); |
1151 | 1191 |
} |
1152 | 1192 |
if ($cache && $cache->cache_get('results')) { |
1153 |
if($this->query->pager->use_pager() || !empty($this->get_total_rows)) { |
|
1193 |
if ($this->query->pager->use_pager() || !empty($this->get_total_rows)) {
|
|
1154 | 1194 |
$this->query->pager->total_items = $this->total_rows; |
1155 | 1195 |
$this->query->pager->update_page_info(); |
1156 | 1196 |
} |
... | ... | |
1185 | 1225 |
* @param string $display_id |
1186 | 1226 |
* The machine name of the display, which should be rendered. |
1187 | 1227 |
* |
1188 |
* @return (string|NULL) |
|
1189 |
* Return the output of the rendered view or NULL if something failed in the process. |
|
1228 |
* @return string|NULL |
|
1229 |
* Return the output of the rendered view or NULL if something failed in the |
|
1230 |
* process. |
|
1190 | 1231 |
*/ |
1191 |
function render($display_id = NULL) { |
|
1232 |
public function render($display_id = NULL) {
|
|
1192 | 1233 |
$this->execute($display_id); |
1193 | 1234 |
|
1194 | 1235 |
// Check to see if the build failed. |
... | ... | |
1300 | 1341 |
} |
1301 | 1342 |
|
1302 | 1343 |
/** |
1303 |
* Render a specific field via the field ID and the row # |
|
1344 |
* Render a specific field via the field ID and the row #.
|
|
1304 | 1345 |
* |
1305 | 1346 |
* Note: You might want to use views_plugin_style::render_fields as it |
1306 | 1347 |
* caches the output for you. |
1307 | 1348 |
* |
1308 | 1349 |
* @param string $field |
1309 | 1350 |
* The id of the field to be rendered. |
1310 |
* |
|
1311 | 1351 |
* @param int $row |
1312 | 1352 |
* The row number in the $view->result which is used for the rendering. |
1313 | 1353 |
* |
1314 | 1354 |
* @return string |
1315 | 1355 |
* The rendered output of the field. |
1316 | 1356 |
*/ |
1317 |
function render_field($field, $row) { |
|
1357 |
public function render_field($field, $row) {
|
|
1318 | 1358 |
if (isset($this->field[$field]) && isset($this->result[$row])) { |
1319 | 1359 |
return $this->field[$field]->advanced_render($this->result[$row]); |
1320 | 1360 |
} |
... | ... | |
1332 | 1372 |
* |
1333 | 1373 |
* If you simply want to view the display, use view::preview() instead. |
1334 | 1374 |
*/ |
1335 |
function execute_display($display_id = NULL, $args = array()) { |
|
1375 |
public function execute_display($display_id = NULL, $args = array()) {
|
|
1336 | 1376 |
if (empty($this->current_display) || $this->current_display != $this->choose_display($display_id)) { |
1337 | 1377 |
if (!$this->set_display($display_id)) { |
1338 | 1378 |
return FALSE; |
... | ... | |
1341 | 1381 |
|
1342 | 1382 |
$this->pre_execute($args); |
1343 | 1383 |
|
1344 |
// Execute the view |
|
1384 |
// Execute the view.
|
|
1345 | 1385 |
$output = $this->display_handler->execute(); |
1346 | 1386 |
|
1347 | 1387 |
$this->post_execute(); |
... | ... | |
1355 | 1395 |
* Can also be called when views are embedded, as this guarantees |
1356 | 1396 |
* normalized output. |
1357 | 1397 |
*/ |
1358 |
function preview($display_id = NULL, $args = array()) { |
|
1398 |
public function preview($display_id = NULL, $args = array()) {
|
|
1359 | 1399 |
if (empty($this->current_display) || ((!empty($display_id)) && $this->current_display != $display_id)) { |
1360 | 1400 |
if (!$this->set_display($display_id)) { |
1361 | 1401 |
return FALSE; |
... | ... | |
1375 | 1415 |
* Run attachments and let the display do what it needs to do prior |
1376 | 1416 |
* to running. |
1377 | 1417 |
*/ |
1378 |
function pre_execute($args = array()) { |
|
1418 |
public function pre_execute($args = array()) {
|
|
1379 | 1419 |
$this->old_view[] = views_get_current_view(); |
1380 | 1420 |
views_set_current_view($this); |
1381 | 1421 |
$display_id = $this->current_display; |
... | ... | |
1386 | 1426 |
$this->set_arguments($args); |
1387 | 1427 |
} |
1388 | 1428 |
|
1389 |
// Let modules modify the view just prior to executing it. |
|
1390 |
foreach (module_implements('views_pre_view') as $module) { |
|
1391 |
$function = $module . '_views_pre_view'; |
|
1429 |
// Trigger hook_views_pre_preview(). Allow other modules to modify the view |
|
1430 |
// just prior to executing the preview. |
|
1431 |
foreach (module_implements('views_pre_preview') as $module) { |
|
1432 |
$function = $module . '_views_pre_preview'; |
|
1392 | 1433 |
$function($this, $display_id, $this->args); |
1393 | 1434 |
} |
1394 | 1435 |
|
1395 |
// Allow hook_views_pre_view() to set the dom_id, then ensure it is set. |
|
1436 |
// Allow hook_views_pre_preview() to set the dom_id, then ensure it is set.
|
|
1396 | 1437 |
$this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->name . REQUEST_TIME . rand()); |
1397 | 1438 |
|
1398 |
// Allow the display handler to set up for execution |
|
1439 |
// Allow the display handler to set up for execution.
|
|
1399 | 1440 |
$this->display_handler->pre_execute(); |
1400 | 1441 |
} |
1401 | 1442 |
|
1402 | 1443 |
/** |
1403 | 1444 |
* Unset the current view, mostly. |
1404 | 1445 |
*/ |
1405 |
function post_execute() { |
|
1446 |
public function post_execute() {
|
|
1406 | 1447 |
// unset current view so we can be properly destructed later on. |
1407 | 1448 |
// Return the previous value in case we're an attachment. |
1408 |
|
|
1409 | 1449 |
if ($this->old_view) { |
1410 | 1450 |
$old_view = array_pop($this->old_view); |
1411 | 1451 |
} |
... | ... | |
1416 | 1456 |
/** |
1417 | 1457 |
* Run attachment displays for the view. |
1418 | 1458 |
*/ |
1419 |
function attach_displays() { |
|
1459 |
public function attach_displays() {
|
|
1420 | 1460 |
if (!empty($this->is_attachment)) { |
1421 | 1461 |
return; |
1422 | 1462 |
} |
... | ... | |
1436 | 1476 |
} |
1437 | 1477 |
|
1438 | 1478 |
/** |
1439 |
* Called to get hook_menu() information from the view and the named display handler.
|
|
1479 |
* Called to get hook_menu() info from the view and the named display handler. |
|
1440 | 1480 |
* |
1441 |
* @param $display_id |
|
1481 |
* @param string $display_id
|
|
1442 | 1482 |
* A display id. |
1443 |
* @param $callbacks |
|
1483 |
* @param array $callbacks
|
|
1444 | 1484 |
* A menu callback array passed from views_menu_alter(). |
1445 | 1485 |
*/ |
1446 |
function execute_hook_menu($display_id = NULL, &$callbacks = array()) { |
|
1486 |
public function execute_hook_menu($display_id = NULL, &$callbacks = array()) {
|
|
1447 | 1487 |
// Prepare the view with the information we have. |
1448 |
|
|
1449 | 1488 |
// This was probably already called, but it's good to be safe. |
1450 | 1489 |
if (!$this->set_display($display_id)) { |
1451 | 1490 |
return FALSE; |
1452 | 1491 |
} |
1453 | 1492 |
|
1454 |
// Execute the view |
|
1493 |
// Execute the view.
|
|
1455 | 1494 |
if (isset($this->display_handler)) { |
1456 | 1495 |
return $this->display_handler->execute_hook_menu($callbacks); |
1457 | 1496 |
} |
... | ... | |
1461 | 1500 |
* Called to get hook_block information from the view and the |
1462 | 1501 |
* named display handler. |
1463 | 1502 |
*/ |
1464 |
function execute_hook_block_list($display_id = NULL) { |
|
1503 |
public function execute_hook_block_list($display_id = NULL) {
|
|
1465 | 1504 |
// Prepare the view with the information we have. |
1466 |
|
|
1467 | 1505 |
// This was probably already called, but it's good to be safe. |
1468 | 1506 |
if (!$this->set_display($display_id)) { |
1469 | 1507 |
return FALSE; |
1470 | 1508 |
} |
1471 | 1509 |
|
1472 |
// Execute the view |
|
1510 |
// Execute the view.
|
|
1473 | 1511 |
if (isset($this->display_handler)) { |
1474 | 1512 |
return $this->display_handler->execute_hook_block_list(); |
1475 | 1513 |
} |
1476 | 1514 |
} |
1477 | 1515 |
|
1478 | 1516 |
/** |
1479 |
* Determine if the given user has access to the view. Note that |
|
1480 |
* this sets the display handler if it hasn't been. |
|
1517 |
* Determine if the given user has access to the view. |
|
1518 |
* |
|
1519 |
* Note that this sets the display handler if it hasn't been. |
|
1481 | 1520 |
*/ |
1482 |
function access($displays = NULL, $account = NULL) { |
|
1521 |
public function access($displays = NULL, $account = NULL) {
|
|
1483 | 1522 |
// No one should have access to disabled views. |
1484 | 1523 |
if (!empty($this->disabled)) { |
1485 | 1524 |
return FALSE; |
... | ... | |
1493 | 1532 |
$account = $GLOBALS['user']; |
1494 | 1533 |
} |
1495 | 1534 |
|
1496 |
// We can't use choose_display() here because that function |
|
1497 |
// calls this one. |
|
1498 |
$displays = (array)$displays; |
|
1535 |
// We can't use choose_display() here because that function calls this one. |
|
1536 |
$displays = (array) $displays; |
|
1499 | 1537 |
foreach ($displays as $display_id) { |
1500 | 1538 |
if (!empty($this->display[$display_id]->handler)) { |
1501 | 1539 |
if ($this->display[$display_id]->handler->access($account)) { |
... | ... | |
1508 | 1546 |
} |
1509 | 1547 |
|
1510 | 1548 |
/** |
1511 |
* Get the view's current title. This can change depending upon how it |
|
1512 |
* was built. |
|
1549 |
* Get the view's current title. |
|
1550 |
* |
|
1551 |
* This can change depending upon how it was built. |
|
1513 | 1552 |
*/ |
1514 |
function get_title() { |
|
1553 |
public function get_title() {
|
|
1515 | 1554 |
if (empty($this->display_handler)) { |
1516 | 1555 |
if (!$this->set_display('default')) { |
1517 | 1556 |
return FALSE; |
... | ... | |
1538 | 1577 |
* |
1539 | 1578 |
* The tokens in the title get's replaced before rendering. |
1540 | 1579 |
*/ |
1541 |
function set_title($title) { |
|
1542 |
$this->build_info['title'] = $title;
|
|
1543 |
return TRUE;
|
|
1544 |
}
|
|
1580 |
public function set_title($title) {
|
|
1581 |
$this->build_info['title'] = $title; |
|
1582 |
return TRUE; |
|
1583 |
} |
|
1545 | 1584 |
|
1546 | 1585 |
/** |
1547 | 1586 |
* Return the human readable name for a view. |
1548 | 1587 |
* |
1549 |
* When a certain view doesn't have a human readable name return the machine readable name. |
|
1588 |
* When a certain view doesn't have a human readable name return the machine |
|
1589 |
* readable name. |
|
1550 | 1590 |
*/ |
1551 |
function get_human_name() { |
|
1591 |
public function get_human_name() {
|
|
1552 | 1592 |
if (!empty($this->human_name)) { |
1553 | 1593 |
$human_name = $this->human_name; |
1554 | 1594 |
} |
... | ... | |
1561 | 1601 |
/** |
1562 | 1602 |
* Force the view to build a title. |
1563 | 1603 |
*/ |
1564 |
function build_title() { |
|
1604 |
public function build_title() {
|
|
1565 | 1605 |
$this->init_display(); |
1566 | 1606 |
|
1567 | 1607 |
if (empty($this->built)) { |
... | ... | |
1578 | 1618 |
* |
1579 | 1619 |
* This URL will be adjusted for arguments. |
1580 | 1620 |
*/ |
1581 |
function get_url($args = NULL, $path = NULL) { |
|
1621 |
public function get_url($args = NULL, $path = NULL) {
|
|
1582 | 1622 |
if (!empty($this->override_url)) { |
1583 | 1623 |
return $this->override_url; |
1584 | 1624 |
} |
... | ... | |
1600 | 1640 |
} |
1601 | 1641 |
} |
1602 | 1642 |
} |
1603 |
// Don't bother working if there's nothing to do:
|
|
1643 |
// Don't bother working if there's nothing to do.
|
|
1604 | 1644 |
if (empty($path) || (empty($args) && strpos($path, '%') === FALSE)) { |
1605 | 1645 |
return $path; |
1606 | 1646 |
} |
... | ... | |
1619 | 1659 |
$pieces[] = $this->argument[$id]->options['exception']['value']; |
1620 | 1660 |
} |
1621 | 1661 |
else { |
1622 |
$pieces[] = '*'; // gotta put something if there just isn't one. |
|
1662 |
$pieces[] = '*'; |
|
1663 |
// @todo Gotta put something if there just isn't one. |
|
1623 | 1664 |
} |
1624 | 1665 |
|
1625 | 1666 |
} |
... | ... | |
1642 | 1683 |
/** |
1643 | 1684 |
* Get the base path used for this view. |
1644 | 1685 |
*/ |
1645 |
function get_path() { |
|
1686 |
public function get_path() {
|
|
1646 | 1687 |
if (!empty($this->override_path)) { |
1647 | 1688 |
return $this->override_path; |
1648 | 1689 |
} |
... | ... | |
1658 | 1699 |
/** |
1659 | 1700 |
* Get the breadcrumb used for this view. |
1660 | 1701 |
* |
1661 |
* @param $set |
|
1702 |
* @param bool $set
|
|
1662 | 1703 |
* If true, use drupal_set_breadcrumb() to install the breadcrumb. |
1663 | 1704 |
*/ |
1664 |
function get_breadcrumb($set = FALSE) { |
|
1705 |
public function get_breadcrumb($set = FALSE) {
|
|
1665 | 1706 |
// Now that we've built the view, extract the breadcrumb. |
1666 | 1707 |
$base = TRUE; |
1667 | 1708 |
$breadcrumb = array(); |
... | ... | |
1690 | 1731 |
} |
1691 | 1732 |
|
1692 | 1733 |
/** |
1693 |
* Is this view cacheable? |
|
1734 |
* Is this view cacheable?.
|
|
1694 | 1735 |
*/ |
1695 |
function is_cacheable() { |
|
1736 |
public function is_cacheable() {
|
|
1696 | 1737 |
return $this->is_cacheable; |
1697 | 1738 |
} |
1698 | 1739 |
|
1699 | 1740 |
/** |
1700 | 1741 |
* Set up query capturing. |
1701 | 1742 |
* |
1702 |
* db_query() stores the queries that it runs in global $queries, |
|
1703 |
* bit only if dev_query is set to true. In this case, we want |
|
1704 |
* to temporarily override that setting if it's not and we |
|
1705 |
* can do that without forcing a db rewrite by just manipulating |
|
1706 |
* $conf. This is kind of evil but it works. |
|
1743 |
* Db_query() stores the queries that it runs in global $queries, bit only if |
|
1744 |
* dev_query is set to true. In this case, we want to temporarily override |
|
1745 |
* that setting if it's not and we can do that without forcing a db rewrite by |
|
1746 |
* just manipulating $conf. This is kind of evil but it works. |
|
1707 | 1747 |
*/ |
1708 |
function start_query_capture() { |
|
1748 |
public function start_query_capture() {
|
|
1709 | 1749 |
global $conf, $queries; |
1710 | 1750 |
if (empty($conf['dev_query'])) { |
1711 | 1751 |
$this->fix_dev_query = TRUE; |
1712 | 1752 |
$conf['dev_query'] = TRUE; |
1713 | 1753 |
} |
1714 | 1754 |
|
1715 |
// Record the last query key used; anything already run isn't |
|
1716 |
// a query that we are interested in.
|
|
1755 |
// Record the last query key used; anything already run isn't a query that
|
|
1756 |
// we are interested in. |
|
1717 | 1757 |
$this->last_query_key = NULL; |
1718 | 1758 |
|
1719 | 1759 |
if (!empty($queries)) { |
... | ... | |
1727 | 1767 |
* |
1728 | 1768 |
* @see view::start_query_capture() |
1729 | 1769 |
*/ |
1730 |
function end_query_capture() { |
|
1770 |
public function end_query_capture() {
|
|
1731 | 1771 |
global $conf, $queries; |
1732 | 1772 |
if (!empty($this->fix_dev_query)) { |
1733 | 1773 |
$conf['dev_query'] = FALSE; |
1734 | 1774 |
} |
1735 | 1775 |
|
1736 |
// make a copy of the array so we can manipulate it with array_splice.
|
|
1776 |
// Make a copy of the array so we can manipulate it with array_splice.
|
|
1737 | 1777 |
$temp = $queries; |
1738 | 1778 |
|
1739 | 1779 |
// Scroll through the queries until we get to our last query key. |
1740 | 1780 |
// Unset anything in our temp array. |
1741 | 1781 |
if (isset($this->last_query_key)) { |
1742 |
while (list($id, $query) = each($queries)) {
|
|
1782 |
foreach ($queries as $id => $query) {
|
|
1743 | 1783 |
if ($id == $this->last_query_key) { |
1744 | 1784 |
break; |
1745 | 1785 |
} |
... | ... | |
1754 | 1794 |
/** |
1755 | 1795 |
* Static factory method to load a list of views based upon a $where clause. |
1756 | 1796 |
* |
1757 |
* Although this method could be implemented to simply iterate over views::load(),
|
|
1758 |
* that would be very slow. Buiding the views externally from unified queries is
|
|
1759 |
* much faster. |
|
1797 |
* Although this method could be implemented to simply iterate over |
|
1798 |
* views::load(), that would be very slow. Buiding the views externally from
|
|
1799 |
* unified queries is much faster.
|
|
1760 | 1800 |
*/ |
1761 | 1801 |
static function load_views() { |
1762 | 1802 |
$result = db_query("SELECT DISTINCT v.* FROM {views_view} v"); |
... | ... | |
1764 | 1804 |
|
1765 | 1805 |
// Load all the views. |
1766 | 1806 |
foreach ($result as $data) { |
1767 |
$view = new view; |
|
1807 |
$view = new view();
|
|
1768 | 1808 |
$view->load_row($data); |
1769 | 1809 |
$view->loaded = TRUE; |
1770 | 1810 |
$view->type = t('Normal'); |
... | ... | |
1777 | 1817 |
return array(); |
1778 | 1818 |
} |
1779 | 1819 |
|
1780 |
// Now load all the subtables:
|
|
1820 |
// Now load all the subtables.
|
|
1781 | 1821 |
foreach (view::db_objects() as $key) { |
1782 | 1822 |
$object_name = "views_$key"; |
1783 | 1823 |
$result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN (:vids) ORDER BY vid, position", |
... | ... | |
1787 | 1827 |
$object = new $object_name(FALSE); |
1788 | 1828 |
$object->load_row($data); |
1789 | 1829 |
|
1790 |
// Because it can get complicated with this much indirection, |
|
1791 |
// make a shortcut reference.
|
|
1830 |
// Because it can get complicated with this much indirection, make a
|
|
1831 |
// shortcut reference. |
|
1792 | 1832 |
$location = &$views[$names[$object->vid]]->$key; |
1793 | 1833 |
|
1794 | 1834 |
// If we have a basic id field, load the item onto the view based on |
... | ... | |
1805 | 1845 |
} |
1806 | 1846 |
|
1807 | 1847 |
/** |
1808 |
* Save the view to the database. If the view does not already exist, |
|
1809 |
* A vid will be assigned to the view and also returned from this function. |
|
1848 |
* Save the view to the database. |
|
1849 |
* |
|
1850 |
* If the view does not already exist a vid will be assigned to the view and |
|
1851 |
* also returned from this function. |
|
1810 | 1852 |
*/ |
1811 |
function save() { |
|
1853 |
public function save() {
|
|
1812 | 1854 |
if ($this->vid == 'new') { |
1813 | 1855 |
$this->vid = NULL; |
1814 | 1856 |
} |
1815 |
// If there is no vid, check if a view with this machine name already exists. |
|
1857 |
// If there is no vid, check if a view with this machine name already |
|
1858 |
// exists. |
|
1816 | 1859 |
elseif (empty($this->vid)) { |
1817 | 1860 |
$vid = db_query("SELECT vid from {views_view} WHERE name = :name", array(':name' => $this->name))->fetchField(); |
1818 | 1861 |
$this->vid = $vid ? $vid : NULL; |
... | ... | |
1826 | 1869 |
try { |
1827 | 1870 |
// If we have no vid or our vid is a string, this is a new view. |
1828 | 1871 |
if (!empty($this->vid)) { |
1829 |
// remove existing table entries |
|
1872 |
// remove existing table entries.
|
|
1830 | 1873 |
foreach ($this->db_objects() as $key) { |
1831 | 1874 |
db_delete('views_' . $key) |
1832 | 1875 |
->condition('vid', $this->vid) |
... | ... | |
1857 | 1900 |
} |
1858 | 1901 |
|
1859 | 1902 |
/** |
1860 |
* Save a row to the database for the given key, which is one of the |
|
1861 |
* keys from view::db_objects() |
|
1903 |
* Save a row to the database for the given key. |
|
1904 |
* |
|
1905 |
* i.e. one of the keys from view::db_objects(). |
|
1862 | 1906 |
*/ |
1863 |
function _save_rows($key) { |
|
1907 |
public function _save_rows($key) {
|
|
1864 | 1908 |
$count = 0; |
1865 | 1909 |
foreach ($this->$key as $position => $object) { |
1866 | 1910 |
$object->position = ++$count; |
... | ... | |
1872 | 1916 |
/** |
1873 | 1917 |
* Delete the view from the database. |
1874 | 1918 |
*/ |
1875 |
function delete($clear = TRUE) { |
|
1919 |
public function delete($clear = TRUE) {
|
|
1876 | 1920 |
if (empty($this->vid)) { |
1877 | 1921 |
return; |
1878 | 1922 |
} |
... | ... | |
1882 | 1926 |
->execute(); |
1883 | 1927 |
// Delete from all of our subtables as well. |
1884 | 1928 |
foreach ($this->db_objects() as $key) { |
1885 |
db_delete('views_'. $key) |
|
1929 |
db_delete('views_' . $key)
|
|
1886 | 1930 |
->condition('vid', $this->vid) |
1887 | 1931 |
->execute(); |
1888 | 1932 |
} |
... | ... | |
1901 | 1945 |
/** |
1902 | 1946 |
* Export a view as PHP code. |
1903 | 1947 |
*/ |
1904 |
function export($indent = '') { |
|
1948 |
public function export($indent = '') {
|
|
1905 | 1949 |
$this->init_display(); |
1906 | 1950 |
$this->init_query(); |
1907 | 1951 |
$output = ''; |
1908 | 1952 |
$output .= $this->export_row('view', $indent); |
1909 |
// Set the API version |
|
1953 |
// Set the API version.
|
|
1910 | 1954 |
$output .= $indent . '$view->api_version = \'' . views_api_version() . "';\n"; |
1911 | 1955 |
$output .= $indent . '$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */' . "\n"; |
1912 | 1956 |
|
... | ... | |
1914 | 1958 |
$output .= "\n" . $indent . "/* Display: $display->display_title */\n"; |
1915 | 1959 |
$output .= $indent . '$handler = $view->new_display(' . ctools_var_export($display->display_plugin, $indent) . ', ' . ctools_var_export($display->display_title, $indent) . ', \'' . $id . "');\n"; |
1916 | 1960 |
if (empty($display->handler)) { |
1917 |
// @todo -- probably need a method of exporting broken displays as
|
|
1918 |
// they may simply be broken because a module is not installed. That
|
|
1919 |
// does not invalidate the display.
|
|
1961 |
// @todo Probably need a method of exporting broken displays as they
|
|
1962 |
// may simply be broken because a module is not installed. That does
|
|
1963 |
// not invalidate the display. |
|
1920 | 1964 |
continue; |
1921 | 1965 |
} |
1922 | 1966 |
|
... | ... | |
1936 | 1980 |
} |
1937 | 1981 |
|
1938 | 1982 |
/** |
1939 |
* Make a copy of this view that has been sanitized of all database IDs |
|
1940 |
* and handlers and other stuff. |
|
1983 |
* Make a copy of this view with IDs, handlers sanitized |
|
1941 | 1984 |
* |
1942 | 1985 |
* I'd call this clone() but it's reserved. |
1943 | 1986 |
*/ |
1944 |
function copy() { |
|
1987 |
public function copy() {
|
|
1945 | 1988 |
$code = $this->export(); |
1946 | 1989 |
eval($code); |
1947 | 1990 |
return $view; |
... | ... | |
1950 | 1993 |
/** |
1951 | 1994 |
* Safely clone a view. |
1952 | 1995 |
* |
1953 |
* Because views are complicated objects within objects, and PHP loves to |
|
1954 |
* do references to everything, if a View is not properly and safely |
|
1955 |
* cloned it will still have references to the original view, and can |
|
1956 |
* actually cause the original view to point to objects in the cloned |
|
1957 |
* view. This gets ugly fast. |
|
1996 |
* Because views are complicated objects within objects, and PHP loves to do |
|
1997 |
* references to everything, if a View is not properly and safely cloned it |
|
1998 |
* will still have references to the original view, and can actually cause the |
|
1999 |
* original view to point to objects in the cloned view. This gets ugly fast. |
|
1958 | 2000 |
* |
1959 | 2001 |
* This will completely wipe a view clean so it can be considered fresh. |
1960 | 2002 |
* |
1961 | 2003 |
* @return view |
1962 | 2004 |
* The cloned view. |
1963 | 2005 |
*/ |
1964 |
function clone_view() { |
|
2006 |
public function clone_view() {
|
|
1965 | 2007 |
$clone = clone $this; |
1966 | 2008 |
|
1967 | 2009 |
$keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon'); |
... | ... | |
1976 | 2018 |
$clone->attachment_after = ''; |
1977 | 2019 |
$clone->result = array(); |
1978 | 2020 |
|
1979 |
// shallow cloning means that all the display objects
|
|
1980 |
// *were not cloned*. We must clone them ourselves.
|
|
2021 |
// Shallow cloning means that all the display objects *were not cloned*. We
|
|
2022 |
// must clone them ourselves. |
|
1981 | 2023 |
$displays = array(); |
1982 | 2024 |
foreach ($clone->display as $id => $display) { |
1983 | 2025 |
$displays[$id] = clone $display; |
... | ... | |
1991 | 2033 |
} |
1992 | 2034 |
|
1993 | 2035 |
/** |
1994 |
* Unset references so that a $view object may be properly garbage |
|
1995 |
* collected. |
|
2036 |
* Unset references so that a $view object may be properly garbage collected. |
|
1996 | 2037 |
*/ |
1997 |
function destroy() { |
|
2038 |
public function destroy() {
|
|
1998 | 2039 |
foreach (array_keys($this->display) as $display_id) { |
1999 | 2040 |
if (isset($this->display[$display_id]->handler) && is_object($this->display[$display_id]->handler)) { |
2000 | 2041 |
$this->display[$display_id]->handler->destroy(); |
... | ... | |
2055 | 2096 |
/** |
2056 | 2097 |
* Make sure the view is completely valid. |
2057 | 2098 |
* |
2058 |
* @return |
|
2099 |
* @return bool
|
|
2059 | 2100 |
* TRUE if the view is valid; an array of error strings if it is not. |
2060 | 2101 |
*/ |
2061 |
function validate() { |
|
2102 |
public function validate() {
|
|
2062 | 2103 |
$this->init_display(); |
2063 | 2104 |
|
2064 | 2105 |
$errors = array(); |
... | ... | |
2087 | 2128 |
/** |
2088 | 2129 |
* Find and initialize the localization plugin. |
2089 | 2130 |
*/ |
2090 |
function init_localization() { |
|
2131 |
public function init_localization() {
|
|
2091 | 2132 |
// If the translate attribute isn't set, init the localization plugin. |
2092 | 2133 |
if (!isset($this->localization_plugin->translate)) { |
2093 | 2134 |
$this->localization_plugin = views_get_plugin('localization', views_get_localization_plugin()); |
... | ... | |
2111 | 2152 |
/** |
2112 | 2153 |
* Determine whether a view supports admin string translation. |
2113 | 2154 |
*/ |
2114 |
function is_translatable() { |
|
2155 |
public function is_translatable() {
|
|
2115 | 2156 |
// Use translation no matter what type of view. |
2116 | 2157 |
if (variable_get('views_localize_all', FALSE)) { |
2117 | 2158 |
return TRUE; |
... | ... | |
2124 | 2165 |
/** |
2125 | 2166 |
* Send strings for localization. |
2126 | 2167 |
*/ |
2127 |
function save_locale_strings() { |
|
2168 |
public function save_locale_strings() {
|
|
2128 | 2169 |
$this->process_locale_strings('save'); |
2129 | 2170 |
} |
2130 | 2171 |
|
2131 | 2172 |
/** |
2132 | 2173 |
* Delete localized strings. |
2133 | 2174 |
*/ |
2134 |
function delete_locale_strings() { |
|
2175 |
public function delete_locale_strings() {
|
|
2135 | 2176 |
$this->process_locale_strings('delete'); |
2136 | 2177 |
} |
2137 | 2178 |
|
2138 | 2179 |
/** |
2139 | 2180 |
* Export localized strings. |
2140 | 2181 |
*/ |
2141 |
function export_locale_strings() { |
|
2182 |
public function export_locale_strings() {
|
|
2142 | 2183 |
$this->process_locale_strings('export'); |
2143 | 2184 |
} |
2144 | 2185 |
|
2145 | 2186 |
/** |
2146 | 2187 |
* Process strings for localization, deletion or export to code. |
2147 | 2188 |
*/ |
2148 |
function process_locale_strings($op) { |
|
2189 |
public function process_locale_strings($op) {
|
|
2149 | 2190 |
// Ensure this view supports translation, we have a display, and we |
2150 | 2191 |
// have a localization plugin. |
2151 |
// @fixme Export does not init every handler.
|
|
2192 |
// @todo Export does not init every handler.
|
|
2152 | 2193 |
if (($this->is_translatable() || $op == 'export') && $this->init_display() && $this->init_localization()) { |
2153 | 2194 |
$this->localization_plugin->process_locale_strings($op); |
2154 | 2195 |
} |
... | ... | |
2160 | 2201 |
* Base class for views' database objects. |
2161 | 2202 |
*/ |
2162 | 2203 |
class views_db_object { |
2204 |
|
|
2163 | 2205 |
public $db_table; |
2164 | 2206 |
|
2165 | 2207 |
/** |
2166 | 2208 |
* Initialize this object, setting values from schema defaults. |
2167 | 2209 |
* |
2168 |
* @param $init |
|
2210 |
* @param array|bool $init
|
|
2169 | 2211 |
* If an array, this is a set of values from db_fetch_object to |
2170 | 2212 |
* load. Otherwse, if TRUE values will be filled in from schema |
2171 | 2213 |
* defaults. |
2172 | 2214 |
*/ |
2173 |
function init($init = TRUE) { |
|
2215 |
public function init($init = TRUE) {
|
|
2174 | 2216 |
if (is_array($init)) { |
2175 | 2217 |
return $this->load_row($init); |
2176 | 2218 |
} |
... | ... | |
2207 | 2249 |
/** |
2208 | 2250 |
* Write the row to the database. |
2209 | 2251 |
* |
2210 |
* @param $update |
|
2252 |
* @param bool $update
|
|
2211 | 2253 |
* If true this will be an UPDATE query. Otherwise it will be an INSERT. |
2212 | 2254 |
*/ |
2213 |
function save_row($update = NULL) { |
|
2255 |
public function save_row($update = NULL) {
|
|
2214 | 2256 |
$fields = $defs = $values = $serials = array(); |
2215 | 2257 |
$schema = drupal_get_schema($this->db_table); |
2216 | 2258 |
|
2217 | 2259 |
// Go through our schema and build correlations. |
2218 | 2260 |
foreach ($schema['fields'] as $field => $info) { |
2219 |
// special case -- skip serial types if we are updating.
|
|
2261 |
// Special case - skip serial types if we are updating.
|
|
2220 | 2262 |
if ($info['type'] == 'serial') { |
2221 | 2263 |
$serials[] = $field; |
2222 | 2264 |
continue; |
... | ... | |
2238 | 2280 |
->execute(); |
2239 | 2281 |
|
2240 | 2282 |
if ($serials && !$update) { |
2241 |
// get last insert ids and fill them in. |
|
2242 |
// Well, one ID. |
|
2283 |
// Get last insert ids and fill them in. Well, one ID. |
|
2243 | 2284 |
foreach ($serials as $field) { |
2244 | 2285 |
$this->$field = $return; |
2245 | 2286 |
} |
... | ... | |
2249 | 2290 |
/** |
2250 | 2291 |
* Load the object with a row from the database. |
2251 | 2292 |
* |
Formats disponibles : Unified diff
Weekly update of contrib modules