@@ -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 |
@@ -152,7 +153,7 @@ discard block |
||
152 | 153 | $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
153 | 154 | if( ! $is_model_name ){ |
154 | 155 | return null; |
155 | - }else{ |
|
156 | + } else{ |
|
156 | 157 | return $this->get_first_related($model_name_of_related_obj); |
157 | 158 | } |
158 | 159 | } |
@@ -169,13 +170,13 @@ discard block |
||
169 | 170 | if($object instanceof EE_Base_Class){ |
170 | 171 | $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
171 | 172 | $this->set_OBJ_ID($object->ID()); |
172 | - }else{ |
|
173 | + } else{ |
|
173 | 174 | $this->set_OBJ_type(NULL); |
174 | 175 | $this->set_OBJ_ID(NULL); |
175 | 176 | } |
176 | 177 | if($save){ |
177 | 178 | return $this->save(); |
178 | - }else{ |
|
179 | + } else{ |
|
179 | 180 | return NULL; |
180 | 181 | } |
181 | 182 | } |
@@ -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,17 +25,17 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EE_Change_Log extends EE_Base_Class{ |
|
28 | +class EE_Change_Log extends EE_Base_Class { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * |
32 | 32 | * @param array $props_n_values |
33 | 33 | * @return EE_Change_Log |
34 | 34 | */ |
35 | - public static function new_instance( $props_n_values = array() ) { |
|
36 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
35 | + public static function new_instance($props_n_values = array()) { |
|
36 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
37 | 37 | // d( $has_object ); |
38 | - return $has_object ? $has_object : new self( $props_n_values); |
|
38 | + return $has_object ? $has_object : new self($props_n_values); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | * @param array $props_n_values |
44 | 44 | * @return EE_Change_Log |
45 | 45 | */ |
46 | - public static function new_instance_from_db ( $props_n_values = array() ) { |
|
46 | + public static function new_instance_from_db($props_n_values = array()) { |
|
47 | 47 | // $mapped_object = parent::_get_object_from_entity_mapper($props_n_values, $classname); |
48 | 48 | // d( $mapped_object ); |
49 | 49 | // return $mapped_object ? $mapped_object : new self( $props_n_values, TRUE ); |
50 | - return new self( $props_n_values, TRUE ); |
|
50 | + return new self($props_n_values, TRUE); |
|
51 | 51 | } |
52 | 52 | /** |
53 | 53 | * Gets message |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | * Gets the model object attached to this log |
145 | 145 | * @return EE_Base_Class |
146 | 146 | */ |
147 | - function object(){ |
|
147 | + function object() { |
|
148 | 148 | $model_name_of_related_obj = $this->OBJ_type(); |
149 | 149 | $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
150 | - if( ! $is_model_name ){ |
|
150 | + if ( ! $is_model_name) { |
|
151 | 151 | return null; |
152 | - }else{ |
|
152 | + } else { |
|
153 | 153 | return $this->get_first_related($model_name_of_related_obj); |
154 | 154 | } |
155 | 155 | } |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | * @param boolean $save |
163 | 163 | * @return boolean if $save=true, NULL is $save=false |
164 | 164 | */ |
165 | - function set_object($object, $save = TRUE ) { |
|
166 | - if($object instanceof EE_Base_Class){ |
|
165 | + function set_object($object, $save = TRUE) { |
|
166 | + if ($object instanceof EE_Base_Class) { |
|
167 | 167 | $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
168 | 168 | $this->set_OBJ_ID($object->ID()); |
169 | - }else{ |
|
169 | + } else { |
|
170 | 170 | $this->set_OBJ_type(NULL); |
171 | 171 | $this->set_OBJ_ID(NULL); |
172 | 172 | } |
173 | - if($save){ |
|
173 | + if ($save) { |
|
174 | 174 | return $this->save(); |
175 | - }else{ |
|
175 | + } else { |
|
176 | 176 | return NULL; |
177 | 177 | } |
178 | 178 | } |
@@ -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 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
3 | 5 | /** |
4 | 6 | * Event Espresso |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3 | 3 | /** |
4 | 4 | * Event Espresso |
5 | 5 | * |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | * @subpackage includes/classes/EE_Checkin.class.php |
24 | 24 | * @author Darren Ethier |
25 | 25 | */ |
26 | -class EE_Checkin extends EE_Base_Class{ |
|
26 | +class EE_Checkin extends EE_Base_Class { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param array $props_n_values |
30 | 30 | * @param null $timezone |
31 | 31 | * @return EE_Checkin|mixed |
32 | 32 | */ |
33 | - public static function new_instance( $props_n_values = array(), $timezone = NULL ) { |
|
34 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
35 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
33 | + public static function new_instance($props_n_values = array(), $timezone = NULL) { |
|
34 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
35 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @param null $timezone |
43 | 43 | * @return EE_Checkin |
44 | 44 | */ |
45 | - public static function new_instance_from_db ( $props_n_values = array(), $timezone = NULL ) { |
|
46 | - return new self( $props_n_values, TRUE, $timezone ); |
|
45 | + public static function new_instance_from_db($props_n_values = array(), $timezone = NULL) { |
|
46 | + return new self($props_n_values, TRUE, $timezone); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 |
@@ -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 |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param array $props_n_values |
31 | 31 | * @return EE_Country|mixed |
32 | 32 | */ |
33 | - public static function new_instance( $props_n_values = array() ) { |
|
34 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
35 | - return $has_object ? $has_object : new self( $props_n_values ); |
|
33 | + public static function new_instance($props_n_values = array()) { |
|
34 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
35 | + return $has_object ? $has_object : new self($props_n_values); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * @param array $props_n_values |
42 | 42 | * @return EE_Country |
43 | 43 | */ |
44 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
45 | - return new self( $props_n_values, TRUE ); |
|
44 | + public static function new_instance_from_db($props_n_values = array()) { |
|
45 | + return new self($props_n_values, TRUE); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return string |
55 | 55 | */ |
56 | 56 | public function name() { |
57 | - return $this->get( 'CNT_name' ); |
|
57 | + return $this->get('CNT_name'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return string |
65 | 65 | */ |
66 | 66 | public function currency_code() { |
67 | - return $this->get( 'CNT_cur_code' ); |
|
67 | + return $this->get('CNT_cur_code'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @return string |
75 | 75 | */ |
76 | 76 | public function currency_sign() { |
77 | - $CNT_cur_sign = $this->get( 'CNT_cur_sign' ); |
|
77 | + $CNT_cur_sign = $this->get('CNT_cur_sign'); |
|
78 | 78 | return $CNT_cur_sign ? $CNT_cur_sign : '¤'; |
79 | 79 | } |
80 | 80 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return string |
86 | 86 | */ |
87 | 87 | public function currency_name_single() { |
88 | - return $this->get( 'CNT_cur_single' ); |
|
88 | + return $this->get('CNT_cur_single'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return string |
96 | 96 | */ |
97 | 97 | public function currency_name_plural() { |
98 | - return $this->get( 'CNT_cur_plural' ); |
|
98 | + return $this->get('CNT_cur_plural'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return boolean |
106 | 106 | */ |
107 | 107 | public function currency_sign_before() { |
108 | - return $this->get( 'CNT_cur_sign_b4' ); |
|
108 | + return $this->get('CNT_cur_sign_b4'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return integer |
116 | 116 | */ |
117 | 117 | public function currency_decimal_places() { |
118 | - return $this->get( 'CNT_cur_dec_plc' ); |
|
118 | + return $this->get('CNT_cur_dec_plc'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return string |
126 | 126 | */ |
127 | 127 | public function currency_decimal_mark() { |
128 | - return $this->get( 'CNT_cur_dec_mrk' ); |
|
128 | + return $this->get('CNT_cur_dec_mrk'); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return string |
136 | 136 | */ |
137 | 137 | public function currency_thousands_separator() { |
138 | - return $this->get( 'CNT_cur_thsnds' ); |
|
138 | + return $this->get('CNT_cur_thsnds'); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | /* End of file EE_Country.class.php */ |
@@ -281,8 +281,7 @@ discard block |
||
281 | 281 | $short_desc = $this->get( 'EVT_short_desc' ); |
282 | 282 | if ( !empty( $short_desc ) || $not_full_desc ) { |
283 | 283 | return $short_desc; |
284 | - } |
|
285 | - else { |
|
284 | + } else { |
|
286 | 285 | $full_desc = $this->get( 'EVT_desc' ); |
287 | 286 | return wp_trim_words( $full_desc, $num_words, $more ); |
288 | 287 | } |
@@ -665,8 +664,7 @@ discard block |
||
665 | 664 | // if datetime has unlimited reg limit then the event can never be sold out |
666 | 665 | if ( $dtt_spaces_remaining === INF ) { |
667 | 666 | return FALSE; |
668 | - } |
|
669 | - else { |
|
667 | + } else { |
|
670 | 668 | $spaces_remaining = max( $dtt_spaces_remaining, $spaces_remaining ); |
671 | 669 | } |
672 | 670 | } |
@@ -677,8 +675,7 @@ discard block |
||
677 | 675 | $this->save(); |
678 | 676 | } |
679 | 677 | $sold_out = TRUE; |
680 | - } |
|
681 | - else { |
|
678 | + } else { |
|
682 | 679 | $sold_out = FALSE; |
683 | 680 | } |
684 | 681 | //note: I considered changing the EEM_Event status away from sold_out if this status check reveals that it's no longer sold out (yet the status is still set as sold out) but the problem is... what do we change the status BACK to? We can't always assume that the previous event status was 'published' because this status check is always done in the admin and its entirely possible the event admin manually changes to sold_out status from some other status. We also don't want a draft event to become a "publish event" because the sold out check reveals its NOT sold out. |
@@ -876,8 +873,7 @@ discard block |
||
876 | 873 | public function is_sold_out( $actual = FALSE ) { |
877 | 874 | if ( !$actual ) { |
878 | 875 | return $this->status() == EEM_Event::sold_out; |
879 | - } |
|
880 | - else { |
|
876 | + } else { |
|
881 | 877 | return $this->perform_sold_out_status_check(); |
882 | 878 | } |
883 | 879 | } |
@@ -1067,8 +1063,7 @@ discard block |
||
1067 | 1063 | public function get_permalink() { |
1068 | 1064 | if ( $this->external_url() ) { |
1069 | 1065 | return $this->external_url(); |
1070 | - } |
|
1071 | - else { |
|
1066 | + } else { |
|
1072 | 1067 | return parent::get_permalink(); |
1073 | 1068 | } |
1074 | 1069 | } |
@@ -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 |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | * @param array $props_n_values |
47 | 47 | * @return EE_Event |
48 | 48 | */ |
49 | - public static function new_instance( $props_n_values = array() ) { |
|
50 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
51 | - $obj = $has_object ? $has_object : new self( $props_n_values ); |
|
49 | + public static function new_instance($props_n_values = array()) { |
|
50 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
51 | + $obj = $has_object ? $has_object : new self($props_n_values); |
|
52 | 52 | //we need to set the _timezone property to whatever is set in the db for the event initially. |
53 | - $obj->set_timezone( $obj->timezone_string() ); |
|
53 | + $obj->set_timezone($obj->timezone_string()); |
|
54 | 54 | return $obj; |
55 | 55 | } |
56 | 56 | |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param array $props_n_values |
62 | 62 | * @return EE_Event |
63 | 63 | */ |
64 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
65 | - $obj = new self( $props_n_values, TRUE ); |
|
64 | + public static function new_instance_from_db($props_n_values = array()) { |
|
65 | + $obj = new self($props_n_values, TRUE); |
|
66 | 66 | //we need to set the _timezone property to whatever is set in the db for the event initially. |
67 | - $obj->set_timezone( $obj->timezone_string() ); |
|
67 | + $obj->set_timezone($obj->timezone_string()); |
|
68 | 68 | return $obj; |
69 | 69 | } |
70 | 70 | |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @param boolean $show_deleted whether or not to include deleted events |
80 | 80 | * @return EE_Datetime[] |
81 | 81 | */ |
82 | - public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE, $limit = NULL ) { |
|
83 | - return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_event_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted, $limit ); |
|
82 | + public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE, $limit = NULL) { |
|
83 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted, $limit); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return EE_Datetime |
91 | 91 | */ |
92 | 92 | public function first_datetime() { |
93 | - return $this->get_first_related( 'Datetime' ); |
|
93 | + return $this->get_first_related('Datetime'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | * @param bool $try_to_exclude_deleted |
102 | 102 | * @return EE_Datetime |
103 | 103 | */ |
104 | - public function primary_datetime( $try_to_exclude_expired = TRUE, $try_to_exclude_deleted = TRUE ) { |
|
105 | - if ( !empty ( $this->_Primary_Datetime ) ) { |
|
104 | + public function primary_datetime($try_to_exclude_expired = TRUE, $try_to_exclude_deleted = TRUE) { |
|
105 | + if ( ! empty ($this->_Primary_Datetime)) { |
|
106 | 106 | return $this->_Primary_Datetime; |
107 | 107 | } |
108 | - $this->_Primary_Datetime = EEM_Datetime::instance( $this->_timezone )->get_primary_datetime_for_event( $this->ID(), $try_to_exclude_expired, $try_to_exclude_deleted ); |
|
108 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event($this->ID(), $try_to_exclude_expired, $try_to_exclude_deleted); |
|
109 | 109 | return $this->_Primary_Datetime; |
110 | 110 | } |
111 | 111 | |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @param array $query_params like EEM_Base::get_all |
117 | 117 | * @return EE_Ticket |
118 | 118 | */ |
119 | - public function tickets( $query_params = array() ) { |
|
120 | - return $this->get_many_related( 'Ticket', $query_params ); |
|
119 | + public function tickets($query_params = array()) { |
|
120 | + return $this->get_many_related('Ticket', $query_params); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @return bool |
127 | 127 | */ |
128 | 128 | function additional_limit() { |
129 | - return $this->get( 'EVT_additional_limit' ); |
|
129 | + return $this->get('EVT_additional_limit'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return bool |
136 | 136 | */ |
137 | 137 | function allow_overflow() { |
138 | - return $this->get( 'EVT_allow_overflow' ); |
|
138 | + return $this->get('EVT_allow_overflow'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return bool |
145 | 145 | */ |
146 | 146 | function created() { |
147 | - return $this->get( 'EVT_created' ); |
|
147 | + return $this->get('EVT_created'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return bool |
154 | 154 | */ |
155 | 155 | function description() { |
156 | - return $this->get( 'EVT_desc' ); |
|
156 | + return $this->get('EVT_desc'); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return string of html |
164 | 164 | */ |
165 | 165 | function description_filtered() { |
166 | - return $this->get_pretty( 'EVT_desc' ); |
|
166 | + return $this->get_pretty('EVT_desc'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @return bool |
173 | 173 | */ |
174 | 174 | function display_description() { |
175 | - return $this->get( 'EVT_display_desc' ); |
|
175 | + return $this->get('EVT_display_desc'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return bool |
182 | 182 | */ |
183 | 183 | function display_ticket_selector() { |
184 | - return (bool)$this->get( 'EVT_display_ticket_selector' ); |
|
184 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @return bool |
191 | 191 | */ |
192 | 192 | function external_url() { |
193 | - return $this->get( 'EVT_external_URL' ); |
|
193 | + return $this->get('EVT_external_URL'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @return bool |
200 | 200 | */ |
201 | 201 | function member_only() { |
202 | - return $this->get( 'EVT_member_only' ); |
|
202 | + return $this->get('EVT_member_only'); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @return bool |
209 | 209 | */ |
210 | 210 | function phone() { |
211 | - return $this->get( 'EVT_phone' ); |
|
211 | + return $this->get('EVT_phone'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @return bool |
218 | 218 | */ |
219 | 219 | function modified() { |
220 | - return $this->get( 'EVT_modified' ); |
|
220 | + return $this->get('EVT_modified'); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return bool |
227 | 227 | */ |
228 | 228 | function name() { |
229 | - return $this->get( 'EVT_name' ); |
|
229 | + return $this->get('EVT_name'); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @return bool |
236 | 236 | */ |
237 | 237 | function order() { |
238 | - return $this->get( 'EVT_order' ); |
|
238 | + return $this->get('EVT_order'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @return bool|string |
245 | 245 | */ |
246 | 246 | function default_registration_status() { |
247 | - $event_default_registration_status = $this->get( 'EVT_default_registration_status' ); |
|
248 | - return !empty( $event_default_registration_status ) ? $event_default_registration_status : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
247 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
248 | + return ! empty($event_default_registration_status) ? $event_default_registration_status : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -256,14 +256,14 @@ discard block |
||
256 | 256 | * @param bool $not_full_desc |
257 | 257 | * @return bool|string |
258 | 258 | */ |
259 | - function short_description( $num_words = 55, $more = NULL, $not_full_desc = FALSE ) { |
|
260 | - $short_desc = $this->get( 'EVT_short_desc' ); |
|
261 | - if ( !empty( $short_desc ) || $not_full_desc ) { |
|
259 | + function short_description($num_words = 55, $more = NULL, $not_full_desc = FALSE) { |
|
260 | + $short_desc = $this->get('EVT_short_desc'); |
|
261 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
262 | 262 | return $short_desc; |
263 | 263 | } |
264 | 264 | else { |
265 | - $full_desc = $this->get( 'EVT_desc' ); |
|
266 | - return wp_trim_words( $full_desc, $num_words, $more ); |
|
265 | + $full_desc = $this->get('EVT_desc'); |
|
266 | + return wp_trim_words($full_desc, $num_words, $more); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @return bool |
274 | 274 | */ |
275 | 275 | function slug() { |
276 | - return $this->get( 'EVT_slug' ); |
|
276 | + return $this->get('EVT_slug'); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return bool |
283 | 283 | */ |
284 | 284 | function timezone_string() { |
285 | - return $this->get( 'EVT_timezone_string' ); |
|
285 | + return $this->get('EVT_timezone_string'); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | function visible_on() { |
294 | - return $this->get( 'EVT_visible_on' ); |
|
294 | + return $this->get('EVT_visible_on'); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @return bool |
301 | 301 | */ |
302 | 302 | function wp_user() { |
303 | - return $this->get( 'EVT_wp_user' ); |
|
303 | + return $this->get('EVT_wp_user'); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @return bool |
310 | 310 | */ |
311 | 311 | function donations() { |
312 | - return $this->get( 'EVT_donations' ); |
|
312 | + return $this->get('EVT_donations'); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | /** |
318 | 318 | * @param $limit |
319 | 319 | */ |
320 | - function set_additional_limit( $limit ) { |
|
321 | - $this->set( 'EVT_additional_limit', $limit ); |
|
320 | + function set_additional_limit($limit) { |
|
321 | + $this->set('EVT_additional_limit', $limit); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | /** |
327 | 327 | * @param $created |
328 | 328 | */ |
329 | - function set_created( $created ) { |
|
330 | - $this->set( 'EVT_created', $created ); |
|
329 | + function set_created($created) { |
|
330 | + $this->set('EVT_created', $created); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | /** |
336 | 336 | * @param $desc |
337 | 337 | */ |
338 | - function set_description( $desc ) { |
|
339 | - $this->set( 'EVT_desc', $desc ); |
|
338 | + function set_description($desc) { |
|
339 | + $this->set('EVT_desc', $desc); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | /** |
345 | 345 | * @param $display_desc |
346 | 346 | */ |
347 | - function set_display_description( $display_desc ) { |
|
348 | - $this->set( 'EVT_display_desc', $display_desc ); |
|
347 | + function set_display_description($display_desc) { |
|
348 | + $this->set('EVT_display_desc', $display_desc); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | /** |
354 | 354 | * @param $display_ticket_selector |
355 | 355 | */ |
356 | - function set_display_ticket_selector( $display_ticket_selector ) { |
|
357 | - $this->set( 'EVT_display_ticket_selector', $display_ticket_selector ); |
|
356 | + function set_display_ticket_selector($display_ticket_selector) { |
|
357 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * @param $external_url |
364 | 364 | */ |
365 | - function set_external_url( $external_url ) { |
|
366 | - $this->set( 'EVT_external_URL', $external_url ); |
|
365 | + function set_external_url($external_url) { |
|
366 | + $this->set('EVT_external_URL', $external_url); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | /** |
372 | 372 | * @param $member_only |
373 | 373 | */ |
374 | - function set_member_only( $member_only ) { |
|
375 | - $this->set( 'EVT_member_only', $member_only ); |
|
374 | + function set_member_only($member_only) { |
|
375 | + $this->set('EVT_member_only', $member_only); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | /** |
381 | 381 | * @param $event_phone |
382 | 382 | */ |
383 | - function set_event_phone( $event_phone ) { |
|
384 | - $this->set( 'EVT_phone', $event_phone ); |
|
383 | + function set_event_phone($event_phone) { |
|
384 | + $this->set('EVT_phone', $event_phone); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | /** |
390 | 390 | * @param $modified |
391 | 391 | */ |
392 | - function set_modified( $modified ) { |
|
393 | - $this->set( 'EVT_modified', $modified ); |
|
392 | + function set_modified($modified) { |
|
393 | + $this->set('EVT_modified', $modified); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | /** |
399 | 399 | * @param $name |
400 | 400 | */ |
401 | - function set_name( $name ) { |
|
402 | - $this->set( 'EVT_name', $name ); |
|
401 | + function set_name($name) { |
|
402 | + $this->set('EVT_name', $name); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | /** |
408 | 408 | * @param $order |
409 | 409 | */ |
410 | - function set_order( $order ) { |
|
411 | - $this->set( 'EVT_order', $order ); |
|
410 | + function set_order($order) { |
|
411 | + $this->set('EVT_order', $order); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | /** |
417 | 417 | * @param $short_desc |
418 | 418 | */ |
419 | - function set_short_description( $short_desc ) { |
|
420 | - $this->set( 'EVT_short_desc', $short_desc ); |
|
419 | + function set_short_description($short_desc) { |
|
420 | + $this->set('EVT_short_desc', $short_desc); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * @param $slug |
427 | 427 | */ |
428 | - function set_slug( $slug ) { |
|
429 | - $this->set( 'EVT_slug', $slug ); |
|
428 | + function set_slug($slug) { |
|
429 | + $this->set('EVT_slug', $slug); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | /** |
435 | 435 | * @param $timezone_string |
436 | 436 | */ |
437 | - function set_timezone_string( $timezone_string ) { |
|
438 | - $this->set( 'EVT_timezone_string', $timezone_string ); |
|
437 | + function set_timezone_string($timezone_string) { |
|
438 | + $this->set('EVT_timezone_string', $timezone_string); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | /** |
444 | 444 | * @param $visible_on |
445 | 445 | */ |
446 | - function set_visible_on( $visible_on ) { |
|
447 | - $this->set( 'EVT_visible_on', $visible_on ); |
|
446 | + function set_visible_on($visible_on) { |
|
447 | + $this->set('EVT_visible_on', $visible_on); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | |
@@ -452,8 +452,8 @@ discard block |
||
452 | 452 | /** |
453 | 453 | * @param $wp_user |
454 | 454 | */ |
455 | - function set_wp_user( $wp_user ) { |
|
456 | - $this->set( 'EVT_wp_user', $wp_user ); |
|
455 | + function set_wp_user($wp_user) { |
|
456 | + $this->set('EVT_wp_user', $wp_user); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | /** |
462 | 462 | * @param $default_registration_status |
463 | 463 | */ |
464 | - function set_default_registration_status( $default_registration_status ) { |
|
465 | - $this->set( 'EVT_default_registration_status', $default_registration_status ); |
|
464 | + function set_default_registration_status($default_registration_status) { |
|
465 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | /** |
471 | 471 | * @param $donations |
472 | 472 | */ |
473 | - function set_donations( $donations ) { |
|
474 | - $this->set( 'EVT_donations', $donations ); |
|
473 | + function set_donations($donations) { |
|
474 | + $this->set('EVT_donations', $donations); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * @param EE_Venue /int $venue_id_or_obj |
482 | 482 | * @return EE_Venue |
483 | 483 | */ |
484 | - function add_venue( $venue_id_or_obj ) { |
|
485 | - return $this->_add_relation_to( $venue_id_or_obj, 'Venue' ); |
|
484 | + function add_venue($venue_id_or_obj) { |
|
485 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | |
@@ -492,8 +492,8 @@ discard block |
||
492 | 492 | * @param EE_Venue /int $venue_id_or_obj |
493 | 493 | * @return EE_Venue |
494 | 494 | */ |
495 | - function remove_venue( $venue_id_or_obj ) { |
|
496 | - return $this->_remove_relation_to( $venue_id_or_obj, 'Venue' ); |
|
495 | + function remove_venue($venue_id_or_obj) { |
|
496 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | |
@@ -503,8 +503,8 @@ discard block |
||
503 | 503 | * @param array $query_params like EEM_Base::get_all's $query_params |
504 | 504 | * @return EE_Venue[] |
505 | 505 | */ |
506 | - function venues( $query_params = array() ) { |
|
507 | - return $this->get_many_related( 'Venue', $query_params ); |
|
506 | + function venues($query_params = array()) { |
|
507 | + return $this->get_many_related('Venue', $query_params); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | */ |
517 | 517 | private function _has_ID_and_is_published() { |
518 | 518 | // first check if event id is present and not NULL, then check if this event is published (or any of the equivalent "published" statuses) |
519 | - return ( $this->ID() && $this->ID() !== NULL && ( $this->status() == 'publish' || $this->status() == EEM_Event::sold_out || $this->status() == EEM_Event::postponed || $this->status() == EEM_Event::cancelled ) ) ? TRUE : FALSE; |
|
519 | + return ($this->ID() && $this->ID() !== NULL && ($this->status() == 'publish' || $this->status() == EEM_Event::sold_out || $this->status() == EEM_Event::postponed || $this->status() == EEM_Event::cancelled)) ? TRUE : FALSE; |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -528,21 +528,21 @@ discard block |
||
528 | 528 | */ |
529 | 529 | public function is_upcoming() { |
530 | 530 | // check if event id is present and if this event is published |
531 | - if ( $this->is_inactive() ) { |
|
531 | + if ($this->is_inactive()) { |
|
532 | 532 | return FALSE; |
533 | 533 | } |
534 | 534 | // set initial value |
535 | 535 | $upcoming = FALSE; |
536 | 536 | //next let's get all datetimes and loop through them |
537 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
538 | - foreach ( $datetimes as $datetime ) { |
|
539 | - if ( $datetime instanceof EE_Datetime ) { |
|
537 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
538 | + foreach ($datetimes as $datetime) { |
|
539 | + if ($datetime instanceof EE_Datetime) { |
|
540 | 540 | //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
541 | - if ( $datetime->is_expired() ) { |
|
541 | + if ($datetime->is_expired()) { |
|
542 | 542 | continue; |
543 | 543 | } |
544 | 544 | //if this dtt is active then we return false. |
545 | - if ( $datetime->is_active() ) { |
|
545 | + if ($datetime->is_active()) { |
|
546 | 546 | return FALSE; |
547 | 547 | } |
548 | 548 | //otherwise let's check upcoming status |
@@ -559,21 +559,21 @@ discard block |
||
559 | 559 | */ |
560 | 560 | public function is_active() { |
561 | 561 | // check if event id is present and if this event is published |
562 | - if ( $this->is_inactive() ) { |
|
562 | + if ($this->is_inactive()) { |
|
563 | 563 | return FALSE; |
564 | 564 | } |
565 | 565 | // set initial value |
566 | 566 | $active = FALSE; |
567 | 567 | //next let's get all datetimes and loop through them |
568 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
569 | - foreach ( $datetimes as $datetime ) { |
|
570 | - if ( $datetime instanceof EE_Datetime ) { |
|
568 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
569 | + foreach ($datetimes as $datetime) { |
|
570 | + if ($datetime instanceof EE_Datetime) { |
|
571 | 571 | //if this dtt is expired then we continue cause one of the other datetimes might be active. |
572 | - if ( $datetime->is_expired() ) { |
|
572 | + if ($datetime->is_expired()) { |
|
573 | 573 | continue; |
574 | 574 | } |
575 | 575 | //if this dtt is upcoming then we return false. |
576 | - if ( $datetime->is_upcoming() ) { |
|
576 | + if ($datetime->is_upcoming()) { |
|
577 | 577 | return FALSE; |
578 | 578 | } |
579 | 579 | //otherwise let's check active status |
@@ -590,17 +590,17 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function is_expired() { |
592 | 592 | // check if event id is present and if this event is published |
593 | - if ( $this->is_inactive() ) { |
|
593 | + if ($this->is_inactive()) { |
|
594 | 594 | return FALSE; |
595 | 595 | } |
596 | 596 | // set initial value |
597 | 597 | $expired = FALSE; |
598 | 598 | //first let's get all datetimes and loop through them |
599 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
600 | - foreach ( $datetimes as $datetime ) { |
|
601 | - if ( $datetime instanceof EE_Datetime ) { |
|
599 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
600 | + foreach ($datetimes as $datetime) { |
|
601 | + if ($datetime instanceof EE_Datetime) { |
|
602 | 602 | //if this dtt is upcoming or active then we return false. |
603 | - if ( $datetime->is_upcoming() || $datetime->is_active() ) { |
|
603 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
604 | 604 | return FALSE; |
605 | 605 | } |
606 | 606 | //otherwise let's check active status |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | */ |
618 | 618 | public function is_inactive() { |
619 | 619 | // check if event id is present and if this event is published |
620 | - if ( $this->_has_ID_and_is_published() ) { |
|
620 | + if ($this->_has_ID_and_is_published()) { |
|
621 | 621 | return FALSE; |
622 | 622 | } |
623 | 623 | return TRUE; |
@@ -637,22 +637,22 @@ discard block |
||
637 | 637 | // set initial value |
638 | 638 | $spaces_remaining = 0; |
639 | 639 | //next let's get all datetimes and loop through them |
640 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
641 | - foreach ( $datetimes as $datetime ) { |
|
642 | - if ( $datetime instanceof EE_Datetime ) { |
|
643 | - $dtt_spaces_remaining = $datetime->spaces_remaining( TRUE ); |
|
640 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
641 | + foreach ($datetimes as $datetime) { |
|
642 | + if ($datetime instanceof EE_Datetime) { |
|
643 | + $dtt_spaces_remaining = $datetime->spaces_remaining(TRUE); |
|
644 | 644 | // if datetime has unlimited reg limit then the event can never be sold out |
645 | - if ( $dtt_spaces_remaining === INF ) { |
|
645 | + if ($dtt_spaces_remaining === INF) { |
|
646 | 646 | return FALSE; |
647 | 647 | } |
648 | 648 | else { |
649 | - $spaces_remaining = max( $dtt_spaces_remaining, $spaces_remaining ); |
|
649 | + $spaces_remaining = max($dtt_spaces_remaining, $spaces_remaining); |
|
650 | 650 | } |
651 | 651 | } |
652 | 652 | } |
653 | - if ( $spaces_remaining === 0 ) { |
|
654 | - $this->set_status( EEM_Event::sold_out ); |
|
655 | - if ( !is_admin() || ( is_admin() && defined( 'DOING_AJAX' ) ) ) { |
|
653 | + if ($spaces_remaining === 0) { |
|
654 | + $this->set_status(EEM_Event::sold_out); |
|
655 | + if ( ! is_admin() || (is_admin() && defined('DOING_AJAX'))) { |
|
656 | 656 | $this->save(); |
657 | 657 | } |
658 | 658 | $sold_out = TRUE; |
@@ -672,8 +672,8 @@ discard block |
||
672 | 672 | * @param bool $actual whether or not to perform calculations to not only figure the actual status but also to flip the status if necessary to sold out If false, we just check the existing status of the event |
673 | 673 | * @return boolean |
674 | 674 | */ |
675 | - public function is_sold_out( $actual = FALSE ) { |
|
676 | - if ( !$actual ) { |
|
675 | + public function is_sold_out($actual = FALSE) { |
|
676 | + if ( ! $actual) { |
|
677 | 677 | return $this->status() == EEM_Event::sold_out; |
678 | 678 | } |
679 | 679 | else { |
@@ -711,36 +711,36 @@ discard block |
||
711 | 711 | * @param bool $reset |
712 | 712 | * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
713 | 713 | */ |
714 | - public function get_active_status( $reset = FALSE ) { |
|
714 | + public function get_active_status($reset = FALSE) { |
|
715 | 715 | // if the active status has already been set, then just use that value (unless we are resetting it) |
716 | - if ( ! empty( $this->_active_status ) && ! $reset ) { |
|
716 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
717 | 717 | return $this->_active_status; |
718 | 718 | } |
719 | 719 | //first check if event id is present on this object |
720 | - if ( ! $this->ID() ) { |
|
720 | + if ( ! $this->ID()) { |
|
721 | 721 | return FALSE; |
722 | 722 | } |
723 | 723 | //first get all datetimes ordered by date |
724 | - $datetimes = $this->get_many_related( 'Datetime', array( 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) ) ); |
|
724 | + $datetimes = $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
725 | 725 | //next loop through $datetimes and setup status array |
726 | 726 | $status_array = array(); |
727 | - foreach ( $datetimes as $datetime ) { |
|
728 | - if ( $datetime instanceof EE_Datetime ) { |
|
727 | + foreach ($datetimes as $datetime) { |
|
728 | + if ($datetime instanceof EE_Datetime) { |
|
729 | 729 | $status_array[] = $datetime->get_active_status(); |
730 | 730 | } |
731 | 731 | } |
732 | 732 | //now we can conditionally determine status |
733 | - if ( $this->status() == 'publish' ) { |
|
734 | - if ( in_array( EE_Datetime::active, $status_array ) ) { |
|
733 | + if ($this->status() == 'publish') { |
|
734 | + if (in_array(EE_Datetime::active, $status_array)) { |
|
735 | 735 | $this->_active_status = EE_Datetime::active; |
736 | 736 | } else { |
737 | - if ( in_array( EE_Datetime::upcoming, $status_array ) ) { |
|
737 | + if (in_array(EE_Datetime::upcoming, $status_array)) { |
|
738 | 738 | $this->_active_status = EE_Datetime::upcoming; |
739 | 739 | } else { |
740 | - if ( in_array( EE_Datetime::expired, $status_array ) ) { |
|
740 | + if (in_array(EE_Datetime::expired, $status_array)) { |
|
741 | 741 | $this->_active_status = EE_Datetime::expired; |
742 | 742 | } else { |
743 | - if ( in_array( EE_Datetime::sold_out, $status_array ) ) { |
|
743 | + if (in_array(EE_Datetime::sold_out, $status_array)) { |
|
744 | 744 | $this->_active_status = EE_Datetime::sold_out; |
745 | 745 | } else { |
746 | 746 | $this->_active_status = EE_Datetime::expired; //catchall |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | } |
750 | 750 | } |
751 | 751 | } else { |
752 | - switch ( $this->status() ) { |
|
752 | + switch ($this->status()) { |
|
753 | 753 | case EEM_Event::sold_out : |
754 | 754 | $this->_active_status = EE_Datetime::sold_out; |
755 | 755 | break; |
@@ -775,10 +775,10 @@ discard block |
||
775 | 775 | * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
776 | 776 | * @return mixed void|string |
777 | 777 | */ |
778 | - public function pretty_active_status( $echo = TRUE ) { |
|
778 | + public function pretty_active_status($echo = TRUE) { |
|
779 | 779 | $active_status = $this->get_active_status(); |
780 | - $status = '<span class="ee-status event-active-status-' . $active_status . '">' . EEH_Template::pretty_status( $active_status, FALSE, 'sentence' ) . '</span>'; |
|
781 | - if ( $echo ) { |
|
780 | + $status = '<span class="ee-status event-active-status-'.$active_status.'">'.EEH_Template::pretty_status($active_status, FALSE, 'sentence').'</span>'; |
|
781 | + if ($echo) { |
|
782 | 782 | echo $status; |
783 | 783 | } else { |
784 | 784 | return $status; |
@@ -792,12 +792,12 @@ discard block |
||
792 | 792 | */ |
793 | 793 | public function get_number_of_tickets_sold() { |
794 | 794 | $tkt_sold = 0; |
795 | - if ( !$this->ID() ) { |
|
795 | + if ( ! $this->ID()) { |
|
796 | 796 | return 0; |
797 | 797 | } |
798 | - $datetimes = $this->get_many_related( 'Datetime' ); |
|
799 | - foreach ( $datetimes as $datetime ) { |
|
800 | - $tkt_sold += $datetime->get( 'DTT_sold' ); |
|
798 | + $datetimes = $this->get_many_related('Datetime'); |
|
799 | + foreach ($datetimes as $datetime) { |
|
800 | + $tkt_sold += $datetime->get('DTT_sold'); |
|
801 | 801 | } |
802 | 802 | return $tkt_sold; |
803 | 803 | } |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | * @return int |
811 | 811 | */ |
812 | 812 | public function get_count_of_all_registrations() { |
813 | - return EEM_Event::instance()->count_related( $this, 'Registration' ); |
|
813 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | * @return EE_Ticket |
821 | 821 | */ |
822 | 822 | public function get_ticket_with_earliest_start_time() { |
823 | - $where[ 'Datetime.EVT_ID' ] = $this->ID(); |
|
824 | - $query_params = array( $where, 'order_by' => array( 'TKT_start_date' => 'ASC' ) ); |
|
825 | - return EE_Registry::instance()->load_model( 'Ticket' )->get_one( $query_params ); |
|
823 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
824 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
825 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | |
@@ -832,9 +832,9 @@ discard block |
||
832 | 832 | * @return EE_Ticket |
833 | 833 | */ |
834 | 834 | public function get_ticket_with_latest_end_time() { |
835 | - $where[ 'Datetime.EVT_ID' ] = $this->ID(); |
|
836 | - $query_params = array( $where, 'order_by' => array( 'TKT_end_date' => 'DESC' ) ); |
|
837 | - return EE_Registry::instance()->load_model( 'Ticket' )->get_one( $query_params ); |
|
835 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
836 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
837 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | |
@@ -846,11 +846,11 @@ discard block |
||
846 | 846 | public function tickets_on_sale() { |
847 | 847 | $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
848 | 848 | $latest_ticket = $this->get_ticket_with_latest_end_time(); |
849 | - if ( !$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket ) { |
|
849 | + if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) { |
|
850 | 850 | return FALSE; |
851 | 851 | } |
852 | 852 | //check on sale for these two tickets. |
853 | - if ( $latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale() ) { |
|
853 | + if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
854 | 854 | return TRUE; |
855 | 855 | } |
856 | 856 | return FALSE; |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | * @return string |
865 | 865 | */ |
866 | 866 | public function get_permalink() { |
867 | - if ( $this->external_url() ) { |
|
867 | + if ($this->external_url()) { |
|
868 | 868 | return $this->external_url(); |
869 | 869 | } |
870 | 870 | else { |
@@ -879,10 +879,10 @@ discard block |
||
879 | 879 | * @param array $query_params like EEM_Base::get_all |
880 | 880 | * @return EE_Term |
881 | 881 | */ |
882 | - public function first_event_category( $query_params = array() ) { |
|
883 | - $query_params[ 0 ][ 'Term_Taxonomy.taxonomy' ] = 'espresso_event_categories'; |
|
884 | - $query_params[ 0 ][ 'Term_Taxonomy.Event.EVT_ID' ] = $this->ID(); |
|
885 | - return EEM_Term::instance()->get_one( $query_params ); |
|
882 | + public function first_event_category($query_params = array()) { |
|
883 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
884 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
885 | + return EEM_Term::instance()->get_one($query_params); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | |
@@ -892,10 +892,10 @@ discard block |
||
892 | 892 | * @param array $query_params |
893 | 893 | * @return EE_Term[] |
894 | 894 | */ |
895 | - public function get_all_event_categories( $query_params = array() ) { |
|
896 | - $query_params[ 0 ][ 'Term_Taxonomy.taxonomy' ] = 'espresso_event_categories'; |
|
897 | - $query_params[ 0 ][ 'Term_Taxonomy.Event.EVT_ID' ] = $this->ID(); |
|
898 | - return EEM_Term::instance()->get_all( $query_params ); |
|
895 | + public function get_all_event_categories($query_params = array()) { |
|
896 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
897 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
898 | + return EEM_Term::instance()->get_all($query_params); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | /** |
@@ -903,8 +903,8 @@ discard block |
||
903 | 903 | * @param array $query_params @see EEM_Base::get_all |
904 | 904 | * @return EE_Question_Group[] |
905 | 905 | */ |
906 | - public function question_groups($query_params = array()){ |
|
907 | - $query_params = ! empty( $query_params ) ? $query_params : array( 'order_by' => array( 'QSG_order' => 'ASC' )); |
|
906 | + public function question_groups($query_params = array()) { |
|
907 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
908 | 908 | return $this->get_many_related('Question_Group', $query_params); |
909 | 909 | } |
910 | 910 |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * @param null $timezone |
23 | 23 | * @return EE_Event_Message_Template|mixed |
24 | 24 | */ |
25 | - public static function new_instance( $props_n_values = array(), $timezone = NULL ) { |
|
26 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
27 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
25 | + public static function new_instance($props_n_values = array(), $timezone = NULL) { |
|
26 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
27 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @param null $timezone |
35 | 35 | * @return EE_Event_Message_Template |
36 | 36 | */ |
37 | - public static function new_instance_from_db ( $props_n_values = array(), $timezone = NULL ) { |
|
38 | - return new self( $props_n_values, TRUE, $timezone ); |
|
37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = NULL) { |
|
38 | + return new self($props_n_values, TRUE, $timezone); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | } |
@@ -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 | * Contains definition for EE_Event_Message_Template model object |
4 | 6 | * @package Event Espresso |
@@ -1,18 +1,18 @@ 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 | * Required by EEM_Event_Question_Group in case someone queries for all its model objects |
6 | 6 | */ |
7 | -class EE_Event_Question_Group extends EE_Base_Class{ |
|
7 | +class EE_Event_Question_Group extends EE_Base_Class { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @param array $props_n_values |
11 | 11 | * @return EE_Event_Question_Group|mixed |
12 | 12 | */ |
13 | - public static function new_instance( $props_n_values = array() ) { |
|
14 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
15 | - return $has_object ? $has_object : new self( $props_n_values); |
|
13 | + public static function new_instance($props_n_values = array()) { |
|
14 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
15 | + return $has_object ? $has_object : new self($props_n_values); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param array $props_n_values |
22 | 22 | * @return EE_Event_Question_Group |
23 | 23 | */ |
24 | - public static function new_instance_from_db ( $props_n_values = array() ) { |
|
25 | - return new self( $props_n_values, TRUE ); |
|
24 | + public static function new_instance_from_db($props_n_values = array()) { |
|
25 | + return new self($props_n_values, TRUE); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -2,15 +2,15 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * Required by EEM_Event_Question_Group in case someone queries for all its model objects |
4 | 4 | */ |
5 | -class EE_Event_Venue extends EE_Base_Class{ |
|
5 | +class EE_Event_Venue extends EE_Base_Class { |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * @param array $props_n_values |
9 | 9 | * @return EE_Event_Venue|mixed |
10 | 10 | */ |
11 | - public static function new_instance( $props_n_values = array() ) { |
|
12 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
13 | - return $has_object ? $has_object : new self( $props_n_values); |
|
11 | + public static function new_instance($props_n_values = array()) { |
|
12 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
13 | + return $has_object ? $has_object : new self($props_n_values); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | * @param array $props_n_values |
20 | 20 | * @return EE_Event_Venue |
21 | 21 | */ |
22 | - public static function new_instance_from_db ( $props_n_values = array() ) { |
|
23 | - return new self( $props_n_values, TRUE ); |
|
22 | + public static function new_instance_from_db($props_n_values = array()) { |
|
23 | + return new self($props_n_values, TRUE); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -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 |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param array $props_n_values |
31 | 31 | * @return EE_Extra_Meta|mixed |
32 | 32 | */ |
33 | - public static function new_instance( $props_n_values = array() ) { |
|
34 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
35 | - return $has_object ? $has_object : new self( $props_n_values ); |
|
33 | + public static function new_instance($props_n_values = array()) { |
|
34 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
35 | + return $has_object ? $has_object : new self($props_n_values); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * @param array $props_n_values |
42 | 42 | * @return EE_Extra_Meta |
43 | 43 | */ |
44 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
45 | - return new self( $props_n_values, TRUE ); |
|
44 | + public static function new_instance_from_db($props_n_values = array()) { |
|
45 | + return new self($props_n_values, TRUE); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @return int |
53 | 53 | */ |
54 | 54 | function FK_ID() { |
55 | - return $this->get( 'FK_ID' ); |
|
55 | + return $this->get('FK_ID'); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param int $FK_ID |
63 | 63 | * @return boolean |
64 | 64 | */ |
65 | - function set_FK_ID( $FK_ID ) { |
|
66 | - $this->set( 'FK_ID', $FK_ID ); |
|
65 | + function set_FK_ID($FK_ID) { |
|
66 | + $this->set('FK_ID', $FK_ID); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return string |
74 | 74 | */ |
75 | 75 | function model() { |
76 | - return $this->get( 'EXM_model' ); |
|
76 | + return $this->get('EXM_model'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * @param string $model |
84 | 84 | * @return boolean |
85 | 85 | */ |
86 | - function set_model( $model ) { |
|
87 | - $this->set( 'EXM_model', $model ); |
|
86 | + function set_model($model) { |
|
87 | + $this->set('EXM_model', $model); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return string |
95 | 95 | */ |
96 | 96 | function key() { |
97 | - return $this->get( 'EXM_key' ); |
|
97 | + return $this->get('EXM_key'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param string $key |
105 | 105 | * @return boolean |
106 | 106 | */ |
107 | - function set_key( $key ) { |
|
108 | - $this->set( 'EXM_key', $key ); |
|
107 | + function set_key($key) { |
|
108 | + $this->set('EXM_key', $key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return string |
116 | 116 | */ |
117 | 117 | function value() { |
118 | - return $this->get( 'EXM_value' ); |
|
118 | + return $this->get('EXM_value'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $value |
126 | 126 | * @return boolean |
127 | 127 | */ |
128 | - function set_value( $value ) { |
|
129 | - $this->set( 'EXM_value', $value ); |
|
128 | + function set_value($value) { |
|
129 | + $this->set('EXM_value', $value); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 |
@@ -131,43 +131,43 @@ discard block |
||
131 | 131 | if ( isset( $_REQUEST['import'] )) { |
132 | 132 | if( isset( $_POST['csv_submitted'] )) { |
133 | 133 | |
134 | - switch ( $_FILES['file']['error'][0] ) { |
|
135 | - case UPLOAD_ERR_OK: |
|
136 | - $error_msg = FALSE; |
|
137 | - break; |
|
138 | - case UPLOAD_ERR_INI_SIZE: |
|
139 | - $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
140 | - break; |
|
141 | - case UPLOAD_ERR_FORM_SIZE: |
|
142 | - $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
143 | - break; |
|
144 | - case UPLOAD_ERR_PARTIAL: |
|
145 | - $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
146 | - break; |
|
147 | - case UPLOAD_ERR_NO_FILE: |
|
148 | - $error_msg = __('No file was uploaded.', "event_espresso"); |
|
149 | - break; |
|
150 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
151 | - $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
152 | - break; |
|
153 | - case UPLOAD_ERR_CANT_WRITE: |
|
154 | - $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
155 | - break; |
|
156 | - case UPLOAD_ERR_EXTENSION: |
|
157 | - $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
158 | - break; |
|
159 | - default: |
|
160 | - $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
161 | - break; |
|
162 | - } |
|
134 | + switch ( $_FILES['file']['error'][0] ) { |
|
135 | + case UPLOAD_ERR_OK: |
|
136 | + $error_msg = FALSE; |
|
137 | + break; |
|
138 | + case UPLOAD_ERR_INI_SIZE: |
|
139 | + $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
140 | + break; |
|
141 | + case UPLOAD_ERR_FORM_SIZE: |
|
142 | + $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
143 | + break; |
|
144 | + case UPLOAD_ERR_PARTIAL: |
|
145 | + $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
146 | + break; |
|
147 | + case UPLOAD_ERR_NO_FILE: |
|
148 | + $error_msg = __('No file was uploaded.', "event_espresso"); |
|
149 | + break; |
|
150 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
151 | + $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
152 | + break; |
|
153 | + case UPLOAD_ERR_CANT_WRITE: |
|
154 | + $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
155 | + break; |
|
156 | + case UPLOAD_ERR_EXTENSION: |
|
157 | + $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
158 | + break; |
|
159 | + default: |
|
160 | + $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
161 | + break; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | if ( ! $error_msg ) { |
165 | 165 | |
166 | - $filename = $_FILES['file']['name'][0]; |
|
166 | + $filename = $_FILES['file']['name'][0]; |
|
167 | 167 | $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
168 | - $file_type = $_FILES['file']['type'][0]; |
|
169 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
168 | + $file_type = $_FILES['file']['type'][0]; |
|
169 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | + $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
171 | 171 | |
172 | 172 | if ( $file_ext=='csv' ) { |
173 | 173 | |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | unset($csv_data_array[EE_CSV::metadata_header]); |
303 | 303 | } |
304 | 304 | /** |
305 | - * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
306 | - * the value will be the newly-inserted ID. |
|
307 | - * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
308 | - */ |
|
305 | + * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
306 | + * the value will be the newly-inserted ID. |
|
307 | + * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
308 | + */ |
|
309 | 309 | $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
310 | 310 | if( $old_db_to_new_db_mapping){ |
311 | 311 | EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url())); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3 | 3 | /** |
4 | 4 | * EE_Import class |
5 | 5 | * |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public static function instance() { |
58 | 58 | // check if class object is instantiated |
59 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) { |
|
59 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
60 | 60 | self::$_instance = new self(); |
61 | 61 | } |
62 | 62 | return self::$_instance; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * Resets the importer |
67 | 67 | * @return EE_Import |
68 | 68 | */ |
69 | - public static function reset(){ |
|
69 | + public static function reset() { |
|
70 | 70 | self::$_instance = null; |
71 | 71 | return self::instance(); |
72 | 72 | } |
@@ -84,27 +84,27 @@ discard block |
||
84 | 84 | * @param string $type - type of file to import |
85 | 85 | * @ return string |
86 | 86 | */ |
87 | - public function upload_form ( $title, $intro, $form_url, $action, $type ) { |
|
87 | + public function upload_form($title, $intro, $form_url, $action, $type) { |
|
88 | 88 | |
89 | - $form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url ); |
|
89 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
90 | 90 | |
91 | 91 | ob_start(); |
92 | 92 | ?> |
93 | 93 | <div class="ee-upload-form-dv"> |
94 | - <h3><?php echo $title;?></h3> |
|
95 | - <p><?php echo $intro;?></p> |
|
94 | + <h3><?php echo $title; ?></h3> |
|
95 | + <p><?php echo $intro; ?></p> |
|
96 | 96 | |
97 | 97 | <form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data"> |
98 | - <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>"> |
|
99 | - <input name="import" type="hidden" value="<?php echo $type;?>" /> |
|
98 | + <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>"> |
|
99 | + <input name="import" type="hidden" value="<?php echo $type; ?>" /> |
|
100 | 100 | <input type="file" name="file[]" size="90" > |
101 | - <input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>"> |
|
101 | + <input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>"> |
|
102 | 102 | </form> |
103 | 103 | |
104 | 104 | <p class="ee-attention"> |
105 | - <b><?php _e( 'Attention', 'event_espresso' );?></b><br/> |
|
106 | - <?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?> |
|
107 | - <?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?> |
|
105 | + <b><?php _e('Attention', 'event_espresso'); ?></b><br/> |
|
106 | + <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
|
107 | + <?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?> |
|
108 | 108 | </p> |
109 | 109 | |
110 | 110 | </div> |
@@ -125,13 +125,13 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function import() { |
127 | 127 | |
128 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
128 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
129 | 129 | $this->EE_CSV = EE_CSV::instance(); |
130 | 130 | |
131 | - if ( isset( $_REQUEST['import'] )) { |
|
132 | - if( isset( $_POST['csv_submitted'] )) { |
|
131 | + if (isset($_REQUEST['import'])) { |
|
132 | + if (isset($_POST['csv_submitted'])) { |
|
133 | 133 | |
134 | - switch ( $_FILES['file']['error'][0] ) { |
|
134 | + switch ($_FILES['file']['error'][0]) { |
|
135 | 135 | case UPLOAD_ERR_OK: |
136 | 136 | $error_msg = FALSE; |
137 | 137 | break; |
@@ -161,32 +161,32 @@ discard block |
||
161 | 161 | break; |
162 | 162 | } |
163 | 163 | |
164 | - if ( ! $error_msg ) { |
|
164 | + if ( ! $error_msg) { |
|
165 | 165 | |
166 | - $filename = $_FILES['file']['name'][0]; |
|
167 | - $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
|
168 | - $file_type = $_FILES['file']['type'][0]; |
|
169 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
166 | + $filename = $_FILES['file']['name'][0]; |
|
167 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
168 | + $file_type = $_FILES['file']['type'][0]; |
|
169 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | + $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB |
|
171 | 171 | |
172 | - if ( $file_ext=='csv' ) { |
|
172 | + if ($file_ext == 'csv') { |
|
173 | 173 | |
174 | - $max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB |
|
175 | - if ( $filesize < $max_upload || true) { |
|
174 | + $max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB |
|
175 | + if ($filesize < $max_upload || true) { |
|
176 | 176 | |
177 | - $wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir()); |
|
178 | - $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename; |
|
177 | + $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir()); |
|
178 | + $path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename; |
|
179 | 179 | |
180 | - if( move_uploaded_file( $temp_file, $path_to_file )) { |
|
180 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
181 | 181 | |
182 | 182 | // convert csv to array |
183 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file ); |
|
183 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
184 | 184 | |
185 | 185 | // was data successfully stored in an array? |
186 | - if ( is_array( $this->csv_array ) ) { |
|
186 | + if (is_array($this->csv_array)) { |
|
187 | 187 | |
188 | - $import_what = str_replace( 'csv_import_', '', $_REQUEST['action'] ); |
|
189 | - $import_what = str_replace( '_', ' ', ucwords( $import_what )); |
|
188 | + $import_what = str_replace('csv_import_', '', $_REQUEST['action']); |
|
189 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
190 | 190 | $processed_data = $this->csv_array; |
191 | 191 | $this->columns_to_save = FALSE; |
192 | 192 | |
@@ -205,33 +205,33 @@ discard block |
||
205 | 205 | |
206 | 206 | } |
207 | 207 | // save processed codes to db |
208 | - if ( $this->save_csv_data_array_to_db( $processed_data, $this->columns_to_save ) ) { |
|
208 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
209 | 209 | return TRUE; |
210 | 210 | |
211 | 211 | } |
212 | 212 | } else { |
213 | 213 | // no array? must be an error |
214 | - EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ ); |
|
214 | + EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
215 | 215 | return FALSE; |
216 | 216 | } |
217 | 217 | |
218 | 218 | } else { |
219 | - EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
219 | + EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
220 | 220 | return FALSE; |
221 | 221 | } |
222 | 222 | |
223 | 223 | } else { |
224 | - EE_Error::add_error( sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"),$filename,$max_upload), __FILE__, __FUNCTION__, __LINE__ ); |
|
224 | + EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__); |
|
225 | 225 | return FALSE; |
226 | 226 | } |
227 | 227 | |
228 | 228 | } else { |
229 | - EE_Error::add_error( sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
229 | + EE_Error::add_error(sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
230 | 230 | return FALSE; |
231 | 231 | } |
232 | 232 | |
233 | 233 | } else { |
234 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
234 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
235 | 235 | return FALSE; |
236 | 236 | } |
237 | 237 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to |
273 | 273 | * @return TRUE on success, FALSE on fail |
274 | 274 | */ |
275 | - public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) { |
|
275 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) { |
|
276 | 276 | |
277 | 277 | |
278 | 278 | $success = FALSE; |
@@ -282,22 +282,22 @@ discard block |
||
282 | 282 | $export_from_site_a_to_b = true; |
283 | 283 | // first level of array is not table information but a table name was passed to the function |
284 | 284 | // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
285 | - if($model_name){ |
|
285 | + if ($model_name) { |
|
286 | 286 | $csv_data_array = array($csv_data_array); |
287 | 287 | } |
288 | 288 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
289 | 289 | $old_site_url = 'none-specified'; |
290 | 290 | |
291 | 291 | //hanlde metadata |
292 | - if(isset($csv_data_array[EE_CSV::metadata_header]) ){ |
|
292 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
293 | 293 | $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
294 | 294 | //ok so its metadata, dont try to save it to ehte db obviously... |
295 | - if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
|
295 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
296 | 296 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
297 | 297 | $export_from_site_a_to_b = false; |
298 | - }else{ |
|
299 | - $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
300 | - EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
|
298 | + } else { |
|
299 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
300 | + EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"), $old_site_url, site_url())); |
|
301 | 301 | }; |
302 | 302 | unset($csv_data_array[EE_CSV::metadata_header]); |
303 | 303 | } |
@@ -306,40 +306,40 @@ discard block |
||
306 | 306 | * the value will be the newly-inserted ID. |
307 | 307 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
308 | 308 | */ |
309 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
|
310 | - if( $old_db_to_new_db_mapping){ |
|
311 | - EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url())); |
|
309 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
310 | + if ($old_db_to_new_db_mapping) { |
|
311 | + EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"), $old_site_url, site_url())); |
|
312 | 312 | } |
313 | 313 | $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping); |
314 | 314 | |
315 | 315 | //save the mapping from old db to new db in case they try re-importing the same data from the same website again |
316 | - update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping); |
|
316 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
317 | 317 | |
318 | - if ( $this->_total_updates > 0 ) { |
|
319 | - EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->_total_updates)); |
|
318 | + if ($this->_total_updates > 0) { |
|
319 | + EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->_total_updates)); |
|
320 | 320 | $success = true; |
321 | 321 | } |
322 | - if ( $this->_total_inserts > 0 ) { |
|
323 | - EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->_total_inserts)); |
|
322 | + if ($this->_total_inserts > 0) { |
|
323 | + EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)); |
|
324 | 324 | $success = true; |
325 | 325 | } |
326 | 326 | |
327 | - if ( $this->_total_update_errors > 0 ) { |
|
328 | - EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
327 | + if ($this->_total_update_errors > 0) { |
|
328 | + EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__); |
|
329 | 329 | $error = true; |
330 | 330 | } |
331 | - if ( $this->_total_insert_errors > 0 ) { |
|
332 | - EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
331 | + if ($this->_total_insert_errors > 0) { |
|
332 | + EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__); |
|
333 | 333 | $error = true; |
334 | 334 | } |
335 | 335 | |
336 | 336 | //lastly, we need to update the datetime and ticket sold amounts |
337 | 337 | //as those may ahve been affected by this |
338 | - EEM_Datetime::instance()->update_sold( EEM_Datetime::instance()->get_all() ); |
|
338 | + EEM_Datetime::instance()->update_sold(EEM_Datetime::instance()->get_all()); |
|
339 | 339 | EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
340 | 340 | |
341 | 341 | // if there was at least one success and absolutely no errors |
342 | - if ( $success && ! $error ) { |
|
342 | + if ($success && ! $error) { |
|
343 | 343 | return TRUE; |
344 | 344 | } else { |
345 | 345 | return FALSE; |
@@ -371,81 +371,81 @@ discard block |
||
371 | 371 | * @param type $old_db_to_new_db_mapping |
372 | 372 | * @return array updated $old_db_to_new_db_mapping |
373 | 373 | */ |
374 | - public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping ) { |
|
375 | - foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) { |
|
374 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) { |
|
375 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
376 | 376 | //now check that assumption was correct. If |
377 | - if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
377 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
378 | 378 | $model_name = $model_name_in_csv_data; |
379 | - }else { |
|
379 | + } else { |
|
380 | 380 | // no table info in the array and no table name passed to the function?? FAIL |
381 | - EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
381 | + EE_Error::add_error(__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
382 | 382 | return FALSE; |
383 | 383 | } |
384 | 384 | /* @var $model EEM_Base */ |
385 | 385 | $model = EE_Registry::instance()->load_model($model_name); |
386 | 386 | |
387 | 387 | //so without further ado, scanning all the data provided for primary keys and their inital values |
388 | - foreach ( $model_data_from_import as $model_object_data ) { |
|
388 | + foreach ($model_data_from_import as $model_object_data) { |
|
389 | 389 | //before we do ANYTHING, make sure the csv row wasn't just completely blank |
390 | 390 | $row_is_completely_empty = true; |
391 | - foreach($model_object_data as $field){ |
|
392 | - if($field){ |
|
391 | + foreach ($model_object_data as $field) { |
|
392 | + if ($field) { |
|
393 | 393 | $row_is_completely_empty = false; |
394 | 394 | } |
395 | 395 | } |
396 | - if($row_is_completely_empty){ |
|
396 | + if ($row_is_completely_empty) { |
|
397 | 397 | continue; |
398 | 398 | } |
399 | 399 | //find the PK in the row of data (or a combined key if |
400 | 400 | //there is no primary key) |
401 | - if($model->has_primary_key_field()){ |
|
402 | - $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
403 | - }else{ |
|
401 | + if ($model->has_primary_key_field()) { |
|
402 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
403 | + } else { |
|
404 | 404 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
405 | 405 | } |
406 | 406 | |
407 | 407 | |
408 | - $model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ); |
|
408 | + $model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b); |
|
409 | 409 | //now we need to decide if we're going to add a new model object given the $model_object_data, |
410 | 410 | //or just update. |
411 | - if($export_from_site_a_to_b){ |
|
412 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
413 | - }else{//this is just a re-import |
|
414 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
411 | + if ($export_from_site_a_to_b) { |
|
412 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
413 | + } else {//this is just a re-import |
|
414 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
415 | 415 | } |
416 | - if( $what_to_do == self::do_nothing ) { |
|
416 | + if ($what_to_do == self::do_nothing) { |
|
417 | 417 | continue; |
418 | 418 | } |
419 | 419 | |
420 | 420 | //double-check we actually want to insert, if that's what we're planning |
421 | 421 | //based on whether this item would be unique in the DB or not |
422 | - if( $what_to_do == self::do_insert ) { |
|
422 | + if ($what_to_do == self::do_insert) { |
|
423 | 423 | //we're supposed to be inserting. But wait, will this thing |
424 | 424 | //be acceptable if inserted? |
425 | - $conflicting = $model->get_one_conflicting( $model_object_data, false ); |
|
426 | - if($conflicting){ |
|
425 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
426 | + if ($conflicting) { |
|
427 | 427 | //ok, this item would conflict if inserted. Just update the item that it conflicts with. |
428 | 428 | $what_to_do = self::do_update; |
429 | 429 | //and if this model has a primary key, remember its mapping |
430 | - if($model->has_primary_key_field()){ |
|
430 | + if ($model->has_primary_key_field()) { |
|
431 | 431 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
432 | 432 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
433 | - }else{ |
|
433 | + } else { |
|
434 | 434 | //we want to update this conflicting item, instead of inserting a conflicting item |
435 | 435 | //so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
436 | 436 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
437 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
437 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
438 | 438 | $model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name()); |
439 | 439 | } |
440 | 440 | } |
441 | 441 | } |
442 | 442 | } |
443 | - if( $what_to_do == self::do_insert ) { |
|
444 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
445 | - }elseif( $what_to_do == self::do_update ) { |
|
446 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
447 | - }else{ |
|
448 | - throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
|
443 | + if ($what_to_do == self::do_insert) { |
|
444 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
445 | + }elseif ($what_to_do == self::do_update) { |
|
446 | + $old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
447 | + } else { |
|
448 | + throw new EE_Error(sprintf(__('Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso'), $what_to_do)); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | } |
@@ -466,13 +466,13 @@ discard block |
||
466 | 466 | * @param array $old_db_to_new_db_mapping by reference so it can be modified |
467 | 467 | * @return string one of the consts on this class that starts with do_* |
468 | 468 | */ |
469 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
469 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
470 | 470 | $model_name = $model->get_this_model_name(); |
471 | 471 | //if it's a site-to-site export-and-import, see if this modelobject's id |
472 | 472 | //in the old data that we know of |
473 | - if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
|
473 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
474 | 474 | return self::do_update; |
475 | - }else{ |
|
475 | + } else { |
|
476 | 476 | return self::do_insert; |
477 | 477 | } |
478 | 478 | } |
@@ -487,11 +487,11 @@ discard block |
||
487 | 487 | * @param type $old_db_to_new_db_mapping |
488 | 488 | * @return |
489 | 489 | */ |
490 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) { |
|
490 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) { |
|
491 | 491 | //in this case, check if this thing ACTUALLY exists in the database |
492 | - if( $model->get_one_conflicting( $model_object_data ) ){ |
|
492 | + if ($model->get_one_conflicting($model_object_data)) { |
|
493 | 493 | return self::do_update; |
494 | - }else{ |
|
494 | + } else { |
|
495 | 495 | return self::do_insert; |
496 | 496 | } |
497 | 497 | } |
@@ -510,55 +510,55 @@ discard block |
||
510 | 510 | * @param boolean $export_from_site_a_to_b |
511 | 511 | * @return array updated model object data with temp IDs removed |
512 | 512 | */ |
513 | - protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) { |
|
513 | + protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
514 | 514 | //if this model object's primary key is in the mapping, replace it |
515 | - if( $model->has_primary_key_field() && |
|
515 | + if ($model->has_primary_key_field() && |
|
516 | 516 | $model->get_primary_key_field()->is_auto_increment() && |
517 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) && |
|
518 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) { |
|
519 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
517 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
518 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) { |
|
519 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]]; |
|
520 | 520 | } |
521 | 521 | |
522 | - try{ |
|
522 | + try { |
|
523 | 523 | $model_name_field = $model->get_field_containing_related_model_name(); |
524 | 524 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
525 | - }catch( EE_Error $e ){ |
|
525 | + } catch (EE_Error $e) { |
|
526 | 526 | $model_name_field = NULL; |
527 | 527 | $models_pointed_to_by_model_name_field = array(); |
528 | 528 | } |
529 | - foreach( $model->field_settings( true ) as $field_obj ){ |
|
530 | - if( $field_obj instanceof EE_Foreign_Key_Int_Field ) { |
|
529 | + foreach ($model->field_settings(true) as $field_obj) { |
|
530 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
531 | 531 | $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
532 | 532 | $found_a_mapping = false; |
533 | - foreach( $models_pointed_to as $model_pointed_to_by_fk ) { |
|
533 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
534 | 534 | |
535 | - if( $model_name_field ){ |
|
536 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
537 | - if( $value_of_model_name_field == $model_pointed_to_by_fk ) { |
|
538 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
539 | - $model_object_data[ $field_obj->get_name() ], |
|
535 | + if ($model_name_field) { |
|
536 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
537 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
538 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
539 | + $model_object_data[$field_obj->get_name()], |
|
540 | 540 | $model_pointed_to_by_fk, |
541 | 541 | $old_db_to_new_db_mapping, |
542 | 542 | $export_from_site_a_to_b ); |
543 | 543 | $found_a_mapping = true; |
544 | 544 | break; |
545 | 545 | } |
546 | - }else{ |
|
547 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
548 | - $model_object_data[ $field_obj->get_name() ], |
|
546 | + } else { |
|
547 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
548 | + $model_object_data[$field_obj->get_name()], |
|
549 | 549 | $model_pointed_to_by_fk, |
550 | 550 | $old_db_to_new_db_mapping, |
551 | 551 | $export_from_site_a_to_b ); |
552 | 552 | $found_a_mapping = true; |
553 | 553 | } |
554 | 554 | //once we've found a mapping for this field no need to continue |
555 | - if( $found_a_mapping ) { |
|
555 | + if ($found_a_mapping) { |
|
556 | 556 | break; |
557 | 557 | } |
558 | 558 | |
559 | 559 | |
560 | 560 | } |
561 | - }else{ |
|
561 | + } else { |
|
562 | 562 | //it's a string foreign key (which we leave alone, because those are things |
563 | 563 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
564 | 564 | //prefer to just update one) |
@@ -566,8 +566,8 @@ discard block |
||
566 | 566 | } |
567 | 567 | } |
568 | 568 | // |
569 | - if( $model instanceof EEM_Term_Taxonomy ){ |
|
570 | - $model_object_data = $this->_handle_split_term_ids( $model_object_data ); |
|
569 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
570 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
571 | 571 | } |
572 | 572 | return $model_object_data; |
573 | 573 | } |
@@ -579,11 +579,11 @@ discard block |
||
579 | 579 | * @param type $model_object_data |
580 | 580 | * @return array new model object data |
581 | 581 | */ |
582 | - protected function _handle_split_term_ids( $model_object_data ){ |
|
583 | - if( isset( $model_object_data['term_id'] ) && isset( $model_object_data[ 'taxonomy' ]) && apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) { |
|
584 | - $new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] ); |
|
585 | - if( $new_term_id ){ |
|
586 | - $model_object_data[ 'term_id' ] = $new_term_id; |
|
582 | + protected function _handle_split_term_ids($model_object_data) { |
|
583 | + if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) { |
|
584 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
585 | + if ($new_term_id) { |
|
586 | + $model_object_data['term_id'] = $new_term_id; |
|
587 | 587 | } |
588 | 588 | } |
589 | 589 | return $model_object_data; |
@@ -597,18 +597,18 @@ discard block |
||
597 | 597 | * @param type $export_from_site_a_to_b |
598 | 598 | * @return int |
599 | 599 | */ |
600 | - protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
601 | - if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
|
600 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
601 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
602 | 602 | |
603 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
604 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
603 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
604 | + }elseif ($object_id == '0' || $object_id == '') { |
|
605 | 605 | //leave as-is |
606 | 606 | return $object_id; |
607 | - }elseif( $export_from_site_a_to_b ){ |
|
607 | + }elseif ($export_from_site_a_to_b) { |
|
608 | 608 | //we couldn't find a mapping for this, and it's from a different site, |
609 | 609 | //so blank it out |
610 | 610 | return NULL; |
611 | - }elseif( ! $export_from_site_a_to_b ) { |
|
611 | + }elseif ( ! $export_from_site_a_to_b) { |
|
612 | 612 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
613 | 613 | //so let's just leave it as-is |
614 | 614 | return $object_id; |
@@ -623,36 +623,36 @@ discard block |
||
623 | 623 | * @param type $old_db_to_new_db_mapping |
624 | 624 | * @return array updated $old_db_to_new_db_mapping |
625 | 625 | */ |
626 | - protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
626 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
627 | 627 | //remove the primary key, if there is one (we don't want it for inserts OR updates) |
628 | 628 | //we'll put it back in if we need it |
629 | - if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
|
629 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
630 | 630 | $effective_id = $model_object_data[$model->primary_key_name()]; |
631 | 631 | unset($model_object_data[$model->primary_key_name()]); |
632 | - }else{ |
|
633 | - $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
|
632 | + } else { |
|
633 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
634 | 634 | } |
635 | 635 | //the model takes care of validating the CSV's input |
636 | - try{ |
|
636 | + try { |
|
637 | 637 | $new_id = $model->insert($model_object_data); |
638 | - if( $new_id ){ |
|
638 | + if ($new_id) { |
|
639 | 639 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
640 | 640 | $this->_total_inserts++; |
641 | - EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
|
642 | - }else{ |
|
641 | + EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data))); |
|
642 | + } else { |
|
643 | 643 | $this->_total_insert_errors++; |
644 | 644 | //put the ID used back in there for the error message |
645 | - if($model->has_primary_key_field()){ |
|
645 | + if ($model->has_primary_key_field()) { |
|
646 | 646 | $model_object_data[$model->primary_key_name()] = $effective_id; |
647 | 647 | } |
648 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
|
648 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__); |
|
649 | 649 | } |
650 | - }catch(EE_Error $e){ |
|
650 | + } catch (EE_Error $e) { |
|
651 | 651 | $this->_total_insert_errors++; |
652 | - if($model->has_primary_key_field()){ |
|
652 | + if ($model->has_primary_key_field()) { |
|
653 | 653 | $model_object_data[$model->primary_key_name()] = $effective_id; |
654 | 654 | } |
655 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()), __FILE__, __FUNCTION__, __LINE__ ); |
|
655 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
656 | 656 | } |
657 | 657 | return $old_db_to_new_db_mapping; |
658 | 658 | } |
@@ -665,55 +665,55 @@ discard block |
||
665 | 665 | * @param array $old_db_to_new_db_mapping |
666 | 666 | * @return array updated $old_db_to_new_db_mapping |
667 | 667 | */ |
668 | - protected function _update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
669 | - try{ |
|
668 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
669 | + try { |
|
670 | 670 | //let's keep two copies of the model object data: |
671 | 671 | //one for performing an update, one for everthing else |
672 | 672 | $model_object_data_for_update = $model_object_data; |
673 | - if($model->has_primary_key_field()){ |
|
673 | + if ($model->has_primary_key_field()) { |
|
674 | 674 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
675 | 675 | //remove the primary key because we shouldn't use it for updating |
676 | 676 | unset($model_object_data_for_update[$model->primary_key_name()]); |
677 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
677 | + }elseif ($model->get_combined_primary_key_fields() > 1) { |
|
678 | 678 | $conditions = array(); |
679 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
679 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
680 | 680 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
681 | 681 | } |
682 | - }else{ |
|
683 | - $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
682 | + } else { |
|
683 | + $model->primary_key_name(); //this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
684 | 684 | } |
685 | 685 | |
686 | - $success = $model->update($model_object_data_for_update,array($conditions)); |
|
687 | - if($success){ |
|
686 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
687 | + if ($success) { |
|
688 | 688 | $this->_total_updates++; |
689 | - EE_Error::add_success( sprintf(__("Successfully updated %s with csv data %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data_for_update))); |
|
689 | + EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update))); |
|
690 | 690 | //we should still record the mapping even though it was an update |
691 | 691 | //because if we were going to insert somethign but it was going to conflict |
692 | 692 | //we would have last-minute decided to update. So we'd like to know what we updated |
693 | 693 | //and so we record what record ended up being updated using the mapping |
694 | - if( $model->has_primary_key_field() ){ |
|
695 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
696 | - }else{ |
|
694 | + if ($model->has_primary_key_field()) { |
|
695 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
696 | + } else { |
|
697 | 697 | //no primary key just a combined key |
698 | - $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
|
698 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
699 | 699 | } |
700 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
701 | - }else{ |
|
700 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
701 | + } else { |
|
702 | 702 | $matched_items = $model->get_all(array($conditions)); |
703 | - if( ! $matched_items){ |
|
703 | + if ( ! $matched_items) { |
|
704 | 704 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
705 | 705 | $this->_total_update_errors++; |
706 | - EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
|
707 | - }else{ |
|
706 | + EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__); |
|
707 | + } else { |
|
708 | 708 | $this->_total_updates++; |
709 | - EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
|
709 | + EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data))); |
|
710 | 710 | } |
711 | 711 | } |
712 | - }catch(EE_Error $e){ |
|
712 | + } catch (EE_Error $e) { |
|
713 | 713 | $this->_total_update_errors++; |
714 | - $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
|
715 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
716 | - EE_Error::add_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ ); |
|
714 | + $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()); |
|
715 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
716 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
717 | 717 | } |
718 | 718 | return $old_db_to_new_db_mapping; |
719 | 719 | } |
@@ -722,28 +722,28 @@ discard block |
||
722 | 722 | * Gets the number of inserts performed since importer was instantiated or reset |
723 | 723 | * @return int |
724 | 724 | */ |
725 | - public function get_total_inserts(){ |
|
725 | + public function get_total_inserts() { |
|
726 | 726 | return $this->_total_inserts; |
727 | 727 | } |
728 | 728 | /** |
729 | 729 | * Gets the number of insert errors since importer was instantiated or reset |
730 | 730 | * @return int |
731 | 731 | */ |
732 | - public function get_total_insert_errors(){ |
|
732 | + public function get_total_insert_errors() { |
|
733 | 733 | return $this->_total_insert_errors; |
734 | 734 | } |
735 | 735 | /** |
736 | 736 | * Gets the number of updates performed since importer was instantiated or reset |
737 | 737 | * @return int |
738 | 738 | */ |
739 | - public function get_total_updates(){ |
|
739 | + public function get_total_updates() { |
|
740 | 740 | return $this->_total_updates; |
741 | 741 | } |
742 | 742 | /** |
743 | 743 | * Gets the number of update errors since importer was instantiated or reset |
744 | 744 | * @return int |
745 | 745 | */ |
746 | - public function get_total_update_errors(){ |
|
746 | + public function get_total_update_errors() { |
|
747 | 747 | return $this->_total_update_errors; |
748 | 748 | } |
749 | 749 |
@@ -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 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
3 | 5 | /** |
4 | 6 | * EE_Import class |
@@ -295,7 +297,7 @@ discard block |
||
295 | 297 | if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
296 | 298 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
297 | 299 | $export_from_site_a_to_b = false; |
298 | - }else{ |
|
300 | + } else{ |
|
299 | 301 | $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
300 | 302 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
301 | 303 | }; |
@@ -376,7 +378,7 @@ discard block |
||
376 | 378 | //now check that assumption was correct. If |
377 | 379 | if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
378 | 380 | $model_name = $model_name_in_csv_data; |
379 | - }else { |
|
381 | + } else { |
|
380 | 382 | // no table info in the array and no table name passed to the function?? FAIL |
381 | 383 | EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
382 | 384 | return FALSE; |
@@ -400,7 +402,7 @@ discard block |
||
400 | 402 | //there is no primary key) |
401 | 403 | if($model->has_primary_key_field()){ |
402 | 404 | $id_in_csv = $model_object_data[$model->primary_key_name()]; |
403 | - }else{ |
|
405 | + } else{ |
|
404 | 406 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
405 | 407 | } |
406 | 408 | |
@@ -410,7 +412,7 @@ discard block |
||
410 | 412 | //or just update. |
411 | 413 | if($export_from_site_a_to_b){ |
412 | 414 | $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
413 | - }else{//this is just a re-import |
|
415 | + } else{//this is just a re-import |
|
414 | 416 | $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
415 | 417 | } |
416 | 418 | if( $what_to_do == self::do_nothing ) { |
@@ -430,7 +432,7 @@ discard block |
||
430 | 432 | if($model->has_primary_key_field()){ |
431 | 433 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
432 | 434 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
433 | - }else{ |
|
435 | + } else{ |
|
434 | 436 | //we want to update this conflicting item, instead of inserting a conflicting item |
435 | 437 | //so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
436 | 438 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
@@ -442,9 +444,9 @@ discard block |
||
442 | 444 | } |
443 | 445 | if( $what_to_do == self::do_insert ) { |
444 | 446 | $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
445 | - }elseif( $what_to_do == self::do_update ) { |
|
447 | + } elseif( $what_to_do == self::do_update ) { |
|
446 | 448 | $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
447 | - }else{ |
|
449 | + } else{ |
|
448 | 450 | throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
449 | 451 | } |
450 | 452 | } |
@@ -472,7 +474,7 @@ discard block |
||
472 | 474 | //in the old data that we know of |
473 | 475 | if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
474 | 476 | return self::do_update; |
475 | - }else{ |
|
477 | + } else{ |
|
476 | 478 | return self::do_insert; |
477 | 479 | } |
478 | 480 | } |
@@ -491,7 +493,7 @@ discard block |
||
491 | 493 | //in this case, check if this thing ACTUALLY exists in the database |
492 | 494 | if( $model->get_one_conflicting( $model_object_data ) ){ |
493 | 495 | return self::do_update; |
494 | - }else{ |
|
496 | + } else{ |
|
495 | 497 | return self::do_insert; |
496 | 498 | } |
497 | 499 | } |
@@ -522,7 +524,7 @@ discard block |
||
522 | 524 | try{ |
523 | 525 | $model_name_field = $model->get_field_containing_related_model_name(); |
524 | 526 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
525 | - }catch( EE_Error $e ){ |
|
527 | + } catch( EE_Error $e ){ |
|
526 | 528 | $model_name_field = NULL; |
527 | 529 | $models_pointed_to_by_model_name_field = array(); |
528 | 530 | } |
@@ -543,7 +545,7 @@ discard block |
||
543 | 545 | $found_a_mapping = true; |
544 | 546 | break; |
545 | 547 | } |
546 | - }else{ |
|
548 | + } else{ |
|
547 | 549 | $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
548 | 550 | $model_object_data[ $field_obj->get_name() ], |
549 | 551 | $model_pointed_to_by_fk, |
@@ -558,7 +560,7 @@ discard block |
||
558 | 560 | |
559 | 561 | |
560 | 562 | } |
561 | - }else{ |
|
563 | + } else{ |
|
562 | 564 | //it's a string foreign key (which we leave alone, because those are things |
563 | 565 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
564 | 566 | //prefer to just update one) |
@@ -601,14 +603,14 @@ discard block |
||
601 | 603 | if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
602 | 604 | |
603 | 605 | return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
604 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
606 | + } elseif( $object_id == '0' || $object_id == '' ) { |
|
605 | 607 | //leave as-is |
606 | 608 | return $object_id; |
607 | - }elseif( $export_from_site_a_to_b ){ |
|
609 | + } elseif( $export_from_site_a_to_b ){ |
|
608 | 610 | //we couldn't find a mapping for this, and it's from a different site, |
609 | 611 | //so blank it out |
610 | 612 | return NULL; |
611 | - }elseif( ! $export_from_site_a_to_b ) { |
|
613 | + } elseif( ! $export_from_site_a_to_b ) { |
|
612 | 614 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
613 | 615 | //so let's just leave it as-is |
614 | 616 | return $object_id; |
@@ -629,7 +631,7 @@ discard block |
||
629 | 631 | if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
630 | 632 | $effective_id = $model_object_data[$model->primary_key_name()]; |
631 | 633 | unset($model_object_data[$model->primary_key_name()]); |
632 | - }else{ |
|
634 | + } else{ |
|
633 | 635 | $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
634 | 636 | } |
635 | 637 | //the model takes care of validating the CSV's input |
@@ -639,7 +641,7 @@ discard block |
||
639 | 641 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
640 | 642 | $this->_total_inserts++; |
641 | 643 | EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
642 | - }else{ |
|
644 | + } else{ |
|
643 | 645 | $this->_total_insert_errors++; |
644 | 646 | //put the ID used back in there for the error message |
645 | 647 | if($model->has_primary_key_field()){ |
@@ -647,7 +649,7 @@ discard block |
||
647 | 649 | } |
648 | 650 | EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
649 | 651 | } |
650 | - }catch(EE_Error $e){ |
|
652 | + } catch(EE_Error $e){ |
|
651 | 653 | $this->_total_insert_errors++; |
652 | 654 | if($model->has_primary_key_field()){ |
653 | 655 | $model_object_data[$model->primary_key_name()] = $effective_id; |
@@ -674,12 +676,12 @@ discard block |
||
674 | 676 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
675 | 677 | //remove the primary key because we shouldn't use it for updating |
676 | 678 | unset($model_object_data_for_update[$model->primary_key_name()]); |
677 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
679 | + } elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
678 | 680 | $conditions = array(); |
679 | 681 | foreach($model->get_combined_primary_key_fields() as $key_field){ |
680 | 682 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
681 | 683 | } |
682 | - }else{ |
|
684 | + } else{ |
|
683 | 685 | $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
684 | 686 | } |
685 | 687 | |
@@ -693,23 +695,23 @@ discard block |
||
693 | 695 | //and so we record what record ended up being updated using the mapping |
694 | 696 | if( $model->has_primary_key_field() ){ |
695 | 697 | $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
696 | - }else{ |
|
698 | + } else{ |
|
697 | 699 | //no primary key just a combined key |
698 | 700 | $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
699 | 701 | } |
700 | 702 | $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
701 | - }else{ |
|
703 | + } else{ |
|
702 | 704 | $matched_items = $model->get_all(array($conditions)); |
703 | 705 | if( ! $matched_items){ |
704 | 706 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
705 | 707 | $this->_total_update_errors++; |
706 | 708 | EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
707 | - }else{ |
|
709 | + } else{ |
|
708 | 710 | $this->_total_updates++; |
709 | 711 | EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
710 | 712 | } |
711 | 713 | } |
712 | - }catch(EE_Error $e){ |
|
714 | + } catch(EE_Error $e){ |
|
713 | 715 | $this->_total_update_errors++; |
714 | 716 | $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
715 | 717 | $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |