@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | /** |
68 | 68 | * Gets name |
69 | - * @return string |
|
69 | + * @return boolean |
|
70 | 70 | */ |
71 | 71 | function name() { |
72 | 72 | return $this->get( 'name' ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * Sets name |
79 | 79 | * @param string $name |
80 | - * @return boolean |
|
80 | + * @return boolean|null |
|
81 | 81 | */ |
82 | 82 | function set_name( $name ) { |
83 | 83 | $this->set( 'name', $name ); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Gets slug |
90 | - * @return string |
|
90 | + * @return boolean |
|
91 | 91 | */ |
92 | 92 | function slug() { |
93 | 93 | return $this->get( 'slug' ); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * Sets slug |
100 | 100 | * @param string $slug |
101 | - * @return boolean |
|
101 | + * @return boolean|null |
|
102 | 102 | */ |
103 | 103 | function set_slug( $slug ) { |
104 | 104 | $this->set( 'slug', $slug ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * @param bool $bydb |
35 | 35 | * @param string $timezone |
36 | 36 | */ |
37 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
38 | - if ( ! isset( $fieldValues[ 'slug' ] ) ) { |
|
39 | - $fieldValues[ 'slug' ] = $fieldValues[ 'name' ]; |
|
37 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
38 | + if ( ! isset($fieldValues['slug'])) { |
|
39 | + $fieldValues['slug'] = $fieldValues['name']; |
|
40 | 40 | } |
41 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
41 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $props_n_values |
48 | 48 | * @return EE_Term|mixed |
49 | 49 | */ |
50 | - public static function new_instance( $props_n_values = array() ) { |
|
51 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
52 | - return $has_object ? $has_object : new self( $props_n_values ); |
|
50 | + public static function new_instance($props_n_values = array()) { |
|
51 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
52 | + return $has_object ? $has_object : new self($props_n_values); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @param array $props_n_values |
59 | 59 | * @return EE_Term |
60 | 60 | */ |
61 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
62 | - return new self( $props_n_values, TRUE ); |
|
61 | + public static function new_instance_from_db($props_n_values = array()) { |
|
62 | + return new self($props_n_values, TRUE); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return string |
70 | 70 | */ |
71 | 71 | function name() { |
72 | - return $this->get( 'name' ); |
|
72 | + return $this->get('name'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @param string $name |
80 | 80 | * @return boolean |
81 | 81 | */ |
82 | - function set_name( $name ) { |
|
83 | - $this->set( 'name', $name ); |
|
82 | + function set_name($name) { |
|
83 | + $this->set('name', $name); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return string |
91 | 91 | */ |
92 | 92 | function slug() { |
93 | - return $this->get( 'slug' ); |
|
93 | + return $this->get('slug'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param string $slug |
101 | 101 | * @return boolean |
102 | 102 | */ |
103 | - function set_slug( $slug ) { |
|
104 | - $this->set( 'slug', $slug ); |
|
103 | + function set_slug($slug) { |
|
104 | + $this->set('slug', $slug); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 |
@@ -2,18 +2,18 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * Event Espresso |
|
6 | - * |
|
7 | - * Event Registration and Management Plugin for WordPress |
|
8 | - * |
|
9 | - * @ package Event Espresso |
|
10 | - * @ author Event Espresso |
|
11 | - * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | - * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | - * @ link {@link http://www.eventespresso.com} |
|
14 | - * @ since 4.0 |
|
15 | - * |
|
16 | - */ |
|
5 | + * Event Espresso |
|
6 | + * |
|
7 | + * Event Registration and Management Plugin for WordPress |
|
8 | + * |
|
9 | + * @ package Event Espresso |
|
10 | + * @ author Event Espresso |
|
11 | + * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | + * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | + * @ link {@link http://www.eventespresso.com} |
|
14 | + * @ since 4.0 |
|
15 | + * |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Gets taxonomy |
54 | - * @return string |
|
54 | + * @return boolean |
|
55 | 55 | */ |
56 | 56 | function taxonomy() { |
57 | 57 | return $this->get( 'taxonomy' ); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * Sets taxonomy |
64 | 64 | * @param string $taxonomy |
65 | - * @return boolean |
|
65 | + * @return boolean|null |
|
66 | 66 | */ |
67 | 67 | function set_taxonomy( $taxonomy ) { |
68 | 68 | $this->set( 'taxonomy', $taxonomy ); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Gets term_count |
75 | - * @return int |
|
75 | + * @return boolean |
|
76 | 76 | */ |
77 | 77 | function count() { |
78 | 78 | return $this->get( 'term_count' ); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * Sets term_count |
85 | 85 | * @param int $term_count |
86 | - * @return boolean |
|
86 | + * @return boolean|null |
|
87 | 87 | */ |
88 | 88 | function set_count( $term_count ) { |
89 | 89 | $this->set( 'term_count', $term_count ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @param array $props_n_values |
33 | 33 | * @return EE_Term_Taxonomy |
34 | 34 | */ |
35 | - public static function new_instance( $props_n_values = array() ) { |
|
36 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
37 | - return $has_object ? $has_object : new self( $props_n_values ); |
|
35 | + public static function new_instance($props_n_values = array()) { |
|
36 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
37 | + return $has_object ? $has_object : new self($props_n_values); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @param array $props_n_values |
44 | 44 | * @return EE_Term_Taxonomy |
45 | 45 | */ |
46 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
47 | - return new self( $props_n_values, TRUE ); |
|
46 | + public static function new_instance_from_db($props_n_values = array()) { |
|
47 | + return new self($props_n_values, TRUE); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return string |
55 | 55 | */ |
56 | 56 | function taxonomy() { |
57 | - return $this->get( 'taxonomy' ); |
|
57 | + return $this->get('taxonomy'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * @param string $taxonomy |
65 | 65 | * @return boolean |
66 | 66 | */ |
67 | - function set_taxonomy( $taxonomy ) { |
|
68 | - $this->set( 'taxonomy', $taxonomy ); |
|
67 | + function set_taxonomy($taxonomy) { |
|
68 | + $this->set('taxonomy', $taxonomy); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return int |
76 | 76 | */ |
77 | 77 | function count() { |
78 | - return $this->get( 'term_count' ); |
|
78 | + return $this->get('term_count'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param int $term_count |
86 | 86 | * @return boolean |
87 | 87 | */ |
88 | - function set_count( $term_count ) { |
|
89 | - $this->set( 'term_count', $term_count ); |
|
88 | + function set_count($term_count) { |
|
89 | + $this->set('term_count', $term_count); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return EE_Term |
97 | 97 | */ |
98 | 98 | function term() { |
99 | - return $this->get_first_related( 'Term' ); |
|
99 | + return $this->get_first_related('Term'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 |
@@ -2,18 +2,18 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * Event Espresso |
|
6 | - * |
|
7 | - * Event Registration and Management Plugin for WordPress |
|
8 | - * |
|
9 | - * @ package Event Espresso |
|
10 | - * @ author Event Espresso |
|
11 | - * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | - * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | - * @ link {@link http://www.eventespresso.com} |
|
14 | - * @ since 4.0 |
|
15 | - * |
|
16 | - */ |
|
5 | + * Event Espresso |
|
6 | + * |
|
7 | + * Event Registration and Management Plugin for WordPress |
|
8 | + * |
|
9 | + * @ package Event Espresso |
|
10 | + * @ author Event Espresso |
|
11 | + * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | + * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | + * @ link {@link http://www.eventespresso.com} |
|
14 | + * @ since 4.0 |
|
15 | + * |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param array $props_n_values incoming values from the database |
78 | 78 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
79 | 79 | * the website will be used. |
80 | - * @return EE_Attendee |
|
80 | + * @return EE_Ticket |
|
81 | 81 | */ |
82 | 82 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
83 | 83 | return new self( $props_n_values, TRUE, $timezone ); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Gets min |
200 | - * @return int |
|
200 | + * @return boolean |
|
201 | 201 | */ |
202 | 202 | function min() { |
203 | 203 | return $this->get( 'TKT_min' ); |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * This returns the chronologically last datetime that this ticket is associated with |
240 | 240 | * @param string $dt_frmt |
241 | 241 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
242 | - * @return array |
|
242 | + * @return string |
|
243 | 243 | */ |
244 | 244 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
245 | 245 | $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | /** |
381 | 381 | * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
382 | 382 | * @param array $query_params see EEM_Base::get_all() |
383 | - * @return EE_Datetime_Ticket |
|
383 | + * @return EE_Base_Class[] |
|
384 | 384 | */ |
385 | 385 | public function datetime_tickets( $query_params = array() ) { |
386 | 386 | return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | |
403 | 403 | /** |
404 | 404 | * Gets ID |
405 | - * @return string |
|
405 | + * @return boolean |
|
406 | 406 | */ |
407 | 407 | function ID() { |
408 | 408 | return $this->get( 'TKT_ID' ); |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * |
417 | 417 | * @since 4.5.0 |
418 | 418 | * |
419 | - * @return int |
|
419 | + * @return boolean |
|
420 | 420 | */ |
421 | 421 | public function wp_user() { |
422 | 422 | return $this->get('TKT_wp_user'); |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | /** |
515 | 515 | * Sets name |
516 | 516 | * @param string $name |
517 | - * @return boolean |
|
517 | + * @return boolean|null |
|
518 | 518 | */ |
519 | 519 | function set_name( $name ) { |
520 | 520 | $this->set( 'TKT_name', $name ); |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | |
525 | 525 | /** |
526 | 526 | * Gets description |
527 | - * @return string |
|
527 | + * @return boolean |
|
528 | 528 | */ |
529 | 529 | function description() { |
530 | 530 | return $this->get( 'TKT_description' ); |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * Sets description |
537 | 537 | * @param string $description |
538 | - * @return boolean |
|
538 | + * @return boolean|null |
|
539 | 539 | */ |
540 | 540 | function set_description( $description ) { |
541 | 541 | $this->set( 'TKT_description', $description ); |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | /** |
606 | 606 | * Sets min |
607 | 607 | * @param int $min |
608 | - * @return boolean |
|
608 | + * @return boolean|null |
|
609 | 609 | */ |
610 | 610 | function set_min( $min ) { |
611 | 611 | $this->set( 'TKT_min', $min ); |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Gets max |
618 | - * @return int |
|
618 | + * @return boolean |
|
619 | 619 | */ |
620 | 620 | function max() { |
621 | 621 | return $this->get( 'TKT_max' ); |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | /** |
627 | 627 | * Sets max |
628 | 628 | * @param int $max |
629 | - * @return boolean |
|
629 | + * @return boolean|null |
|
630 | 630 | */ |
631 | 631 | function set_max( $max ) { |
632 | 632 | $this->set( 'TKT_max', $max ); |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | /** |
638 | 638 | * Sets price |
639 | 639 | * @param float $price |
640 | - * @return boolean |
|
640 | + * @return boolean|null |
|
641 | 641 | */ |
642 | 642 | function set_price( $price ) { |
643 | 643 | $this->set( 'TKT_price', $price ); |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | |
648 | 648 | /** |
649 | 649 | * Gets sold |
650 | - * @return int |
|
650 | + * @return boolean |
|
651 | 651 | */ |
652 | 652 | function sold() { |
653 | 653 | return $this->get( 'TKT_sold' ); |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | /** |
659 | 659 | * increments sold by amount passed by $qty |
660 | 660 | * @param int $qty |
661 | - * @return boolean |
|
661 | + * @return boolean|null |
|
662 | 662 | */ |
663 | 663 | function increase_sold( $qty = 1 ) { |
664 | 664 | $sold = $this->get_raw( 'TKT_sold' ) + $qty; |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | /** |
671 | 671 | * Sets sold |
672 | 672 | * @param int $sold |
673 | - * @return boolean |
|
673 | + * @return boolean|null |
|
674 | 674 | */ |
675 | 675 | function set_sold( $sold ) { |
676 | 676 | $this->set( 'TKT_sold', $sold ); |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | /** |
682 | 682 | * decrements (subtracts) sold by amount passed by $qty |
683 | 683 | * @param int $qty |
684 | - * @return boolean |
|
684 | + * @return boolean|null |
|
685 | 685 | */ |
686 | 686 | function decrease_sold( $qty = 1 ) { |
687 | 687 | $sold = $this->get_raw( 'TKT_sold' ) - $qty; |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | |
695 | 695 | /** |
696 | 696 | * Gets qty |
697 | - * @return int |
|
697 | + * @return boolean |
|
698 | 698 | */ |
699 | 699 | function qty() { |
700 | 700 | return $this->get( 'TKT_qty' ); |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | /** |
706 | 706 | * Sets qty |
707 | 707 | * @param int $qty |
708 | - * @return boolean |
|
708 | + * @return boolean|null |
|
709 | 709 | */ |
710 | 710 | function set_qty( $qty ) { |
711 | 711 | $this->set( 'TKT_qty', $qty ); |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | |
716 | 716 | /** |
717 | 717 | * Gets uses |
718 | - * @return int |
|
718 | + * @return boolean |
|
719 | 719 | */ |
720 | 720 | function uses() { |
721 | 721 | return $this->get( 'TKT_uses' ); |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | /** |
727 | 727 | * Sets uses |
728 | 728 | * @param int $uses |
729 | - * @return boolean |
|
729 | + * @return boolean|null |
|
730 | 730 | */ |
731 | 731 | function set_uses( $uses ) { |
732 | 732 | $this->set( 'TKT_uses', $uses ); |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | /** |
748 | 748 | * sets the TKT_required property |
749 | 749 | * @param boolean $required |
750 | - * @return boolean |
|
750 | + * @return boolean|null |
|
751 | 751 | */ |
752 | 752 | public function set_required( $required ) { |
753 | 753 | $this->set( 'TKT_required', $required ); |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | /** |
769 | 769 | * Sets taxable |
770 | 770 | * @param boolean $taxable |
771 | - * @return boolean |
|
771 | + * @return boolean|null |
|
772 | 772 | */ |
773 | 773 | function set_taxable( $taxable ) { |
774 | 774 | $this->set( 'TKT_taxable', $taxable ); |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | /** |
790 | 790 | * Sets is_default |
791 | 791 | * @param boolean $is_default |
792 | - * @return boolean |
|
792 | + * @return boolean|null |
|
793 | 793 | */ |
794 | 794 | function set_is_default( $is_default ) { |
795 | 795 | $this->set( 'TKT_is_default', $is_default ); |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | |
800 | 800 | /** |
801 | 801 | * Gets order |
802 | - * @return int |
|
802 | + * @return boolean |
|
803 | 803 | */ |
804 | 804 | function order() { |
805 | 805 | return $this->get( 'TKT_order' ); |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | /** |
811 | 811 | * Sets order |
812 | 812 | * @param int $order |
813 | - * @return boolean |
|
813 | + * @return boolean|null |
|
814 | 814 | */ |
815 | 815 | function set_order( $order ) { |
816 | 816 | $this->set( 'TKT_order', $order ); |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | |
821 | 821 | /** |
822 | 822 | * Gets row |
823 | - * @return int |
|
823 | + * @return boolean |
|
824 | 824 | */ |
825 | 825 | function row() { |
826 | 826 | return $this->get( 'TKT_row' ); |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | /** |
832 | 832 | * Sets row |
833 | 833 | * @param int $row |
834 | - * @return boolean |
|
834 | + * @return boolean|null |
|
835 | 835 | */ |
836 | 836 | function set_row( $row ) { |
837 | 837 | $this->set( 'TKT_row', $row ); |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | /** |
853 | 853 | * Sets deleted |
854 | 854 | * @param boolean $deleted |
855 | - * @return boolean |
|
855 | + * @return boolean|null |
|
856 | 856 | */ |
857 | 857 | function set_deleted( $deleted ) { |
858 | 858 | $this->set( 'TKT_deleted', $deleted ); |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | |
863 | 863 | /** |
864 | 864 | * Gets parent |
865 | - * @return int |
|
865 | + * @return boolean |
|
866 | 866 | */ |
867 | 867 | function parent_ID() { |
868 | 868 | return $this->get( 'TKT_parent' ); |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | /** |
874 | 874 | * Sets parent |
875 | 875 | * @param int $parent |
876 | - * @return boolean |
|
876 | + * @return boolean|null |
|
877 | 877 | */ |
878 | 878 | function set_parent_ID( $parent ) { |
879 | 879 | $this->set( 'TKT_parent', $parent ); |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | |
898 | 898 | /** |
899 | 899 | * Gets name |
900 | - * @return string |
|
900 | + * @return boolean |
|
901 | 901 | */ |
902 | 902 | function name() { |
903 | 903 | return $this->get( 'TKT_name' ); |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | |
908 | 908 | /** |
909 | 909 | * Gets price |
910 | - * @return float |
|
910 | + * @return boolean |
|
911 | 911 | */ |
912 | 912 | function price() { |
913 | 913 | return $this->get( 'TKT_price' ); |
@@ -2,18 +2,18 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * Event Espresso |
|
6 | - * |
|
7 | - * Event Registration and Management Plugin for WordPress |
|
8 | - * |
|
9 | - * @ package Event Espresso |
|
10 | - * @ author Event Espresso |
|
11 | - * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | - * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | - * @ link {@link http://www.eventespresso.com} |
|
14 | - * @ since 4.0 |
|
15 | - * |
|
16 | - */ |
|
5 | + * Event Espresso |
|
6 | + * |
|
7 | + * Event Registration and Management Plugin for WordPress |
|
8 | + * |
|
9 | + * @ package Event Espresso |
|
10 | + * @ author Event Espresso |
|
11 | + * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | + * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | + * @ link {@link http://www.eventespresso.com} |
|
14 | + * @ since 4.0 |
|
15 | + * |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * date_format and the second value is the time format |
67 | 67 | * @return EE_Attendee |
68 | 68 | */ |
69 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
70 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
71 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
69 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
70 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
71 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * the website will be used. |
80 | 80 | * @return EE_Attendee |
81 | 81 | */ |
82 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
83 | - return new self( $props_n_values, TRUE, $timezone ); |
|
82 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
83 | + return new self($props_n_values, TRUE, $timezone); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | */ |
91 | 91 | public function parent() { |
92 | - return $this->get( 'TKT_parent' ); |
|
92 | + return $this->get('TKT_parent'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | * @param int $DTT_ID the primary key for a particular datetime |
100 | 100 | * @return boolean |
101 | 101 | */ |
102 | - public function available( $DTT_ID = 0 ) { |
|
102 | + public function available($DTT_ID = 0) { |
|
103 | 103 | // are we checking availability for a particular datetime ? |
104 | - if ( $DTT_ID ) { |
|
104 | + if ($DTT_ID) { |
|
105 | 105 | // get that datetime object |
106 | - $datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
106 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
107 | 107 | // if ticket sales for this datetime have exceeded the reg limit... |
108 | - if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) { |
|
108 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
109 | 109 | return FALSE; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | // datetime is still open for registration, but is this ticket sold out ? |
113 | - return $this->get_raw( 'TKT_qty' ) < 1 || $this->get_raw( 'TKT_qty' ) > $this->get_raw( 'TKT_sold' ) ? TRUE : FALSE; |
|
113 | + return $this->get_raw('TKT_qty') < 1 || $this->get_raw('TKT_qty') > $this->get_raw('TKT_sold') ? TRUE : FALSE; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -120,21 +120,21 @@ discard block |
||
120 | 120 | * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
121 | 121 | * @return mixed(int|string) status int if the display string isn't requested |
122 | 122 | */ |
123 | - public function ticket_status( $display = FALSE ) { |
|
124 | - if ( ! $this->is_remaining() ) { |
|
125 | - return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out; |
|
123 | + public function ticket_status($display = FALSE) { |
|
124 | + if ( ! $this->is_remaining()) { |
|
125 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out; |
|
126 | 126 | } |
127 | - if ( $this->get( 'TKT_deleted' ) ) { |
|
128 | - return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived; |
|
127 | + if ($this->get('TKT_deleted')) { |
|
128 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived; |
|
129 | 129 | } |
130 | - if ( $this->is_expired() ) { |
|
131 | - return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired; |
|
130 | + if ($this->is_expired()) { |
|
131 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired; |
|
132 | 132 | } |
133 | - if ( $this->is_pending() ) { |
|
134 | - return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending; |
|
133 | + if ($this->is_pending()) { |
|
134 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending; |
|
135 | 135 | } |
136 | - if ( $this->is_on_sale() ) { |
|
137 | - return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale; |
|
136 | + if ($this->is_on_sale()) { |
|
137 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale; |
|
138 | 138 | } |
139 | 139 | return ''; |
140 | 140 | } |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
149 | 149 | * @return boolean true = tickets remaining, false not. |
150 | 150 | */ |
151 | - public function is_remaining( $DTT_ID = 0 ) { |
|
152 | - $num_remaining = $this->remaining( $DTT_ID ); |
|
153 | - if ( $num_remaining === 0 ) { |
|
151 | + public function is_remaining($DTT_ID = 0) { |
|
152 | + $num_remaining = $this->remaining($DTT_ID); |
|
153 | + if ($num_remaining === 0) { |
|
154 | 154 | return FALSE; |
155 | 155 | } |
156 | - if ( $num_remaining > 0 && $num_remaining < $this->min() ) { |
|
156 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
157 | 157 | return FALSE; |
158 | 158 | } |
159 | 159 | return TRUE; |
@@ -167,25 +167,25 @@ discard block |
||
167 | 167 | * all related datetimes |
168 | 168 | * @return int |
169 | 169 | */ |
170 | - public function remaining( $DTT_ID = 0 ) { |
|
170 | + public function remaining($DTT_ID = 0) { |
|
171 | 171 | // are we checking availability for a particular datetime ? |
172 | - if ( $DTT_ID ) { |
|
172 | + if ($DTT_ID) { |
|
173 | 173 | // get array with the one requested datetime |
174 | - $datetimes = $this->get_many_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
174 | + $datetimes = $this->get_many_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
175 | 175 | } else { |
176 | 176 | // we need to check availability of ALL datetimes |
177 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
177 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
178 | 178 | } |
179 | 179 | // d( $datetimes ); |
180 | 180 | // if datetime reg limit is not unlimited |
181 | - if ( ! empty( $datetimes ) ) { |
|
181 | + if ( ! empty($datetimes)) { |
|
182 | 182 | // although TKT_qty and $datetime->spaces_remaining() could both be INF |
183 | 183 | //we only need to check for INF explicitly if we want to optimize. |
184 | 184 | //because INF - x = INF; and min(x,INF) = x( |
185 | - $tickets_remaining = $this->get( 'TKT_qty' ) - $this->get( 'TKT_sold' ); |
|
186 | - foreach ( $datetimes as $datetime ) { |
|
187 | - if ( $datetime instanceof EE_Datetime ) { |
|
188 | - $tickets_remaining = min( $tickets_remaining, $datetime->spaces_remaining() ); |
|
185 | + $tickets_remaining = $this->get('TKT_qty') - $this->get('TKT_sold'); |
|
186 | + foreach ($datetimes as $datetime) { |
|
187 | + if ($datetime instanceof EE_Datetime) { |
|
188 | + $tickets_remaining = min($tickets_remaining, $datetime->spaces_remaining()); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | return $tickets_remaining; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return int |
201 | 201 | */ |
202 | 202 | function min() { |
203 | - return $this->get( 'TKT_min' ); |
|
203 | + return $this->get('TKT_min'); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @return boolean |
211 | 211 | */ |
212 | 212 | public function is_expired() { |
213 | - return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
|
213 | + return ($this->get_raw('TKT_end_date') < time()); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | 222 | public function is_pending() { |
223 | - return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
|
223 | + return ($this->get_raw('TKT_start_date') > time()); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @return boolean |
231 | 231 | */ |
232 | 232 | public function is_on_sale() { |
233 | - return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
|
233 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
242 | 242 | * @return array |
243 | 243 | */ |
244 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
245 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
|
246 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
|
244 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
245 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : ''; |
|
246 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
247 | 247 | |
248 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
248 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @return EE_Datetime |
256 | 256 | */ |
257 | 257 | public function first_datetime() { |
258 | - $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
|
259 | - return reset( $datetimes ); |
|
258 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
259 | + return reset($datetimes); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | |
@@ -267,11 +267,11 @@ discard block |
||
267 | 267 | * @param array $query_params see EEM_Base::get_all() |
268 | 268 | * @return EE_Datetime[] |
269 | 269 | */ |
270 | - public function datetimes( $query_params = array() ) { |
|
271 | - if ( ! isset( $query_params[ 'order_by' ] ) ) { |
|
272 | - $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
|
270 | + public function datetimes($query_params = array()) { |
|
271 | + if ( ! isset($query_params['order_by'])) { |
|
272 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
273 | 273 | } |
274 | - return $this->get_many_related( 'Datetime', $query_params ); |
|
274 | + return $this->get_many_related('Datetime', $query_params); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @return EE_Datetime |
282 | 282 | */ |
283 | 283 | public function last_datetime() { |
284 | - $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
|
285 | - return end( $datetimes ); |
|
284 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
285 | + return end($datetimes); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -296,22 +296,22 @@ discard block |
||
296 | 296 | * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
297 | 297 | * @return mixed (array|int) how many tickets have sold |
298 | 298 | */ |
299 | - public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
|
299 | + public function tickets_sold($what = 'ticket', $dtt_id = NULL) { |
|
300 | 300 | $total = 0; |
301 | 301 | $tickets_sold = $this->_all_tickets_sold(); |
302 | - switch ( $what ) { |
|
302 | + switch ($what) { |
|
303 | 303 | case 'ticket' : |
304 | - return $tickets_sold[ 'ticket' ]; |
|
304 | + return $tickets_sold['ticket']; |
|
305 | 305 | break; |
306 | 306 | case 'datetime' : |
307 | - if ( empty( $tickets_sold[ 'datetime' ] ) ) { |
|
307 | + if (empty($tickets_sold['datetime'])) { |
|
308 | 308 | return $total; |
309 | 309 | } |
310 | - if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) { |
|
311 | - EE_Error::add_error( __( "You've requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
310 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
311 | + EE_Error::add_error(__("You've requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
312 | 312 | return $total; |
313 | 313 | } |
314 | - return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ]; |
|
314 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
315 | 315 | break; |
316 | 316 | default: |
317 | 317 | return $total; |
@@ -325,15 +325,15 @@ discard block |
||
325 | 325 | * @return EE_Ticket[] |
326 | 326 | */ |
327 | 327 | protected function _all_tickets_sold() { |
328 | - $datetimes = $this->get_many_related( 'Datetime' ); |
|
328 | + $datetimes = $this->get_many_related('Datetime'); |
|
329 | 329 | $tickets_sold = array(); |
330 | - if ( ! empty( $datetimes ) ) { |
|
331 | - foreach ( $datetimes as $datetime ) { |
|
332 | - $tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' ); |
|
330 | + if ( ! empty($datetimes)) { |
|
331 | + foreach ($datetimes as $datetime) { |
|
332 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | //Tickets sold |
336 | - $tickets_sold[ 'ticket' ] = $this->get_raw( 'TKT_sold' ); |
|
336 | + $tickets_sold['ticket'] = $this->get_raw('TKT_sold'); |
|
337 | 337 | return $tickets_sold; |
338 | 338 | } |
339 | 339 | |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * @param bool $return_array whether to return as an array indexed by price id or just the object. |
347 | 347 | * @return EE_Price |
348 | 348 | */ |
349 | - public function base_price( $return_array = FALSE ) { |
|
350 | - $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
|
351 | - return $return_array ? $this->get_many_related( 'Price', array( $_where ) ) : $this->get_first_related( 'Price', array( $_where ) ); |
|
349 | + public function base_price($return_array = FALSE) { |
|
350 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
351 | + return $return_array ? $this->get_many_related('Price', array($_where)) : $this->get_first_related('Price', array($_where)); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | * @return EE_Price[] |
361 | 361 | */ |
362 | 362 | public function price_modifiers() { |
363 | - $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
|
364 | - return $this->prices( $query_params ); |
|
363 | + $query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax)))); |
|
364 | + return $this->prices($query_params); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param array $query_params like EEM_Base::get_all |
372 | 372 | * @return EE_Price[] |
373 | 373 | */ |
374 | - public function prices( $query_params = array() ) { |
|
375 | - return $this->get_many_related( 'Price', $query_params ); |
|
374 | + public function prices($query_params = array()) { |
|
375 | + return $this->get_many_related('Price', $query_params); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param array $query_params see EEM_Base::get_all() |
383 | 383 | * @return EE_Datetime_Ticket |
384 | 384 | */ |
385 | - public function datetime_tickets( $query_params = array() ) { |
|
386 | - return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
|
385 | + public function datetime_tickets($query_params = array()) { |
|
386 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param boolean $show_deleted |
395 | 395 | * @return EE_Datetime[] |
396 | 396 | */ |
397 | - public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
|
398 | - return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
|
397 | + public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) { |
|
398 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @return string |
406 | 406 | */ |
407 | 407 | function ID() { |
408 | - return $this->get( 'TKT_ID' ); |
|
408 | + return $this->get('TKT_ID'); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | * @return EE_Ticket_Template |
430 | 430 | */ |
431 | 431 | public function template() { |
432 | - return $this->get_first_related( 'Ticket_Template' ); |
|
432 | + return $this->get_first_related('Ticket_Template'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | * @return EE_Price[] |
440 | 440 | */ |
441 | 441 | public function get_ticket_taxes_for_admin() { |
442 | - return EE_Taxes::get_taxes_for_admin( $this ); |
|
442 | + return EE_Taxes::get_taxes_for_admin($this); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @return bool |
449 | 449 | */ |
450 | 450 | public function ticket_price() { |
451 | - return $this->get( 'TKT_price' ); |
|
451 | + return $this->get('TKT_price'); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @return mixed |
458 | 458 | */ |
459 | 459 | public function pretty_price() { |
460 | - return $this->get_pretty( 'TKT_price' ); |
|
460 | + return $this->get_pretty('TKT_price'); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | |
@@ -476,17 +476,17 @@ discard block |
||
476 | 476 | * @param bool $no_cache |
477 | 477 | * @return float |
478 | 478 | */ |
479 | - public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
|
480 | - if ( ! isset( $this->_ticket_total_with_taxes ) || $no_cache ) { |
|
479 | + public function get_ticket_total_with_taxes($no_cache = FALSE) { |
|
480 | + if ( ! isset($this->_ticket_total_with_taxes) || $no_cache) { |
|
481 | 481 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
482 | 482 | } |
483 | - return (float)$this->_ticket_total_with_taxes; |
|
483 | + return (float) $this->_ticket_total_with_taxes; |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | |
487 | 487 | |
488 | 488 | public function ensure_TKT_Price_correct() { |
489 | - $this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) ); |
|
489 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
490 | 490 | $this->save(); |
491 | 491 | } |
492 | 492 | |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @return float |
497 | 497 | */ |
498 | 498 | public function get_ticket_subtotal() { |
499 | - return EE_Taxes::get_subtotal_for_admin( $this ); |
|
499 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * @return float |
507 | 507 | */ |
508 | 508 | public function get_ticket_taxes_total_for_admin() { |
509 | - return EE_Taxes::get_total_taxes_for_admin( $this ); |
|
509 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | |
@@ -516,8 +516,8 @@ discard block |
||
516 | 516 | * @param string $name |
517 | 517 | * @return boolean |
518 | 518 | */ |
519 | - function set_name( $name ) { |
|
520 | - $this->set( 'TKT_name', $name ); |
|
519 | + function set_name($name) { |
|
520 | + $this->set('TKT_name', $name); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | * @return string |
528 | 528 | */ |
529 | 529 | function description() { |
530 | - return $this->get( 'TKT_description' ); |
|
530 | + return $this->get('TKT_description'); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | |
@@ -537,8 +537,8 @@ discard block |
||
537 | 537 | * @param string $description |
538 | 538 | * @return boolean |
539 | 539 | */ |
540 | - function set_description( $description ) { |
|
541 | - $this->set( 'TKT_description', $description ); |
|
540 | + function set_description($description) { |
|
541 | + $this->set('TKT_description', $description); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @param string $tm_frmt |
550 | 550 | * @return string |
551 | 551 | */ |
552 | - function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
553 | - return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
|
552 | + function start_date($dt_frmt = '', $tm_frmt = '') { |
|
553 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | * @param string $start_date |
561 | 561 | * @return void |
562 | 562 | */ |
563 | - function set_start_date( $start_date ) { |
|
564 | - $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
|
563 | + function set_start_date($start_date) { |
|
564 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $tm_frmt |
573 | 573 | * @return string |
574 | 574 | */ |
575 | - function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
576 | - return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
|
575 | + function end_date($dt_frmt = '', $tm_frmt = '') { |
|
576 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | |
@@ -583,8 +583,8 @@ discard block |
||
583 | 583 | * @param string $end_date |
584 | 584 | * @return void |
585 | 585 | */ |
586 | - function set_end_date( $end_date ) { |
|
587 | - $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
|
586 | + function set_end_date($end_date) { |
|
587 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | |
@@ -596,8 +596,8 @@ discard block |
||
596 | 596 | * |
597 | 597 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
598 | 598 | */ |
599 | - function set_end_time( $time ) { |
|
600 | - $this->_set_time_for( $time, 'TKT_end_date' ); |
|
599 | + function set_end_time($time) { |
|
600 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | |
@@ -607,8 +607,8 @@ discard block |
||
607 | 607 | * @param int $min |
608 | 608 | * @return boolean |
609 | 609 | */ |
610 | - function set_min( $min ) { |
|
611 | - $this->set( 'TKT_min', $min ); |
|
610 | + function set_min($min) { |
|
611 | + $this->set('TKT_min', $min); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | * @return int |
619 | 619 | */ |
620 | 620 | function max() { |
621 | - return $this->get( 'TKT_max' ); |
|
621 | + return $this->get('TKT_max'); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | * @param int $max |
629 | 629 | * @return boolean |
630 | 630 | */ |
631 | - function set_max( $max ) { |
|
632 | - $this->set( 'TKT_max', $max ); |
|
631 | + function set_max($max) { |
|
632 | + $this->set('TKT_max', $max); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | |
@@ -639,8 +639,8 @@ discard block |
||
639 | 639 | * @param float $price |
640 | 640 | * @return boolean |
641 | 641 | */ |
642 | - function set_price( $price ) { |
|
643 | - $this->set( 'TKT_price', $price ); |
|
642 | + function set_price($price) { |
|
643 | + $this->set('TKT_price', $price); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @return int |
651 | 651 | */ |
652 | 652 | function sold() { |
653 | - return $this->get( 'TKT_sold' ); |
|
653 | + return $this->get('TKT_sold'); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | * @param int $qty |
661 | 661 | * @return boolean |
662 | 662 | */ |
663 | - function increase_sold( $qty = 1 ) { |
|
664 | - $sold = $this->get_raw( 'TKT_sold' ) + $qty; |
|
665 | - return $this->set_sold( $sold ); |
|
663 | + function increase_sold($qty = 1) { |
|
664 | + $sold = $this->get_raw('TKT_sold') + $qty; |
|
665 | + return $this->set_sold($sold); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | |
@@ -672,8 +672,8 @@ discard block |
||
672 | 672 | * @param int $sold |
673 | 673 | * @return boolean |
674 | 674 | */ |
675 | - function set_sold( $sold ) { |
|
676 | - $this->set( 'TKT_sold', $sold ); |
|
675 | + function set_sold($sold) { |
|
676 | + $this->set('TKT_sold', $sold); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | |
@@ -683,11 +683,11 @@ discard block |
||
683 | 683 | * @param int $qty |
684 | 684 | * @return boolean |
685 | 685 | */ |
686 | - function decrease_sold( $qty = 1 ) { |
|
687 | - $sold = $this->get_raw( 'TKT_sold' ) - $qty; |
|
686 | + function decrease_sold($qty = 1) { |
|
687 | + $sold = $this->get_raw('TKT_sold') - $qty; |
|
688 | 688 | // sold can not go below zero |
689 | - $sold = max( 0, $sold ); |
|
690 | - return $this->set_sold( $sold ); |
|
689 | + $sold = max(0, $sold); |
|
690 | + return $this->set_sold($sold); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * @return int |
698 | 698 | */ |
699 | 699 | function qty() { |
700 | - return $this->get( 'TKT_qty' ); |
|
700 | + return $this->get('TKT_qty'); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | |
@@ -707,8 +707,8 @@ discard block |
||
707 | 707 | * @param int $qty |
708 | 708 | * @return boolean |
709 | 709 | */ |
710 | - function set_qty( $qty ) { |
|
711 | - $this->set( 'TKT_qty', $qty ); |
|
710 | + function set_qty($qty) { |
|
711 | + $this->set('TKT_qty', $qty); |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | * @return int |
719 | 719 | */ |
720 | 720 | function uses() { |
721 | - return $this->get( 'TKT_uses' ); |
|
721 | + return $this->get('TKT_uses'); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | |
@@ -728,8 +728,8 @@ discard block |
||
728 | 728 | * @param int $uses |
729 | 729 | * @return boolean |
730 | 730 | */ |
731 | - function set_uses( $uses ) { |
|
732 | - $this->set( 'TKT_uses', $uses ); |
|
731 | + function set_uses($uses) { |
|
732 | + $this->set('TKT_uses', $uses); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | * @return boolean |
740 | 740 | */ |
741 | 741 | public function required() { |
742 | - return $this->get( 'TKT_required' ); |
|
742 | + return $this->get('TKT_required'); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | |
@@ -749,8 +749,8 @@ discard block |
||
749 | 749 | * @param boolean $required |
750 | 750 | * @return boolean |
751 | 751 | */ |
752 | - public function set_required( $required ) { |
|
753 | - $this->set( 'TKT_required', $required ); |
|
752 | + public function set_required($required) { |
|
753 | + $this->set('TKT_required', $required); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | * @return boolean |
761 | 761 | */ |
762 | 762 | function taxable() { |
763 | - return $this->get( 'TKT_taxable' ); |
|
763 | + return $this->get('TKT_taxable'); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | |
@@ -770,8 +770,8 @@ discard block |
||
770 | 770 | * @param boolean $taxable |
771 | 771 | * @return boolean |
772 | 772 | */ |
773 | - function set_taxable( $taxable ) { |
|
774 | - $this->set( 'TKT_taxable', $taxable ); |
|
773 | + function set_taxable($taxable) { |
|
774 | + $this->set('TKT_taxable', $taxable); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * @return boolean |
782 | 782 | */ |
783 | 783 | function is_default() { |
784 | - return $this->get( 'TKT_is_default' ); |
|
784 | + return $this->get('TKT_is_default'); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | |
@@ -791,8 +791,8 @@ discard block |
||
791 | 791 | * @param boolean $is_default |
792 | 792 | * @return boolean |
793 | 793 | */ |
794 | - function set_is_default( $is_default ) { |
|
795 | - $this->set( 'TKT_is_default', $is_default ); |
|
794 | + function set_is_default($is_default) { |
|
795 | + $this->set('TKT_is_default', $is_default); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | * @return int |
803 | 803 | */ |
804 | 804 | function order() { |
805 | - return $this->get( 'TKT_order' ); |
|
805 | + return $this->get('TKT_order'); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | |
@@ -812,8 +812,8 @@ discard block |
||
812 | 812 | * @param int $order |
813 | 813 | * @return boolean |
814 | 814 | */ |
815 | - function set_order( $order ) { |
|
816 | - $this->set( 'TKT_order', $order ); |
|
815 | + function set_order($order) { |
|
816 | + $this->set('TKT_order', $order); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | * @return int |
824 | 824 | */ |
825 | 825 | function row() { |
826 | - return $this->get( 'TKT_row' ); |
|
826 | + return $this->get('TKT_row'); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | |
@@ -833,8 +833,8 @@ discard block |
||
833 | 833 | * @param int $row |
834 | 834 | * @return boolean |
835 | 835 | */ |
836 | - function set_row( $row ) { |
|
837 | - $this->set( 'TKT_row', $row ); |
|
836 | + function set_row($row) { |
|
837 | + $this->set('TKT_row', $row); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | * @return boolean |
845 | 845 | */ |
846 | 846 | function deleted() { |
847 | - return $this->get( 'TKT_deleted' ); |
|
847 | + return $this->get('TKT_deleted'); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | |
@@ -854,8 +854,8 @@ discard block |
||
854 | 854 | * @param boolean $deleted |
855 | 855 | * @return boolean |
856 | 856 | */ |
857 | - function set_deleted( $deleted ) { |
|
858 | - $this->set( 'TKT_deleted', $deleted ); |
|
857 | + function set_deleted($deleted) { |
|
858 | + $this->set('TKT_deleted', $deleted); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return int |
866 | 866 | */ |
867 | 867 | function parent_ID() { |
868 | - return $this->get( 'TKT_parent' ); |
|
868 | + return $this->get('TKT_parent'); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | |
@@ -875,8 +875,8 @@ discard block |
||
875 | 875 | * @param int $parent |
876 | 876 | * @return boolean |
877 | 877 | */ |
878 | - function set_parent_ID( $parent ) { |
|
879 | - $this->set( 'TKT_parent', $parent ); |
|
878 | + function set_parent_ID($parent) { |
|
879 | + $this->set('TKT_parent', $parent); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | |
@@ -887,10 +887,10 @@ discard block |
||
887 | 887 | */ |
888 | 888 | function name_and_info() { |
889 | 889 | $times = array(); |
890 | - foreach ( $this->datetimes() as $datetime ) { |
|
890 | + foreach ($this->datetimes() as $datetime) { |
|
891 | 891 | $times[] = $datetime->start_date_and_time(); |
892 | 892 | } |
893 | - return $this->name() . " @ " . implode( ", ", $times ) . " for " . $this->price(); |
|
893 | + return $this->name()." @ ".implode(", ", $times)." for ".$this->price(); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * @return string |
901 | 901 | */ |
902 | 902 | function name() { |
903 | - return $this->get( 'TKT_name' ); |
|
903 | + return $this->get('TKT_name'); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * @return float |
911 | 911 | */ |
912 | 912 | function price() { |
913 | - return $this->get( 'TKT_price' ); |
|
913 | + return $this->get('TKT_price'); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | |
@@ -920,8 +920,8 @@ discard block |
||
920 | 920 | * @param array $query_params like EEM_Base::get_all's |
921 | 921 | * @return EE_Registration[] |
922 | 922 | */ |
923 | - public function registrations( $query_params = array() ) { |
|
924 | - return $this->get_many_related( 'Registration', $query_params ); |
|
923 | + public function registrations($query_params = array()) { |
|
924 | + return $this->get_many_related('Registration', $query_params); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | * @return int |
933 | 933 | */ |
934 | 934 | public function update_tickets_sold() { |
935 | - $count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) ); |
|
936 | - $this->set_sold( $count_regs_for_this_ticket ); |
|
935 | + $count_regs_for_this_ticket = $this->count_registrations(array(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0))); |
|
936 | + $this->set_sold($count_regs_for_this_ticket); |
|
937 | 937 | $this->save(); |
938 | 938 | return $count_regs_for_this_ticket; |
939 | 939 | } |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | * @param array $query_params like EEM_Base::get_all's |
946 | 946 | * @return int |
947 | 947 | */ |
948 | - public function count_registrations( $query_params = array() ) { |
|
948 | + public function count_registrations($query_params = array()) { |
|
949 | 949 | return $this->count_related('Registration', $query_params); |
950 | 950 | } |
951 | 951 | |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | public function get_related_event() { |
971 | 971 | //get one datetime to use for getting the event |
972 | 972 | $datetime = $this->first_datetime(); |
973 | - if ( $datetime instanceof EE_Datetime ) { |
|
973 | + if ($datetime instanceof EE_Datetime) { |
|
974 | 974 | return $datetime->event(); |
975 | 975 | } |
976 | 976 | return null; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param array $props_n_values incoming values from the database |
50 | 50 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
51 | 51 | * the website will be used. |
52 | - * @return EE_Attendee |
|
52 | + * @return EE_Transaction |
|
53 | 53 | */ |
54 | 54 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
55 | 55 | return new self( $props_n_values, TRUE, $timezone ); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | /** |
213 | 213 | * get Transaction Total |
214 | 214 | * @access public |
215 | - * @return float |
|
215 | + * @return boolean |
|
216 | 216 | */ |
217 | 217 | public function total() { |
218 | 218 | return $this->get( 'TXN_total' ); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | /** |
224 | 224 | * get Total Amount Paid to Date |
225 | 225 | * @access public |
226 | - * @return float |
|
226 | + * @return boolean |
|
227 | 227 | */ |
228 | 228 | public function paid() { |
229 | 229 | return $this->get( 'TXN_paid' ); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | /** |
327 | 327 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event function |
328 | 328 | * for getting attendees and how many registrations they each have for an event) |
329 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
329 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
330 | 330 | */ |
331 | 331 | public function attendees() { |
332 | 332 | return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) ); |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | /** |
572 | 572 | * Gets all the extra meta info on this payment |
573 | 573 | * @param array $query_params like EEM_Base::get_all |
574 | - * @return EE_Extra_Meta |
|
574 | + * @return EE_Base_Class[] |
|
575 | 575 | */ |
576 | 576 | public function extra_meta( $query_params = array() ) { |
577 | 577 | return $this->get_many_related( 'Extra_Meta', $query_params ); |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | |
714 | 714 | /** |
715 | 715 | * Gets PMD_ID |
716 | - * @return int |
|
716 | + * @return boolean |
|
717 | 717 | */ |
718 | 718 | function payment_method_ID() { |
719 | 719 | return $this->get('PMD_ID'); |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | /** |
725 | 725 | * Sets PMD_ID |
726 | 726 | * @param int $PMD_ID |
727 | - * @return boolean |
|
727 | + * @return boolean|null |
|
728 | 728 | */ |
729 | 729 | function set_payment_method_ID($PMD_ID) { |
730 | 730 | $this->set('PMD_ID', $PMD_ID); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @subpackage includes/classes/EE_Transaction.class.php |
27 | 27 | * @author Brent Christensen |
28 | 28 | */ |
29 | -class EE_Transaction extends EE_Base_Class implements EEI_Transaction{ |
|
29 | +class EE_Transaction extends EE_Base_Class implements EEI_Transaction { |
|
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | * date_format and the second value is the time format |
39 | 39 | * @return EE_Attendee |
40 | 40 | */ |
41 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
42 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
43 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
41 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
42 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
43 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * the website will be used. |
52 | 52 | * @return EE_Attendee |
53 | 53 | */ |
54 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
55 | - return new self( $props_n_values, TRUE, $timezone ); |
|
54 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
55 | + return new self($props_n_values, TRUE, $timezone); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @return void |
68 | 68 | */ |
69 | 69 | public function lock() { |
70 | - $locked_transactions = get_option( 'ee_locked_transactions', array() ); |
|
71 | - $locked_transactions[ $this->ID() ] = true; |
|
72 | - update_option( 'ee_locked_transactions', $locked_transactions ); |
|
70 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
71 | + $locked_transactions[$this->ID()] = true; |
|
72 | + update_option('ee_locked_transactions', $locked_transactions); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @return void |
84 | 84 | */ |
85 | 85 | public function unlock() { |
86 | - $locked_transactions = get_option( 'ee_locked_transactions', array() ); |
|
87 | - unset( $locked_transactions[ $this->ID() ] ); |
|
88 | - update_option( 'ee_locked_transactions', $locked_transactions ); |
|
86 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
87 | + unset($locked_transactions[$this->ID()]); |
|
88 | + update_option('ee_locked_transactions', $locked_transactions); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @return boolean |
103 | 103 | */ |
104 | 104 | public function is_locked() { |
105 | - $locked_transactions = get_option( 'ee_locked_transactions', array() ); |
|
106 | - return isset( $locked_transactions[ $this->ID() ] ) ? true : false; |
|
105 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
106 | + return isset($locked_transactions[$this->ID()]) ? true : false; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @access public |
115 | 115 | * @param float $total total value of transaction |
116 | 116 | */ |
117 | - public function set_total( $total = 0.00 ) { |
|
118 | - $this->set( 'TXN_total', $total ); |
|
117 | + public function set_total($total = 0.00) { |
|
118 | + $this->set('TXN_total', $total); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @access public |
127 | 127 | * @param float $total_paid total amount paid to date (sum of all payments) |
128 | 128 | */ |
129 | - public function set_paid( $total_paid = 0.00 ) { |
|
130 | - $this->set( 'TXN_paid', $total_paid ); |
|
129 | + public function set_paid($total_paid = 0.00) { |
|
130 | + $this->set('TXN_paid', $total_paid); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * @access public |
139 | 139 | * @param string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set |
140 | 140 | */ |
141 | - public function set_status( $status = '' ) { |
|
142 | - $this->set( 'STS_ID', $status ); |
|
141 | + public function set_status($status = '') { |
|
142 | + $this->set('STS_ID', $status); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | * @access public |
151 | 151 | * @param string $hash_salt required for some payment gateways |
152 | 152 | */ |
153 | - public function set_hash_salt( $hash_salt = '' ) { |
|
154 | - $this->set( 'TXN_hash_salt', $hash_salt ); |
|
153 | + public function set_hash_salt($hash_salt = '') { |
|
154 | + $this->set('TXN_hash_salt', $hash_salt); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * Sets TXN_reg_steps array |
161 | 161 | * @param array $txn_reg_steps |
162 | 162 | */ |
163 | - function set_reg_steps( $txn_reg_steps ) { |
|
164 | - $this->set( 'TXN_reg_steps', $txn_reg_steps ); |
|
163 | + function set_reg_steps($txn_reg_steps) { |
|
164 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @return array |
172 | 172 | */ |
173 | 173 | function reg_steps() { |
174 | - $TXN_reg_steps = $this->get( 'TXN_reg_steps' ); |
|
175 | - return is_array( $TXN_reg_steps ) ? $TXN_reg_steps : array(); |
|
174 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
175 | + return is_array($TXN_reg_steps) ? $TXN_reg_steps : array(); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return string of transaction's total cost, with currency symbol and decimal |
183 | 183 | */ |
184 | 184 | public function pretty_total() { |
185 | - return $this->get_pretty( 'TXN_total' ); |
|
185 | + return $this->get_pretty('TXN_total'); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public function pretty_paid() { |
195 | - return $this->get_pretty( 'TXN_paid' ); |
|
195 | + return $this->get_pretty('TXN_paid'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @return float amount remaining |
205 | 205 | */ |
206 | 206 | public function remaining() { |
207 | - return (float)( $this->total() - $this->paid() ); |
|
207 | + return (float) ($this->total() - $this->paid()); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return float |
216 | 216 | */ |
217 | 217 | public function total() { |
218 | - return $this->get( 'TXN_total' ); |
|
218 | + return $this->get('TXN_total'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return float |
227 | 227 | */ |
228 | 228 | public function paid() { |
229 | - return $this->get( 'TXN_paid' ); |
|
229 | + return $this->get('TXN_paid'); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * @access public |
237 | 237 | */ |
238 | 238 | public function get_cart_session() { |
239 | - $session_data = $this->get( 'TXN_session_data' ); |
|
240 | - return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart ? $session_data[ 'cart' ] : NULL; |
|
239 | + $session_data = $this->get('TXN_session_data'); |
|
240 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart ? $session_data['cart'] : NULL; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * @access public |
248 | 248 | */ |
249 | 249 | public function session_data() { |
250 | - $session_data = $this->get( 'TXN_session_data' ); |
|
251 | - if ( empty( $session_data ) ) { |
|
252 | - $session_data = array( 'id' => NULL, 'user_id' => NULL, 'ip_address' => NULL, 'user_agent' => NULL, 'init_access' => NULL, 'last_access' => NULL, 'pages_visited' => array() ); |
|
250 | + $session_data = $this->get('TXN_session_data'); |
|
251 | + if (empty($session_data)) { |
|
252 | + $session_data = array('id' => NULL, 'user_id' => NULL, 'ip_address' => NULL, 'user_agent' => NULL, 'init_access' => NULL, 'last_access' => NULL, 'pages_visited' => array()); |
|
253 | 253 | } |
254 | 254 | return $session_data; |
255 | 255 | } |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * @access public |
263 | 263 | * @param EE_Session|array $session_data |
264 | 264 | */ |
265 | - public function set_txn_session_data( $session_data ) { |
|
266 | - if ( $session_data instanceof EE_Session ) { |
|
267 | - $this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE )); |
|
265 | + public function set_txn_session_data($session_data) { |
|
266 | + if ($session_data instanceof EE_Session) { |
|
267 | + $this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE)); |
|
268 | 268 | } else { |
269 | - $this->set( 'TXN_session_data', $session_data ); |
|
269 | + $this->set('TXN_session_data', $session_data); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @access public |
278 | 278 | */ |
279 | 279 | public function hash_salt_() { |
280 | - return $this->get( 'TXN_hash_salt' ); |
|
280 | + return $this->get('TXN_hash_salt'); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | |
@@ -297,13 +297,13 @@ discard block |
||
297 | 297 | * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) or no UTC offset applied |
298 | 298 | * @return string | int |
299 | 299 | */ |
300 | - public function datetime( $format = FALSE, $gmt = FALSE ) { |
|
301 | - if ( $format ) { |
|
302 | - return $this->get_pretty( 'TXN_timestamp' ); |
|
303 | - } else if ( $gmt ) { |
|
304 | - return $this->get_raw( 'TXN_timestamp' ); |
|
300 | + public function datetime($format = FALSE, $gmt = FALSE) { |
|
301 | + if ($format) { |
|
302 | + return $this->get_pretty('TXN_timestamp'); |
|
303 | + } else if ($gmt) { |
|
304 | + return $this->get_raw('TXN_timestamp'); |
|
305 | 305 | } else { |
306 | - return $this->get( 'TXN_timestamp' ); |
|
306 | + return $this->get('TXN_timestamp'); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
@@ -315,10 +315,10 @@ discard block |
||
315 | 315 | * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
316 | 316 | * @return EE_Registration[] |
317 | 317 | */ |
318 | - public function registrations( $query_params = array(), $get_cached = FALSE ) { |
|
319 | - $query_params = ( empty( $query_params ) || ! is_array( $query_params ) ) ? array( 'order_by' => array( 'Event.EVT_name' => 'ASC', 'Attendee.ATT_lname' => 'ASC', 'Attendee.ATT_fname' => 'ASC' ) ) : $query_params; |
|
318 | + public function registrations($query_params = array(), $get_cached = FALSE) { |
|
319 | + $query_params = (empty($query_params) || ! is_array($query_params)) ? array('order_by' => array('Event.EVT_name' => 'ASC', 'Attendee.ATT_lname' => 'ASC', 'Attendee.ATT_fname' => 'ASC')) : $query_params; |
|
320 | 320 | $query_params = $get_cached ? array() : $query_params; |
321 | - return $this->get_many_related( 'Registration', $query_params ); |
|
321 | + return $this->get_many_related('Registration', $query_params); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
330 | 330 | */ |
331 | 331 | public function attendees() { |
332 | - return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) ); |
|
332 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param array $query_params like EEM_Base::get_all |
340 | 340 | * @return EE_Payment[] |
341 | 341 | */ |
342 | - public function payments( $query_params = array() ) { |
|
343 | - return $this->get_many_related( 'Payment', $query_params ); |
|
342 | + public function payments($query_params = array()) { |
|
343 | + return $this->get_many_related('Payment', $query_params); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | * @return EE_Payment[] |
351 | 351 | */ |
352 | 352 | public function approved_payments() { |
353 | - EE_Registry::instance()->load_model( 'Payment' ); |
|
354 | - return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) ); |
|
353 | + EE_Registry::instance()->load_model('Payment'); |
|
354 | + return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC'))); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | * @param bool $show_icons |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
365 | - echo $this->pretty_status( $show_icons ); |
|
364 | + public function e_pretty_status($show_icons = FALSE) { |
|
365 | + echo $this->pretty_status($show_icons); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | * @param bool $show_icons |
373 | 373 | * @return string |
374 | 374 | */ |
375 | - public function pretty_status( $show_icons = FALSE ) { |
|
376 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
375 | + public function pretty_status($show_icons = FALSE) { |
|
376 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
377 | 377 | $icon = ''; |
378 | - switch ( $this->status_ID() ) { |
|
378 | + switch ($this->status_ID()) { |
|
379 | 379 | case EEM_Transaction::complete_status_code: |
380 | 380 | $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
381 | 381 | break; |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
393 | 393 | break; |
394 | 394 | } |
395 | - return $icon . $status[ $this->status_ID() ]; |
|
395 | + return $icon.$status[$this->status_ID()]; |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @access public |
403 | 403 | */ |
404 | 404 | public function status_ID() { |
405 | - return $this->get( 'STS_ID' ); |
|
405 | + return $this->get('STS_ID'); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | * @return boolean |
413 | 413 | */ |
414 | 414 | public function is_free() { |
415 | - return (float)$this->get( 'TXN_total' ) == 0 ? TRUE : FALSE; |
|
415 | + return (float) $this->get('TXN_total') == 0 ? TRUE : FALSE; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | * @access public |
481 | 481 | * @return string |
482 | 482 | */ |
483 | - public function invoice_url( $type = 'html' ) { |
|
483 | + public function invoice_url($type = 'html') { |
|
484 | 484 | $REG = $this->primary_registration(); |
485 | - if ( ! $REG instanceof EE_Registration ) { |
|
485 | + if ( ! $REG instanceof EE_Registration) { |
|
486 | 486 | return ''; |
487 | 487 | } |
488 | - return $REG->invoice_url( $type ); |
|
488 | + return $REG->invoice_url($type); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @return EE_Registration |
496 | 496 | */ |
497 | 497 | public function primary_registration() { |
498 | - return $this->get_first_related( 'Registration', array( array( 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT ) ) ); |
|
498 | + return $this->get_first_related('Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | |
@@ -505,12 +505,12 @@ discard block |
||
505 | 505 | * @param string $type 'pdf' or 'html' (default is 'html') |
506 | 506 | * @return string |
507 | 507 | */ |
508 | - public function receipt_url( $type = 'html' ) { |
|
508 | + public function receipt_url($type = 'html') { |
|
509 | 509 | $REG = $this->primary_registration(); |
510 | - if ( ! $REG instanceof EE_Registration ) { |
|
510 | + if ( ! $REG instanceof EE_Registration) { |
|
511 | 511 | return ''; |
512 | 512 | } |
513 | - return $REG->receipt_url( $type ); |
|
513 | + return $REG->receipt_url($type); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | |
@@ -535,15 +535,15 @@ discard block |
||
535 | 535 | * @deprecated |
536 | 536 | * @return boolean |
537 | 537 | */ |
538 | - public function update_based_on_payments(){ |
|
538 | + public function update_based_on_payments() { |
|
539 | 539 | EE_Error::doing_it_wrong( |
540 | - __CLASS__ . '::' . __FUNCTION__, |
|
541 | - sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ), |
|
540 | + __CLASS__.'::'.__FUNCTION__, |
|
541 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
542 | 542 | '4.6.0' |
543 | 543 | ); |
544 | 544 | /** @type EE_Transaction_Processor $transaction_processor */ |
545 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
546 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $this ); |
|
545 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
546 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | * @return string |
553 | 553 | */ |
554 | 554 | public function gateway_response_on_transaction() { |
555 | - $payment = $this->get_first_related( 'Payment' ); |
|
555 | + $payment = $this->get_first_related('Payment'); |
|
556 | 556 | return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
557 | 557 | } |
558 | 558 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return EE_Status |
564 | 564 | */ |
565 | 565 | public function status_obj() { |
566 | - return $this->get_first_related( 'Status' ); |
|
566 | + return $this->get_first_related('Status'); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | |
@@ -573,8 +573,8 @@ discard block |
||
573 | 573 | * @param array $query_params like EEM_Base::get_all |
574 | 574 | * @return EE_Extra_Meta |
575 | 575 | */ |
576 | - public function extra_meta( $query_params = array() ) { |
|
577 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
576 | + public function extra_meta($query_params = array()) { |
|
577 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | |
@@ -584,8 +584,8 @@ discard block |
||
584 | 584 | * @param EE_Registration $registration |
585 | 585 | * @return EE_Base_Class the relation was added to |
586 | 586 | */ |
587 | - public function add_registration( EE_Registration $registration ) { |
|
588 | - return $this->_add_relation_to( $registration, 'Registration' ); |
|
587 | + public function add_registration(EE_Registration $registration) { |
|
588 | + return $this->_add_relation_to($registration, 'Registration'); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | |
@@ -596,8 +596,8 @@ discard block |
||
596 | 596 | * @param int $registration_or_id |
597 | 597 | * @return EE_Base_Class that was removed from being related |
598 | 598 | */ |
599 | - public function remove_registration_with_id( $registration_or_id ) { |
|
600 | - return $this->_remove_relation_to( $registration_or_id, 'Registration' ); |
|
599 | + public function remove_registration_with_id($registration_or_id) { |
|
600 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @return EE_Line_Item[] |
608 | 608 | */ |
609 | 609 | public function items_purchased() { |
610 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) ); |
|
610 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | |
@@ -617,8 +617,8 @@ discard block |
||
617 | 617 | * @param EE_Line_Item $line_item |
618 | 618 | * @return EE_Base_Class the relation was added to |
619 | 619 | */ |
620 | - public function add_line_item( EE_Line_Item $line_item ) { |
|
621 | - return $this->_add_relation_to( $line_item, 'Line_Item' ); |
|
620 | + public function add_line_item(EE_Line_Item $line_item) { |
|
621 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | * @param array $query_params |
629 | 629 | * @return EE_Line_Item[] |
630 | 630 | */ |
631 | - public function line_items( $query_params = array() ) { |
|
632 | - return $this->get_many_related( 'Line_Item', $query_params ); |
|
631 | + public function line_items($query_params = array()) { |
|
632 | + return $this->get_many_related('Line_Item', $query_params); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | * @return EE_Line_Item[] |
640 | 640 | */ |
641 | 641 | public function tax_items() { |
642 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) ); |
|
642 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | |
@@ -650,10 +650,10 @@ discard block |
||
650 | 650 | * @return EE_Line_Item |
651 | 651 | */ |
652 | 652 | public function total_line_item() { |
653 | - $item = $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) ); |
|
654 | - if( ! $item ){ |
|
655 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
656 | - $item = EEH_Line_Item::create_total_line_item( $this ); |
|
653 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
654 | + if ( ! $item) { |
|
655 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
656 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
657 | 657 | } |
658 | 658 | return $item; |
659 | 659 | } |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public function tax_total() { |
669 | 669 | $tax_line_item = $this->tax_total_line_item(); |
670 | - if ( $tax_line_item ) { |
|
670 | + if ($tax_line_item) { |
|
671 | 671 | return $tax_line_item->total(); |
672 | 672 | } else { |
673 | 673 | return 0; |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | * @return EE_Line_Item |
682 | 682 | */ |
683 | 683 | public function tax_total_line_item() { |
684 | - return $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_tax_sub_total ) ) ); |
|
684 | + return $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax_sub_total))); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -690,20 +690,20 @@ discard block |
||
690 | 690 | * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
691 | 691 | * @return EE_Form_Section_Proper |
692 | 692 | */ |
693 | - public function billing_info(){ |
|
693 | + public function billing_info() { |
|
694 | 694 | $payment_method = $this->payment_method(); |
695 | - if ( !$payment_method){ |
|
695 | + if ( ! $payment_method) { |
|
696 | 696 | EE_Error::add_error(__("Could not find billing info for transaction because no gateway has been used for it yet", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
697 | 697 | return false; |
698 | 698 | } |
699 | 699 | $primary_reg = $this->primary_registration(); |
700 | - if ( ! $primary_reg ) { |
|
701 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
700 | + if ( ! $primary_reg) { |
|
701 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
702 | 702 | return FALSE; |
703 | 703 | } |
704 | 704 | $attendee = $primary_reg->attendee(); |
705 | - if ( ! $attendee ) { |
|
706 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
705 | + if ( ! $attendee) { |
|
706 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
707 | 707 | return FALSE; |
708 | 708 | } |
709 | 709 | return $attendee->billing_info_for_payment_method($payment_method); |
@@ -738,15 +738,15 @@ discard block |
||
738 | 738 | * offline ones, dont' create payments) |
739 | 739 | * @return EE_Payment_Method |
740 | 740 | */ |
741 | - function payment_method(){ |
|
741 | + function payment_method() { |
|
742 | 742 | $pm = $this->get_first_related('Payment_Method'); |
743 | - if( $pm instanceof EE_Payment_Method ){ |
|
743 | + if ($pm instanceof EE_Payment_Method) { |
|
744 | 744 | return $pm; |
745 | - }else{ |
|
745 | + } else { |
|
746 | 746 | $last_payment = $this->last_payment(); |
747 | - if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){ |
|
747 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
748 | 748 | return $last_payment->payment_method(); |
749 | - }else{ |
|
749 | + } else { |
|
750 | 750 | return NULL; |
751 | 751 | } |
752 | 752 | } |
@@ -757,15 +757,15 @@ discard block |
||
757 | 757 | * @return EE_Payment |
758 | 758 | */ |
759 | 759 | public function last_payment() { |
760 | - return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) ); |
|
760 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | 764 | * Gets all the line items which are unrelated to tickets on this transaction |
765 | 765 | * @return EE_Line_Item[] |
766 | 766 | */ |
767 | - public function non_ticket_line_items(){ |
|
768 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() ); |
|
767 | + public function non_ticket_line_items() { |
|
768 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 |
@@ -742,11 +742,11 @@ |
||
742 | 742 | $pm = $this->get_first_related('Payment_Method'); |
743 | 743 | if( $pm instanceof EE_Payment_Method ){ |
744 | 744 | return $pm; |
745 | - }else{ |
|
745 | + } else{ |
|
746 | 746 | $last_payment = $this->last_payment(); |
747 | 747 | if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){ |
748 | 748 | return $last_payment->payment_method(); |
749 | - }else{ |
|
749 | + } else{ |
|
750 | 750 | return NULL; |
751 | 751 | } |
752 | 752 | } |
@@ -2,18 +2,18 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * Event Espresso |
|
6 | - * |
|
7 | - * Event Registration and Management Plugin for WordPress |
|
8 | - * |
|
9 | - * @ package Event Espresso |
|
10 | - * @ author Event Espresso |
|
11 | - * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | - * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | - * @ link {@link http://www.eventespresso.com} |
|
14 | - * @ since 4.0 |
|
15 | - * |
|
16 | - */ |
|
5 | + * Event Espresso |
|
6 | + * |
|
7 | + * Event Registration and Management Plugin for WordPress |
|
8 | + * |
|
9 | + * @ package Event Espresso |
|
10 | + * @ author Event Espresso |
|
11 | + * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | + * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | + * @ link {@link http://www.eventespresso.com} |
|
14 | + * @ since 4.0 |
|
15 | + * |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param array $props_n_values incoming values from the database |
49 | 49 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
50 | 50 | * the website will be used. |
51 | - * @return EE_Attendee |
|
51 | + * @return EE_Venue |
|
52 | 52 | */ |
53 | 53 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
54 | 54 | return new self( $props_n_values, TRUE, $timezone ); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Gets name |
61 | - * @return string |
|
61 | + * @return boolean |
|
62 | 62 | */ |
63 | 63 | function name() { |
64 | 64 | return $this->get( 'VNU_name' ); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Gets phone |
70 | - * @return string |
|
70 | + * @return boolean |
|
71 | 71 | */ |
72 | 72 | function phone() { |
73 | 73 | return $this->get( 'VNU_phone' ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | /** |
79 | 79 | * venue_url |
80 | - * @return string |
|
80 | + * @return boolean |
|
81 | 81 | */ |
82 | 82 | function venue_url() { |
83 | 83 | return $this->get( 'VNU_url' ); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Gets desc |
89 | - * @return string |
|
89 | + * @return boolean |
|
90 | 90 | */ |
91 | 91 | function description() { |
92 | 92 | return $this->get( 'VNU_desc' ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Gets short description (AKA: the excerpt) |
99 | - * @return string |
|
99 | + * @return boolean |
|
100 | 100 | */ |
101 | 101 | function excerpt() { |
102 | 102 | return $this->get( 'VNU_short_desc' ); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | /** |
108 | 108 | * Gets identifier |
109 | - * @return string |
|
109 | + * @return boolean |
|
110 | 110 | */ |
111 | 111 | function identifier() { |
112 | 112 | return $this->get( 'VNU_identifier' ); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | /** |
118 | 118 | * Gets address |
119 | - * @return string |
|
119 | + * @return boolean |
|
120 | 120 | */ |
121 | 121 | function address() { |
122 | 122 | return $this->get( 'VNU_address' ); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Gets address2 |
129 | - * @return string |
|
129 | + * @return boolean |
|
130 | 130 | */ |
131 | 131 | function address2() { |
132 | 132 | return $this->get( 'VNU_address2' ); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | /** |
139 | 139 | * Gets city |
140 | - * @return string |
|
140 | + * @return boolean |
|
141 | 141 | */ |
142 | 142 | function city() { |
143 | 143 | return $this->get( 'VNU_city' ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | /** |
147 | 147 | * Gets state |
148 | - * @return int |
|
148 | + * @return boolean |
|
149 | 149 | */ |
150 | 150 | function state_ID() { |
151 | 151 | return $this->get( 'STA_ID' ); |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | /** |
201 | 201 | * country_ID |
202 | - * @return string |
|
202 | + * @return boolean |
|
203 | 203 | */ |
204 | 204 | function country_ID() { |
205 | 205 | return $this->get( 'CNT_ISO' ); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Gets zip |
247 | - * @return string |
|
247 | + * @return boolean |
|
248 | 248 | */ |
249 | 249 | function zip() { |
250 | 250 | return $this->get( 'VNU_zip' ); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Gets created |
267 | - * @return string |
|
267 | + * @return boolean |
|
268 | 268 | */ |
269 | 269 | function created() { |
270 | 270 | return $this->get( 'VNU_created' ); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | /** |
276 | 276 | * Gets modified |
277 | - * @return string |
|
277 | + * @return boolean |
|
278 | 278 | */ |
279 | 279 | function modified() { |
280 | 280 | return $this->get( 'VNU_modified' ); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Gets order |
287 | - * @return int |
|
287 | + * @return boolean |
|
288 | 288 | */ |
289 | 289 | function order() { |
290 | 290 | return $this->get( 'VNU_order' ); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Gets wp_user |
297 | - * @return int |
|
297 | + * @return boolean |
|
298 | 298 | */ |
299 | 299 | function wp_user() { |
300 | 300 | return $this->get( 'VNU_wp_user' ); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | |
304 | 304 | |
305 | 305 | /** |
306 | - * @return string |
|
306 | + * @return boolean |
|
307 | 307 | */ |
308 | 308 | function virtual_phone() { |
309 | 309 | return $this->get( 'VNU_virtual_phone' ); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | |
313 | 313 | |
314 | 314 | /** |
315 | - * @return string |
|
315 | + * @return boolean |
|
316 | 316 | */ |
317 | 317 | function virtual_url() { |
318 | 318 | return $this->get( 'VNU_virtual_url' ); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | |
331 | 331 | |
332 | 332 | /** |
333 | - * @return string |
|
333 | + * @return boolean |
|
334 | 334 | */ |
335 | 335 | function google_map_link() { |
336 | 336 | return $this->get( 'VNU_google_map_link' ); |
@@ -2,18 +2,18 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * Event Espresso |
|
6 | - * |
|
7 | - * Event Registration and Management Plugin for WordPress |
|
8 | - * |
|
9 | - * @ package Event Espresso |
|
10 | - * @ author Event Espresso |
|
11 | - * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | - * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | - * @ link {@link http://www.eventespresso.com} |
|
14 | - * @ since 4.0 |
|
15 | - * |
|
16 | - */ |
|
5 | + * Event Espresso |
|
6 | + * |
|
7 | + * Event Registration and Management Plugin for WordPress |
|
8 | + * |
|
9 | + * @ package Event Espresso |
|
10 | + * @ author Event Espresso |
|
11 | + * @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
|
12 | + * @ license {@link http://eventespresso.com/support/terms-conditions/} * see Plugin Licensing * |
|
13 | + * @ link {@link http://www.eventespresso.com} |
|
14 | + * @ since 4.0 |
|
15 | + * |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * date_format and the second value is the time format |
38 | 38 | * @return EE_Attendee |
39 | 39 | */ |
40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * the website will be used. |
51 | 51 | * @return EE_Attendee |
52 | 52 | */ |
53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
54 | + return new self($props_n_values, TRUE, $timezone); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | function name() { |
64 | - return $this->get( 'VNU_name' ); |
|
64 | + return $this->get('VNU_name'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return string |
71 | 71 | */ |
72 | 72 | function phone() { |
73 | - return $this->get( 'VNU_phone' ); |
|
73 | + return $this->get('VNU_phone'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return string |
81 | 81 | */ |
82 | 82 | function venue_url() { |
83 | - return $this->get( 'VNU_url' ); |
|
83 | + return $this->get('VNU_url'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return string |
90 | 90 | */ |
91 | 91 | function description() { |
92 | - return $this->get( 'VNU_desc' ); |
|
92 | + return $this->get('VNU_desc'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return string |
100 | 100 | */ |
101 | 101 | function excerpt() { |
102 | - return $this->get( 'VNU_short_desc' ); |
|
102 | + return $this->get('VNU_short_desc'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return string |
110 | 110 | */ |
111 | 111 | function identifier() { |
112 | - return $this->get( 'VNU_identifier' ); |
|
112 | + return $this->get('VNU_identifier'); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return string |
120 | 120 | */ |
121 | 121 | function address() { |
122 | - return $this->get( 'VNU_address' ); |
|
122 | + return $this->get('VNU_address'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return string |
130 | 130 | */ |
131 | 131 | function address2() { |
132 | - return $this->get( 'VNU_address2' ); |
|
132 | + return $this->get('VNU_address2'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @return string |
141 | 141 | */ |
142 | 142 | function city() { |
143 | - return $this->get( 'VNU_city' ); |
|
143 | + return $this->get('VNU_city'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @return int |
149 | 149 | */ |
150 | 150 | function state_ID() { |
151 | - return $this->get( 'STA_ID' ); |
|
151 | + return $this->get('STA_ID'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return string |
158 | 158 | */ |
159 | 159 | public function state_abbrev() { |
160 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : __( 'Unknown', 'event_espresso' ); |
|
160 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : __('Unknown', 'event_espresso'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @return string |
167 | 167 | */ |
168 | 168 | public function state_name() { |
169 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : __( 'Unknown', 'event_espresso' ); |
|
169 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : __('Unknown', 'event_espresso'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @return EE_State |
177 | 177 | */ |
178 | 178 | function state_obj() { |
179 | - return $this->get_first_related( 'State' ); |
|
179 | + return $this->get_first_related('State'); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return string |
189 | 189 | */ |
190 | 190 | public function state() { |
191 | - if ( apply_filters( 'FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj() ) ) { |
|
191 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
192 | 192 | return $this->state_abbrev(); |
193 | 193 | } else { |
194 | 194 | return $this->state_name(); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return string |
203 | 203 | */ |
204 | 204 | function country_ID() { |
205 | - return $this->get( 'CNT_ISO' ); |
|
205 | + return $this->get('CNT_ISO'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @return string |
212 | 212 | */ |
213 | 213 | public function country_name() { |
214 | - return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : __( 'Unknown', 'event_espresso' ); |
|
214 | + return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : __('Unknown', 'event_espresso'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @return EE_Country |
222 | 222 | */ |
223 | 223 | function country_obj() { |
224 | - return $this->get_first_related( 'Country' ); |
|
224 | + return $this->get_first_related('Country'); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @return string |
234 | 234 | */ |
235 | 235 | public function country() { |
236 | - if ( apply_filters( 'FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj() ) ) { |
|
236 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
237 | 237 | return $this->country_ID(); |
238 | 238 | } else { |
239 | 239 | return $this->country_name(); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @return string |
248 | 248 | */ |
249 | 249 | function zip() { |
250 | - return $this->get( 'VNU_zip' ); |
|
250 | + return $this->get('VNU_zip'); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @return int |
258 | 258 | */ |
259 | 259 | function capacity() { |
260 | - return $this->get_pretty( 'VNU_capacity', 'symbol' ); |
|
260 | + return $this->get_pretty('VNU_capacity', 'symbol'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return string |
268 | 268 | */ |
269 | 269 | function created() { |
270 | - return $this->get( 'VNU_created' ); |
|
270 | + return $this->get('VNU_created'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @return string |
278 | 278 | */ |
279 | 279 | function modified() { |
280 | - return $this->get( 'VNU_modified' ); |
|
280 | + return $this->get('VNU_modified'); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @return int |
288 | 288 | */ |
289 | 289 | function order() { |
290 | - return $this->get( 'VNU_order' ); |
|
290 | + return $this->get('VNU_order'); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @return int |
298 | 298 | */ |
299 | 299 | function wp_user() { |
300 | - return $this->get( 'VNU_wp_user' ); |
|
300 | + return $this->get('VNU_wp_user'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @return string |
307 | 307 | */ |
308 | 308 | function virtual_phone() { |
309 | - return $this->get( 'VNU_virtual_phone' ); |
|
309 | + return $this->get('VNU_virtual_phone'); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @return string |
316 | 316 | */ |
317 | 317 | function virtual_url() { |
318 | - return $this->get( 'VNU_virtual_url' ); |
|
318 | + return $this->get('VNU_virtual_url'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @return bool |
325 | 325 | */ |
326 | 326 | function enable_for_gmap() { |
327 | - return $this->get( 'VNU_enable_for_gmap' ); |
|
327 | + return $this->get('VNU_enable_for_gmap'); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | function google_map_link() { |
336 | - return $this->get( 'VNU_google_map_link' ); |
|
336 | + return $this->get('VNU_google_map_link'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | |
@@ -345,16 +345,16 @@ discard block |
||
345 | 345 | * @param bool $upcoming |
346 | 346 | * @return EE_Event[] |
347 | 347 | */ |
348 | - function events( $query_params = array(), $upcoming = FALSE ) { |
|
349 | - if ( $upcoming ) { |
|
348 | + function events($query_params = array(), $upcoming = FALSE) { |
|
349 | + if ($upcoming) { |
|
350 | 350 | $query_params = array( |
351 | 351 | array( |
352 | 352 | 'status' => 'publish', |
353 | - 'Datetime.DTT_EVT_start' => array( '>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ) |
|
353 | + 'Datetime.DTT_EVT_start' => array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')) |
|
354 | 354 | ) |
355 | 355 | ); |
356 | 356 | } |
357 | - return $this->get_many_related( 'Event', $query_params ); |
|
357 | + return $this->get_many_related('Event', $query_params); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | /** |
373 | 373 | * Sets address |
374 | 374 | */ |
375 | - function set_address( $address = '' ) { |
|
376 | - $this->set( 'VNU_address', $address ); |
|
375 | + function set_address($address = '') { |
|
376 | + $this->set('VNU_address', $address); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | /** |
382 | 382 | * @param string $address2 |
383 | 383 | */ |
384 | - function set_address2( $address2 = '' ) { |
|
385 | - $this->set( 'VNU_address2', $address2 ); |
|
384 | + function set_address2($address2 = '') { |
|
385 | + $this->set('VNU_address2', $address2); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | /** |
391 | 391 | * @param string $city |
392 | 392 | */ |
393 | - function set_city( $city = '' ) { |
|
394 | - $this->set( 'VNU_city', $city ); |
|
393 | + function set_city($city = '') { |
|
394 | + $this->set('VNU_city', $city); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * @param int $state |
401 | 401 | */ |
402 | - function set_state_ID( $state = 0 ) { |
|
403 | - $this->set( 'STA_ID', $state ); |
|
402 | + function set_state_ID($state = 0) { |
|
403 | + $this->set('STA_ID', $state); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | |
@@ -411,8 +411,8 @@ discard block |
||
411 | 411 | * @param EE_State /int $state_id_or_obj |
412 | 412 | * @return EE_State |
413 | 413 | */ |
414 | - function set_state_obj( $state_id_or_obj ) { |
|
415 | - return $this->_add_relation_to( $state_id_or_obj, 'State' ); |
|
414 | + function set_state_obj($state_id_or_obj) { |
|
415 | + return $this->_add_relation_to($state_id_or_obj, 'State'); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | /** |
421 | 421 | * @param int $country_ID |
422 | 422 | */ |
423 | - function set_country_ID( $country_ID = 0 ) { |
|
424 | - $this->set( 'CNT_ISO', $country_ID ); |
|
423 | + function set_country_ID($country_ID = 0) { |
|
424 | + $this->set('CNT_ISO', $country_ID); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @param EE_Country /string $country_id_or_obj |
431 | 431 | * @return EE_Country |
432 | 432 | */ |
433 | - function set_country_obj( $country_id_or_obj ) { |
|
433 | + function set_country_obj($country_id_or_obj) { |
|
434 | 434 | return $this->_add_relation_to($country_id_or_obj, 'Country'); |
435 | 435 | } |
436 | 436 | |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | /** |
440 | 440 | * @param string $zip |
441 | 441 | */ |
442 | - function set_zip( $zip = '' ) { |
|
443 | - $this->set( 'VNU_zip', $zip ); |
|
442 | + function set_zip($zip = '') { |
|
443 | + $this->set('VNU_zip', $zip); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | /** |
449 | 449 | * @param int $capacity |
450 | 450 | */ |
451 | - function set_capacity( $capacity = 0 ) { |
|
452 | - $this->set( 'VNU_capacity', $capacity ); |
|
451 | + function set_capacity($capacity = 0) { |
|
452 | + $this->set('VNU_capacity', $capacity); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * @param string $created |
459 | 459 | */ |
460 | - function set_created( $created = '' ) { |
|
461 | - $this->set( 'VNU_created', $created ); |
|
460 | + function set_created($created = '') { |
|
461 | + $this->set('VNU_created', $created); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | |
@@ -466,8 +466,8 @@ discard block |
||
466 | 466 | /** |
467 | 467 | * @param string $desc |
468 | 468 | */ |
469 | - function set_description( $desc = '' ) { |
|
470 | - $this->set( 'VNU_desc', $desc ); |
|
469 | + function set_description($desc = '') { |
|
470 | + $this->set('VNU_desc', $desc); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | /** |
476 | 476 | * @param string $identifier |
477 | 477 | */ |
478 | - function set_identifier( $identifier = '' ) { |
|
479 | - $this->set( 'VNU_identifier', $identifier ); |
|
478 | + function set_identifier($identifier = '') { |
|
479 | + $this->set('VNU_identifier', $identifier); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | /** |
485 | 485 | * @param string $modified |
486 | 486 | */ |
487 | - function set_modified( $modified = '' ) { |
|
488 | - $this->set( 'VNU_modified', $modified ); |
|
487 | + function set_modified($modified = '') { |
|
488 | + $this->set('VNU_modified', $modified); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | /** |
494 | 494 | * @param string $name |
495 | 495 | */ |
496 | - function set_name( $name = '' ) { |
|
497 | - $this->set( 'VNU_name', $name ); |
|
496 | + function set_name($name = '') { |
|
497 | + $this->set('VNU_name', $name); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | /** |
503 | 503 | * @param int $order |
504 | 504 | */ |
505 | - function set_order( $order = 0 ) { |
|
506 | - $this->set( 'VNU_order', $order ); |
|
505 | + function set_order($order = 0) { |
|
506 | + $this->set('VNU_order', $order); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | |
@@ -511,8 +511,8 @@ discard block |
||
511 | 511 | /** |
512 | 512 | * @param string $phone |
513 | 513 | */ |
514 | - function set_phone( $phone = '' ) { |
|
515 | - $this->set( 'VNU_phone', $phone ); |
|
514 | + function set_phone($phone = '') { |
|
515 | + $this->set('VNU_phone', $phone); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | /** |
521 | 521 | * @param int $wp_user |
522 | 522 | */ |
523 | - function set_wp_user( $wp_user = 1 ) { |
|
524 | - $this->set( 'VNU_wp_user', $wp_user ); |
|
523 | + function set_wp_user($wp_user = 1) { |
|
524 | + $this->set('VNU_wp_user', $wp_user); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | /** |
530 | 530 | * @param string $url |
531 | 531 | */ |
532 | - function set_venue_url( $url = '' ) { |
|
533 | - $this->set( 'VNU_url', $url ); |
|
532 | + function set_venue_url($url = '') { |
|
533 | + $this->set('VNU_url', $url); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * @param string $phone |
540 | 540 | */ |
541 | - function set_virtual_phone( $phone = '' ) { |
|
542 | - $this->set( 'VNU_virtual_phone', $phone ); |
|
541 | + function set_virtual_phone($phone = '') { |
|
542 | + $this->set('VNU_virtual_phone', $phone); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -547,8 +547,8 @@ discard block |
||
547 | 547 | /** |
548 | 548 | * @param string $url |
549 | 549 | */ |
550 | - function set_virtual_url( $url = '' ) { |
|
551 | - $this->set( 'VNU_virtual_url', $url ); |
|
550 | + function set_virtual_url($url = '') { |
|
551 | + $this->set('VNU_virtual_url', $url); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * @param string $enable |
558 | 558 | */ |
559 | - function set_enable_for_gmap( $enable = '' ) { |
|
560 | - $this->set( 'VNU_enable_for_gmap', $enable ); |
|
559 | + function set_enable_for_gmap($enable = '') { |
|
560 | + $this->set('VNU_enable_for_gmap', $enable); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | /** |
566 | 566 | * @param string $google_map_link |
567 | 567 | */ |
568 | - function set_google_map_link( $google_map_link = '' ) { |
|
569 | - $this->set( 'VNU_google_map_link', $google_map_link ); |
|
568 | + function set_google_map_link($google_map_link = '') { |
|
569 | + $this->set('VNU_google_map_link', $google_map_link); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | * Returns the name of the field's name that points to the WP_User table |
719 | 719 | * on this model (or follows the _model_chain_to_wp_user and uses that model's |
720 | 720 | * foreign key to the WP_User table) |
721 | - * @return string|boolean string on success, boolean false when there is no |
|
721 | + * @return string|false string on success, boolean false when there is no |
|
722 | 722 | * foreign key to the WP_User table |
723 | 723 | */ |
724 | 724 | function wp_user_field_name() { |
@@ -814,6 +814,7 @@ discard block |
||
814 | 814 | * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array. |
815 | 815 | * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection |
816 | 816 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
817 | + * @param string $columns_to_select |
|
817 | 818 | * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
818 | 819 | */ |
819 | 820 | public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
@@ -1116,7 +1117,7 @@ discard block |
||
1116 | 1117 | * @param bool $pretty Whether to return the pretty formats (true) or not (false). |
1117 | 1118 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1118 | 1119 | * |
1119 | - * @return array formats in an array with the date format first, and the time format last. |
|
1120 | + * @return string[] formats in an array with the date format first, and the time format last. |
|
1120 | 1121 | */ |
1121 | 1122 | public function get_formats_for( $field_name, $pretty = false ) { |
1122 | 1123 | $field_settings = $this->field_settings_for( $field_name ); |
@@ -1451,7 +1452,7 @@ discard block |
||
1451 | 1452 | * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value). |
1452 | 1453 | * Wrapper for EEM_Base::delete() |
1453 | 1454 | * @param mixed $id |
1454 | - * @return boolean whether the row got deleted or not |
|
1455 | + * @return integer whether the row got deleted or not |
|
1455 | 1456 | */ |
1456 | 1457 | public function delete_by_ID( $id ){ |
1457 | 1458 | return $this->delete( array( |
@@ -1785,7 +1786,6 @@ discard block |
||
1785 | 1786 | * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one. |
1786 | 1787 | * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table |
1787 | 1788 | * |
1788 | - * @param EE_Base_Class/int $thisModelObject |
|
1789 | 1789 | * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object |
1790 | 1790 | * @param string $relationName, key in EEM_Base::_relations |
1791 | 1791 | * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
@@ -1807,8 +1807,8 @@ discard block |
||
1807 | 1807 | * |
1808 | 1808 | * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models. |
1809 | 1809 | * |
1810 | - * @param EE_Base_Class/int $id_or_obj |
|
1811 | - * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1810 | + * @param EE_CPT_Base $id_or_obj |
|
1811 | + * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1812 | 1812 | * @param string $relationName key in EEM_Base::_relations |
1813 | 1813 | * @return boolean of success |
1814 | 1814 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
@@ -1884,7 +1884,7 @@ discard block |
||
1884 | 1884 | /** |
1885 | 1885 | * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
1886 | 1886 | * unless otherwise specified in the $query_params |
1887 | - * @param int/EE_Base_Class $id_or_obj |
|
1887 | + * @param EE_Event $id_or_obj |
|
1888 | 1888 | * @param string $model_name like 'Event', or 'Registration' |
1889 | 1889 | * @param array $query_params like EEM_Base::get_all's |
1890 | 1890 | * @param string $field_to_count name of field to count by. By default, uses primary key |
@@ -2273,7 +2273,7 @@ discard block |
||
2273 | 2273 | /** |
2274 | 2274 | * Finds all the fields that correspond to the given table |
2275 | 2275 | * @param string $table_alias, array key in EEM_Base::_tables |
2276 | - * @return EE_Model_Field_Base[] |
|
2276 | + * @return EE_Model_Field_Base |
|
2277 | 2277 | */ |
2278 | 2278 | function _get_fields_for_table($table_alias){ |
2279 | 2279 | return $this->_fields[$table_alias]; |
@@ -3337,8 +3337,8 @@ discard block |
||
3337 | 3337 | /** |
3338 | 3338 | * gets the field object of type 'primary_key' from the fieldsSettings attribute. |
3339 | 3339 | * Eg, on EE_Answer that would be ANS_ID field object |
3340 | - * @param $field_obj |
|
3341 | - * @return EE_Model_Field_Base |
|
3340 | + * @param EE_Model_Field_Base $field_obj |
|
3341 | + * @return boolean |
|
3342 | 3342 | */ |
3343 | 3343 | public function is_primary_key_field( $field_obj ){ |
3344 | 3344 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
@@ -3432,7 +3432,7 @@ discard block |
||
3432 | 3432 | * Gets the actual table for the table alias |
3433 | 3433 | * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe |
3434 | 3434 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3435 | - * @return EE_Table_Base |
|
3435 | + * @return string |
|
3436 | 3436 | */ |
3437 | 3437 | function get_table_for_alias($table_alias){ |
3438 | 3438 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
@@ -3532,7 +3532,7 @@ discard block |
||
3532 | 3532 | * The purpose of this method is to allow us to create a model object that is not in the db that holds default values. |
3533 | 3533 | * A typical example of where this is used is when creating a new item and the initial load of a form. We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!). |
3534 | 3534 | * |
3535 | - * @return EE_Base_Class single EE_Base_Class object with default values for the properties. |
|
3535 | + * @return boolean single EE_Base_Class object with default values for the properties. |
|
3536 | 3536 | */ |
3537 | 3537 | public function create_default_object() { |
3538 | 3538 | |
@@ -3687,6 +3687,9 @@ discard block |
||
3687 | 3687 | return $this_model_fields_n_values; |
3688 | 3688 | } |
3689 | 3689 | |
3690 | + /** |
|
3691 | + * @param string $cols_n_values |
|
3692 | + */ |
|
3690 | 3693 | protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
3691 | 3694 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
3692 | 3695 | //does the field on the model relate to this column retrieved from the db? |
@@ -3922,7 +3925,7 @@ discard block |
||
3922 | 3925 | } |
3923 | 3926 | /** |
3924 | 3927 | * Read comments for assume_values_already_prepared_by_model_object() |
3925 | - * @return int |
|
3928 | + * @return boolean |
|
3926 | 3929 | */ |
3927 | 3930 | public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
3928 | 3931 | return $this->_values_already_prepared_by_model_object; |
@@ -555,10 +555,10 @@ |
||
555 | 555 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
556 | 556 | $status_array = array(); |
557 | 557 | foreach ( $stati as $status ) { |
558 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
559 | - } |
|
560 | - return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
561 | - } |
|
558 | + $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
559 | + } |
|
560 | + return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
561 | + } |
|
562 | 562 | |
563 | 563 | |
564 | 564 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * Flag indicating whether this model has a primary key or not |
229 | 229 | * @var boolean |
230 | 230 | */ |
231 | - protected $_has_primary_key_field=null; |
|
231 | + protected $_has_primary_key_field = null; |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -283,19 +283,19 @@ discard block |
||
283 | 283 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
284 | 284 | * @var array |
285 | 285 | */ |
286 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
286 | + protected $_between_style_operators = array('BETWEEN'); |
|
287 | 287 | |
288 | 288 | /** |
289 | 289 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
290 | 290 | * @var array |
291 | 291 | */ |
292 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
292 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
293 | 293 | |
294 | 294 | /** |
295 | 295 | * Allowed values for $query_params['order'] for ordering in queries |
296 | 296 | * @var array |
297 | 297 | */ |
298 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
298 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
299 | 299 | |
300 | 300 | /** |
301 | 301 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
310 | 310 | * @var array |
311 | 311 | */ |
312 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
312 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * All the data types that can be used in $wpdb->prepare statements. |
316 | 316 | * @var array |
317 | 317 | */ |
318 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
318 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * EE_Registry Object |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | * @param null $timezone |
367 | 367 | * @throws \EE_Error |
368 | 368 | */ |
369 | - protected function __construct( $timezone = NULL ){ |
|
369 | + protected function __construct($timezone = NULL) { |
|
370 | 370 | // check that the model has not been loaded too soon |
371 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
372 | - throw new EE_Error ( |
|
371 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
372 | + throw new EE_Error( |
|
373 | 373 | sprintf( |
374 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
375 | - get_class( $this ) |
|
374 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
375 | + get_class($this) |
|
376 | 376 | ) |
377 | 377 | ); |
378 | 378 | } |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | * just use EE_Register_Model_Extension |
383 | 383 | * @var EE_Table_Base[] $_tables |
384 | 384 | */ |
385 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
386 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
385 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
386 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
387 | 387 | /** @var $table_obj EE_Table_Base */ |
388 | 388 | $table_obj->_construct_finalize_with_alias($table_alias); |
389 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
389 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
390 | 390 | /** @var $table_obj EE_Secondary_Table */ |
391 | 391 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
392 | 392 | } |
@@ -396,48 +396,48 @@ discard block |
||
396 | 396 | * EE_Register_Model_Extension |
397 | 397 | * @param EE_Model_Field_Base[] $_fields |
398 | 398 | */ |
399 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
400 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
401 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
402 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
399 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
400 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
401 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
402 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
403 | 403 | } |
404 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
404 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
405 | 405 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
406 | 406 | //primary key field base has a slightly different _construct_finalize |
407 | 407 | /** @var $field_obj EE_Model_Field_Base */ |
408 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
408 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | 412 | // everything is related to Extra_Meta |
413 | - if( get_class($this) != 'EEM_Extra_Meta'){ |
|
413 | + if (get_class($this) != 'EEM_Extra_Meta') { |
|
414 | 414 | //make extra meta related to everything, but don't block deleting things just |
415 | 415 | //because they have related extra meta info. For now just orphan those extra meta |
416 | 416 | //in the future we should automatically delete them |
417 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
417 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
418 | 418 | } |
419 | 419 | //and change logs |
420 | - if( get_class( $this) != 'EEM_Change_Log' ) { |
|
421 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
420 | + if (get_class($this) != 'EEM_Change_Log') { |
|
421 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
422 | 422 | } |
423 | 423 | /** |
424 | 424 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
425 | 425 | * EE_Register_Model_Extension |
426 | 426 | * @param EE_Model_Relation_Base[] $_model_relations |
427 | 427 | */ |
428 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
429 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
428 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
429 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
430 | 430 | /** @var $relation_obj EE_Model_Relation_Base */ |
431 | 431 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
432 | 432 | } |
433 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
433 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
434 | 434 | /** @var $index_obj EE_Index */ |
435 | 435 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
436 | 436 | } |
437 | 437 | |
438 | 438 | $this->set_timezone($timezone); |
439 | 439 | //finalize default where condition strategy, or set default |
440 | - if( ! $this->_default_where_conditions_strategy){ |
|
440 | + if ( ! $this->_default_where_conditions_strategy) { |
|
441 | 441 | //nothing was set during child constructor, so set default |
442 | 442 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
443 | 443 | } |
@@ -445,15 +445,15 @@ discard block |
||
445 | 445 | |
446 | 446 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
447 | 447 | //to indicate to NOT set it, set it to the logical default |
448 | - if( $this->_caps_slug === null ) { |
|
449 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
450 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
448 | + if ($this->_caps_slug === null) { |
|
449 | + EE_Registry::instance()->load_helper('Inflector'); |
|
450 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
451 | 451 | } |
452 | 452 | //initialize the standard cap restriction generators if none were specified by the child constructor |
453 | - if( $this->_cap_restriction_generators !== false ){ |
|
454 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
455 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
456 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
453 | + if ($this->_cap_restriction_generators !== false) { |
|
454 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
455 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
456 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
457 | 457 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
458 | 458 | new EE_Restriction_Generator_Protected(), |
459 | 459 | $cap_context, |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | //if there are cap restriction generators, use them to make the default cap restrictions |
466 | - if( $this->_cap_restriction_generators !== false ){ |
|
467 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
468 | - if( ! $generator_object ){ |
|
466 | + if ($this->_cap_restriction_generators !== false) { |
|
467 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
468 | + if ( ! $generator_object) { |
|
469 | 469 | continue; |
470 | 470 | } |
471 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
471 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
472 | 472 | throw new EE_Error( |
473 | 473 | sprintf( |
474 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
474 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
475 | 475 | $context, |
476 | 476 | $this->get_this_model_name() |
477 | 477 | ) |
478 | 478 | ); |
479 | 479 | } |
480 | - $action = $this->cap_action_for_context( $context ); |
|
481 | - if( ! $generator_object->construction_finalized() ){ |
|
482 | - $generator_object->_construct_finalize( $this, $action ); |
|
480 | + $action = $this->cap_action_for_context($context); |
|
481 | + if ( ! $generator_object->construction_finalized()) { |
|
482 | + $generator_object->_construct_finalize($this, $action); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | } |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | * @param string $context one of EEM_Base::valid_cap_contexts() |
494 | 494 | * @return EE_Default_Where_Conditions[] |
495 | 495 | */ |
496 | - protected function _generate_cap_restrictions( $context ){ |
|
497 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
498 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
499 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
500 | - }else{ |
|
496 | + protected function _generate_cap_restrictions($context) { |
|
497 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
498 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
499 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
500 | + } else { |
|
501 | 501 | return array(); |
502 | 502 | } |
503 | 503 | } |
@@ -510,16 +510,16 @@ discard block |
||
510 | 510 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
511 | 511 | * @return static (as in the concrete child class) |
512 | 512 | */ |
513 | - public static function instance( $timezone = NULL ){ |
|
513 | + public static function instance($timezone = NULL) { |
|
514 | 514 | |
515 | 515 | // check if instance of Espresso_model already exists |
516 | 516 | if ( ! static::$_instance instanceof static) { |
517 | 517 | // instantiate Espresso_model |
518 | - static::$_instance = new static( $timezone ); |
|
518 | + static::$_instance = new static($timezone); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | //we might have a timezone set, let set_timezone decide what to do with it |
522 | - static::$_instance->set_timezone( $timezone ); |
|
522 | + static::$_instance->set_timezone($timezone); |
|
523 | 523 | |
524 | 524 | // Espresso_model object |
525 | 525 | return static::$_instance; |
@@ -532,11 +532,11 @@ discard block |
||
532 | 532 | * @param null | string $timezone |
533 | 533 | * @return static |
534 | 534 | */ |
535 | - public static function reset( $timezone = NULL ){ |
|
536 | - if ( ! is_null( static::$_instance ) ) { |
|
535 | + public static function reset($timezone = NULL) { |
|
536 | + if ( ! is_null(static::$_instance)) { |
|
537 | 537 | static::$_instance = null; |
538 | 538 | |
539 | - return self::instance( $timezone ); |
|
539 | + return self::instance($timezone); |
|
540 | 540 | } |
541 | 541 | return null; |
542 | 542 | } |
@@ -547,15 +547,15 @@ discard block |
||
547 | 547 | * @param boolean $translated return localized strings or JUST the array. |
548 | 548 | * @return array |
549 | 549 | */ |
550 | - public function status_array( $translated = FALSE ) { |
|
551 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
550 | + public function status_array($translated = FALSE) { |
|
551 | + if ( ! array_key_exists('Status', $this->_model_relations)) |
|
552 | 552 | return array(); |
553 | 553 | $model_name = $this->get_this_model_name(); |
554 | - $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
|
555 | - $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
|
554 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
555 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
556 | 556 | $status_array = array(); |
557 | - foreach ( $stati as $status ) { |
|
558 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
557 | + foreach ($stati as $status) { |
|
558 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
559 | 559 | } |
560 | 560 | return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
561 | 561 | } |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | * 'order_by'=>array('ANS_value'=>'ASC') |
697 | 697 | * )); |
698 | 698 | */ |
699 | - function get_all($query_params = array()){ |
|
699 | + function get_all($query_params = array()) { |
|
700 | 700 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
701 | 701 | } |
702 | 702 | |
@@ -706,10 +706,10 @@ discard block |
||
706 | 706 | * @param array $query_params @see EEM_Base::get_all() |
707 | 707 | * @return array like EEM_Base::get_all |
708 | 708 | */ |
709 | - function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
709 | + function alter_query_params_to_only_include_mine($query_params = array()) { |
|
710 | 710 | $wp_user_field_name = $this->wp_user_field_name(); |
711 | - if( $wp_user_field_name ){ |
|
712 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
711 | + if ($wp_user_field_name) { |
|
712 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
713 | 713 | } |
714 | 714 | return $query_params; |
715 | 715 | } |
@@ -722,19 +722,19 @@ discard block |
||
722 | 722 | * foreign key to the WP_User table |
723 | 723 | */ |
724 | 724 | function wp_user_field_name() { |
725 | - try{ |
|
726 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
727 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
728 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
729 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
730 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
731 | - }else{ |
|
725 | + try { |
|
726 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
727 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
728 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
729 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
730 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
731 | + } else { |
|
732 | 732 | $model_with_fk_to_wp_users = $this; |
733 | 733 | $model_chain_to_wp_user = ''; |
734 | 734 | } |
735 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
736 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
737 | - }catch( EE_Error $e ) { |
|
735 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
736 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
737 | + } catch (EE_Error $e) { |
|
738 | 738 | return false; |
739 | 739 | } |
740 | 740 | } |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | * (or transietly-related model) |
749 | 749 | * @return string |
750 | 750 | */ |
751 | - public function model_chain_to_wp_user(){ |
|
751 | + public function model_chain_to_wp_user() { |
|
752 | 752 | return $this->_model_chain_to_wp_user; |
753 | 753 | } |
754 | 754 | |
@@ -760,13 +760,13 @@ discard block |
||
760 | 760 | * @return boolean |
761 | 761 | */ |
762 | 762 | public function is_owned() { |
763 | - if( $this->model_chain_to_wp_user() ){ |
|
763 | + if ($this->model_chain_to_wp_user()) { |
|
764 | 764 | return true; |
765 | - }else{ |
|
766 | - try{ |
|
767 | - $this->get_foreign_key_to( 'WP_User' ); |
|
765 | + } else { |
|
766 | + try { |
|
767 | + $this->get_foreign_key_to('WP_User'); |
|
768 | 768 | return true; |
769 | - }catch( EE_Error $e ){ |
|
769 | + } catch (EE_Error $e) { |
|
770 | 770 | return false; |
771 | 771 | } |
772 | 772 | } |
@@ -785,21 +785,21 @@ discard block |
||
785 | 785 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
786 | 786 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
787 | 787 | */ |
788 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
788 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
789 | 789 | //remember the custom selections, if any |
790 | - if(is_array($columns_to_select)){ |
|
790 | + if (is_array($columns_to_select)) { |
|
791 | 791 | $this->_custom_selections = $columns_to_select; |
792 | - }elseif(is_string($columns_to_select)){ |
|
792 | + }elseif (is_string($columns_to_select)) { |
|
793 | 793 | $this->_custom_selections = array($this->_custom_selections); |
794 | - }else{ |
|
794 | + } else { |
|
795 | 795 | $this->_custom_selections = array(); |
796 | 796 | } |
797 | 797 | |
798 | 798 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
799 | 799 | $select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info); |
800 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
800 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
801 | 801 | // echo "sql:$SQL"; |
802 | - $results = $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output); |
|
802 | + $results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output); |
|
803 | 803 | return $results; |
804 | 804 | } |
805 | 805 | |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
817 | 817 | * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
818 | 818 | */ |
819 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
819 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
820 | 820 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
821 | 821 | } |
822 | 822 | |
@@ -828,21 +828,21 @@ discard block |
||
828 | 828 | * @throws EE_Error |
829 | 829 | * @return string |
830 | 830 | */ |
831 | - private function _construct_select_from_input($columns_to_select){ |
|
832 | - if(is_array($columns_to_select)){ |
|
831 | + private function _construct_select_from_input($columns_to_select) { |
|
832 | + if (is_array($columns_to_select)) { |
|
833 | 833 | $select_sql_array = array(); |
834 | 834 | |
835 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
836 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
837 | - throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"),$selection_and_datatype,$alias)); |
|
835 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
836 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
837 | + throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"), $selection_and_datatype, $alias)); |
|
838 | 838 | } |
839 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
840 | - throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"),$selection_and_datatype[1],$selection_and_datatype[0],$alias,implode(",",$this->_valid_wpdb_data_types))); |
|
839 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
840 | + throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"), $selection_and_datatype[1], $selection_and_datatype[0], $alias, implode(",", $this->_valid_wpdb_data_types))); |
|
841 | 841 | } |
842 | 842 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
843 | 843 | } |
844 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
845 | - }else{ |
|
844 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
845 | + } else { |
|
846 | 846 | $columns_to_select_string = $columns_to_select; |
847 | 847 | } |
848 | 848 | return $columns_to_select_string; |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID' |
856 | 856 | * @return string |
857 | 857 | */ |
858 | - function primary_key_name(){ |
|
858 | + function primary_key_name() { |
|
859 | 859 | return $this->get_primary_key_field()->get_name(); |
860 | 860 | } |
861 | 861 | |
@@ -867,15 +867,15 @@ discard block |
||
867 | 867 | * @param mixed $id int or string, depending on the type of the model's primary key |
868 | 868 | * @return EE_Base_Class |
869 | 869 | */ |
870 | - function get_one_by_ID($id){ |
|
871 | - if( $this->get_from_entity_map( $id ) ){ |
|
872 | - return $this->get_from_entity_map( $id ); |
|
873 | - }elseif( $this->has_primary_key_field ( ) ) { |
|
870 | + function get_one_by_ID($id) { |
|
871 | + if ($this->get_from_entity_map($id)) { |
|
872 | + return $this->get_from_entity_map($id); |
|
873 | + }elseif ($this->has_primary_key_field( )) { |
|
874 | 874 | $primary_key_name = $this->get_primary_key_field()->get_name(); |
875 | 875 | return $this->get_one(array(array($primary_key_name => $id))); |
876 | - }else{ |
|
876 | + } else { |
|
877 | 877 | //no primary key, so the $id must be from the get_index_primary_key_string() |
878 | - return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) ); |
|
878 | + return $this->get_one(array($this->parse_index_primary_key_string($id))); |
|
879 | 879 | } |
880 | 880 | } |
881 | 881 | |
@@ -886,16 +886,16 @@ discard block |
||
886 | 886 | * @param array $query_params like EEM_Base's $query_params variable. |
887 | 887 | * @return EE_Base_Class | NULL |
888 | 888 | */ |
889 | - function get_one($query_params = array()){ |
|
890 | - if( ! is_array( $query_params ) ){ |
|
891 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
889 | + function get_one($query_params = array()) { |
|
890 | + if ( ! is_array($query_params)) { |
|
891 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
892 | 892 | $query_params = array(); |
893 | 893 | } |
894 | 894 | $query_params['limit'] = 1; |
895 | 895 | $items = $this->get_all($query_params); |
896 | - if(empty($items)){ |
|
896 | + if (empty($items)) { |
|
897 | 897 | return null; |
898 | - }else{ |
|
898 | + } else { |
|
899 | 899 | return array_shift($items); |
900 | 900 | } |
901 | 901 | } |
@@ -919,8 +919,8 @@ discard block |
||
919 | 919 | * |
920 | 920 | * @return EE_Base_Class[]|array |
921 | 921 | */ |
922 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
923 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
922 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
923 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @return EE_Base_Class[]|array |
945 | 945 | */ |
946 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
947 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
946 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
947 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | |
@@ -966,9 +966,9 @@ discard block |
||
966 | 966 | * |
967 | 967 | * @return EE_Base_Class|null|array() |
968 | 968 | */ |
969 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
970 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
971 | - return empty( $results ) ? null : reset( $results ); |
|
969 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
970 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
971 | + return empty($results) ? null : reset($results); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | |
@@ -990,9 +990,9 @@ discard block |
||
990 | 990 | * |
991 | 991 | * @return EE_Base_Class|null|array() |
992 | 992 | */ |
993 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
994 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
995 | - return empty( $results ) ? null : reset( $results ); |
|
993 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
994 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
995 | + return empty($results) ? null : reset($results); |
|
996 | 996 | } |
997 | 997 | |
998 | 998 | |
@@ -1018,40 +1018,40 @@ discard block |
||
1018 | 1018 | * @return EE_Base_Class[]|array |
1019 | 1019 | * @throws EE_Error |
1020 | 1020 | */ |
1021 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1021 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1022 | 1022 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1023 | - if ( empty( $field_to_order_by ) ) { |
|
1024 | - if ( $this->has_primary_key_field() ) { |
|
1023 | + if (empty($field_to_order_by)) { |
|
1024 | + if ($this->has_primary_key_field()) { |
|
1025 | 1025 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1026 | 1026 | } else { |
1027 | 1027 | |
1028 | - if ( WP_DEBUG ) { |
|
1029 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1028 | + if (WP_DEBUG) { |
|
1029 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1030 | 1030 | } |
1031 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1031 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1032 | 1032 | return array(); |
1033 | 1033 | } |
1034 | 1034 | } |
1035 | 1035 | |
1036 | - if( ! is_array( $query_params ) ){ |
|
1037 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1036 | + if ( ! is_array($query_params)) { |
|
1037 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1038 | 1038 | $query_params = array(); |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | //let's add the where query param for consecutive look up. |
1042 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1042 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1043 | 1043 | $query_params['limit'] = $limit; |
1044 | 1044 | |
1045 | 1045 | //set direction |
1046 | - $incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array(); |
|
1047 | - $query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1046 | + $incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array(); |
|
1047 | + $query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1048 | 1048 | |
1049 | 1049 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1050 | - if ( empty( $columns_to_select ) ) { |
|
1051 | - return $this->get_all( $query_params ); |
|
1050 | + if (empty($columns_to_select)) { |
|
1051 | + return $this->get_all($query_params); |
|
1052 | 1052 | } else { |
1053 | 1053 | //getting just the fields |
1054 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1054 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | |
@@ -1062,18 +1062,18 @@ discard block |
||
1062 | 1062 | * This sets the _timezone property after model object has been instantiated. |
1063 | 1063 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1064 | 1064 | */ |
1065 | - public function set_timezone( $timezone ) { |
|
1066 | - if ( $timezone !== null ) { |
|
1065 | + public function set_timezone($timezone) { |
|
1066 | + if ($timezone !== null) { |
|
1067 | 1067 | $this->_timezone = $timezone; |
1068 | 1068 | } |
1069 | 1069 | //note we need to loop through relations and set the timezone on those objects as well. |
1070 | - foreach ( $this->_model_relations as $relation ) { |
|
1071 | - $relation->set_timezone( $timezone ); |
|
1070 | + foreach ($this->_model_relations as $relation) { |
|
1071 | + $relation->set_timezone($timezone); |
|
1072 | 1072 | } |
1073 | 1073 | //and finally we do the same for any datetime fields |
1074 | - foreach ( $this->_fields as $field ) { |
|
1075 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1076 | - $field->set_timezone( $timezone ); |
|
1074 | + foreach ($this->_fields as $field) { |
|
1075 | + if ($field instanceof EE_Datetime_Field) { |
|
1076 | + $field->set_timezone($timezone); |
|
1077 | 1077 | } |
1078 | 1078 | } |
1079 | 1079 | } |
@@ -1088,9 +1088,9 @@ discard block |
||
1088 | 1088 | */ |
1089 | 1089 | public function get_timezone() { |
1090 | 1090 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1091 | - if ( empty( $this->_timezone ) ) { |
|
1092 | - foreach( $this->_fields as $field ) { |
|
1093 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1091 | + if (empty($this->_timezone)) { |
|
1092 | + foreach ($this->_fields as $field) { |
|
1093 | + if ($field instanceof EE_Datetime_Field) { |
|
1094 | 1094 | $this->set_timezone($field->get_timezone()); |
1095 | 1095 | break; |
1096 | 1096 | } |
@@ -1098,9 +1098,9 @@ discard block |
||
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | //if timezone STILL empty then return the default timezone for the site. |
1101 | - if ( empty( $this->_timezone ) ) { |
|
1102 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1103 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1101 | + if (empty($this->_timezone)) { |
|
1102 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1103 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1104 | 1104 | } |
1105 | 1105 | return $this->_timezone; |
1106 | 1106 | } |
@@ -1118,19 +1118,19 @@ discard block |
||
1118 | 1118 | * |
1119 | 1119 | * @return array formats in an array with the date format first, and the time format last. |
1120 | 1120 | */ |
1121 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1122 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1121 | + public function get_formats_for($field_name, $pretty = false) { |
|
1122 | + $field_settings = $this->field_settings_for($field_name); |
|
1123 | 1123 | |
1124 | 1124 | //if not a valid EE_Datetime_Field then throw error |
1125 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1126 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1125 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1126 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1130 | 1130 | //the field. |
1131 | 1131 | $this->_timezone = $field_settings->get_timezone(); |
1132 | 1132 | |
1133 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1133 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | |
@@ -1154,25 +1154,25 @@ discard block |
||
1154 | 1154 | * @return string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1155 | 1155 | * exception is triggered. |
1156 | 1156 | */ |
1157 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1158 | - $formats = $this->get_formats_for( $field_name ); |
|
1157 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1158 | + $formats = $this->get_formats_for($field_name); |
|
1159 | 1159 | |
1160 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1160 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1161 | 1161 | |
1162 | - if ( $timestamp ) { |
|
1163 | - return $DateTime->format( 'U' ); |
|
1162 | + if ($timestamp) { |
|
1163 | + return $DateTime->format('U'); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | //not returning timestamp, so return formatted string in timezone. |
1167 | - switch( $what ) { |
|
1167 | + switch ($what) { |
|
1168 | 1168 | case 'time' : |
1169 | - return $DateTime->format( $formats[1] ); |
|
1169 | + return $DateTime->format($formats[1]); |
|
1170 | 1170 | break; |
1171 | 1171 | case 'date' : |
1172 | - return $DateTime->format( $formats[0] ); |
|
1172 | + return $DateTime->format($formats[0]); |
|
1173 | 1173 | break; |
1174 | 1174 | default : |
1175 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1175 | + return $DateTime->format(implode(' ', $formats)); |
|
1176 | 1176 | break; |
1177 | 1177 | } |
1178 | 1178 | } |
@@ -1196,18 +1196,18 @@ discard block |
||
1196 | 1196 | * 'U', this is ignored. |
1197 | 1197 | * @return DateTime |
1198 | 1198 | */ |
1199 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1199 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1200 | 1200 | |
1201 | 1201 | //just using this to ensure the timezone is set correctly internally |
1202 | - $this->get_formats_for( $field_name ); |
|
1202 | + $this->get_formats_for($field_name); |
|
1203 | 1203 | |
1204 | 1204 | //load EEH_DTT_Helper |
1205 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1206 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1205 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1206 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1207 | 1207 | |
1208 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1208 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1209 | 1209 | |
1210 | - return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) ); |
|
1210 | + return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone)); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1218 | 1218 | * @return EE_Table_Base[] |
1219 | 1219 | */ |
1220 | - function get_tables(){ |
|
1220 | + function get_tables() { |
|
1221 | 1221 | return $this->_tables; |
1222 | 1222 | } |
1223 | 1223 | |
@@ -1251,9 +1251,9 @@ discard block |
||
1251 | 1251 | * be aware that model objects being used could get out-of-sync with the database |
1252 | 1252 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1253 | 1253 | */ |
1254 | - function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1255 | - if( ! is_array( $query_params ) ){ |
|
1256 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1254 | + function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1255 | + if ( ! is_array($query_params)) { |
|
1256 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1257 | 1257 | $query_params = array(); |
1258 | 1258 | } |
1259 | 1259 | /** |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | * @param array $fields_n_values the updated fields and their new values |
1264 | 1264 | * @param array $query_params @see EEM_Base::get_all() |
1265 | 1265 | */ |
1266 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1266 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1267 | 1267 | /** |
1268 | 1268 | * Filters the fields about to be updated given the query parameters. You can provide the |
1269 | 1269 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1271,10 +1271,10 @@ discard block |
||
1271 | 1271 | * @param EEM_Base $model the model being queried |
1272 | 1272 | * @param array $query_params see EEM_Base::get_all() |
1273 | 1273 | */ |
1274 | - $fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1274 | + $fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1275 | 1275 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1276 | 1276 | //to do that, for each table, verify that it's PK isn't null. |
1277 | - $tables= $this->get_tables(); |
|
1277 | + $tables = $this->get_tables(); |
|
1278 | 1278 | |
1279 | 1279 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1280 | 1280 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1284,29 +1284,29 @@ discard block |
||
1284 | 1284 | //we want to make sure the default_where strategy is ignored |
1285 | 1285 | $this->_ignore_where_strategy = TRUE; |
1286 | 1286 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1287 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1287 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1288 | 1288 | // type cast stdClass as array |
1289 | - $wpdb_result = (array)$wpdb_result; |
|
1289 | + $wpdb_result = (array) $wpdb_result; |
|
1290 | 1290 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1291 | - if( $this->has_primary_key_field() ){ |
|
1292 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1293 | - }else{ |
|
1291 | + if ($this->has_primary_key_field()) { |
|
1292 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1293 | + } else { |
|
1294 | 1294 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work) |
1295 | 1295 | $main_table_pk_value = null; |
1296 | 1296 | } |
1297 | 1297 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1298 | 1298 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1299 | - if(count($tables) > 1){ |
|
1299 | + if (count($tables) > 1) { |
|
1300 | 1300 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1301 | 1301 | //in that table, and so we'll want to insert one |
1302 | - foreach($tables as $table_obj){ |
|
1302 | + foreach ($tables as $table_obj) { |
|
1303 | 1303 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1304 | 1304 | //if there is no private key for this table on the results, it means there's no entry |
1305 | 1305 | //in this table, right? so insert a row in the current table, using any fields available |
1306 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1306 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1307 | 1307 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1308 | 1308 | //if we died here, report the error |
1309 | - if( ! $success ) { |
|
1309 | + if ( ! $success) { |
|
1310 | 1310 | return false; |
1311 | 1311 | } |
1312 | 1312 | } |
@@ -1326,44 +1326,44 @@ discard block |
||
1326 | 1326 | //if this wasn't called from a model object (to update itself) |
1327 | 1327 | //then we want to make sure we keep all the existing |
1328 | 1328 | //model objects in sync with the db |
1329 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1330 | - if( $this->has_primary_key_field() ){ |
|
1331 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1332 | - }else{ |
|
1329 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1330 | + if ($this->has_primary_key_field()) { |
|
1331 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1332 | + } else { |
|
1333 | 1333 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1334 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1334 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1335 | 1335 | $model_objs_affected_ids = array(); |
1336 | - foreach( $models_affected_key_columns as $row ){ |
|
1337 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1338 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1336 | + foreach ($models_affected_key_columns as $row) { |
|
1337 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1338 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | } |
1342 | 1342 | |
1343 | - if( ! $model_objs_affected_ids ){ |
|
1343 | + if ( ! $model_objs_affected_ids) { |
|
1344 | 1344 | //wait wait wait- if nothing was affected let's stop here |
1345 | 1345 | return 0; |
1346 | 1346 | } |
1347 | - foreach( $model_objs_affected_ids as $id ){ |
|
1348 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1349 | - if( $model_obj_in_entity_map ){ |
|
1350 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1351 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1347 | + foreach ($model_objs_affected_ids as $id) { |
|
1348 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1349 | + if ($model_obj_in_entity_map) { |
|
1350 | + foreach ($fields_n_values as $field => $new_value) { |
|
1351 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1352 | 1352 | } |
1353 | 1353 | } |
1354 | 1354 | } |
1355 | 1355 | //if there is a primary key on this model, we can now do a slight optimization |
1356 | - if( $this->has_primary_key_field() ){ |
|
1356 | + if ($this->has_primary_key_field()) { |
|
1357 | 1357 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1358 | 1358 | $query_params = array( |
1359 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1360 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1359 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1360 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1361 | 1361 | } |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1365 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1366 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1364 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1365 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1366 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1367 | 1367 | /** |
1368 | 1368 | * Action called after a model update call has been made. |
1369 | 1369 | * |
@@ -1372,8 +1372,8 @@ discard block |
||
1372 | 1372 | * @param array $query_params @see EEM_Base::get_all() |
1373 | 1373 | * @param int $rows_affected |
1374 | 1374 | */ |
1375 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1376 | - return $rows_affected;//how many supposedly got updated |
|
1375 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1376 | + return $rows_affected; //how many supposedly got updated |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | 1379 | /** |
@@ -1385,22 +1385,22 @@ discard block |
||
1385 | 1385 | * @param string $field_to_select |
1386 | 1386 | * @return array just like $wpdb->get_col() |
1387 | 1387 | */ |
1388 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1388 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1389 | 1389 | |
1390 | - if( $field_to_select ){ |
|
1391 | - $field = $this->field_settings_for( $field_to_select ); |
|
1392 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1390 | + if ($field_to_select) { |
|
1391 | + $field = $this->field_settings_for($field_to_select); |
|
1392 | + }elseif ($this->has_primary_key_field( )) { |
|
1393 | 1393 | $field = $this->get_primary_key_field(); |
1394 | - }else{ |
|
1394 | + } else { |
|
1395 | 1395 | //no primary key, just grab the first column |
1396 | - $field = reset( $this->field_settings()); |
|
1396 | + $field = reset($this->field_settings()); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | |
1400 | 1400 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1401 | 1401 | $select_expressions = $field->get_qualified_column(); |
1402 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1403 | - $results = $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1402 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1403 | + $results = $this->_do_wpdb_query('get_col', array($SQL)); |
|
1404 | 1404 | return $results; |
1405 | 1405 | } |
1406 | 1406 | |
@@ -1410,12 +1410,12 @@ discard block |
||
1410 | 1410 | * @param string $field_to_select @see EEM_Base::get_col() |
1411 | 1411 | * @return string |
1412 | 1412 | */ |
1413 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1414 | - $query_params[ 'limit' ] = 1; |
|
1415 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1416 | - if( ! empty( $col ) ) { |
|
1417 | - return reset( $col ); |
|
1418 | - }else{ |
|
1413 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1414 | + $query_params['limit'] = 1; |
|
1415 | + $col = $this->get_col($query_params, $field_to_select); |
|
1416 | + if ( ! empty($col)) { |
|
1417 | + return reset($col); |
|
1418 | + } else { |
|
1419 | 1419 | return NULL; |
1420 | 1420 | } |
1421 | 1421 | } |
@@ -1429,19 +1429,19 @@ discard block |
||
1429 | 1429 | * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB |
1430 | 1430 | * @return string of SQL |
1431 | 1431 | */ |
1432 | - function _construct_update_sql($fields_n_values){ |
|
1432 | + function _construct_update_sql($fields_n_values) { |
|
1433 | 1433 | /** @type WPDB $wpdb */ |
1434 | 1434 | global $wpdb; |
1435 | 1435 | $cols_n_values = array(); |
1436 | - foreach($fields_n_values as $field_name => $value){ |
|
1436 | + foreach ($fields_n_values as $field_name => $value) { |
|
1437 | 1437 | $field_obj = $this->field_settings_for($field_name); |
1438 | 1438 | //if the value is NULL, we want to assign the value to that. |
1439 | 1439 | //wpdb->prepare doesn't really handle that properly |
1440 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1441 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1440 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1441 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1442 | 1442 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1443 | 1443 | } |
1444 | - return implode(",",$cols_n_values); |
|
1444 | + return implode(",", $cols_n_values); |
|
1445 | 1445 | |
1446 | 1446 | } |
1447 | 1447 | |
@@ -1453,11 +1453,11 @@ discard block |
||
1453 | 1453 | * @param mixed $id |
1454 | 1454 | * @return boolean whether the row got deleted or not |
1455 | 1455 | */ |
1456 | - public function delete_by_ID( $id ){ |
|
1457 | - return $this->delete( array( |
|
1458 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1456 | + public function delete_by_ID($id) { |
|
1457 | + return $this->delete(array( |
|
1458 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1459 | 1459 | 'limit' => 1 |
1460 | - ) ); |
|
1460 | + )); |
|
1461 | 1461 | } |
1462 | 1462 | |
1463 | 1463 | |
@@ -1472,7 +1472,7 @@ discard block |
||
1472 | 1472 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1473 | 1473 | * @return int how many rows got deleted |
1474 | 1474 | */ |
1475 | - function delete($query_params,$allow_blocking = true){ |
|
1475 | + function delete($query_params, $allow_blocking = true) { |
|
1476 | 1476 | /** |
1477 | 1477 | * Action called just before performing a real deletion query. You can use the |
1478 | 1478 | * model and its $query_params to find exactly which items will be deleted |
@@ -1481,34 +1481,34 @@ discard block |
||
1481 | 1481 | * @param boolean $allow_blocking whether or not to allow related model objects |
1482 | 1482 | * to block (prevent) this deletion |
1483 | 1483 | */ |
1484 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1484 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1485 | 1485 | //some MySQL databases may be running safe mode, which may restrict |
1486 | 1486 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1487 | 1487 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1488 | 1488 | //to delete them |
1489 | 1489 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1490 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1491 | - if($deletion_where){ |
|
1490 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1491 | + if ($deletion_where) { |
|
1492 | 1492 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1493 | 1493 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1494 | 1494 | $table_aliases = array(); |
1495 | - foreach(array_keys($this->_tables) as $table_alias){ |
|
1495 | + foreach (array_keys($this->_tables) as $table_alias) { |
|
1496 | 1496 | $table_aliases[] = $table_alias; |
1497 | 1497 | } |
1498 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1498 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1499 | 1499 | |
1500 | 1500 | // /echo "delete sql:$SQL"; |
1501 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1502 | - }else{ |
|
1501 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1502 | + } else { |
|
1503 | 1503 | $rows_deleted = 0; |
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1507 | - if( $this->has_primary_key_field() ){ |
|
1508 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1509 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1510 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1511 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1507 | + if ($this->has_primary_key_field()) { |
|
1508 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1509 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1510 | + if (isset($this->_entity_map[$pk_value])) { |
|
1511 | + unset($this->_entity_map[$pk_value]); |
|
1512 | 1512 | } |
1513 | 1513 | } |
1514 | 1514 | } |
@@ -1520,8 +1520,8 @@ discard block |
||
1520 | 1520 | * @param array $query_params @see EEM_Base::get_all() |
1521 | 1521 | * @param int $rows_deleted |
1522 | 1522 | */ |
1523 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1524 | - return $rows_deleted;//how many supposedly got deleted |
|
1523 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1524 | + return $rows_deleted; //how many supposedly got deleted |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | |
@@ -1537,28 +1537,28 @@ discard block |
||
1537 | 1537 | * blocking its deletion before removing the relation between A and B |
1538 | 1538 | * @return boolean |
1539 | 1539 | */ |
1540 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1540 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1541 | 1541 | //first, if $ignore_this_model_obj was supplied, get its model |
1542 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1542 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1543 | 1543 | $ignored_model = $ignore_this_model_obj->get_model(); |
1544 | - }else{ |
|
1544 | + } else { |
|
1545 | 1545 | $ignored_model = null; |
1546 | 1546 | } |
1547 | 1547 | //now check all the relations of $this_model_obj_or_id and see if there |
1548 | 1548 | //are any related model objects blocking it? |
1549 | 1549 | $is_blocked = false; |
1550 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1551 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1550 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1551 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1552 | 1552 | //if $ignore_this_model_obj was supplied, then for the query |
1553 | 1553 | //on that model needs to be told to ignore $ignore_this_model_obj |
1554 | - if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
|
1555 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1556 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1557 | - }else{ |
|
1554 | + if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) { |
|
1555 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1556 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1557 | + } else { |
|
1558 | 1558 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1559 | 1559 | } |
1560 | 1560 | |
1561 | - if($related_model_objects){ |
|
1561 | + if ($related_model_objects) { |
|
1562 | 1562 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1563 | 1563 | $is_blocked = true; |
1564 | 1564 | } |
@@ -1578,65 +1578,65 @@ discard block |
||
1578 | 1578 | * @throws EE_Error |
1579 | 1579 | * @return string everything that comes after the WHERE statement. |
1580 | 1580 | */ |
1581 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1582 | - if($this->has_primary_key_field()){ |
|
1581 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1582 | + if ($this->has_primary_key_field()) { |
|
1583 | 1583 | $primary_table = $this->_get_main_table(); |
1584 | 1584 | $other_tables = $this->_get_other_tables(); |
1585 | 1585 | $deletes = $query = array(); |
1586 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1586 | + foreach ($objects_for_deletion as $delete_object) { |
|
1587 | 1587 | //before we mark this object for deletion, |
1588 | 1588 | //make sure there's no related objects blocking its deletion (if we're checking) |
1589 | - if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){ |
|
1589 | + if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1590 | 1590 | continue; |
1591 | 1591 | } |
1592 | 1592 | |
1593 | 1593 | //primary table deletes |
1594 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1594 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) |
|
1595 | 1595 | $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
1596 | 1596 | |
1597 | 1597 | //other tables |
1598 | - if ( !empty( $other_tables ) ) { |
|
1599 | - foreach ( $other_tables as $ot ) { |
|
1598 | + if ( ! empty($other_tables)) { |
|
1599 | + foreach ($other_tables as $ot) { |
|
1600 | 1600 | |
1601 | 1601 | //first check if we've got the foreign key column here. |
1602 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1602 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) |
|
1603 | 1603 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
1604 | 1604 | |
1605 | 1605 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1606 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1606 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) |
|
1607 | 1607 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1608 | 1608 | |
1609 | 1609 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1610 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1610 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) |
|
1611 | 1611 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1612 | 1612 | } |
1613 | 1613 | } |
1614 | 1614 | } |
1615 | 1615 | |
1616 | 1616 | //we should have deletes now, so let's just go through and setup the where statement |
1617 | - foreach ( $deletes as $column => $values ) { |
|
1617 | + foreach ($deletes as $column => $values) { |
|
1618 | 1618 | //make sure we have unique $values; |
1619 | 1619 | $values = array_unique($values); |
1620 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1620 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1621 | 1621 | } |
1622 | 1622 | |
1623 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1624 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1623 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1624 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1625 | 1625 | $ways_to_identify_a_row = array(); |
1626 | 1626 | $fields = $this->get_combined_primary_key_fields(); |
1627 | 1627 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1628 | - foreach($objects_for_deletion as $delete_object){ |
|
1628 | + foreach ($objects_for_deletion as $delete_object) { |
|
1629 | 1629 | $values_for_each_cpk_for_a_row = array(); |
1630 | - foreach($fields as $cpk_field){ |
|
1630 | + foreach ($fields as $cpk_field) { |
|
1631 | 1631 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1632 | 1632 | } |
1633 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1633 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1634 | 1634 | } |
1635 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1636 | - }else{ |
|
1635 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1636 | + } else { |
|
1637 | 1637 | //so there's no primary key and no combined key... |
1638 | 1638 | //sorry, can't help you |
1639 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1639 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1640 | 1640 | } |
1641 | 1641 | } |
1642 | 1642 | |
@@ -1650,21 +1650,21 @@ discard block |
||
1650 | 1650 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1651 | 1651 | * @return int |
1652 | 1652 | */ |
1653 | - function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1653 | + function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1654 | 1654 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1655 | - if($field_to_count){ |
|
1655 | + if ($field_to_count) { |
|
1656 | 1656 | $field_obj = $this->field_settings_for($field_to_count); |
1657 | 1657 | $column_to_count = $field_obj->get_qualified_column(); |
1658 | - }elseif($this->has_primary_key_field ()){ |
|
1658 | + }elseif ($this->has_primary_key_field()) { |
|
1659 | 1659 | $pk_field_obj = $this->get_primary_key_field(); |
1660 | 1660 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1661 | - }else{//there's no primary key |
|
1661 | + } else {//there's no primary key |
|
1662 | 1662 | $column_to_count = '*'; |
1663 | 1663 | } |
1664 | 1664 | |
1665 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1666 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1667 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1665 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1666 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1667 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | /** |
@@ -1674,23 +1674,23 @@ discard block |
||
1674 | 1674 | * @param string $field_to_sum name of field (array key in $_fields array) |
1675 | 1675 | * @return float |
1676 | 1676 | */ |
1677 | - function sum($query_params, $field_to_sum = NULL){ |
|
1677 | + function sum($query_params, $field_to_sum = NULL) { |
|
1678 | 1678 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1679 | 1679 | |
1680 | - if($field_to_sum){ |
|
1680 | + if ($field_to_sum) { |
|
1681 | 1681 | $field_obj = $this->field_settings_for($field_to_sum); |
1682 | 1682 | |
1683 | - }else{ |
|
1683 | + } else { |
|
1684 | 1684 | $field_obj = $this->get_primary_key_field(); |
1685 | 1685 | } |
1686 | 1686 | $column_to_count = $field_obj->get_qualified_column(); |
1687 | 1687 | |
1688 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1689 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1690 | - if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
|
1691 | - return (float)$return_value; |
|
1692 | - }else{//must be %f |
|
1693 | - return (float)$return_value; |
|
1688 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1689 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1690 | + if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') { |
|
1691 | + return (float) $return_value; |
|
1692 | + } else {//must be %f |
|
1693 | + return (float) $return_value; |
|
1694 | 1694 | } |
1695 | 1695 | } |
1696 | 1696 | |
@@ -1705,35 +1705,35 @@ discard block |
||
1705 | 1705 | * @global wpdb $wpdb |
1706 | 1706 | * @return mixed |
1707 | 1707 | */ |
1708 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1708 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1709 | 1709 | //if we're in maintenance mode level 2, DON'T run any queries |
1710 | 1710 | //because level 2 indicates the database needs updating and |
1711 | 1711 | //is probably out of sync with the code |
1712 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1712 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1713 | 1713 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1714 | 1714 | } |
1715 | 1715 | /** @type WPDB $wpdb */ |
1716 | 1716 | global $wpdb; |
1717 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1718 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1717 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1718 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1719 | 1719 | } |
1720 | - if( WP_DEBUG ){ |
|
1720 | + if (WP_DEBUG) { |
|
1721 | 1721 | $wpdb->last_error = NULL; |
1722 | 1722 | $old_show_errors_value = $wpdb->show_errors; |
1723 | - $wpdb->show_errors( FALSE ); |
|
1723 | + $wpdb->show_errors(FALSE); |
|
1724 | 1724 | } |
1725 | 1725 | |
1726 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ) , $arguments_to_provide ); |
|
1727 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1728 | - if( WP_DEBUG ){ |
|
1729 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1730 | - if( ! empty( $wpdb->last_error ) ){ |
|
1731 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1732 | - }elseif( $result === false ){ |
|
1733 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1726 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1727 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1728 | + if (WP_DEBUG) { |
|
1729 | + $wpdb->show_errors($old_show_errors_value); |
|
1730 | + if ( ! empty($wpdb->last_error)) { |
|
1731 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1732 | + }elseif ($result === false) { |
|
1733 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1734 | 1734 | } |
1735 | - }elseif( $result === false ) { |
|
1736 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1735 | + }elseif ($result === false) { |
|
1736 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1737 | 1737 | } |
1738 | 1738 | return $result; |
1739 | 1739 | } |
@@ -1745,7 +1745,7 @@ discard block |
||
1745 | 1745 | * @param EE_Model_Query_Info_Carrier $model_query_info |
1746 | 1746 | * @return string |
1747 | 1747 | */ |
1748 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
1748 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
1749 | 1749 | return " FROM ".$model_query_info->get_full_join_sql(). |
1750 | 1750 | $model_query_info->get_where_sql(). |
1751 | 1751 | $model_query_info->get_group_by_sql(). |
@@ -1758,7 +1758,7 @@ discard block |
||
1758 | 1758 | * Set to easily debug the next X queries ran from this model. |
1759 | 1759 | * @param int $count |
1760 | 1760 | */ |
1761 | - function show_next_x_db_queries($count = 1){ |
|
1761 | + function show_next_x_db_queries($count = 1) { |
|
1762 | 1762 | $this->_show_next_x_db_queries = $count; |
1763 | 1763 | } |
1764 | 1764 | |
@@ -1767,8 +1767,8 @@ discard block |
||
1767 | 1767 | /** |
1768 | 1768 | * @param $sql_query |
1769 | 1769 | */ |
1770 | - function show_db_query_if_previously_requested($sql_query){ |
|
1771 | - if($this->_show_next_x_db_queries > 0){ |
|
1770 | + function show_db_query_if_previously_requested($sql_query) { |
|
1771 | + if ($this->_show_next_x_db_queries > 0) { |
|
1772 | 1772 | echo $sql_query; |
1773 | 1773 | $this->_show_next_x_db_queries--; |
1774 | 1774 | } |
@@ -1792,7 +1792,7 @@ discard block |
||
1792 | 1792 | * @param array $extra_join_model_fields_n_values This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
1793 | 1793 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
1794 | 1794 | */ |
1795 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
1795 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
1796 | 1796 | $relation_obj = $this->related_settings_for($relationName); |
1797 | 1797 | return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
1798 | 1798 | } |
@@ -1813,9 +1813,9 @@ discard block |
||
1813 | 1813 | * @return boolean of success |
1814 | 1814 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
1815 | 1815 | */ |
1816 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
1816 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
1817 | 1817 | $relation_obj = $this->related_settings_for($relationName); |
1818 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
1818 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | |
@@ -1828,9 +1828,9 @@ discard block |
||
1828 | 1828 | * @param EE_Base_Class[] objects to which relations were removed |
1829 | 1829 | * @return \EE_Base_Class[] |
1830 | 1830 | */ |
1831 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
1831 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
1832 | 1832 | $relation_obj = $this->related_settings_for($relationName); |
1833 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
1833 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
1834 | 1834 | } |
1835 | 1835 | |
1836 | 1836 | |
@@ -1843,10 +1843,10 @@ discard block |
||
1843 | 1843 | * @param array $query_params like EEM_Base::get_all |
1844 | 1844 | * @return EE_Base_Class[] |
1845 | 1845 | */ |
1846 | - function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
1846 | + function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
1847 | 1847 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1848 | 1848 | $relation_settings = $this->related_settings_for($model_name); |
1849 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
1849 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
1850 | 1850 | } |
1851 | 1851 | |
1852 | 1852 | /** |
@@ -1859,10 +1859,10 @@ discard block |
||
1859 | 1859 | * @param array $query_params |
1860 | 1860 | * @return int how many deleted |
1861 | 1861 | */ |
1862 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
1862 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
1863 | 1863 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1864 | 1864 | $relation_settings = $this->related_settings_for($model_name); |
1865 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
1865 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
1866 | 1866 | } |
1867 | 1867 | |
1868 | 1868 | /** |
@@ -1875,10 +1875,10 @@ discard block |
||
1875 | 1875 | * @param array $query_params |
1876 | 1876 | * @return int how many deleted |
1877 | 1877 | */ |
1878 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
1878 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
1879 | 1879 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1880 | 1880 | $relation_settings = $this->related_settings_for($model_name); |
1881 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
1881 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | 1884 | /** |
@@ -1891,17 +1891,17 @@ discard block |
||
1891 | 1891 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1892 | 1892 | * @return int |
1893 | 1893 | */ |
1894 | - function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
1894 | + function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
1895 | 1895 | $related_model = $this->get_related_model_obj($model_name); |
1896 | 1896 | //we're just going to use the query params on the related model's normal get_all query, |
1897 | 1897 | //except add a condition to say to match the current mod |
1898 | - if( ! isset($query_params['default_where_conditions'])){ |
|
1899 | - $query_params['default_where_conditions']='none'; |
|
1898 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
1899 | + $query_params['default_where_conditions'] = 'none'; |
|
1900 | 1900 | } |
1901 | 1901 | $this_model_name = $this->get_this_model_name(); |
1902 | 1902 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
1903 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
1904 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
1903 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
1904 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
1905 | 1905 | } |
1906 | 1906 | |
1907 | 1907 | |
@@ -1915,21 +1915,21 @@ discard block |
||
1915 | 1915 | * @param string $field_to_sum name of field to count by. By default, uses primary key |
1916 | 1916 | * @return float |
1917 | 1917 | */ |
1918 | - function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
1918 | + function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
1919 | 1919 | $related_model = $this->get_related_model_obj($model_name); |
1920 | - if( ! is_array( $query_params ) ){ |
|
1921 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1920 | + if ( ! is_array($query_params)) { |
|
1921 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1922 | 1922 | $query_params = array(); |
1923 | 1923 | } |
1924 | 1924 | //we're just going to use the query params on the related model's normal get_all query, |
1925 | 1925 | //except add a condition to say to match the current mod |
1926 | - if( ! isset($query_params['default_where_conditions'])){ |
|
1927 | - $query_params['default_where_conditions']='none'; |
|
1926 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
1927 | + $query_params['default_where_conditions'] = 'none'; |
|
1928 | 1928 | } |
1929 | 1929 | $this_model_name = $this->get_this_model_name(); |
1930 | 1930 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
1931 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
1932 | - return $related_model->sum($query_params,$field_to_sum); |
|
1931 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
1932 | + return $related_model->sum($query_params, $field_to_sum); |
|
1933 | 1933 | } |
1934 | 1934 | |
1935 | 1935 | |
@@ -1941,12 +1941,12 @@ discard block |
||
1941 | 1941 | * @param array $query_params like EEM_Base::get_all's |
1942 | 1942 | * @return EE_Base_Class |
1943 | 1943 | */ |
1944 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
1945 | - $query_params['limit']=1; |
|
1946 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
1947 | - if( $results ){ |
|
1944 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
1945 | + $query_params['limit'] = 1; |
|
1946 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
1947 | + if ($results) { |
|
1948 | 1948 | return array_shift($results); |
1949 | - }else{ |
|
1949 | + } else { |
|
1950 | 1950 | return null; |
1951 | 1951 | } |
1952 | 1952 | |
@@ -1956,8 +1956,8 @@ discard block |
||
1956 | 1956 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
1957 | 1957 | * @return string |
1958 | 1958 | */ |
1959 | - function get_this_model_name(){ |
|
1960 | - return str_replace("EEM_","",get_class($this)); |
|
1959 | + function get_this_model_name() { |
|
1960 | + return str_replace("EEM_", "", get_class($this)); |
|
1961 | 1961 | } |
1962 | 1962 | |
1963 | 1963 | /** |
@@ -1965,14 +1965,14 @@ discard block |
||
1965 | 1965 | * @return EE_Any_Foreign_Model_Name_Field |
1966 | 1966 | * @throws EE_Error |
1967 | 1967 | */ |
1968 | - public function get_field_containing_related_model_name(){ |
|
1969 | - foreach($this->field_settings(true) as $field){ |
|
1970 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
1968 | + public function get_field_containing_related_model_name() { |
|
1969 | + foreach ($this->field_settings(true) as $field) { |
|
1970 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
1971 | 1971 | $field_with_model_name = $field; |
1972 | 1972 | } |
1973 | 1973 | } |
1974 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
1975 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
1974 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
1975 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
1976 | 1976 | } |
1977 | 1977 | return $field_with_model_name; |
1978 | 1978 | } |
@@ -1993,19 +1993,19 @@ discard block |
||
1993 | 1993 | * @return int new primary key on main table that got inserted |
1994 | 1994 | * @throws EE_Error |
1995 | 1995 | */ |
1996 | - function insert($field_n_values){ |
|
1996 | + function insert($field_n_values) { |
|
1997 | 1997 | /** |
1998 | 1998 | * Filters the fields and their values before inserting an item using the models |
1999 | 1999 | * @param array $fields_n_values keys are the fields and values are their new values |
2000 | 2000 | * @param EEM_Base $model the model used |
2001 | 2001 | */ |
2002 | - $field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2003 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2002 | + $field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2003 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2004 | 2004 | $main_table = $this->_get_main_table(); |
2005 | 2005 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2006 | - if( $new_id !== false ) { |
|
2007 | - foreach($this->_get_other_tables() as $other_table){ |
|
2008 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2006 | + if ($new_id !== false) { |
|
2007 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2008 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2009 | 2009 | } |
2010 | 2010 | } |
2011 | 2011 | /** |
@@ -2015,9 +2015,9 @@ discard block |
||
2015 | 2015 | * @param array $fields_n_values fields and their values |
2016 | 2016 | * @param int|string the ID of the newly-inserted model object |
2017 | 2017 | */ |
2018 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2018 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2019 | 2019 | return $new_id; |
2020 | - }else{ |
|
2020 | + } else { |
|
2021 | 2021 | return FALSE; |
2022 | 2022 | } |
2023 | 2023 | } |
@@ -2030,11 +2030,11 @@ discard block |
||
2030 | 2030 | * @param string $action |
2031 | 2031 | * @return boolean |
2032 | 2032 | */ |
2033 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2034 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2033 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2034 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2035 | 2035 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2036 | - if($this->exists(array($uniqueness_where_params))){ |
|
2037 | - EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ ); |
|
2036 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2037 | + EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__); |
|
2038 | 2038 | return false; |
2039 | 2039 | } |
2040 | 2040 | } |
@@ -2055,28 +2055,28 @@ discard block |
||
2055 | 2055 | * @throws EE_Error |
2056 | 2056 | * @return EE_Base_Class |
2057 | 2057 | */ |
2058 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2059 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2058 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2059 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2060 | 2060 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2061 | - }elseif( is_array($obj_or_fields_array)){ |
|
2061 | + }elseif (is_array($obj_or_fields_array)) { |
|
2062 | 2062 | $fields_n_values = $obj_or_fields_array; |
2063 | - }else{ |
|
2064 | - throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
|
2063 | + } else { |
|
2064 | + throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array)); |
|
2065 | 2065 | } |
2066 | 2066 | $query_params = array(); |
2067 | - if( $this->has_primary_key_field() && |
|
2068 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2069 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2067 | + if ($this->has_primary_key_field() && |
|
2068 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2069 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2070 | 2070 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2071 | 2071 | } |
2072 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2072 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2073 | 2073 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2074 | 2074 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2075 | 2075 | } |
2076 | 2076 | //if there is nothing to base this search on, then we shouldn't find anything |
2077 | - if( empty( $query_params ) ){ |
|
2077 | + if (empty($query_params)) { |
|
2078 | 2078 | return array(); |
2079 | - }else{ |
|
2079 | + } else { |
|
2080 | 2080 | return $this->get_one($query_params); |
2081 | 2081 | } |
2082 | 2082 | } |
@@ -2086,7 +2086,7 @@ discard block |
||
2086 | 2086 | * @param array $query_params |
2087 | 2087 | * @return boolean |
2088 | 2088 | */ |
2089 | - function exists($query_params){ |
|
2089 | + function exists($query_params) { |
|
2090 | 2090 | $query_params['limit'] = 1; |
2091 | 2091 | return $this->count($query_params) > 0; |
2092 | 2092 | } |
@@ -2096,7 +2096,7 @@ discard block |
||
2096 | 2096 | * @param int|string $id |
2097 | 2097 | * @return boolean |
2098 | 2098 | */ |
2099 | - function exists_by_ID($id){ |
|
2099 | + function exists_by_ID($id) { |
|
2100 | 2100 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2101 | 2101 | } |
2102 | 2102 | |
@@ -2116,45 +2116,45 @@ discard block |
||
2116 | 2116 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2117 | 2117 | * @return int ID of new row inserted, or FALSE on failure |
2118 | 2118 | */ |
2119 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2119 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2120 | 2120 | global $wpdb; |
2121 | 2121 | $insertion_col_n_values = array(); |
2122 | 2122 | $format_for_insertion = array(); |
2123 | 2123 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2124 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2124 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2125 | 2125 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2126 | - if($field_obj->is_auto_increment()){ |
|
2126 | + if ($field_obj->is_auto_increment()) { |
|
2127 | 2127 | continue; |
2128 | 2128 | } |
2129 | 2129 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2130 | 2130 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2131 | - if( $prepared_value !== NULL ){ |
|
2132 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2131 | + if ($prepared_value !== NULL) { |
|
2132 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2133 | 2133 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2134 | 2134 | } |
2135 | 2135 | } |
2136 | 2136 | |
2137 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2137 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2138 | 2138 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2139 | 2139 | //so add the fk to the main table as a column |
2140 | 2140 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2141 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2141 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2142 | 2142 | } |
2143 | 2143 | //insert the new entry |
2144 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2145 | - if( $result === false ) { |
|
2144 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2145 | + if ($result === false) { |
|
2146 | 2146 | return false; |
2147 | 2147 | } |
2148 | 2148 | //ok, now what do we return for the ID of the newly-inserted thing? |
2149 | - if($this->has_primary_key_field()){ |
|
2150 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2149 | + if ($this->has_primary_key_field()) { |
|
2150 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2151 | 2151 | return $wpdb->insert_id; |
2152 | - }else{ |
|
2152 | + } else { |
|
2153 | 2153 | //it's not an auto-increment primary key, so |
2154 | 2154 | //it must have been supplied |
2155 | 2155 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2156 | 2156 | } |
2157 | - }else{ |
|
2157 | + } else { |
|
2158 | 2158 | //we can't return a primary key because there is none. instead return |
2159 | 2159 | //a unique string indicating this model |
2160 | 2160 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2169,15 +2169,15 @@ discard block |
||
2169 | 2169 | * @param array $fields_n_values |
2170 | 2170 | * @return mixed string|int|float depending on what the table column will be expecting |
2171 | 2171 | */ |
2172 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2172 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2173 | 2173 | //if this field doesn't allow nullable, don't allow it |
2174 | - if( ! $field_obj->is_nullable() && ( |
|
2175 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2176 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2177 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2174 | + if ( ! $field_obj->is_nullable() && ( |
|
2175 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2176 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2177 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2178 | 2178 | } |
2179 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2180 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2179 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2180 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2181 | 2181 | } |
2182 | 2182 | |
2183 | 2183 | |
@@ -2189,9 +2189,9 @@ discard block |
||
2189 | 2189 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2190 | 2190 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2191 | 2191 | */ |
2192 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2193 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2194 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2192 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2193 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2194 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2195 | 2195 | /** @noinspection PhpMissingBreakStatementInspection */ |
2196 | 2196 | case self::not_prepared_by_model_object: |
2197 | 2197 | $value = $field->prepare_for_set($value); |
@@ -2202,7 +2202,7 @@ discard block |
||
2202 | 2202 | //leave the value alone |
2203 | 2203 | } |
2204 | 2204 | return $value; |
2205 | - }else{ |
|
2205 | + } else { |
|
2206 | 2206 | return $value; |
2207 | 2207 | } |
2208 | 2208 | } |
@@ -2212,13 +2212,13 @@ discard block |
||
2212 | 2212 | * @return EE_Primary_Table |
2213 | 2213 | * @throws EE_Error |
2214 | 2214 | */ |
2215 | - protected function _get_main_table(){ |
|
2216 | - foreach($this->_tables as $table){ |
|
2217 | - if($table instanceof EE_Primary_Table){ |
|
2215 | + protected function _get_main_table() { |
|
2216 | + foreach ($this->_tables as $table) { |
|
2217 | + if ($table instanceof EE_Primary_Table) { |
|
2218 | 2218 | return $table; |
2219 | 2219 | } |
2220 | 2220 | } |
2221 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2221 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2222 | 2222 | } |
2223 | 2223 | |
2224 | 2224 | /** |
@@ -2237,7 +2237,7 @@ discard block |
||
2237 | 2237 | */ |
2238 | 2238 | public function second_table() { |
2239 | 2239 | // grab second table from tables array |
2240 | - $second_table = end( $this->_tables ); |
|
2240 | + $second_table = end($this->_tables); |
|
2241 | 2241 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2242 | 2242 | } |
2243 | 2243 | |
@@ -2250,8 +2250,8 @@ discard block |
||
2250 | 2250 | * @param string $table_alias |
2251 | 2251 | * @return EE_Primary_Table | EE_Secondary_Table |
2252 | 2252 | */ |
2253 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2254 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2253 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2254 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2255 | 2255 | } |
2256 | 2256 | |
2257 | 2257 | |
@@ -2260,10 +2260,10 @@ discard block |
||
2260 | 2260 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2261 | 2261 | * @return EE_Secondary_Table[] |
2262 | 2262 | */ |
2263 | - protected function _get_other_tables(){ |
|
2264 | - $other_tables =array(); |
|
2265 | - foreach($this->_tables as $table_alias => $table){ |
|
2266 | - if($table instanceof EE_Secondary_Table){ |
|
2263 | + protected function _get_other_tables() { |
|
2264 | + $other_tables = array(); |
|
2265 | + foreach ($this->_tables as $table_alias => $table) { |
|
2266 | + if ($table instanceof EE_Secondary_Table) { |
|
2267 | 2267 | $other_tables[$table_alias] = $table; |
2268 | 2268 | } |
2269 | 2269 | } |
@@ -2275,7 +2275,7 @@ discard block |
||
2275 | 2275 | * @param string $table_alias, array key in EEM_Base::_tables |
2276 | 2276 | * @return EE_Model_Field_Base[] |
2277 | 2277 | */ |
2278 | - function _get_fields_for_table($table_alias){ |
|
2278 | + function _get_fields_for_table($table_alias) { |
|
2279 | 2279 | return $this->_fields[$table_alias]; |
2280 | 2280 | } |
2281 | 2281 | |
@@ -2287,29 +2287,29 @@ discard block |
||
2287 | 2287 | * @param array $query_params like EEM_Base::get_all's $query_parameters['where'] |
2288 | 2288 | * @return EE_Model_Query_Info_Carrier |
2289 | 2289 | */ |
2290 | - function _extract_related_models_from_query($query_params){ |
|
2290 | + function _extract_related_models_from_query($query_params) { |
|
2291 | 2291 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2292 | - if(array_key_exists(0,$query_params)){ |
|
2293 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0); |
|
2294 | - } |
|
2295 | - if(array_key_exists('group_by', $query_params)){ |
|
2296 | - if(is_array($query_params['group_by'])){ |
|
2297 | - $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
|
2298 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2299 | - $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
|
2292 | + if (array_key_exists(0, $query_params)) { |
|
2293 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2294 | + } |
|
2295 | + if (array_key_exists('group_by', $query_params)) { |
|
2296 | + if (is_array($query_params['group_by'])) { |
|
2297 | + $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2298 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2299 | + $this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2300 | 2300 | } |
2301 | 2301 | } |
2302 | - if(array_key_exists('having',$query_params)){ |
|
2303 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
|
2302 | + if (array_key_exists('having', $query_params)) { |
|
2303 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having'); |
|
2304 | 2304 | } |
2305 | - if(array_key_exists('order_by', $query_params)){ |
|
2306 | - if ( is_array( $query_params['order_by'] ) ) |
|
2307 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2308 | - elseif( ! empty( $query_params['order_by'] )) |
|
2309 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2305 | + if (array_key_exists('order_by', $query_params)) { |
|
2306 | + if (is_array($query_params['order_by'])) |
|
2307 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2308 | + elseif ( ! empty($query_params['order_by'])) |
|
2309 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2310 | 2310 | } |
2311 | - if(array_key_exists('force_join', $query_params)){ |
|
2312 | - $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
|
2311 | + if (array_key_exists('force_join', $query_params)) { |
|
2312 | + $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join'); |
|
2313 | 2313 | } |
2314 | 2314 | return $query_info_carrier; |
2315 | 2315 | } |
@@ -2322,34 +2322,34 @@ discard block |
||
2322 | 2322 | * @throws EE_Error |
2323 | 2323 | * @return \EE_Model_Query_Info_Carrier |
2324 | 2324 | */ |
2325 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2326 | - if (!empty($sub_query_params)){ |
|
2325 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2326 | + if ( ! empty($sub_query_params)) { |
|
2327 | 2327 | $sub_query_params = (array) $sub_query_params; |
2328 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2328 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2329 | 2329 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2330 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2330 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2331 | 2331 | |
2332 | 2332 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2333 | 2333 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2334 | 2334 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2335 | 2335 | //of array('Registration.TXN_ID'=>23) |
2336 | 2336 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2337 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2338 | - if (! is_array($possibly_array_of_params)){ |
|
2337 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2338 | + if ( ! is_array($possibly_array_of_params)) { |
|
2339 | 2339 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2340 | - $param,$possibly_array_of_params)); |
|
2341 | - }else{ |
|
2342 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2340 | + $param, $possibly_array_of_params)); |
|
2341 | + } else { |
|
2342 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2343 | 2343 | } |
2344 | - }elseif($query_param_type === 0 //ie WHERE |
|
2344 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2345 | 2345 | && is_array($possibly_array_of_params) |
2346 | 2346 | && isset($possibly_array_of_params[2]) |
2347 | - && $possibly_array_of_params[2] == true){ |
|
2347 | + && $possibly_array_of_params[2] == true) { |
|
2348 | 2348 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2349 | 2349 | //indicating that $possible_array_of_params[1] is actually a field name, |
2350 | 2350 | //from which we should extract query parameters! |
2351 | - if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){ |
|
2352 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2351 | + if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) { |
|
2352 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2353 | 2353 | } |
2354 | 2354 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2355 | 2355 | } |
@@ -2368,14 +2368,14 @@ discard block |
||
2368 | 2368 | * @throws EE_Error |
2369 | 2369 | * @return \EE_Model_Query_Info_Carrier |
2370 | 2370 | */ |
2371 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2372 | - if (!empty($sub_query_params)){ |
|
2373 | - if(!is_array($sub_query_params)){ |
|
2374 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2371 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2372 | + if ( ! empty($sub_query_params)) { |
|
2373 | + if ( ! is_array($sub_query_params)) { |
|
2374 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2375 | 2375 | } |
2376 | - foreach($sub_query_params as $param){ |
|
2376 | + foreach ($sub_query_params as $param) { |
|
2377 | 2377 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2378 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2378 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2379 | 2379 | } |
2380 | 2380 | } |
2381 | 2381 | return $model_query_info_carrier; |
@@ -2394,81 +2394,81 @@ discard block |
||
2394 | 2394 | * @throws EE_Error |
2395 | 2395 | * @return EE_Model_Query_Info_Carrier |
2396 | 2396 | */ |
2397 | - function _create_model_query_info_carrier($query_params){ |
|
2398 | - if( ! is_array( $query_params ) ){ |
|
2399 | - EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2397 | + function _create_model_query_info_carrier($query_params) { |
|
2398 | + if ( ! is_array($query_params)) { |
|
2399 | + EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2400 | 2400 | $query_params = array(); |
2401 | 2401 | } |
2402 | - if( isset( $query_params[0] ) ) { |
|
2402 | + if (isset($query_params[0])) { |
|
2403 | 2403 | $where_query_params = $query_params[0]; |
2404 | - }else{ |
|
2404 | + } else { |
|
2405 | 2405 | $where_query_params = array(); |
2406 | 2406 | } |
2407 | 2407 | //first check if we should alter the query to account for caps or not |
2408 | 2408 | //because the caps might require us to do extra joins |
2409 | - if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) { |
|
2410 | - $query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) ); |
|
2409 | + if (isset($query_params['caps']) && $query_params['caps'] != 'none') { |
|
2410 | + $query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps'])); |
|
2411 | 2411 | } |
2412 | 2412 | $query_object = $this->_extract_related_models_from_query($query_params); |
2413 | 2413 | |
2414 | 2414 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2415 | - foreach($where_query_params as $key => $value){ |
|
2416 | - if(is_int($key)){ |
|
2417 | - throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this))); |
|
2415 | + foreach ($where_query_params as $key => $value) { |
|
2416 | + if (is_int($key)) { |
|
2417 | + throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this))); |
|
2418 | 2418 | } |
2419 | 2419 | } |
2420 | - if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
|
2420 | + if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) { |
|
2421 | 2421 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2422 | - }else{ |
|
2422 | + } else { |
|
2423 | 2423 | $use_default_where_conditions = 'all'; |
2424 | 2424 | } |
2425 | - $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
|
2426 | - $query_object->set_where_sql( $this->_construct_where_clause($where_query_params)); |
|
2425 | + $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params); |
|
2426 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2427 | 2427 | |
2428 | 2428 | |
2429 | 2429 | //if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. So we need to setup a subquery and use that for the main join. Note for now this only works on the primary table for the model. So for instance, you could set the limit array like this: |
2430 | 2430 | //array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2431 | - if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) { |
|
2432 | - $query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) ); |
|
2431 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2432 | + $query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1])); |
|
2433 | 2433 | } |
2434 | 2434 | |
2435 | 2435 | |
2436 | 2436 | //set limit |
2437 | - if(array_key_exists('limit',$query_params)){ |
|
2438 | - if(is_array($query_params['limit'])){ |
|
2439 | - if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){ |
|
2440 | - $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2437 | + if (array_key_exists('limit', $query_params)) { |
|
2438 | + if (is_array($query_params['limit'])) { |
|
2439 | + if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) { |
|
2440 | + $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2441 | 2441 | throw new EE_Error($e."|".$e); |
2442 | 2442 | } |
2443 | 2443 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2444 | 2444 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2445 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2445 | + }elseif ( ! empty ($query_params['limit'])) { |
|
2446 | 2446 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2447 | 2447 | } |
2448 | 2448 | } |
2449 | 2449 | //set order by |
2450 | - if(array_key_exists('order_by',$query_params)){ |
|
2451 | - if(is_array($query_params['order_by'])){ |
|
2450 | + if (array_key_exists('order_by', $query_params)) { |
|
2451 | + if (is_array($query_params['order_by'])) { |
|
2452 | 2452 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2453 | 2453 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2454 | 2454 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2455 | - if(array_key_exists('order', $query_params)){ |
|
2455 | + if (array_key_exists('order', $query_params)) { |
|
2456 | 2456 | throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"), |
2457 | - get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order'])); |
|
2457 | + get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order'])); |
|
2458 | 2458 | } |
2459 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by'); |
|
2459 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by'); |
|
2460 | 2460 | //assume it's an array of fields to order by |
2461 | 2461 | $order_array = array(); |
2462 | - foreach($query_params['order_by'] as $field_name_to_order_by => $order){ |
|
2462 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2463 | 2463 | $order = $this->_extract_order($order); |
2464 | 2464 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2465 | 2465 | } |
2466 | - $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
|
2467 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2468 | - $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
|
2469 | - if(isset($query_params['order'])){ |
|
2466 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2467 | + }elseif ( ! empty ($query_params['order_by'])) { |
|
2468 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']); |
|
2469 | + if (isset($query_params['order'])) { |
|
2470 | 2470 | $order = $this->_extract_order($query_params['order']); |
2471 | - }else{ |
|
2471 | + } else { |
|
2472 | 2472 | $order = 'DESC'; |
2473 | 2473 | } |
2474 | 2474 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2476,46 +2476,46 @@ discard block |
||
2476 | 2476 | } |
2477 | 2477 | |
2478 | 2478 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2479 | - if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){ |
|
2479 | + if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) { |
|
2480 | 2480 | $pk_field = $this->get_primary_key_field(); |
2481 | 2481 | $order = $this->_extract_order($query_params['order']); |
2482 | 2482 | $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
2483 | 2483 | } |
2484 | 2484 | |
2485 | 2485 | //set group by |
2486 | - if(array_key_exists('group_by',$query_params)){ |
|
2487 | - if(is_array($query_params['group_by'])){ |
|
2486 | + if (array_key_exists('group_by', $query_params)) { |
|
2487 | + if (is_array($query_params['group_by'])) { |
|
2488 | 2488 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2489 | 2489 | $group_by_array = array(); |
2490 | - foreach($query_params['group_by'] as $field_name_to_group_by){ |
|
2490 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2491 | 2491 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2492 | 2492 | } |
2493 | - $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
|
2494 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2493 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2494 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2495 | 2495 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2496 | 2496 | } |
2497 | 2497 | } |
2498 | 2498 | //set having |
2499 | - if(array_key_exists('having',$query_params) && $query_params['having']){ |
|
2500 | - $query_object->set_having_sql( $this->_construct_having_clause($query_params['having'])); |
|
2499 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2500 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2501 | 2501 | } |
2502 | 2502 | |
2503 | 2503 | //now, just verify they didn't pass anything wack |
2504 | - foreach($query_params as $query_key => $query_value){ |
|
2505 | - if( ! in_array($query_key,$this->_allowed_query_params,true)){ |
|
2504 | + foreach ($query_params as $query_key => $query_value) { |
|
2505 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2506 | 2506 | throw new EE_Error( |
2507 | 2507 | sprintf( |
2508 | - __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'), |
|
2508 | + __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'), |
|
2509 | 2509 | $query_key, |
2510 | 2510 | get_class($this), |
2511 | 2511 | // print_r( $this->_allowed_query_params, TRUE ) |
2512 | - implode( ',', $this->_allowed_query_params ) |
|
2512 | + implode(',', $this->_allowed_query_params) |
|
2513 | 2513 | ) |
2514 | 2514 | ); |
2515 | 2515 | } |
2516 | 2516 | } |
2517 | 2517 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2518 | - if ( empty( $main_model_join_sql ) ) |
|
2518 | + if (empty($main_model_join_sql)) |
|
2519 | 2519 | $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
2520 | 2520 | return $query_object; |
2521 | 2521 | } |
@@ -2526,17 +2526,17 @@ discard block |
||
2526 | 2526 | * @param string $context one of EEM_Base::valid_cap_contexts() |
2527 | 2527 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2528 | 2528 | */ |
2529 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2530 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2529 | + public function caps_where_conditions($context = self::caps_read) { |
|
2530 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2531 | 2531 | $cap_where_conditions = array(); |
2532 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2532 | + $cap_restrictions = $this->caps_missing($context); |
|
2533 | 2533 | /** |
2534 | 2534 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2535 | 2535 | */ |
2536 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2537 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2536 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2537 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2538 | 2538 | } |
2539 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2539 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2540 | 2540 | } |
2541 | 2541 | |
2542 | 2542 | /** |
@@ -2546,11 +2546,11 @@ discard block |
||
2546 | 2546 | * @return string either ASC, asc, DESC or desc |
2547 | 2547 | * @throws EE_Error |
2548 | 2548 | */ |
2549 | - private function _extract_order($should_be_order_string){ |
|
2550 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2549 | + private function _extract_order($should_be_order_string) { |
|
2550 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2551 | 2551 | return $should_be_order_string; |
2552 | - }else{ |
|
2553 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
2552 | + } else { |
|
2553 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
2554 | 2554 | } |
2555 | 2555 | } |
2556 | 2556 | |
@@ -2568,19 +2568,19 @@ discard block |
||
2568 | 2568 | * @throws EE_Error |
2569 | 2569 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2570 | 2570 | */ |
2571 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
2572 | - $allowed_used_default_where_conditions_values = array('all','this_model_only', 'other_models_only','none'); |
|
2573 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2574 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
2571 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
2572 | + $allowed_used_default_where_conditions_values = array('all', 'this_model_only', 'other_models_only', 'none'); |
|
2573 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2574 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
2575 | 2575 | } |
2576 | - if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
|
2576 | + if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) { |
|
2577 | 2577 | $universal_query_params = $this->_get_default_where_conditions(); |
2578 | - }else{ |
|
2578 | + } else { |
|
2579 | 2579 | $universal_query_params = array(); |
2580 | 2580 | } |
2581 | 2581 | |
2582 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
2583 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2582 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2583 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2584 | 2584 | $related_model = $this->get_related_model_obj($model_name); |
2585 | 2585 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2586 | 2586 | |
@@ -2607,22 +2607,22 @@ discard block |
||
2607 | 2607 | * @param string $model_relation_path like 'Transaction.Payment.' |
2608 | 2608 | * @return array like EEM_Base::get_all's $query_params[0] |
2609 | 2609 | */ |
2610 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
2610 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
2611 | 2611 | $null_friendly_where_conditions = array(); |
2612 | 2612 | $none_overridden = true; |
2613 | 2613 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
2614 | 2614 | |
2615 | - foreach($default_where_conditions as $key => $val){ |
|
2616 | - if( isset($provided_where_conditions[$key])){ |
|
2615 | + foreach ($default_where_conditions as $key => $val) { |
|
2616 | + if (isset($provided_where_conditions[$key])) { |
|
2617 | 2617 | $none_overridden = false; |
2618 | - }else{ |
|
2618 | + } else { |
|
2619 | 2619 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2620 | 2620 | } |
2621 | 2621 | } |
2622 | - if( $none_overridden && $default_where_conditions){ |
|
2623 | - if($model->has_primary_key_field()){ |
|
2622 | + if ($none_overridden && $default_where_conditions) { |
|
2623 | + if ($model->has_primary_key_field()) { |
|
2624 | 2624 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2625 | - }else{ |
|
2625 | + } else { |
|
2626 | 2626 | //@todo NO PK, use other defaults |
2627 | 2627 | } |
2628 | 2628 | } |
@@ -2637,8 +2637,8 @@ discard block |
||
2637 | 2637 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2638 | 2638 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2639 | 2639 | */ |
2640 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
2641 | - if ( $this->_ignore_where_strategy ) |
|
2640 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
2641 | + if ($this->_ignore_where_strategy) |
|
2642 | 2642 | return array(); |
2643 | 2643 | |
2644 | 2644 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2649,13 +2649,13 @@ discard block |
||
2649 | 2649 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2650 | 2650 | * @return string |
2651 | 2651 | */ |
2652 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2652 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2653 | 2653 | $selects = $this->_get_columns_to_select_for_this_model(); |
2654 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
2654 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
2655 | 2655 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
2656 | 2656 | $selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain)); |
2657 | 2657 | } |
2658 | - return implode(", ",$selects); |
|
2658 | + return implode(", ", $selects); |
|
2659 | 2659 | } |
2660 | 2660 | |
2661 | 2661 | /** |
@@ -2664,19 +2664,19 @@ discard block |
||
2664 | 2664 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
2665 | 2665 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
2666 | 2666 | */ |
2667 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
2667 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
2668 | 2668 | $fields = $this->field_settings(); |
2669 | 2669 | $selects = array(); |
2670 | 2670 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
2671 | - foreach($fields as $field_obj){ |
|
2672 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2671 | + foreach ($fields as $field_obj) { |
|
2672 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2673 | 2673 | } |
2674 | 2674 | //make sure we are also getting the PKs of each table |
2675 | 2675 | $tables = $this->get_tables(); |
2676 | - if(count($tables) > 1){ |
|
2677 | - foreach($tables as $table_obj){ |
|
2678 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
2679 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
2676 | + if (count($tables) > 1) { |
|
2677 | + foreach ($tables as $table_obj) { |
|
2678 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
2679 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
2680 | 2680 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
2681 | 2681 | } |
2682 | 2682 | } |
@@ -2700,66 +2700,66 @@ discard block |
||
2700 | 2700 | * @throws EE_Error |
2701 | 2701 | * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it |
2702 | 2702 | */ |
2703 | - private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){ |
|
2704 | - if($original_query_param == NULL){ |
|
2703 | + private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) { |
|
2704 | + if ($original_query_param == NULL) { |
|
2705 | 2705 | $original_query_param = $query_param; |
2706 | 2706 | } |
2707 | 2707 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
2708 | 2708 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
2709 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
2710 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
2709 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
2710 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
2711 | 2711 | //check to see if we have a field on this model |
2712 | 2712 | $this_model_fields = $this->field_settings(true); |
2713 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
2714 | - if($allow_fields){ |
|
2713 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
2714 | + if ($allow_fields) { |
|
2715 | 2715 | return; |
2716 | - }else{ |
|
2716 | + } else { |
|
2717 | 2717 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
2718 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2718 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2719 | 2719 | } |
2720 | 2720 | } |
2721 | 2721 | //check if this is a special logic query param |
2722 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
2723 | - if($allow_logic_query_params){ |
|
2722 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
2723 | + if ($allow_logic_query_params) { |
|
2724 | 2724 | return; |
2725 | - }else{ |
|
2725 | + } else { |
|
2726 | 2726 | throw new EE_Error( |
2727 | 2727 | sprintf( |
2728 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
2729 | - implode( '", "', $this->_logic_query_param_keys ), |
|
2730 | - $query_param , |
|
2731 | - get_class( $this ), |
|
2728 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
2729 | + implode('", "', $this->_logic_query_param_keys), |
|
2730 | + $query_param, |
|
2731 | + get_class($this), |
|
2732 | 2732 | '<br />', |
2733 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
2733 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
2734 | 2734 | ) |
2735 | 2735 | ); |
2736 | 2736 | } |
2737 | 2737 | } |
2738 | 2738 | |
2739 | 2739 | //check if it's a custom selection |
2740 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2740 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
2741 | 2741 | return; |
2742 | 2742 | } |
2743 | 2743 | |
2744 | 2744 | //check if has a model name at the beginning |
2745 | 2745 | //and |
2746 | 2746 | //check if it's a field on a related model |
2747 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
2748 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
2749 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2747 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
2748 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
2749 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2750 | 2750 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
2751 | - if($query_param == ''){ |
|
2751 | + if ($query_param == '') { |
|
2752 | 2752 | //nothing left to $query_param |
2753 | 2753 | //we should actually end in a field name, not a model like this! |
2754 | 2754 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2755 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
2756 | - }else{ |
|
2755 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
2756 | + } else { |
|
2757 | 2757 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2758 | 2758 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2759 | 2759 | return; |
2760 | 2760 | } |
2761 | - }elseif($query_param == $valid_related_model_name){ |
|
2762 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2761 | + }elseif ($query_param == $valid_related_model_name) { |
|
2762 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2763 | 2763 | return; |
2764 | 2764 | } |
2765 | 2765 | } |
@@ -2769,7 +2769,7 @@ discard block |
||
2769 | 2769 | //and we previously confirmed it wasn't a logic query param or field on the current model |
2770 | 2770 | //it's wack, that's what it is |
2771 | 2771 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
2772 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2772 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2773 | 2773 | |
2774 | 2774 | } |
2775 | 2775 | |
@@ -2786,26 +2786,26 @@ discard block |
||
2786 | 2786 | * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table) |
2787 | 2787 | * @return void |
2788 | 2788 | */ |
2789 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
2789 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
2790 | 2790 | $relation_obj = $this->related_settings_for($model_name); |
2791 | 2791 | |
2792 | 2792 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
2793 | 2793 | //check if the relation is HABTM, because then we're essentially doing two joins |
2794 | 2794 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
2795 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
2795 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
2796 | 2796 | $join_model_obj = $relation_obj->get_join_model(); |
2797 | 2797 | //replace the model specified with the join model for this relation chain, whi |
2798 | 2798 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
2799 | 2799 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2800 | 2800 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
2801 | 2801 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
2802 | - $passed_in_query_info->merge( $new_query_info ); |
|
2802 | + $passed_in_query_info->merge($new_query_info); |
|
2803 | 2803 | } |
2804 | 2804 | //now just join to the other table pointed to by the relation object, and add its data types |
2805 | 2805 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2806 | 2806 | array($model_relation_chain=>$model_name), |
2807 | 2807 | $relation_obj->get_join_statement($model_relation_chain)); |
2808 | - $passed_in_query_info->merge( $new_query_info ); |
|
2808 | + $passed_in_query_info->merge($new_query_info); |
|
2809 | 2809 | } |
2810 | 2810 | |
2811 | 2811 | |
@@ -2814,11 +2814,11 @@ discard block |
||
2814 | 2814 | * @param array $where_params like EEM_Base::get_all |
2815 | 2815 | * @return string of SQL |
2816 | 2816 | */ |
2817 | - private function _construct_where_clause($where_params){ |
|
2817 | + private function _construct_where_clause($where_params) { |
|
2818 | 2818 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
2819 | - if($SQL){ |
|
2820 | - return " WHERE ". $SQL; |
|
2821 | - }else{ |
|
2819 | + if ($SQL) { |
|
2820 | + return " WHERE ".$SQL; |
|
2821 | + } else { |
|
2822 | 2822 | return ''; |
2823 | 2823 | } |
2824 | 2824 | } |
@@ -2829,11 +2829,11 @@ discard block |
||
2829 | 2829 | * @param array $having_params |
2830 | 2830 | * @return string |
2831 | 2831 | */ |
2832 | - private function _construct_having_clause($having_params){ |
|
2832 | + private function _construct_having_clause($having_params) { |
|
2833 | 2833 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
2834 | - if($SQL){ |
|
2835 | - return " HAVING ". $SQL; |
|
2836 | - }else{ |
|
2834 | + if ($SQL) { |
|
2835 | + return " HAVING ".$SQL; |
|
2836 | + } else { |
|
2837 | 2837 | return ''; |
2838 | 2838 | } |
2839 | 2839 | |
@@ -2847,17 +2847,17 @@ discard block |
||
2847 | 2847 | * @return EE_Model_Field_Base |
2848 | 2848 | * @throws EE_Error |
2849 | 2849 | */ |
2850 | - protected function _get_field_on_model($field_name,$model_name){ |
|
2850 | + protected function _get_field_on_model($field_name, $model_name) { |
|
2851 | 2851 | $model_class = 'EEM_'.$model_name; |
2852 | 2852 | $model_filepath = $model_class.".model.php"; |
2853 | - EE_Registry::instance()->load_helper( 'File' ); |
|
2854 | - if ( is_readable($model_filepath)){ |
|
2853 | + EE_Registry::instance()->load_helper('File'); |
|
2854 | + if (is_readable($model_filepath)) { |
|
2855 | 2855 | require_once($model_filepath); |
2856 | - $model_instance=call_user_func($model_name."::instance"); |
|
2856 | + $model_instance = call_user_func($model_name."::instance"); |
|
2857 | 2857 | /* @var $model_instance EEM_Base */ |
2858 | 2858 | return $model_instance->field_settings_for($field_name); |
2859 | - }else{ |
|
2860 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
2859 | + } else { |
|
2860 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
2861 | 2861 | } |
2862 | 2862 | } |
2863 | 2863 | |
@@ -2870,43 +2870,43 @@ discard block |
||
2870 | 2870 | * @throws EE_Error |
2871 | 2871 | * @return string of SQL |
2872 | 2872 | */ |
2873 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
2874 | - $where_clauses=array(); |
|
2875 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
2876 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
2877 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
2878 | - switch($query_param){ |
|
2873 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
2874 | + $where_clauses = array(); |
|
2875 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
2876 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
2877 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
2878 | + switch ($query_param) { |
|
2879 | 2879 | case 'not': |
2880 | 2880 | case 'NOT': |
2881 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
2881 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
2882 | 2882 | break; |
2883 | 2883 | case 'and': |
2884 | 2884 | case 'AND': |
2885 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
2885 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
2886 | 2886 | break; |
2887 | 2887 | case 'or': |
2888 | 2888 | case 'OR': |
2889 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
2889 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
2890 | 2890 | break; |
2891 | 2891 | } |
2892 | - }else{ |
|
2892 | + } else { |
|
2893 | 2893 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
2894 | 2894 | |
2895 | 2895 | //if it's not a normal field, maybe it's a custom selection? |
2896 | - if( ! $field_obj){ |
|
2897 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
2896 | + if ( ! $field_obj) { |
|
2897 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
2898 | 2898 | $field_obj = $this->_custom_selections[$query_param][1]; |
2899 | - }else{ |
|
2900 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
2899 | + } else { |
|
2900 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
2901 | 2901 | } |
2902 | 2902 | } |
2903 | 2903 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
2904 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
2904 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
2905 | 2905 | } |
2906 | 2906 | } |
2907 | - if($where_clauses){ |
|
2908 | - $SQL = implode($glue,$where_clauses); |
|
2909 | - }else{ |
|
2907 | + if ($where_clauses) { |
|
2908 | + $SQL = implode($glue, $where_clauses); |
|
2909 | + } else { |
|
2910 | 2910 | $SQL = ''; |
2911 | 2911 | } |
2912 | 2912 | return $SQL; |
@@ -2920,18 +2920,18 @@ discard block |
||
2920 | 2920 | * @throws EE_Error |
2921 | 2921 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
2922 | 2922 | */ |
2923 | - private function _deduce_column_name_from_query_param($query_param){ |
|
2923 | + private function _deduce_column_name_from_query_param($query_param) { |
|
2924 | 2924 | $field = $this->_deduce_field_from_query_param($query_param); |
2925 | 2925 | |
2926 | - if( $field ){ |
|
2927 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
2928 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
2929 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2926 | + if ($field) { |
|
2927 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
2928 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
2929 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
2930 | 2930 | //maybe it's custom selection item? |
2931 | 2931 | //if so, just use it as the "column name" |
2932 | 2932 | return $query_param; |
2933 | - }else{ |
|
2934 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
2933 | + } else { |
|
2934 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
2935 | 2935 | } |
2936 | 2936 | } |
2937 | 2937 | |
@@ -2943,11 +2943,11 @@ discard block |
||
2943 | 2943 | * @param string $condition_query_param_key |
2944 | 2944 | * @return string |
2945 | 2945 | */ |
2946 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
2946 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
2947 | 2947 | $pos_of_star = strpos($condition_query_param_key, '*'); |
2948 | - if($pos_of_star === FALSE){ |
|
2948 | + if ($pos_of_star === FALSE) { |
|
2949 | 2949 | return $condition_query_param_key; |
2950 | - }else{ |
|
2950 | + } else { |
|
2951 | 2951 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
2952 | 2952 | return $condition_query_param_sans_star; |
2953 | 2953 | } |
@@ -2962,54 +2962,54 @@ discard block |
||
2962 | 2962 | * @throws EE_Error |
2963 | 2963 | * @return string |
2964 | 2964 | */ |
2965 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
2966 | - if(is_array( $op_and_value )){ |
|
2965 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
2966 | + if (is_array($op_and_value)) { |
|
2967 | 2967 | $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
2968 | - if( ! $operator){ |
|
2968 | + if ( ! $operator) { |
|
2969 | 2969 | $php_array_like_string = array(); |
2970 | - foreach($op_and_value as $key => $value){ |
|
2970 | + foreach ($op_and_value as $key => $value) { |
|
2971 | 2971 | $php_array_like_string[] = "$key=>$value"; |
2972 | 2972 | } |
2973 | - throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
|
2973 | + throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string))); |
|
2974 | 2974 | } |
2975 | 2975 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
2976 | - }else{ |
|
2976 | + } else { |
|
2977 | 2977 | $operator = '='; |
2978 | 2978 | $value = $op_and_value; |
2979 | 2979 | } |
2980 | 2980 | |
2981 | 2981 | //check to see if the value is actually another field |
2982 | - if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
|
2982 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
2983 | 2983 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
2984 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
2984 | + }elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
2985 | 2985 | //in this case, the value should be an array, or at least a comma-separated list |
2986 | 2986 | //it will need to handle a little differently |
2987 | 2987 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
2988 | 2988 | //note: $cleaned_value has already been run through $wpdb->prepare() |
2989 | 2989 | return $operator.SP.$cleaned_value; |
2990 | - } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
2990 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
2991 | 2991 | //the value should be an array with count of two. |
2992 | - if ( count($value) !== 2 ) |
|
2993 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
2994 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
2992 | + if (count($value) !== 2) |
|
2993 | + throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN")); |
|
2994 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
2995 | 2995 | return $operator.SP.$cleaned_value; |
2996 | - } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
|
2997 | - if($value != NULL){ |
|
2998 | - throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
|
2996 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
2997 | + if ($value != NULL) { |
|
2998 | + throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator)); |
|
2999 | 2999 | } |
3000 | 3000 | return $operator; |
3001 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3001 | + }elseif ($operator == 'LIKE' && ! is_array($value)) { |
|
3002 | 3002 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3003 | 3003 | //remove other junk. So just treat it as a string. |
3004 | 3004 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3005 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3006 | - return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
|
3007 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3008 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
|
3009 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3010 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
|
3011 | - }else{ |
|
3012 | - throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3005 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3006 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3007 | + }elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3008 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator)); |
|
3009 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3010 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator)); |
|
3011 | + } else { |
|
3012 | + throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3013 | 3013 | } |
3014 | 3014 | } |
3015 | 3015 | |
@@ -3021,12 +3021,12 @@ discard block |
||
3021 | 3021 | * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s' |
3022 | 3022 | * @return string |
3023 | 3023 | */ |
3024 | - function _construct_between_value( $values, $field_obj ) { |
|
3024 | + function _construct_between_value($values, $field_obj) { |
|
3025 | 3025 | $cleaned_values = array(); |
3026 | - foreach ( $values as $value ) { |
|
3027 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3026 | + foreach ($values as $value) { |
|
3027 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3028 | 3028 | } |
3029 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3029 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3030 | 3030 | } |
3031 | 3031 | |
3032 | 3032 | |
@@ -3042,26 +3042,26 @@ discard block |
||
3042 | 3042 | * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d' |
3043 | 3043 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3044 | 3044 | */ |
3045 | - function _construct_in_value($values, $field_obj){ |
|
3045 | + function _construct_in_value($values, $field_obj) { |
|
3046 | 3046 | //check if the value is a CSV list |
3047 | - if(is_string($values)){ |
|
3047 | + if (is_string($values)) { |
|
3048 | 3048 | //in which case, turn it into an array |
3049 | - $values = explode(",",$values); |
|
3049 | + $values = explode(",", $values); |
|
3050 | 3050 | } |
3051 | 3051 | $cleaned_values = array(); |
3052 | - foreach($values as $value){ |
|
3053 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3052 | + foreach ($values as $value) { |
|
3053 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3054 | 3054 | } |
3055 | 3055 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3056 | 3056 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3057 | 3057 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3058 | - if(empty($cleaned_values)){ |
|
3058 | + if (empty($cleaned_values)) { |
|
3059 | 3059 | $all_fields = $this->field_settings(); |
3060 | 3060 | $a_field = array_shift($all_fields); |
3061 | 3061 | $main_table = $this->_get_main_table(); |
3062 | 3062 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3063 | 3063 | } |
3064 | - return "(".implode(",",$cleaned_values).")"; |
|
3064 | + return "(".implode(",", $cleaned_values).")"; |
|
3065 | 3065 | } |
3066 | 3066 | |
3067 | 3067 | |
@@ -3073,16 +3073,16 @@ discard block |
||
3073 | 3073 | * @throws EE_Error |
3074 | 3074 | * @return false|null|string |
3075 | 3075 | */ |
3076 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3076 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3077 | 3077 | /** @type WPDB $wpdb */ |
3078 | 3078 | global $wpdb; |
3079 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3080 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3081 | - }else{//$field_obj should really just be a data type |
|
3082 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3083 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3079 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3080 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3081 | + } else {//$field_obj should really just be a data type |
|
3082 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3083 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3084 | 3084 | } |
3085 | - return $wpdb->prepare($field_obj,$value); |
|
3085 | + return $wpdb->prepare($field_obj, $value); |
|
3086 | 3086 | } |
3087 | 3087 | } |
3088 | 3088 | |
@@ -3094,27 +3094,27 @@ discard block |
||
3094 | 3094 | * @throws EE_Error |
3095 | 3095 | * @return EE_Model_Field_Base |
3096 | 3096 | */ |
3097 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3097 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3098 | 3098 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3099 | 3099 | //which will help us find the database table and column |
3100 | 3100 | |
3101 | - $query_param_parts = explode(".",$query_param_name); |
|
3102 | - if(empty($query_param_parts)){ |
|
3103 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3101 | + $query_param_parts = explode(".", $query_param_name); |
|
3102 | + if (empty($query_param_parts)) { |
|
3103 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3104 | 3104 | } |
3105 | 3105 | $number_of_parts = count($query_param_parts); |
3106 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3107 | - if($number_of_parts == 1){ |
|
3106 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3107 | + if ($number_of_parts == 1) { |
|
3108 | 3108 | $field_name = $last_query_param_part; |
3109 | 3109 | $model_obj = $this; |
3110 | - }else{// $number_of_parts >= 2 |
|
3110 | + } else {// $number_of_parts >= 2 |
|
3111 | 3111 | //the last part is the column name, and there are only 2parts. therefore... |
3112 | 3112 | $field_name = $last_query_param_part; |
3113 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3113 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3114 | 3114 | } |
3115 | - try{ |
|
3115 | + try { |
|
3116 | 3116 | return $model_obj->field_settings_for($field_name); |
3117 | - }catch(EE_Error $e){ |
|
3117 | + } catch (EE_Error $e) { |
|
3118 | 3118 | return null; |
3119 | 3119 | } |
3120 | 3120 | } |
@@ -3128,13 +3128,13 @@ discard block |
||
3128 | 3128 | * @throws EE_Error |
3129 | 3129 | * @return string |
3130 | 3130 | */ |
3131 | - function _get_qualified_column_for_field($field_name){ |
|
3131 | + function _get_qualified_column_for_field($field_name) { |
|
3132 | 3132 | $all_fields = $this->field_settings(); |
3133 | 3133 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3134 | - if($field){ |
|
3134 | + if ($field) { |
|
3135 | 3135 | return $field->get_qualified_column(); |
3136 | - }else{ |
|
3137 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3136 | + } else { |
|
3137 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3138 | 3138 | } |
3139 | 3139 | } |
3140 | 3140 | |
@@ -3148,14 +3148,14 @@ discard block |
||
3148 | 3148 | * @param mixed|string $limit The limit for this select |
3149 | 3149 | * @return string The final select join element for the query. |
3150 | 3150 | */ |
3151 | - function _construct_limit_join_select( $table_alias, $limit ) { |
|
3151 | + function _construct_limit_join_select($table_alias, $limit) { |
|
3152 | 3152 | $SQL = ''; |
3153 | 3153 | |
3154 | - foreach ( $this->_tables as $table_obj ) { |
|
3155 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3156 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3157 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3158 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP; |
|
3154 | + foreach ($this->_tables as $table_obj) { |
|
3155 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3156 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3157 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3158 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3159 | 3159 | } |
3160 | 3160 | } |
3161 | 3161 | return $SQL; |
@@ -3168,7 +3168,7 @@ discard block |
||
3168 | 3168 | * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id" |
3169 | 3169 | * @return string SQL |
3170 | 3170 | */ |
3171 | - function _construct_internal_join(){ |
|
3171 | + function _construct_internal_join() { |
|
3172 | 3172 | $SQL = $this->_get_main_table()->get_table_sql(); |
3173 | 3173 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3174 | 3174 | return $SQL; |
@@ -3189,17 +3189,17 @@ discard block |
||
3189 | 3189 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3190 | 3190 | * @return string |
3191 | 3191 | */ |
3192 | - function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3192 | + function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3193 | 3193 | $SQL = ''; |
3194 | 3194 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3195 | - foreach($this->_tables as $table_obj){ |
|
3196 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3197 | - if($alias_sans_prefix == $table_obj->get_table_alias()){ |
|
3195 | + foreach ($this->_tables as $table_obj) { |
|
3196 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3197 | + if ($alias_sans_prefix == $table_obj->get_table_alias()) { |
|
3198 | 3198 | //so we're joining to this table, meaning the table is already in |
3199 | 3199 | //the FROM statement, BUT the primary table isn't. So we want |
3200 | 3200 | //to add the inverse join sql |
3201 | 3201 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3202 | - }else{ |
|
3202 | + } else { |
|
3203 | 3203 | //just add a regular JOIN to this table from the primary table |
3204 | 3204 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3205 | 3205 | } |
@@ -3213,9 +3213,9 @@ discard block |
||
3213 | 3213 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3214 | 3214 | * @return array |
3215 | 3215 | */ |
3216 | - function _get_data_types(){ |
|
3216 | + function _get_data_types() { |
|
3217 | 3217 | $data_types = array(); |
3218 | - foreach(array_values($this->field_settings()) as $field_obj){ |
|
3218 | + foreach (array_values($this->field_settings()) as $field_obj) { |
|
3219 | 3219 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3220 | 3220 | /** @var $field_obj EE_Model_Field_Base */ |
3221 | 3221 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3231,11 +3231,11 @@ discard block |
||
3231 | 3231 | * @throws EE_Error |
3232 | 3232 | * @return EEM_Base |
3233 | 3233 | */ |
3234 | - function get_related_model_obj($model_name){ |
|
3234 | + function get_related_model_obj($model_name) { |
|
3235 | 3235 | |
3236 | 3236 | $model_classname = "EEM_".$model_name; |
3237 | - if(!class_exists($model_classname)){ |
|
3238 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3237 | + if ( ! class_exists($model_classname)) { |
|
3238 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3239 | 3239 | } |
3240 | 3240 | $model_obj = call_user_func($model_classname."::instance"); |
3241 | 3241 | return $model_obj; |
@@ -3246,7 +3246,7 @@ discard block |
||
3246 | 3246 | * Returns the array of EE_ModelRelations for this model. |
3247 | 3247 | * @return EE_Model_Relation_Base[] |
3248 | 3248 | */ |
3249 | - public function relation_settings(){ |
|
3249 | + public function relation_settings() { |
|
3250 | 3250 | return $this->_model_relations; |
3251 | 3251 | } |
3252 | 3252 | |
@@ -3256,10 +3256,10 @@ discard block |
||
3256 | 3256 | * (Eg, without an event, datetimes have little purpose.) |
3257 | 3257 | * @return EE_Belongs_To_Relation[] |
3258 | 3258 | */ |
3259 | - public function belongs_to_relations(){ |
|
3259 | + public function belongs_to_relations() { |
|
3260 | 3260 | $belongs_to_relations = array(); |
3261 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3262 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3261 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3262 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3263 | 3263 | $belongs_to_relations[$model_name] = $relation_obj; |
3264 | 3264 | } |
3265 | 3265 | } |
@@ -3274,15 +3274,15 @@ discard block |
||
3274 | 3274 | * @throws EE_Error |
3275 | 3275 | * @return EE_Model_Relation_Base |
3276 | 3276 | */ |
3277 | - public function related_settings_for($relation_name){ |
|
3278 | - $relatedModels=$this->relation_settings(); |
|
3279 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3277 | + public function related_settings_for($relation_name) { |
|
3278 | + $relatedModels = $this->relation_settings(); |
|
3279 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3280 | 3280 | throw new EE_Error( |
3281 | 3281 | sprintf( |
3282 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3282 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3283 | 3283 | $relation_name, |
3284 | 3284 | $this->_get_class_name(), |
3285 | - implode( ', ', array_keys( $relatedModels )) |
|
3285 | + implode(', ', array_keys($relatedModels)) |
|
3286 | 3286 | ) |
3287 | 3287 | ); |
3288 | 3288 | } |
@@ -3297,10 +3297,10 @@ discard block |
||
3297 | 3297 | * @throws EE_Error |
3298 | 3298 | * @return EE_Model_Field_Base |
3299 | 3299 | */ |
3300 | - public function field_settings_for($fieldName){ |
|
3301 | - $fieldSettings=$this->field_settings(true); |
|
3302 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3303 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3300 | + public function field_settings_for($fieldName) { |
|
3301 | + $fieldSettings = $this->field_settings(true); |
|
3302 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3303 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3304 | 3304 | } |
3305 | 3305 | return $fieldSettings[$fieldName]; |
3306 | 3306 | } |
@@ -3310,11 +3310,11 @@ discard block |
||
3310 | 3310 | * @param string $fieldName a key in the model's _field_settings array |
3311 | 3311 | * @return boolean |
3312 | 3312 | */ |
3313 | - public function has_field($fieldName){ |
|
3313 | + public function has_field($fieldName) { |
|
3314 | 3314 | $fieldSettings = $this->field_settings(true); |
3315 | - if( isset($fieldSettings[$fieldName])){ |
|
3315 | + if (isset($fieldSettings[$fieldName])) { |
|
3316 | 3316 | return true; |
3317 | - }else{ |
|
3317 | + } else { |
|
3318 | 3318 | return false; |
3319 | 3319 | } |
3320 | 3320 | } |
@@ -3324,11 +3324,11 @@ discard block |
||
3324 | 3324 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3325 | 3325 | * @return boolean |
3326 | 3326 | */ |
3327 | - public function has_relation($relation_name){ |
|
3327 | + public function has_relation($relation_name) { |
|
3328 | 3328 | $relations = $this->relation_settings(); |
3329 | - if(isset($relations[$relation_name])){ |
|
3329 | + if (isset($relations[$relation_name])) { |
|
3330 | 3330 | return true; |
3331 | - }else{ |
|
3331 | + } else { |
|
3332 | 3332 | return false; |
3333 | 3333 | } |
3334 | 3334 | } |
@@ -3340,7 +3340,7 @@ discard block |
||
3340 | 3340 | * @param $field_obj |
3341 | 3341 | * @return EE_Model_Field_Base |
3342 | 3342 | */ |
3343 | - public function is_primary_key_field( $field_obj ){ |
|
3343 | + public function is_primary_key_field($field_obj) { |
|
3344 | 3344 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3345 | 3345 | } |
3346 | 3346 | |
@@ -3352,16 +3352,16 @@ discard block |
||
3352 | 3352 | * @return EE_Model_Field_Base |
3353 | 3353 | * @throws EE_Error |
3354 | 3354 | */ |
3355 | - public function get_primary_key_field(){ |
|
3356 | - if( $this->_primary_key_field === NULL ){ |
|
3357 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3358 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3355 | + public function get_primary_key_field() { |
|
3356 | + if ($this->_primary_key_field === NULL) { |
|
3357 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3358 | + if ($this->is_primary_key_field($field_obj)) { |
|
3359 | 3359 | $this->_primary_key_field = $field_obj; |
3360 | 3360 | break; |
3361 | 3361 | } |
3362 | 3362 | } |
3363 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3364 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3363 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3364 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3365 | 3365 | } |
3366 | 3366 | } |
3367 | 3367 | return $this->_primary_key_field; |
@@ -3374,12 +3374,12 @@ discard block |
||
3374 | 3374 | * Internally does some caching. |
3375 | 3375 | * @return boolean |
3376 | 3376 | */ |
3377 | - public function has_primary_key_field(){ |
|
3378 | - if($this->_has_primary_key_field === null){ |
|
3379 | - try{ |
|
3377 | + public function has_primary_key_field() { |
|
3378 | + if ($this->_has_primary_key_field === null) { |
|
3379 | + try { |
|
3380 | 3380 | $this->get_primary_key_field(); |
3381 | 3381 | $this->_has_primary_key_field = true; |
3382 | - }catch(EE_Error $e){ |
|
3382 | + } catch (EE_Error $e) { |
|
3383 | 3383 | $this->_has_primary_key_field = false; |
3384 | 3384 | } |
3385 | 3385 | } |
@@ -3393,9 +3393,9 @@ discard block |
||
3393 | 3393 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3394 | 3394 | * @return EE_Model_Field_Base or null if none is found |
3395 | 3395 | */ |
3396 | - public function get_a_field_of_type($field_class_name){ |
|
3397 | - foreach($this->field_settings() as $field){ |
|
3398 | - if( $field instanceof $field_class_name ){ |
|
3396 | + public function get_a_field_of_type($field_class_name) { |
|
3397 | + foreach ($this->field_settings() as $field) { |
|
3398 | + if ($field instanceof $field_class_name) { |
|
3399 | 3399 | return $field; |
3400 | 3400 | } |
3401 | 3401 | } |
@@ -3409,21 +3409,21 @@ discard block |
||
3409 | 3409 | * @return EE_Foreign_Key_Field_Base |
3410 | 3410 | * @throws EE_Error |
3411 | 3411 | */ |
3412 | - public function get_foreign_key_to($model_name){ |
|
3413 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3414 | - foreach($this->field_settings() as $field){ |
|
3412 | + public function get_foreign_key_to($model_name) { |
|
3413 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3414 | + foreach ($this->field_settings() as $field) { |
|
3415 | 3415 | // if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){ |
3416 | - if( $field instanceof EE_Foreign_Key_Field_Base ){ |
|
3417 | - if (in_array($model_name,$field->get_model_names_pointed_to() ) ) { |
|
3418 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3416 | + if ($field instanceof EE_Foreign_Key_Field_Base) { |
|
3417 | + if (in_array($model_name, $field->get_model_names_pointed_to())) { |
|
3418 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3419 | 3419 | } |
3420 | 3420 | } |
3421 | 3421 | } |
3422 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3423 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
3422 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3423 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
3424 | 3424 | } |
3425 | 3425 | } |
3426 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3426 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3427 | 3427 | } |
3428 | 3428 | |
3429 | 3429 | |
@@ -3434,7 +3434,7 @@ discard block |
||
3434 | 3434 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3435 | 3435 | * @return EE_Table_Base |
3436 | 3436 | */ |
3437 | - function get_table_for_alias($table_alias){ |
|
3437 | + function get_table_for_alias($table_alias) { |
|
3438 | 3438 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3439 | 3439 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3440 | 3440 | } |
@@ -3447,25 +3447,25 @@ discard block |
||
3447 | 3447 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3448 | 3448 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3449 | 3449 | */ |
3450 | - public function field_settings($include_db_only_fields = false){ |
|
3451 | - if( $include_db_only_fields ){ |
|
3452 | - if( $this->_cached_fields === NULL ){ |
|
3450 | + public function field_settings($include_db_only_fields = false) { |
|
3451 | + if ($include_db_only_fields) { |
|
3452 | + if ($this->_cached_fields === NULL) { |
|
3453 | 3453 | $this->_cached_fields = array(); |
3454 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3455 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3456 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3454 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3455 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3456 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3457 | 3457 | } |
3458 | 3458 | } |
3459 | 3459 | } |
3460 | 3460 | return $this->_cached_fields; |
3461 | - }else{ |
|
3462 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3461 | + } else { |
|
3462 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3463 | 3463 | $this->_cached_fields_non_db_only = array(); |
3464 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3465 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3464 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3465 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3466 | 3466 | /** @var $field_obj EE_Model_Field_Base */ |
3467 | - if( ! $field_obj->is_db_only_field() ){ |
|
3468 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3467 | + if ( ! $field_obj->is_db_only_field()) { |
|
3468 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3469 | 3469 | } |
3470 | 3470 | } |
3471 | 3471 | } |
@@ -3484,40 +3484,40 @@ discard block |
||
3484 | 3484 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3485 | 3485 | * @throws \EE_Error |
3486 | 3486 | */ |
3487 | - protected function _create_objects( $rows = array() ) { |
|
3488 | - $array_of_objects=array(); |
|
3489 | - if(empty($rows)){ |
|
3487 | + protected function _create_objects($rows = array()) { |
|
3488 | + $array_of_objects = array(); |
|
3489 | + if (empty($rows)) { |
|
3490 | 3490 | return array(); |
3491 | 3491 | } |
3492 | 3492 | $count_if_model_has_no_primary_key = 0; |
3493 | - foreach ( $rows as $row ) { |
|
3494 | - if(empty($row)){//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
|
3493 | + foreach ($rows as $row) { |
|
3494 | + if (empty($row)) {//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
|
3495 | 3495 | return array(); |
3496 | 3496 | } |
3497 | - $classInstance=$this->instantiate_class_from_array_or_object($row); |
|
3498 | - if( ! $classInstance ) { |
|
3499 | - throw new EE_Error( sprintf( __( 'Could not create instance of class %s from row %s', 'event_espresso' ), $this->get_this_model_name(), http_build_query( $row ) ) ); |
|
3497 | + $classInstance = $this->instantiate_class_from_array_or_object($row); |
|
3498 | + if ( ! $classInstance) { |
|
3499 | + throw new EE_Error(sprintf(__('Could not create instance of class %s from row %s', 'event_espresso'), $this->get_this_model_name(), http_build_query($row))); |
|
3500 | 3500 | } |
3501 | 3501 | //set the timezone on the instantiated objects |
3502 | - $classInstance->set_timezone( $this->_timezone ); |
|
3502 | + $classInstance->set_timezone($this->_timezone); |
|
3503 | 3503 | //make sure if there is any timezone setting present that we set the timezone for the object |
3504 | - $array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++]=$classInstance; |
|
3504 | + $array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++] = $classInstance; |
|
3505 | 3505 | //also, for all the relations of type BelongsTo, see if we can cache |
3506 | 3506 | //those related models |
3507 | 3507 | //(we could do this for other relations too, but if there are conditions |
3508 | 3508 | //that filtered out some fo the results, then we'd be caching an incomplete set |
3509 | 3509 | //so it requires a little more thought than just caching them immediately...) |
3510 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
3511 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
3510 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
3511 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3512 | 3512 | //check if this model's INFO is present. If so, cache it on the model |
3513 | 3513 | $other_model = $relation_obj->get_other_model(); |
3514 | 3514 | |
3515 | 3515 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
3516 | 3516 | |
3517 | 3517 | //if we managed to make a model object from the results, cache it on the main model object |
3518 | - if( $other_model_obj_maybe ){ |
|
3518 | + if ($other_model_obj_maybe) { |
|
3519 | 3519 | //set timezone on these other model objects if they are present |
3520 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
3520 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
3521 | 3521 | $classInstance->cache($modelName, $other_model_obj_maybe); |
3522 | 3522 | } |
3523 | 3523 | } |
@@ -3538,12 +3538,12 @@ discard block |
||
3538 | 3538 | |
3539 | 3539 | $this_model_fields_and_values = array(); |
3540 | 3540 | //setup the row using default values; |
3541 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
3541 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
3542 | 3542 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
3543 | 3543 | } |
3544 | 3544 | |
3545 | 3545 | $className = $this->_get_class_name(); |
3546 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
3546 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
3547 | 3547 | |
3548 | 3548 | return $classInstance; |
3549 | 3549 | } |
@@ -3556,45 +3556,45 @@ discard block |
||
3556 | 3556 | * or an stdClass where each property is the name of a column, |
3557 | 3557 | * @return EE_Base_Class |
3558 | 3558 | */ |
3559 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
3560 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
3561 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
3559 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
3560 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
3561 | + $cols_n_values = get_object_vars($cols_n_values); |
|
3562 | 3562 | } |
3563 | 3563 | $primary_key = NULL; |
3564 | 3564 | //make sure the array only has keys that are fields/columns on this model |
3565 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3566 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
3567 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
3565 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3566 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3567 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
3568 | 3568 | } |
3569 | - $className=$this->_get_class_name(); |
|
3569 | + $className = $this->_get_class_name(); |
|
3570 | 3570 | |
3571 | 3571 | //check we actually found results that we can use to build our model object |
3572 | 3572 | //if not, return null |
3573 | - if( $this->has_primary_key_field()){ |
|
3574 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
3573 | + if ($this->has_primary_key_field()) { |
|
3574 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3575 | 3575 | return NULL; |
3576 | 3576 | } |
3577 | - }else if($this->unique_indexes()){ |
|
3577 | + } else if ($this->unique_indexes()) { |
|
3578 | 3578 | $first_column = reset($this_model_fields_n_values); |
3579 | - if(empty($first_column)){ |
|
3579 | + if (empty($first_column)) { |
|
3580 | 3580 | return NULL; |
3581 | 3581 | } |
3582 | 3582 | } |
3583 | 3583 | |
3584 | 3584 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
3585 | - if ( $primary_key){ |
|
3586 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
3587 | - if( ! $classInstance) { |
|
3588 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3585 | + if ($primary_key) { |
|
3586 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
3587 | + if ( ! $classInstance) { |
|
3588 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3589 | 3589 | // add this new object to the entity map |
3590 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
3590 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
3591 | 3591 | } |
3592 | - }else{ |
|
3593 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3592 | + } else { |
|
3593 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3594 | 3594 | } |
3595 | 3595 | |
3596 | 3596 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
3597 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
3597 | + $this->set_timezone($classInstance->get_timezone()); |
|
3598 | 3598 | return $classInstance; |
3599 | 3599 | } |
3600 | 3600 | /** |
@@ -3602,8 +3602,8 @@ discard block |
||
3602 | 3602 | * @param int|string $id the ID of the model object |
3603 | 3603 | * @return EE_Base_Class |
3604 | 3604 | */ |
3605 | - public function get_from_entity_map( $id ){ |
|
3606 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
3605 | + public function get_from_entity_map($id) { |
|
3606 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
3607 | 3607 | } |
3608 | 3608 | |
3609 | 3609 | |
@@ -3622,21 +3622,21 @@ discard block |
||
3622 | 3622 | * @throws EE_Error |
3623 | 3623 | * @return \EE_Base_Class |
3624 | 3624 | */ |
3625 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
3625 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
3626 | 3626 | $className = $this->_get_class_name(); |
3627 | - if( ! $object instanceof $className ){ |
|
3628 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
3627 | + if ( ! $object instanceof $className) { |
|
3628 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
3629 | 3629 | } |
3630 | 3630 | /** @var $object EE_Base_Class */ |
3631 | - if ( ! $object->ID() ){ |
|
3632 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
3631 | + if ( ! $object->ID()) { |
|
3632 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
3633 | 3633 | } |
3634 | 3634 | // double check it's not already there |
3635 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
3636 | - if ( $classInstance ) { |
|
3635 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
3636 | + if ($classInstance) { |
|
3637 | 3637 | return $classInstance; |
3638 | 3638 | } else { |
3639 | - $this->_entity_map[ $object->ID() ] = $object; |
|
3639 | + $this->_entity_map[$object->ID()] = $object; |
|
3640 | 3640 | return $object; |
3641 | 3641 | } |
3642 | 3642 | } |
@@ -3649,8 +3649,8 @@ discard block |
||
3649 | 3649 | * @param array $cols_n_values |
3650 | 3650 | * @return array |
3651 | 3651 | */ |
3652 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
3653 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3652 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3653 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3654 | 3654 | } |
3655 | 3655 | |
3656 | 3656 | |
@@ -3663,40 +3663,40 @@ discard block |
||
3663 | 3663 | * @param string $cols_n_values |
3664 | 3664 | * @return array |
3665 | 3665 | */ |
3666 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
3666 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3667 | 3667 | $this_model_fields_n_values = array(); |
3668 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
3669 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
3668 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
3669 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
3670 | 3670 | //there is a primary key on this table and its not set. Use defaults for all its columns |
3671 | - if( $table_obj->get_pk_column() && $table_pk_value === NULL ){ |
|
3672 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3673 | - if( ! $field_obj->is_db_only_field() ){ |
|
3671 | + if ($table_obj->get_pk_column() && $table_pk_value === NULL) { |
|
3672 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3673 | + if ( ! $field_obj->is_db_only_field()) { |
|
3674 | 3674 | //prepare field as if its coming from db |
3675 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
3676 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
3675 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
3676 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
3677 | 3677 | } |
3678 | 3678 | } |
3679 | - }else{ |
|
3679 | + } else { |
|
3680 | 3680 | //the table's rows existed. Use their values |
3681 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3682 | - if( ! $field_obj->is_db_only_field() ) |
|
3683 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
3681 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3682 | + if ( ! $field_obj->is_db_only_field()) |
|
3683 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column()); |
|
3684 | 3684 | } |
3685 | 3685 | } |
3686 | 3686 | } |
3687 | 3687 | return $this_model_fields_n_values; |
3688 | 3688 | } |
3689 | 3689 | |
3690 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
3690 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
3691 | 3691 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
3692 | 3692 | //does the field on the model relate to this column retrieved from the db? |
3693 | 3693 | //or is it a db-only field? (not relating to the model) |
3694 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
3695 | - $value = $cols_n_values[ $qualified_column ]; |
|
3694 | + if (isset($cols_n_values[$qualified_column])) { |
|
3695 | + $value = $cols_n_values[$qualified_column]; |
|
3696 | 3696 | |
3697 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3698 | - $value = $cols_n_values[ $regular_column ]; |
|
3699 | - }else{ |
|
3697 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
3698 | + $value = $cols_n_values[$regular_column]; |
|
3699 | + } else { |
|
3700 | 3700 | $value = NULL; |
3701 | 3701 | } |
3702 | 3702 | |
@@ -3714,23 +3714,23 @@ discard block |
||
3714 | 3714 | * @param int|string $id |
3715 | 3715 | * @return EE_Base_Class |
3716 | 3716 | */ |
3717 | - public function refresh_entity_map_from_db( $id ){ |
|
3718 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3719 | - if( $obj_in_map ){ |
|
3720 | - $wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) ); |
|
3721 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
3722 | - $one_row = reset( $wpdb_results ); |
|
3723 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
3724 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
3717 | + public function refresh_entity_map_from_db($id) { |
|
3718 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3719 | + if ($obj_in_map) { |
|
3720 | + $wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)); |
|
3721 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
3722 | + $one_row = reset($wpdb_results); |
|
3723 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
3724 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
3725 | 3725 | } |
3726 | 3726 | //clear the cache of related model objects |
3727 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3728 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3727 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3728 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3729 | 3729 | } |
3730 | 3730 | } |
3731 | 3731 | return $obj_in_map; |
3732 | - }else{ |
|
3733 | - return $this->get_one_by_ID( $id ); |
|
3732 | + } else { |
|
3733 | + return $this->get_one_by_ID($id); |
|
3734 | 3734 | } |
3735 | 3735 | } |
3736 | 3736 | |
@@ -3748,24 +3748,24 @@ discard block |
||
3748 | 3748 | * @param EE_Base_Class $replacing_model_obj |
3749 | 3749 | * @return \EE_Base_Class |
3750 | 3750 | */ |
3751 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
3752 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3753 | - if( $obj_in_map ){ |
|
3754 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
3755 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
3756 | - $obj_in_map->set( $field_name, $value ); |
|
3751 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
3752 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3753 | + if ($obj_in_map) { |
|
3754 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
3755 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
3756 | + $obj_in_map->set($field_name, $value); |
|
3757 | 3757 | } |
3758 | 3758 | //make the model object in the entity map's cache match the $replacing_model_obj |
3759 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3760 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3761 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
3762 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
3759 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3760 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3761 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
3762 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
3763 | 3763 | } |
3764 | 3764 | } |
3765 | 3765 | } |
3766 | 3766 | return $obj_in_map; |
3767 | - }else{ |
|
3768 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
3767 | + } else { |
|
3768 | + $this->add_to_entity_map($replacing_model_obj); |
|
3769 | 3769 | return $replacing_model_obj; |
3770 | 3770 | } |
3771 | 3771 | } |
@@ -3778,7 +3778,7 @@ discard block |
||
3778 | 3778 | * require_once($this->_getClassName().".class.php"); |
3779 | 3779 | * @return string |
3780 | 3780 | */ |
3781 | - private function _get_class_name(){ |
|
3781 | + private function _get_class_name() { |
|
3782 | 3782 | return "EE_".$this->get_this_model_name(); |
3783 | 3783 | } |
3784 | 3784 | |
@@ -3791,10 +3791,10 @@ discard block |
||
3791 | 3791 | * @param int $quantity |
3792 | 3792 | * @return string |
3793 | 3793 | */ |
3794 | - public function item_name($quantity = 1){ |
|
3795 | - if($quantity == 1){ |
|
3794 | + public function item_name($quantity = 1) { |
|
3795 | + if ($quantity == 1) { |
|
3796 | 3796 | return $this->singular_item; |
3797 | - }else{ |
|
3797 | + } else { |
|
3798 | 3798 | return $this->plural_item; |
3799 | 3799 | } |
3800 | 3800 | } |
@@ -3823,13 +3823,13 @@ discard block |
||
3823 | 3823 | * @throws EE_Error |
3824 | 3824 | * @return mixed whatever the plugin which calls add_filter decides |
3825 | 3825 | */ |
3826 | - public function __call($methodName,$args){ |
|
3827 | - $className=get_class($this); |
|
3828 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
3829 | - if(!has_filter($tagName)){ |
|
3826 | + public function __call($methodName, $args) { |
|
3827 | + $className = get_class($this); |
|
3828 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
3829 | + if ( ! has_filter($tagName)) { |
|
3830 | 3830 | throw new EE_Error( |
3831 | 3831 | sprintf( |
3832 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
3832 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
3833 | 3833 | $methodName, |
3834 | 3834 | $className, |
3835 | 3835 | $tagName, |
@@ -3838,7 +3838,7 @@ discard block |
||
3838 | 3838 | ); |
3839 | 3839 | } |
3840 | 3840 | |
3841 | - return apply_filters($tagName,null,$this,$args); |
|
3841 | + return apply_filters($tagName, null, $this, $args); |
|
3842 | 3842 | } |
3843 | 3843 | |
3844 | 3844 | |
@@ -3851,22 +3851,22 @@ discard block |
||
3851 | 3851 | * @throws EE_Error |
3852 | 3852 | * @return EE_Base_Class |
3853 | 3853 | */ |
3854 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
3854 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
3855 | 3855 | $className = $this->_get_class_name(); |
3856 | 3856 | $primary_key_field = $this->get_primary_key_field(); |
3857 | - if( $base_class_obj_or_id instanceof $className ){ |
|
3857 | + if ($base_class_obj_or_id instanceof $className) { |
|
3858 | 3858 | $model_object = $base_class_obj_or_id; |
3859 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3860 | - is_int( $base_class_obj_or_id ) || |
|
3861 | - is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
3859 | + }elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3860 | + is_int($base_class_obj_or_id) || |
|
3861 | + is_string($base_class_obj_or_id) )) {//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
3862 | 3862 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
3863 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
3863 | + }elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
3864 | 3864 | //assume its a string representation of the object |
3865 | 3865 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
3866 | - }else{ |
|
3867 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
3866 | + } else { |
|
3867 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
3868 | 3868 | } |
3869 | - if( $model_object->ID() == NULL && $ensure_is_in_db){ |
|
3869 | + if ($model_object->ID() == NULL && $ensure_is_in_db) { |
|
3870 | 3870 | $model_object->save(); |
3871 | 3871 | } |
3872 | 3872 | return $model_object; |
@@ -3882,19 +3882,19 @@ discard block |
||
3882 | 3882 | * @return int|string depending on the type of this model object's ID |
3883 | 3883 | * @throws EE_Error |
3884 | 3884 | */ |
3885 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
3885 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
3886 | 3886 | $className = $this->_get_class_name(); |
3887 | - if( $base_class_obj_or_id instanceof $className ){ |
|
3887 | + if ($base_class_obj_or_id instanceof $className) { |
|
3888 | 3888 | /** @var $base_class_obj_or_id EE_Base_Class */ |
3889 | 3889 | $id = $base_class_obj_or_id->ID(); |
3890 | - }elseif(is_int($base_class_obj_or_id)){ |
|
3890 | + }elseif (is_int($base_class_obj_or_id)) { |
|
3891 | 3891 | //assume it's an ID |
3892 | 3892 | $id = $base_class_obj_or_id; |
3893 | - }elseif(is_string($base_class_obj_or_id)){ |
|
3893 | + }elseif (is_string($base_class_obj_or_id)) { |
|
3894 | 3894 | //assume its a string representation of the object |
3895 | 3895 | $id = $base_class_obj_or_id; |
3896 | - }else{ |
|
3897 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
3896 | + } else { |
|
3897 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
3898 | 3898 | } |
3899 | 3899 | return $id; |
3900 | 3900 | } |
@@ -3917,14 +3917,14 @@ discard block |
||
3917 | 3917 | * @param int $values_already_prepared like one of the constants on EEM_Base |
3918 | 3918 | * @return void |
3919 | 3919 | */ |
3920 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
3920 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
3921 | 3921 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
3922 | 3922 | } |
3923 | 3923 | /** |
3924 | 3924 | * Read comments for assume_values_already_prepared_by_model_object() |
3925 | 3925 | * @return int |
3926 | 3926 | */ |
3927 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
3927 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
3928 | 3928 | return $this->_values_already_prepared_by_model_object; |
3929 | 3929 | } |
3930 | 3930 | |
@@ -3932,17 +3932,17 @@ discard block |
||
3932 | 3932 | * Gets all the indexes on this model |
3933 | 3933 | * @return EE_Index[] |
3934 | 3934 | */ |
3935 | - public function indexes(){ |
|
3935 | + public function indexes() { |
|
3936 | 3936 | return $this->_indexes; |
3937 | 3937 | } |
3938 | 3938 | /** |
3939 | 3939 | * Gets all the Unique Indexes on this model |
3940 | 3940 | * @return EE_Unique_Index[] |
3941 | 3941 | */ |
3942 | - public function unique_indexes(){ |
|
3942 | + public function unique_indexes() { |
|
3943 | 3943 | $unique_indexes = array(); |
3944 | - foreach($this->_indexes as $name => $index){ |
|
3945 | - if($index instanceof EE_Unique_Index){ |
|
3944 | + foreach ($this->_indexes as $name => $index) { |
|
3945 | + if ($index instanceof EE_Unique_Index) { |
|
3946 | 3946 | $unique_indexes [$name] = $index; |
3947 | 3947 | } |
3948 | 3948 | } |
@@ -3955,9 +3955,9 @@ discard block |
||
3955 | 3955 | * on a primary index |
3956 | 3956 | * @return EE_Model_Field_Base[] |
3957 | 3957 | */ |
3958 | - public function get_combined_primary_key_fields(){ |
|
3959 | - foreach($this->indexes() as $index){ |
|
3960 | - if($index instanceof EE_Primary_Key_Index){ |
|
3958 | + public function get_combined_primary_key_fields() { |
|
3959 | + foreach ($this->indexes() as $index) { |
|
3960 | + if ($index instanceof EE_Primary_Key_Index) { |
|
3961 | 3961 | return $index->fields(); |
3962 | 3962 | } |
3963 | 3963 | } |
@@ -3970,7 +3970,7 @@ discard block |
||
3970 | 3970 | * @param array $cols_n_values keys are field names, values are their values |
3971 | 3971 | * @return string |
3972 | 3972 | */ |
3973 | - public function get_index_primary_key_string($cols_n_values){ |
|
3973 | + public function get_index_primary_key_string($cols_n_values) { |
|
3974 | 3974 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
3975 | 3975 | return http_build_query($cols_n_values_for_primary_key_index); |
3976 | 3976 | } |
@@ -3982,13 +3982,13 @@ discard block |
||
3982 | 3982 | * @param string $index_primary_key_string |
3983 | 3983 | * @return null|array |
3984 | 3984 | */ |
3985 | - function parse_index_primary_key_string( $index_primary_key_string) { |
|
3985 | + function parse_index_primary_key_string($index_primary_key_string) { |
|
3986 | 3986 | $key_fields = $this->get_combined_primary_key_fields(); |
3987 | 3987 | //check all of them are in the $id |
3988 | 3988 | $key_vals_in_combined_pk = array(); |
3989 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
3990 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
3991 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
3989 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
3990 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
3991 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
3992 | 3992 | return NULL; |
3993 | 3993 | } |
3994 | 3994 | } |
@@ -4001,10 +4001,10 @@ discard block |
||
4001 | 4001 | * @param array $key_vals |
4002 | 4002 | * @return boolean |
4003 | 4003 | */ |
4004 | - function has_all_combined_primary_key_fields( $key_vals ) { |
|
4005 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4006 | - foreach( $keys_it_should_have as $key ){ |
|
4007 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4004 | + function has_all_combined_primary_key_fields($key_vals) { |
|
4005 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4006 | + foreach ($keys_it_should_have as $key) { |
|
4007 | + if ( ! isset($key_vals[$key])) { |
|
4008 | 4008 | return false; |
4009 | 4009 | } |
4010 | 4010 | } |
@@ -4020,23 +4020,23 @@ discard block |
||
4020 | 4020 | * @throws EE_Error |
4021 | 4021 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4022 | 4022 | */ |
4023 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4023 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4024 | 4024 | |
4025 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4025 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4026 | 4026 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4027 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4027 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4028 | 4028 | $attributes_array = $model_object_or_attributes_array; |
4029 | - }else{ |
|
4030 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4029 | + } else { |
|
4030 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4031 | 4031 | } |
4032 | 4032 | //even copies obviously won't have the same ID, so remove the primary key |
4033 | 4033 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4034 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4034 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4035 | 4035 | unset($attributes_array[$this->primary_key_name()]); |
4036 | 4036 | } |
4037 | - if(isset($query_params[0])){ |
|
4038 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4039 | - }else{ |
|
4037 | + if (isset($query_params[0])) { |
|
4038 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4039 | + } else { |
|
4040 | 4040 | $query_params[0] = $attributes_array; |
4041 | 4041 | } |
4042 | 4042 | return $this->get_all($query_params); |
@@ -4050,16 +4050,16 @@ discard block |
||
4050 | 4050 | * @param array $query_params |
4051 | 4051 | * @return EE_Base_Class |
4052 | 4052 | */ |
4053 | - function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4054 | - if( ! is_array( $query_params ) ){ |
|
4055 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4053 | + function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4054 | + if ( ! is_array($query_params)) { |
|
4055 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4056 | 4056 | $query_params = array(); |
4057 | 4057 | } |
4058 | 4058 | $query_params['limit'] = 1; |
4059 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4060 | - if(is_array($copies)){ |
|
4059 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4060 | + if (is_array($copies)) { |
|
4061 | 4061 | return array_shift($copies); |
4062 | - }else{ |
|
4062 | + } else { |
|
4063 | 4063 | return null; |
4064 | 4064 | } |
4065 | 4065 | } |
@@ -4073,10 +4073,10 @@ discard block |
||
4073 | 4073 | * @param int|string $id the value of the primary key to update |
4074 | 4074 | * @return int number of rows updated |
4075 | 4075 | */ |
4076 | - public function update_by_ID($fields_n_values,$id){ |
|
4076 | + public function update_by_ID($fields_n_values, $id) { |
|
4077 | 4077 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4078 | 4078 | 'default_where_conditions'=>'other_models_only',); |
4079 | - return $this->update($fields_n_values,$query_params); |
|
4079 | + return $this->update($fields_n_values, $query_params); |
|
4080 | 4080 | } |
4081 | 4081 | |
4082 | 4082 | |
@@ -4087,12 +4087,12 @@ discard block |
||
4087 | 4087 | * @return string an operator which can be used in SQL |
4088 | 4088 | * @throws EE_Error |
4089 | 4089 | */ |
4090 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4090 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4091 | 4091 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4092 | - if($sql_operator){ |
|
4092 | + if ($sql_operator) { |
|
4093 | 4093 | return $sql_operator; |
4094 | - }else{ |
|
4095 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4094 | + } else { |
|
4095 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4096 | 4096 | } |
4097 | 4097 | } |
4098 | 4098 | |
@@ -4102,10 +4102,10 @@ discard block |
||
4102 | 4102 | * @param array $query_params like get_all's |
4103 | 4103 | * @return string[] |
4104 | 4104 | */ |
4105 | - public function get_all_names($query_params = array()){ |
|
4105 | + public function get_all_names($query_params = array()) { |
|
4106 | 4106 | $objs = $this->get_all($query_params); |
4107 | 4107 | $names = array(); |
4108 | - foreach($objs as $obj){ |
|
4108 | + foreach ($objs as $obj) { |
|
4109 | 4109 | $names[$obj->ID()] = $obj->name(); |
4110 | 4110 | } |
4111 | 4111 | return $names; |
@@ -4120,22 +4120,22 @@ discard block |
||
4120 | 4120 | * @param boolean $filter_out_empty_ids if a model object has an ID of '' or 0, don't bother including it in the returned array |
4121 | 4121 | * @return array |
4122 | 4122 | */ |
4123 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4124 | - if( ! $this->has_primary_key_field() ) { |
|
4125 | - if( WP_DEBUG ) { |
|
4126 | - EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4123 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4124 | + if ( ! $this->has_primary_key_field()) { |
|
4125 | + if (WP_DEBUG) { |
|
4126 | + EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4127 | 4127 | return array(); |
4128 | 4128 | } |
4129 | 4129 | } |
4130 | 4130 | $IDs = array(); |
4131 | - foreach( $model_objects as $model_object ) { |
|
4131 | + foreach ($model_objects as $model_object) { |
|
4132 | 4132 | $id = $model_object->ID(); |
4133 | - if( ! $id ) { |
|
4134 | - if( $filter_out_empty_ids ) { |
|
4133 | + if ( ! $id) { |
|
4134 | + if ($filter_out_empty_ids) { |
|
4135 | 4135 | continue; |
4136 | 4136 | } |
4137 | - if( WP_DEBUG ) { |
|
4138 | - EE_Error::add_error(__( 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4137 | + if (WP_DEBUG) { |
|
4138 | + EE_Error::add_error(__('Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4139 | 4139 | } |
4140 | 4140 | } |
4141 | 4141 | $IDs[] = $id; |
@@ -4148,8 +4148,8 @@ discard block |
||
4148 | 4148 | * are no capabilities that relate to this model returns false |
4149 | 4149 | * @return string|false |
4150 | 4150 | */ |
4151 | - public function cap_slug(){ |
|
4152 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4151 | + public function cap_slug() { |
|
4152 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4153 | 4153 | } |
4154 | 4154 | |
4155 | 4155 | /** |
@@ -4161,27 +4161,27 @@ discard block |
||
4161 | 4161 | * @param string $context |
4162 | 4162 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4163 | 4163 | */ |
4164 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4165 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4164 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4165 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4166 | 4166 | //check if we ought to run the restriction generator first |
4167 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
4168 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base && |
|
4169 | - ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) { |
|
4170 | - $this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ], $this->_cap_restriction_generators[ $context ]->generate_restrictions() ); |
|
4167 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
4168 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base && |
|
4169 | + ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) { |
|
4170 | + $this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions()); |
|
4171 | 4171 | } |
4172 | 4172 | //and make sure we've finalized the construction of each restriction |
4173 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4174 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4173 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4174 | + $where_conditions_obj->_finalize_construct($this); |
|
4175 | 4175 | } |
4176 | 4176 | |
4177 | - return $this->_cap_restrictions[ $context ]; |
|
4177 | + return $this->_cap_restrictions[$context]; |
|
4178 | 4178 | } |
4179 | 4179 | |
4180 | 4180 | /** |
4181 | 4181 | * Indicating whether or not this model thinks its a wp core model |
4182 | 4182 | * @return boolean |
4183 | 4183 | */ |
4184 | - public function is_wp_core_model(){ |
|
4184 | + public function is_wp_core_model() { |
|
4185 | 4185 | return $this->_wp_core_model; |
4186 | 4186 | } |
4187 | 4187 | |
@@ -4191,12 +4191,12 @@ discard block |
||
4191 | 4191 | * @param string $context one of EEM_Base::caps_ constants |
4192 | 4192 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4193 | 4193 | */ |
4194 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4194 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4195 | 4195 | $missing_caps = array(); |
4196 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4197 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4198 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4199 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4196 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4197 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4198 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4199 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4200 | 4200 | } |
4201 | 4201 | } |
4202 | 4202 | return $missing_caps; |
@@ -4208,7 +4208,7 @@ discard block |
||
4208 | 4208 | * one of 'read', 'edit', or 'delete' |
4209 | 4209 | */ |
4210 | 4210 | public function cap_contexts_to_cap_action_map() { |
4211 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4211 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4212 | 4212 | } |
4213 | 4213 | |
4214 | 4214 | |
@@ -4219,19 +4219,19 @@ discard block |
||
4219 | 4219 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4220 | 4220 | * @throws \EE_Error |
4221 | 4221 | */ |
4222 | - public function cap_action_for_context( $context ) { |
|
4222 | + public function cap_action_for_context($context) { |
|
4223 | 4223 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4224 | - if( isset( $mapping[ $context ] ) ) { |
|
4225 | - return $mapping[ $context ]; |
|
4224 | + if (isset($mapping[$context])) { |
|
4225 | + return $mapping[$context]; |
|
4226 | 4226 | } |
4227 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4227 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4228 | 4228 | return $action; |
4229 | 4229 | } |
4230 | 4230 | throw new EE_Error( |
4231 | 4231 | sprintf( |
4232 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4232 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4233 | 4233 | $context, |
4234 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4234 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4235 | 4235 | ) |
4236 | 4236 | ); |
4237 | 4237 | |
@@ -4242,7 +4242,7 @@ discard block |
||
4242 | 4242 | * @return array |
4243 | 4243 | */ |
4244 | 4244 | static public function valid_cap_contexts() { |
4245 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4245 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4246 | 4246 | self::caps_read, |
4247 | 4247 | self::caps_read_admin, |
4248 | 4248 | self::caps_edit, |
@@ -4258,17 +4258,17 @@ discard block |
||
4258 | 4258 | * @return bool |
4259 | 4259 | * @throws \EE_Error |
4260 | 4260 | */ |
4261 | - static public function verify_is_valid_cap_context( $context ) { |
|
4261 | + static public function verify_is_valid_cap_context($context) { |
|
4262 | 4262 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4263 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4263 | + if (in_array($context, $valid_cap_contexts)) { |
|
4264 | 4264 | return true; |
4265 | - }else{ |
|
4265 | + } else { |
|
4266 | 4266 | throw new EE_Error( |
4267 | 4267 | sprintf( |
4268 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4268 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4269 | 4269 | $context, |
4270 | - 'EEM_Base' , |
|
4271 | - implode(',', $valid_cap_contexts ) |
|
4270 | + 'EEM_Base', |
|
4271 | + implode(',', $valid_cap_contexts) |
|
4272 | 4272 | ) |
4273 | 4273 | ); |
4274 | 4274 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
498 | 498 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
499 | 499 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
500 | - }else{ |
|
500 | + } else{ |
|
501 | 501 | return array(); |
502 | 502 | } |
503 | 503 | } |
@@ -548,8 +548,9 @@ discard block |
||
548 | 548 | * @return array |
549 | 549 | */ |
550 | 550 | public function status_array( $translated = FALSE ) { |
551 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
552 | - return array(); |
|
551 | + if ( !array_key_exists('Status', $this->_model_relations ) ) { |
|
552 | + return array(); |
|
553 | + } |
|
553 | 554 | $model_name = $this->get_this_model_name(); |
554 | 555 | $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
555 | 556 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
@@ -728,13 +729,13 @@ discard block |
||
728 | 729 | $last_model_name = end( $models_to_follow_to_wp_users ); |
729 | 730 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
730 | 731 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
731 | - }else{ |
|
732 | + } else{ |
|
732 | 733 | $model_with_fk_to_wp_users = $this; |
733 | 734 | $model_chain_to_wp_user = ''; |
734 | 735 | } |
735 | 736 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
736 | 737 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
737 | - }catch( EE_Error $e ) { |
|
738 | + } catch( EE_Error $e ) { |
|
738 | 739 | return false; |
739 | 740 | } |
740 | 741 | } |
@@ -762,11 +763,11 @@ discard block |
||
762 | 763 | public function is_owned() { |
763 | 764 | if( $this->model_chain_to_wp_user() ){ |
764 | 765 | return true; |
765 | - }else{ |
|
766 | + } else{ |
|
766 | 767 | try{ |
767 | 768 | $this->get_foreign_key_to( 'WP_User' ); |
768 | 769 | return true; |
769 | - }catch( EE_Error $e ){ |
|
770 | + } catch( EE_Error $e ){ |
|
770 | 771 | return false; |
771 | 772 | } |
772 | 773 | } |
@@ -789,9 +790,9 @@ discard block |
||
789 | 790 | //remember the custom selections, if any |
790 | 791 | if(is_array($columns_to_select)){ |
791 | 792 | $this->_custom_selections = $columns_to_select; |
792 | - }elseif(is_string($columns_to_select)){ |
|
793 | + } elseif(is_string($columns_to_select)){ |
|
793 | 794 | $this->_custom_selections = array($this->_custom_selections); |
794 | - }else{ |
|
795 | + } else{ |
|
795 | 796 | $this->_custom_selections = array(); |
796 | 797 | } |
797 | 798 | |
@@ -842,7 +843,7 @@ discard block |
||
842 | 843 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
843 | 844 | } |
844 | 845 | $columns_to_select_string = implode(", ",$select_sql_array); |
845 | - }else{ |
|
846 | + } else{ |
|
846 | 847 | $columns_to_select_string = $columns_to_select; |
847 | 848 | } |
848 | 849 | return $columns_to_select_string; |
@@ -870,10 +871,10 @@ discard block |
||
870 | 871 | function get_one_by_ID($id){ |
871 | 872 | if( $this->get_from_entity_map( $id ) ){ |
872 | 873 | return $this->get_from_entity_map( $id ); |
873 | - }elseif( $this->has_primary_key_field ( ) ) { |
|
874 | + } elseif( $this->has_primary_key_field ( ) ) { |
|
874 | 875 | $primary_key_name = $this->get_primary_key_field()->get_name(); |
875 | 876 | return $this->get_one(array(array($primary_key_name => $id))); |
876 | - }else{ |
|
877 | + } else{ |
|
877 | 878 | //no primary key, so the $id must be from the get_index_primary_key_string() |
878 | 879 | return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) ); |
879 | 880 | } |
@@ -895,7 +896,7 @@ discard block |
||
895 | 896 | $items = $this->get_all($query_params); |
896 | 897 | if(empty($items)){ |
897 | 898 | return null; |
898 | - }else{ |
|
899 | + } else{ |
|
899 | 900 | return array_shift($items); |
900 | 901 | } |
901 | 902 | } |
@@ -1290,7 +1291,7 @@ discard block |
||
1290 | 1291 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1291 | 1292 | if( $this->has_primary_key_field() ){ |
1292 | 1293 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1293 | - }else{ |
|
1294 | + } else{ |
|
1294 | 1295 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work) |
1295 | 1296 | $main_table_pk_value = null; |
1296 | 1297 | } |
@@ -1329,7 +1330,7 @@ discard block |
||
1329 | 1330 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1330 | 1331 | if( $this->has_primary_key_field() ){ |
1331 | 1332 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1332 | - }else{ |
|
1333 | + } else{ |
|
1333 | 1334 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1334 | 1335 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1335 | 1336 | $model_objs_affected_ids = array(); |
@@ -1389,9 +1390,9 @@ discard block |
||
1389 | 1390 | |
1390 | 1391 | if( $field_to_select ){ |
1391 | 1392 | $field = $this->field_settings_for( $field_to_select ); |
1392 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1393 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1393 | 1394 | $field = $this->get_primary_key_field(); |
1394 | - }else{ |
|
1395 | + } else{ |
|
1395 | 1396 | //no primary key, just grab the first column |
1396 | 1397 | $field = reset( $this->field_settings()); |
1397 | 1398 | } |
@@ -1415,7 +1416,7 @@ discard block |
||
1415 | 1416 | $col = $this->get_col( $query_params, $field_to_select ); |
1416 | 1417 | if( ! empty( $col ) ) { |
1417 | 1418 | return reset( $col ); |
1418 | - }else{ |
|
1419 | + } else{ |
|
1419 | 1420 | return NULL; |
1420 | 1421 | } |
1421 | 1422 | } |
@@ -1499,7 +1500,7 @@ discard block |
||
1499 | 1500 | |
1500 | 1501 | // /echo "delete sql:$SQL"; |
1501 | 1502 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1502 | - }else{ |
|
1503 | + } else{ |
|
1503 | 1504 | $rows_deleted = 0; |
1504 | 1505 | } |
1505 | 1506 | |
@@ -1541,7 +1542,7 @@ discard block |
||
1541 | 1542 | //first, if $ignore_this_model_obj was supplied, get its model |
1542 | 1543 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1543 | 1544 | $ignored_model = $ignore_this_model_obj->get_model(); |
1544 | - }else{ |
|
1545 | + } else{ |
|
1545 | 1546 | $ignored_model = null; |
1546 | 1547 | } |
1547 | 1548 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1554,7 +1555,7 @@ discard block |
||
1554 | 1555 | if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
1555 | 1556 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1556 | 1557 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1557 | - }else{ |
|
1558 | + } else{ |
|
1558 | 1559 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1559 | 1560 | } |
1560 | 1561 | |
@@ -1591,24 +1592,28 @@ discard block |
||
1591 | 1592 | } |
1592 | 1593 | |
1593 | 1594 | //primary table deletes |
1594 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1595 | - $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1595 | + if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) { |
|
1596 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1597 | + } |
|
1596 | 1598 | |
1597 | 1599 | //other tables |
1598 | 1600 | if ( !empty( $other_tables ) ) { |
1599 | 1601 | foreach ( $other_tables as $ot ) { |
1600 | 1602 | |
1601 | 1603 | //first check if we've got the foreign key column here. |
1602 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1603 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1604 | + if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) { |
|
1605 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1606 | + } |
|
1604 | 1607 | |
1605 | 1608 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1606 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1607 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1609 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) { |
|
1610 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1611 | + } |
|
1608 | 1612 | |
1609 | 1613 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1610 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1611 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1614 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) { |
|
1615 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1616 | + } |
|
1612 | 1617 | } |
1613 | 1618 | } |
1614 | 1619 | } |
@@ -1621,7 +1626,7 @@ discard block |
||
1621 | 1626 | } |
1622 | 1627 | |
1623 | 1628 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1624 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1629 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1625 | 1630 | $ways_to_identify_a_row = array(); |
1626 | 1631 | $fields = $this->get_combined_primary_key_fields(); |
1627 | 1632 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1633,7 +1638,7 @@ discard block |
||
1633 | 1638 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1634 | 1639 | } |
1635 | 1640 | return implode(" OR ",$ways_to_identify_a_row); |
1636 | - }else{ |
|
1641 | + } else{ |
|
1637 | 1642 | //so there's no primary key and no combined key... |
1638 | 1643 | //sorry, can't help you |
1639 | 1644 | throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
@@ -1655,10 +1660,10 @@ discard block |
||
1655 | 1660 | if($field_to_count){ |
1656 | 1661 | $field_obj = $this->field_settings_for($field_to_count); |
1657 | 1662 | $column_to_count = $field_obj->get_qualified_column(); |
1658 | - }elseif($this->has_primary_key_field ()){ |
|
1663 | + } elseif($this->has_primary_key_field ()){ |
|
1659 | 1664 | $pk_field_obj = $this->get_primary_key_field(); |
1660 | 1665 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1661 | - }else{//there's no primary key |
|
1666 | + } else{//there's no primary key |
|
1662 | 1667 | $column_to_count = '*'; |
1663 | 1668 | } |
1664 | 1669 | |
@@ -1680,7 +1685,7 @@ discard block |
||
1680 | 1685 | if($field_to_sum){ |
1681 | 1686 | $field_obj = $this->field_settings_for($field_to_sum); |
1682 | 1687 | |
1683 | - }else{ |
|
1688 | + } else{ |
|
1684 | 1689 | $field_obj = $this->get_primary_key_field(); |
1685 | 1690 | } |
1686 | 1691 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1689,7 +1694,7 @@ discard block |
||
1689 | 1694 | $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
1690 | 1695 | if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
1691 | 1696 | return (float)$return_value; |
1692 | - }else{//must be %f |
|
1697 | + } else{//must be %f |
|
1693 | 1698 | return (float)$return_value; |
1694 | 1699 | } |
1695 | 1700 | } |
@@ -1729,10 +1734,10 @@ discard block |
||
1729 | 1734 | $wpdb->show_errors( $old_show_errors_value ); |
1730 | 1735 | if( ! empty( $wpdb->last_error ) ){ |
1731 | 1736 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1732 | - }elseif( $result === false ){ |
|
1737 | + } elseif( $result === false ){ |
|
1733 | 1738 | throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
1734 | 1739 | } |
1735 | - }elseif( $result === false ) { |
|
1740 | + } elseif( $result === false ) { |
|
1736 | 1741 | EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
1737 | 1742 | } |
1738 | 1743 | return $result; |
@@ -1946,7 +1951,7 @@ discard block |
||
1946 | 1951 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
1947 | 1952 | if( $results ){ |
1948 | 1953 | return array_shift($results); |
1949 | - }else{ |
|
1954 | + } else{ |
|
1950 | 1955 | return null; |
1951 | 1956 | } |
1952 | 1957 | |
@@ -2017,7 +2022,7 @@ discard block |
||
2017 | 2022 | */ |
2018 | 2023 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2019 | 2024 | return $new_id; |
2020 | - }else{ |
|
2025 | + } else{ |
|
2021 | 2026 | return FALSE; |
2022 | 2027 | } |
2023 | 2028 | } |
@@ -2058,9 +2063,9 @@ discard block |
||
2058 | 2063 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2059 | 2064 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2060 | 2065 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2061 | - }elseif( is_array($obj_or_fields_array)){ |
|
2066 | + } elseif( is_array($obj_or_fields_array)){ |
|
2062 | 2067 | $fields_n_values = $obj_or_fields_array; |
2063 | - }else{ |
|
2068 | + } else{ |
|
2064 | 2069 | throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
2065 | 2070 | } |
2066 | 2071 | $query_params = array(); |
@@ -2076,7 +2081,7 @@ discard block |
||
2076 | 2081 | //if there is nothing to base this search on, then we shouldn't find anything |
2077 | 2082 | if( empty( $query_params ) ){ |
2078 | 2083 | return array(); |
2079 | - }else{ |
|
2084 | + } else{ |
|
2080 | 2085 | return $this->get_one($query_params); |
2081 | 2086 | } |
2082 | 2087 | } |
@@ -2149,12 +2154,12 @@ discard block |
||
2149 | 2154 | if($this->has_primary_key_field()){ |
2150 | 2155 | if($this->get_primary_key_field()->is_auto_increment()){ |
2151 | 2156 | return $wpdb->insert_id; |
2152 | - }else{ |
|
2157 | + } else{ |
|
2153 | 2158 | //it's not an auto-increment primary key, so |
2154 | 2159 | //it must have been supplied |
2155 | 2160 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2156 | 2161 | } |
2157 | - }else{ |
|
2162 | + } else{ |
|
2158 | 2163 | //we can't return a primary key because there is none. instead return |
2159 | 2164 | //a unique string indicating this model |
2160 | 2165 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2202,7 +2207,7 @@ discard block |
||
2202 | 2207 | //leave the value alone |
2203 | 2208 | } |
2204 | 2209 | return $value; |
2205 | - }else{ |
|
2210 | + } else{ |
|
2206 | 2211 | return $value; |
2207 | 2212 | } |
2208 | 2213 | } |
@@ -2295,7 +2300,7 @@ discard block |
||
2295 | 2300 | if(array_key_exists('group_by', $query_params)){ |
2296 | 2301 | if(is_array($query_params['group_by'])){ |
2297 | 2302 | $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
2298 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2303 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2299 | 2304 | $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
2300 | 2305 | } |
2301 | 2306 | } |
@@ -2303,10 +2308,11 @@ discard block |
||
2303 | 2308 | $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
2304 | 2309 | } |
2305 | 2310 | if(array_key_exists('order_by', $query_params)){ |
2306 | - if ( is_array( $query_params['order_by'] ) ) |
|
2307 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2308 | - elseif( ! empty( $query_params['order_by'] )) |
|
2309 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2311 | + if ( is_array( $query_params['order_by'] ) ) { |
|
2312 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2313 | + } elseif( ! empty( $query_params['order_by'] )) { |
|
2314 | + $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2315 | + } |
|
2310 | 2316 | } |
2311 | 2317 | if(array_key_exists('force_join', $query_params)){ |
2312 | 2318 | $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
@@ -2338,10 +2344,10 @@ discard block |
||
2338 | 2344 | if (! is_array($possibly_array_of_params)){ |
2339 | 2345 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2340 | 2346 | $param,$possibly_array_of_params)); |
2341 | - }else{ |
|
2347 | + } else{ |
|
2342 | 2348 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2343 | 2349 | } |
2344 | - }elseif($query_param_type === 0 //ie WHERE |
|
2350 | + } elseif($query_param_type === 0 //ie WHERE |
|
2345 | 2351 | && is_array($possibly_array_of_params) |
2346 | 2352 | && isset($possibly_array_of_params[2]) |
2347 | 2353 | && $possibly_array_of_params[2] == true){ |
@@ -2401,7 +2407,7 @@ discard block |
||
2401 | 2407 | } |
2402 | 2408 | if( isset( $query_params[0] ) ) { |
2403 | 2409 | $where_query_params = $query_params[0]; |
2404 | - }else{ |
|
2410 | + } else{ |
|
2405 | 2411 | $where_query_params = array(); |
2406 | 2412 | } |
2407 | 2413 | //first check if we should alter the query to account for caps or not |
@@ -2419,7 +2425,7 @@ discard block |
||
2419 | 2425 | } |
2420 | 2426 | if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
2421 | 2427 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2422 | - }else{ |
|
2428 | + } else{ |
|
2423 | 2429 | $use_default_where_conditions = 'all'; |
2424 | 2430 | } |
2425 | 2431 | $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
@@ -2442,7 +2448,7 @@ discard block |
||
2442 | 2448 | } |
2443 | 2449 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2444 | 2450 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2445 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2451 | + } elseif( ! empty ( $query_params['limit'] )){ |
|
2446 | 2452 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2447 | 2453 | } |
2448 | 2454 | } |
@@ -2464,11 +2470,11 @@ discard block |
||
2464 | 2470 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2465 | 2471 | } |
2466 | 2472 | $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
2467 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2473 | + } elseif( ! empty ( $query_params['order_by'] )){ |
|
2468 | 2474 | $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
2469 | 2475 | if(isset($query_params['order'])){ |
2470 | 2476 | $order = $this->_extract_order($query_params['order']); |
2471 | - }else{ |
|
2477 | + } else{ |
|
2472 | 2478 | $order = 'DESC'; |
2473 | 2479 | } |
2474 | 2480 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2491,7 +2497,7 @@ discard block |
||
2491 | 2497 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2492 | 2498 | } |
2493 | 2499 | $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
2494 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2500 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2495 | 2501 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2496 | 2502 | } |
2497 | 2503 | } |
@@ -2515,8 +2521,9 @@ discard block |
||
2515 | 2521 | } |
2516 | 2522 | } |
2517 | 2523 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2518 | - if ( empty( $main_model_join_sql ) ) |
|
2519 | - $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2524 | + if ( empty( $main_model_join_sql ) ) { |
|
2525 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2526 | + } |
|
2520 | 2527 | return $query_object; |
2521 | 2528 | } |
2522 | 2529 | |
@@ -2549,7 +2556,7 @@ discard block |
||
2549 | 2556 | private function _extract_order($should_be_order_string){ |
2550 | 2557 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
2551 | 2558 | return $should_be_order_string; |
2552 | - }else{ |
|
2559 | + } else{ |
|
2553 | 2560 | throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
2554 | 2561 | } |
2555 | 2562 | } |
@@ -2575,7 +2582,7 @@ discard block |
||
2575 | 2582 | } |
2576 | 2583 | if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
2577 | 2584 | $universal_query_params = $this->_get_default_where_conditions(); |
2578 | - }else{ |
|
2585 | + } else{ |
|
2579 | 2586 | $universal_query_params = array(); |
2580 | 2587 | } |
2581 | 2588 | |
@@ -2615,14 +2622,14 @@ discard block |
||
2615 | 2622 | foreach($default_where_conditions as $key => $val){ |
2616 | 2623 | if( isset($provided_where_conditions[$key])){ |
2617 | 2624 | $none_overridden = false; |
2618 | - }else{ |
|
2625 | + } else{ |
|
2619 | 2626 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2620 | 2627 | } |
2621 | 2628 | } |
2622 | 2629 | if( $none_overridden && $default_where_conditions){ |
2623 | 2630 | if($model->has_primary_key_field()){ |
2624 | 2631 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2625 | - }else{ |
|
2632 | + } else{ |
|
2626 | 2633 | //@todo NO PK, use other defaults |
2627 | 2634 | } |
2628 | 2635 | } |
@@ -2638,8 +2645,9 @@ discard block |
||
2638 | 2645 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2639 | 2646 | */ |
2640 | 2647 | private function _get_default_where_conditions($model_relation_path = null){ |
2641 | - if ( $this->_ignore_where_strategy ) |
|
2642 | - return array(); |
|
2648 | + if ( $this->_ignore_where_strategy ) { |
|
2649 | + return array(); |
|
2650 | + } |
|
2643 | 2651 | |
2644 | 2652 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
2645 | 2653 | } |
@@ -2713,7 +2721,7 @@ discard block |
||
2713 | 2721 | if(array_key_exists($query_param,$this_model_fields)){ |
2714 | 2722 | if($allow_fields){ |
2715 | 2723 | return; |
2716 | - }else{ |
|
2724 | + } else{ |
|
2717 | 2725 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
2718 | 2726 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
2719 | 2727 | } |
@@ -2722,7 +2730,7 @@ discard block |
||
2722 | 2730 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
2723 | 2731 | if($allow_logic_query_params){ |
2724 | 2732 | return; |
2725 | - }else{ |
|
2733 | + } else{ |
|
2726 | 2734 | throw new EE_Error( |
2727 | 2735 | sprintf( |
2728 | 2736 | __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
@@ -2753,12 +2761,12 @@ discard block |
||
2753 | 2761 | //we should actually end in a field name, not a model like this! |
2754 | 2762 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2755 | 2763 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
2756 | - }else{ |
|
2764 | + } else{ |
|
2757 | 2765 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2758 | 2766 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2759 | 2767 | return; |
2760 | 2768 | } |
2761 | - }elseif($query_param == $valid_related_model_name){ |
|
2769 | + } elseif($query_param == $valid_related_model_name){ |
|
2762 | 2770 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
2763 | 2771 | return; |
2764 | 2772 | } |
@@ -2818,7 +2826,7 @@ discard block |
||
2818 | 2826 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
2819 | 2827 | if($SQL){ |
2820 | 2828 | return " WHERE ". $SQL; |
2821 | - }else{ |
|
2829 | + } else{ |
|
2822 | 2830 | return ''; |
2823 | 2831 | } |
2824 | 2832 | } |
@@ -2833,7 +2841,7 @@ discard block |
||
2833 | 2841 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
2834 | 2842 | if($SQL){ |
2835 | 2843 | return " HAVING ". $SQL; |
2836 | - }else{ |
|
2844 | + } else{ |
|
2837 | 2845 | return ''; |
2838 | 2846 | } |
2839 | 2847 | |
@@ -2856,7 +2864,7 @@ discard block |
||
2856 | 2864 | $model_instance=call_user_func($model_name."::instance"); |
2857 | 2865 | /* @var $model_instance EEM_Base */ |
2858 | 2866 | return $model_instance->field_settings_for($field_name); |
2859 | - }else{ |
|
2867 | + } else{ |
|
2860 | 2868 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
2861 | 2869 | } |
2862 | 2870 | } |
@@ -2889,14 +2897,14 @@ discard block |
||
2889 | 2897 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
2890 | 2898 | break; |
2891 | 2899 | } |
2892 | - }else{ |
|
2900 | + } else{ |
|
2893 | 2901 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
2894 | 2902 | |
2895 | 2903 | //if it's not a normal field, maybe it's a custom selection? |
2896 | 2904 | if( ! $field_obj){ |
2897 | 2905 | if(isset( $this->_custom_selections[$query_param][1])){ |
2898 | 2906 | $field_obj = $this->_custom_selections[$query_param][1]; |
2899 | - }else{ |
|
2907 | + } else{ |
|
2900 | 2908 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
2901 | 2909 | } |
2902 | 2910 | } |
@@ -2906,7 +2914,7 @@ discard block |
||
2906 | 2914 | } |
2907 | 2915 | if($where_clauses){ |
2908 | 2916 | $SQL = implode($glue,$where_clauses); |
2909 | - }else{ |
|
2917 | + } else{ |
|
2910 | 2918 | $SQL = ''; |
2911 | 2919 | } |
2912 | 2920 | return $SQL; |
@@ -2926,11 +2934,11 @@ discard block |
||
2926 | 2934 | if( $field ){ |
2927 | 2935 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
2928 | 2936 | return $table_alias_prefix . $field->get_qualified_column(); |
2929 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2937 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2930 | 2938 | //maybe it's custom selection item? |
2931 | 2939 | //if so, just use it as the "column name" |
2932 | 2940 | return $query_param; |
2933 | - }else{ |
|
2941 | + } else{ |
|
2934 | 2942 | throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
2935 | 2943 | } |
2936 | 2944 | } |
@@ -2947,7 +2955,7 @@ discard block |
||
2947 | 2955 | $pos_of_star = strpos($condition_query_param_key, '*'); |
2948 | 2956 | if($pos_of_star === FALSE){ |
2949 | 2957 | return $condition_query_param_key; |
2950 | - }else{ |
|
2958 | + } else{ |
|
2951 | 2959 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
2952 | 2960 | return $condition_query_param_sans_star; |
2953 | 2961 | } |
@@ -2973,7 +2981,7 @@ discard block |
||
2973 | 2981 | throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
2974 | 2982 | } |
2975 | 2983 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
2976 | - }else{ |
|
2984 | + } else{ |
|
2977 | 2985 | $operator = '='; |
2978 | 2986 | $value = $op_and_value; |
2979 | 2987 | } |
@@ -2981,7 +2989,7 @@ discard block |
||
2981 | 2989 | //check to see if the value is actually another field |
2982 | 2990 | if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
2983 | 2991 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
2984 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
2992 | + } elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
2985 | 2993 | //in this case, the value should be an array, or at least a comma-separated list |
2986 | 2994 | //it will need to handle a little differently |
2987 | 2995 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
@@ -2989,8 +2997,9 @@ discard block |
||
2989 | 2997 | return $operator.SP.$cleaned_value; |
2990 | 2998 | } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
2991 | 2999 | //the value should be an array with count of two. |
2992 | - if ( count($value) !== 2 ) |
|
2993 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3000 | + if ( count($value) !== 2 ) { |
|
3001 | + throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3002 | + } |
|
2994 | 3003 | $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
2995 | 3004 | return $operator.SP.$cleaned_value; |
2996 | 3005 | } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
@@ -2998,17 +3007,17 @@ discard block |
||
2998 | 3007 | throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
2999 | 3008 | } |
3000 | 3009 | return $operator; |
3001 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3010 | + } elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3002 | 3011 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3003 | 3012 | //remove other junk. So just treat it as a string. |
3004 | 3013 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3005 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3014 | + } elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3006 | 3015 | return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
3007 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3016 | + } elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3008 | 3017 | throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
3009 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3018 | + } elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3010 | 3019 | throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
3011 | - }else{ |
|
3020 | + } else{ |
|
3012 | 3021 | throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
3013 | 3022 | } |
3014 | 3023 | } |
@@ -3078,7 +3087,7 @@ discard block |
||
3078 | 3087 | global $wpdb; |
3079 | 3088 | if($field_obj instanceof EE_Model_Field_Base){ |
3080 | 3089 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3081 | - }else{//$field_obj should really just be a data type |
|
3090 | + } else{//$field_obj should really just be a data type |
|
3082 | 3091 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3083 | 3092 | throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
3084 | 3093 | } |
@@ -3107,14 +3116,14 @@ discard block |
||
3107 | 3116 | if($number_of_parts == 1){ |
3108 | 3117 | $field_name = $last_query_param_part; |
3109 | 3118 | $model_obj = $this; |
3110 | - }else{// $number_of_parts >= 2 |
|
3119 | + } else{// $number_of_parts >= 2 |
|
3111 | 3120 | //the last part is the column name, and there are only 2parts. therefore... |
3112 | 3121 | $field_name = $last_query_param_part; |
3113 | 3122 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3114 | 3123 | } |
3115 | 3124 | try{ |
3116 | 3125 | return $model_obj->field_settings_for($field_name); |
3117 | - }catch(EE_Error $e){ |
|
3126 | + } catch(EE_Error $e){ |
|
3118 | 3127 | return null; |
3119 | 3128 | } |
3120 | 3129 | } |
@@ -3133,7 +3142,7 @@ discard block |
||
3133 | 3142 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3134 | 3143 | if($field){ |
3135 | 3144 | return $field->get_qualified_column(); |
3136 | - }else{ |
|
3145 | + } else{ |
|
3137 | 3146 | throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
3138 | 3147 | } |
3139 | 3148 | } |
@@ -3199,7 +3208,7 @@ discard block |
||
3199 | 3208 | //the FROM statement, BUT the primary table isn't. So we want |
3200 | 3209 | //to add the inverse join sql |
3201 | 3210 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3202 | - }else{ |
|
3211 | + } else{ |
|
3203 | 3212 | //just add a regular JOIN to this table from the primary table |
3204 | 3213 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3205 | 3214 | } |
@@ -3314,7 +3323,7 @@ discard block |
||
3314 | 3323 | $fieldSettings = $this->field_settings(true); |
3315 | 3324 | if( isset($fieldSettings[$fieldName])){ |
3316 | 3325 | return true; |
3317 | - }else{ |
|
3326 | + } else{ |
|
3318 | 3327 | return false; |
3319 | 3328 | } |
3320 | 3329 | } |
@@ -3328,7 +3337,7 @@ discard block |
||
3328 | 3337 | $relations = $this->relation_settings(); |
3329 | 3338 | if(isset($relations[$relation_name])){ |
3330 | 3339 | return true; |
3331 | - }else{ |
|
3340 | + } else{ |
|
3332 | 3341 | return false; |
3333 | 3342 | } |
3334 | 3343 | } |
@@ -3379,7 +3388,7 @@ discard block |
||
3379 | 3388 | try{ |
3380 | 3389 | $this->get_primary_key_field(); |
3381 | 3390 | $this->_has_primary_key_field = true; |
3382 | - }catch(EE_Error $e){ |
|
3391 | + } catch(EE_Error $e){ |
|
3383 | 3392 | $this->_has_primary_key_field = false; |
3384 | 3393 | } |
3385 | 3394 | } |
@@ -3458,7 +3467,7 @@ discard block |
||
3458 | 3467 | } |
3459 | 3468 | } |
3460 | 3469 | return $this->_cached_fields; |
3461 | - }else{ |
|
3470 | + } else{ |
|
3462 | 3471 | if( $this->_cached_fields_non_db_only === NULL ){ |
3463 | 3472 | $this->_cached_fields_non_db_only = array(); |
3464 | 3473 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -3574,7 +3583,7 @@ discard block |
||
3574 | 3583 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
3575 | 3584 | return NULL; |
3576 | 3585 | } |
3577 | - }else if($this->unique_indexes()){ |
|
3586 | + } else if($this->unique_indexes()){ |
|
3578 | 3587 | $first_column = reset($this_model_fields_n_values); |
3579 | 3588 | if(empty($first_column)){ |
3580 | 3589 | return NULL; |
@@ -3589,7 +3598,7 @@ discard block |
||
3589 | 3598 | // add this new object to the entity map |
3590 | 3599 | $classInstance = $this->add_to_entity_map( $classInstance ); |
3591 | 3600 | } |
3592 | - }else{ |
|
3601 | + } else{ |
|
3593 | 3602 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
3594 | 3603 | } |
3595 | 3604 | |
@@ -3676,11 +3685,12 @@ discard block |
||
3676 | 3685 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
3677 | 3686 | } |
3678 | 3687 | } |
3679 | - }else{ |
|
3688 | + } else{ |
|
3680 | 3689 | //the table's rows existed. Use their values |
3681 | 3690 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
3682 | - if( ! $field_obj->is_db_only_field() ) |
|
3683 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
3691 | + if( ! $field_obj->is_db_only_field() ) { |
|
3692 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
3693 | + } |
|
3684 | 3694 | } |
3685 | 3695 | } |
3686 | 3696 | } |
@@ -3694,9 +3704,9 @@ discard block |
||
3694 | 3704 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
3695 | 3705 | $value = $cols_n_values[ $qualified_column ]; |
3696 | 3706 | |
3697 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3707 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3698 | 3708 | $value = $cols_n_values[ $regular_column ]; |
3699 | - }else{ |
|
3709 | + } else{ |
|
3700 | 3710 | $value = NULL; |
3701 | 3711 | } |
3702 | 3712 | |
@@ -3729,7 +3739,7 @@ discard block |
||
3729 | 3739 | } |
3730 | 3740 | } |
3731 | 3741 | return $obj_in_map; |
3732 | - }else{ |
|
3742 | + } else{ |
|
3733 | 3743 | return $this->get_one_by_ID( $id ); |
3734 | 3744 | } |
3735 | 3745 | } |
@@ -3764,7 +3774,7 @@ discard block |
||
3764 | 3774 | } |
3765 | 3775 | } |
3766 | 3776 | return $obj_in_map; |
3767 | - }else{ |
|
3777 | + } else{ |
|
3768 | 3778 | $this->add_to_entity_map( $replacing_model_obj ); |
3769 | 3779 | return $replacing_model_obj; |
3770 | 3780 | } |
@@ -3794,7 +3804,7 @@ discard block |
||
3794 | 3804 | public function item_name($quantity = 1){ |
3795 | 3805 | if($quantity == 1){ |
3796 | 3806 | return $this->singular_item; |
3797 | - }else{ |
|
3807 | + } else{ |
|
3798 | 3808 | return $this->plural_item; |
3799 | 3809 | } |
3800 | 3810 | } |
@@ -3856,14 +3866,14 @@ discard block |
||
3856 | 3866 | $primary_key_field = $this->get_primary_key_field(); |
3857 | 3867 | if( $base_class_obj_or_id instanceof $className ){ |
3858 | 3868 | $model_object = $base_class_obj_or_id; |
3859 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3869 | + } elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3860 | 3870 | is_int( $base_class_obj_or_id ) || |
3861 | 3871 | is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
3862 | 3872 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
3863 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
3873 | + } elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
3864 | 3874 | //assume its a string representation of the object |
3865 | 3875 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
3866 | - }else{ |
|
3876 | + } else{ |
|
3867 | 3877 | throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
3868 | 3878 | } |
3869 | 3879 | if( $model_object->ID() == NULL && $ensure_is_in_db){ |
@@ -3887,13 +3897,13 @@ discard block |
||
3887 | 3897 | if( $base_class_obj_or_id instanceof $className ){ |
3888 | 3898 | /** @var $base_class_obj_or_id EE_Base_Class */ |
3889 | 3899 | $id = $base_class_obj_or_id->ID(); |
3890 | - }elseif(is_int($base_class_obj_or_id)){ |
|
3900 | + } elseif(is_int($base_class_obj_or_id)){ |
|
3891 | 3901 | //assume it's an ID |
3892 | 3902 | $id = $base_class_obj_or_id; |
3893 | - }elseif(is_string($base_class_obj_or_id)){ |
|
3903 | + } elseif(is_string($base_class_obj_or_id)){ |
|
3894 | 3904 | //assume its a string representation of the object |
3895 | 3905 | $id = $base_class_obj_or_id; |
3896 | - }else{ |
|
3906 | + } else{ |
|
3897 | 3907 | throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
3898 | 3908 | } |
3899 | 3909 | return $id; |
@@ -4024,9 +4034,9 @@ discard block |
||
4024 | 4034 | |
4025 | 4035 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4026 | 4036 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4027 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4037 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4028 | 4038 | $attributes_array = $model_object_or_attributes_array; |
4029 | - }else{ |
|
4039 | + } else{ |
|
4030 | 4040 | throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
4031 | 4041 | } |
4032 | 4042 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4036,7 +4046,7 @@ discard block |
||
4036 | 4046 | } |
4037 | 4047 | if(isset($query_params[0])){ |
4038 | 4048 | $query_params[0] = array_merge($attributes_array,$query_params); |
4039 | - }else{ |
|
4049 | + } else{ |
|
4040 | 4050 | $query_params[0] = $attributes_array; |
4041 | 4051 | } |
4042 | 4052 | return $this->get_all($query_params); |
@@ -4059,7 +4069,7 @@ discard block |
||
4059 | 4069 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4060 | 4070 | if(is_array($copies)){ |
4061 | 4071 | return array_shift($copies); |
4062 | - }else{ |
|
4072 | + } else{ |
|
4063 | 4073 | return null; |
4064 | 4074 | } |
4065 | 4075 | } |
@@ -4091,7 +4101,7 @@ discard block |
||
4091 | 4101 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4092 | 4102 | if($sql_operator){ |
4093 | 4103 | return $sql_operator; |
4094 | - }else{ |
|
4104 | + } else{ |
|
4095 | 4105 | throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
4096 | 4106 | } |
4097 | 4107 | } |
@@ -4262,7 +4272,7 @@ discard block |
||
4262 | 4272 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4263 | 4273 | if( in_array( $context, $valid_cap_contexts ) ) { |
4264 | 4274 | return true; |
4265 | - }else{ |
|
4275 | + } else{ |
|
4266 | 4276 | throw new EE_Error( |
4267 | 4277 | sprintf( |
4268 | 4278 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
118 | 118 | * @param mixed $message array|string of the message you want to record |
119 | 119 | * @param EE_Base_Class $related_model_obj |
120 | - * @return EE_Change_Log |
|
120 | + * @return EE_Attendee |
|
121 | 121 | */ |
122 | 122 | public function log($log_type,$message,$related_model_obj){ |
123 | 123 | if($related_model_obj instanceof EE_Base_Class){ |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param mixed $related_obj_id |
146 | 146 | * @param string $related_obj_type |
147 | 147 | * @throws EE_Error |
148 | - * @return EE_Change_Log |
|
148 | + * @return EE_Attendee |
|
149 | 149 | */ |
150 | 150 | public function gateway_log( $message, $related_obj_id, $related_obj_type ){ |
151 | 151 | if( ! EE_Registry::instance()->is_model_name($related_obj_type)){ |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EEM_Change_Log extends EEM_Base{ |
|
28 | +class EEM_Change_Log extends EEM_Base { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * the related object was created log type |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | * @access protected |
69 | 69 | * @return EEM_Change_Log |
70 | 70 | */ |
71 | - protected function __construct( $timezone = null ){ |
|
71 | + protected function __construct($timezone = null) { |
|
72 | 72 | global $current_user; |
73 | - $this->singular_item = __('Log','event_espresso'); |
|
74 | - $this->plural_item = __('Logs','event_espresso'); |
|
73 | + $this->singular_item = __('Log', 'event_espresso'); |
|
74 | + $this->plural_item = __('Logs', 'event_espresso'); |
|
75 | 75 | $this->_tables = array( |
76 | 76 | 'Log'=> new EE_Primary_Table('esp_log', 'LOG_ID') |
77 | 77 | ); |
78 | 78 | $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
79 | 79 | $this->_fields = array( |
80 | 80 | 'Log'=>array( |
81 | - 'LOG_ID'=> new EE_Primary_Key_Int_Field('LOG_ID', __('Log ID','event_espresso')), |
|
81 | + 'LOG_ID'=> new EE_Primary_Key_Int_Field('LOG_ID', __('Log ID', 'event_espresso')), |
|
82 | 82 | 'LOG_time'=>new EE_Datetime_Field('LOG_time', __("Log Time", 'event_espresso'), false, time()), |
83 | - 'OBJ_ID'=>new EE_Foreign_Key_String_Field('OBJ_ID', __("Object ID (int or string)", 'event_espresso'), true, NULL,$models_this_can_attach_to), |
|
83 | + 'OBJ_ID'=>new EE_Foreign_Key_String_Field('OBJ_ID', __("Object ID (int or string)", 'event_espresso'), true, NULL, $models_this_can_attach_to), |
|
84 | 84 | 'OBJ_type'=>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Object Type", 'event_espresso'), true, NULL, $models_this_can_attach_to), |
85 | 85 | 'LOG_type'=>new EE_Enum_Text_Field('LOG_type', __("Type of log entry", "event_espresso"), false, self::type_debug, |
86 | 86 | array( |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | self::type_gateway=> __("Gateway Interaction (IPN or Direct Payment)", 'event_espresso'), |
93 | 93 | )), |
94 | 94 | 'LOG_message'=>new EE_Maybe_Serialized_Text_Field('LOG_message', __("Log Message (body)", 'event_espresso'), true), |
95 | - 'LOG_wp_user' => new EE_WP_User_Field('LOG_wp_user', __("User who was logged in while this occurred", 'event_espresso'), true ), |
|
95 | + 'LOG_wp_user' => new EE_WP_User_Field('LOG_wp_user', __("User who was logged in while this occurred", 'event_espresso'), true), |
|
96 | 96 | |
97 | 97 | )); |
98 | 98 | $this->_model_relations = array(); |
99 | - foreach($models_this_can_attach_to as $model){ |
|
100 | - if( $model == 'WP_User' ){ |
|
101 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
|
102 | - }elseif( $model != 'Change_Log' ) { |
|
99 | + foreach ($models_this_can_attach_to as $model) { |
|
100 | + if ($model == 'WP_User') { |
|
101 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
102 | + }elseif ($model != 'Change_Log') { |
|
103 | 103 | $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | //use completely custom caps for this |
107 | 107 | $this->_cap_restriction_generators = false; |
108 | 108 | //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
109 | - foreach( $this->_cap_contexts_to_cap_action_map as $cap_context => $action ) { |
|
110 | - $this->_cap_restrictions[ $cap_context ][ EE_Restriction_Generator_Base::get_default_restrictions_cap() ] = new EE_Return_None_Where_Conditions(); |
|
109 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
110 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] = new EE_Return_None_Where_Conditions(); |
|
111 | 111 | } |
112 | - parent::__construct( $timezone ); |
|
112 | + parent::__construct($timezone); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @param EE_Base_Class $related_model_obj |
120 | 120 | * @return EE_Change_Log |
121 | 121 | */ |
122 | - public function log($log_type,$message,$related_model_obj){ |
|
123 | - if($related_model_obj instanceof EE_Base_Class){ |
|
122 | + public function log($log_type, $message, $related_model_obj) { |
|
123 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
124 | 124 | $obj_id = $related_model_obj->ID(); |
125 | 125 | $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
126 | - }else{ |
|
126 | + } else { |
|
127 | 127 | $obj_id = NULL; |
128 | 128 | $obj_type = NULL; |
129 | 129 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * @throws EE_Error |
148 | 148 | * @return EE_Change_Log |
149 | 149 | */ |
150 | - public function gateway_log( $message, $related_obj_id, $related_obj_type ){ |
|
151 | - if( ! EE_Registry::instance()->is_model_name($related_obj_type)){ |
|
152 | - throw new EE_Error(sprintf(__("'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", "event_espresso"),$related_obj_type)); |
|
150 | + public function gateway_log($message, $related_obj_id, $related_obj_type) { |
|
151 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
152 | + throw new EE_Error(sprintf(__("'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", "event_espresso"), $related_obj_type)); |
|
153 | 153 | } |
154 | 154 | $log = EE_Change_Log::new_instance(array( |
155 | 155 | 'LOG_type'=>EEM_Change_Log::type_gateway, |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param array $query_params @see EEM_Base::get_all |
169 | 169 | * @return array of arrays |
170 | 170 | */ |
171 | - public function get_all_efficiently($query_params){ |
|
171 | + public function get_all_efficiently($query_params) { |
|
172 | 172 | return $this->_get_all_wpdb_results($query_params); |
173 | 173 | } |
174 | 174 |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | +} |
|
5 | 6 | |
6 | 7 | /** |
7 | 8 | * Event Espresso |
@@ -99,7 +100,7 @@ discard block |
||
99 | 100 | foreach($models_this_can_attach_to as $model){ |
100 | 101 | if( $model == 'WP_User' ){ |
101 | 102 | $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
102 | - }elseif( $model != 'Change_Log' ) { |
|
103 | + } elseif( $model != 'Change_Log' ) { |
|
103 | 104 | $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
104 | 105 | } |
105 | 106 | } |
@@ -123,7 +124,7 @@ discard block |
||
123 | 124 | if($related_model_obj instanceof EE_Base_Class){ |
124 | 125 | $obj_id = $related_model_obj->ID(); |
125 | 126 | $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
126 | - }else{ |
|
127 | + } else{ |
|
127 | 128 | $obj_id = NULL; |
128 | 129 | $obj_type = NULL; |
129 | 130 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @public |
136 | 136 | * @param int $EVT_ID event id |
137 | 137 | * @param bolean $include_expired |
138 | - * @param boolean $inlude_deleted |
|
138 | + * @param boolean $include_deleted |
|
139 | 139 | * @param int $limit If included then limit the count of results by |
140 | 140 | * the given number |
141 | 141 | * @return EE_Datetime[] |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | /** |
184 | 184 | * |
185 | - * @param type $EVT_ID |
|
185 | + * @param integer $EVT_ID |
|
186 | 186 | * @param type $include_expired |
187 | 187 | * @param type $include_deleted |
188 | 188 | * @return EE_Datetime |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * only by start date |
222 | 222 | * @param int $EVT_ID |
223 | 223 | * @param bolean $include_expired |
224 | - * @param boolean $inlude_deleted |
|
224 | + * @param boolean $include_deleted |
|
225 | 225 | * @param int $limit |
226 | 226 | * @return EE_Datetime[] |
227 | 227 | */ |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * only by start date |
251 | 251 | * @param int $TKT_ID |
252 | 252 | * @param bolean $include_expired |
253 | - * @param boolean $inlude_deleted |
|
253 | + * @param boolean $include_deleted |
|
254 | 254 | * @param int $limit |
255 | 255 | * @return EE_Datetime[] |
256 | 256 | */ |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | /** |
329 | 329 | * This returns a wpdb->results array of all DTT month and years matching the incoming query params and grouped by month and year. |
330 | - * @param array $query_params Array of query_parms as described in the comments for EEM_Base::get_all() |
|
330 | + * @param array $where_params Array of query_parms as described in the comments for EEM_Base::get_all() |
|
331 | 331 | * @param string $evt_active_status A string representing the evt active status to filter the months by. Can be: |
332 | 332 | * - '' = no filter |
333 | 333 | * - upcoming = Published events with at least one upcoming datetime. |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | |
77 | 77 | |
78 | 78 | /** |
79 | - * create new blank datetime |
|
80 | - * |
|
81 | - * @access public |
|
82 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
83 | - */ |
|
79 | + * create new blank datetime |
|
80 | + * |
|
81 | + * @access public |
|
82 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
83 | + */ |
|
84 | 84 | public function create_new_blank_datetime() { |
85 | 85 | $times = array( |
86 | 86 | EE_Datetime::new_instance( |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | |
108 | 108 | |
109 | 109 | /** |
110 | - * get event start date from db |
|
111 | - * |
|
112 | - * @access public |
|
113 | - * @param int $EVT_ID |
|
114 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
115 | - */ |
|
110 | + * get event start date from db |
|
111 | + * |
|
112 | + * @access public |
|
113 | + * @param int $EVT_ID |
|
114 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
115 | + */ |
|
116 | 116 | public function get_all_event_dates( $EVT_ID = FALSE ) { |
117 | 117 | if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0 |
118 | 118 | return $this->create_new_blank_datetime(); |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
249 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
250 | - * only by start date |
|
251 | - * @param int $TKT_ID |
|
252 | - * @param bolean $include_expired |
|
253 | - * @param boolean $inlude_deleted |
|
254 | - * @param int $limit |
|
255 | - * @return EE_Datetime[] |
|
256 | - */ |
|
249 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
250 | + * only by start date |
|
251 | + * @param int $TKT_ID |
|
252 | + * @param bolean $include_expired |
|
253 | + * @param boolean $inlude_deleted |
|
254 | + * @param int $limit |
|
255 | + * @return EE_Datetime[] |
|
256 | + */ |
|
257 | 257 | public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){ |
258 | 258 | //sanitize TKT_ID |
259 | 259 | $TKT_ID = intval( $TKT_ID ); |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * |
22 | 22 | * ------------------------------------------------------------------------ |
23 | 23 | */ |
24 | -require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' ); |
|
25 | -require_once ( EE_CLASSES . 'EE_Datetime.class.php' ); |
|
24 | +require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
25 | +require_once (EE_CLASSES.'EE_Datetime.class.php'); |
|
26 | 26 | |
27 | 27 | class EEM_Datetime extends EEM_Soft_Delete_Base { |
28 | 28 | |
@@ -36,27 +36,27 @@ discard block |
||
36 | 36 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - protected function __construct( $timezone ) { |
|
40 | - $this->singular_item = __('Datetime','event_espresso'); |
|
41 | - $this->plural_item = __('Datetimes','event_espresso'); |
|
39 | + protected function __construct($timezone) { |
|
40 | + $this->singular_item = __('Datetime', 'event_espresso'); |
|
41 | + $this->plural_item = __('Datetimes', 'event_espresso'); |
|
42 | 42 | |
43 | 43 | $this->_tables = array( |
44 | 44 | 'Datetime'=> new EE_Primary_Table('esp_datetime', 'DTT_ID') |
45 | 45 | ); |
46 | 46 | $this->_fields = array( |
47 | 47 | 'Datetime'=>array( |
48 | - 'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID','event_espresso')), |
|
49 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'), |
|
48 | + 'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')), |
|
49 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
50 | 50 | 'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, ''), |
51 | 51 | 'DTT_description' => new EE_Full_HTML_Field('DTT_description', __('Description for Datetime', 'event_espresso'), false, ''), |
52 | - 'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event','event_espresso'), false, time(), $timezone ), |
|
53 | - 'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event','event_espresso'), false, time(), $timezone ), |
|
54 | - 'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time','event_espresso'), true, INF), |
|
55 | - 'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0 ), |
|
56 | - 'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false,false), |
|
52 | + 'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, time(), $timezone), |
|
53 | + 'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, time(), $timezone), |
|
54 | + 'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, INF), |
|
55 | + 'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0), |
|
56 | + 'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false, false), |
|
57 | 57 | 'DTT_order' => new EE_Integer_Field('DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0), |
58 | - 'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0 ), |
|
59 | - 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false ), |
|
58 | + 'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0), |
|
59 | + 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false), |
|
60 | 60 | )); |
61 | 61 | $this->_model_relations = array( |
62 | 62 | 'Ticket'=>new EE_HABTM_Relation('Datetime_Ticket'), |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | ); |
66 | 66 | $this->_model_chain_to_wp_user = 'Event'; |
67 | 67 | //this model is generally available for reading |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( 'Event' ); |
|
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' ); |
|
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event', EEM_Base::caps_edit ); |
|
72 | - parent::__construct( $timezone ); |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
70 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
72 | + parent::__construct($timezone); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | $times = array( |
86 | 86 | EE_Datetime::new_instance( |
87 | 87 | array( |
88 | - 'DTT_EVT_start' => $this->current_time_for_query( 'DTT_EVT_start', true ) + (60 * 60 * 24 * 30), |
|
89 | - 'DTT_EVT_end' => $this->current_time_for_query( 'DTT_EVT_end', true ) + (60 * 60 * 24 * 30), |
|
88 | + 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30), |
|
89 | + 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30), |
|
90 | 90 | // 'DTT_is_primary' => 1, |
91 | 91 | 'DTT_order' => 1, |
92 | 92 | 'DTT_reg_limit' => INF |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - $times[0]->set_start_time( $this->convert_datetime_for_query( 'DTT_EVT_start', '8am', 'ga', $this->_timezone ) ); |
|
101 | - $times[0]->set_end_time( $this->convert_datetime_for_query( 'DTT_EVT_end', '5pm', 'ga', $this->_timezone ) ); |
|
100 | + $times[0]->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', $this->_timezone)); |
|
101 | + $times[0]->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone)); |
|
102 | 102 | return $times; |
103 | 103 | } |
104 | 104 | |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * @param int $EVT_ID |
114 | 114 | * @return EE_Datetime[] array on success, FALSE on fail |
115 | 115 | */ |
116 | - public function get_all_event_dates( $EVT_ID = FALSE ) { |
|
117 | - if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0 |
|
116 | + public function get_all_event_dates($EVT_ID = FALSE) { |
|
117 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
118 | 118 | return $this->create_new_blank_datetime(); |
119 | 119 | } |
120 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
120 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
121 | 121 | |
122 | - if ( empty( $results ) ) { |
|
122 | + if (empty($results)) { |
|
123 | 123 | return $this->create_new_blank_datetime(); |
124 | 124 | } |
125 | 125 | |
@@ -140,26 +140,26 @@ discard block |
||
140 | 140 | * the given number |
141 | 141 | * @return EE_Datetime[] |
142 | 142 | */ |
143 | - public function get_datetimes_for_event_ordered_by_DTT_order( $EVT_ID, $include_expired = TRUE, $include_deleted= TRUE, $limit = NULL ) { |
|
143 | + public function get_datetimes_for_event_ordered_by_DTT_order($EVT_ID, $include_expired = TRUE, $include_deleted = TRUE, $limit = NULL) { |
|
144 | 144 | |
145 | 145 | //sanitize EVT_ID |
146 | - $EVT_ID = intval( $EVT_ID ); |
|
146 | + $EVT_ID = intval($EVT_ID); |
|
147 | 147 | |
148 | 148 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
149 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
150 | - $where_params = array( 'Event.EVT_ID' => $EVT_ID ); |
|
149 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
150 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
151 | 151 | |
152 | - $query_params = ! empty( $limit ) ? array( $where_params, 'limit' => $limit, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ) : array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ); |
|
152 | + $query_params = ! empty($limit) ? array($where_params, 'limit' => $limit, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none') : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none'); |
|
153 | 153 | |
154 | - if( ! $include_expired){ |
|
155 | - $query_params[0]['DTT_EVT_end'] = array( '>=', current_time( 'mysql', TRUE ) ); |
|
154 | + if ( ! $include_expired) { |
|
155 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
156 | 156 | } |
157 | - if( $include_deleted){ |
|
158 | - $query_params[0]['DTT_deleted'] = array( 'IN', array( TRUE, FALSE )); |
|
157 | + if ($include_deleted) { |
|
158 | + $query_params[0]['DTT_deleted'] = array('IN', array(TRUE, FALSE)); |
|
159 | 159 | } |
160 | 160 | |
161 | - $result = $this->get_all( $query_params ); |
|
162 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
161 | + $result = $this->get_all($query_params); |
|
162 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
163 | 163 | return $result; |
164 | 164 | } |
165 | 165 | |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * @param int $limit |
175 | 175 | * @return EE_Datetime[] |
176 | 176 | */ |
177 | - public function get_datetimes_for_event_ordered_by_importance( $EVT_ID = FALSE, $limit = NULL){ |
|
178 | - return $this->get_all( array(array('Event.EVT_ID'=>$EVT_ID), |
|
177 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = FALSE, $limit = NULL) { |
|
178 | + return $this->get_all(array(array('Event.EVT_ID'=>$EVT_ID), |
|
179 | 179 | 'limit'=>$limit, |
180 | 180 | 'order_by'=>array('DTT_EVT_start'=>'ASC'), |
181 | 181 | 'default_where_conditions' => 'none')); |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | * @param type $include_deleted |
188 | 188 | * @return EE_Datetime |
189 | 189 | */ |
190 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false,$include_deleted = false){ |
|
191 | - $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
192 | - if($results){ |
|
190 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) { |
|
191 | + $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
192 | + if ($results) { |
|
193 | 193 | return array_shift($results); |
194 | - }else{ |
|
194 | + } else { |
|
195 | 195 | return NULL; |
196 | 196 | } |
197 | 197 | } |
@@ -200,16 +200,16 @@ discard block |
||
200 | 200 | * @param int $EVT_ID |
201 | 201 | * @return EE_Datetime |
202 | 202 | */ |
203 | - public function get_primary_datetime_for_event($EVT_ID,$try_to_exclude_expired = true, $try_to_exclude_deleted = true){ |
|
204 | - if($try_to_exclude_expired){ |
|
205 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false,false); |
|
206 | - if($non_expired){ |
|
203 | + public function get_primary_datetime_for_event($EVT_ID, $try_to_exclude_expired = true, $try_to_exclude_deleted = true) { |
|
204 | + if ($try_to_exclude_expired) { |
|
205 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
206 | + if ($non_expired) { |
|
207 | 207 | return $non_expired; |
208 | 208 | } |
209 | 209 | } |
210 | - if($try_to_exclude_deleted){ |
|
210 | + if ($try_to_exclude_deleted) { |
|
211 | 211 | $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
212 | - if($expired_even){ |
|
212 | + if ($expired_even) { |
|
213 | 213 | return $expired_even; |
214 | 214 | } |
215 | 215 | } |
@@ -225,23 +225,23 @@ discard block |
||
225 | 225 | * @param int $limit |
226 | 226 | * @return EE_Datetime[] |
227 | 227 | */ |
228 | - public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted= true, $limit = NULL ){ |
|
228 | + public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
229 | 229 | //sanitize EVT_ID |
230 | - $EVT_ID = intval( $EVT_ID ); |
|
230 | + $EVT_ID = intval($EVT_ID); |
|
231 | 231 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
232 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
233 | - $query_params =array(array('Event.EVT_ID'=>$EVT_ID),'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
234 | - if( ! $include_expired){ |
|
235 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
232 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
233 | + $query_params = array(array('Event.EVT_ID'=>$EVT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
234 | + if ( ! $include_expired) { |
|
235 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
236 | 236 | } |
237 | - if( $include_deleted){ |
|
238 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
237 | + if ($include_deleted) { |
|
238 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
239 | 239 | } |
240 | - if($limit){ |
|
240 | + if ($limit) { |
|
241 | 241 | $query_params['limit'] = $limit; |
242 | 242 | } |
243 | - $result = $this->get_all( $query_params ); |
|
244 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
243 | + $result = $this->get_all($query_params); |
|
244 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
245 | 245 | return $result; |
246 | 246 | } |
247 | 247 | |
@@ -254,23 +254,23 @@ discard block |
||
254 | 254 | * @param int $limit |
255 | 255 | * @return EE_Datetime[] |
256 | 256 | */ |
257 | - public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){ |
|
257 | + public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
258 | 258 | //sanitize TKT_ID |
259 | - $TKT_ID = intval( $TKT_ID ); |
|
259 | + $TKT_ID = intval($TKT_ID); |
|
260 | 260 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
261 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
262 | - $query_params =array(array('Ticket.TKT_ID'=>$TKT_ID),'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
263 | - if( ! $include_expired){ |
|
264 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
261 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
262 | + $query_params = array(array('Ticket.TKT_ID'=>$TKT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
263 | + if ( ! $include_expired) { |
|
264 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
265 | 265 | } |
266 | - if( $include_deleted){ |
|
267 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
266 | + if ($include_deleted) { |
|
267 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
268 | 268 | } |
269 | - if($limit){ |
|
269 | + if ($limit) { |
|
270 | 270 | $query_params['limit'] = $limit; |
271 | 271 | } |
272 | - $result = $this->get_all( $query_params ); |
|
273 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
272 | + $result = $this->get_all($query_params); |
|
273 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
274 | 274 | return $result; |
275 | 275 | } |
276 | 276 | |
@@ -286,24 +286,24 @@ discard block |
||
286 | 286 | * that number |
287 | 287 | * @return EE_Datetime[] |
288 | 288 | */ |
289 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( $TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL ) { |
|
289 | + public function get_datetimes_for_ticket_ordered_by_DTT_order($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
290 | 290 | //sanitize id. |
291 | - $TKT_ID = intval( $TKT_ID ); |
|
291 | + $TKT_ID = intval($TKT_ID); |
|
292 | 292 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
293 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
294 | - $where_params = array( 'Ticket.TKT_ID' => $TKT_ID ); |
|
295 | - $query_params = array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ) ); |
|
296 | - if( ! $include_expired){ |
|
297 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
293 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
294 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
295 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
296 | + if ( ! $include_expired) { |
|
297 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
298 | 298 | } |
299 | - if( $include_deleted){ |
|
300 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
299 | + if ($include_deleted) { |
|
300 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
301 | 301 | } |
302 | - if($limit){ |
|
302 | + if ($limit) { |
|
303 | 303 | $query_params['limit'] = $limit; |
304 | 304 | } |
305 | - $result = $this->get_all( $query_params ); |
|
306 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
305 | + $result = $this->get_all($query_params); |
|
306 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
307 | 307 | return $result; |
308 | 308 | } |
309 | 309 | |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | * @param int $EVT_ID |
315 | 315 | * @return EE_Datetime |
316 | 316 | */ |
317 | - public function get_most_important_datetime_for_event($EVT_ID){ |
|
317 | + public function get_most_important_datetime_for_event($EVT_ID) { |
|
318 | 318 | $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
319 | - if($results){ |
|
319 | + if ($results) { |
|
320 | 320 | return array_shift($results); |
321 | - }else{ |
|
321 | + } else { |
|
322 | 322 | return null; |
323 | 323 | } |
324 | 324 | } |
@@ -337,72 +337,72 @@ discard block |
||
337 | 337 | * - inactive = Events that are either not published. |
338 | 338 | * @return wpdb results array |
339 | 339 | */ |
340 | - public function get_dtt_months_and_years( $where_params, $evt_active_status = '' ) { |
|
340 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') { |
|
341 | 341 | $where_params; |
342 | 342 | |
343 | - switch ( $evt_active_status ) { |
|
343 | + switch ($evt_active_status) { |
|
344 | 344 | case 'upcoming' : |
345 | 345 | $where_params['Event.status'] = 'publish'; |
346 | 346 | //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
347 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
347 | + if (isset($where_params['DTT_EVT_start'])) { |
|
348 | 348 | $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
349 | 349 | } |
350 | - $where_params['DTT_EVT_start'] = array('>', $this->current_time_for_query( 'DTT_EVT_start' ) ); |
|
350 | + $where_params['DTT_EVT_start'] = array('>', $this->current_time_for_query('DTT_EVT_start')); |
|
351 | 351 | break; |
352 | 352 | |
353 | 353 | case 'expired' : |
354 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
354 | + if (isset($where_params['Event.status'])) unset($where_params['Event.status']); |
|
355 | 355 | //get events to exclude |
356 | - $exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $this->current_time_for_query( 'DTT_EVT_end' ) ) ) ); |
|
356 | + $exclude_query[0] = array_merge($where_params, array('DTT_EVT_end' => array('>', $this->current_time_for_query('DTT_EVT_end')))); |
|
357 | 357 | //first get all events that have datetimes where its not expired. |
358 | - $event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Datetime.EVT_ID' ); |
|
359 | - $event_ids = array_keys( $event_ids ); |
|
358 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID'); |
|
359 | + $event_ids = array_keys($event_ids); |
|
360 | 360 | |
361 | - if ( isset( $where_params['DTT_EVT_end'] ) ) { |
|
361 | + if (isset($where_params['DTT_EVT_end'])) { |
|
362 | 362 | $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
363 | 363 | } |
364 | - $where_params['DTT_EVT_end'] = array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
365 | - $where_params['Event.EVT_ID'] = array( 'NOT IN', $event_ids ); |
|
364 | + $where_params['DTT_EVT_end'] = array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
365 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
366 | 366 | break; |
367 | 367 | |
368 | 368 | case 'active' : |
369 | 369 | $where_params['Event.status'] = 'publish'; |
370 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
370 | + if (isset($where_params['DTT_EVT_start'])) { |
|
371 | 371 | $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
372 | 372 | } |
373 | - if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) { |
|
373 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
374 | 374 | $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
375 | 375 | } |
376 | - $where_params['DTT_EVT_start'] = array('<', $this->current_time_for_query( 'DTT_EVT_start' ) ); |
|
377 | - $where_params['DTT_EVT_end'] = array('>', $this->current_time_for_query( 'DTT_EVT_end' ) ); |
|
376 | + $where_params['DTT_EVT_start'] = array('<', $this->current_time_for_query('DTT_EVT_start')); |
|
377 | + $where_params['DTT_EVT_end'] = array('>', $this->current_time_for_query('DTT_EVT_end')); |
|
378 | 378 | break; |
379 | 379 | |
380 | 380 | case 'inactive' : |
381 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
382 | - if ( isset( $where_params['OR'] ) ) { |
|
381 | + if (isset($where_params['Event.status'])) unset($where_params['Event.status']); |
|
382 | + if (isset($where_params['OR'])) { |
|
383 | 383 | $where_params['AND']['OR'] = $where_params['OR']; |
384 | 384 | } |
385 | - if ( isset( $where_params['DTT_EVT_end'] ) ) { |
|
385 | + if (isset($where_params['DTT_EVT_end'])) { |
|
386 | 386 | $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
387 | - unset( $where_params['DTT_EVT_end'] ); |
|
387 | + unset($where_params['DTT_EVT_end']); |
|
388 | 388 | } |
389 | 389 | |
390 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
390 | + if (isset($where_params['DTT_EVT_start'])) { |
|
391 | 391 | $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
392 | - unset( $where_params['DTT_EVT_start'] ); |
|
392 | + unset($where_params['DTT_EVT_start']); |
|
393 | 393 | } |
394 | - $where_params['AND']['Event.status'] = array( '!=', 'publish' ); |
|
394 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
395 | 395 | break; |
396 | 396 | } |
397 | 397 | |
398 | 398 | $query_params[0] = $where_params; |
399 | 399 | $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
400 | - $query_params['order_by'] = array( 'DTT_EVT_start' => 'DESC' ); |
|
400 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
401 | 401 | $columns_to_select = array( |
402 | 402 | 'dtt_year' => array('YEAR(DTT_EVT_start)', '%s'), |
403 | 403 | 'dtt_month' => array('MONTHNAME(DTT_EVT_start)', '%s') |
404 | 404 | ); |
405 | - return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select ); |
|
405 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | * for the tickets for each datetime) |
411 | 411 | * @param EE_Datetime[] $datetimes |
412 | 412 | */ |
413 | - public function update_sold($datetimes){ |
|
414 | - foreach($datetimes as $datetime){ |
|
413 | + public function update_sold($datetimes) { |
|
414 | + foreach ($datetimes as $datetime) { |
|
415 | 415 | $datetime->update_sold(); |
416 | 416 | } |
417 | 417 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -191,7 +193,7 @@ discard block |
||
191 | 193 | $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
192 | 194 | if($results){ |
193 | 195 | return array_shift($results); |
194 | - }else{ |
|
196 | + } else{ |
|
195 | 197 | return NULL; |
196 | 198 | } |
197 | 199 | } |
@@ -318,7 +320,7 @@ discard block |
||
318 | 320 | $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
319 | 321 | if($results){ |
320 | 322 | return array_shift($results); |
321 | - }else{ |
|
323 | + } else{ |
|
322 | 324 | return null; |
323 | 325 | } |
324 | 326 | } |
@@ -351,7 +353,9 @@ discard block |
||
351 | 353 | break; |
352 | 354 | |
353 | 355 | case 'expired' : |
354 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
356 | + if ( isset( $where_params['Event.status'] ) ) { |
|
357 | + unset( $where_params['Event.status'] ); |
|
358 | + } |
|
355 | 359 | //get events to exclude |
356 | 360 | $exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $this->current_time_for_query( 'DTT_EVT_end' ) ) ) ); |
357 | 361 | //first get all events that have datetimes where its not expired. |
@@ -378,7 +382,9 @@ discard block |
||
378 | 382 | break; |
379 | 383 | |
380 | 384 | case 'inactive' : |
381 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
385 | + if ( isset( $where_params['Event.status'] ) ) { |
|
386 | + unset( $where_params['Event.status'] ); |
|
387 | + } |
|
382 | 388 | if ( isset( $where_params['OR'] ) ) { |
383 | 389 | $where_params['AND']['OR'] = $where_params['OR']; |
384 | 390 | } |
@@ -292,7 +292,7 @@ |
||
292 | 292 | * which would happen if some of the registrations had a price modifier while others didn't. |
293 | 293 | * In order to support that, we'd probably need a LIN_ID on registrations or something. |
294 | 294 | * @param EE_Registration $registration |
295 | - * @return EEM_Line_ITem |
|
295 | + * @return EE_Base_Class|null |
|
296 | 296 | */ |
297 | 297 | public function get_line_item_for_registration( EE_Registration $registration ) { |
298 | 298 | return $this->get_one( $this->line_item_for_registration_query_params( $registration )); |
@@ -103,40 +103,40 @@ discard block |
||
103 | 103 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
104 | 104 | * @return \EEM_Line_Item |
105 | 105 | */ |
106 | - protected function __construct( $timezone ) { |
|
107 | - $this->singular_item = __('Line Item','event_espresso'); |
|
108 | - $this->plural_item = __('Line Items','event_espresso'); |
|
106 | + protected function __construct($timezone) { |
|
107 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
108 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
109 | 109 | |
110 | 110 | $this->_tables = array( |
111 | - 'Line_Item'=>new EE_Primary_Table('esp_line_item','LIN_ID') |
|
111 | + 'Line_Item'=>new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
112 | 112 | ); |
113 | - $line_items_can_be_for = apply_filters( 'FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket','Price', 'Event' ) ); |
|
113 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
114 | 114 | $this->_fields = array( |
115 | 115 | 'Line_Item' => array( |
116 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( 'LIN_ID', __( "ID", "event_espresso" ) ), |
|
117 | - 'LIN_code' => new EE_Slug_Field( 'LIN_code', __( "Code for index into Cart", "event_espresso" ), TRUE ), |
|
118 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( 'TXN_ID', __( "Transaction ID", "event_espresso" ), TRUE, NULL, 'Transaction' ), |
|
119 | - 'LIN_name' => new EE_Full_HTML_Field( 'LIN_name', __( "Line Item Name", "event_espresso" ), FALSE, '' ), |
|
120 | - 'LIN_desc' => new EE_Full_HTML_Field( 'LIN_desc', __( "Line Item Description", "event_espresso" ), TRUE ), |
|
121 | - 'LIN_unit_price' => new EE_Money_Field( 'LIN_unit_price', __( "Unit Price", "event_espresso" ), FALSE, 0 ), |
|
122 | - 'LIN_percent' => new EE_Float_Field( 'LIN_percent', __( "Percent", "event_espresso" ), FALSE, 0 ), |
|
123 | - 'LIN_is_taxable' => new EE_Boolean_Field( 'LIN_is_taxable', __( "Taxable", "event_espresso" ), FALSE, FALSE ), |
|
124 | - 'LIN_order' => new EE_Integer_Field( 'LIN_order', __( "Order of Application towards total of parent", "event_espresso" ), FALSE, 1 ), |
|
125 | - 'LIN_total' => new EE_Money_Field( 'LIN_total', __( "Total (unit price x quantity)", "event_espresso" ), FALSE, 0 ), |
|
126 | - 'LIN_quantity' => new EE_Integer_Field( 'LIN_quantity', __( "Quantity", "event_espresso" ), TRUE, 1 ), |
|
127 | - 'LIN_parent' => new EE_Integer_Field( 'LIN_parent', __( "Parent ID (this item goes towards that Line Item's total)", "event_espresso" ), TRUE, NULL ), |
|
128 | - 'LIN_type' => new EE_Enum_Text_Field( 'LIN_type', __( "Type", "event_espresso" ), FALSE, 'line-item', array( |
|
116 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
117 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
118 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
119 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
120 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
121 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
122 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
123 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
124 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
125 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
126 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
127 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
128 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
129 | 129 | self::type_line_item => __("Line Item", "event_espresso"), |
130 | 130 | self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
131 | 131 | self::type_sub_total => __("Subtotal", "event_espresso"), |
132 | 132 | self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
133 | 133 | self::type_tax => __("Tax", "event_espresso"), |
134 | 134 | self::type_total => __("Total", "event_espresso"), |
135 | - self::type_cancellation => __( 'Cancellation', 'event_espresso' ) |
|
135 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
136 | 136 | ) |
137 | 137 | ), |
138 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( 'OBJ_ID', __( 'ID of Item purchased.', 'event_espresso' ), TRUE, NULL, $line_items_can_be_for ), |
|
139 | - 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field( 'OBJ_type', __( "Model Name this Line Item is for", "event_espresso" ), TRUE, NULL, $line_items_can_be_for ), |
|
138 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
139 | + 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
140 | 140 | ) |
141 | 141 | ); |
142 | 142 | $this->_model_relations = array( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | ); |
148 | 148 | $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
149 | 149 | $this->_caps_slug = 'transactions'; |
150 | - parent::__construct( $timezone ); |
|
150 | + parent::__construct($timezone); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param EE_Transaction|int $transaction |
159 | 159 | * @return EE_Line_Item[] |
160 | 160 | */ |
161 | - public function get_all_of_type_for_transaction( $line_item_type, $transaction ){ |
|
162 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
163 | - return $this->get_all( array( array( |
|
161 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) { |
|
162 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
163 | + return $this->get_all(array(array( |
|
164 | 164 | 'LIN_type' => $line_item_type, |
165 | 165 | 'TXN_ID' => $transaction |
166 | 166 | ))); |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @param EE_Transaction|int $transaction |
175 | 175 | * @return \EE_Base_Class[] |
176 | 176 | */ |
177 | - public function get_all_non_ticket_line_items_for_transaction( $transaction ) { |
|
178 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
179 | - return $this->get_all( array( array( |
|
177 | + public function get_all_non_ticket_line_items_for_transaction($transaction) { |
|
178 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
179 | + return $this->get_all(array(array( |
|
180 | 180 | 'LIN_type' => self::type_line_item, |
181 | 181 | 'TXN_ID' => $transaction, |
182 | 182 | 'OR' => array( |
183 | - 'OBJ_type*notticket' => array( '!=', 'Ticket'), |
|
184 | - 'OBJ_type*null' => array( 'IS_NULL' )) |
|
183 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
184 | + 'OBJ_type*null' => array('IS_NULL')) |
|
185 | 185 | ))); |
186 | 186 | } |
187 | 187 | |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | * because if there are spam bots afoot there will be LOTS of line items |
191 | 191 | * @return int count of how many deleted |
192 | 192 | */ |
193 | - public function delete_line_items_with_no_transaction(){ |
|
193 | + public function delete_line_items_with_no_transaction() { |
|
194 | 194 | /** @type WPDB $wpdb */ |
195 | 195 | global $wpdb; |
196 | 196 | return $wpdb->query( |
197 | 197 | 'DELETE li |
198 | - FROM ' . $this->table() . ' li |
|
199 | - LEFT JOIN ' . EEM_Transaction::instance()->table(). ' t ON li.TXN_ID = t.TXN_ID |
|
198 | + FROM ' . $this->table().' li |
|
199 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
200 | 200 | WHERE t.TXN_ID IS NULL' |
201 | 201 | ); |
202 | 202 | } |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | * @param \EE_Base_Class $object |
212 | 212 | * @return EE_Line_Item[] |
213 | 213 | */ |
214 | - public function get_line_item_for_transaction_object( $TXN_ID, EE_Base_Class $object ){ |
|
215 | - return $this->get_all( array( array( |
|
214 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) { |
|
215 | + return $this->get_all(array(array( |
|
216 | 216 | 'TXN_ID' => $TXN_ID, |
217 | - 'OBJ_type' => str_replace( 'EE_', '', get_class( $object )), |
|
217 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
218 | 218 | 'OBJ_ID' => $object->ID() |
219 | 219 | ))); |
220 | 220 | } |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | * @param array $OBJ_IDs |
231 | 231 | * @return EE_Line_Item[] |
232 | 232 | */ |
233 | - public function get_object_line_items_for_transaction( $TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array() ){ |
|
233 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) { |
|
234 | 234 | $query_params = array( |
235 | 235 | 'OBJ_type' => $OBJ_type, |
236 | 236 | // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
237 | - 'OBJ_ID' => is_array( $OBJ_IDs ) && ! isset( $OBJ_IDs['IN'] ) ? array( 'IN', $OBJ_IDs ) : $OBJ_IDs |
|
237 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
238 | 238 | ); |
239 | - if ( $TXN_ID ) { |
|
239 | + if ($TXN_ID) { |
|
240 | 240 | $query_params['TXN_ID'] = $TXN_ID; |
241 | 241 | } |
242 | - return $this->get_all( array( $query_params )); |
|
242 | + return $this->get_all(array($query_params)); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | * @param EE_Promotion $promotion |
255 | 255 | * @return EE_Line_Item |
256 | 256 | */ |
257 | - public function get_existing_promotion_line_item( EE_Line_Item $parent_line_item, EE_Promotion $promotion ) { |
|
258 | - return $this->get_one( array( |
|
257 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) { |
|
258 | + return $this->get_one(array( |
|
259 | 259 | array( |
260 | 260 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
261 | 261 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | * @param EE_Line_Item $parent_line_item |
277 | 277 | * @return EE_Line_Item[] |
278 | 278 | */ |
279 | - public function get_all_promotion_line_items( EE_Line_Item $parent_line_item ) { |
|
280 | - return $this->get_all( array( |
|
279 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) { |
|
280 | + return $this->get_all(array( |
|
281 | 281 | array( |
282 | 282 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
283 | 283 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | * @param EE_Registration $registration |
295 | 295 | * @return EEM_Line_ITem |
296 | 296 | */ |
297 | - public function get_line_item_for_registration( EE_Registration $registration ) { |
|
298 | - return $this->get_one( $this->line_item_for_registration_query_params( $registration )); |
|
297 | + public function get_line_item_for_registration(EE_Registration $registration) { |
|
298 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | * @param array $original_query_params any extra query params you'd like to be merged with |
305 | 305 | * @return array like EEM_Base::get_all()'s $query_params |
306 | 306 | */ |
307 | - public function line_item_for_registration_query_params( EE_Registration $registration, $original_query_params = array() ) { |
|
308 | - return array_replace_recursive( $original_query_params, array( |
|
307 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) { |
|
308 | + return array_replace_recursive($original_query_params, array( |
|
309 | 309 | array( |
310 | 310 | 'OBJ_ID' => $registration->ticket_ID(), |
311 | 311 | 'OBJ_type' => 'Ticket', |
312 | 312 | 'TXN_ID' => $registration->transaction_ID() |
313 | 313 | ) |
314 | - ) ); |
|
314 | + )); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |