Projet

Général

Profil

Révision 5d12d676

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/includes/handlers.inc
6 6
 */
7 7

  
8 8
/**
9
 * Instantiate and construct a new handler
9
 * Instantiate and construct a new handler.
10 10
 */
11 11
function _views_create_handler($definition, $type = 'handler', $handler_type = NULL) {
12
//  debug('Instantiating handler ' . $definition['handler']);
12
  //  debug('Instantiating handler ' . $definition['handler']);
13 13
  if (empty($definition['handler'])) {
14 14
    vpr('_views_create_handler - type: @type - failed: handler has not been provided.',
15
      array('@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type)
15
      array('@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type)
16 16
    );
17 17
    return;
18 18
  }
......
24 24
      '_views_create_handler - loading override handler @type failed: class @override_handler could not be loaded. ' .
25 25
      'Verify the class file has been registered in the corresponding .info-file (files[]).',
26 26
      array(
27
        '@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type,
28
        '@override_handler' => $definition['override handler']
27
        '@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type,
28
        '@override_handler' => $definition['override handler'],
29 29
      )
30 30
    );
31 31
    return;
......
36 36
      '_views_create_handler - loading handler @type failed: class @handler could not be loaded. ' .
37 37
      'Verify the class file has been registered in the corresponding .info-file (files[]).',
38 38
      array(
39
        '@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type,
40
        '@handler' => $definition['handler']
39
        '@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type,
40
        '@handler' => $definition['handler'],
41 41
      )
42 42
    );
43 43
    return;
44 44
  }
45 45

  
46
   if (!empty($definition['override handler'])) {
47
     $handler = new $definition['override handler'];
48
   }
49
   else {
50
     $handler = new $definition['handler'];
51
   }
46
  if (!empty($definition['override handler'])) {
47
    $handler = new $definition['override handler'];
48
  }
49
  else {
50
    $handler = new $definition['handler'];
51
  }
52 52

  
53 53
  $handler->set_definition($definition);
54 54
  if ($type == 'handler') {
......
73 73
function _views_prepare_handler($definition, $data, $field, $type) {
74 74
  foreach (array('group', 'title', 'title short', 'help', 'real field') as $key) {
75 75
    if (!isset($definition[$key])) {
76
      // First check the field level
76
      // First check the field level.
77 77
      if (!empty($data[$field][$key])) {
78 78
        $definition[$key] = $data[$field][$key];
79 79
      }
80
      // Then if that doesn't work, check the table level
80
      // Then if that doesn't work, check the table level.
81 81
      elseif (!empty($data['table'][$key])) {
82 82
        $definition[$key] = $data['table'][$key];
83 83
      }
......
88 88
}
89 89

  
90 90
/**
91
 * Fetch a handler to join one table to a primary table from the data cache
91
 * Fetch a handler to join one table to a primary table from the data cache.
92 92
 */
93 93
function views_get_table_join($table, $base_table) {
94 94
  $data = views_fetch_data($table);
......
101 101
      $handler = new views_join();
102 102
    }
103 103

  
104
    // Fill in some easy defaults
104
    // Fill in some easy defaults.
105 105
    $handler->definition = $h;
106 106
    if (empty($handler->definition['table'])) {
107 107
      $handler->definition['table'] = $table;
......
121 121
    return $handler;
122 122
  }
123 123

  
124
  // DEBUG -- identify missing handlers
124
  // DEBUG -- identify missing handlers.
125 125
  vpr("Missing join: @table @base_table", array('@table' => $table, '@base_table' => $base_table));
126 126
}
127 127

  
......
147 147
 *         field/handler is or does.
148 148
 * - access callback: If this field should have access control, this could
149 149
 *                    be a function to use. 'user_access' is a common
150
 *                    function to use here. If not specified, no access
150
 *                    public function to use here. If not specified, no access
151 151
 *                    control is provided.
152 152
 * - access arguments: An array of arguments for the access callback.
153 153
 */
154 154
class views_handler extends views_object {
155

  
155 156
  /**
156 157
   * The top object of a view.
157 158
   *
158 159
   * @var view
159 160
   */
160
  var $view = NULL;
161
  public $view = NULL;
161 162

  
162 163
  /**
163
   * Where the $query object will reside:
164
   * Where the $query object will reside:.
164 165
   *
165 166
   * @var views_plugin_query
166 167
   */
167
  var $query = NULL;
168
  public $query = NULL;
168 169

  
169 170
  /**
170 171
   * The type of the handler, for example filter/footer/field.
171 172
   */
172
  var $handler_type = NULL;
173
  public $handler_type = NULL;
173 174

  
174 175
  /**
175 176
   * The alias of the table of this handler which is used in the query.
......
180 181
   * The actual field in the database table, maybe different
181 182
   * on other kind of query plugins/special handlers.
182 183
   */
183
  var $real_field;
184
  public $real_field;
184 185

  
185 186
  /**
186 187
   * The relationship used for this field.
187 188
   */
188
  var $relationship = NULL;
189
  public $relationship = NULL;
189 190

  
190 191
  /**
191
   * init the handler with necessary data.
192
   * @param $view
192
   * Init the handler with necessary data.
193
   *
194
   * @param view $view
193 195
   *   The $view object this handler is attached to.
194
   * @param $options
196
   * @param array $options
195 197
   *   The item from the database; the actual contents of this will vary
196 198
   *   based upon the type of handler.
197 199
   */
198
  function init(&$view, &$options) {
200
  public function init(&$view, &$options) {
199 201
    $this->view = &$view;
200 202
    $display_id = $this->view->current_display;
201 203
    // Check to see if this handler type is defaulted. Note that
202 204
    // we have to do a lookup because the type is singular but the
203 205
    // option is stored as the plural.
204

  
205 206
    // If the 'moved to' keyword moved our handler, let's fix that now.
206 207
    if (isset($this->actual_table)) {
207 208
      $options['table'] = $this->actual_table;
......
224 225
      $display_id,
225 226
      $this->handler_type,
226 227
      $options['table'],
227
      $options['id']
228
      $options['id'],
228 229
    );
229 230

  
230 231
    $this->unpack_options($this->options, $options);
......
252 253
    $this->query = &$view->query;
253 254
  }
254 255

  
255
  function option_definition() {
256
  /**
257
   * {@inheritdoc}
258
   */
259
  public function option_definition() {
256 260
    $options = parent::option_definition();
257 261

  
258 262
    $options['id'] = array('default' => '');
......
268 272
  /**
269 273
   * Return a string representing this handler's name in the UI.
270 274
   */
271
  function ui_name($short = FALSE) {
275
  public function ui_name($short = FALSE) {
272 276
    if (!empty($this->options['ui_name'])) {
273 277
      $title = check_plain($this->options['ui_name']);
274 278
      return $title;
......
284 288
   * non-standard fields. Because this takes an argument, fields
285 289
   * overriding this can just call return parent::get_field($formula)
286 290
   */
287
  function get_field($field = NULL) {
291
  public function get_field($field = NULL) {
288 292
    if (!isset($field)) {
289 293
      if (!empty($this->formula)) {
290 294
        $field = $this->get_formula();
......
294 298
      }
295 299
    }
296 300

  
297
    // If grouping, check to see if the aggregation method needs to modify the field.
301
    // If grouping, check to see if the aggregation method needs to modify the
302
    // field.
298 303
    if ($this->view->display_handler->use_group_by()) {
299 304
      $this->view->init_query();
300 305
      if ($this->query) {
......
311 316
  /**
312 317
   * Sanitize the value for output.
313 318
   *
314
   * @param $value
319
   * @param string $value
315 320
   *   The value being rendered.
316
   * @param $type
321
   * @param string $type
317 322
   *   The type of sanitization needed. If not provided, check_plain() is used.
318 323
   *
319 324
   * @return string
320 325
   *   Returns the safe value.
321 326
   */
322
  function sanitize_value($value, $type = NULL) {
327
  public function sanitize_value($value, $type = NULL) {
323 328
    switch ($type) {
324 329
      case 'xss':
325 330
        $value = filter_xss($value);
326 331
        break;
332

  
327 333
      case 'xss_admin':
328 334
        $value = filter_xss_admin($value);
329 335
        break;
336

  
330 337
      case 'url':
331 338
        $value = check_url($value);
332 339
        break;
340

  
333 341
      default:
334 342
        $value = check_plain($value);
335 343
        break;
......
340 348
  /**
341 349
   * Transform a string by a certain method.
342 350
   *
343
   * @param $string
351
   * @param string $string
344 352
   *    The input you want to transform.
345
   * @param $option
353
   * @param array $option
346 354
   *    How do you want to transform it, possible values:
347 355
   *      - upper: Uppercase the string.
348 356
   *      - lower: lowercase the string.
......
352 360
   * @return string
353 361
   *    The transformed string.
354 362
   */
355
  function case_transform($string, $option) {
363
  public function case_transform($string, $option) {
356 364
    global $multibyte;
357 365

  
358 366
    switch ($option) {
......
360 368
        return $string;
361 369
      case 'upper':
362 370
        return drupal_strtoupper($string);
371

  
363 372
      case 'lower':
364 373
        return drupal_strtolower($string);
374

  
365 375
      case 'ucfirst':
366 376
        return drupal_strtoupper(drupal_substr($string, 0, 1)) . drupal_substr($string, 1);
377

  
367 378
      case 'ucwords':
368 379
        if ($multibyte == UNICODE_MULTIBYTE) {
369 380
          return mb_convert_case($string, MB_CASE_TITLE);
......
377 388
  /**
378 389
   * Validate the options form.
379 390
   */
380
  function options_validate(&$form, &$form_state) { }
391
  public function options_validate(&$form, &$form_state) {
392
  }
381 393

  
382 394
  /**
383 395
   * Build the options form.
384 396
   */
385
  function options_form(&$form, &$form_state) {
397
  public function options_form(&$form, &$form_state) {
386 398
    // Some form elements belong in a fieldset for presentation, but can't
387 399
    // be moved into one because of the form_state['values'] hierarchy. Those
388 400
    // elements can add a #fieldset => 'fieldset_name' property, and they'll
......
414 426
   * Perform any necessary changes to the form values prior to storage.
415 427
   * There is no need for this function to actually store the data.
416 428
   */
417
  function options_submit(&$form, &$form_state) { }
429
  public function options_submit(&$form, &$form_state) {
430
  }
418 431

  
419 432
  /**
420 433
   * Provides the handler some groupby.
421 434
   */
422
  function use_group_by() {
435
  public function use_group_by() {
423 436
    return TRUE;
424 437
  }
438

  
425 439
  /**
426 440
   * Provide a form for aggregation settings.
427 441
   */
428
  function groupby_form(&$form, &$form_state) {
442
  public function groupby_form(&$form, &$form_state) {
429 443
    $view = &$form_state['view'];
430 444
    $display_id = $form_state['display_id'];
431 445
    $types = views_object_types();
......
456 470
   * Perform any necessary changes to the form values prior to storage.
457 471
   * There is no need for this function to actually store the data.
458 472
   */
459
  function groupby_form_submit(&$form, &$form_state) {
473
  public function groupby_form_submit(&$form, &$form_state) {
460 474
    $item =& $form_state['handler']->options;
461 475

  
462 476
    $item['group_type'] = $form_state['values']['options']['group_type'];
......
466 480
   * If a handler has 'extra options' it will get a little settings widget and
467 481
   * another form called extra_options.
468 482
   */
469
  function has_extra_options() { return FALSE; }
483
  public function has_extra_options() {
484
    return FALSE;
485
  }
470 486

  
471 487
  /**
472 488
   * Provide defaults for the handler.
473 489
   */
474
  function extra_options(&$option) { }
490
  public function extra_options(&$option) {
491
  }
475 492

  
476 493
  /**
477 494
   * Provide a form for setting options.
478 495
   */
479
  function extra_options_form(&$form, &$form_state) { }
496
  public function extra_options_form(&$form, &$form_state) {
497
  }
480 498

  
481 499
  /**
482 500
   * Validate the options form.
483 501
   */
484
  function extra_options_validate($form, &$form_state) { }
502
  public function extra_options_validate($form, &$form_state) {
503
  }
485 504

  
486 505
  /**
487 506
   * Perform any necessary changes to the form values prior to storage.
488 507
   * There is no need for this function to actually store the data.
489 508
   */
490
  function extra_options_submit($form, &$form_state) { }
509
  public function extra_options_submit($form, &$form_state) {
510
  }
491 511

  
492 512
  /**
493 513
   * Determine if a handler can be exposed.
494 514
   */
495
  function can_expose() { return FALSE; }
515
  public function can_expose() {
516
    return FALSE;
517
  }
496 518

  
497 519
  /**
498 520
   * Set new exposed option defaults when exposed setting is flipped
499 521
   * on.
500 522
   */
501
  function expose_options() { }
523
  public function expose_options() {
524
  }
502 525

  
503 526
  /**
504 527
   * Get information about the exposed form for the form renderer.
505 528
   */
506
  function exposed_info() { }
529
  public function exposed_info() {
530
  }
507 531

  
508 532
  /**
509
   * Render our chunk of the exposed handler form when selecting
533
   * Render our chunk of the exposed handler form when selecting.
510 534
   */
511
  function exposed_form(&$form, &$form_state) { }
535
  public function exposed_form(&$form, &$form_state) {
536
  }
512 537

  
513 538
  /**
514
   * Validate the exposed handler form
539
   * Validate the exposed handler form.
515 540
   */
516
  function exposed_validate(&$form, &$form_state) { }
541
  public function exposed_validate(&$form, &$form_state) {
542
  }
517 543

  
518 544
  /**
519
   * Submit the exposed handler form
545
   * Submit the exposed handler form.
520 546
   */
521
  function exposed_submit(&$form, &$form_state) { }
547
  public function exposed_submit(&$form, &$form_state) {
548
  }
522 549

  
523 550
  /**
524 551
   * Form for exposed handler options.
525 552
   */
526
  function expose_form(&$form, &$form_state) { }
553
  public function expose_form(&$form, &$form_state) {
554
  }
527 555

  
528 556
  /**
529 557
   * Validate the options form.
530 558
   */
531
  function expose_validate($form, &$form_state) { }
559
  public function expose_validate($form, &$form_state) {
560
  }
532 561

  
533 562
  /**
534 563
   * Perform any necessary changes to the form exposes prior to storage.
535 564
   * There is no need for this function to actually store the data.
536 565
   */
537
  function expose_submit($form, &$form_state) { }
566
  public function expose_submit($form, &$form_state) {
567
  }
538 568

  
539 569
  /**
540 570
   * Shortcut to display the expose/hide button.
541 571
   */
542
  function show_expose_button(&$form, &$form_state) { }
572
  public function show_expose_button(&$form, &$form_state) {
573
  }
543 574

  
544 575
  /**
545 576
   * Shortcut to display the exposed options form.
546 577
   */
547
  function show_expose_form(&$form, &$form_state) {
578
  public function show_expose_form(&$form, &$form_state) {
548 579
    if (empty($this->options['exposed'])) {
549 580
      return;
550 581
    }
......
567 598
  /**
568 599
   * Check whether current user has access to this handler.
569 600
   *
570
   * @return boolean
601
   * @return bool
571 602
   */
572
  function access() {
603
  public function access() {
573 604
    if (isset($this->definition['access callback']) && function_exists($this->definition['access callback'])) {
574 605
      if (isset($this->definition['access arguments']) && is_array($this->definition['access arguments'])) {
575 606
        return call_user_func_array($this->definition['access callback'], $this->definition['access arguments']);
......
586 617
   * This gives all the handlers some time to set up before any handler has
587 618
   * been fully run.
588 619
   */
589
  function pre_query() { }
620
  public function pre_query() {
621
  }
590 622

  
591 623
  /**
592 624
   * Run after the view is executed, before the result is cached.
......
595 627
   * used so that handlers that pull up secondary data can put it in the
596 628
   * $values so that the raw data can be utilized externally.
597 629
   */
598
  function post_execute(&$values) { }
630
  public function post_execute(&$values) {
631
  }
599 632

  
600 633
  /**
601 634
   * Provides a unique placeholders for handlers.
602 635
   */
603
  function placeholder() {
636
  public function placeholder() {
604 637
    return $this->query->placeholder($this->options['table'] . '_' . $this->options['field']);
605 638
  }
606 639

  
......
608 641
   * Called just prior to query(), this lets a handler set up any relationship
609 642
   * it needs.
610 643
   */
611
  function set_relationship() {
644
  public function set_relationship() {
612 645
    // Ensure this gets set to something.
613 646
    $this->relationship = NULL;
614 647

  
......
638 671
   * Ensure the main table for this handler is in the query. This is used
639 672
   * a lot.
640 673
   */
641
  function ensure_my_table() {
674
  public function ensure_my_table() {
642 675
    if (!isset($this->table_alias)) {
643 676
      if (!method_exists($this->query, 'ensure_table')) {
644 677
        vpr(t('Ensure my table called but query has no ensure_table method.'));
......
650 683
  }
651 684

  
652 685
  /**
653
   * Provide text for the administrative summary
686
   * Provide text for the administrative summary.
654 687
   */
655
  function admin_summary() { }
688
  public function admin_summary() {
689
  }
656 690

  
657 691
  /**
658 692
   * Determine if the argument needs a style plugin.
659 693
   *
660
   * @return TRUE/FALSE
694
   * @return bool
661 695
   */
662
  function needs_style_plugin() { return FALSE; }
696
  public function needs_style_plugin() {
697
    return FALSE;
698
  }
663 699

  
664 700
  /**
665 701
   * Determine if this item is 'exposed', meaning it provides form elements
666 702
   * to let users modify the view.
667 703
   *
668
   * @return TRUE/FALSE
704
   * @return bool
669 705
   */
670
  function is_exposed() {
706
  public function is_exposed() {
671 707
    return !empty($this->options['exposed']);
672 708
  }
673 709

  
674 710
  /**
675 711
   * Returns TRUE if the exposed filter works like a grouped filter.
676 712
   */
677
  function is_a_group() { return FALSE; }
713
  public function is_a_group() {
714
    return FALSE;
715
  }
678 716

  
679 717
  /**
680 718
   * Define if the exposed input has to be submitted multiple times.
681 719
   * This is TRUE when exposed filters grouped are using checkboxes as
682 720
   * widgets.
683 721
   */
684
  function multiple_exposed_input() { return FALSE; }
722
  public function multiple_exposed_input() {
723
    return FALSE;
724
  }
685 725

  
686 726
  /**
687 727
   * Take input from exposed handlers and assign to this handler, if necessary.
688 728
   */
689
  function accept_exposed_input($input) { return TRUE; }
729
  public function accept_exposed_input($input) {
730
    return TRUE;
731
  }
690 732

  
691 733
  /**
692 734
   * If set to remember exposed input in the session, store it there.
693 735
   */
694
  function store_exposed_input($input, $status) { return TRUE; }
736
  public function store_exposed_input($input, $status) {
737
    return TRUE;
738
  }
695 739

  
696 740
  /**
697 741
   * Get the join object that should be used for this handler.
......
700 744
   * getting the join if it is necessary to make some changes to it, such
701 745
   * as adding an 'extra'.
702 746
   */
703
  function get_join() {
747
  public function get_join() {
704 748
    // get the join from this table that links back to the base table.
705
    // Determine the primary table to seek
749
    // Determine the primary table to seek.
706 750
    if (empty($this->query->relationships[$this->relationship])) {
707 751
      $base_table = $this->query->base_table;
708 752
    }
......
724 768
   *
725 769
   * @see views_handler::options_validate()
726 770
   *
727
   * @return
728
   *   Empty array if the handler is valid; an array of error strings if it is not.
771
   * @return array
772
   *   Empty array if the handler is valid; an array of error strings if it is
773
   *   not.
729 774
   */
730
  function validate() { return array(); }
775
  public function validate() {
776
    return array();
777
  }
731 778

  
732 779
  /**
733
   * Determine if the handler is considered 'broken', meaning it's a
734
   * a placeholder used when a handler can't be found.
780
   * Determine if the handler is considered 'broken'.
781
   *
782
   * Generally only returns TRUE if the handler can't be found.
783
   *
784
   * @return bool
785
   *   The handler could not be loaded.
735 786
   */
736
  function broken() { }
787
  public function broken() {
788
  }
789

  
737 790
}
738 791

  
739 792
/**
......
748 801
 * definition terms:
749 802
 * - numeric: If true, treat this field as numeric, using %d instead of %s in
750 803
 *            queries.
751
 *
752 804
 */
753 805
class views_many_to_one_helper {
806

  
754 807
  /**
755 808
   * Contains possible existing placeholders used by the query.
756 809
   *
......
758 811
   */
759 812
  public $placeholders = array();
760 813

  
761
  function __construct(&$handler) {
814
  /**
815
   * {@inheritdoc}
816
   */
817
  public function __construct(&$handler) {
762 818
    $this->handler = &$handler;
763 819
  }
764 820

  
821
  /**
822
   * {@inheritdoc}
823
   */
765 824
  static function option_definition(&$options) {
766 825
    $options['reduce_duplicates'] = array('default' => FALSE, 'bool' => TRUE);
767 826
  }
768 827

  
769
  function options_form(&$form, &$form_state) {
828
  /**
829
   * {@inheritdoc}
830
   */
831
  public function options_form(&$form, &$form_state) {
770 832
    $form['reduce_duplicates'] = array(
771 833
      '#type' => 'checkbox',
772 834
      '#title' => t('Reduce duplicates'),
......
777 839
  }
778 840

  
779 841
  /**
780
   * Sometimes the handler might want us to use some kind of formula, so give
781
   * it that option. If it wants us to do this, it must set $helper->formula = TRUE
782
   * and implement handler->get_formula();
842
   * Provide an option to use a formula.
843
   *
844
   * If it wants us to do this, it must set $helper->formula = TRUE and
845
   * implement handler->get_formula();.
783 846
   */
784
  function get_field() {
847
  public function get_field() {
785 848
    if (!empty($this->formula)) {
786 849
      return $this->handler->get_formula();
787 850
    }
......
793 856
  /**
794 857
   * Add a table to the query.
795 858
   *
796
   * This is an advanced concept; not only does it add a new instance of the table,
797
   * but it follows the relationship path all the way down to the relationship
798
   * link point and adds *that* as a new relationship and then adds the table to
799
   * the relationship, if necessary.
859
   * This is an advanced concept; not only does it add a new instance of the
860
   * table, but it follows the relationship path all the way down to the
861
   * relationship link point and adds *that* as a new relationship and then adds
862
   * the table to the relationship, if necessary.
800 863
   */
801
  function add_table($join = NULL, $alias = NULL) {
864
  public function add_table($join = NULL, $alias = NULL) {
802 865
    // This is used for lookups in the many_to_one table.
803 866
    $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
804 867

  
......
806 869
      $join = $this->get_join();
807 870
    }
808 871

  
809
    // See if there's a chain between us and the base relationship. If so, we need
810
    // to create a new relationship to use.
872
    // See if there's a chain between us and the base relationship. If so, we
873
    // need to create a new relationship to use.
811 874
    $relationship = $this->handler->relationship;
812 875

  
813
    // Determine the primary table to seek
876
    // Determine the primary table to seek.
814 877
    if (empty($this->handler->query->relationships[$relationship])) {
815 878
      $base_table = $this->handler->query->base_table;
816 879
    }
......
821 884
    // Cycle through the joins. This isn't as error-safe as the normal
822 885
    // ensure_path logic. Perhaps it should be.
823 886
    $r_join = clone $join;
824
    while ($r_join->left_table != $base_table) {
887
    while (!empty($r_join) && $r_join->left_table != $base_table) {
825 888
      $r_join = views_get_table_join($r_join->left_table, $base_table);
826 889
    }
827 890
    // If we found that there are tables in between, add the relationship.
......
844 907
    return $alias;
845 908
  }
846 909

  
847
  function get_join() {
910
  /**
911
   * {@inheritdoc}
912
   */
913
  public function get_join() {
848 914
    return $this->handler->get_join();
849 915
  }
850 916

  
851 917
  /**
852
   * Provide the proper join for summary queries. This is important in part because
853
   * it will cooperate with other arguments if possible.
918
   * Provide the proper join for summary queries.
919
   *
920
   * This is important in part because it will cooperate with other arguments if
921
   * possible.
854 922
   */
855
  function summary_join() {
923
  public function summary_join() {
856 924
    $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
857 925
    $join = $this->get_join();
858 926

  
859
    // shortcuts
927
    // Shortcuts.
860 928
    $options = $this->handler->options;
861 929
    $view = &$this->handler->view;
862 930
    $query = &$this->handler->query;
......
887 955

  
888 956
  /**
889 957
   * Override ensure_my_table so we can control how this joins in.
958
   *
890 959
   * The operator actually has influence over joining.
891 960
   */
892
  function ensure_my_table() {
961
  public function ensure_my_table() {
893 962
    if (!isset($this->handler->table_alias)) {
894 963
      // Case 1: Operator is an 'or' and we're not reducing duplicates.
895
      // We hence get the absolute simplest:
964
      // We hence get the absolute simplest.
896 965
      $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
897 966
      if ($this->handler->operator == 'or' && empty($this->handler->options['reduce_duplicates'])) {
898 967
        if (empty($this->handler->options['add_table']) && empty($this->handler->view->many_to_one_tables[$field])) {
899
          // query optimization, INNER joins are slightly faster, so use them
968
          // Query optimization, INNER joins are slightly faster, so use them
900 969
          // when we know we can.
901 970
          $join = $this->get_join();
902 971
          if (isset($join)) {
......
930 999
      // Case 2: it's an 'and' or an 'or'.
931 1000
      // We do one join per selected value.
932 1001
      if ($this->handler->operator != 'not') {
933
        // Clone the join for each table:
1002
        // Clone the join for each table.
934 1003
        $this->handler->table_aliases = array();
935 1004
        foreach ($this->handler->value as $value) {
936 1005
          $join = $this->get_join();
......
962 1031
        }
963 1032
      }
964 1033
      // Case 3: it's a 'not'.
965
      // We just do one join. We'll add a where clause during
966
      // the query phase to ensure that $table.$field IS NULL.
1034
      // We just do one join. We'll add a where clause during the query phase
1035
      // to ensure that $table.$field IS NULL.
967 1036
      else {
968 1037
        $join = $this->get_join();
969 1038
        $join->type = 'LEFT';
......
986 1055
  /**
987 1056
   * Provides a unique placeholders for handlers.
988 1057
   */
989
  function placeholder() {
1058
  public function placeholder() {
990 1059
    return $this->handler->query->placeholder($this->handler->options['table'] . '_' . $this->handler->options['field']);
991 1060
  }
992 1061

  
993
  function add_filter() {
1062
  /**
1063
   *
1064
   */
1065
  public function add_filter() {
994 1066
    if (empty($this->handler->value)) {
995 1067
      return;
996 1068
    }
997 1069
    $this->handler->ensure_my_table();
998 1070

  
999
    // Shorten some variables:
1071
    // Shorten some variables.
1000 1072
    $field = $this->get_field();
1001 1073
    $options = $this->handler->options;
1002 1074
    $operator = $this->handler->operator;
......
1006 1078
      $options['group'] = 0;
1007 1079
    }
1008 1080

  
1009
    // add_condition determines whether a single expression is enough(FALSE) or the
1010
    // conditions should be added via an db_or()/db_and() (TRUE).
1081
    // Determine whether a single expression is enough(FALSE) or the conditions
1082
    // should be added via an db_or()/db_and() (TRUE).
1011 1083
    $add_condition = TRUE;
1012 1084
    if ($operator == 'not') {
1013 1085
      $value = NULL;
......
1051 1123
        $clause->condition("$alias.$field", $value);
1052 1124
      }
1053 1125

  
1054
      // implode on either AND or OR.
1126
      // Implode on either AND or OR.
1055 1127
      $this->handler->query->add_where($options['group'], $clause);
1056 1128
    }
1057 1129
  }
1130

  
1058 1131
}
1059 1132

  
1060 1133
/**
1061 1134
 * Break x,y,z and x+y+z into an array. Works for strings.
1062 1135
 *
1063
 * @param $str
1136
 * @param string $str
1064 1137
 *   The string to parse.
1065
 * @param $object
1066
 *   The object to use as a base. If not specified one will
1067
 *   be created.
1138
 * @param object $object
1139
 *   The object to use as a base. If not specified one will be created.
1068 1140
 *
1069
 * @return $object
1141
 * @return object
1070 1142
 *   An object containing
1071 1143
 *   - operator: Either 'and' or 'or'
1072 1144
 *   - value: An array of numeric values.
......
1076 1148
    $handler = new stdClass();
1077 1149
  }
1078 1150

  
1079
  // Set up defaults:
1151
  // Set up defaults.
1080 1152
  if (!isset($handler->value)) {
1081 1153
    $handler->value = array();
1082 1154
  }
......
1121 1193
/**
1122 1194
 * Break x,y,z and x+y+z into an array. Numeric only.
1123 1195
 *
1124
 * @param $str
1196
 * @param string $str
1125 1197
 *   The string to parse.
1126
 * @param $handler
1127
 *   The handler object to use as a base. If not specified one will
1128
 *   be created.
1198
 * @param object $handler
1199
 *   The handler object to use as a base. If not specified one will be created.
1129 1200
 *
1130 1201
 * @return $handler
1131 1202
 *   The new handler object.
......
1135 1206
    $handler = new stdClass();
1136 1207
  }
1137 1208

  
1138
  // Set up defaults:
1139

  
1209
  // Set up defaults.
1140 1210
  if (!isset($handler->value)) {
1141 1211
    $handler->value = array();
1142 1212
  }
......
1174 1244
}
1175 1245

  
1176 1246
// --------------------------------------------------------------------------
1177
// Date helper functions
1178

  
1247
// Date helper functions.
1179 1248
/**
1180 1249
 * Figure out what timezone we're in; needed for some date manipulations.
1181 1250
 */
......
1188 1257
    $timezone = variable_get('date_default_timezone', 0);
1189 1258
  }
1190 1259

  
1191
  // set up the database timezone
1260
  // Set up the database timezone.
1192 1261
  $db_type = Database::getConnection()->databaseType();
1193 1262
  if (in_array($db_type, array('mysql', 'pgsql'))) {
1194 1263
    $offset = '+00:00';
......
1201 1270
        db_query("SET @@session.time_zone = '$offset'");
1202 1271
      }
1203 1272

  
1204
      $already_set = true;
1273
      $already_set = TRUE;
1205 1274
    }
1206 1275
  }
1207 1276

  
......
1211 1280
/**
1212 1281
 * Helper function to create cross-database SQL dates.
1213 1282
 *
1214
 * @param $field
1283
 * @param string $field
1215 1284
 *   The real table and field name, like 'tablename.fieldname'.
1216
 * @param $field_type
1285
 * @param string $field_type
1217 1286
 *  The type of date field, 'int' or 'datetime'.
1218
 * @param $set_offset
1287
 * @param string $set_offset
1219 1288
 *   The name of a field that holds the timezone offset or a fixed timezone
1220 1289
 *   offset value. If not provided, the normal Drupal timezone handling
1221 1290
 *   will be used, i.e. $set_offset = 0 will make no timezone adjustment.
1222
 * @return
1291
 *
1292
 * @return string
1223 1293
 *   An appropriate SQL string for the db type and field type.
1224 1294
 */
1225 1295
function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) {
......
1237 1307
        case 'int':
1238 1308
          $field = "DATE_ADD('19700101', INTERVAL $field SECOND)";
1239 1309
          break;
1310

  
1240 1311
        case 'datetime':
1241 1312
          break;
1242 1313
      }
......
1244 1315
        $field = "($field + INTERVAL $offset_seconds SECOND)";
1245 1316
      }
1246 1317
      return $field;
1318

  
1247 1319
    case 'pgsql':
1248 1320
      switch ($field_type) {
1249 1321
        case 'int':
1250 1322
          $field = "TO_TIMESTAMP($field)";
1251 1323
          break;
1324

  
1252 1325
        case 'datetime':
1253 1326
          break;
1254 1327
      }
......
1256 1329
        $field = "($field + INTERVAL '$offset_seconds SECONDS')";
1257 1330
      }
1258 1331
      return $field;
1332

  
1259 1333
    case 'sqlite':
1260 1334
      if (!empty($offset)) {
1261 1335
        $field = "($field + '$offset_seconds')";
......
1267 1341
/**
1268 1342
 * Helper function to create cross-database SQL date formatting.
1269 1343
 *
1270
 * @param $format
1344
 * @param string $format
1271 1345
 *   A format string for the result, like 'Y-m-d H:i:s'.
1272
 * @param $field
1346
 * @param string $field
1273 1347
 *   The real table and field name, like 'tablename.fieldname'.
1274
 * @param $field_type
1348
 * @param string $field_type
1275 1349
 *   The type of date field, 'int' or 'datetime'.
1276
 * @param $set_offset
1350
 * @param string $set_offset
1277 1351
 *   The name of a field that holds the timezone offset or a fixed timezone
1278
 *   offset value. If not provided, the normal Drupal timezone handling
1279
 *   will be used, i.e. $set_offset = 0 will make no timezone adjustment.
1280
 * @return
1352
 *   offset value. If not provided, the normal Drupal timezone handling will be
1353
 *   used, i.e. $set_offset = 0 will make no timezone adjustment.
1354
 *
1355
 * @return string
1281 1356
 *   An appropriate SQL string for the db type and field type.
1282 1357
 */
1283 1358
function views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL) {
......
1302 1377
        'i' => '%i',
1303 1378
        's' => '%s',
1304 1379
        'A' => '%p',
1305
        );
1380
      );
1306 1381
      $format = strtr($format, $replace);
1307 1382
      return "DATE_FORMAT($field, '$format')";
1383

  
1308 1384
    case 'pgsql':
1309 1385
      $replace = array(
1310 1386
        'Y' => 'YYYY',
1311 1387
        'y' => 'YY',
1312 1388
        'M' => 'Mon',
1313 1389
        'm' => 'MM',
1314
        'n' => 'MM', // no format for Numeric representation of a month, without leading zeros
1390
        // No format for Numeric representation of a month, without leading
1391
        // zeros.
1392
        'n' => 'MM',
1315 1393
        'F' => 'Month',
1316 1394
        'D' => 'Dy',
1317 1395
        'd' => 'DD',
1318 1396
        'l' => 'Day',
1319
        'j' => 'DD', // no format for Day of the month without leading zeros
1397
        // No format for Day of the month without leading zeros.
1398
        'j' => 'DD',
1320 1399
        'W' => 'WW',
1321 1400
        'H' => 'HH24',
1322 1401
        'h' => 'HH12',
1323 1402
        'i' => 'MI',
1324 1403
        's' => 'SS',
1325 1404
        'A' => 'AM',
1326
        );
1405
      );
1327 1406
      $format = strtr($format, $replace);
1328 1407
      return "TO_CHAR($field, '$format')";
1408

  
1329 1409
    case 'sqlite':
1330 1410
      $replace = array(
1331
        'Y' => '%Y', // 4 digit year number
1332
        'y' => '%Y', // no format for 2 digit year number
1333
        'M' => '%m', // no format for 3 letter month name
1334
        'm' => '%m', // month number with leading zeros
1335
        'n' => '%m', // no format for month number without leading zeros
1336
        'F' => '%m', // no format for full month name
1337
        'D' => '%d', // no format for 3 letter day name
1338
        'd' => '%d', // day of month number with leading zeros
1339
        'l' => '%d', // no format for full day name
1340
        'j' => '%d', // no format for day of month number without leading zeros
1341
        'W' => '%W', // ISO week number
1342
        'H' => '%H', // 24 hour hour with leading zeros
1343
        'h' => '%H', // no format for 12 hour hour with leading zeros
1344
        'i' => '%M', // minutes with leading zeros
1345
        's' => '%S', // seconds with leading zeros
1346
        'A' => '', // no format for  AM/PM
1411
        // 4 digit year number.
1412
        'Y' => '%Y',
1413
        // No format for 2 digit year number.
1414
        'y' => '%Y',
1415
        // No format for 3 letter month name.
1416
        'M' => '%m',
1417
        // Month number with leading zeros.
1418
        'm' => '%m',
1419
        // No format for month number without leading zeros.
1420
        'n' => '%m',
1421
        // No format for full month name.
1422
        'F' => '%m',
1423
        // No format for 3 letter day name.
1424
        'D' => '%d',
1425
        // Day of month number with leading zeros.
1426
        'd' => '%d',
1427
        // No format for full day name.
1428
        'l' => '%d',
1429
        // No format for day of month number without leading zeros.
1430
        'j' => '%d',
1431
        // ISO week number.
1432
        'W' => '%W',
1433
        // 24 hour hour with leading zeros.
1434
        'H' => '%H',
1435
        // No format for 12 hour hour with leading zeros.
1436
        'h' => '%H',
1437
        // Minutes with leading zeros.
1438
        'i' => '%M',
1439
        // Seconds with leading zeros.
1440
        's' => '%S',
1441
        // No format for AM/PM.
1442
        'A' => '',
1347 1443
      );
1348 1444
      $format = strtr($format, $replace);
1349 1445
      return "strftime('$format', $field, 'unixepoch')";
......
1353 1449
/**
1354 1450
 * Helper function to create cross-database SQL date extraction.
1355 1451
 *
1356
 * @param $extract_type
1452
 * @param string $extract_type
1357 1453
 *   The type of value to extract from the date, like 'MONTH'.
1358
 * @param $field
1454
 * @param string $field
1359 1455
 *   The real table and field name, like 'tablename.fieldname'.
1360
 * @param $field_type
1456
 * @param string $field_type
1361 1457
 *   The type of date field, 'int' or 'datetime'.
1362
 * @param $set_offset
1458
 * @param string $set_offset
1363 1459
 *   The name of a field that holds the timezone offset or a fixed timezone
1364 1460
 *   offset value. If not provided, the normal Drupal timezone handling
1365 1461
 *   will be used, i.e. $set_offset = 0 will make no timezone adjustment.
1366
 * @return
1462
 *
1463
 * @return string
1367 1464
 *   An appropriate SQL string for the db type and field type.
1368 1465
 */
1369 1466
function views_date_sql_extract($extract_type, $field, $field_type = 'int', $set_offset = NULL) {
......
1371 1468
  $field = views_date_sql_field($field, $field_type, $set_offset);
1372 1469

  
1373 1470
  // Note there is no space after FROM to avoid db_rewrite problems
1374
  // see http://drupal.org/node/79904.
1471
  // @see http://drupal.org/node/79904.
1375 1472
  switch ($extract_type) {
1376
  case('DATE'):
1377
    return $field;
1378
  case('YEAR'):
1379
    return "EXTRACT(YEAR FROM($field))";
1380
  case('MONTH'):
1381
    return "EXTRACT(MONTH FROM($field))";
1382
  case('DAY'):
1383
    return "EXTRACT(DAY FROM($field))";
1384
  case('HOUR'):
1385
    return "EXTRACT(HOUR FROM($field))";
1386
  case('MINUTE'):
1387
    return "EXTRACT(MINUTE FROM($field))";
1388
  case('SECOND'):
1389
    return "EXTRACT(SECOND FROM($field))";
1390
  case('WEEK'):  // ISO week number for date
1391
    switch ($db_type) {
1392
      case('mysql'):
1393
        // WEEK using arg 3 in mysql should return the same value as postgres EXTRACT
1394
        return "WEEK($field, 3)";
1395
      case('pgsql'):
1396
        return "EXTRACT(WEEK FROM($field))";
1397
    }
1398
  case('DOW'):
1399
    switch ($db_type) {
1400
      case('mysql'):
1401
        // mysql returns 1 for Sunday through 7 for Saturday
1402
        // php date functions and postgres use 0 for Sunday and 6 for Saturday
1403
        return "INTEGER(DAYOFWEEK($field) - 1)";
1404
      case('pgsql'):
1405
        return "EXTRACT(DOW FROM($field))";
1406
    }
1407
  case('DOY'):
1408
    switch ($db_type) {
1409
      case('mysql'):
1410
        return "DAYOFYEAR($field)";
1411
      case('pgsql'):
1412
        return "EXTRACT(DOY FROM($field))";
1413
    }
1473
    case('DATE'):
1474
      return $field;
1475

  
1476
    case('YEAR'):
1477
      return "EXTRACT(YEAR FROM($field))";
1478

  
1479
    case('MONTH'):
1480
      return "EXTRACT(MONTH FROM($field))";
1481

  
1482
    case('DAY'):
1483
      return "EXTRACT(DAY FROM($field))";
1484

  
1485
    case('HOUR'):
1486
      return "EXTRACT(HOUR FROM($field))";
1487

  
1488
    case('MINUTE'):
1489
      return "EXTRACT(MINUTE FROM($field))";
1490

  
1491
    case('SECOND'):
1492
      return "EXTRACT(SECOND FROM($field))";
1493

  
1494
    case('WEEK'):
1495
      // ISO week number for date.
1496
      switch ($db_type) {
1497
        case('mysql'):
1498
          // WEEK using arg 3 in mysql should return the same value as postgres
1499
          // EXTRACT.
1500
          return "WEEK($field, 3)";
1501

  
1502
        case('pgsql'):
1503
          return "EXTRACT(WEEK FROM($field))";
1504
      }
1505
    case('DOW'):
1506
      switch ($db_type) {
1507
        // MySQL returns 1 for Sunday through 7 for Saturday.
1508
        case('mysql'):
1509
          return "INTEGER(DAYOFWEEK($field) - 1)";
1510

  
1511
        // PHP date functions and postgres use 0 for Sunday and 6 for Saturday.
1512
        case('pgsql'):
1513
          return "EXTRACT(DOW FROM($field))";
1514
      }
1515
    case('DOY'):
1516
      switch ($db_type) {
1517
        case('mysql'):
1518
          return "DAYOFYEAR($field)";
1519

  
1520
        case('pgsql'):
1521
          return "EXTRACT(DOY FROM($field))";
1522
      }
1414 1523
  }
1415 1524
}
1416 1525

  
......
1430 1539
 *   // PHP 4 doesn't call constructors of the base class automatically from a
1431 1540
 *   // constructor of a derived class. It is your responsibility to propagate
1432 1541
 *   // the call to constructors upstream where appropriate.
1433
 *   function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1542
 *   public function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1434 1543
 *     parent::construct($table, $left_table, $left_field, $field, $extra, $type);
1435 1544
 *   }
1436 1545
 *
1437
 *   function build_join($select_query, $table, $view_query) {
1546
 *   public function build_join($select_query, $table, $view_query) {
1438 1547
 *     $this->extra = 'foo.bar = baz.boing';
1439 1548
 *     parent::build_join($select_query, $table, $view_query);
1440 1549
 *   }
......
1451 1560
 *
1452 1561
 * Extensions of this class can be used to create more interesting joins.
1453 1562
 *
1454
 * join definition
1563
 * 'join' definition:
1455 1564
 *   - table: table to join (right table)
1456 1565
 *   - field: field to join on (right field)
1457 1566
 *   - left_table: The table we join to
......
1464 1573
 *       alias. If you use realtime joins, it works better.
1465 1574
 *   - - field: Field or formula
1466 1575
 *       in formulas we can reference the right table by using %alias
1467
 *       @see SelectQueryInterface::addJoin()
1468
 *   - - operator: defaults to =
1469
 *   - - value: Must be set. If an array, operator will be defaulted to IN.
1470
 *   - - numeric: If true, the value will not be surrounded in quotes.
1471
 *   - - extra type: How all the extras will be combined. Either AND or OR. Defaults to AND.
1576
 *
1577
 * @see SelectQueryInterface::addJoin()
1578
 *   - operator: Defaults to =.
1579
 *   - value: Must be set. If an array, operator will be defaulted to IN.
1580
 *   - numeric: If true, the value will not be surrounded in quotes.
1581
 *   - extra type: How all the extras will be combined. Either AND or OR.
1582
 *     Defaults to AND.
1472 1583
 */
1473 1584
class views_join {
1474
  var $table = NULL;
1475
  var $left_table = NULL;
1476
  var $left_field = NULL;
1477
  var $field = NULL;
1478
  var $extra = NULL;
1479
  var $type = NULL;
1480
  var $definition = array();
1585
  public $table = NULL;
1586
  public $left_table = NULL;
1587
  public $left_field = NULL;
1588
  public $field = NULL;
1589
  public $extra = NULL;
1590
  public $type = NULL;
1591
  public $definition = array();
1481 1592

  
1482 1593
  /**
1483 1594
   * Construct the views_join object.
1484 1595
   */
1485
  function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1596
  public function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1486 1597
    $this->extra_type = 'AND';
1487 1598
    if (!empty($table)) {
1488 1599
      $this->table = $table;
......
1493 1604
      $this->type = strtoupper($type);
1494 1605
    }
1495 1606
    elseif (!empty($this->definition)) {
1496
      // if no arguments, construct from definition.
1497
      // These four must exist or it will throw notices.
1607
      // If no arguments, construct from definition. These four must exist or
1608
      // it will throw notices.
1498 1609
      $this->table = $this->definition['table'];
1499 1610
      $this->left_table = $this->definition['left_table'];
1500 1611
      $this->left_field = $this->definition['left_field'];
......
1515 1626
   *
1516 1627
   * When possible, try to use table alias instead of table names.
1517 1628
   *
1518
   * @param $select_query
1519
   *   An implementation of SelectQueryInterface.
1520
   * @param $table
1629
   * @param SelectQueryInterface $select_query
1630
   *   An Implements SelectQueryInterface.
1631
   * @param string $table
1521 1632
   *   The base table to join.
1522
   * @param $view_query
1523
   *   The source query, implementation of views_plugin_query.
1633
   * @param views_plugin_query $view_query
1634
   *   The source query, Implements views_plugin_query.
1524 1635
   */
1525
  function build_join($select_query, $table, $view_query) {
1636
  public function build_join($select_query, $table, $view_query) {
1526 1637
    if (empty($this->definition['table formula'])) {
1527 1638
      $right_table = $this->table;
1528 1639
    }
......
1535 1646
      $left_field = "$left[alias].$this->left_field";
1536 1647
    }
1537 1648
    else {
1538
      // This can be used if left_field is a formula or something. It should be used only *very* rarely.
1649
      // This can be used if left_field is a formula or something. It should be
1650
      // used only *very* rarely.
1539 1651
      $left_field = $this->left_field;
1540 1652
    }
1541 1653

  
......
1554 1666
      foreach ($this->extra as $info) {
1555 1667
        if (is_array($info)) {
1556 1668
          $extra = '';
1557
          // Figure out the table name. Remember, only use aliases provided
1558
          // if at all possible.
1669
          // Figure out the table name. Remember, only use aliases provided if
1670
          // at all possible.
1559 1671
          $join_table = '';
1560 1672
          if (!array_key_exists('table', $info)) {
1561 1673
            $join_table = $table['alias'] . '.';
......
1572 1684
          }
1573 1685

  
1574 1686
          // Convert a single-valued array of values to the single-value case,
1575
          // and transform from IN() notation to = notation
1687
          // and transform from IN() notation to = notation.
1576 1688
          if (is_array($info['value']) && count($info['value']) == 1) {
1577 1689
            if (empty($info['operator'])) {
1578 1690
              $operator = '=';
......
1609 1721

  
1610 1722
      if ($extras) {
1611 1723
        if (count($extras) == 1) {
1612
          $condition .= ' AND ' . array_shift($extras);
1724
          $condition .= ' AND (' . array_shift($extras) . ')';
1613 1725
        }
1614 1726
        else {
1615 1727
          $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
......
1623 1735

  
1624 1736
/**
1625 1737
 * Join handler for relationships that join with a subquery as the left field.
1626
 * eg:
1738
 *
1739
 * For example:
1627 1740
 *  LEFT JOIN node node_term_data ON ([YOUR SUBQUERY HERE]) = node_term_data.nid
1628 1741
 *
1629
 * join definition
1630
 *   same as views_join class above, except:
1742
 * 'join' definition:
1743
 *   Same as views_join class above, except:
1631 1744
 *   - left_query: The subquery to use in the left side of the join clause.
1632 1745
 */
1633 1746
class views_join_subquery extends views_join {
1634
  function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1747

  
1748
  /**
1749
   * {@inheritdoc}
1750
   */
1751
  public function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
1635 1752
    parent::construct($table, $left_table, $left_field, $field, $extra, $type);
1636 1753
    $this->left_query = $this->definition['left_query'];
1637 1754
  }
......
1639 1756
  /**
1640 1757
   * Build the SQL for the join this object represents.
1641 1758
   *
1642
   * @param $select_query
1643
   *   An implementation of SelectQueryInterface.
1644
   * @param $table
1759
   * @param object $select_query
1760
   *   An Implements SelectQueryInterface.
1761
   * @param string $table
1645 1762
   *   The base table to join.
1646
   * @param $view_query
1647
   *   The source query, implementation of views_plugin_query.
1648
   * @return
1649
   *
1763
   * @param array $view_query
1764
   *   The source query, Implements views_plugin_query.
1650 1765
   */
1651
  function build_join($select_query, $table, $view_query) {
1766
  public function build_join($select_query, $table, $view_query) {
1652 1767
    if (empty($this->definition['table formula'])) {
1653 1768
      $right_table = "{" . $this->table . "}";
1654 1769
    }
......
1662 1777

  
1663 1778
    // Tack on the extra.
1664 1779
    // This is just copied verbatim from the parent class, which itself has a
1665
    // bug: http://drupal.org/node/1118100
1780
    // bug.
1781
    // @see http://drupal.org/node/1118100
1666 1782
    if (isset($this->extra)) {
1667 1783
      // If extra has been provided as string instead of an array, convert it
1668 1784
      // to an array.
......
1674 1790
      foreach ($this->extra as $info) {
1675 1791
        if (is_array($info)) {
1676 1792
          $extra = '';
1677
          // Figure out the table name. Remember, only use aliases provided
1678
          // if at all possible.
1793
          // Figure out the table name. Remember, only use aliases provided if
1794
          // at all possible.
1679 1795
          $join_table = '';
1680 1796
          if (!array_key_exists('table', $info)) {
1681 1797
            $join_table = $table['alias'] . '.';
......
1708 1824

  
1709 1825
      if ($extras) {
1710 1826
        if (count($extras) == 1) {
1711
          $condition .= ' AND ' . array_shift($extras);
1827
          $condition .= ' AND (' . array_shift($extras) . ')';
1712 1828
        }
1713 1829
        else {
1714 1830
          $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';

Formats disponibles : Unified diff