@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | -require_once ( EE_MODELS . 'EEM_Base.model.php' ); |
|
2 | +require_once (EE_MODELS.'EEM_Base.model.php'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * |
@@ -21,60 +21,60 @@ discard block |
||
21 | 21 | * Please instead use the EEM_Attendee::system_question_* constants |
22 | 22 | * @deprecated |
23 | 23 | */ |
24 | - const fname_question_id=1; |
|
24 | + const fname_question_id = 1; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @deprecated |
28 | 28 | */ |
29 | - const lname_question_id=2; |
|
29 | + const lname_question_id = 2; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @deprecated |
34 | 34 | */ |
35 | - const email_question_id=3; |
|
35 | + const email_question_id = 3; |
|
36 | 36 | |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @deprecated |
40 | 40 | */ |
41 | - const address_question_id=4; |
|
41 | + const address_question_id = 4; |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @deprecated |
46 | 46 | */ |
47 | - const address2_question_id=5; |
|
47 | + const address2_question_id = 5; |
|
48 | 48 | |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @deprecated |
52 | 52 | */ |
53 | - const city_question_id=6; |
|
53 | + const city_question_id = 6; |
|
54 | 54 | |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @deprecated |
58 | 58 | */ |
59 | - const state_question_id=7; |
|
59 | + const state_question_id = 7; |
|
60 | 60 | |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @deprecated |
64 | 64 | */ |
65 | - const country_question_id=8; |
|
65 | + const country_question_id = 8; |
|
66 | 66 | |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @deprecated |
70 | 70 | */ |
71 | - const zip_question_id=9; |
|
71 | + const zip_question_id = 9; |
|
72 | 72 | |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @deprecated |
76 | 76 | */ |
77 | - const phone_question_id=10; |
|
77 | + const phone_question_id = 10; |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * When looking for questions that correspond to attendee fields, |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @access protected |
120 | 120 | * @param null $timezone |
121 | 121 | */ |
122 | - protected function __construct( $timezone = NULL ) { |
|
123 | - $this->singular_item = __('Attendee','event_espresso'); |
|
124 | - $this->plural_item = __('Attendees','event_espresso'); |
|
122 | + protected function __construct($timezone = NULL) { |
|
123 | + $this->singular_item = __('Attendee', 'event_espresso'); |
|
124 | + $this->plural_item = __('Attendees', 'event_espresso'); |
|
125 | 125 | $this->_tables = array( |
126 | 126 | 'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'), |
127 | 127 | 'Attendee_Meta'=>new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID') |
@@ -132,40 +132,40 @@ discard block |
||
132 | 132 | 'ATT_full_name'=>new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"), false, __("Unknown", "event_espresso")), |
133 | 133 | 'ATT_bio'=>new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"), false, __("No Biography Provided", "event_espresso")), |
134 | 134 | 'ATT_slug'=>new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false), |
135 | - 'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, EE_Datetime_Field::now ), |
|
135 | + 'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, EE_Datetime_Field::now), |
|
136 | 136 | 'ATT_short_bio'=>new EE_Simple_HTML_Field('post_excerpt', __("Attendee Short Biography", "event_espresso"), true, __("No Biography Provided", "event_espresso")), |
137 | - 'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, EE_Datetime_Field::now ), |
|
138 | - 'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false ), |
|
137 | + 'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, EE_Datetime_Field::now), |
|
138 | + 'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false), |
|
139 | 139 | 'ATT_parent'=>new EE_DB_Only_Int_Field('post_parent', __("Parent Attendee (unused)", "event_espresso"), false, 0), |
140 | - 'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'),// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'), |
|
140 | + 'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'), // EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'), |
|
141 | 141 | 'status' => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'), false, 'publish') |
142 | 142 | ), |
143 | 143 | 'Attendee_Meta'=>array( |
144 | - 'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID','event_espresso'), false), |
|
144 | + 'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'), false), |
|
145 | 145 | 'ATT_ID_fk'=>new EE_DB_Only_Int_Field('ATT_ID', __("Foreign Key to Attendee in Post Table", "event_espresso"), false), |
146 | - 'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name','event_espresso'), true, ''), |
|
147 | - 'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name','event_espresso'), true, ''), |
|
148 | - 'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1','event_espresso'), true, ''), |
|
149 | - 'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2','event_espresso'), true, ''), |
|
150 | - 'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City','event_espresso'), true, ''), |
|
151 | - 'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State','event_espresso'), true,0,'State'), |
|
152 | - 'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country','event_espresso'), true,'','Country'), |
|
153 | - 'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code','event_espresso'), true, ''), |
|
154 | - 'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address','event_espresso'), true, ''), |
|
155 | - 'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone','event_espresso'), true, '') |
|
146 | + 'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''), |
|
147 | + 'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''), |
|
148 | + 'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true, ''), |
|
149 | + 'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true, ''), |
|
150 | + 'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''), |
|
151 | + 'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0, 'State'), |
|
152 | + 'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '', 'Country'), |
|
153 | + 'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''), |
|
154 | + 'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''), |
|
155 | + 'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, '') |
|
156 | 156 | )); |
157 | 157 | $this->_model_relations = array( |
158 | 158 | 'Registration'=>new EE_Has_Many_Relation(), |
159 | 159 | 'State'=>new EE_Belongs_To_Relation(), |
160 | 160 | 'Country'=>new EE_Belongs_To_Relation(), |
161 | - 'Event'=>new EE_HABTM_Relation('Registration', FALSE ), |
|
161 | + 'Event'=>new EE_HABTM_Relation('Registration', FALSE), |
|
162 | 162 | 'WP_User' => new EE_Belongs_To_Relation(), |
163 | - 'Message' => new EE_Has_Many_Any_Relation( false ), //allow deletion of attendees even if they have messages in the queue for them. |
|
163 | + 'Message' => new EE_Has_Many_Any_Relation(false), //allow deletion of attendees even if they have messages in the queue for them. |
|
164 | 164 | 'Term_Relationship' => new EE_Has_Many_Relation(), |
165 | 165 | 'Term_Taxonomy'=>new EE_HABTM_Relation('Term_Relationship'), |
166 | 166 | ); |
167 | 167 | $this->_caps_slug = 'contacts'; |
168 | - parent::__construct( $timezone ); |
|
168 | + parent::__construct($timezone); |
|
169 | 169 | |
170 | 170 | } |
171 | 171 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @param string $system_question_string |
176 | 176 | * @return string|null if not found |
177 | 177 | */ |
178 | - public function get_attendee_field_for_system_question( $system_question_string ) { |
|
179 | - return isset( $this->_system_question_to_attendee_field_name[ $system_question_string ] ) ? $this->_system_question_to_attendee_field_name[ $system_question_string ] : null; |
|
178 | + public function get_attendee_field_for_system_question($system_question_string) { |
|
179 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) ? $this->_system_question_to_attendee_field_name[$system_question_string] : null; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param EE_Transaction/int $transaction_id_or_obj EE_Transaction or its ID |
188 | 188 | * @return EE_Attendee[] |
189 | 189 | */ |
190 | - public function get_attendees_for_transaction( $transaction_id_or_obj ){ |
|
191 | - return $this->get_all( array( array( |
|
190 | + public function get_attendees_for_transaction($transaction_id_or_obj) { |
|
191 | + return $this->get_all(array(array( |
|
192 | 192 | 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction ? $transaction_id_or_obj->ID() : $transaction_id_or_obj |
193 | 193 | ))); |
194 | 194 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * @return mixed array on success, FALSE on fail |
204 | 204 | * @deprecated |
205 | 205 | */ |
206 | - public function get_attendee_by_ID( $ATT_ID = FALSE ) { |
|
206 | + public function get_attendee_by_ID($ATT_ID = FALSE) { |
|
207 | 207 | // retrieve a particular EE_Attendee |
208 | - return $this->get_one_by_ID( $ATT_ID ); |
|
208 | + return $this->get_one_by_ID($ATT_ID); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | * @param array $where_cols_n_values |
219 | 219 | * @return mixed array on success, FALSE on fail |
220 | 220 | */ |
221 | - public function get_attendee( $where_cols_n_values = array() ) { |
|
221 | + public function get_attendee($where_cols_n_values = array()) { |
|
222 | 222 | |
223 | - if ( empty( $where_cols_n_values )) { |
|
223 | + if (empty($where_cols_n_values)) { |
|
224 | 224 | return FALSE; |
225 | 225 | } |
226 | - $attendee = $this->get_all( array($where_cols_n_values )); |
|
227 | - if ( ! empty( $attendee )) { |
|
228 | - return array_shift( $attendee ); |
|
226 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
227 | + if ( ! empty($attendee)) { |
|
228 | + return array_shift($attendee); |
|
229 | 229 | } else { |
230 | 230 | return FALSE; |
231 | 231 | } |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | * @param array $where_cols_n_values |
242 | 242 | * @return bool|mixed |
243 | 243 | */ |
244 | - public function find_existing_attendee( $where_cols_n_values = NULL ) { |
|
244 | + public function find_existing_attendee($where_cols_n_values = NULL) { |
|
245 | 245 | // search by combo of first and last names plus the email address |
246 | - $attendee_data_keys = array( 'ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email ); |
|
246 | + $attendee_data_keys = array('ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email); |
|
247 | 247 | // no search params means attendee object already exists. |
248 | - $where_cols_n_values = is_array( $where_cols_n_values ) && ! empty( $where_cols_n_values ) ? $where_cols_n_values : $attendee_data_keys; |
|
248 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values : $attendee_data_keys; |
|
249 | 249 | $valid_data = TRUE; |
250 | 250 | // check for required values |
251 | - $valid_data = isset( $where_cols_n_values['ATT_fname'] ) && ! empty( $where_cols_n_values['ATT_fname'] ) ? $valid_data : FALSE; |
|
252 | - $valid_data = isset( $where_cols_n_values['ATT_lname'] ) && ! empty( $where_cols_n_values['ATT_lname'] ) ? $valid_data : FALSE; |
|
253 | - $valid_data = isset( $where_cols_n_values['ATT_email'] ) && ! empty( $where_cols_n_values['ATT_email'] ) ? $valid_data : FALSE; |
|
251 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) ? $valid_data : FALSE; |
|
252 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) ? $valid_data : FALSE; |
|
253 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) ? $valid_data : FALSE; |
|
254 | 254 | |
255 | - if ( $valid_data ) { |
|
256 | - $attendee = $this->get_attendee( $where_cols_n_values ); |
|
257 | - if ( $attendee instanceof EE_Attendee ) { |
|
255 | + if ($valid_data) { |
|
256 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
257 | + if ($attendee instanceof EE_Attendee) { |
|
258 | 258 | return $attendee; |
259 | 259 | } |
260 | 260 | } |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * @param array $ids array of EE_Registration ids |
273 | 273 | * @return EE_Attendee[] |
274 | 274 | */ |
275 | - public function get_array_of_contacts_from_reg_ids( $ids ) { |
|
275 | + public function get_array_of_contacts_from_reg_ids($ids) { |
|
276 | 276 | $ids = (array) $ids; |
277 | 277 | $_where = array( |
278 | - 'Registration.REG_ID' => array( 'in', $ids ) |
|
278 | + 'Registration.REG_ID' => array('in', $ids) |
|
279 | 279 | ); |
280 | - return $this->get_all( array( $_where ) ); |
|
280 | + return $this->get_all(array($_where)); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 |
@@ -36,53 +36,53 @@ discard block |
||
36 | 36 | <h2 id="invoice-hdr"><?php _e('Order Confirmation', 'event_espresso')?></h2> |
37 | 37 | <h3 id="invoice-date"><?php _e('Date:', 'event_espresso')?> <span class="plain-text">[registration_date]</span></h3> |
38 | 38 | <h3 id="invoice-txn-id"><?php _e('Transaction ID:', 'event_espresso')?> <span class="plain-text">[transaction_id]</span></h3> |
39 | - <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso')?> <span class="<?php echo $transaction->status_ID()?> plain-text"><?php echo $transaction->pretty_status();?></span></h3> |
|
39 | + <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso')?> <span class="<?php echo $transaction->status_ID()?> plain-text"><?php echo $transaction->pretty_status(); ?></span></h3> |
|
40 | 40 | </div> |
41 | 41 | </td> |
42 | 42 | </tr> |
43 | 43 | </table> |
44 | 44 | <div class="events"> |
45 | - <?php foreach($events_for_txn as $event_id => $event){ |
|
46 | - ?><h3 class="section-title event-name"><img class="icon" src="<?php echo EE_IMAGES_URL.'calendar_year-24x24.png';?>"><?php _e("Event Name:","event_espresso")?> <span class="plain-text"><?php echo $event->name();?></span> <span class="small-text link">[ <a href='<?php echo $event->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></h3> |
|
47 | - <?php if (strlen($event->description()>1)){?><p class="event-description"><?php $event->description()?></p><?php }?> |
|
45 | + <?php foreach ($events_for_txn as $event_id => $event) { |
|
46 | + ?><h3 class="section-title event-name"><img class="icon" src="<?php echo EE_IMAGES_URL.'calendar_year-24x24.png'; ?>"><?php _e("Event Name:", "event_espresso")?> <span class="plain-text"><?php echo $event->name(); ?></span> <span class="small-text link">[ <a href='<?php echo $event->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></h3> |
|
47 | + <?php if (strlen($event->description() > 1)) {?><p class="event-description"><?php $event->description()?></p><?php }?> |
|
48 | 48 | <ul class="tickets-per-event"> |
49 | - <?php foreach($ticket_line_items_per_event[$event_id] as $line_item_id => $line_item){ |
|
49 | + <?php foreach ($ticket_line_items_per_event[$event_id] as $line_item_id => $line_item) { |
|
50 | 50 | $ticket = $line_item->ticket(); |
51 | - $taxable_html = $ticket->taxable() ? '*': ''; |
|
51 | + $taxable_html = $ticket->taxable() ? '*' : ''; |
|
52 | 52 | $subitems = $line_item->children(); |
53 | - $ticket_uses = $ticket->get_pretty('TKT_uses', __("any", "event_espresso")); |
|
53 | + $ticket_uses = $ticket->get_pretty('TKT_uses', __("any", "event_espresso")); |
|
54 | 54 | ?> |
55 | 55 | <li class="event-ticket"> |
56 | 56 | <div class="ticket-details"> |
57 | 57 | <table class="invoice-amount"> |
58 | 58 | <thead> |
59 | 59 | <tr class="header_row"> |
60 | - <th class="name-column"><?php _e("Ticket", "event_espresso");?></th> |
|
61 | - <th colspan="2" class="desc-column"><?php _e("Description", "event_espresso");?></th> |
|
62 | - <th class="number-column item_c"><?php _e("Quantity", "event_espresso");?></th> |
|
63 | - <th class="number-column item_c"><?php _e("Price", "event_espresso");?></th> |
|
64 | - <th class="number-column item_r"><?php _e("Total", "event_espresso");?></th> |
|
60 | + <th class="name-column"><?php _e("Ticket", "event_espresso"); ?></th> |
|
61 | + <th colspan="2" class="desc-column"><?php _e("Description", "event_espresso"); ?></th> |
|
62 | + <th class="number-column item_c"><?php _e("Quantity", "event_espresso"); ?></th> |
|
63 | + <th class="number-column item_c"><?php _e("Price", "event_espresso"); ?></th> |
|
64 | + <th class="number-column item_r"><?php _e("Total", "event_espresso"); ?></th> |
|
65 | 65 | </tr> |
66 | 66 | </thead> |
67 | 67 | <tbody> |
68 | - <?php if( count($subitems) < 2){?> |
|
68 | + <?php if (count($subitems) < 2) {?> |
|
69 | 69 | <tr class="item"> |
70 | 70 | <td><?php echo $line_item->name().$taxable_html?></td> |
71 | - <td colspan="2"><?php echo $line_item->desc();?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
71 | + <td colspan="2"><?php echo $line_item->desc(); ?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
72 | 72 | <td class="item_c"><?php echo $line_item->quantity()?></td> |
73 | 73 | <td class="item_c"><?php echo $line_item->unit_price_no_code()?></td> |
74 | 74 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
75 | 75 | </tr> |
76 | - <?php }else{?> |
|
76 | + <?php } else {?> |
|
77 | 77 | <tr class="item"> |
78 | 78 | <td class="aln-left"><?php echo $line_item->name().$taxable_html?></td> |
79 | - <td colspan="2"><?php echo $line_item->desc();?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
79 | + <td colspan="2"><?php echo $line_item->desc(); ?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
80 | 80 | <td class="item_c"><?php echo $line_item->quantity()?></td> |
81 | 81 | <td class="item_c"><?php echo $line_item->unit_price_no_code()?></td> |
82 | 82 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
83 | 83 | </tr> |
84 | - <?php foreach($subitems as $sub_line_item){ |
|
85 | - $is_percent = $sub_line_item->is_percent();?> |
|
84 | + <?php foreach ($subitems as $sub_line_item) { |
|
85 | + $is_percent = $sub_line_item->is_percent(); ?> |
|
86 | 86 | <tr class="subitem-row"> |
87 | 87 | <td class="subitem"><?php echo $sub_line_item->name()?></td> |
88 | 88 | <td colspan="2"><?php echo $sub_line_item->desc()?></td> |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | <?php } ?> |
94 | 94 | <tr class="total_tr odd"> |
95 | 95 | <td colspan="4"></td> |
96 | - <td class="total" nowrap="nowrap"><?php _e("Ticket Total:", "event_espresso");?></td> |
|
96 | + <td class="total" nowrap="nowrap"><?php _e("Ticket Total:", "event_espresso"); ?></td> |
|
97 | 97 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
98 | 98 | </tr> |
99 | 99 | <?php }?> |
@@ -104,22 +104,22 @@ discard block |
||
104 | 104 | <div class="reg-details-for-ticket"> |
105 | 105 | <div class="ticket-time-and-place-details"> |
106 | 106 | <div class="ticket-time-details"> |
107 | - <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png';?>"><?php echo _n("Date/Time:","Dates/Times:",count($ticket->datetimes()), "event_espresso");?></h4> |
|
107 | + <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png'; ?>"><?php echo _n("Date/Time:", "Dates/Times:", count($ticket->datetimes()), "event_espresso"); ?></h4> |
|
108 | 108 | <ul class="event-dates"> |
109 | - <?php foreach($ticket->datetimes_ordered() as $datetime){ |
|
109 | + <?php foreach ($ticket->datetimes_ordered() as $datetime) { |
|
110 | 110 | /* @var $datetime EE_Datetime */ ?> |
111 | 111 | <li><?php |
112 | - echo $datetime->name() ? '<b>'.$datetime->name().' </b>' : '' ; |
|
113 | - echo sprintf(__("%s - %s (%s)", "event_espresso"),$datetime->start_date_and_time(),$datetime->end_date_and_time(),$datetime->get_timezone()); |
|
112 | + echo $datetime->name() ? '<b>'.$datetime->name().' </b>' : ''; |
|
113 | + echo sprintf(__("%s - %s (%s)", "event_espresso"), $datetime->start_date_and_time(), $datetime->end_date_and_time(), $datetime->get_timezone()); |
|
114 | 114 | echo $datetime->description() ? '<p class="ticket-note">'.$datetime->description().'</p>' : '' ?></li> |
115 | 115 | <?php }?> |
116 | 116 | </ul> |
117 | 117 | </div> |
118 | - <?php if ($event->venues()){?> |
|
118 | + <?php if ($event->venues()) {?> |
|
119 | 119 | <div class="ticket-place-details"> |
120 | - <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png';?>"><?php echo _n("Venue:","Venues:",count($event->venues()), "event_espresso");?></h4> |
|
120 | + <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png'; ?>"><?php echo _n("Venue:", "Venues:", count($event->venues()), "event_espresso"); ?></h4> |
|
121 | 121 | <ul class="event-venues"> |
122 | - <?php foreach($event->venues() as $venue){?> |
|
122 | + <?php foreach ($event->venues() as $venue) {?> |
|
123 | 123 | <li><?php echo $venue->name()?> <span class="small-text">[ <a href='<?php echo $venue->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></li> |
124 | 124 | <?php } ?> |
125 | 125 | </ul> |
@@ -127,34 +127,34 @@ discard block |
||
127 | 127 | <?php }?> |
128 | 128 | </div> |
129 | 129 | <div class="ticket-registrations-area"> |
130 | - <h4 class="sub-section-title"><img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png';?>"><?php echo __("Registration Details", "event_espresso");?> <span class="small-text link">[ <a class="print_button noPrint" href="<?php echo $edit_reg_info_url; ?>"><?php _e('edit', 'event_espresso'); ?></a> ]</span></h4> |
|
130 | + <h4 class="sub-section-title"><img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png'; ?>"><?php echo __("Registration Details", "event_espresso"); ?> <span class="small-text link">[ <a class="print_button noPrint" href="<?php echo $edit_reg_info_url; ?>"><?php _e('edit', 'event_espresso'); ?></a> ]</span></h4> |
|
131 | 131 | <ul class="ticket-registrations-list"> |
132 | - <?php foreach($registrations_per_line_item[$line_item_id] as $registration){ |
|
132 | + <?php foreach ($registrations_per_line_item[$line_item_id] as $registration) { |
|
133 | 133 | /* @var $registration EE_Registration */ |
134 | 134 | $attendee = $registration->attendee(); |
135 | - $answers = $registration->answers(array('order_by'=>array('Question.Question_Group_Question.QGQ_order'=>'ASC')));?> |
|
135 | + $answers = $registration->answers(array('order_by'=>array('Question.Question_Group_Question.QGQ_order'=>'ASC'))); ?> |
|
136 | 136 | <li class="ticket-registration"> |
137 | 137 | <table class="registration-details"> |
138 | 138 | <tr class="odd"> |
139 | - <th><?php echo _e("Registration Code:", "event_espresso");?></th> |
|
140 | - <td><?php echo $registration->reg_code();?> - <span class="<?php echo $registration->status_ID()?>"><?php echo $registration->pretty_status()?></span></td> |
|
139 | + <th><?php echo _e("Registration Code:", "event_espresso"); ?></th> |
|
140 | + <td><?php echo $registration->reg_code(); ?> - <span class="<?php echo $registration->status_ID()?>"><?php echo $registration->pretty_status()?></span></td> |
|
141 | 141 | </tr> |
142 | 142 | <?php |
143 | - foreach($event->question_groups() as $question_group){ |
|
144 | - ?><tr><th><?php $question_group->e('QSG_name');?></th><td></td></tr><?php |
|
143 | + foreach ($event->question_groups() as $question_group) { |
|
144 | + ?><tr><th><?php $question_group->e('QSG_name'); ?></th><td></td></tr><?php |
|
145 | 145 | $has_personal_info = false; |
146 | - foreach($question_group->questions() as $question){ |
|
147 | - if( in_array($question->system_ID(),$questions_to_skip)){ |
|
146 | + foreach ($question_group->questions() as $question) { |
|
147 | + if (in_array($question->system_ID(), $questions_to_skip)) { |
|
148 | 148 | $has_personal_info = true; |
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | ?><tr> |
152 | 152 | <th><?php echo $question->display_text()?></th> |
153 | - <td><?php echo $registration->answer_value_to_question($question);?></td> |
|
153 | + <td><?php echo $registration->answer_value_to_question($question); ?></td> |
|
154 | 154 | </tr><?php |
155 | 155 | } |
156 | - if($has_personal_info){ |
|
157 | - ?><tr><th><?php _e('Attendee', 'event_espresso');?></th><td><?php echo sprintf(__('%s (%s)', "event_espresso"),$attendee->full_name(),$attendee->email())?></td></tr><?php |
|
156 | + if ($has_personal_info) { |
|
157 | + ?><tr><th><?php _e('Attendee', 'event_espresso'); ?></th><td><?php echo sprintf(__('%s (%s)', "event_espresso"), $attendee->full_name(), $attendee->email())?></td></tr><?php |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | ?> |
@@ -171,21 +171,21 @@ discard block |
||
171 | 171 | <?php }?> |
172 | 172 | </div> |
173 | 173 | <div class="taxes"> |
174 | - <?php if ($tax_total_line_item && $tax_total_line_item->children()){?> |
|
175 | - <h3 class="section-title"><?php _e("Taxes",'event_espresso')?></h3> |
|
174 | + <?php if ($tax_total_line_item && $tax_total_line_item->children()) {?> |
|
175 | + <h3 class="section-title"><?php _e("Taxes", 'event_espresso')?></h3> |
|
176 | 176 | <table class="invoice-amount"> |
177 | 177 | |
178 | 178 | <thead> |
179 | 179 | <tr class="header_row"> |
180 | - <th class="left ticket_th"><?php _e("Tax Name", "event_espresso");?></th> |
|
181 | - <th class="left"><?php _e('Description', 'event_espresso');?></th> |
|
180 | + <th class="left ticket_th"><?php _e("Tax Name", "event_espresso"); ?></th> |
|
181 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
182 | 182 | <th class="event_th item_c"><?php _e('Rate', 'event_espresso'); ?></th> |
183 | 183 | <th class="subtotal_th"><?php _e('Tax Amount', 'event_espresso'); ?></th> |
184 | 184 | </tr> |
185 | 185 | </thead> |
186 | 186 | <tbody> |
187 | 187 | <?php |
188 | - foreach($tax_total_line_item->children() as $child_tax){?> |
|
188 | + foreach ($tax_total_line_item->children() as $child_tax) {?> |
|
189 | 189 | <tr> |
190 | 190 | <td><?php echo $child_tax->name()?></td> |
191 | 191 | <td><?php echo $child_tax->desc()?></td> |
@@ -195,26 +195,26 @@ discard block |
||
195 | 195 | <?php } ?> |
196 | 196 | <tr class="total_tr odd"> |
197 | 197 | <td class="total_tr" colspan="2"></td> |
198 | - <td class="total"><?php _e("Tax Total:", "event_espresso");?></td> |
|
198 | + <td class="total"><?php _e("Tax Total:", "event_espresso"); ?></td> |
|
199 | 199 | <td class="item_r"><?php echo $tax_total_line_item->total_no_code()?></td> |
200 | 200 | </tr> |
201 | 201 | </tbody> |
202 | 202 | |
203 | 203 | </table> |
204 | 204 | <?php }?> |
205 | - <p><?php _e("* taxable items", "event_espresso");?></p> |
|
205 | + <p><?php _e("* taxable items", "event_espresso"); ?></p> |
|
206 | 206 | </div> |
207 | 207 | <div class="grand-total-dv"> |
208 | - <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"),EEH_Template::format_currency($total_cost));?></h2> |
|
208 | + <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"), EEH_Template::format_currency($total_cost)); ?></h2> |
|
209 | 209 | </div> |
210 | 210 | <div class="payment-dv"> |
211 | - <h3 class="section-title"><?php _e("Payments",'event_espresso')?></h3> |
|
211 | + <h3 class="section-title"><?php _e("Payments", 'event_espresso')?></h3> |
|
212 | 212 | <p>[instructions]</p> |
213 | 213 | <table class="invoice-amount"> |
214 | 214 | <thead> |
215 | 215 | <tr class="header_row"> |
216 | 216 | <th><span class=""><?php _e('Payment Method', 'event_espresso'); ?></span></th> |
217 | - <th class='left datetime_th'><?php _e("Date",'event_espresso')?></th> |
|
217 | + <th class='left datetime_th'><?php _e("Date", 'event_espresso')?></th> |
|
218 | 218 | <th><span class=""><?php _e('Transaction Id / Cheque #', 'event_espresso'); ?></span></th> |
219 | 219 | <th><span class=""><?php _e('P.O. / S.O.#', 'event_espresso'); ?></span></th> |
220 | 220 | <th><span class=""><?php _e('Status', 'event_espresso'); ?></span></th> |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | <tbody> |
225 | 225 | <?php |
226 | 226 | $c = false; |
227 | - if(!empty($payments)){ |
|
227 | + if ( ! empty($payments)) { |
|
228 | 228 | |
229 | - foreach($payments as $payment){ |
|
229 | + foreach ($payments as $payment) { |
|
230 | 230 | /* @var $payment EE_Payment */?> |
231 | - <tr class='item <?php echo (($c = !$c) ? ' odd' : '')?>'> |
|
231 | + <tr class='item <?php echo (($c = ! $c) ? ' odd' : '')?>'> |
|
232 | 232 | <td><?php $payment->e('PAY_gateway')?></td> |
233 | 233 | <td><?php echo $payment->timestamp()?></td> |
234 | 234 | <td><?php $payment->e('PAY_txn_id_chq_nmbr')?></td> |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | <td class='item_r'><?php echo $payment->amount_no_code()?></td> |
238 | 238 | </tr> |
239 | 239 | <?php } |
240 | - }else{?> |
|
240 | + } else {?> |
|
241 | 241 | <tr class='item'> |
242 | - <td class='aln-cntr' colspan="6"><?php _e("No approved payments have been received.",'event_espresso')?> </td> |
|
242 | + <td class='aln-cntr' colspan="6"><?php _e("No approved payments have been received.", 'event_espresso')?> </td> |
|
243 | 243 | </tr> |
244 | 244 | <?php } |
245 | - ?><tr class="item" ><td class='aln-cntr' colspan="6"><?php if($amount_owed){?><a class="noPrint" href='<?php echo $retry_payment_url?>'><?php _e("Please make a payment.", "event_espresso");}?></a></td></tr> |
|
245 | + ?><tr class="item" ><td class='aln-cntr' colspan="6"><?php if ($amount_owed) {?><a class="noPrint" href='<?php echo $retry_payment_url?>'><?php _e("Please make a payment.", "event_espresso"); }?></a></td></tr> |
|
246 | 246 | </tbody> |
247 | 247 | <tfoot> |
248 | 248 | <tr class='total_tr'><td colspan="4"> </td> |
249 | - <td class="item_r"><?php _e('Total Paid','event_espresso')?></td> |
|
250 | - <td class="item_r"><?php echo EEH_Template::format_currency($amount_pd,false,false)?> </td> |
|
249 | + <td class="item_r"><?php _e('Total Paid', 'event_espresso')?></td> |
|
250 | + <td class="item_r"><?php echo EEH_Template::format_currency($amount_pd, false, false)?> </td> |
|
251 | 251 | </tr> |
252 | 252 | <?php //echo $discount; ?> |
253 | 253 | <tr class="total_tr odd"> |
@@ -259,20 +259,20 @@ discard block |
||
259 | 259 | </table> |
260 | 260 | </div> |
261 | 261 | <div class="additional-info-dv"> |
262 | - <h3 class="section-title"><?php _e("Additional Information:", "event_espresso");?></h3> |
|
262 | + <h3 class="section-title"><?php _e("Additional Information:", "event_espresso"); ?></h3> |
|
263 | 263 | <div class="additional-info"> |
264 | - <?php if($venues_for_events){?> |
|
265 | - <h2><?php echo _n("Venue Details:", "Venues Details:", "event_espresso",count($venues_for_events));?></h2> |
|
264 | + <?php if ($venues_for_events) {?> |
|
265 | + <h2><?php echo _n("Venue Details:", "Venues Details:", "event_espresso", count($venues_for_events)); ?></h2> |
|
266 | 266 | <table class="venue-list"> |
267 | - <?php foreach($venues_for_events as $venue){?> |
|
267 | + <?php foreach ($venues_for_events as $venue) {?> |
|
268 | 268 | <tr class="venue-details"> |
269 | 269 | <td class="venue-details-part venue-address-dv"> |
270 | 270 | <h3><a href='<?php echo $venue->get_permalink()?>'><?php |
271 | 271 | echo $venue->name() |
272 | 272 | ?></a></h3> |
273 | 273 | <p><?php echo $venue->description()?></p> |
274 | - <?php echo EEH_Address::format($venue);?></td> |
|
275 | - <?php if($venue->enable_for_gmap()){?> |
|
274 | + <?php echo EEH_Address::format($venue); ?></td> |
|
275 | + <?php if ($venue->enable_for_gmap()) {?> |
|
276 | 276 | <td class="venue-details-part venue-image-dv"><?php echo EEH_Venue_View::espresso_google_static_map($venue)?></td> |
277 | 277 | <?php } ?> |
278 | 278 | </tr> |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | </td> |
24 | 24 | <td> |
25 | 25 | <div id="invoice-info"> |
26 | - <h2 id="invoice-hdr"><?php _e( 'Order Confirmation', 'event_espresso' ) ?></h2> |
|
26 | + <h2 id="invoice-hdr"><?php _e('Order Confirmation', 'event_espresso') ?></h2> |
|
27 | 27 | |
28 | - <h3 id="invoice-date"><?php _e( 'Date:', 'event_espresso' ) ?> |
|
28 | + <h3 id="invoice-date"><?php _e('Date:', 'event_espresso') ?> |
|
29 | 29 | <span class="plain-text">[PRIMARY_REGISTRANT_REGISTRATION_DATE]</span></h3> |
30 | 30 | |
31 | - <h3 id="invoice-txn-id"><?php _e( 'Transaction ID:', 'event_espresso' ) ?> |
|
31 | + <h3 id="invoice-txn-id"><?php _e('Transaction ID:', 'event_espresso') ?> |
|
32 | 32 | <span class="plain-text">[TXN_ID]</span></h3> |
33 | 33 | |
34 | - <h3 id="invoice-txn-status"><?php _e( 'Status:', 'event_espresso' ) ?> |
|
34 | + <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso') ?> |
|
35 | 35 | <span class="[TXN_STATUS_ID] plain-text">[TXN_STATUS]</span></h3> |
36 | 36 | </div> |
37 | 37 | </td> |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | [EVENT_LIST] |
42 | 42 | </div> |
43 | 43 | <div class="taxes"> |
44 | - <h3 class="section-title"><?php _e( "Additional Charges/Discounts", 'event_espresso' ) ?></h3> |
|
44 | + <h3 class="section-title"><?php _e("Additional Charges/Discounts", 'event_espresso') ?></h3> |
|
45 | 45 | <table class="invoice-amount"> |
46 | 46 | <thead> |
47 | 47 | <tr class="header_row"> |
48 | - <th class="left ticket_th"><?php _e( "Name", "event_espresso" ); ?></th> |
|
49 | - <th class="left"><?php _e( 'Description', 'event_espresso' ); ?></th> |
|
50 | - <th class="event_th item_c"><?php _e( 'Quantity', 'event_espresso' ); ?></th> |
|
51 | - <th class="event_th item_c"><?php _e( 'Unit Price', 'event_espresso' ); ?></th> |
|
52 | - <th class="subtotal_th"><?php _e( 'Total', 'event_espresso' ); ?></th> |
|
48 | + <th class="left ticket_th"><?php _e("Name", "event_espresso"); ?></th> |
|
49 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
50 | + <th class="event_th item_c"><?php _e('Quantity', 'event_espresso'); ?></th> |
|
51 | + <th class="event_th item_c"><?php _e('Unit Price', 'event_espresso'); ?></th> |
|
52 | + <th class="subtotal_th"><?php _e('Total', 'event_espresso'); ?></th> |
|
53 | 53 | </tr> |
54 | 54 | </thead> |
55 | 55 | <tbody> |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | </table> |
61 | 61 | </div> |
62 | 62 | <div class="taxes"> |
63 | - <h3 class="section-title"><?php _e( "Taxes", 'event_espresso' ) ?></h3> |
|
64 | - <p><?php printf( __( '%s*%s Taxable items. The total amount collected for taxes is reflected in the total(s) below.', 'event_espresso' ), '<strong>', '</strong>' ); ?></p> |
|
63 | + <h3 class="section-title"><?php _e("Taxes", 'event_espresso') ?></h3> |
|
64 | + <p><?php printf(__('%s*%s Taxable items. The total amount collected for taxes is reflected in the total(s) below.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
65 | 65 | <table class="invoice-amount"> |
66 | 66 | <thead> |
67 | 67 | <tr class="header_row"> |
68 | - <th class="left ticket_th"><?php _e( "Tax Name", "event_espresso" ); ?></th> |
|
69 | - <th class="left"><?php _e( 'Description', 'event_espresso' ); ?></th> |
|
70 | - <th class="event_th item_c"><?php _e( 'Rate', 'event_espresso' ); ?></th> |
|
71 | - <th class="subtotal_th"><?php _e( 'Tax Amount', 'event_espresso' ); ?></th> |
|
68 | + <th class="left ticket_th"><?php _e("Tax Name", "event_espresso"); ?></th> |
|
69 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
70 | + <th class="event_th item_c"><?php _e('Rate', 'event_espresso'); ?></th> |
|
71 | + <th class="subtotal_th"><?php _e('Tax Amount', 'event_espresso'); ?></th> |
|
72 | 72 | </tr> |
73 | 73 | </thead> |
74 | 74 | <tbody> |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | </table> |
80 | 80 | </div> |
81 | 81 | <div class="grand-total-dv"> |
82 | - <h2 class="grand-total"><?php printf( __( "Grand Total: %s", "event_espresso" ), '[TOTAL_COST]' ); ?></h2> |
|
82 | + <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"), '[TOTAL_COST]'); ?></h2> |
|
83 | 83 | </div> |
84 | 84 | <div class="payment-dv"> |
85 | - <h3 class="section-title"><?php _e( "Payments", 'event_espresso' ) ?></h3> |
|
85 | + <h3 class="section-title"><?php _e("Payments", 'event_espresso') ?></h3> |
|
86 | 86 | <table class="invoice-amount"> |
87 | 87 | <thead> |
88 | 88 | <tr class="header_row"> |
89 | - <th><span class=""><?php _e( 'Payment Method', 'event_espresso' ); ?></span></th> |
|
90 | - <th class='left datetime_th'><?php _e( "Date", 'event_espresso' ) ?></th> |
|
91 | - <th><span class=""><?php _e( 'Transaction Id / Cheque #', 'event_espresso' ); ?></span></th> |
|
92 | - <th><span class=""><?php _e( 'P.O. / S.O.#', 'event_espresso' ); ?></span></th> |
|
93 | - <th><span class=""><?php _e( 'Status', 'event_espresso' ); ?></span></th> |
|
94 | - <th><?php _e( 'Amount', 'event_espresso' ); ?></th> |
|
89 | + <th><span class=""><?php _e('Payment Method', 'event_espresso'); ?></span></th> |
|
90 | + <th class='left datetime_th'><?php _e("Date", 'event_espresso') ?></th> |
|
91 | + <th><span class=""><?php _e('Transaction Id / Cheque #', 'event_espresso'); ?></span></th> |
|
92 | + <th><span class=""><?php _e('P.O. / S.O.#', 'event_espresso'); ?></span></th> |
|
93 | + <th><span class=""><?php _e('Status', 'event_espresso'); ?></span></th> |
|
94 | + <th><?php _e('Amount', 'event_espresso'); ?></th> |
|
95 | 95 | </tr> |
96 | 96 | </thead> |
97 | 97 | <tbody> |
@@ -105,21 +105,21 @@ discard block |
||
105 | 105 | <tfoot> |
106 | 106 | <tr class='total_tr'> |
107 | 107 | <td colspan="4"> </td> |
108 | - <td class="item_r"><?php _e( 'Total Paid', 'event_espresso' ) ?></td> |
|
108 | + <td class="item_r"><?php _e('Total Paid', 'event_espresso') ?></td> |
|
109 | 109 | <td class="item_r">[TOTAL_AMOUNT_PAID]</td> |
110 | 110 | </tr> |
111 | 111 | <tr class="total_tr odd"> |
112 | 112 | <td colspan="4"> </td> |
113 | - <td class="total" id="total_currency"><?php _e( 'Amount Owed:', 'event_espresso' ); ?></td> |
|
113 | + <td class="total" id="total_currency"><?php _e('Amount Owed:', 'event_espresso'); ?></td> |
|
114 | 114 | <td class="total">[TOTAL_OWING]</td> |
115 | 115 | </tr> |
116 | 116 | </tfoot> |
117 | 117 | </table> |
118 | 118 | </div> |
119 | 119 | <div class="additional-info-dv"> |
120 | - <h3 class="section-title"><?php _e( "Additional Information:", "event_espresso" ); ?></h3> |
|
120 | + <h3 class="section-title"><?php _e("Additional Information:", "event_espresso"); ?></h3> |
|
121 | 121 | <div class="additional-info"> |
122 | - <h2><?php _e( "Venue Details:", "event_espresso" ); ?></h2> |
|
122 | + <h2><?php _e("Venue Details:", "event_espresso"); ?></h2> |
|
123 | 123 | <table class="venue-list"> |
124 | 124 | <tr class="venue-details"> |
125 | 125 | <td class="venue-details-part venue-address-dv"> |
@@ -1,7 +1,7 @@ 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 | -require_once( EE_MODELS . 'EEM_Base.model.php' ); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param string $timezone |
26 | 26 | */ |
27 | - protected function __construct( $timezone = null ) { |
|
28 | - $this->singular_item = __( 'Term Relationship', 'event_espresso' ); |
|
29 | - $this->plural_item = __( 'Term Relationships', 'event_espresso' ); |
|
27 | + protected function __construct($timezone = null) { |
|
28 | + $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
29 | + $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
30 | 30 | $this->_tables = array( |
31 | - 'Term_Relationship' => new EE_Primary_Table( 'term_relationships' ), |
|
31 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
32 | 32 | ); |
33 | - $models_this_can_attach_to = array_keys( EE_Registry::instance()->cpt_models() ); |
|
33 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
34 | 34 | $this->_fields = array( |
35 | 35 | 'Term_Relationship' => array( |
36 | 36 | 'object_id' => new EE_Foreign_Key_Int_Field( |
37 | 37 | 'object_id', |
38 | - __( 'Object(Post) ID', 'event_espresso' ), |
|
38 | + __('Object(Post) ID', 'event_espresso'), |
|
39 | 39 | false, |
40 | 40 | 0, |
41 | 41 | $models_this_can_attach_to |
@@ -51,63 +51,63 @@ discard block |
||
51 | 51 | 'Term_Taxonomy' |
52 | 52 | ), |
53 | 53 | 'term_order' => new EE_Integer_Field( |
54 | - 'term_order', __( 'Term Order', 'event_espresso' ), false, 0 |
|
54 | + 'term_order', __('Term Order', 'event_espresso'), false, 0 |
|
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | ); |
58 | 58 | $this->_model_relations = array( |
59 | 59 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
60 | 60 | ); |
61 | - foreach ( $models_this_can_attach_to as $model_name ) { |
|
62 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + foreach ($models_this_can_attach_to as $model_name) { |
|
62 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
63 | 63 | } |
64 | 64 | $this->_indexes = array( |
65 | - 'PRIMARY' => new EE_Primary_Key_Index( array( 'object_id', 'term_taxonomy_id' ) ), |
|
65 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | 66 | ); |
67 | 67 | $path_to_event_model = 'Event.'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | 69 | $path_to_event_model |
70 | 70 | ); |
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
72 | 72 | $path_to_event_model |
73 | 73 | ); |
74 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
74 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
75 | 75 | $path_to_event_model |
76 | 76 | ); |
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
77 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
78 | 78 | $path_to_event_model, EEM_Base::caps_edit |
79 | 79 | ); |
80 | 80 | $path_to_tax_model = 'Term_Taxonomy.'; |
81 | 81 | //add cap restrictions for editing term relations to the "ee_assign_*" |
82 | 82 | //and for deleting term relations too |
83 | - $cap_contexts_affected = array( EEM_Base::caps_edit, EEM_Base::caps_delete ); |
|
84 | - foreach ( $cap_contexts_affected as $cap_context_affected ) { |
|
85 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = new EE_Default_Where_Conditions( |
|
83 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
84 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
85 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = new EE_Default_Where_Conditions( |
|
86 | 86 | array( |
87 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
87 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
88 | 88 | '!=', |
89 | 89 | 'espresso_event_categories', |
90 | 90 | ), |
91 | 91 | ) |
92 | 92 | ); |
93 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = new EE_Default_Where_Conditions( |
|
93 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = new EE_Default_Where_Conditions( |
|
94 | 94 | array( |
95 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
95 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
96 | 96 | '!=', |
97 | 97 | 'espresso_venue_categories', |
98 | 98 | ), |
99 | 99 | ) |
100 | 100 | ); |
101 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
101 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
102 | 102 | array( |
103 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array( '!=', 'espresso_event_type' ), |
|
103 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
104 | 104 | ) |
105 | 105 | ); |
106 | 106 | } |
107 | - parent::__construct( $timezone ); |
|
107 | + parent::__construct($timezone); |
|
108 | 108 | add_filter( |
109 | 109 | 'FHEE__Read__create_model_query_params', |
110 | - array( 'EEM_Term_Relationship', 'rest_api_query_params' ), |
|
110 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
111 | 111 | 10, |
112 | 112 | 3 |
113 | 113 | ); |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | * @global wpdb $wpdb |
123 | 123 | * @return int the number of rows affected |
124 | 124 | */ |
125 | - public function update_term_taxonomy_counts( $term_taxonomy_id = null ) { |
|
125 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) { |
|
126 | 126 | //because this uses a subquery and sometimes assigning to column to be another column's |
127 | 127 | //value, we just write the SQL directly. |
128 | 128 | global $wpdb; |
129 | - if ( $term_taxonomy_id ) { |
|
130 | - $second_operand = $wpdb->prepare( '%d', $term_taxonomy_id ); |
|
129 | + if ($term_taxonomy_id) { |
|
130 | + $second_operand = $wpdb->prepare('%d', $term_taxonomy_id); |
|
131 | 131 | } else { |
132 | 132 | $second_operand = 'tr.term_taxonomy_id'; |
133 | 133 | } |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param array $field_n_values @see EEM_Base::insert |
153 | 153 | * @return boolean |
154 | 154 | */ |
155 | - public function insert( $field_n_values ) { |
|
156 | - $return = parent::insert( $field_n_values ); |
|
157 | - if ( isset( $field_n_values['term_taxonomy_id'] ) ) { |
|
158 | - $this->update_term_taxonomy_counts( $field_n_values['term_taxonomy_id'] ); |
|
155 | + public function insert($field_n_values) { |
|
156 | + $return = parent::insert($field_n_values); |
|
157 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
158 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
159 | 159 | } |
160 | 160 | return $return; |
161 | 161 | } |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * could get out-of-sync with the database |
176 | 176 | * @return int |
177 | 177 | */ |
178 | - public function update( $fields_n_values, $query_params, $keep_model_objs_in_sync = true ) { |
|
179 | - $count = parent::update( $fields_n_values, $query_params, $keep_model_objs_in_sync ); |
|
180 | - if ( $count ) { |
|
178 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) { |
|
179 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
180 | + if ($count) { |
|
181 | 181 | $this->update_term_taxonomy_counts(); |
182 | 182 | } |
183 | 183 | return $count; |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | * @param boolean $allow_blocking |
194 | 194 | * @return int @see EEM_Base::delete |
195 | 195 | */ |
196 | - public function delete( $query_params, $allow_blocking = true ) { |
|
197 | - $count = parent::delete( $query_params, $allow_blocking ); |
|
198 | - if ( $count ) { |
|
196 | + public function delete($query_params, $allow_blocking = true) { |
|
197 | + $count = parent::delete($query_params, $allow_blocking); |
|
198 | + if ($count) { |
|
199 | 199 | $this->update_term_taxonomy_counts(); |
200 | 200 | } |
201 | 201 | return $count; |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | * @param EEM_Base $model |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - public static function rest_api_query_params( $model_query_params, $querystring_query_params, $model ) { |
|
216 | - if ( $model === EEM_Term_Relationship::instance() ) { |
|
217 | - $taxonomies = get_taxonomies( array( 'show_in_rest' => true ) ); |
|
218 | - if ( ! empty( $taxonomies ) ) { |
|
219 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array( 'IN', $taxonomies ); |
|
215 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) { |
|
216 | + if ($model === EEM_Term_Relationship::instance()) { |
|
217 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
218 | + if ( ! empty($taxonomies)) { |
|
219 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | return $model_query_params; |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
555 | 555 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
556 | 556 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
557 | - }else{ |
|
557 | + } else{ |
|
558 | 558 | return array(); |
559 | 559 | } |
560 | 560 | } |
@@ -812,13 +812,13 @@ discard block |
||
812 | 812 | $last_model_name = end( $models_to_follow_to_wp_users ); |
813 | 813 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
814 | 814 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
815 | - }else{ |
|
815 | + } else{ |
|
816 | 816 | $model_with_fk_to_wp_users = $this; |
817 | 817 | $model_chain_to_wp_user = ''; |
818 | 818 | } |
819 | 819 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
820 | 820 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
821 | - }catch( EE_Error $e ) { |
|
821 | + } catch( EE_Error $e ) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | } |
@@ -846,11 +846,11 @@ discard block |
||
846 | 846 | public function is_owned() { |
847 | 847 | if( $this->model_chain_to_wp_user() ){ |
848 | 848 | return true; |
849 | - }else{ |
|
849 | + } else{ |
|
850 | 850 | try{ |
851 | 851 | $this->get_foreign_key_to( 'WP_User' ); |
852 | 852 | return true; |
853 | - }catch( EE_Error $e ){ |
|
853 | + } catch( EE_Error $e ){ |
|
854 | 854 | return false; |
855 | 855 | } |
856 | 856 | } |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
947 | 947 | } |
948 | 948 | $columns_to_select_string = implode(", ",$select_sql_array); |
949 | - }else{ |
|
949 | + } else{ |
|
950 | 950 | $columns_to_select_string = $columns_to_select; |
951 | 951 | } |
952 | 952 | return $columns_to_select_string; |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | $conditions_from_id = $this->parse_index_primary_key_string( $id ); |
1005 | 1005 | if( $conditions_from_id === null ) { |
1006 | 1006 | $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
1007 | - }else{ |
|
1007 | + } else{ |
|
1008 | 1008 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1009 | 1009 | $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
1010 | 1010 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | $items = $this->get_all($query_params); |
1032 | 1032 | if(empty($items)){ |
1033 | 1033 | return null; |
1034 | - }else{ |
|
1034 | + } else{ |
|
1035 | 1035 | return array_shift($items); |
1036 | 1036 | } |
1037 | 1037 | } |
@@ -1417,7 +1417,7 @@ discard block |
||
1417 | 1417 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1418 | 1418 | if( $this->has_primary_key_field() ){ |
1419 | 1419 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1420 | - }else{ |
|
1420 | + } else{ |
|
1421 | 1421 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1422 | 1422 | $main_table_pk_value = null; |
1423 | 1423 | } |
@@ -1456,7 +1456,7 @@ discard block |
||
1456 | 1456 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1457 | 1457 | if( $this->has_primary_key_field() ){ |
1458 | 1458 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1459 | - }else{ |
|
1459 | + } else{ |
|
1460 | 1460 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1461 | 1461 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1462 | 1462 | $model_objs_affected_ids = array(); |
@@ -1520,9 +1520,9 @@ discard block |
||
1520 | 1520 | |
1521 | 1521 | if( $field_to_select ){ |
1522 | 1522 | $field = $this->field_settings_for( $field_to_select ); |
1523 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1523 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1524 | 1524 | $field = $this->get_primary_key_field(); |
1525 | - }else{ |
|
1525 | + } else{ |
|
1526 | 1526 | //no primary key, just grab the first column |
1527 | 1527 | $field = reset( $this->field_settings()); |
1528 | 1528 | } |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | $col = $this->get_col( $query_params, $field_to_select ); |
1550 | 1550 | if( ! empty( $col ) ) { |
1551 | 1551 | return reset( $col ); |
1552 | - }else{ |
|
1552 | + } else{ |
|
1553 | 1553 | return NULL; |
1554 | 1554 | } |
1555 | 1555 | } |
@@ -1676,7 +1676,7 @@ discard block |
||
1676 | 1676 | |
1677 | 1677 | // /echo "delete sql:$SQL"; |
1678 | 1678 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1679 | - }else{ |
|
1679 | + } else{ |
|
1680 | 1680 | $rows_deleted = 0; |
1681 | 1681 | } |
1682 | 1682 | |
@@ -1720,7 +1720,7 @@ discard block |
||
1720 | 1720 | //first, if $ignore_this_model_obj was supplied, get its model |
1721 | 1721 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1722 | 1722 | $ignored_model = $ignore_this_model_obj->get_model(); |
1723 | - }else{ |
|
1723 | + } else{ |
|
1724 | 1724 | $ignored_model = null; |
1725 | 1725 | } |
1726 | 1726 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1733,7 +1733,7 @@ discard block |
||
1733 | 1733 | if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
1734 | 1734 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1735 | 1735 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1736 | - }else{ |
|
1736 | + } else{ |
|
1737 | 1737 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1738 | 1738 | } |
1739 | 1739 | |
@@ -1806,7 +1806,7 @@ discard block |
||
1806 | 1806 | } |
1807 | 1807 | |
1808 | 1808 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1809 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1809 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1810 | 1810 | $ways_to_identify_a_row = array(); |
1811 | 1811 | $fields = $this->get_combined_primary_key_fields(); |
1812 | 1812 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1822,7 +1822,7 @@ discard block |
||
1822 | 1822 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1823 | 1823 | } |
1824 | 1824 | return implode(" OR ",$ways_to_identify_a_row); |
1825 | - }else{ |
|
1825 | + } else{ |
|
1826 | 1826 | //so there's no primary key and no combined key... |
1827 | 1827 | //sorry, can't help you |
1828 | 1828 | throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
@@ -1846,10 +1846,10 @@ discard block |
||
1846 | 1846 | if($field_to_count){ |
1847 | 1847 | $field_obj = $this->field_settings_for($field_to_count); |
1848 | 1848 | $column_to_count = $field_obj->get_qualified_column(); |
1849 | - }elseif($this->has_primary_key_field ()){ |
|
1849 | + } elseif($this->has_primary_key_field ()){ |
|
1850 | 1850 | $pk_field_obj = $this->get_primary_key_field(); |
1851 | 1851 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1852 | - }else{ |
|
1852 | + } else{ |
|
1853 | 1853 | //there's no primary key |
1854 | 1854 | //if we're counting distinct items, and there's no primary key, |
1855 | 1855 | //we need to list out the columns for distinction; |
@@ -1887,7 +1887,7 @@ discard block |
||
1887 | 1887 | if($field_to_sum){ |
1888 | 1888 | $field_obj = $this->field_settings_for($field_to_sum); |
1889 | 1889 | |
1890 | - }else{ |
|
1890 | + } else{ |
|
1891 | 1891 | $field_obj = $this->get_primary_key_field(); |
1892 | 1892 | } |
1893 | 1893 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1897,7 +1897,7 @@ discard block |
||
1897 | 1897 | $data_type = $field_obj->get_wpdb_data_type(); |
1898 | 1898 | if( $data_type === '%d' || $data_type === '%s' ){ |
1899 | 1899 | return (float)$return_value; |
1900 | - }else{//must be %f |
|
1900 | + } else{//must be %f |
|
1901 | 1901 | return (float)$return_value; |
1902 | 1902 | } |
1903 | 1903 | } |
@@ -1935,10 +1935,10 @@ discard block |
||
1935 | 1935 | $wpdb->show_errors( $old_show_errors_value ); |
1936 | 1936 | if( ! empty( $wpdb->last_error ) ){ |
1937 | 1937 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1938 | - }elseif( $result === false ){ |
|
1938 | + } elseif( $result === false ){ |
|
1939 | 1939 | throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
1940 | 1940 | } |
1941 | - }elseif( $result === false ) { |
|
1941 | + } elseif( $result === false ) { |
|
1942 | 1942 | EE_Error::add_error( |
1943 | 1943 | sprintf( |
1944 | 1944 | __( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ), |
@@ -2280,7 +2280,7 @@ discard block |
||
2280 | 2280 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
2281 | 2281 | if( $results ){ |
2282 | 2282 | return array_shift($results); |
2283 | - }else{ |
|
2283 | + } else{ |
|
2284 | 2284 | return null; |
2285 | 2285 | } |
2286 | 2286 | |
@@ -2351,7 +2351,7 @@ discard block |
||
2351 | 2351 | */ |
2352 | 2352 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2353 | 2353 | return $new_id; |
2354 | - }else{ |
|
2354 | + } else{ |
|
2355 | 2355 | return FALSE; |
2356 | 2356 | } |
2357 | 2357 | } |
@@ -2413,9 +2413,9 @@ discard block |
||
2413 | 2413 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2414 | 2414 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2415 | 2415 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2416 | - }elseif( is_array($obj_or_fields_array)){ |
|
2416 | + } elseif( is_array($obj_or_fields_array)){ |
|
2417 | 2417 | $fields_n_values = $obj_or_fields_array; |
2418 | - }else{ |
|
2418 | + } else{ |
|
2419 | 2419 | throw new EE_Error( |
2420 | 2420 | sprintf( |
2421 | 2421 | __( |
@@ -2440,7 +2440,7 @@ discard block |
||
2440 | 2440 | //if there is nothing to base this search on, then we shouldn't find anything |
2441 | 2441 | if( empty( $query_params ) ){ |
2442 | 2442 | return array(); |
2443 | - }else{ |
|
2443 | + } else{ |
|
2444 | 2444 | return $this->get_one($query_params); |
2445 | 2445 | } |
2446 | 2446 | } |
@@ -2521,12 +2521,12 @@ discard block |
||
2521 | 2521 | if($this->has_primary_key_field()){ |
2522 | 2522 | if($this->get_primary_key_field()->is_auto_increment()){ |
2523 | 2523 | return $wpdb->insert_id; |
2524 | - }else{ |
|
2524 | + } else{ |
|
2525 | 2525 | //it's not an auto-increment primary key, so |
2526 | 2526 | //it must have been supplied |
2527 | 2527 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2528 | 2528 | } |
2529 | - }else{ |
|
2529 | + } else{ |
|
2530 | 2530 | //we can't return a primary key because there is none. instead return |
2531 | 2531 | //a unique string indicating this model |
2532 | 2532 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2578,7 +2578,7 @@ discard block |
||
2578 | 2578 | //leave the value alone |
2579 | 2579 | } |
2580 | 2580 | return $value; |
2581 | - }else{ |
|
2581 | + } else{ |
|
2582 | 2582 | return $value; |
2583 | 2583 | } |
2584 | 2584 | } |
@@ -2747,10 +2747,10 @@ discard block |
||
2747 | 2747 | if (! is_array($possibly_array_of_params)){ |
2748 | 2748 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2749 | 2749 | $param,$possibly_array_of_params)); |
2750 | - }else{ |
|
2750 | + } else{ |
|
2751 | 2751 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2752 | 2752 | } |
2753 | - }elseif($query_param_type === 0 //ie WHERE |
|
2753 | + } elseif($query_param_type === 0 //ie WHERE |
|
2754 | 2754 | && is_array($possibly_array_of_params) |
2755 | 2755 | && isset($possibly_array_of_params[2]) |
2756 | 2756 | && $possibly_array_of_params[2] == true){ |
@@ -3028,7 +3028,7 @@ discard block |
||
3028 | 3028 | private function _extract_order($should_be_order_string){ |
3029 | 3029 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
3030 | 3030 | return $should_be_order_string; |
3031 | - }else{ |
|
3031 | + } else{ |
|
3032 | 3032 | throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
3033 | 3033 | } |
3034 | 3034 | } |
@@ -3106,7 +3106,7 @@ discard block |
||
3106 | 3106 | foreach($default_where_conditions as $key => $val){ |
3107 | 3107 | if( isset($provided_where_conditions[$key])){ |
3108 | 3108 | $none_overridden = false; |
3109 | - }else{ |
|
3109 | + } else{ |
|
3110 | 3110 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3111 | 3111 | } |
3112 | 3112 | } |
@@ -3232,7 +3232,7 @@ discard block |
||
3232 | 3232 | if(array_key_exists($query_param,$this_model_fields)){ |
3233 | 3233 | if($allow_fields){ |
3234 | 3234 | return; |
3235 | - }else{ |
|
3235 | + } else{ |
|
3236 | 3236 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
3237 | 3237 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
3238 | 3238 | } |
@@ -3241,7 +3241,7 @@ discard block |
||
3241 | 3241 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
3242 | 3242 | if($allow_logic_query_params){ |
3243 | 3243 | return; |
3244 | - }else{ |
|
3244 | + } else{ |
|
3245 | 3245 | throw new EE_Error( |
3246 | 3246 | sprintf( |
3247 | 3247 | __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
@@ -3272,12 +3272,12 @@ discard block |
||
3272 | 3272 | //we should actually end in a field name, not a model like this! |
3273 | 3273 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3274 | 3274 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
3275 | - }else{ |
|
3275 | + } else{ |
|
3276 | 3276 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3277 | 3277 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3278 | 3278 | return; |
3279 | 3279 | } |
3280 | - }elseif($query_param === $valid_related_model_name){ |
|
3280 | + } elseif($query_param === $valid_related_model_name){ |
|
3281 | 3281 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
3282 | 3282 | return; |
3283 | 3283 | } |
@@ -3342,7 +3342,7 @@ discard block |
||
3342 | 3342 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3343 | 3343 | if($SQL){ |
3344 | 3344 | return " WHERE ". $SQL; |
3345 | - }else{ |
|
3345 | + } else{ |
|
3346 | 3346 | return ''; |
3347 | 3347 | } |
3348 | 3348 | } |
@@ -3361,7 +3361,7 @@ discard block |
||
3361 | 3361 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3362 | 3362 | if($SQL){ |
3363 | 3363 | return " HAVING ". $SQL; |
3364 | - }else{ |
|
3364 | + } else{ |
|
3365 | 3365 | return ''; |
3366 | 3366 | } |
3367 | 3367 | |
@@ -3383,7 +3383,7 @@ discard block |
||
3383 | 3383 | $model_instance=call_user_func($model_name."::instance"); |
3384 | 3384 | /* @var $model_instance EEM_Base */ |
3385 | 3385 | return $model_instance->field_settings_for($field_name); |
3386 | - }else{ |
|
3386 | + } else{ |
|
3387 | 3387 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
3388 | 3388 | } |
3389 | 3389 | } |
@@ -3416,14 +3416,14 @@ discard block |
||
3416 | 3416 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3417 | 3417 | break; |
3418 | 3418 | } |
3419 | - }else{ |
|
3419 | + } else{ |
|
3420 | 3420 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3421 | 3421 | |
3422 | 3422 | //if it's not a normal field, maybe it's a custom selection? |
3423 | 3423 | if( ! $field_obj){ |
3424 | 3424 | if(isset( $this->_custom_selections[$query_param][1])){ |
3425 | 3425 | $field_obj = $this->_custom_selections[$query_param][1]; |
3426 | - }else{ |
|
3426 | + } else{ |
|
3427 | 3427 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3428 | 3428 | } |
3429 | 3429 | } |
@@ -3448,11 +3448,11 @@ discard block |
||
3448 | 3448 | if( $field ){ |
3449 | 3449 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3450 | 3450 | return $table_alias_prefix . $field->get_qualified_column(); |
3451 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3451 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3452 | 3452 | //maybe it's custom selection item? |
3453 | 3453 | //if so, just use it as the "column name" |
3454 | 3454 | return $query_param; |
3455 | - }else{ |
|
3455 | + } else{ |
|
3456 | 3456 | throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
3457 | 3457 | } |
3458 | 3458 | } |
@@ -3469,7 +3469,7 @@ discard block |
||
3469 | 3469 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3470 | 3470 | if($pos_of_star === FALSE){ |
3471 | 3471 | return $condition_query_param_key; |
3472 | - }else{ |
|
3472 | + } else{ |
|
3473 | 3473 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3474 | 3474 | return $condition_query_param_sans_star; |
3475 | 3475 | } |
@@ -3654,7 +3654,7 @@ discard block |
||
3654 | 3654 | global $wpdb; |
3655 | 3655 | if($field_obj instanceof EE_Model_Field_Base){ |
3656 | 3656 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3657 | - }else{//$field_obj should really just be a data type |
|
3657 | + } else{//$field_obj should really just be a data type |
|
3658 | 3658 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3659 | 3659 | throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
3660 | 3660 | } |
@@ -3683,14 +3683,14 @@ discard block |
||
3683 | 3683 | if($number_of_parts === 1){ |
3684 | 3684 | $field_name = $last_query_param_part; |
3685 | 3685 | $model_obj = $this; |
3686 | - }else{// $number_of_parts >= 2 |
|
3686 | + } else{// $number_of_parts >= 2 |
|
3687 | 3687 | //the last part is the column name, and there are only 2parts. therefore... |
3688 | 3688 | $field_name = $last_query_param_part; |
3689 | 3689 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3690 | 3690 | } |
3691 | 3691 | try{ |
3692 | 3692 | return $model_obj->field_settings_for($field_name); |
3693 | - }catch(EE_Error $e){ |
|
3693 | + } catch(EE_Error $e){ |
|
3694 | 3694 | return null; |
3695 | 3695 | } |
3696 | 3696 | } |
@@ -3709,7 +3709,7 @@ discard block |
||
3709 | 3709 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3710 | 3710 | if($field){ |
3711 | 3711 | return $field->get_qualified_column(); |
3712 | - }else{ |
|
3712 | + } else{ |
|
3713 | 3713 | throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
3714 | 3714 | } |
3715 | 3715 | } |
@@ -3780,7 +3780,7 @@ discard block |
||
3780 | 3780 | //the FROM statement, BUT the primary table isn't. So we want |
3781 | 3781 | //to add the inverse join sql |
3782 | 3782 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3783 | - }else{ |
|
3783 | + } else{ |
|
3784 | 3784 | //just add a regular JOIN to this table from the primary table |
3785 | 3785 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3786 | 3786 | } |
@@ -3893,7 +3893,7 @@ discard block |
||
3893 | 3893 | $fieldSettings = $this->field_settings(true); |
3894 | 3894 | if( isset($fieldSettings[$fieldName])){ |
3895 | 3895 | return true; |
3896 | - }else{ |
|
3896 | + } else{ |
|
3897 | 3897 | return false; |
3898 | 3898 | } |
3899 | 3899 | } |
@@ -3907,7 +3907,7 @@ discard block |
||
3907 | 3907 | $relations = $this->relation_settings(); |
3908 | 3908 | if(isset($relations[$relation_name])){ |
3909 | 3909 | return true; |
3910 | - }else{ |
|
3910 | + } else{ |
|
3911 | 3911 | return false; |
3912 | 3912 | } |
3913 | 3913 | } |
@@ -3958,7 +3958,7 @@ discard block |
||
3958 | 3958 | try{ |
3959 | 3959 | $this->get_primary_key_field(); |
3960 | 3960 | $this->_has_primary_key_field = true; |
3961 | - }catch(EE_Error $e){ |
|
3961 | + } catch(EE_Error $e){ |
|
3962 | 3962 | $this->_has_primary_key_field = false; |
3963 | 3963 | } |
3964 | 3964 | } |
@@ -4038,7 +4038,7 @@ discard block |
||
4038 | 4038 | } |
4039 | 4039 | } |
4040 | 4040 | return $this->_cached_fields; |
4041 | - }else{ |
|
4041 | + } else{ |
|
4042 | 4042 | if( $this->_cached_fields_non_db_only === NULL ){ |
4043 | 4043 | $this->_cached_fields_non_db_only = array(); |
4044 | 4044 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -4174,7 +4174,7 @@ discard block |
||
4174 | 4174 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
4175 | 4175 | return NULL; |
4176 | 4176 | } |
4177 | - }else if($this->unique_indexes()){ |
|
4177 | + } else if($this->unique_indexes()){ |
|
4178 | 4178 | $first_column = reset($this_model_fields_n_values); |
4179 | 4179 | if(empty($first_column)){ |
4180 | 4180 | return NULL; |
@@ -4189,7 +4189,7 @@ discard block |
||
4189 | 4189 | // add this new object to the entity map |
4190 | 4190 | $classInstance = $this->add_to_entity_map( $classInstance ); |
4191 | 4191 | } |
4192 | - }else{ |
|
4192 | + } else{ |
|
4193 | 4193 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
4194 | 4194 | } |
4195 | 4195 | |
@@ -4302,7 +4302,7 @@ discard block |
||
4302 | 4302 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
4303 | 4303 | } |
4304 | 4304 | } |
4305 | - }else{ |
|
4305 | + } else{ |
|
4306 | 4306 | //the table's rows existed. Use their values |
4307 | 4307 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
4308 | 4308 | if( ! $field_obj->is_db_only_field() ){ |
@@ -4332,7 +4332,7 @@ discard block |
||
4332 | 4332 | //or is it a db-only field? (not relating to the model) |
4333 | 4333 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
4334 | 4334 | $value = $cols_n_values[ $qualified_column ]; |
4335 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4335 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4336 | 4336 | $value = $cols_n_values[ $regular_column ]; |
4337 | 4337 | } |
4338 | 4338 | return $value; |
@@ -4366,7 +4366,7 @@ discard block |
||
4366 | 4366 | } |
4367 | 4367 | } |
4368 | 4368 | return $obj_in_map; |
4369 | - }else{ |
|
4369 | + } else{ |
|
4370 | 4370 | return $this->get_one_by_ID( $id ); |
4371 | 4371 | } |
4372 | 4372 | } |
@@ -4401,7 +4401,7 @@ discard block |
||
4401 | 4401 | } |
4402 | 4402 | } |
4403 | 4403 | return $obj_in_map; |
4404 | - }else{ |
|
4404 | + } else{ |
|
4405 | 4405 | $this->add_to_entity_map( $replacing_model_obj ); |
4406 | 4406 | return $replacing_model_obj; |
4407 | 4407 | } |
@@ -4546,13 +4546,13 @@ discard block |
||
4546 | 4546 | if( $base_class_obj_or_id instanceof $className ){ |
4547 | 4547 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4548 | 4548 | $id = $base_class_obj_or_id->ID(); |
4549 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4549 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4550 | 4550 | //assume it's an ID |
4551 | 4551 | $id = $base_class_obj_or_id; |
4552 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4552 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4553 | 4553 | //assume its a string representation of the object |
4554 | 4554 | $id = $base_class_obj_or_id; |
4555 | - }else{ |
|
4555 | + } else{ |
|
4556 | 4556 | throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
4557 | 4557 | } |
4558 | 4558 | return $id; |
@@ -4700,9 +4700,9 @@ discard block |
||
4700 | 4700 | |
4701 | 4701 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4702 | 4702 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4703 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4703 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4704 | 4704 | $attributes_array = $model_object_or_attributes_array; |
4705 | - }else{ |
|
4705 | + } else{ |
|
4706 | 4706 | throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
4707 | 4707 | } |
4708 | 4708 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4712,7 +4712,7 @@ discard block |
||
4712 | 4712 | } |
4713 | 4713 | if(isset($query_params[0])){ |
4714 | 4714 | $query_params[0] = array_merge($attributes_array,$query_params); |
4715 | - }else{ |
|
4715 | + } else{ |
|
4716 | 4716 | $query_params[0] = $attributes_array; |
4717 | 4717 | } |
4718 | 4718 | return $this->get_all($query_params); |
@@ -4737,7 +4737,7 @@ discard block |
||
4737 | 4737 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4738 | 4738 | if(is_array($copies)){ |
4739 | 4739 | return array_shift($copies); |
4740 | - }else{ |
|
4740 | + } else{ |
|
4741 | 4741 | return null; |
4742 | 4742 | } |
4743 | 4743 | } |
@@ -4771,7 +4771,7 @@ discard block |
||
4771 | 4771 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4772 | 4772 | if($sql_operator){ |
4773 | 4773 | return $sql_operator; |
4774 | - }else{ |
|
4774 | + } else{ |
|
4775 | 4775 | throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
4776 | 4776 | } |
4777 | 4777 | } |
@@ -4976,7 +4976,7 @@ discard block |
||
4976 | 4976 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4977 | 4977 | if( in_array( $context, $valid_cap_contexts ) ) { |
4978 | 4978 | return true; |
4979 | - }else{ |
|
4979 | + } else{ |
|
4980 | 4980 | throw new EE_Error( |
4981 | 4981 | sprintf( |
4982 | 4982 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * Flag indicating whether this model has a primary key or not |
244 | 244 | * @var boolean |
245 | 245 | */ |
246 | - protected $_has_primary_key_field=null; |
|
246 | + protected $_has_primary_key_field = null; |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
306 | 306 | * @var array |
307 | 307 | */ |
308 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
308 | + protected $_between_style_operators = array('BETWEEN'); |
|
309 | 309 | |
310 | 310 | /** |
311 | 311 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
312 | 312 | * @var array |
313 | 313 | */ |
314 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
314 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Allowed values for $query_params['order'] for ordering in queries |
318 | 318 | * @var array |
319 | 319 | */ |
320 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
320 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
321 | 321 | |
322 | 322 | /** |
323 | 323 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
332 | 332 | * @var array |
333 | 333 | */ |
334 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
334 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
335 | 335 | |
336 | 336 | /** |
337 | 337 | * All the data types that can be used in $wpdb->prepare statements. |
338 | 338 | * @var array |
339 | 339 | */ |
340 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
340 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
341 | 341 | |
342 | 342 | /** |
343 | 343 | * EE_Registry Object |
@@ -370,17 +370,17 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * constant used to show EEM_Base has not yet verified the db on this http request |
372 | 372 | */ |
373 | - const db_verified_none = 0; |
|
373 | + const db_verified_none = 0; |
|
374 | 374 | /** |
375 | 375 | * constant used to show EEM_Base has verified the EE core db on this http request, |
376 | 376 | * but not the addons' dbs |
377 | 377 | */ |
378 | - const db_verified_core = 1; |
|
378 | + const db_verified_core = 1; |
|
379 | 379 | /** |
380 | 380 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
381 | 381 | * the EE core db too) |
382 | 382 | */ |
383 | - const db_verified_addons = 2; |
|
383 | + const db_verified_addons = 2; |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | * @param null $timezone |
412 | 412 | * @throws \EE_Error |
413 | 413 | */ |
414 | - protected function __construct( $timezone = NULL ){ |
|
414 | + protected function __construct($timezone = NULL) { |
|
415 | 415 | // check that the model has not been loaded too soon |
416 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
417 | - throw new EE_Error ( |
|
416 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
417 | + throw new EE_Error( |
|
418 | 418 | sprintf( |
419 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
420 | - get_class( $this ) |
|
419 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
420 | + get_class($this) |
|
421 | 421 | ) |
422 | 422 | ); |
423 | 423 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Set blogid for models to current blog. However we ONLY do this if $_model_query_blog_id is not already set. |
427 | 427 | */ |
428 | - if ( empty( EEM_Base::$_model_query_blog_id ) ) { |
|
428 | + if (empty(EEM_Base::$_model_query_blog_id)) { |
|
429 | 429 | EEM_Base::set_model_query_blog_id(); |
430 | 430 | } |
431 | 431 | |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | * just use EE_Register_Model_Extension |
435 | 435 | * @var EE_Table_Base[] $_tables |
436 | 436 | */ |
437 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
438 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
437 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
438 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
439 | 439 | /** @var $table_obj EE_Table_Base */ |
440 | 440 | $table_obj->_construct_finalize_with_alias($table_alias); |
441 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
441 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
442 | 442 | /** @var $table_obj EE_Secondary_Table */ |
443 | 443 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
444 | 444 | } |
@@ -448,54 +448,54 @@ discard block |
||
448 | 448 | * EE_Register_Model_Extension |
449 | 449 | * @param EE_Model_Field_Base[] $_fields |
450 | 450 | */ |
451 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
451 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
452 | 452 | $this->_invalidate_field_caches(); |
453 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
454 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
455 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
453 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
454 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
455 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
456 | 456 | } |
457 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
457 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
458 | 458 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
459 | 459 | //primary key field base has a slightly different _construct_finalize |
460 | 460 | /** @var $field_obj EE_Model_Field_Base */ |
461 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
461 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | |
465 | 465 | // everything is related to Extra_Meta |
466 | - if( get_class($this) !== 'EEM_Extra_Meta'){ |
|
466 | + if (get_class($this) !== 'EEM_Extra_Meta') { |
|
467 | 467 | //make extra meta related to everything, but don't block deleting things just |
468 | 468 | //because they have related extra meta info. For now just orphan those extra meta |
469 | 469 | //in the future we should automatically delete them |
470 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
470 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
471 | 471 | } |
472 | 472 | //and change logs |
473 | - if( get_class( $this) !== 'EEM_Change_Log' ) { |
|
474 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
473 | + if (get_class($this) !== 'EEM_Change_Log') { |
|
474 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
475 | 475 | } |
476 | 476 | /** |
477 | 477 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
478 | 478 | * EE_Register_Model_Extension |
479 | 479 | * @param EE_Model_Relation_Base[] $_model_relations |
480 | 480 | */ |
481 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
482 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
481 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
482 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
483 | 483 | /** @var $relation_obj EE_Model_Relation_Base */ |
484 | 484 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
485 | 485 | } |
486 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
486 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
487 | 487 | /** @var $index_obj EE_Index */ |
488 | 488 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
489 | 489 | } |
490 | 490 | |
491 | 491 | $this->set_timezone($timezone); |
492 | 492 | //finalize default where condition strategy, or set default |
493 | - if( ! $this->_default_where_conditions_strategy){ |
|
493 | + if ( ! $this->_default_where_conditions_strategy) { |
|
494 | 494 | //nothing was set during child constructor, so set default |
495 | 495 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
496 | 496 | } |
497 | 497 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
498 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
498 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
499 | 499 | //nothing was set during child constructor, so set default |
500 | 500 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
501 | 501 | } |
@@ -503,14 +503,14 @@ discard block |
||
503 | 503 | |
504 | 504 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
505 | 505 | //to indicate to NOT set it, set it to the logical default |
506 | - if( $this->_caps_slug === null ) { |
|
507 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
506 | + if ($this->_caps_slug === null) { |
|
507 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
508 | 508 | } |
509 | 509 | //initialize the standard cap restriction generators if none were specified by the child constructor |
510 | - if( $this->_cap_restriction_generators !== false ){ |
|
511 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
512 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
513 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
510 | + if ($this->_cap_restriction_generators !== false) { |
|
511 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
512 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
513 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
514 | 514 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
515 | 515 | new EE_Restriction_Generator_Protected(), |
516 | 516 | $cap_context, |
@@ -520,23 +520,23 @@ discard block |
||
520 | 520 | } |
521 | 521 | } |
522 | 522 | //if there are cap restriction generators, use them to make the default cap restrictions |
523 | - if( $this->_cap_restriction_generators !== false ){ |
|
524 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
525 | - if( ! $generator_object ){ |
|
523 | + if ($this->_cap_restriction_generators !== false) { |
|
524 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
525 | + if ( ! $generator_object) { |
|
526 | 526 | continue; |
527 | 527 | } |
528 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
528 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
529 | 529 | throw new EE_Error( |
530 | 530 | sprintf( |
531 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
531 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
532 | 532 | $context, |
533 | 533 | $this->get_this_model_name() |
534 | 534 | ) |
535 | 535 | ); |
536 | 536 | } |
537 | - $action = $this->cap_action_for_context( $context ); |
|
538 | - if( ! $generator_object->construction_finalized() ){ |
|
539 | - $generator_object->_construct_finalize( $this, $action ); |
|
537 | + $action = $this->cap_action_for_context($context); |
|
538 | + if ( ! $generator_object->construction_finalized()) { |
|
539 | + $generator_object->_construct_finalize($this, $action); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | } |
@@ -550,11 +550,11 @@ discard block |
||
550 | 550 | * @param string $context one of EEM_Base::valid_cap_contexts() |
551 | 551 | * @return EE_Default_Where_Conditions[] |
552 | 552 | */ |
553 | - protected function _generate_cap_restrictions( $context ){ |
|
554 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
555 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
556 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
557 | - }else{ |
|
553 | + protected function _generate_cap_restrictions($context) { |
|
554 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
555 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
556 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
557 | + } else { |
|
558 | 558 | return array(); |
559 | 559 | } |
560 | 560 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @param int $blog_id If provided then will set the blog_id for the models to this id. If not provided then the |
567 | 567 | * value for get_current_blog_id() will be used. |
568 | 568 | */ |
569 | - public static function set_model_query_blog_id( $blog_id = 0 ) { |
|
569 | + public static function set_model_query_blog_id($blog_id = 0) { |
|
570 | 570 | EEM_Base::$_model_query_blog_id = $blog_id > 0 ? (int) $blog_id : get_current_blog_id(); |
571 | 571 | } |
572 | 572 | |
@@ -591,16 +591,16 @@ discard block |
||
591 | 591 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
592 | 592 | * @return static (as in the concrete child class) |
593 | 593 | */ |
594 | - public static function instance( $timezone = NULL ){ |
|
594 | + public static function instance($timezone = NULL) { |
|
595 | 595 | |
596 | 596 | // check if instance of Espresso_model already exists |
597 | 597 | if ( ! static::$_instance instanceof static) { |
598 | 598 | // instantiate Espresso_model |
599 | - static::$_instance = new static( $timezone ); |
|
599 | + static::$_instance = new static($timezone); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | //we might have a timezone set, let set_timezone decide what to do with it |
603 | - static::$_instance->set_timezone( $timezone ); |
|
603 | + static::$_instance->set_timezone($timezone); |
|
604 | 604 | |
605 | 605 | // Espresso_model object |
606 | 606 | return static::$_instance; |
@@ -614,24 +614,24 @@ discard block |
||
614 | 614 | * @return EEM_Base|null (if the model was already instantiated, returns it, with |
615 | 615 | * all its properties reset; if it wasn't instantiated, returns null) |
616 | 616 | */ |
617 | - public static function reset( $timezone = NULL ){ |
|
618 | - if ( static::$_instance instanceof EEM_Base ) { |
|
617 | + public static function reset($timezone = NULL) { |
|
618 | + if (static::$_instance instanceof EEM_Base) { |
|
619 | 619 | //let's try to NOT swap out the current instance for a new one |
620 | 620 | //because if someone has a reference to it, we can't remove their reference |
621 | 621 | //so it's best to keep using the same reference, but change the original object |
622 | 622 | //reset all its properties to their original values as defined in the class |
623 | - $r = new ReflectionClass( get_class( static::$_instance ) ); |
|
623 | + $r = new ReflectionClass(get_class(static::$_instance)); |
|
624 | 624 | $static_properties = $r->getStaticProperties(); |
625 | - foreach( $r->getDefaultProperties() as $property => $value ) { |
|
625 | + foreach ($r->getDefaultProperties() as $property => $value) { |
|
626 | 626 | //don't set instance to null like it was originally, |
627 | 627 | //but it's static anyways, and we're ignoring static properties (for now at least) |
628 | - if( ! isset( $static_properties[ $property ] ) ) { |
|
628 | + if ( ! isset($static_properties[$property])) { |
|
629 | 629 | static::$_instance->{$property} = $value; |
630 | 630 | } |
631 | 631 | } |
632 | 632 | //and then directly call its constructor again, like we would if we |
633 | 633 | //were creating a new one |
634 | - static::$_instance->__construct( $timezone ); |
|
634 | + static::$_instance->__construct($timezone); |
|
635 | 635 | return self::instance(); |
636 | 636 | } |
637 | 637 | return null; |
@@ -646,19 +646,19 @@ discard block |
||
646 | 646 | * @return array |
647 | 647 | * @throws \EE_Error |
648 | 648 | */ |
649 | - public function status_array( $translated = FALSE ) { |
|
650 | - if ( ! array_key_exists( 'Status', $this->_model_relations ) ) { |
|
649 | + public function status_array($translated = FALSE) { |
|
650 | + if ( ! array_key_exists('Status', $this->_model_relations)) { |
|
651 | 651 | return array(); |
652 | 652 | } |
653 | 653 | $model_name = $this->get_this_model_name(); |
654 | - $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) ); |
|
655 | - $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) ); |
|
654 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
655 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
656 | 656 | $status_array = array(); |
657 | - foreach ( $stati as $status ) { |
|
658 | - $status_array[ $status->ID() ] = $status->get( 'STS_code' ); |
|
657 | + foreach ($stati as $status) { |
|
658 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
659 | 659 | } |
660 | 660 | return $translated |
661 | - ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' ) |
|
661 | + ? EEM_Status::instance()->localized_status($status_array, false, 'sentence') |
|
662 | 662 | : $status_array; |
663 | 663 | } |
664 | 664 | |
@@ -791,10 +791,10 @@ discard block |
||
791 | 791 | * )); |
792 | 792 | * @throws \EE_Error |
793 | 793 | */ |
794 | - public function get_all($query_params = array()){ |
|
795 | - if( isset( $query_params[ 'limit' ] ) |
|
796 | - && ! isset( $query_params[ 'group_by' ] ) ) { |
|
797 | - $query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() ); |
|
794 | + public function get_all($query_params = array()) { |
|
795 | + if (isset($query_params['limit']) |
|
796 | + && ! isset($query_params['group_by'])) { |
|
797 | + $query_params['group_by'] = array_keys($this->get_combined_primary_key_fields()); |
|
798 | 798 | } |
799 | 799 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
800 | 800 | } |
@@ -805,10 +805,10 @@ discard block |
||
805 | 805 | * @param array $query_params @see EEM_Base::get_all() |
806 | 806 | * @return array like EEM_Base::get_all |
807 | 807 | */ |
808 | - public function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
808 | + public function alter_query_params_to_only_include_mine($query_params = array()) { |
|
809 | 809 | $wp_user_field_name = $this->wp_user_field_name(); |
810 | - if( $wp_user_field_name ){ |
|
811 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
810 | + if ($wp_user_field_name) { |
|
811 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
812 | 812 | } |
813 | 813 | return $query_params; |
814 | 814 | } |
@@ -821,19 +821,19 @@ discard block |
||
821 | 821 | * foreign key to the WP_User table |
822 | 822 | */ |
823 | 823 | public function wp_user_field_name() { |
824 | - try{ |
|
825 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
826 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
827 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
828 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
829 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
830 | - }else{ |
|
824 | + try { |
|
825 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
826 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
827 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
828 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
829 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
830 | + } else { |
|
831 | 831 | $model_with_fk_to_wp_users = $this; |
832 | 832 | $model_chain_to_wp_user = ''; |
833 | 833 | } |
834 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
835 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
836 | - }catch( EE_Error $e ) { |
|
834 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
835 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
836 | + } catch (EE_Error $e) { |
|
837 | 837 | return false; |
838 | 838 | } |
839 | 839 | } |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * (or transiently-related model) |
848 | 848 | * @return string |
849 | 849 | */ |
850 | - public function model_chain_to_wp_user(){ |
|
850 | + public function model_chain_to_wp_user() { |
|
851 | 851 | return $this->_model_chain_to_wp_user; |
852 | 852 | } |
853 | 853 | |
@@ -859,13 +859,13 @@ discard block |
||
859 | 859 | * @return boolean |
860 | 860 | */ |
861 | 861 | public function is_owned() { |
862 | - if( $this->model_chain_to_wp_user() ){ |
|
862 | + if ($this->model_chain_to_wp_user()) { |
|
863 | 863 | return true; |
864 | - }else{ |
|
865 | - try{ |
|
866 | - $this->get_foreign_key_to( 'WP_User' ); |
|
864 | + } else { |
|
865 | + try { |
|
866 | + $this->get_foreign_key_to('WP_User'); |
|
867 | 867 | return true; |
868 | - }catch( EE_Error $e ){ |
|
868 | + } catch (EE_Error $e) { |
|
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | } |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
888 | 888 | * @throws \EE_Error |
889 | 889 | */ |
890 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
890 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
891 | 891 | // remember the custom selections, if any, and type cast as array |
892 | 892 | // (unless $columns_to_select is an object, then just set as an empty array) |
893 | 893 | // Note: (array) 'some string' === array( 'some string' ) |
894 | - $this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array(); |
|
895 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
894 | + $this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array(); |
|
895 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
896 | 896 | $select_expressions = $columns_to_select !== null |
897 | - ? $this->_construct_select_from_input( $columns_to_select ) |
|
898 | - : $this->_construct_default_select_sql( $model_query_info ); |
|
899 | - $SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info ); |
|
900 | - return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) ); |
|
897 | + ? $this->_construct_select_from_input($columns_to_select) |
|
898 | + : $this->_construct_default_select_sql($model_query_info); |
|
899 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
900 | + return $this->_do_wpdb_query('get_results', array($SQL, $output)); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | /** |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
916 | 916 | * @throws \EE_Error |
917 | 917 | */ |
918 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
918 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
919 | 919 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
920 | 920 | } |
921 | 921 | |
@@ -927,12 +927,12 @@ discard block |
||
927 | 927 | * @throws EE_Error |
928 | 928 | * @return string |
929 | 929 | */ |
930 | - private function _construct_select_from_input($columns_to_select){ |
|
931 | - if(is_array($columns_to_select)){ |
|
930 | + private function _construct_select_from_input($columns_to_select) { |
|
931 | + if (is_array($columns_to_select)) { |
|
932 | 932 | $select_sql_array = array(); |
933 | 933 | |
934 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
935 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
934 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
935 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
936 | 936 | throw new EE_Error( |
937 | 937 | sprintf( |
938 | 938 | __( |
@@ -944,24 +944,24 @@ discard block |
||
944 | 944 | ) |
945 | 945 | ); |
946 | 946 | } |
947 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
947 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
948 | 948 | throw new EE_Error( |
949 | 949 | sprintf( |
950 | 950 | __( |
951 | 951 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
952 | 952 | "event_espresso" |
953 | 953 | ), |
954 | - $selection_and_datatype[ 1 ], |
|
955 | - $selection_and_datatype[ 0 ], |
|
954 | + $selection_and_datatype[1], |
|
955 | + $selection_and_datatype[0], |
|
956 | 956 | $alias, |
957 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
957 | + implode(",", $this->_valid_wpdb_data_types) |
|
958 | 958 | ) |
959 | 959 | ); |
960 | 960 | } |
961 | 961 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
962 | 962 | } |
963 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
964 | - }else{ |
|
963 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
964 | + } else { |
|
965 | 965 | $columns_to_select_string = $columns_to_select; |
966 | 966 | } |
967 | 967 | return $columns_to_select_string; |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | * @return string |
977 | 977 | * @throws \EE_Error |
978 | 978 | */ |
979 | - public function primary_key_name(){ |
|
979 | + public function primary_key_name() { |
|
980 | 980 | return $this->get_primary_key_field()->get_name(); |
981 | 981 | } |
982 | 982 | |
@@ -988,14 +988,14 @@ discard block |
||
988 | 988 | * @param mixed $id int or string, depending on the type of the model's primary key |
989 | 989 | * @return EE_Base_Class |
990 | 990 | */ |
991 | - public function get_one_by_ID($id){ |
|
992 | - if( $this->get_from_entity_map( $id ) ){ |
|
993 | - return $this->get_from_entity_map( $id ); |
|
991 | + public function get_one_by_ID($id) { |
|
992 | + if ($this->get_from_entity_map($id)) { |
|
993 | + return $this->get_from_entity_map($id); |
|
994 | 994 | } |
995 | 995 | return $this->get_one( |
996 | 996 | $this->alter_query_params_to_restrict_by_ID( |
997 | 997 | $id, |
998 | - array( 'default_where_conditions' => 'minimum' ) |
|
998 | + array('default_where_conditions' => 'minimum') |
|
999 | 999 | ) |
1000 | 1000 | ); |
1001 | 1001 | } |
@@ -1012,16 +1012,16 @@ discard block |
||
1012 | 1012 | * @return array of normal query params, @see EEM_Base::get_all |
1013 | 1013 | * @throws \EE_Error |
1014 | 1014 | */ |
1015 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
1016 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
1017 | - $query_params[ 0 ] = array(); |
|
1015 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
1016 | + if ( ! isset($query_params[0])) { |
|
1017 | + $query_params[0] = array(); |
|
1018 | 1018 | } |
1019 | - $conditions_from_id = $this->parse_index_primary_key_string( $id ); |
|
1020 | - if( $conditions_from_id === null ) { |
|
1021 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
1022 | - }else{ |
|
1019 | + $conditions_from_id = $this->parse_index_primary_key_string($id); |
|
1020 | + if ($conditions_from_id === null) { |
|
1021 | + $query_params[0][$this->primary_key_name()] = $id; |
|
1022 | + } else { |
|
1023 | 1023 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1024 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
1024 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
1025 | 1025 | } |
1026 | 1026 | return $query_params; |
1027 | 1027 | } |
@@ -1037,16 +1037,16 @@ discard block |
||
1037 | 1037 | * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL |
1038 | 1038 | * @throws \EE_Error |
1039 | 1039 | */ |
1040 | - public function get_one($query_params = array()){ |
|
1041 | - if( ! is_array( $query_params ) ){ |
|
1042 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1040 | + public function get_one($query_params = array()) { |
|
1041 | + if ( ! is_array($query_params)) { |
|
1042 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1043 | 1043 | $query_params = array(); |
1044 | 1044 | } |
1045 | 1045 | $query_params['limit'] = 1; |
1046 | 1046 | $items = $this->get_all($query_params); |
1047 | - if(empty($items)){ |
|
1047 | + if (empty($items)) { |
|
1048 | 1048 | return null; |
1049 | - }else{ |
|
1049 | + } else { |
|
1050 | 1050 | return array_shift($items); |
1051 | 1051 | } |
1052 | 1052 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | * @return EE_Base_Class[]|array |
1070 | 1070 | * @throws \EE_Error |
1071 | 1071 | */ |
1072 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1073 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1072 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1073 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | |
@@ -1091,8 +1091,8 @@ discard block |
||
1091 | 1091 | * @return EE_Base_Class[]|array |
1092 | 1092 | * @throws \EE_Error |
1093 | 1093 | */ |
1094 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1095 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1094 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1095 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | |
@@ -1113,9 +1113,9 @@ discard block |
||
1113 | 1113 | * @return EE_Base_Class|null|array() |
1114 | 1114 | * @throws \EE_Error |
1115 | 1115 | */ |
1116 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1117 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1118 | - return empty( $results ) ? null : reset( $results ); |
|
1116 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1117 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1118 | + return empty($results) ? null : reset($results); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | |
@@ -1137,9 +1137,9 @@ discard block |
||
1137 | 1137 | * @return EE_Base_Class|null|array() |
1138 | 1138 | * @throws EE_Error |
1139 | 1139 | */ |
1140 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1141 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1142 | - return empty( $results ) ? null : reset( $results ); |
|
1140 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1141 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1142 | + return empty($results) ? null : reset($results); |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | |
@@ -1160,42 +1160,42 @@ discard block |
||
1160 | 1160 | * @return EE_Base_Class[]|array |
1161 | 1161 | * @throws EE_Error |
1162 | 1162 | */ |
1163 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1163 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1164 | 1164 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1165 | - if ( empty( $field_to_order_by ) ) { |
|
1166 | - if ( $this->has_primary_key_field() ) { |
|
1165 | + if (empty($field_to_order_by)) { |
|
1166 | + if ($this->has_primary_key_field()) { |
|
1167 | 1167 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1168 | 1168 | } else { |
1169 | 1169 | |
1170 | - if ( WP_DEBUG ) { |
|
1171 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1170 | + if (WP_DEBUG) { |
|
1171 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1172 | 1172 | } |
1173 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1173 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1174 | 1174 | return array(); |
1175 | 1175 | } |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - if( ! is_array( $query_params ) ){ |
|
1179 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1178 | + if ( ! is_array($query_params)) { |
|
1179 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1180 | 1180 | $query_params = array(); |
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | //let's add the where query param for consecutive look up. |
1184 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1184 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1185 | 1185 | $query_params['limit'] = $limit; |
1186 | 1186 | |
1187 | 1187 | //set direction |
1188 | - $incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array(); |
|
1188 | + $incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array(); |
|
1189 | 1189 | $query_params['order_by'] = $operand === '>' |
1190 | - ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby |
|
1191 | - : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1190 | + ? array($field_to_order_by => 'ASC') + $incoming_orderby |
|
1191 | + : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1192 | 1192 | |
1193 | 1193 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1194 | - if ( empty( $columns_to_select ) ) { |
|
1195 | - return $this->get_all( $query_params ); |
|
1194 | + if (empty($columns_to_select)) { |
|
1195 | + return $this->get_all($query_params); |
|
1196 | 1196 | } else { |
1197 | 1197 | //getting just the fields |
1198 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1198 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | |
@@ -1206,18 +1206,18 @@ discard block |
||
1206 | 1206 | * This sets the _timezone property after model object has been instantiated. |
1207 | 1207 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1208 | 1208 | */ |
1209 | - public function set_timezone( $timezone ) { |
|
1210 | - if ( $timezone !== null ) { |
|
1209 | + public function set_timezone($timezone) { |
|
1210 | + if ($timezone !== null) { |
|
1211 | 1211 | $this->_timezone = $timezone; |
1212 | 1212 | } |
1213 | 1213 | //note we need to loop through relations and set the timezone on those objects as well. |
1214 | - foreach ( $this->_model_relations as $relation ) { |
|
1215 | - $relation->set_timezone( $timezone ); |
|
1214 | + foreach ($this->_model_relations as $relation) { |
|
1215 | + $relation->set_timezone($timezone); |
|
1216 | 1216 | } |
1217 | 1217 | //and finally we do the same for any datetime fields |
1218 | - foreach ( $this->_fields as $field ) { |
|
1219 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1220 | - $field->set_timezone( $timezone ); |
|
1218 | + foreach ($this->_fields as $field) { |
|
1219 | + if ($field instanceof EE_Datetime_Field) { |
|
1220 | + $field->set_timezone($timezone); |
|
1221 | 1221 | } |
1222 | 1222 | } |
1223 | 1223 | } |
@@ -1232,9 +1232,9 @@ discard block |
||
1232 | 1232 | */ |
1233 | 1233 | public function get_timezone() { |
1234 | 1234 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1235 | - if ( empty( $this->_timezone ) ) { |
|
1236 | - foreach( $this->_fields as $field ) { |
|
1237 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1235 | + if (empty($this->_timezone)) { |
|
1236 | + foreach ($this->_fields as $field) { |
|
1237 | + if ($field instanceof EE_Datetime_Field) { |
|
1238 | 1238 | $this->set_timezone($field->get_timezone()); |
1239 | 1239 | break; |
1240 | 1240 | } |
@@ -1242,8 +1242,8 @@ discard block |
||
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | //if timezone STILL empty then return the default timezone for the site. |
1245 | - if ( empty( $this->_timezone ) ) { |
|
1246 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1245 | + if (empty($this->_timezone)) { |
|
1246 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1247 | 1247 | } |
1248 | 1248 | return $this->_timezone; |
1249 | 1249 | } |
@@ -1261,19 +1261,19 @@ discard block |
||
1261 | 1261 | * |
1262 | 1262 | * @return array formats in an array with the date format first, and the time format last. |
1263 | 1263 | */ |
1264 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1265 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1264 | + public function get_formats_for($field_name, $pretty = false) { |
|
1265 | + $field_settings = $this->field_settings_for($field_name); |
|
1266 | 1266 | |
1267 | 1267 | //if not a valid EE_Datetime_Field then throw error |
1268 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1269 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1268 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1269 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1270 | 1270 | } |
1271 | 1271 | |
1272 | 1272 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1273 | 1273 | //the field. |
1274 | 1274 | $this->_timezone = $field_settings->get_timezone(); |
1275 | 1275 | |
1276 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1276 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | |
@@ -1297,25 +1297,25 @@ discard block |
||
1297 | 1297 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1298 | 1298 | * exception is triggered. |
1299 | 1299 | */ |
1300 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1301 | - $formats = $this->get_formats_for( $field_name ); |
|
1300 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1301 | + $formats = $this->get_formats_for($field_name); |
|
1302 | 1302 | |
1303 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1303 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1304 | 1304 | |
1305 | - if ( $timestamp ) { |
|
1306 | - return $DateTime->format( 'U' ); |
|
1305 | + if ($timestamp) { |
|
1306 | + return $DateTime->format('U'); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | //not returning timestamp, so return formatted string in timezone. |
1310 | - switch( $what ) { |
|
1310 | + switch ($what) { |
|
1311 | 1311 | case 'time' : |
1312 | - return $DateTime->format( $formats[1] ); |
|
1312 | + return $DateTime->format($formats[1]); |
|
1313 | 1313 | break; |
1314 | 1314 | case 'date' : |
1315 | - return $DateTime->format( $formats[0] ); |
|
1315 | + return $DateTime->format($formats[0]); |
|
1316 | 1316 | break; |
1317 | 1317 | default : |
1318 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1318 | + return $DateTime->format(implode(' ', $formats)); |
|
1319 | 1319 | break; |
1320 | 1320 | } |
1321 | 1321 | } |
@@ -1337,17 +1337,17 @@ discard block |
||
1337 | 1337 | * @return DateTime |
1338 | 1338 | * @throws \EE_Error |
1339 | 1339 | */ |
1340 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1340 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1341 | 1341 | |
1342 | 1342 | //just using this to ensure the timezone is set correctly internally |
1343 | - $this->get_formats_for( $field_name ); |
|
1343 | + $this->get_formats_for($field_name); |
|
1344 | 1344 | |
1345 | 1345 | //load EEH_DTT_Helper |
1346 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1346 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1347 | 1347 | |
1348 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1348 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1349 | 1349 | |
1350 | - return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
1350 | + return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone)); |
|
1351 | 1351 | } |
1352 | 1352 | |
1353 | 1353 | |
@@ -1357,7 +1357,7 @@ discard block |
||
1357 | 1357 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1358 | 1358 | * @return EE_Table_Base[] |
1359 | 1359 | */ |
1360 | - public function get_tables(){ |
|
1360 | + public function get_tables() { |
|
1361 | 1361 | return $this->_tables; |
1362 | 1362 | } |
1363 | 1363 | |
@@ -1393,9 +1393,9 @@ discard block |
||
1393 | 1393 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1394 | 1394 | * @throws \EE_Error |
1395 | 1395 | */ |
1396 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1397 | - if( ! is_array( $query_params ) ){ |
|
1398 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1396 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1397 | + if ( ! is_array($query_params)) { |
|
1398 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1399 | 1399 | $query_params = array(); |
1400 | 1400 | } |
1401 | 1401 | /** |
@@ -1405,7 +1405,7 @@ discard block |
||
1405 | 1405 | * @param array $fields_n_values the updated fields and their new values |
1406 | 1406 | * @param array $query_params @see EEM_Base::get_all() |
1407 | 1407 | */ |
1408 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1408 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1409 | 1409 | /** |
1410 | 1410 | * Filters the fields about to be updated given the query parameters. You can provide the |
1411 | 1411 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1413,10 +1413,10 @@ discard block |
||
1413 | 1413 | * @param EEM_Base $model the model being queried |
1414 | 1414 | * @param array $query_params see EEM_Base::get_all() |
1415 | 1415 | */ |
1416 | - $fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1416 | + $fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1417 | 1417 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1418 | 1418 | //to do that, for each table, verify that it's PK isn't null. |
1419 | - $tables= $this->get_tables(); |
|
1419 | + $tables = $this->get_tables(); |
|
1420 | 1420 | |
1421 | 1421 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1422 | 1422 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1426,29 +1426,29 @@ discard block |
||
1426 | 1426 | //we want to make sure the default_where strategy is ignored |
1427 | 1427 | $this->_ignore_where_strategy = TRUE; |
1428 | 1428 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1429 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1429 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1430 | 1430 | // type cast stdClass as array |
1431 | - $wpdb_result = (array)$wpdb_result; |
|
1431 | + $wpdb_result = (array) $wpdb_result; |
|
1432 | 1432 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1433 | - if( $this->has_primary_key_field() ){ |
|
1434 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1435 | - }else{ |
|
1433 | + if ($this->has_primary_key_field()) { |
|
1434 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1435 | + } else { |
|
1436 | 1436 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1437 | 1437 | $main_table_pk_value = null; |
1438 | 1438 | } |
1439 | 1439 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1440 | 1440 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1441 | - if(count($tables) > 1){ |
|
1441 | + if (count($tables) > 1) { |
|
1442 | 1442 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1443 | 1443 | //in that table, and so we'll want to insert one |
1444 | - foreach($tables as $table_obj){ |
|
1444 | + foreach ($tables as $table_obj) { |
|
1445 | 1445 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1446 | 1446 | //if there is no private key for this table on the results, it means there's no entry |
1447 | 1447 | //in this table, right? so insert a row in the current table, using any fields available |
1448 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1448 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1449 | 1449 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1450 | 1450 | //if we died here, report the error |
1451 | - if( ! $success ) { |
|
1451 | + if ( ! $success) { |
|
1452 | 1452 | return false; |
1453 | 1453 | } |
1454 | 1454 | } |
@@ -1468,44 +1468,44 @@ discard block |
||
1468 | 1468 | //if this wasn't called from a model object (to update itself) |
1469 | 1469 | //then we want to make sure we keep all the existing |
1470 | 1470 | //model objects in sync with the db |
1471 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1472 | - if( $this->has_primary_key_field() ){ |
|
1473 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1474 | - }else{ |
|
1471 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1472 | + if ($this->has_primary_key_field()) { |
|
1473 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1474 | + } else { |
|
1475 | 1475 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1476 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1476 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1477 | 1477 | $model_objs_affected_ids = array(); |
1478 | - foreach( $models_affected_key_columns as $row ){ |
|
1479 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1480 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1478 | + foreach ($models_affected_key_columns as $row) { |
|
1479 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1480 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | } |
1484 | 1484 | |
1485 | - if( ! $model_objs_affected_ids ){ |
|
1485 | + if ( ! $model_objs_affected_ids) { |
|
1486 | 1486 | //wait wait wait- if nothing was affected let's stop here |
1487 | 1487 | return 0; |
1488 | 1488 | } |
1489 | - foreach( $model_objs_affected_ids as $id ){ |
|
1490 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1491 | - if( $model_obj_in_entity_map ){ |
|
1492 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1493 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1489 | + foreach ($model_objs_affected_ids as $id) { |
|
1490 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1491 | + if ($model_obj_in_entity_map) { |
|
1492 | + foreach ($fields_n_values as $field => $new_value) { |
|
1493 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1494 | 1494 | } |
1495 | 1495 | } |
1496 | 1496 | } |
1497 | 1497 | //if there is a primary key on this model, we can now do a slight optimization |
1498 | - if( $this->has_primary_key_field() ){ |
|
1498 | + if ($this->has_primary_key_field()) { |
|
1499 | 1499 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1500 | 1500 | $query_params = array( |
1501 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1502 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1501 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1502 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1503 | 1503 | } |
1504 | 1504 | } |
1505 | 1505 | |
1506 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1507 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1508 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1506 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1507 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1508 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1509 | 1509 | /** |
1510 | 1510 | * Action called after a model update call has been made. |
1511 | 1511 | * |
@@ -1514,8 +1514,8 @@ discard block |
||
1514 | 1514 | * @param array $query_params @see EEM_Base::get_all() |
1515 | 1515 | * @param int $rows_affected |
1516 | 1516 | */ |
1517 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1518 | - return $rows_affected;//how many supposedly got updated |
|
1517 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1518 | + return $rows_affected; //how many supposedly got updated |
|
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | |
@@ -1531,22 +1531,22 @@ discard block |
||
1531 | 1531 | * @return array just like $wpdb->get_col() |
1532 | 1532 | * @throws \EE_Error |
1533 | 1533 | */ |
1534 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1534 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1535 | 1535 | |
1536 | - if( $field_to_select ){ |
|
1537 | - $field = $this->field_settings_for( $field_to_select ); |
|
1538 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1536 | + if ($field_to_select) { |
|
1537 | + $field = $this->field_settings_for($field_to_select); |
|
1538 | + }elseif ($this->has_primary_key_field( )) { |
|
1539 | 1539 | $field = $this->get_primary_key_field(); |
1540 | - }else{ |
|
1540 | + } else { |
|
1541 | 1541 | //no primary key, just grab the first column |
1542 | - $field = reset( $this->field_settings()); |
|
1542 | + $field = reset($this->field_settings()); |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | |
1546 | 1546 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1547 | 1547 | $select_expressions = $field->get_qualified_column(); |
1548 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1549 | - return $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1548 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1549 | + return $this->_do_wpdb_query('get_col', array($SQL)); |
|
1550 | 1550 | } |
1551 | 1551 | |
1552 | 1552 | |
@@ -1559,12 +1559,12 @@ discard block |
||
1559 | 1559 | * @return string |
1560 | 1560 | * @throws \EE_Error |
1561 | 1561 | */ |
1562 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1563 | - $query_params[ 'limit' ] = 1; |
|
1564 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1565 | - if( ! empty( $col ) ) { |
|
1566 | - return reset( $col ); |
|
1567 | - }else{ |
|
1562 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1563 | + $query_params['limit'] = 1; |
|
1564 | + $col = $this->get_col($query_params, $field_to_select); |
|
1565 | + if ( ! empty($col)) { |
|
1566 | + return reset($col); |
|
1567 | + } else { |
|
1568 | 1568 | return NULL; |
1569 | 1569 | } |
1570 | 1570 | } |
@@ -1580,19 +1580,19 @@ discard block |
||
1580 | 1580 | * @return string of SQL |
1581 | 1581 | * @throws \EE_Error |
1582 | 1582 | */ |
1583 | - public function _construct_update_sql($fields_n_values){ |
|
1583 | + public function _construct_update_sql($fields_n_values) { |
|
1584 | 1584 | /** @type WPDB $wpdb */ |
1585 | 1585 | global $wpdb; |
1586 | 1586 | $cols_n_values = array(); |
1587 | - foreach($fields_n_values as $field_name => $value){ |
|
1587 | + foreach ($fields_n_values as $field_name => $value) { |
|
1588 | 1588 | $field_obj = $this->field_settings_for($field_name); |
1589 | 1589 | //if the value is NULL, we want to assign the value to that. |
1590 | 1590 | //wpdb->prepare doesn't really handle that properly |
1591 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1592 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1591 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1592 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1593 | 1593 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1594 | 1594 | } |
1595 | - return implode(",",$cols_n_values); |
|
1595 | + return implode(",", $cols_n_values); |
|
1596 | 1596 | |
1597 | 1597 | } |
1598 | 1598 | |
@@ -1608,10 +1608,10 @@ discard block |
||
1608 | 1608 | * @return boolean whether the row got deleted or not |
1609 | 1609 | * @throws \EE_Error |
1610 | 1610 | */ |
1611 | - public function delete_permanently_by_ID( $id ) { |
|
1611 | + public function delete_permanently_by_ID($id) { |
|
1612 | 1612 | return $this->delete_permanently( |
1613 | 1613 | array( |
1614 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1614 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1615 | 1615 | 'limit' => 1 |
1616 | 1616 | ) |
1617 | 1617 | ); |
@@ -1627,10 +1627,10 @@ discard block |
||
1627 | 1627 | * @return boolean whether the row got deleted or not |
1628 | 1628 | * @throws \EE_Error |
1629 | 1629 | */ |
1630 | - public function delete_by_ID( $id ){ |
|
1630 | + public function delete_by_ID($id) { |
|
1631 | 1631 | return $this->delete( |
1632 | 1632 | array( |
1633 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1633 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1634 | 1634 | 'limit' => 1 |
1635 | 1635 | ) |
1636 | 1636 | ); |
@@ -1649,7 +1649,7 @@ discard block |
||
1649 | 1649 | * @return int how many rows got deleted |
1650 | 1650 | * @throws \EE_Error |
1651 | 1651 | */ |
1652 | - public function delete($query_params,$allow_blocking = true){ |
|
1652 | + public function delete($query_params, $allow_blocking = true) { |
|
1653 | 1653 | return $this->delete_permanently($query_params, $allow_blocking); |
1654 | 1654 | } |
1655 | 1655 | |
@@ -1667,7 +1667,7 @@ discard block |
||
1667 | 1667 | * @return int how many rows got deleted |
1668 | 1668 | * @throws \EE_Error |
1669 | 1669 | */ |
1670 | - public function delete_permanently($query_params,$allow_blocking = true){ |
|
1670 | + public function delete_permanently($query_params, $allow_blocking = true) { |
|
1671 | 1671 | /** |
1672 | 1672 | * Action called just before performing a real deletion query. You can use the |
1673 | 1673 | * model and its $query_params to find exactly which items will be deleted |
@@ -1676,31 +1676,31 @@ discard block |
||
1676 | 1676 | * @param boolean $allow_blocking whether or not to allow related model objects |
1677 | 1677 | * to block (prevent) this deletion |
1678 | 1678 | */ |
1679 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1679 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1680 | 1680 | //some MySQL databases may be running safe mode, which may restrict |
1681 | 1681 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1682 | 1682 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1683 | 1683 | //to delete them |
1684 | 1684 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1685 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1686 | - if($deletion_where){ |
|
1685 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1686 | + if ($deletion_where) { |
|
1687 | 1687 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1688 | 1688 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1689 | - $table_aliases = array_keys( $this->_tables ); |
|
1690 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1689 | + $table_aliases = array_keys($this->_tables); |
|
1690 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1691 | 1691 | |
1692 | 1692 | // /echo "delete sql:$SQL"; |
1693 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1694 | - }else{ |
|
1693 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1694 | + } else { |
|
1695 | 1695 | $rows_deleted = 0; |
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1699 | - if( $this->has_primary_key_field() ){ |
|
1700 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1701 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1702 | - if( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ) ){ |
|
1703 | - unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ); |
|
1699 | + if ($this->has_primary_key_field()) { |
|
1700 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1701 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1702 | + if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value])) { |
|
1703 | + unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value]); |
|
1704 | 1704 | } |
1705 | 1705 | } |
1706 | 1706 | } |
@@ -1712,8 +1712,8 @@ discard block |
||
1712 | 1712 | * @param array $query_params @see EEM_Base::get_all() |
1713 | 1713 | * @param int $rows_deleted |
1714 | 1714 | */ |
1715 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1716 | - return $rows_deleted;//how many supposedly got deleted |
|
1715 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1716 | + return $rows_deleted; //how many supposedly got deleted |
|
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 | |
@@ -1731,28 +1731,28 @@ discard block |
||
1731 | 1731 | * @return boolean |
1732 | 1732 | * @throws \EE_Error |
1733 | 1733 | */ |
1734 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1734 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1735 | 1735 | //first, if $ignore_this_model_obj was supplied, get its model |
1736 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1736 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1737 | 1737 | $ignored_model = $ignore_this_model_obj->get_model(); |
1738 | - }else{ |
|
1738 | + } else { |
|
1739 | 1739 | $ignored_model = null; |
1740 | 1740 | } |
1741 | 1741 | //now check all the relations of $this_model_obj_or_id and see if there |
1742 | 1742 | //are any related model objects blocking it? |
1743 | 1743 | $is_blocked = false; |
1744 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1745 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1744 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1745 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1746 | 1746 | //if $ignore_this_model_obj was supplied, then for the query |
1747 | 1747 | //on that model needs to be told to ignore $ignore_this_model_obj |
1748 | - if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
|
1749 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1750 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1751 | - }else{ |
|
1748 | + if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) { |
|
1749 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1750 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1751 | + } else { |
|
1752 | 1752 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1753 | 1753 | } |
1754 | 1754 | |
1755 | - if($related_model_objects){ |
|
1755 | + if ($related_model_objects) { |
|
1756 | 1756 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1757 | 1757 | $is_blocked = true; |
1758 | 1758 | } |
@@ -1772,75 +1772,75 @@ discard block |
||
1772 | 1772 | * @throws EE_Error |
1773 | 1773 | * @return string everything that comes after the WHERE statement. |
1774 | 1774 | */ |
1775 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1776 | - if($this->has_primary_key_field()){ |
|
1775 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1776 | + if ($this->has_primary_key_field()) { |
|
1777 | 1777 | $primary_table = $this->_get_main_table(); |
1778 | 1778 | $other_tables = $this->_get_other_tables(); |
1779 | 1779 | $deletes = $query = array(); |
1780 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1780 | + foreach ($objects_for_deletion as $delete_object) { |
|
1781 | 1781 | //before we mark this object for deletion, |
1782 | 1782 | //make sure there's no related objects blocking its deletion (if we're checking) |
1783 | 1783 | if ( |
1784 | 1784 | $allow_blocking |
1785 | 1785 | && $this->delete_is_blocked_by_related_models( |
1786 | - $delete_object[ $primary_table->get_fully_qualified_pk_column() ] |
|
1786 | + $delete_object[$primary_table->get_fully_qualified_pk_column()] |
|
1787 | 1787 | ) |
1788 | 1788 | ) { |
1789 | 1789 | continue; |
1790 | 1790 | } |
1791 | 1791 | //primary table deletes |
1792 | - if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) { |
|
1793 | - $deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ]; |
|
1792 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1793 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1794 | 1794 | } |
1795 | 1795 | //other tables |
1796 | - if ( ! empty( $other_tables ) ) { |
|
1797 | - foreach ( $other_tables as $ot ) { |
|
1796 | + if ( ! empty($other_tables)) { |
|
1797 | + foreach ($other_tables as $ot) { |
|
1798 | 1798 | //first check if we've got the foreign key column here. |
1799 | - if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) { |
|
1800 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ]; |
|
1799 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) { |
|
1800 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1801 | 1801 | } |
1802 | 1802 | // wait! it's entirely possible that we'll have a the primary key |
1803 | 1803 | // for this table in here, if it's a foreign key for one of the other secondary tables |
1804 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) { |
|
1805 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1804 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) { |
|
1805 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1806 | 1806 | } |
1807 | 1807 | // finally, it is possible that the fk for this table is found |
1808 | 1808 | // in the fully qualified pk column for the fk table, so let's see if that's there! |
1809 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) { |
|
1810 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1809 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) { |
|
1810 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1811 | 1811 | } |
1812 | 1812 | } |
1813 | 1813 | } |
1814 | 1814 | } |
1815 | 1815 | |
1816 | 1816 | //we should have deletes now, so let's just go through and setup the where statement |
1817 | - foreach ( $deletes as $column => $values ) { |
|
1817 | + foreach ($deletes as $column => $values) { |
|
1818 | 1818 | //make sure we have unique $values; |
1819 | 1819 | $values = array_unique($values); |
1820 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1820 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1821 | 1821 | } |
1822 | 1822 | |
1823 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1824 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1823 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1824 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1825 | 1825 | $ways_to_identify_a_row = array(); |
1826 | 1826 | $fields = $this->get_combined_primary_key_fields(); |
1827 | 1827 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1828 | - foreach($objects_for_deletion as $delete_object){ |
|
1828 | + foreach ($objects_for_deletion as $delete_object) { |
|
1829 | 1829 | $values_for_each_cpk_for_a_row = array(); |
1830 | - foreach($fields as $cpk_field){ |
|
1831 | - if ( $cpk_field instanceof EE_Model_Field_Base ){ |
|
1830 | + foreach ($fields as $cpk_field) { |
|
1831 | + if ($cpk_field instanceof EE_Model_Field_Base) { |
|
1832 | 1832 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column() |
1833 | 1833 | . "=" |
1834 | - . $delete_object[ $cpk_field->get_qualified_column() ]; |
|
1834 | + . $delete_object[$cpk_field->get_qualified_column()]; |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1837 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1838 | 1838 | } |
1839 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1840 | - }else{ |
|
1839 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1840 | + } else { |
|
1841 | 1841 | //so there's no primary key and no combined key... |
1842 | 1842 | //sorry, can't help you |
1843 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1843 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1844 | 1844 | } |
1845 | 1845 | } |
1846 | 1846 | |
@@ -1856,34 +1856,34 @@ discard block |
||
1856 | 1856 | * @return int |
1857 | 1857 | * @throws \EE_Error |
1858 | 1858 | */ |
1859 | - public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1859 | + public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1860 | 1860 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1861 | - if($field_to_count){ |
|
1861 | + if ($field_to_count) { |
|
1862 | 1862 | $field_obj = $this->field_settings_for($field_to_count); |
1863 | 1863 | $column_to_count = $field_obj->get_qualified_column(); |
1864 | - }elseif($this->has_primary_key_field ()){ |
|
1864 | + }elseif ($this->has_primary_key_field()) { |
|
1865 | 1865 | $pk_field_obj = $this->get_primary_key_field(); |
1866 | 1866 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1867 | - }else{ |
|
1867 | + } else { |
|
1868 | 1868 | //there's no primary key |
1869 | 1869 | //if we're counting distinct items, and there's no primary key, |
1870 | 1870 | //we need to list out the columns for distinction; |
1871 | 1871 | //otherwise we can just use star |
1872 | - if( $distinct ) { |
|
1872 | + if ($distinct) { |
|
1873 | 1873 | $columns_to_use = array(); |
1874 | - foreach( $this->get_combined_primary_key_fields() as $field_obj ) { |
|
1874 | + foreach ($this->get_combined_primary_key_fields() as $field_obj) { |
|
1875 | 1875 | $columns_to_use[] = $field_obj->get_qualified_column(); |
1876 | 1876 | } |
1877 | - $column_to_count = implode(',', $columns_to_use ); |
|
1877 | + $column_to_count = implode(',', $columns_to_use); |
|
1878 | 1878 | } else { |
1879 | 1879 | $column_to_count = '*'; |
1880 | 1880 | } |
1881 | 1881 | |
1882 | 1882 | } |
1883 | 1883 | |
1884 | - $column_to_count = $distinct ? "DISTINCT " . $column_to_count : $column_to_count; |
|
1885 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1886 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1884 | + $column_to_count = $distinct ? "DISTINCT ".$column_to_count : $column_to_count; |
|
1885 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1886 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | |
@@ -1896,24 +1896,24 @@ discard block |
||
1896 | 1896 | * @return float |
1897 | 1897 | * @throws \EE_Error |
1898 | 1898 | */ |
1899 | - public function sum($query_params, $field_to_sum = NULL){ |
|
1899 | + public function sum($query_params, $field_to_sum = NULL) { |
|
1900 | 1900 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1901 | 1901 | |
1902 | - if($field_to_sum){ |
|
1902 | + if ($field_to_sum) { |
|
1903 | 1903 | $field_obj = $this->field_settings_for($field_to_sum); |
1904 | 1904 | |
1905 | - }else{ |
|
1905 | + } else { |
|
1906 | 1906 | $field_obj = $this->get_primary_key_field(); |
1907 | 1907 | } |
1908 | 1908 | $column_to_count = $field_obj->get_qualified_column(); |
1909 | 1909 | |
1910 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1911 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1910 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1911 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1912 | 1912 | $data_type = $field_obj->get_wpdb_data_type(); |
1913 | - if( $data_type === '%d' || $data_type === '%s' ){ |
|
1914 | - return (float)$return_value; |
|
1915 | - }else{//must be %f |
|
1916 | - return (float)$return_value; |
|
1913 | + if ($data_type === '%d' || $data_type === '%s') { |
|
1914 | + return (float) $return_value; |
|
1915 | + } else {//must be %f |
|
1916 | + return (float) $return_value; |
|
1917 | 1917 | } |
1918 | 1918 | } |
1919 | 1919 | |
@@ -1928,37 +1928,37 @@ discard block |
||
1928 | 1928 | * @global wpdb $wpdb |
1929 | 1929 | * @return mixed |
1930 | 1930 | */ |
1931 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1931 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1932 | 1932 | //if we're in maintenance mode level 2, DON'T run any queries |
1933 | 1933 | //because level 2 indicates the database needs updating and |
1934 | 1934 | //is probably out of sync with the code |
1935 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1935 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1936 | 1936 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1937 | 1937 | } |
1938 | 1938 | /** @type WPDB $wpdb */ |
1939 | 1939 | global $wpdb; |
1940 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1941 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1940 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1941 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1942 | 1942 | } |
1943 | - if( WP_DEBUG ){ |
|
1943 | + if (WP_DEBUG) { |
|
1944 | 1944 | $old_show_errors_value = $wpdb->show_errors; |
1945 | - $wpdb->show_errors( FALSE ); |
|
1946 | - } |
|
1947 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1948 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1949 | - if( WP_DEBUG ){ |
|
1950 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1951 | - if( ! empty( $wpdb->last_error ) ){ |
|
1952 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1953 | - }elseif( $result === false ){ |
|
1954 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1945 | + $wpdb->show_errors(FALSE); |
|
1946 | + } |
|
1947 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1948 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1949 | + if (WP_DEBUG) { |
|
1950 | + $wpdb->show_errors($old_show_errors_value); |
|
1951 | + if ( ! empty($wpdb->last_error)) { |
|
1952 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1953 | + }elseif ($result === false) { |
|
1954 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1955 | 1955 | } |
1956 | - }elseif( $result === false ) { |
|
1956 | + }elseif ($result === false) { |
|
1957 | 1957 | EE_Error::add_error( |
1958 | 1958 | sprintf( |
1959 | - __( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ), |
|
1959 | + __('A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso'), |
|
1960 | 1960 | $wpdb_method, |
1961 | - var_export( $arguments_to_provide, true ), |
|
1961 | + var_export($arguments_to_provide, true), |
|
1962 | 1962 | $wpdb->last_error |
1963 | 1963 | ), |
1964 | 1964 | __FILE__, |
@@ -1980,26 +1980,26 @@ discard block |
||
1980 | 1980 | * @param array $arguments_to_provide |
1981 | 1981 | * @return mixed |
1982 | 1982 | */ |
1983 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1983 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1984 | 1984 | /** @type WPDB $wpdb */ |
1985 | 1985 | global $wpdb; |
1986 | 1986 | $wpdb->last_error = null; |
1987 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1987 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1988 | 1988 | // was there an error running the query? but we don't care on new activations |
1989 | 1989 | // (we're going to setup the DB anyway on new activations) |
1990 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) |
|
1990 | + if (($result === false || ! empty($wpdb->last_error)) |
|
1991 | 1991 | && EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation |
1992 | 1992 | ) { |
1993 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1993 | + switch (EEM_Base::$_db_verification_level) { |
|
1994 | 1994 | |
1995 | 1995 | case EEM_Base::db_verified_none : |
1996 | 1996 | // let's double-check core's DB |
1997 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1997 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1998 | 1998 | break; |
1999 | 1999 | |
2000 | 2000 | case EEM_Base::db_verified_core : |
2001 | 2001 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
2002 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
2002 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
2003 | 2003 | break; |
2004 | 2004 | |
2005 | 2005 | case EEM_Base::db_verified_addons : |
@@ -2007,11 +2007,11 @@ discard block |
||
2007 | 2007 | return $result; |
2008 | 2008 | break; |
2009 | 2009 | } |
2010 | - if ( ! empty( $error_message ) ) { |
|
2011 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
2012 | - trigger_error( $error_message ); |
|
2010 | + if ( ! empty($error_message)) { |
|
2011 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
2012 | + trigger_error($error_message); |
|
2013 | 2013 | } |
2014 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
2014 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
2015 | 2015 | |
2016 | 2016 | } |
2017 | 2017 | |
@@ -2027,18 +2027,18 @@ discard block |
||
2027 | 2027 | * @param array $arguments_to_provide |
2028 | 2028 | * @return string |
2029 | 2029 | */ |
2030 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
2030 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
2031 | 2031 | /** @type WPDB $wpdb */ |
2032 | 2032 | global $wpdb; |
2033 | 2033 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
2034 | 2034 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
2035 | 2035 | $error_message = sprintf( |
2036 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
2036 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
2037 | 2037 | $wpdb->last_error, |
2038 | 2038 | $wpdb_method, |
2039 | - json_encode( $arguments_to_provide ) |
|
2039 | + json_encode($arguments_to_provide) |
|
2040 | 2040 | ); |
2041 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
2041 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
2042 | 2042 | return $error_message; |
2043 | 2043 | } |
2044 | 2044 | |
@@ -2051,16 +2051,16 @@ discard block |
||
2051 | 2051 | * @param $arguments_to_provide |
2052 | 2052 | * @return string |
2053 | 2053 | */ |
2054 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
2054 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
2055 | 2055 | /** @type WPDB $wpdb */ |
2056 | 2056 | global $wpdb; |
2057 | 2057 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
2058 | 2058 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
2059 | 2059 | $error_message = sprintf( |
2060 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
2060 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
2061 | 2061 | $wpdb->last_error, |
2062 | 2062 | $wpdb_method, |
2063 | - json_encode( $arguments_to_provide ) |
|
2063 | + json_encode($arguments_to_provide) |
|
2064 | 2064 | ); |
2065 | 2065 | EE_System::instance()->initialize_addons(); |
2066 | 2066 | return $error_message; |
@@ -2075,7 +2075,7 @@ discard block |
||
2075 | 2075 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2076 | 2076 | * @return string |
2077 | 2077 | */ |
2078 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2078 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2079 | 2079 | return " FROM ".$model_query_info->get_full_join_sql(). |
2080 | 2080 | $model_query_info->get_where_sql(). |
2081 | 2081 | $model_query_info->get_group_by_sql(). |
@@ -2088,7 +2088,7 @@ discard block |
||
2088 | 2088 | * Set to easily debug the next X queries ran from this model. |
2089 | 2089 | * @param int $count |
2090 | 2090 | */ |
2091 | - public function show_next_x_db_queries($count = 1){ |
|
2091 | + public function show_next_x_db_queries($count = 1) { |
|
2092 | 2092 | $this->_show_next_x_db_queries = $count; |
2093 | 2093 | } |
2094 | 2094 | |
@@ -2097,8 +2097,8 @@ discard block |
||
2097 | 2097 | /** |
2098 | 2098 | * @param $sql_query |
2099 | 2099 | */ |
2100 | - public function show_db_query_if_previously_requested($sql_query){ |
|
2101 | - if($this->_show_next_x_db_queries > 0){ |
|
2100 | + public function show_db_query_if_previously_requested($sql_query) { |
|
2101 | + if ($this->_show_next_x_db_queries > 0) { |
|
2102 | 2102 | echo $sql_query; |
2103 | 2103 | $this->_show_next_x_db_queries--; |
2104 | 2104 | } |
@@ -2122,9 +2122,9 @@ discard block |
||
2122 | 2122 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2123 | 2123 | * @throws \EE_Error |
2124 | 2124 | */ |
2125 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2125 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2126 | 2126 | $relation_obj = $this->related_settings_for($relationName); |
2127 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2127 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2128 | 2128 | } |
2129 | 2129 | |
2130 | 2130 | |
@@ -2143,9 +2143,9 @@ discard block |
||
2143 | 2143 | * @throws \EE_Error |
2144 | 2144 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2145 | 2145 | */ |
2146 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2146 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2147 | 2147 | $relation_obj = $this->related_settings_for($relationName); |
2148 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2148 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2149 | 2149 | } |
2150 | 2150 | |
2151 | 2151 | |
@@ -2158,9 +2158,9 @@ discard block |
||
2158 | 2158 | * @return \EE_Base_Class[] |
2159 | 2159 | * @throws \EE_Error |
2160 | 2160 | */ |
2161 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2161 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2162 | 2162 | $relation_obj = $this->related_settings_for($relationName); |
2163 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2163 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2164 | 2164 | } |
2165 | 2165 | |
2166 | 2166 | |
@@ -2176,10 +2176,10 @@ discard block |
||
2176 | 2176 | * @return EE_Base_Class[] |
2177 | 2177 | * @throws \EE_Error |
2178 | 2178 | */ |
2179 | - public function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2179 | + public function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2180 | 2180 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2181 | 2181 | $relation_settings = $this->related_settings_for($model_name); |
2182 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2182 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2183 | 2183 | } |
2184 | 2184 | |
2185 | 2185 | |
@@ -2196,10 +2196,10 @@ discard block |
||
2196 | 2196 | * @return int how many deleted |
2197 | 2197 | * @throws \EE_Error |
2198 | 2198 | */ |
2199 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2199 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2200 | 2200 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2201 | 2201 | $relation_settings = $this->related_settings_for($model_name); |
2202 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2202 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2203 | 2203 | } |
2204 | 2204 | |
2205 | 2205 | |
@@ -2216,10 +2216,10 @@ discard block |
||
2216 | 2216 | * @return int how many deleted |
2217 | 2217 | * @throws \EE_Error |
2218 | 2218 | */ |
2219 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2219 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2220 | 2220 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2221 | 2221 | $relation_settings = $this->related_settings_for($model_name); |
2222 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2222 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2223 | 2223 | } |
2224 | 2224 | |
2225 | 2225 | |
@@ -2236,17 +2236,17 @@ discard block |
||
2236 | 2236 | * @return int |
2237 | 2237 | * @throws \EE_Error |
2238 | 2238 | */ |
2239 | - public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2239 | + public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2240 | 2240 | $related_model = $this->get_related_model_obj($model_name); |
2241 | 2241 | //we're just going to use the query params on the related model's normal get_all query, |
2242 | 2242 | //except add a condition to say to match the current mod |
2243 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2244 | - $query_params['default_where_conditions']='none'; |
|
2243 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2244 | + $query_params['default_where_conditions'] = 'none'; |
|
2245 | 2245 | } |
2246 | 2246 | $this_model_name = $this->get_this_model_name(); |
2247 | 2247 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2248 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2249 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2248 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2249 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2250 | 2250 | } |
2251 | 2251 | |
2252 | 2252 | |
@@ -2262,21 +2262,21 @@ discard block |
||
2262 | 2262 | * @return float |
2263 | 2263 | * @throws \EE_Error |
2264 | 2264 | */ |
2265 | - public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2265 | + public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2266 | 2266 | $related_model = $this->get_related_model_obj($model_name); |
2267 | - if( ! is_array( $query_params ) ){ |
|
2268 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2267 | + if ( ! is_array($query_params)) { |
|
2268 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2269 | 2269 | $query_params = array(); |
2270 | 2270 | } |
2271 | 2271 | //we're just going to use the query params on the related model's normal get_all query, |
2272 | 2272 | //except add a condition to say to match the current mod |
2273 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2274 | - $query_params['default_where_conditions']='none'; |
|
2273 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2274 | + $query_params['default_where_conditions'] = 'none'; |
|
2275 | 2275 | } |
2276 | 2276 | $this_model_name = $this->get_this_model_name(); |
2277 | 2277 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2278 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2279 | - return $related_model->sum($query_params,$field_to_sum); |
|
2278 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2279 | + return $related_model->sum($query_params, $field_to_sum); |
|
2280 | 2280 | } |
2281 | 2281 | |
2282 | 2282 | |
@@ -2290,12 +2290,12 @@ discard block |
||
2290 | 2290 | * @return EE_Base_Class |
2291 | 2291 | * @throws \EE_Error |
2292 | 2292 | */ |
2293 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2294 | - $query_params['limit']=1; |
|
2295 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2296 | - if( $results ){ |
|
2293 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2294 | + $query_params['limit'] = 1; |
|
2295 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2296 | + if ($results) { |
|
2297 | 2297 | return array_shift($results); |
2298 | - }else{ |
|
2298 | + } else { |
|
2299 | 2299 | return null; |
2300 | 2300 | } |
2301 | 2301 | |
@@ -2305,8 +2305,8 @@ discard block |
||
2305 | 2305 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2306 | 2306 | * @return string |
2307 | 2307 | */ |
2308 | - public function get_this_model_name(){ |
|
2309 | - return str_replace("EEM_","",get_class($this)); |
|
2308 | + public function get_this_model_name() { |
|
2309 | + return str_replace("EEM_", "", get_class($this)); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | /** |
@@ -2314,14 +2314,14 @@ discard block |
||
2314 | 2314 | * @return EE_Any_Foreign_Model_Name_Field |
2315 | 2315 | * @throws EE_Error |
2316 | 2316 | */ |
2317 | - public function get_field_containing_related_model_name(){ |
|
2318 | - foreach($this->field_settings(true) as $field){ |
|
2319 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2317 | + public function get_field_containing_related_model_name() { |
|
2318 | + foreach ($this->field_settings(true) as $field) { |
|
2319 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2320 | 2320 | $field_with_model_name = $field; |
2321 | 2321 | } |
2322 | 2322 | } |
2323 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2324 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2323 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2324 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2325 | 2325 | } |
2326 | 2326 | return $field_with_model_name; |
2327 | 2327 | } |
@@ -2342,19 +2342,19 @@ discard block |
||
2342 | 2342 | * @return int new primary key on main table that got inserted |
2343 | 2343 | * @throws EE_Error |
2344 | 2344 | */ |
2345 | - public function insert($field_n_values){ |
|
2345 | + public function insert($field_n_values) { |
|
2346 | 2346 | /** |
2347 | 2347 | * Filters the fields and their values before inserting an item using the models |
2348 | 2348 | * @param array $fields_n_values keys are the fields and values are their new values |
2349 | 2349 | * @param EEM_Base $model the model used |
2350 | 2350 | */ |
2351 | - $field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2352 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2351 | + $field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2352 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2353 | 2353 | $main_table = $this->_get_main_table(); |
2354 | 2354 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2355 | - if( $new_id !== false ) { |
|
2356 | - foreach($this->_get_other_tables() as $other_table){ |
|
2357 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2355 | + if ($new_id !== false) { |
|
2356 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2357 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2358 | 2358 | } |
2359 | 2359 | } |
2360 | 2360 | /** |
@@ -2364,9 +2364,9 @@ discard block |
||
2364 | 2364 | * @param array $fields_n_values fields and their values |
2365 | 2365 | * @param int|string the ID of the newly-inserted model object |
2366 | 2366 | */ |
2367 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2367 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2368 | 2368 | return $new_id; |
2369 | - }else{ |
|
2369 | + } else { |
|
2370 | 2370 | return FALSE; |
2371 | 2371 | } |
2372 | 2372 | } |
@@ -2381,10 +2381,10 @@ discard block |
||
2381 | 2381 | * @return boolean |
2382 | 2382 | * @throws \EE_Error |
2383 | 2383 | */ |
2384 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2385 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2384 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2385 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2386 | 2386 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2387 | - if($this->exists(array($uniqueness_where_params))){ |
|
2387 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2388 | 2388 | EE_Error::add_error( |
2389 | 2389 | sprintf( |
2390 | 2390 | __( |
@@ -2394,8 +2394,8 @@ discard block |
||
2394 | 2394 | $action, |
2395 | 2395 | $this->_get_class_name(), |
2396 | 2396 | $index_name, |
2397 | - implode( ",", $index->field_names() ), |
|
2398 | - http_build_query( $uniqueness_where_params ) |
|
2397 | + implode(",", $index->field_names()), |
|
2398 | + http_build_query($uniqueness_where_params) |
|
2399 | 2399 | ), |
2400 | 2400 | __FILE__, |
2401 | 2401 | __FUNCTION__, |
@@ -2425,37 +2425,37 @@ discard block |
||
2425 | 2425 | * @throws EE_Error |
2426 | 2426 | * @return EE_Base_Class|array |
2427 | 2427 | */ |
2428 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2429 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2428 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2429 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2430 | 2430 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2431 | - }elseif( is_array($obj_or_fields_array)){ |
|
2431 | + }elseif (is_array($obj_or_fields_array)) { |
|
2432 | 2432 | $fields_n_values = $obj_or_fields_array; |
2433 | - }else{ |
|
2433 | + } else { |
|
2434 | 2434 | throw new EE_Error( |
2435 | 2435 | sprintf( |
2436 | 2436 | __( |
2437 | 2437 | "%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", |
2438 | 2438 | "event_espresso" |
2439 | 2439 | ), |
2440 | - get_class( $this ), |
|
2440 | + get_class($this), |
|
2441 | 2441 | $obj_or_fields_array |
2442 | 2442 | ) |
2443 | 2443 | ); |
2444 | 2444 | } |
2445 | 2445 | $query_params = array(); |
2446 | - if( $this->has_primary_key_field() && |
|
2447 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2448 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2446 | + if ($this->has_primary_key_field() && |
|
2447 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2448 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2449 | 2449 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2450 | 2450 | } |
2451 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2451 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2452 | 2452 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2453 | 2453 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2454 | 2454 | } |
2455 | 2455 | //if there is nothing to base this search on, then we shouldn't find anything |
2456 | - if( empty( $query_params ) ){ |
|
2456 | + if (empty($query_params)) { |
|
2457 | 2457 | return array(); |
2458 | - }else{ |
|
2458 | + } else { |
|
2459 | 2459 | return $this->get_one($query_params); |
2460 | 2460 | } |
2461 | 2461 | } |
@@ -2469,7 +2469,7 @@ discard block |
||
2469 | 2469 | * @return boolean |
2470 | 2470 | * @throws \EE_Error |
2471 | 2471 | */ |
2472 | - public function exists($query_params){ |
|
2472 | + public function exists($query_params) { |
|
2473 | 2473 | $query_params['limit'] = 1; |
2474 | 2474 | return $this->count($query_params) > 0; |
2475 | 2475 | } |
@@ -2483,7 +2483,7 @@ discard block |
||
2483 | 2483 | * @return boolean |
2484 | 2484 | * @throws \EE_Error |
2485 | 2485 | */ |
2486 | - public function exists_by_ID($id){ |
|
2486 | + public function exists_by_ID($id) { |
|
2487 | 2487 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2488 | 2488 | } |
2489 | 2489 | |
@@ -2503,45 +2503,45 @@ discard block |
||
2503 | 2503 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2504 | 2504 | * @return int ID of new row inserted, or FALSE on failure |
2505 | 2505 | */ |
2506 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2506 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2507 | 2507 | global $wpdb; |
2508 | 2508 | $insertion_col_n_values = array(); |
2509 | 2509 | $format_for_insertion = array(); |
2510 | 2510 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2511 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2511 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2512 | 2512 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2513 | - if($field_obj->is_auto_increment()){ |
|
2513 | + if ($field_obj->is_auto_increment()) { |
|
2514 | 2514 | continue; |
2515 | 2515 | } |
2516 | 2516 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2517 | 2517 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2518 | - if( $prepared_value !== NULL ){ |
|
2519 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2518 | + if ($prepared_value !== NULL) { |
|
2519 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2520 | 2520 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2521 | 2521 | } |
2522 | 2522 | } |
2523 | 2523 | |
2524 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2524 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2525 | 2525 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2526 | 2526 | //so add the fk to the main table as a column |
2527 | 2527 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2528 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2528 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2529 | 2529 | } |
2530 | 2530 | //insert the new entry |
2531 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2532 | - if( $result === false ) { |
|
2531 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2532 | + if ($result === false) { |
|
2533 | 2533 | return false; |
2534 | 2534 | } |
2535 | 2535 | //ok, now what do we return for the ID of the newly-inserted thing? |
2536 | - if($this->has_primary_key_field()){ |
|
2537 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2536 | + if ($this->has_primary_key_field()) { |
|
2537 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2538 | 2538 | return $wpdb->insert_id; |
2539 | - }else{ |
|
2539 | + } else { |
|
2540 | 2540 | //it's not an auto-increment primary key, so |
2541 | 2541 | //it must have been supplied |
2542 | 2542 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2543 | 2543 | } |
2544 | - }else{ |
|
2544 | + } else { |
|
2545 | 2545 | //we can't return a primary key because there is none. instead return |
2546 | 2546 | //a unique string indicating this model |
2547 | 2547 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2560,15 +2560,15 @@ discard block |
||
2560 | 2560 | * @return mixed string|int|float depending on what the table column will be expecting |
2561 | 2561 | * @throws \EE_Error |
2562 | 2562 | */ |
2563 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2563 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2564 | 2564 | //if this field doesn't allow nullable, don't allow it |
2565 | - if( ! $field_obj->is_nullable() && ( |
|
2566 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2567 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2568 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2565 | + if ( ! $field_obj->is_nullable() && ( |
|
2566 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2567 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2568 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2569 | 2569 | } |
2570 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2571 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2570 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2571 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2572 | 2572 | } |
2573 | 2573 | |
2574 | 2574 | |
@@ -2580,9 +2580,9 @@ discard block |
||
2580 | 2580 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2581 | 2581 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2582 | 2582 | */ |
2583 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2584 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2585 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2583 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2584 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2585 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2586 | 2586 | /** @noinspection PhpMissingBreakStatementInspection */ |
2587 | 2587 | case self::not_prepared_by_model_object: |
2588 | 2588 | $value = $field->prepare_for_set($value); |
@@ -2593,7 +2593,7 @@ discard block |
||
2593 | 2593 | //leave the value alone |
2594 | 2594 | } |
2595 | 2595 | return $value; |
2596 | - }else{ |
|
2596 | + } else { |
|
2597 | 2597 | return $value; |
2598 | 2598 | } |
2599 | 2599 | } |
@@ -2603,13 +2603,13 @@ discard block |
||
2603 | 2603 | * @return EE_Primary_Table |
2604 | 2604 | * @throws EE_Error |
2605 | 2605 | */ |
2606 | - protected function _get_main_table(){ |
|
2607 | - foreach($this->_tables as $table){ |
|
2608 | - if($table instanceof EE_Primary_Table){ |
|
2606 | + protected function _get_main_table() { |
|
2607 | + foreach ($this->_tables as $table) { |
|
2608 | + if ($table instanceof EE_Primary_Table) { |
|
2609 | 2609 | return $table; |
2610 | 2610 | } |
2611 | 2611 | } |
2612 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2612 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2613 | 2613 | } |
2614 | 2614 | |
2615 | 2615 | |
@@ -2632,7 +2632,7 @@ discard block |
||
2632 | 2632 | */ |
2633 | 2633 | public function second_table() { |
2634 | 2634 | // grab second table from tables array |
2635 | - $second_table = end( $this->_tables ); |
|
2635 | + $second_table = end($this->_tables); |
|
2636 | 2636 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2637 | 2637 | } |
2638 | 2638 | |
@@ -2645,8 +2645,8 @@ discard block |
||
2645 | 2645 | * @param string $table_alias |
2646 | 2646 | * @return EE_Primary_Table | EE_Secondary_Table |
2647 | 2647 | */ |
2648 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2649 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2648 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2649 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2650 | 2650 | } |
2651 | 2651 | |
2652 | 2652 | |
@@ -2655,10 +2655,10 @@ discard block |
||
2655 | 2655 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2656 | 2656 | * @return EE_Secondary_Table[] |
2657 | 2657 | */ |
2658 | - protected function _get_other_tables(){ |
|
2659 | - $other_tables =array(); |
|
2660 | - foreach($this->_tables as $table_alias => $table){ |
|
2661 | - if($table instanceof EE_Secondary_Table){ |
|
2658 | + protected function _get_other_tables() { |
|
2659 | + $other_tables = array(); |
|
2660 | + foreach ($this->_tables as $table_alias => $table) { |
|
2661 | + if ($table instanceof EE_Secondary_Table) { |
|
2662 | 2662 | $other_tables[$table_alias] = $table; |
2663 | 2663 | } |
2664 | 2664 | } |
@@ -2670,7 +2670,7 @@ discard block |
||
2670 | 2670 | * @param string $table_alias, array key in EEM_Base::_tables |
2671 | 2671 | * @return EE_Model_Field_Base[] |
2672 | 2672 | */ |
2673 | - public function _get_fields_for_table($table_alias){ |
|
2673 | + public function _get_fields_for_table($table_alias) { |
|
2674 | 2674 | return $this->_fields[$table_alias]; |
2675 | 2675 | } |
2676 | 2676 | |
@@ -2686,19 +2686,19 @@ discard block |
||
2686 | 2686 | * @return EE_Model_Query_Info_Carrier |
2687 | 2687 | * @throws \EE_Error |
2688 | 2688 | */ |
2689 | - public function _extract_related_models_from_query($query_params){ |
|
2689 | + public function _extract_related_models_from_query($query_params) { |
|
2690 | 2690 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2691 | - if ( array_key_exists( 0, $query_params ) ) { |
|
2692 | - $this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 ); |
|
2691 | + if (array_key_exists(0, $query_params)) { |
|
2692 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2693 | 2693 | } |
2694 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2695 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2694 | + if (array_key_exists('group_by', $query_params)) { |
|
2695 | + if (is_array($query_params['group_by'])) { |
|
2696 | 2696 | $this->_extract_related_models_from_sub_params_array_values( |
2697 | 2697 | $query_params['group_by'], |
2698 | 2698 | $query_info_carrier, |
2699 | 2699 | 'group_by' |
2700 | 2700 | ); |
2701 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2701 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2702 | 2702 | $this->_extract_related_model_info_from_query_param( |
2703 | 2703 | $query_params['group_by'], |
2704 | 2704 | $query_info_carrier, |
@@ -2706,21 +2706,21 @@ discard block |
||
2706 | 2706 | ); |
2707 | 2707 | } |
2708 | 2708 | } |
2709 | - if ( array_key_exists( 'having', $query_params ) ) { |
|
2709 | + if (array_key_exists('having', $query_params)) { |
|
2710 | 2710 | $this->_extract_related_models_from_sub_params_array_keys( |
2711 | 2711 | $query_params[0], |
2712 | 2712 | $query_info_carrier, |
2713 | 2713 | 'having' |
2714 | 2714 | ); |
2715 | 2715 | } |
2716 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2717 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2716 | + if (array_key_exists('order_by', $query_params)) { |
|
2717 | + if (is_array($query_params['order_by'])) { |
|
2718 | 2718 | $this->_extract_related_models_from_sub_params_array_keys( |
2719 | 2719 | $query_params['order_by'], |
2720 | 2720 | $query_info_carrier, |
2721 | 2721 | 'order_by' |
2722 | 2722 | ); |
2723 | - } elseif ( ! empty( $query_params['order_by'] ) ) { |
|
2723 | + } elseif ( ! empty($query_params['order_by'])) { |
|
2724 | 2724 | $this->_extract_related_model_info_from_query_param( |
2725 | 2725 | $query_params['order_by'], |
2726 | 2726 | $query_info_carrier, |
@@ -2728,7 +2728,7 @@ discard block |
||
2728 | 2728 | ); |
2729 | 2729 | } |
2730 | 2730 | } |
2731 | - if ( array_key_exists( 'force_join', $query_params ) ) { |
|
2731 | + if (array_key_exists('force_join', $query_params)) { |
|
2732 | 2732 | $this->_extract_related_models_from_sub_params_array_values( |
2733 | 2733 | $query_params['force_join'], |
2734 | 2734 | $query_info_carrier, |
@@ -2746,34 +2746,34 @@ discard block |
||
2746 | 2746 | * @throws EE_Error |
2747 | 2747 | * @return \EE_Model_Query_Info_Carrier |
2748 | 2748 | */ |
2749 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2750 | - if (!empty($sub_query_params)){ |
|
2749 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2750 | + if ( ! empty($sub_query_params)) { |
|
2751 | 2751 | $sub_query_params = (array) $sub_query_params; |
2752 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2752 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2753 | 2753 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2754 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2754 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2755 | 2755 | |
2756 | 2756 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2757 | 2757 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2758 | 2758 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2759 | 2759 | //of array('Registration.TXN_ID'=>23) |
2760 | 2760 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2761 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2762 | - if (! is_array($possibly_array_of_params)){ |
|
2761 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2762 | + if ( ! is_array($possibly_array_of_params)) { |
|
2763 | 2763 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2764 | - $param,$possibly_array_of_params)); |
|
2765 | - }else{ |
|
2766 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2764 | + $param, $possibly_array_of_params)); |
|
2765 | + } else { |
|
2766 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2767 | 2767 | } |
2768 | - }elseif($query_param_type === 0 //ie WHERE |
|
2768 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2769 | 2769 | && is_array($possibly_array_of_params) |
2770 | 2770 | && isset($possibly_array_of_params[2]) |
2771 | - && $possibly_array_of_params[2] == true){ |
|
2771 | + && $possibly_array_of_params[2] == true) { |
|
2772 | 2772 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2773 | 2773 | //indicating that $possible_array_of_params[1] is actually a field name, |
2774 | 2774 | //from which we should extract query parameters! |
2775 | - if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) { |
|
2776 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2775 | + if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) { |
|
2776 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2777 | 2777 | } |
2778 | 2778 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2779 | 2779 | } |
@@ -2792,14 +2792,14 @@ discard block |
||
2792 | 2792 | * @throws EE_Error |
2793 | 2793 | * @return \EE_Model_Query_Info_Carrier |
2794 | 2794 | */ |
2795 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2796 | - if (!empty($sub_query_params)){ |
|
2797 | - if(!is_array($sub_query_params)){ |
|
2798 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2795 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2796 | + if ( ! empty($sub_query_params)) { |
|
2797 | + if ( ! is_array($sub_query_params)) { |
|
2798 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2799 | 2799 | } |
2800 | - foreach($sub_query_params as $param){ |
|
2800 | + foreach ($sub_query_params as $param) { |
|
2801 | 2801 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2802 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2802 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2803 | 2803 | } |
2804 | 2804 | } |
2805 | 2805 | return $model_query_info_carrier; |
@@ -2818,8 +2818,8 @@ discard block |
||
2818 | 2818 | * @throws EE_Error |
2819 | 2819 | * @return EE_Model_Query_Info_Carrier |
2820 | 2820 | */ |
2821 | - public function _create_model_query_info_carrier($query_params){ |
|
2822 | - if ( ! is_array( $query_params ) ) { |
|
2821 | + public function _create_model_query_info_carrier($query_params) { |
|
2822 | + if ( ! is_array($query_params)) { |
|
2823 | 2823 | EE_Error::doing_it_wrong( |
2824 | 2824 | 'EEM_Base::_create_model_query_info_carrier', |
2825 | 2825 | sprintf( |
@@ -2827,16 +2827,16 @@ discard block |
||
2827 | 2827 | '$query_params should be an array, you passed a variable of type %s', |
2828 | 2828 | 'event_espresso' |
2829 | 2829 | ), |
2830 | - gettype( $query_params ) |
|
2830 | + gettype($query_params) |
|
2831 | 2831 | ), |
2832 | 2832 | '4.6.0' |
2833 | 2833 | ); |
2834 | 2834 | $query_params = array(); |
2835 | 2835 | } |
2836 | - $where_query_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
2836 | + $where_query_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
2837 | 2837 | //first check if we should alter the query to account for caps or not |
2838 | 2838 | //because the caps might require us to do extra joins |
2839 | - if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) { |
|
2839 | + if (isset($query_params['caps']) && $query_params['caps'] !== 'none') { |
|
2840 | 2840 | $query_params[0] = $where_query_params = array_replace_recursive( |
2841 | 2841 | $where_query_params, |
2842 | 2842 | $this->caps_where_conditions( |
@@ -2844,10 +2844,10 @@ discard block |
||
2844 | 2844 | ) |
2845 | 2845 | ); |
2846 | 2846 | } |
2847 | - $query_object = $this->_extract_related_models_from_query( $query_params ); |
|
2847 | + $query_object = $this->_extract_related_models_from_query($query_params); |
|
2848 | 2848 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2849 | - foreach ( $where_query_params as $key => $value ) { |
|
2850 | - if ( is_int( $key ) ) { |
|
2849 | + foreach ($where_query_params as $key => $value) { |
|
2850 | + if (is_int($key)) { |
|
2851 | 2851 | throw new EE_Error( |
2852 | 2852 | sprintf( |
2853 | 2853 | __( |
@@ -2855,16 +2855,16 @@ discard block |
||
2855 | 2855 | "event_espresso" |
2856 | 2856 | ), |
2857 | 2857 | $key, |
2858 | - var_export( $value, true ), |
|
2859 | - var_export( $query_params, true ), |
|
2860 | - get_class( $this ) |
|
2858 | + var_export($value, true), |
|
2859 | + var_export($query_params, true), |
|
2860 | + get_class($this) |
|
2861 | 2861 | ) |
2862 | 2862 | ); |
2863 | 2863 | } |
2864 | 2864 | } |
2865 | 2865 | if ( |
2866 | - array_key_exists( 'default_where_conditions', $query_params ) |
|
2867 | - && ! empty( $query_params['default_where_conditions'] ) |
|
2866 | + array_key_exists('default_where_conditions', $query_params) |
|
2867 | + && ! empty($query_params['default_where_conditions']) |
|
2868 | 2868 | ) { |
2869 | 2869 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2870 | 2870 | } else { |
@@ -2878,13 +2878,13 @@ discard block |
||
2878 | 2878 | ), |
2879 | 2879 | $where_query_params |
2880 | 2880 | ); |
2881 | - $query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) ); |
|
2881 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2882 | 2882 | // if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. |
2883 | 2883 | // So we need to setup a subquery and use that for the main join. |
2884 | 2884 | // Note for now this only works on the primary table for the model. |
2885 | 2885 | // So for instance, you could set the limit array like this: |
2886 | 2886 | // array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2887 | - if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) { |
|
2887 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2888 | 2888 | $query_object->set_main_model_join_sql( |
2889 | 2889 | $this->_construct_limit_join_select( |
2890 | 2890 | $query_params['on_join_limit'][0], |
@@ -2893,40 +2893,40 @@ discard block |
||
2893 | 2893 | ); |
2894 | 2894 | } |
2895 | 2895 | //set limit |
2896 | - if ( array_key_exists( 'limit', $query_params ) ) { |
|
2897 | - if ( is_array( $query_params['limit'] ) ) { |
|
2898 | - if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) { |
|
2896 | + if (array_key_exists('limit', $query_params)) { |
|
2897 | + if (is_array($query_params['limit'])) { |
|
2898 | + if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) { |
|
2899 | 2899 | $e = sprintf( |
2900 | 2900 | __( |
2901 | 2901 | "Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", |
2902 | 2902 | "event_espresso" |
2903 | 2903 | ), |
2904 | - http_build_query( $query_params['limit'] ) |
|
2904 | + http_build_query($query_params['limit']) |
|
2905 | 2905 | ); |
2906 | - throw new EE_Error( $e . "|" . $e ); |
|
2906 | + throw new EE_Error($e."|".$e); |
|
2907 | 2907 | } |
2908 | 2908 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2909 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] ); |
|
2910 | - } elseif ( ! empty ( $query_params['limit'] ) ) { |
|
2911 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'] ); |
|
2909 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
|
2910 | + } elseif ( ! empty ($query_params['limit'])) { |
|
2911 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit']); |
|
2912 | 2912 | } |
2913 | 2913 | } |
2914 | 2914 | //set order by |
2915 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2916 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2915 | + if (array_key_exists('order_by', $query_params)) { |
|
2916 | + if (is_array($query_params['order_by'])) { |
|
2917 | 2917 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2918 | 2918 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2919 | 2919 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2920 | - if ( array_key_exists( 'order', $query_params ) ) { |
|
2920 | + if (array_key_exists('order', $query_params)) { |
|
2921 | 2921 | throw new EE_Error( |
2922 | 2922 | sprintf( |
2923 | 2923 | __( |
2924 | 2924 | "In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", |
2925 | 2925 | "event_espresso" |
2926 | 2926 | ), |
2927 | - get_class( $this ), |
|
2928 | - implode( ", ", array_keys( $query_params['order_by'] ) ), |
|
2929 | - implode( ", ", $query_params['order_by'] ), |
|
2927 | + get_class($this), |
|
2928 | + implode(", ", array_keys($query_params['order_by'])), |
|
2929 | + implode(", ", $query_params['order_by']), |
|
2930 | 2930 | $query_params['order'] |
2931 | 2931 | ) |
2932 | 2932 | ); |
@@ -2938,57 +2938,57 @@ discard block |
||
2938 | 2938 | ); |
2939 | 2939 | //assume it's an array of fields to order by |
2940 | 2940 | $order_array = array(); |
2941 | - foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) { |
|
2942 | - $order = $this->_extract_order( $order ); |
|
2943 | - $order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order; |
|
2941 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2942 | + $order = $this->_extract_order($order); |
|
2943 | + $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
|
2944 | 2944 | } |
2945 | - $query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) ); |
|
2946 | - } elseif ( ! empty ( $query_params['order_by'] ) ) { |
|
2945 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2946 | + } elseif ( ! empty ($query_params['order_by'])) { |
|
2947 | 2947 | $this->_extract_related_model_info_from_query_param( |
2948 | 2948 | $query_params['order_by'], |
2949 | 2949 | $query_object, |
2950 | 2950 | 'order', |
2951 | 2951 | $query_params['order_by'] |
2952 | 2952 | ); |
2953 | - $order = isset( $query_params['order'] ) |
|
2954 | - ? $this->_extract_order( $query_params['order'] ) |
|
2953 | + $order = isset($query_params['order']) |
|
2954 | + ? $this->_extract_order($query_params['order']) |
|
2955 | 2955 | : 'DESC'; |
2956 | 2956 | $query_object->set_order_by_sql( |
2957 | - " ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order |
|
2957 | + " ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order |
|
2958 | 2958 | ); |
2959 | 2959 | } |
2960 | 2960 | } |
2961 | 2961 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2962 | - if ( ! array_key_exists( 'order_by', $query_params ) |
|
2963 | - && array_key_exists( 'order', $query_params ) |
|
2964 | - && ! empty( $query_params['order'] ) |
|
2962 | + if ( ! array_key_exists('order_by', $query_params) |
|
2963 | + && array_key_exists('order', $query_params) |
|
2964 | + && ! empty($query_params['order']) |
|
2965 | 2965 | ) { |
2966 | 2966 | $pk_field = $this->get_primary_key_field(); |
2967 | - $order = $this->_extract_order( $query_params['order'] ); |
|
2968 | - $query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order ); |
|
2967 | + $order = $this->_extract_order($query_params['order']); |
|
2968 | + $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
|
2969 | 2969 | } |
2970 | 2970 | //set group by |
2971 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2972 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2971 | + if (array_key_exists('group_by', $query_params)) { |
|
2972 | + if (is_array($query_params['group_by'])) { |
|
2973 | 2973 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2974 | 2974 | $group_by_array = array(); |
2975 | - foreach ( $query_params['group_by'] as $field_name_to_group_by ) { |
|
2976 | - $group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by ); |
|
2975 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2976 | + $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
|
2977 | 2977 | } |
2978 | - $query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) ); |
|
2979 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2978 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2979 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2980 | 2980 | $query_object->set_group_by_sql( |
2981 | - " GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] ) |
|
2981 | + " GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']) |
|
2982 | 2982 | ); |
2983 | 2983 | } |
2984 | 2984 | } |
2985 | 2985 | //set having |
2986 | - if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) { |
|
2987 | - $query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) ); |
|
2986 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2987 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2988 | 2988 | } |
2989 | 2989 | //now, just verify they didn't pass anything wack |
2990 | - foreach ( $query_params as $query_key => $query_value ) { |
|
2991 | - if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) { |
|
2990 | + foreach ($query_params as $query_key => $query_value) { |
|
2991 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2992 | 2992 | throw new EE_Error( |
2993 | 2993 | sprintf( |
2994 | 2994 | __( |
@@ -2996,16 +2996,16 @@ discard block |
||
2996 | 2996 | 'event_espresso' |
2997 | 2997 | ), |
2998 | 2998 | $query_key, |
2999 | - get_class( $this ), |
|
2999 | + get_class($this), |
|
3000 | 3000 | // print_r( $this->_allowed_query_params, TRUE ) |
3001 | - implode( ',', $this->_allowed_query_params ) |
|
3001 | + implode(',', $this->_allowed_query_params) |
|
3002 | 3002 | ) |
3003 | 3003 | ); |
3004 | 3004 | } |
3005 | 3005 | } |
3006 | 3006 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
3007 | - if ( empty( $main_model_join_sql ) ) { |
|
3008 | - $query_object->set_main_model_join_sql( $this->_construct_internal_join() ); |
|
3007 | + if (empty($main_model_join_sql)) { |
|
3008 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
3009 | 3009 | } |
3010 | 3010 | return $query_object; |
3011 | 3011 | } |
@@ -3020,17 +3020,17 @@ discard block |
||
3020 | 3020 | * @return array like EEM_Base::get_all() 's $query_params[0] |
3021 | 3021 | * @throws \EE_Error |
3022 | 3022 | */ |
3023 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
3024 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
3023 | + public function caps_where_conditions($context = self::caps_read) { |
|
3024 | + EEM_Base::verify_is_valid_cap_context($context); |
|
3025 | 3025 | $cap_where_conditions = array(); |
3026 | - $cap_restrictions = $this->caps_missing( $context ); |
|
3026 | + $cap_restrictions = $this->caps_missing($context); |
|
3027 | 3027 | /** |
3028 | 3028 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
3029 | 3029 | */ |
3030 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
3031 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
3030 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
3031 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
3032 | 3032 | } |
3033 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
3033 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
3034 | 3034 | } |
3035 | 3035 | |
3036 | 3036 | /** |
@@ -3040,11 +3040,11 @@ discard block |
||
3040 | 3040 | * @return string either ASC, asc, DESC or desc |
3041 | 3041 | * @throws EE_Error |
3042 | 3042 | */ |
3043 | - private function _extract_order($should_be_order_string){ |
|
3044 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
3043 | + private function _extract_order($should_be_order_string) { |
|
3044 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
3045 | 3045 | return $should_be_order_string; |
3046 | - }else{ |
|
3047 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
3046 | + } else { |
|
3047 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
3048 | 3048 | } |
3049 | 3049 | } |
3050 | 3050 | |
@@ -3062,7 +3062,7 @@ discard block |
||
3062 | 3062 | * @throws EE_Error |
3063 | 3063 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
3064 | 3064 | */ |
3065 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
3065 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
3066 | 3066 | $allowed_used_default_where_conditions_values = array( |
3067 | 3067 | 'all', |
3068 | 3068 | 'this_model_only', |
@@ -3070,17 +3070,17 @@ discard block |
||
3070 | 3070 | 'minimum', |
3071 | 3071 | 'none' |
3072 | 3072 | ); |
3073 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
3074 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
3073 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
3074 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
3075 | 3075 | } |
3076 | 3076 | $universal_query_params = array(); |
3077 | - if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){ |
|
3077 | + if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') { |
|
3078 | 3078 | $universal_query_params = $this->_get_default_where_conditions(); |
3079 | - } else if( $use_default_where_conditions === 'minimum' ) { |
|
3079 | + } else if ($use_default_where_conditions === 'minimum') { |
|
3080 | 3080 | $universal_query_params = $this->_get_minimum_where_conditions(); |
3081 | 3081 | } |
3082 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
3083 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
3082 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
3083 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
3084 | 3084 | $related_model = $this->get_related_model_obj($model_name); |
3085 | 3085 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
3086 | 3086 | $overrides = $this->_override_defaults_or_make_null_friendly( |
@@ -3113,20 +3113,20 @@ discard block |
||
3113 | 3113 | * @return array like EEM_Base::get_all's $query_params[0] |
3114 | 3114 | * @throws \EE_Error |
3115 | 3115 | */ |
3116 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
3116 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
3117 | 3117 | $null_friendly_where_conditions = array(); |
3118 | 3118 | $none_overridden = true; |
3119 | 3119 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
3120 | 3120 | |
3121 | - foreach($default_where_conditions as $key => $val){ |
|
3122 | - if( isset($provided_where_conditions[$key])){ |
|
3121 | + foreach ($default_where_conditions as $key => $val) { |
|
3122 | + if (isset($provided_where_conditions[$key])) { |
|
3123 | 3123 | $none_overridden = false; |
3124 | - }else{ |
|
3124 | + } else { |
|
3125 | 3125 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3126 | 3126 | } |
3127 | 3127 | } |
3128 | - if( $none_overridden && $default_where_conditions){ |
|
3129 | - if($model->has_primary_key_field()){ |
|
3128 | + if ($none_overridden && $default_where_conditions) { |
|
3129 | + if ($model->has_primary_key_field()) { |
|
3130 | 3130 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
3131 | 3131 | }/*else{ |
3132 | 3132 | //@todo NO PK, use other defaults |
@@ -3143,8 +3143,8 @@ discard block |
||
3143 | 3143 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3144 | 3144 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3145 | 3145 | */ |
3146 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
3147 | - if ( $this->_ignore_where_strategy ){ |
|
3146 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
3147 | + if ($this->_ignore_where_strategy) { |
|
3148 | 3148 | return array(); |
3149 | 3149 | } |
3150 | 3150 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3158,8 +3158,8 @@ discard block |
||
3158 | 3158 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3159 | 3159 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3160 | 3160 | */ |
3161 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
3162 | - if ( $this->_ignore_where_strategy ){ |
|
3161 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
3162 | + if ($this->_ignore_where_strategy) { |
|
3163 | 3163 | return array(); |
3164 | 3164 | } |
3165 | 3165 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3175,16 +3175,16 @@ discard block |
||
3175 | 3175 | * @return string |
3176 | 3176 | * @throws \EE_Error |
3177 | 3177 | */ |
3178 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
3178 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
3179 | 3179 | $selects = $this->_get_columns_to_select_for_this_model(); |
3180 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
3180 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
3181 | 3181 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
3182 | - $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain ); |
|
3183 | - foreach ( $other_model_selects as $key => $value ) { |
|
3182 | + $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain); |
|
3183 | + foreach ($other_model_selects as $key => $value) { |
|
3184 | 3184 | $selects[] = $value; |
3185 | 3185 | } |
3186 | 3186 | } |
3187 | - return implode(", ",$selects); |
|
3187 | + return implode(", ", $selects); |
|
3188 | 3188 | } |
3189 | 3189 | |
3190 | 3190 | /** |
@@ -3193,19 +3193,19 @@ discard block |
||
3193 | 3193 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
3194 | 3194 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
3195 | 3195 | */ |
3196 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
3196 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
3197 | 3197 | $fields = $this->field_settings(); |
3198 | 3198 | $selects = array(); |
3199 | 3199 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
3200 | - foreach($fields as $field_obj){ |
|
3201 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
3200 | + foreach ($fields as $field_obj) { |
|
3201 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
3202 | 3202 | } |
3203 | 3203 | //make sure we are also getting the PKs of each table |
3204 | 3204 | $tables = $this->get_tables(); |
3205 | - if(count($tables) > 1){ |
|
3206 | - foreach($tables as $table_obj){ |
|
3207 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
3208 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
3205 | + if (count($tables) > 1) { |
|
3206 | + foreach ($tables as $table_obj) { |
|
3207 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
3208 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
3209 | 3209 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
3210 | 3210 | } |
3211 | 3211 | } |
@@ -3235,65 +3235,65 @@ discard block |
||
3235 | 3235 | $query_param_type, |
3236 | 3236 | $original_query_param = null |
3237 | 3237 | ) { |
3238 | - if( $original_query_param === null ){ |
|
3238 | + if ($original_query_param === null) { |
|
3239 | 3239 | $original_query_param = $query_param; |
3240 | 3240 | } |
3241 | 3241 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3242 | 3242 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3243 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3244 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3243 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3244 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3245 | 3245 | //check to see if we have a field on this model |
3246 | 3246 | $this_model_fields = $this->field_settings(true); |
3247 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3248 | - if($allow_fields){ |
|
3247 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3248 | + if ($allow_fields) { |
|
3249 | 3249 | return; |
3250 | - }else{ |
|
3250 | + } else { |
|
3251 | 3251 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
3252 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3252 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3253 | 3253 | } |
3254 | 3254 | } |
3255 | 3255 | //check if this is a special logic query param |
3256 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3257 | - if($allow_logic_query_params){ |
|
3256 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3257 | + if ($allow_logic_query_params) { |
|
3258 | 3258 | return; |
3259 | - }else{ |
|
3259 | + } else { |
|
3260 | 3260 | throw new EE_Error( |
3261 | 3261 | sprintf( |
3262 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
3263 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3264 | - $query_param , |
|
3265 | - get_class( $this ), |
|
3262 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
3263 | + implode('", "', $this->_logic_query_param_keys), |
|
3264 | + $query_param, |
|
3265 | + get_class($this), |
|
3266 | 3266 | '<br />', |
3267 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
3267 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
3268 | 3268 | ) |
3269 | 3269 | ); |
3270 | 3270 | } |
3271 | 3271 | } |
3272 | 3272 | |
3273 | 3273 | //check if it's a custom selection |
3274 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3274 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3275 | 3275 | return; |
3276 | 3276 | } |
3277 | 3277 | |
3278 | 3278 | //check if has a model name at the beginning |
3279 | 3279 | //and |
3280 | 3280 | //check if it's a field on a related model |
3281 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3282 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3283 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3281 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3282 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3283 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3284 | 3284 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3285 | - if($query_param === ''){ |
|
3285 | + if ($query_param === '') { |
|
3286 | 3286 | //nothing left to $query_param |
3287 | 3287 | //we should actually end in a field name, not a model like this! |
3288 | 3288 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3289 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3290 | - }else{ |
|
3289 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3290 | + } else { |
|
3291 | 3291 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3292 | 3292 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3293 | 3293 | return; |
3294 | 3294 | } |
3295 | - }elseif($query_param === $valid_related_model_name){ |
|
3296 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3295 | + }elseif ($query_param === $valid_related_model_name) { |
|
3296 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3297 | 3297 | return; |
3298 | 3298 | } |
3299 | 3299 | } |
@@ -3303,7 +3303,7 @@ discard block |
||
3303 | 3303 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3304 | 3304 | //it's wack, that's what it is |
3305 | 3305 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
3306 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3306 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3307 | 3307 | |
3308 | 3308 | } |
3309 | 3309 | |
@@ -3322,26 +3322,26 @@ discard block |
||
3322 | 3322 | * @return void |
3323 | 3323 | * @throws \EE_Error |
3324 | 3324 | */ |
3325 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3325 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3326 | 3326 | $relation_obj = $this->related_settings_for($model_name); |
3327 | 3327 | |
3328 | 3328 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3329 | 3329 | //check if the relation is HABTM, because then we're essentially doing two joins |
3330 | 3330 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3331 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3331 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3332 | 3332 | $join_model_obj = $relation_obj->get_join_model(); |
3333 | 3333 | //replace the model specified with the join model for this relation chain, whi |
3334 | 3334 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
3335 | 3335 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3336 | 3336 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3337 | 3337 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3338 | - $passed_in_query_info->merge( $new_query_info ); |
|
3338 | + $passed_in_query_info->merge($new_query_info); |
|
3339 | 3339 | } |
3340 | 3340 | //now just join to the other table pointed to by the relation object, and add its data types |
3341 | 3341 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3342 | 3342 | array($model_relation_chain=>$model_name), |
3343 | 3343 | $relation_obj->get_join_statement($model_relation_chain)); |
3344 | - $passed_in_query_info->merge( $new_query_info ); |
|
3344 | + $passed_in_query_info->merge($new_query_info); |
|
3345 | 3345 | } |
3346 | 3346 | |
3347 | 3347 | |
@@ -3353,11 +3353,11 @@ discard block |
||
3353 | 3353 | * @return string of SQL |
3354 | 3354 | * @throws \EE_Error |
3355 | 3355 | */ |
3356 | - private function _construct_where_clause($where_params){ |
|
3356 | + private function _construct_where_clause($where_params) { |
|
3357 | 3357 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3358 | - if($SQL){ |
|
3359 | - return " WHERE ". $SQL; |
|
3360 | - }else{ |
|
3358 | + if ($SQL) { |
|
3359 | + return " WHERE ".$SQL; |
|
3360 | + } else { |
|
3361 | 3361 | return ''; |
3362 | 3362 | } |
3363 | 3363 | } |
@@ -3372,11 +3372,11 @@ discard block |
||
3372 | 3372 | * @return string |
3373 | 3373 | * @throws \EE_Error |
3374 | 3374 | */ |
3375 | - private function _construct_having_clause($having_params){ |
|
3375 | + private function _construct_having_clause($having_params) { |
|
3376 | 3376 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3377 | - if($SQL){ |
|
3378 | - return " HAVING ". $SQL; |
|
3379 | - }else{ |
|
3377 | + if ($SQL) { |
|
3378 | + return " HAVING ".$SQL; |
|
3379 | + } else { |
|
3380 | 3380 | return ''; |
3381 | 3381 | } |
3382 | 3382 | |
@@ -3390,16 +3390,16 @@ discard block |
||
3390 | 3390 | * @return EE_Model_Field_Base |
3391 | 3391 | * @throws EE_Error |
3392 | 3392 | */ |
3393 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3393 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3394 | 3394 | $model_class = 'EEM_'.$model_name; |
3395 | 3395 | $model_filepath = $model_class.".model.php"; |
3396 | - if ( is_readable($model_filepath)){ |
|
3396 | + if (is_readable($model_filepath)) { |
|
3397 | 3397 | require_once($model_filepath); |
3398 | - $model_instance=call_user_func($model_name."::instance"); |
|
3398 | + $model_instance = call_user_func($model_name."::instance"); |
|
3399 | 3399 | /* @var $model_instance EEM_Base */ |
3400 | 3400 | return $model_instance->field_settings_for($field_name); |
3401 | - }else{ |
|
3402 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3401 | + } else { |
|
3402 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3403 | 3403 | } |
3404 | 3404 | } |
3405 | 3405 | |
@@ -3412,41 +3412,41 @@ discard block |
||
3412 | 3412 | * @throws EE_Error |
3413 | 3413 | * @return string of SQL |
3414 | 3414 | */ |
3415 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3416 | - $where_clauses=array(); |
|
3417 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3418 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3419 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3420 | - switch($query_param){ |
|
3415 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3416 | + $where_clauses = array(); |
|
3417 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3418 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3419 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3420 | + switch ($query_param) { |
|
3421 | 3421 | case 'not': |
3422 | 3422 | case 'NOT': |
3423 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3423 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3424 | 3424 | break; |
3425 | 3425 | case 'and': |
3426 | 3426 | case 'AND': |
3427 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3427 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3428 | 3428 | break; |
3429 | 3429 | case 'or': |
3430 | 3430 | case 'OR': |
3431 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3431 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3432 | 3432 | break; |
3433 | 3433 | } |
3434 | - }else{ |
|
3434 | + } else { |
|
3435 | 3435 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3436 | 3436 | |
3437 | 3437 | //if it's not a normal field, maybe it's a custom selection? |
3438 | - if( ! $field_obj){ |
|
3439 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3438 | + if ( ! $field_obj) { |
|
3439 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3440 | 3440 | $field_obj = $this->_custom_selections[$query_param][1]; |
3441 | - }else{ |
|
3442 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3441 | + } else { |
|
3442 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3443 | 3443 | } |
3444 | 3444 | } |
3445 | 3445 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3446 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3446 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3447 | 3447 | } |
3448 | 3448 | } |
3449 | - return $where_clauses ? implode( $glue, $where_clauses ) : ''; |
|
3449 | + return $where_clauses ? implode($glue, $where_clauses) : ''; |
|
3450 | 3450 | } |
3451 | 3451 | |
3452 | 3452 | |
@@ -3457,18 +3457,18 @@ discard block |
||
3457 | 3457 | * @throws EE_Error |
3458 | 3458 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3459 | 3459 | */ |
3460 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3460 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3461 | 3461 | $field = $this->_deduce_field_from_query_param($query_param); |
3462 | 3462 | |
3463 | - if( $field ){ |
|
3464 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3465 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3466 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3463 | + if ($field) { |
|
3464 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3465 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3466 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3467 | 3467 | //maybe it's custom selection item? |
3468 | 3468 | //if so, just use it as the "column name" |
3469 | 3469 | return $query_param; |
3470 | - }else{ |
|
3471 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
3470 | + } else { |
|
3471 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
3472 | 3472 | } |
3473 | 3473 | } |
3474 | 3474 | |
@@ -3480,11 +3480,11 @@ discard block |
||
3480 | 3480 | * @param string $condition_query_param_key |
3481 | 3481 | * @return string |
3482 | 3482 | */ |
3483 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3483 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3484 | 3484 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3485 | - if($pos_of_star === FALSE){ |
|
3485 | + if ($pos_of_star === FALSE) { |
|
3486 | 3486 | return $condition_query_param_key; |
3487 | - }else{ |
|
3487 | + } else { |
|
3488 | 3488 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3489 | 3489 | return $condition_query_param_sans_star; |
3490 | 3490 | } |
@@ -3499,12 +3499,12 @@ discard block |
||
3499 | 3499 | * @throws EE_Error |
3500 | 3500 | * @return string |
3501 | 3501 | */ |
3502 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3503 | - if ( is_array( $op_and_value ) ) { |
|
3504 | - $operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null; |
|
3505 | - if ( ! $operator ) { |
|
3502 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3503 | + if (is_array($op_and_value)) { |
|
3504 | + $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
|
3505 | + if ( ! $operator) { |
|
3506 | 3506 | $php_array_like_string = array(); |
3507 | - foreach ( $op_and_value as $key => $value ) { |
|
3507 | + foreach ($op_and_value as $key => $value) { |
|
3508 | 3508 | $php_array_like_string[] = "$key=>$value"; |
3509 | 3509 | } |
3510 | 3510 | throw new EE_Error( |
@@ -3513,27 +3513,27 @@ discard block |
||
3513 | 3513 | "You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", |
3514 | 3514 | "event_espresso" |
3515 | 3515 | ), |
3516 | - implode( ",", $php_array_like_string ) |
|
3516 | + implode(",", $php_array_like_string) |
|
3517 | 3517 | ) |
3518 | 3518 | ); |
3519 | 3519 | } |
3520 | - $value = isset( $op_and_value[1] ) ? $op_and_value[1] : null; |
|
3520 | + $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
|
3521 | 3521 | } else { |
3522 | 3522 | $operator = '='; |
3523 | 3523 | $value = $op_and_value; |
3524 | 3524 | } |
3525 | 3525 | //check to see if the value is actually another field |
3526 | - if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) { |
|
3527 | - return $operator . SP . $this->_deduce_column_name_from_query_param( $value ); |
|
3528 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3526 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3527 | + return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
|
3528 | + } elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3529 | 3529 | //in this case, the value should be an array, or at least a comma-separated list |
3530 | 3530 | //it will need to handle a little differently |
3531 | - $cleaned_value = $this->_construct_in_value( $value, $field_obj ); |
|
3531 | + $cleaned_value = $this->_construct_in_value($value, $field_obj); |
|
3532 | 3532 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3533 | - return $operator . SP . $cleaned_value; |
|
3534 | - } elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3533 | + return $operator.SP.$cleaned_value; |
|
3534 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3535 | 3535 | //the value should be an array with count of two. |
3536 | - if ( count( $value ) !== 2 ) { |
|
3536 | + if (count($value) !== 2) { |
|
3537 | 3537 | throw new EE_Error( |
3538 | 3538 | sprintf( |
3539 | 3539 | __( |
@@ -3544,10 +3544,10 @@ discard block |
||
3544 | 3544 | ) |
3545 | 3545 | ); |
3546 | 3546 | } |
3547 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3548 | - return $operator . SP . $cleaned_value; |
|
3549 | - } elseif ( in_array( $operator, $this->_null_style_operators ) ) { |
|
3550 | - if ( $value !== null ) { |
|
3547 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3548 | + return $operator.SP.$cleaned_value; |
|
3549 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3550 | + if ($value !== null) { |
|
3551 | 3551 | throw new EE_Error( |
3552 | 3552 | sprintf( |
3553 | 3553 | __( |
@@ -3560,13 +3560,13 @@ discard block |
||
3560 | 3560 | ); |
3561 | 3561 | } |
3562 | 3562 | return $operator; |
3563 | - } elseif ( $operator === 'LIKE' && ! is_array( $value ) ) { |
|
3563 | + } elseif ($operator === 'LIKE' && ! is_array($value)) { |
|
3564 | 3564 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3565 | 3565 | //remove other junk. So just treat it as a string. |
3566 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' ); |
|
3567 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3568 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj ); |
|
3569 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3566 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
|
3567 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3568 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3569 | + } elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3570 | 3570 | throw new EE_Error( |
3571 | 3571 | sprintf( |
3572 | 3572 | __( |
@@ -3577,7 +3577,7 @@ discard block |
||
3577 | 3577 | $operator |
3578 | 3578 | ) |
3579 | 3579 | ); |
3580 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3580 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3581 | 3581 | throw new EE_Error( |
3582 | 3582 | sprintf( |
3583 | 3583 | __( |
@@ -3595,7 +3595,7 @@ discard block |
||
3595 | 3595 | "It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", |
3596 | 3596 | "event_espresso" |
3597 | 3597 | ), |
3598 | - http_build_query( $op_and_value ) |
|
3598 | + http_build_query($op_and_value) |
|
3599 | 3599 | ) |
3600 | 3600 | ); |
3601 | 3601 | } |
@@ -3611,12 +3611,12 @@ discard block |
||
3611 | 3611 | * @return string |
3612 | 3612 | * @throws \EE_Error |
3613 | 3613 | */ |
3614 | - public function _construct_between_value( $values, $field_obj ) { |
|
3614 | + public function _construct_between_value($values, $field_obj) { |
|
3615 | 3615 | $cleaned_values = array(); |
3616 | - foreach ( $values as $value ) { |
|
3617 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3616 | + foreach ($values as $value) { |
|
3617 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3618 | 3618 | } |
3619 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3619 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3620 | 3620 | } |
3621 | 3621 | |
3622 | 3622 | |
@@ -3633,26 +3633,26 @@ discard block |
||
3633 | 3633 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3634 | 3634 | * @throws \EE_Error |
3635 | 3635 | */ |
3636 | - public function _construct_in_value($values, $field_obj){ |
|
3636 | + public function _construct_in_value($values, $field_obj) { |
|
3637 | 3637 | //check if the value is a CSV list |
3638 | - if(is_string($values)){ |
|
3638 | + if (is_string($values)) { |
|
3639 | 3639 | //in which case, turn it into an array |
3640 | - $values = explode(",",$values); |
|
3640 | + $values = explode(",", $values); |
|
3641 | 3641 | } |
3642 | 3642 | $cleaned_values = array(); |
3643 | - foreach($values as $value){ |
|
3644 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3643 | + foreach ($values as $value) { |
|
3644 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3645 | 3645 | } |
3646 | 3646 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3647 | 3647 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3648 | 3648 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3649 | - if(empty($cleaned_values)){ |
|
3649 | + if (empty($cleaned_values)) { |
|
3650 | 3650 | $all_fields = $this->field_settings(); |
3651 | 3651 | $a_field = array_shift($all_fields); |
3652 | 3652 | $main_table = $this->_get_main_table(); |
3653 | 3653 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3654 | 3654 | } |
3655 | - return "(".implode(",",$cleaned_values).")"; |
|
3655 | + return "(".implode(",", $cleaned_values).")"; |
|
3656 | 3656 | } |
3657 | 3657 | |
3658 | 3658 | |
@@ -3664,16 +3664,16 @@ discard block |
||
3664 | 3664 | * @throws EE_Error |
3665 | 3665 | * @return false|null|string |
3666 | 3666 | */ |
3667 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3667 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3668 | 3668 | /** @type WPDB $wpdb */ |
3669 | 3669 | global $wpdb; |
3670 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3671 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3672 | - }else{//$field_obj should really just be a data type |
|
3673 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3674 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3670 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3671 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3672 | + } else {//$field_obj should really just be a data type |
|
3673 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3674 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3675 | 3675 | } |
3676 | - return $wpdb->prepare($field_obj,$value); |
|
3676 | + return $wpdb->prepare($field_obj, $value); |
|
3677 | 3677 | } |
3678 | 3678 | } |
3679 | 3679 | |
@@ -3685,27 +3685,27 @@ discard block |
||
3685 | 3685 | * @throws EE_Error |
3686 | 3686 | * @return EE_Model_Field_Base |
3687 | 3687 | */ |
3688 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3688 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3689 | 3689 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3690 | 3690 | //which will help us find the database table and column |
3691 | 3691 | |
3692 | - $query_param_parts = explode(".",$query_param_name); |
|
3693 | - if(empty($query_param_parts)){ |
|
3694 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3692 | + $query_param_parts = explode(".", $query_param_name); |
|
3693 | + if (empty($query_param_parts)) { |
|
3694 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3695 | 3695 | } |
3696 | 3696 | $number_of_parts = count($query_param_parts); |
3697 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3698 | - if($number_of_parts === 1){ |
|
3697 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3698 | + if ($number_of_parts === 1) { |
|
3699 | 3699 | $field_name = $last_query_param_part; |
3700 | 3700 | $model_obj = $this; |
3701 | - }else{// $number_of_parts >= 2 |
|
3701 | + } else {// $number_of_parts >= 2 |
|
3702 | 3702 | //the last part is the column name, and there are only 2parts. therefore... |
3703 | 3703 | $field_name = $last_query_param_part; |
3704 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3704 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3705 | 3705 | } |
3706 | - try{ |
|
3706 | + try { |
|
3707 | 3707 | return $model_obj->field_settings_for($field_name); |
3708 | - }catch(EE_Error $e){ |
|
3708 | + } catch (EE_Error $e) { |
|
3709 | 3709 | return null; |
3710 | 3710 | } |
3711 | 3711 | } |
@@ -3719,13 +3719,13 @@ discard block |
||
3719 | 3719 | * @throws EE_Error |
3720 | 3720 | * @return string |
3721 | 3721 | */ |
3722 | - public function _get_qualified_column_for_field($field_name){ |
|
3722 | + public function _get_qualified_column_for_field($field_name) { |
|
3723 | 3723 | $all_fields = $this->field_settings(); |
3724 | 3724 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3725 | - if($field){ |
|
3725 | + if ($field) { |
|
3726 | 3726 | return $field->get_qualified_column(); |
3727 | - }else{ |
|
3728 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3727 | + } else { |
|
3728 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3729 | 3729 | } |
3730 | 3730 | } |
3731 | 3731 | |
@@ -3739,17 +3739,17 @@ discard block |
||
3739 | 3739 | * @param mixed|string $limit The limit for this select |
3740 | 3740 | * @return string The final select join element for the query. |
3741 | 3741 | */ |
3742 | - public function _construct_limit_join_select( $table_alias, $limit ) { |
|
3742 | + public function _construct_limit_join_select($table_alias, $limit) { |
|
3743 | 3743 | $SQL = ''; |
3744 | - foreach ( $this->_tables as $table_obj ) { |
|
3745 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3744 | + foreach ($this->_tables as $table_obj) { |
|
3745 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3746 | 3746 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3747 | - ? $table_obj->get_select_join_limit( $limit ) |
|
3748 | - : SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP; |
|
3749 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3747 | + ? $table_obj->get_select_join_limit($limit) |
|
3748 | + : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3749 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3750 | 3750 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3751 | - ? $table_obj->get_select_join_limit_join( $limit ) |
|
3752 | - : SP . $table_obj->get_join_sql( $table_alias ) . SP; |
|
3751 | + ? $table_obj->get_select_join_limit_join($limit) |
|
3752 | + : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3753 | 3753 | } |
3754 | 3754 | } |
3755 | 3755 | return $SQL; |
@@ -3764,7 +3764,7 @@ discard block |
||
3764 | 3764 | * @return string SQL |
3765 | 3765 | * @throws \EE_Error |
3766 | 3766 | */ |
3767 | - public function _construct_internal_join(){ |
|
3767 | + public function _construct_internal_join() { |
|
3768 | 3768 | $SQL = $this->_get_main_table()->get_table_sql(); |
3769 | 3769 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3770 | 3770 | return $SQL; |
@@ -3785,17 +3785,17 @@ discard block |
||
3785 | 3785 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3786 | 3786 | * @return string |
3787 | 3787 | */ |
3788 | - public function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3788 | + public function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3789 | 3789 | $SQL = ''; |
3790 | 3790 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3791 | - foreach($this->_tables as $table_obj){ |
|
3792 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3793 | - if($alias_sans_prefix === $table_obj->get_table_alias()){ |
|
3791 | + foreach ($this->_tables as $table_obj) { |
|
3792 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3793 | + if ($alias_sans_prefix === $table_obj->get_table_alias()) { |
|
3794 | 3794 | //so we're joining to this table, meaning the table is already in |
3795 | 3795 | //the FROM statement, BUT the primary table isn't. So we want |
3796 | 3796 | //to add the inverse join sql |
3797 | 3797 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3798 | - }else{ |
|
3798 | + } else { |
|
3799 | 3799 | //just add a regular JOIN to this table from the primary table |
3800 | 3800 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3801 | 3801 | } |
@@ -3809,9 +3809,9 @@ discard block |
||
3809 | 3809 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3810 | 3810 | * @return array |
3811 | 3811 | */ |
3812 | - public function _get_data_types(){ |
|
3812 | + public function _get_data_types() { |
|
3813 | 3813 | $data_types = array(); |
3814 | - foreach( $this->field_settings() as $field_obj){ |
|
3814 | + foreach ($this->field_settings() as $field_obj) { |
|
3815 | 3815 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3816 | 3816 | /** @var $field_obj EE_Model_Field_Base */ |
3817 | 3817 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3827,10 +3827,10 @@ discard block |
||
3827 | 3827 | * @throws EE_Error |
3828 | 3828 | * @return EEM_Base |
3829 | 3829 | */ |
3830 | - public function get_related_model_obj($model_name){ |
|
3830 | + public function get_related_model_obj($model_name) { |
|
3831 | 3831 | $model_classname = "EEM_".$model_name; |
3832 | - if(!class_exists($model_classname)){ |
|
3833 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3832 | + if ( ! class_exists($model_classname)) { |
|
3833 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3834 | 3834 | } |
3835 | 3835 | return call_user_func($model_classname."::instance"); |
3836 | 3836 | } |
@@ -3840,7 +3840,7 @@ discard block |
||
3840 | 3840 | * Returns the array of EE_ModelRelations for this model. |
3841 | 3841 | * @return EE_Model_Relation_Base[] |
3842 | 3842 | */ |
3843 | - public function relation_settings(){ |
|
3843 | + public function relation_settings() { |
|
3844 | 3844 | return $this->_model_relations; |
3845 | 3845 | } |
3846 | 3846 | |
@@ -3850,10 +3850,10 @@ discard block |
||
3850 | 3850 | * (Eg, without an event, datetimes have little purpose.) |
3851 | 3851 | * @return EE_Belongs_To_Relation[] |
3852 | 3852 | */ |
3853 | - public function belongs_to_relations(){ |
|
3853 | + public function belongs_to_relations() { |
|
3854 | 3854 | $belongs_to_relations = array(); |
3855 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3856 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3855 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3856 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3857 | 3857 | $belongs_to_relations[$model_name] = $relation_obj; |
3858 | 3858 | } |
3859 | 3859 | } |
@@ -3868,15 +3868,15 @@ discard block |
||
3868 | 3868 | * @throws EE_Error |
3869 | 3869 | * @return EE_Model_Relation_Base |
3870 | 3870 | */ |
3871 | - public function related_settings_for($relation_name){ |
|
3872 | - $relatedModels=$this->relation_settings(); |
|
3873 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3871 | + public function related_settings_for($relation_name) { |
|
3872 | + $relatedModels = $this->relation_settings(); |
|
3873 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3874 | 3874 | throw new EE_Error( |
3875 | 3875 | sprintf( |
3876 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3876 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3877 | 3877 | $relation_name, |
3878 | 3878 | $this->_get_class_name(), |
3879 | - implode( ', ', array_keys( $relatedModels )) |
|
3879 | + implode(', ', array_keys($relatedModels)) |
|
3880 | 3880 | ) |
3881 | 3881 | ); |
3882 | 3882 | } |
@@ -3891,10 +3891,10 @@ discard block |
||
3891 | 3891 | * @throws EE_Error |
3892 | 3892 | * @return EE_Model_Field_Base |
3893 | 3893 | */ |
3894 | - public function field_settings_for($fieldName){ |
|
3895 | - $fieldSettings=$this->field_settings(true); |
|
3896 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3897 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3894 | + public function field_settings_for($fieldName) { |
|
3895 | + $fieldSettings = $this->field_settings(true); |
|
3896 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3897 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3898 | 3898 | } |
3899 | 3899 | return $fieldSettings[$fieldName]; |
3900 | 3900 | } |
@@ -3904,11 +3904,11 @@ discard block |
||
3904 | 3904 | * @param string $fieldName a key in the model's _field_settings array |
3905 | 3905 | * @return boolean |
3906 | 3906 | */ |
3907 | - public function has_field($fieldName){ |
|
3907 | + public function has_field($fieldName) { |
|
3908 | 3908 | $fieldSettings = $this->field_settings(true); |
3909 | - if( isset($fieldSettings[$fieldName])){ |
|
3909 | + if (isset($fieldSettings[$fieldName])) { |
|
3910 | 3910 | return true; |
3911 | - }else{ |
|
3911 | + } else { |
|
3912 | 3912 | return false; |
3913 | 3913 | } |
3914 | 3914 | } |
@@ -3918,11 +3918,11 @@ discard block |
||
3918 | 3918 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3919 | 3919 | * @return boolean |
3920 | 3920 | */ |
3921 | - public function has_relation($relation_name){ |
|
3921 | + public function has_relation($relation_name) { |
|
3922 | 3922 | $relations = $this->relation_settings(); |
3923 | - if(isset($relations[$relation_name])){ |
|
3923 | + if (isset($relations[$relation_name])) { |
|
3924 | 3924 | return true; |
3925 | - }else{ |
|
3925 | + } else { |
|
3926 | 3926 | return false; |
3927 | 3927 | } |
3928 | 3928 | } |
@@ -3934,7 +3934,7 @@ discard block |
||
3934 | 3934 | * @param $field_obj |
3935 | 3935 | * @return boolean |
3936 | 3936 | */ |
3937 | - public function is_primary_key_field( $field_obj ){ |
|
3937 | + public function is_primary_key_field($field_obj) { |
|
3938 | 3938 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3939 | 3939 | } |
3940 | 3940 | |
@@ -3946,16 +3946,16 @@ discard block |
||
3946 | 3946 | * @return EE_Model_Field_Base |
3947 | 3947 | * @throws EE_Error |
3948 | 3948 | */ |
3949 | - public function get_primary_key_field(){ |
|
3950 | - if( $this->_primary_key_field === NULL ){ |
|
3951 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3952 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3949 | + public function get_primary_key_field() { |
|
3950 | + if ($this->_primary_key_field === NULL) { |
|
3951 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3952 | + if ($this->is_primary_key_field($field_obj)) { |
|
3953 | 3953 | $this->_primary_key_field = $field_obj; |
3954 | 3954 | break; |
3955 | 3955 | } |
3956 | 3956 | } |
3957 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3958 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3957 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3958 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3959 | 3959 | } |
3960 | 3960 | } |
3961 | 3961 | return $this->_primary_key_field; |
@@ -3968,12 +3968,12 @@ discard block |
||
3968 | 3968 | * Internally does some caching. |
3969 | 3969 | * @return boolean |
3970 | 3970 | */ |
3971 | - public function has_primary_key_field(){ |
|
3972 | - if($this->_has_primary_key_field === null){ |
|
3973 | - try{ |
|
3971 | + public function has_primary_key_field() { |
|
3972 | + if ($this->_has_primary_key_field === null) { |
|
3973 | + try { |
|
3974 | 3974 | $this->get_primary_key_field(); |
3975 | 3975 | $this->_has_primary_key_field = true; |
3976 | - }catch(EE_Error $e){ |
|
3976 | + } catch (EE_Error $e) { |
|
3977 | 3977 | $this->_has_primary_key_field = false; |
3978 | 3978 | } |
3979 | 3979 | } |
@@ -3987,9 +3987,9 @@ discard block |
||
3987 | 3987 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3988 | 3988 | * @return EE_Model_Field_Base or null if none is found |
3989 | 3989 | */ |
3990 | - public function get_a_field_of_type($field_class_name){ |
|
3991 | - foreach($this->field_settings() as $field){ |
|
3992 | - if( $field instanceof $field_class_name ){ |
|
3990 | + public function get_a_field_of_type($field_class_name) { |
|
3991 | + foreach ($this->field_settings() as $field) { |
|
3992 | + if ($field instanceof $field_class_name) { |
|
3993 | 3993 | return $field; |
3994 | 3994 | } |
3995 | 3995 | } |
@@ -4003,22 +4003,22 @@ discard block |
||
4003 | 4003 | * @return EE_Foreign_Key_Field_Base |
4004 | 4004 | * @throws EE_Error |
4005 | 4005 | */ |
4006 | - public function get_foreign_key_to($model_name){ |
|
4007 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
4008 | - foreach($this->field_settings() as $field){ |
|
4009 | - if( |
|
4006 | + public function get_foreign_key_to($model_name) { |
|
4007 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
4008 | + foreach ($this->field_settings() as $field) { |
|
4009 | + if ( |
|
4010 | 4010 | $field instanceof EE_Foreign_Key_Field_Base |
4011 | - && in_array($model_name,$field->get_model_names_pointed_to() ) |
|
4011 | + && in_array($model_name, $field->get_model_names_pointed_to()) |
|
4012 | 4012 | ) { |
4013 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
4013 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
4014 | 4014 | break; |
4015 | 4015 | } |
4016 | 4016 | } |
4017 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
4018 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
4017 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
4018 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
4019 | 4019 | } |
4020 | 4020 | } |
4021 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
4021 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
4022 | 4022 | } |
4023 | 4023 | |
4024 | 4024 | |
@@ -4029,7 +4029,7 @@ discard block |
||
4029 | 4029 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
4030 | 4030 | * @return EE_Table_Base |
4031 | 4031 | */ |
4032 | - public function get_table_for_alias($table_alias){ |
|
4032 | + public function get_table_for_alias($table_alias) { |
|
4033 | 4033 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
4034 | 4034 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
4035 | 4035 | } |
@@ -4042,25 +4042,25 @@ discard block |
||
4042 | 4042 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
4043 | 4043 | * @return EE_Model_Field_Base[] where the keys are the field's name |
4044 | 4044 | */ |
4045 | - public function field_settings($include_db_only_fields = false){ |
|
4046 | - if( $include_db_only_fields ){ |
|
4047 | - if( $this->_cached_fields === NULL ){ |
|
4045 | + public function field_settings($include_db_only_fields = false) { |
|
4046 | + if ($include_db_only_fields) { |
|
4047 | + if ($this->_cached_fields === NULL) { |
|
4048 | 4048 | $this->_cached_fields = array(); |
4049 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4050 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4051 | - $this->_cached_fields[$field_name]=$field_obj; |
|
4049 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4050 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4051 | + $this->_cached_fields[$field_name] = $field_obj; |
|
4052 | 4052 | } |
4053 | 4053 | } |
4054 | 4054 | } |
4055 | 4055 | return $this->_cached_fields; |
4056 | - }else{ |
|
4057 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
4056 | + } else { |
|
4057 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
4058 | 4058 | $this->_cached_fields_non_db_only = array(); |
4059 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4060 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4059 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4060 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4061 | 4061 | /** @var $field_obj EE_Model_Field_Base */ |
4062 | - if( ! $field_obj->is_db_only_field() ){ |
|
4063 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
4062 | + if ( ! $field_obj->is_db_only_field()) { |
|
4063 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
4064 | 4064 | } |
4065 | 4065 | } |
4066 | 4066 | } |
@@ -4079,60 +4079,60 @@ discard block |
||
4079 | 4079 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
4080 | 4080 | * @throws \EE_Error |
4081 | 4081 | */ |
4082 | - protected function _create_objects( $rows = array() ) { |
|
4083 | - $array_of_objects=array(); |
|
4084 | - if(empty($rows)){ |
|
4082 | + protected function _create_objects($rows = array()) { |
|
4083 | + $array_of_objects = array(); |
|
4084 | + if (empty($rows)) { |
|
4085 | 4085 | return array(); |
4086 | 4086 | } |
4087 | 4087 | $count_if_model_has_no_primary_key = 0; |
4088 | 4088 | $has_primary_key = $this->has_primary_key_field(); |
4089 | 4089 | $primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null; |
4090 | - foreach ( (array)$rows as $row ) { |
|
4091 | - if(empty($row)){ |
|
4090 | + foreach ((array) $rows as $row) { |
|
4091 | + if (empty($row)) { |
|
4092 | 4092 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
4093 | 4093 | return array(); |
4094 | 4094 | } |
4095 | 4095 | //check if we've already set this object in the results array, |
4096 | 4096 | //in which case there's no need to process it further (again) |
4097 | - if( $has_primary_key ) { |
|
4097 | + if ($has_primary_key) { |
|
4098 | 4098 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
4099 | 4099 | $row, |
4100 | 4100 | $primary_key_field->get_qualified_column(), |
4101 | 4101 | $primary_key_field->get_table_column() |
4102 | 4102 | ); |
4103 | - if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
4103 | + if ($table_pk_value && isset($array_of_objects[$table_pk_value])) { |
|
4104 | 4104 | continue; |
4105 | 4105 | } |
4106 | 4106 | } |
4107 | 4107 | $classInstance = $this->instantiate_class_from_array_or_object($row); |
4108 | - if( ! $classInstance ) { |
|
4108 | + if ( ! $classInstance) { |
|
4109 | 4109 | throw new EE_Error( |
4110 | 4110 | sprintf( |
4111 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
4111 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
4112 | 4112 | $this->get_this_model_name(), |
4113 | - http_build_query( $row ) |
|
4113 | + http_build_query($row) |
|
4114 | 4114 | ) |
4115 | 4115 | ); |
4116 | 4116 | } |
4117 | 4117 | //set the timezone on the instantiated objects |
4118 | - $classInstance->set_timezone( $this->_timezone ); |
|
4118 | + $classInstance->set_timezone($this->_timezone); |
|
4119 | 4119 | //make sure if there is any timezone setting present that we set the timezone for the object |
4120 | 4120 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
4121 | - $array_of_objects[ $key ] = $classInstance; |
|
4121 | + $array_of_objects[$key] = $classInstance; |
|
4122 | 4122 | //also, for all the relations of type BelongsTo, see if we can cache |
4123 | 4123 | //those related models |
4124 | 4124 | //(we could do this for other relations too, but if there are conditions |
4125 | 4125 | //that filtered out some fo the results, then we'd be caching an incomplete set |
4126 | 4126 | //so it requires a little more thought than just caching them immediately...) |
4127 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
4128 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
4127 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
4128 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
4129 | 4129 | //check if this model's INFO is present. If so, cache it on the model |
4130 | 4130 | $other_model = $relation_obj->get_other_model(); |
4131 | 4131 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
4132 | 4132 | //if we managed to make a model object from the results, cache it on the main model object |
4133 | - if( $other_model_obj_maybe ){ |
|
4133 | + if ($other_model_obj_maybe) { |
|
4134 | 4134 | //set timezone on these other model objects if they are present |
4135 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
4135 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
4136 | 4136 | $classInstance->cache($modelName, $other_model_obj_maybe); |
4137 | 4137 | } |
4138 | 4138 | } |
@@ -4153,12 +4153,12 @@ discard block |
||
4153 | 4153 | |
4154 | 4154 | $this_model_fields_and_values = array(); |
4155 | 4155 | //setup the row using default values; |
4156 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
4156 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
4157 | 4157 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
4158 | 4158 | } |
4159 | 4159 | |
4160 | 4160 | $className = $this->_get_class_name(); |
4161 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
4161 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
4162 | 4162 | |
4163 | 4163 | return $classInstance; |
4164 | 4164 | } |
@@ -4171,45 +4171,45 @@ discard block |
||
4171 | 4171 | * @return EE_Base_Class |
4172 | 4172 | * @throws \EE_Error |
4173 | 4173 | */ |
4174 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
4175 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
4176 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
4174 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
4175 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
4176 | + $cols_n_values = get_object_vars($cols_n_values); |
|
4177 | 4177 | } |
4178 | 4178 | $primary_key = NULL; |
4179 | 4179 | //make sure the array only has keys that are fields/columns on this model |
4180 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4181 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
4182 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
4180 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4181 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4182 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
4183 | 4183 | } |
4184 | - $className=$this->_get_class_name(); |
|
4184 | + $className = $this->_get_class_name(); |
|
4185 | 4185 | |
4186 | 4186 | //check we actually found results that we can use to build our model object |
4187 | 4187 | //if not, return null |
4188 | - if( $this->has_primary_key_field()){ |
|
4189 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
4188 | + if ($this->has_primary_key_field()) { |
|
4189 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4190 | 4190 | return NULL; |
4191 | 4191 | } |
4192 | - }else if($this->unique_indexes()){ |
|
4192 | + } else if ($this->unique_indexes()) { |
|
4193 | 4193 | $first_column = reset($this_model_fields_n_values); |
4194 | - if(empty($first_column)){ |
|
4194 | + if (empty($first_column)) { |
|
4195 | 4195 | return NULL; |
4196 | 4196 | } |
4197 | 4197 | } |
4198 | 4198 | |
4199 | 4199 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
4200 | - if ( $primary_key){ |
|
4201 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
4202 | - if( ! $classInstance) { |
|
4203 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4200 | + if ($primary_key) { |
|
4201 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
4202 | + if ( ! $classInstance) { |
|
4203 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4204 | 4204 | // add this new object to the entity map |
4205 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
4205 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
4206 | 4206 | } |
4207 | - }else{ |
|
4208 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4207 | + } else { |
|
4208 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4209 | 4209 | } |
4210 | 4210 | |
4211 | 4211 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
4212 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
4212 | + $this->set_timezone($classInstance->get_timezone()); |
|
4213 | 4213 | return $classInstance; |
4214 | 4214 | } |
4215 | 4215 | /** |
@@ -4217,8 +4217,8 @@ discard block |
||
4217 | 4217 | * @param int|string $id the ID of the model object |
4218 | 4218 | * @return EE_Base_Class |
4219 | 4219 | */ |
4220 | - public function get_from_entity_map( $id ){ |
|
4221 | - return isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ? $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] : NULL; |
|
4220 | + public function get_from_entity_map($id) { |
|
4221 | + return isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]) ? $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] : NULL; |
|
4222 | 4222 | } |
4223 | 4223 | |
4224 | 4224 | |
@@ -4240,21 +4240,21 @@ discard block |
||
4240 | 4240 | * @throws EE_Error |
4241 | 4241 | * @return \EE_Base_Class |
4242 | 4242 | */ |
4243 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
4243 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
4244 | 4244 | $className = $this->_get_class_name(); |
4245 | - if( ! $object instanceof $className ){ |
|
4246 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
4245 | + if ( ! $object instanceof $className) { |
|
4246 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
4247 | 4247 | } |
4248 | 4248 | /** @var $object EE_Base_Class */ |
4249 | - if ( ! $object->ID() ){ |
|
4250 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
4249 | + if ( ! $object->ID()) { |
|
4250 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
4251 | 4251 | } |
4252 | 4252 | // double check it's not already there |
4253 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
4254 | - if ( $classInstance ) { |
|
4253 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
4254 | + if ($classInstance) { |
|
4255 | 4255 | return $classInstance; |
4256 | 4256 | } else { |
4257 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $object->ID() ] = $object; |
|
4257 | + $this->_entity_map[EEM_Base::$_model_query_blog_id][$object->ID()] = $object; |
|
4258 | 4258 | return $object; |
4259 | 4259 | } |
4260 | 4260 | } |
@@ -4268,13 +4268,13 @@ discard block |
||
4268 | 4268 | * @param int|string $id the ID of the model object |
4269 | 4269 | * @return boolean |
4270 | 4270 | */ |
4271 | - public function clear_entity_map( $id = null ) { |
|
4272 | - if ( empty( $id ) ) { |
|
4273 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ] = array(); |
|
4271 | + public function clear_entity_map($id = null) { |
|
4272 | + if (empty($id)) { |
|
4273 | + $this->_entity_map[EEM_Base::$_model_query_blog_id] = array(); |
|
4274 | 4274 | return true; |
4275 | 4275 | } |
4276 | - if ( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ) { |
|
4277 | - unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ); |
|
4276 | + if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id])) { |
|
4277 | + unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]); |
|
4278 | 4278 | return true; |
4279 | 4279 | } |
4280 | 4280 | return false; |
@@ -4290,8 +4290,8 @@ discard block |
||
4290 | 4290 | * @param array $cols_n_values |
4291 | 4291 | * @return array |
4292 | 4292 | */ |
4293 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
4294 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4293 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4294 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4295 | 4295 | } |
4296 | 4296 | |
4297 | 4297 | |
@@ -4304,23 +4304,23 @@ discard block |
||
4304 | 4304 | * @param string $cols_n_values |
4305 | 4305 | * @return array |
4306 | 4306 | */ |
4307 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
4307 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4308 | 4308 | $this_model_fields_n_values = array(); |
4309 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
4310 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
4309 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
4310 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
4311 | 4311 | //there is a primary key on this table and its not set. Use defaults for all its columns |
4312 | - if( $table_pk_value === null && $table_obj->get_pk_column() ){ |
|
4313 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4314 | - if( ! $field_obj->is_db_only_field() ){ |
|
4312 | + if ($table_pk_value === null && $table_obj->get_pk_column()) { |
|
4313 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4314 | + if ( ! $field_obj->is_db_only_field()) { |
|
4315 | 4315 | //prepare field as if its coming from db |
4316 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
4317 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
4316 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
4317 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
4318 | 4318 | } |
4319 | 4319 | } |
4320 | - }else{ |
|
4320 | + } else { |
|
4321 | 4321 | //the table's rows existed. Use their values |
4322 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4323 | - if( ! $field_obj->is_db_only_field() ){ |
|
4322 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4323 | + if ( ! $field_obj->is_db_only_field()) { |
|
4324 | 4324 | $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not( |
4325 | 4325 | $cols_n_values, $field_obj->get_qualified_column(), |
4326 | 4326 | $field_obj->get_table_column() |
@@ -4340,15 +4340,15 @@ discard block |
||
4340 | 4340 | * @param $regular_column |
4341 | 4341 | * @return null |
4342 | 4342 | */ |
4343 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4343 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4344 | 4344 | $value = null; |
4345 | 4345 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4346 | 4346 | //does the field on the model relate to this column retrieved from the db? |
4347 | 4347 | //or is it a db-only field? (not relating to the model) |
4348 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4349 | - $value = $cols_n_values[ $qualified_column ]; |
|
4350 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4351 | - $value = $cols_n_values[ $regular_column ]; |
|
4348 | + if (isset($cols_n_values[$qualified_column])) { |
|
4349 | + $value = $cols_n_values[$qualified_column]; |
|
4350 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4351 | + $value = $cols_n_values[$regular_column]; |
|
4352 | 4352 | } |
4353 | 4353 | return $value; |
4354 | 4354 | } |
@@ -4364,26 +4364,26 @@ discard block |
||
4364 | 4364 | * @return EE_Base_Class |
4365 | 4365 | * @throws \EE_Error |
4366 | 4366 | */ |
4367 | - public function refresh_entity_map_from_db( $id ){ |
|
4368 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4369 | - if( $obj_in_map ){ |
|
4367 | + public function refresh_entity_map_from_db($id) { |
|
4368 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4369 | + if ($obj_in_map) { |
|
4370 | 4370 | $wpdb_results = $this->_get_all_wpdb_results( |
4371 | - array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) |
|
4371 | + array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1) |
|
4372 | 4372 | ); |
4373 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4374 | - $one_row = reset( $wpdb_results ); |
|
4375 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4376 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4373 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4374 | + $one_row = reset($wpdb_results); |
|
4375 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4376 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4377 | 4377 | } |
4378 | 4378 | //clear the cache of related model objects |
4379 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4380 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4379 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4380 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4381 | 4381 | } |
4382 | 4382 | } |
4383 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] = $obj_in_map; |
|
4383 | + $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] = $obj_in_map; |
|
4384 | 4384 | return $obj_in_map; |
4385 | - }else{ |
|
4386 | - return $this->get_one_by_ID( $id ); |
|
4385 | + } else { |
|
4386 | + return $this->get_one_by_ID($id); |
|
4387 | 4387 | } |
4388 | 4388 | } |
4389 | 4389 | |
@@ -4401,24 +4401,24 @@ discard block |
||
4401 | 4401 | * @return \EE_Base_Class |
4402 | 4402 | * @throws \EE_Error |
4403 | 4403 | */ |
4404 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4405 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4406 | - if( $obj_in_map ){ |
|
4407 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4408 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4409 | - $obj_in_map->set( $field_name, $value ); |
|
4404 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4405 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4406 | + if ($obj_in_map) { |
|
4407 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4408 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4409 | + $obj_in_map->set($field_name, $value); |
|
4410 | 4410 | } |
4411 | 4411 | //make the model object in the entity map's cache match the $replacing_model_obj |
4412 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4413 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4414 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4415 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4412 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4413 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4414 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4415 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4416 | 4416 | } |
4417 | 4417 | } |
4418 | 4418 | } |
4419 | 4419 | return $obj_in_map; |
4420 | - }else{ |
|
4421 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4420 | + } else { |
|
4421 | + $this->add_to_entity_map($replacing_model_obj); |
|
4422 | 4422 | return $replacing_model_obj; |
4423 | 4423 | } |
4424 | 4424 | } |
@@ -4431,7 +4431,7 @@ discard block |
||
4431 | 4431 | * require_once($this->_getClassName().".class.php"); |
4432 | 4432 | * @return string |
4433 | 4433 | */ |
4434 | - private function _get_class_name(){ |
|
4434 | + private function _get_class_name() { |
|
4435 | 4435 | return "EE_".$this->get_this_model_name(); |
4436 | 4436 | } |
4437 | 4437 | |
@@ -4444,8 +4444,8 @@ discard block |
||
4444 | 4444 | * @param int $quantity |
4445 | 4445 | * @return string |
4446 | 4446 | */ |
4447 | - public function item_name($quantity = 1){ |
|
4448 | - return (int)$quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4447 | + public function item_name($quantity = 1) { |
|
4448 | + return (int) $quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4449 | 4449 | } |
4450 | 4450 | |
4451 | 4451 | |
@@ -4472,13 +4472,13 @@ discard block |
||
4472 | 4472 | * @throws EE_Error |
4473 | 4473 | * @return mixed whatever the plugin which calls add_filter decides |
4474 | 4474 | */ |
4475 | - public function __call($methodName,$args){ |
|
4476 | - $className=get_class($this); |
|
4477 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4478 | - if(!has_filter($tagName)){ |
|
4475 | + public function __call($methodName, $args) { |
|
4476 | + $className = get_class($this); |
|
4477 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4478 | + if ( ! has_filter($tagName)) { |
|
4479 | 4479 | throw new EE_Error( |
4480 | 4480 | sprintf( |
4481 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
4481 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
4482 | 4482 | $methodName, |
4483 | 4483 | $className, |
4484 | 4484 | $tagName, |
@@ -4487,7 +4487,7 @@ discard block |
||
4487 | 4487 | ); |
4488 | 4488 | } |
4489 | 4489 | |
4490 | - return apply_filters($tagName,null,$this,$args); |
|
4490 | + return apply_filters($tagName, null, $this, $args); |
|
4491 | 4491 | } |
4492 | 4492 | |
4493 | 4493 | |
@@ -4505,28 +4505,28 @@ discard block |
||
4505 | 4505 | * @throws EE_Error |
4506 | 4506 | * @return EE_Base_Class |
4507 | 4507 | */ |
4508 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4508 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4509 | 4509 | $className = $this->_get_class_name(); |
4510 | - if ( $base_class_obj_or_id instanceof $className ) { |
|
4510 | + if ($base_class_obj_or_id instanceof $className) { |
|
4511 | 4511 | $model_object = $base_class_obj_or_id; |
4512 | 4512 | } else { |
4513 | 4513 | $primary_key_field = $this->get_primary_key_field(); |
4514 | 4514 | if ( |
4515 | 4515 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4516 | 4516 | && ( |
4517 | - is_int( $base_class_obj_or_id ) |
|
4518 | - || is_string( $base_class_obj_or_id ) |
|
4517 | + is_int($base_class_obj_or_id) |
|
4518 | + || is_string($base_class_obj_or_id) |
|
4519 | 4519 | ) |
4520 | 4520 | ) { |
4521 | 4521 | // assume it's an ID. |
4522 | 4522 | // either a proper integer or a string representing an integer (eg "101" instead of 101) |
4523 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4523 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4524 | 4524 | } else if ( |
4525 | 4525 | $primary_key_field instanceof EE_Primary_Key_String_Field |
4526 | - && is_string( $base_class_obj_or_id ) |
|
4526 | + && is_string($base_class_obj_or_id) |
|
4527 | 4527 | ) { |
4528 | 4528 | // assume its a string representation of the object |
4529 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4529 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4530 | 4530 | } else { |
4531 | 4531 | throw new EE_Error( |
4532 | 4532 | sprintf( |
@@ -4536,12 +4536,12 @@ discard block |
||
4536 | 4536 | ), |
4537 | 4537 | $base_class_obj_or_id, |
4538 | 4538 | $this->_get_class_name(), |
4539 | - print_r( $base_class_obj_or_id, true ) |
|
4539 | + print_r($base_class_obj_or_id, true) |
|
4540 | 4540 | ) |
4541 | 4541 | ); |
4542 | 4542 | } |
4543 | 4543 | } |
4544 | - if ( $ensure_is_in_db && $model_object->ID() !== null ) { |
|
4544 | + if ($ensure_is_in_db && $model_object->ID() !== null) { |
|
4545 | 4545 | $model_object->save(); |
4546 | 4546 | } |
4547 | 4547 | return $model_object; |
@@ -4557,19 +4557,19 @@ discard block |
||
4557 | 4557 | * @return int|string depending on the type of this model object's ID |
4558 | 4558 | * @throws EE_Error |
4559 | 4559 | */ |
4560 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4560 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4561 | 4561 | $className = $this->_get_class_name(); |
4562 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4562 | + if ($base_class_obj_or_id instanceof $className) { |
|
4563 | 4563 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4564 | 4564 | $id = $base_class_obj_or_id->ID(); |
4565 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4565 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4566 | 4566 | //assume it's an ID |
4567 | 4567 | $id = $base_class_obj_or_id; |
4568 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4568 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4569 | 4569 | //assume its a string representation of the object |
4570 | 4570 | $id = $base_class_obj_or_id; |
4571 | - }else{ |
|
4572 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4571 | + } else { |
|
4572 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4573 | 4573 | } |
4574 | 4574 | return $id; |
4575 | 4575 | } |
@@ -4592,14 +4592,14 @@ discard block |
||
4592 | 4592 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4593 | 4593 | * @return void |
4594 | 4594 | */ |
4595 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4595 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4596 | 4596 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4597 | 4597 | } |
4598 | 4598 | /** |
4599 | 4599 | * Read comments for assume_values_already_prepared_by_model_object() |
4600 | 4600 | * @return int |
4601 | 4601 | */ |
4602 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4602 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4603 | 4603 | return $this->_values_already_prepared_by_model_object; |
4604 | 4604 | } |
4605 | 4605 | |
@@ -4607,17 +4607,17 @@ discard block |
||
4607 | 4607 | * Gets all the indexes on this model |
4608 | 4608 | * @return EE_Index[] |
4609 | 4609 | */ |
4610 | - public function indexes(){ |
|
4610 | + public function indexes() { |
|
4611 | 4611 | return $this->_indexes; |
4612 | 4612 | } |
4613 | 4613 | /** |
4614 | 4614 | * Gets all the Unique Indexes on this model |
4615 | 4615 | * @return EE_Unique_Index[] |
4616 | 4616 | */ |
4617 | - public function unique_indexes(){ |
|
4617 | + public function unique_indexes() { |
|
4618 | 4618 | $unique_indexes = array(); |
4619 | - foreach($this->_indexes as $name => $index){ |
|
4620 | - if($index instanceof EE_Unique_Index){ |
|
4619 | + foreach ($this->_indexes as $name => $index) { |
|
4620 | + if ($index instanceof EE_Unique_Index) { |
|
4621 | 4621 | $unique_indexes [$name] = $index; |
4622 | 4622 | } |
4623 | 4623 | } |
@@ -4635,13 +4635,13 @@ discard block |
||
4635 | 4635 | * @return EE_Model_Field_Base[] indexed by the field's name |
4636 | 4636 | * @throws \EE_Error |
4637 | 4637 | */ |
4638 | - public function get_combined_primary_key_fields(){ |
|
4639 | - foreach($this->indexes() as $index){ |
|
4640 | - if($index instanceof EE_Primary_Key_Index){ |
|
4638 | + public function get_combined_primary_key_fields() { |
|
4639 | + foreach ($this->indexes() as $index) { |
|
4640 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4641 | 4641 | return $index->fields(); |
4642 | 4642 | } |
4643 | 4643 | } |
4644 | - return array( $this->primary_key_name() => $this->get_primary_key_field()); |
|
4644 | + return array($this->primary_key_name() => $this->get_primary_key_field()); |
|
4645 | 4645 | } |
4646 | 4646 | |
4647 | 4647 | |
@@ -4655,7 +4655,7 @@ discard block |
||
4655 | 4655 | * @return string |
4656 | 4656 | * @throws \EE_Error |
4657 | 4657 | */ |
4658 | - public function get_index_primary_key_string($cols_n_values){ |
|
4658 | + public function get_index_primary_key_string($cols_n_values) { |
|
4659 | 4659 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4660 | 4660 | return http_build_query($cols_n_values_for_primary_key_index); |
4661 | 4661 | } |
@@ -4670,13 +4670,13 @@ discard block |
||
4670 | 4670 | * @return null|array |
4671 | 4671 | * @throws \EE_Error |
4672 | 4672 | */ |
4673 | - public function parse_index_primary_key_string( $index_primary_key_string) { |
|
4673 | + public function parse_index_primary_key_string($index_primary_key_string) { |
|
4674 | 4674 | $key_fields = $this->get_combined_primary_key_fields(); |
4675 | 4675 | //check all of them are in the $id |
4676 | 4676 | $key_vals_in_combined_pk = array(); |
4677 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4678 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4679 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4677 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4678 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4679 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4680 | 4680 | return NULL; |
4681 | 4681 | } |
4682 | 4682 | } |
@@ -4693,10 +4693,10 @@ discard block |
||
4693 | 4693 | * @return boolean |
4694 | 4694 | * @throws \EE_Error |
4695 | 4695 | */ |
4696 | - public function has_all_combined_primary_key_fields( $key_vals ) { |
|
4697 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4698 | - foreach( $keys_it_should_have as $key ){ |
|
4699 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4696 | + public function has_all_combined_primary_key_fields($key_vals) { |
|
4697 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4698 | + foreach ($keys_it_should_have as $key) { |
|
4699 | + if ( ! isset($key_vals[$key])) { |
|
4700 | 4700 | return false; |
4701 | 4701 | } |
4702 | 4702 | } |
@@ -4712,23 +4712,23 @@ discard block |
||
4712 | 4712 | * @throws EE_Error |
4713 | 4713 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4714 | 4714 | */ |
4715 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4715 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4716 | 4716 | |
4717 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4717 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4718 | 4718 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4719 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4719 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4720 | 4720 | $attributes_array = $model_object_or_attributes_array; |
4721 | - }else{ |
|
4722 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4721 | + } else { |
|
4722 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4723 | 4723 | } |
4724 | 4724 | //even copies obviously won't have the same ID, so remove the primary key |
4725 | 4725 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4726 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4726 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4727 | 4727 | unset($attributes_array[$this->primary_key_name()]); |
4728 | 4728 | } |
4729 | - if(isset($query_params[0])){ |
|
4730 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4731 | - }else{ |
|
4729 | + if (isset($query_params[0])) { |
|
4730 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4731 | + } else { |
|
4732 | 4732 | $query_params[0] = $attributes_array; |
4733 | 4733 | } |
4734 | 4734 | return $this->get_all($query_params); |
@@ -4744,16 +4744,16 @@ discard block |
||
4744 | 4744 | * @return EE_Base_Class |
4745 | 4745 | * @throws \EE_Error |
4746 | 4746 | */ |
4747 | - public function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4748 | - if( ! is_array( $query_params ) ){ |
|
4749 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4747 | + public function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4748 | + if ( ! is_array($query_params)) { |
|
4749 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4750 | 4750 | $query_params = array(); |
4751 | 4751 | } |
4752 | 4752 | $query_params['limit'] = 1; |
4753 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4754 | - if(is_array($copies)){ |
|
4753 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4754 | + if (is_array($copies)) { |
|
4755 | 4755 | return array_shift($copies); |
4756 | - }else{ |
|
4756 | + } else { |
|
4757 | 4757 | return null; |
4758 | 4758 | } |
4759 | 4759 | } |
@@ -4769,10 +4769,10 @@ discard block |
||
4769 | 4769 | * @return int number of rows updated |
4770 | 4770 | * @throws \EE_Error |
4771 | 4771 | */ |
4772 | - public function update_by_ID($fields_n_values,$id){ |
|
4772 | + public function update_by_ID($fields_n_values, $id) { |
|
4773 | 4773 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4774 | 4774 | 'default_where_conditions'=>'other_models_only',); |
4775 | - return $this->update($fields_n_values,$query_params); |
|
4775 | + return $this->update($fields_n_values, $query_params); |
|
4776 | 4776 | } |
4777 | 4777 | |
4778 | 4778 | |
@@ -4783,12 +4783,12 @@ discard block |
||
4783 | 4783 | * @return string an operator which can be used in SQL |
4784 | 4784 | * @throws EE_Error |
4785 | 4785 | */ |
4786 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4786 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4787 | 4787 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4788 | - if($sql_operator){ |
|
4788 | + if ($sql_operator) { |
|
4789 | 4789 | return $sql_operator; |
4790 | - }else{ |
|
4791 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4790 | + } else { |
|
4791 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4792 | 4792 | } |
4793 | 4793 | } |
4794 | 4794 | |
@@ -4802,10 +4802,10 @@ discard block |
||
4802 | 4802 | * @return string[] |
4803 | 4803 | * @throws \EE_Error |
4804 | 4804 | */ |
4805 | - public function get_all_names($query_params = array()){ |
|
4805 | + public function get_all_names($query_params = array()) { |
|
4806 | 4806 | $objs = $this->get_all($query_params); |
4807 | 4807 | $names = array(); |
4808 | - foreach($objs as $obj){ |
|
4808 | + foreach ($objs as $obj) { |
|
4809 | 4809 | $names[$obj->ID()] = $obj->name(); |
4810 | 4810 | } |
4811 | 4811 | return $names; |
@@ -4824,11 +4824,11 @@ discard block |
||
4824 | 4824 | * @return array |
4825 | 4825 | * @throws \EE_Error |
4826 | 4826 | */ |
4827 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4828 | - if( ! $this->has_primary_key_field() ) { |
|
4829 | - if( WP_DEBUG ) { |
|
4827 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4828 | + if ( ! $this->has_primary_key_field()) { |
|
4829 | + if (WP_DEBUG) { |
|
4830 | 4830 | EE_Error::add_error( |
4831 | - __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), |
|
4831 | + __('Trying to get IDs from a model than has no primary key', 'event_espresso'), |
|
4832 | 4832 | __FILE__, |
4833 | 4833 | __FUNCTION__, |
4834 | 4834 | __LINE__ |
@@ -4836,13 +4836,13 @@ discard block |
||
4836 | 4836 | } |
4837 | 4837 | } |
4838 | 4838 | $IDs = array(); |
4839 | - foreach( $model_objects as $model_object ) { |
|
4839 | + foreach ($model_objects as $model_object) { |
|
4840 | 4840 | $id = $model_object->ID(); |
4841 | - if( ! $id ) { |
|
4842 | - if( $filter_out_empty_ids ) { |
|
4841 | + if ( ! $id) { |
|
4842 | + if ($filter_out_empty_ids) { |
|
4843 | 4843 | continue; |
4844 | 4844 | } |
4845 | - if ( WP_DEBUG ) { |
|
4845 | + if (WP_DEBUG) { |
|
4846 | 4846 | EE_Error::add_error( |
4847 | 4847 | __( |
4848 | 4848 | 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', |
@@ -4864,8 +4864,8 @@ discard block |
||
4864 | 4864 | * are no capabilities that relate to this model returns false |
4865 | 4865 | * @return string|false |
4866 | 4866 | */ |
4867 | - public function cap_slug(){ |
|
4868 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4867 | + public function cap_slug() { |
|
4868 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4869 | 4869 | } |
4870 | 4870 | |
4871 | 4871 | |
@@ -4880,34 +4880,34 @@ discard block |
||
4880 | 4880 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4881 | 4881 | * @throws \EE_Error |
4882 | 4882 | */ |
4883 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4884 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4883 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4884 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4885 | 4885 | //check if we ought to run the restriction generator first |
4886 | - if( |
|
4887 | - isset( $this->_cap_restriction_generators[ $context ] ) |
|
4888 | - && $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base |
|
4889 | - && ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() |
|
4886 | + if ( |
|
4887 | + isset($this->_cap_restriction_generators[$context]) |
|
4888 | + && $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base |
|
4889 | + && ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions() |
|
4890 | 4890 | ) { |
4891 | - $this->_cap_restrictions[ $context ] = array_merge( |
|
4892 | - $this->_cap_restrictions[ $context ], |
|
4893 | - $this->_cap_restriction_generators[ $context ]->generate_restrictions() |
|
4891 | + $this->_cap_restrictions[$context] = array_merge( |
|
4892 | + $this->_cap_restrictions[$context], |
|
4893 | + $this->_cap_restriction_generators[$context]->generate_restrictions() |
|
4894 | 4894 | ); |
4895 | 4895 | } |
4896 | 4896 | //and make sure we've finalized the construction of each restriction |
4897 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4898 | - if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) { |
|
4899 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4897 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4898 | + if ($where_conditions_obj instanceof EE_Default_Where_Conditions) { |
|
4899 | + $where_conditions_obj->_finalize_construct($this); |
|
4900 | 4900 | } |
4901 | 4901 | } |
4902 | 4902 | |
4903 | - return $this->_cap_restrictions[ $context ]; |
|
4903 | + return $this->_cap_restrictions[$context]; |
|
4904 | 4904 | } |
4905 | 4905 | |
4906 | 4906 | /** |
4907 | 4907 | * Indicating whether or not this model thinks its a wp core model |
4908 | 4908 | * @return boolean |
4909 | 4909 | */ |
4910 | - public function is_wp_core_model(){ |
|
4910 | + public function is_wp_core_model() { |
|
4911 | 4911 | return $this->_wp_core_model; |
4912 | 4912 | } |
4913 | 4913 | |
@@ -4921,12 +4921,12 @@ discard block |
||
4921 | 4921 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4922 | 4922 | * @throws \EE_Error |
4923 | 4923 | */ |
4924 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4924 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4925 | 4925 | $missing_caps = array(); |
4926 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4927 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4928 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4929 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4926 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4927 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4928 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4929 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4930 | 4930 | } |
4931 | 4931 | } |
4932 | 4932 | return $missing_caps; |
@@ -4938,7 +4938,7 @@ discard block |
||
4938 | 4938 | * one of 'read', 'edit', or 'delete' |
4939 | 4939 | */ |
4940 | 4940 | public function cap_contexts_to_cap_action_map() { |
4941 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4941 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4942 | 4942 | } |
4943 | 4943 | |
4944 | 4944 | |
@@ -4949,19 +4949,19 @@ discard block |
||
4949 | 4949 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4950 | 4950 | * @throws \EE_Error |
4951 | 4951 | */ |
4952 | - public function cap_action_for_context( $context ) { |
|
4952 | + public function cap_action_for_context($context) { |
|
4953 | 4953 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4954 | - if( isset( $mapping[ $context ] ) ) { |
|
4955 | - return $mapping[ $context ]; |
|
4954 | + if (isset($mapping[$context])) { |
|
4955 | + return $mapping[$context]; |
|
4956 | 4956 | } |
4957 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4957 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4958 | 4958 | return $action; |
4959 | 4959 | } |
4960 | 4960 | throw new EE_Error( |
4961 | 4961 | sprintf( |
4962 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4962 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4963 | 4963 | $context, |
4964 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4964 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4965 | 4965 | ) |
4966 | 4966 | ); |
4967 | 4967 | |
@@ -4972,7 +4972,7 @@ discard block |
||
4972 | 4972 | * @return array |
4973 | 4973 | */ |
4974 | 4974 | static public function valid_cap_contexts() { |
4975 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4975 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4976 | 4976 | self::caps_read, |
4977 | 4977 | self::caps_read_admin, |
4978 | 4978 | self::caps_edit, |
@@ -4988,17 +4988,17 @@ discard block |
||
4988 | 4988 | * @return bool |
4989 | 4989 | * @throws \EE_Error |
4990 | 4990 | */ |
4991 | - static public function verify_is_valid_cap_context( $context ) { |
|
4991 | + static public function verify_is_valid_cap_context($context) { |
|
4992 | 4992 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4993 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4993 | + if (in_array($context, $valid_cap_contexts)) { |
|
4994 | 4994 | return true; |
4995 | - }else{ |
|
4995 | + } else { |
|
4996 | 4996 | throw new EE_Error( |
4997 | 4997 | sprintf( |
4998 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4998 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4999 | 4999 | $context, |
5000 | - 'EEM_Base' , |
|
5001 | - implode(',', $valid_cap_contexts ) |
|
5000 | + 'EEM_Base', |
|
5001 | + implode(',', $valid_cap_contexts) |
|
5002 | 5002 | ) |
5003 | 5003 | ); |
5004 | 5004 | } |
@@ -1,7 +1,7 @@ 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 | -require_once( EE_MODELS . 'EEM_Base.model.php' ); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -25,65 +25,65 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $timezone |
27 | 27 | */ |
28 | - protected function __construct( $timezone = null ) { |
|
29 | - $this->singular_item = __( 'Term', 'event_espresso' ); |
|
30 | - $this->plural_item = __( 'Terms', 'event_espresso' ); |
|
28 | + protected function __construct($timezone = null) { |
|
29 | + $this->singular_item = __('Term', 'event_espresso'); |
|
30 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
31 | 31 | $this->_tables = array( |
32 | - 'Term' => new EE_Primary_Table( 'terms', 'term_id' ), |
|
32 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
33 | 33 | ); |
34 | 34 | $this->_fields = array( |
35 | 35 | 'Term' => array( |
36 | - 'term_id' => new EE_Primary_Key_Int_Field( 'term_id', __( 'Term ID', 'event_espresso' ) ), |
|
37 | - 'name' => new EE_Plain_Text_Field( 'name', __( 'Term Name', 'event_espresso' ), false, '' ), |
|
38 | - 'slug' => new EE_Slug_Field( 'slug', __( 'Term Slug', 'event_espresso' ), false ), |
|
39 | - 'term_group' => new EE_Integer_Field( 'term_group', __( "Term Group", "event_espresso" ), false, 0 ), |
|
36 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
37 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
38 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
39 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
40 | 40 | ), |
41 | 41 | ); |
42 | 42 | $this->_model_relations = array( |
43 | 43 | 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
44 | 44 | ); |
45 | 45 | $path_to_tax_model = 'Term_Taxonomy'; |
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
48 | 48 | $path_to_tax_model |
49 | 49 | ); |
50 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
52 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
50 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
51 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
52 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
53 | 53 | //add cap restrictions for editing relating to the "ee_edit_*" |
54 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
54 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
55 | 55 | array( |
56 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array( '!=', 'espresso_event_categories' ), |
|
56 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
57 | 57 | ) |
58 | 58 | ); |
59 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
59 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
60 | 60 | array( |
61 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
61 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
62 | 62 | ) |
63 | 63 | ); |
64 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
64 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
65 | 65 | array( |
66 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array( '!=', 'espresso_event_type' ), |
|
66 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | //add cap restrictions for deleting relating to the "ee_deleting_*" |
70 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
70 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
71 | 71 | array( |
72 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array( '!=', 'espresso_event_categories' ), |
|
72 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
73 | 73 | ) |
74 | 74 | ); |
75 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
75 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
76 | 76 | array( |
77 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
77 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
78 | 78 | ) |
79 | 79 | ); |
80 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
80 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
81 | 81 | array( |
82 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array( '!=', 'espresso_event_type' ), |
|
82 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
83 | 83 | ) |
84 | 84 | ); |
85 | - parent::__construct( $timezone ); |
|
86 | - add_filter( 'FHEE__Read__create_model_query_params', array( 'EEM_Term', 'rest_api_query_params' ), 10, 3 ); |
|
85 | + parent::__construct($timezone); |
|
86 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * @param bool $show_uncategorized |
96 | 96 | * @return \EE_Base_Class[] |
97 | 97 | */ |
98 | - public function get_all_ee_categories( $show_uncategorized = false ) { |
|
98 | + public function get_all_ee_categories($show_uncategorized = false) { |
|
99 | 99 | $where_params = array( |
100 | 100 | 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
101 | - 'NOT' => array( 'name' => __( 'Uncategorized', 'event_espresso' ) ), |
|
101 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
102 | 102 | ); |
103 | - if ( $show_uncategorized ) { |
|
104 | - unset( $where_params['NOT'] ); |
|
103 | + if ($show_uncategorized) { |
|
104 | + unset($where_params['NOT']); |
|
105 | 105 | } |
106 | 106 | return EEM_Term::instance()->get_all( |
107 | 107 | array( |
108 | 108 | $where_params, |
109 | - 'order_by' => array( 'name' => 'ASC' ), |
|
109 | + 'order_by' => array('name' => 'ASC'), |
|
110 | 110 | ) |
111 | 111 | ); |
112 | 112 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $post_type |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - public function get_all_CPT_post_tags( $post_type = '' ) { |
|
124 | - switch ( $post_type ) { |
|
123 | + public function get_all_CPT_post_tags($post_type = '') { |
|
124 | + switch ($post_type) { |
|
125 | 125 | case 'espresso_events' : |
126 | 126 | return $this->get_all_event_post_tags(); |
127 | 127 | break; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | default : |
132 | 132 | $event_tags = $this->get_all_event_post_tags(); |
133 | 133 | $venue_tags = $this->get_all_venue_post_tags(); |
134 | - return array_merge( $event_tags, $venue_tags ); |
|
134 | + return array_merge($event_tags, $venue_tags); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
150 | 150 | 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
151 | 151 | ), |
152 | - 'order_by' => array( 'name' => 'ASC' ), |
|
153 | - 'force_join' => array( 'Term_Taxonomy.Event' ), |
|
152 | + 'order_by' => array('name' => 'ASC'), |
|
153 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
154 | 154 | ) |
155 | 155 | ); |
156 | - foreach ( $post_tags as $key => $post_tag ) { |
|
157 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
158 | - $post_tags[ $key ]->post_type = array(); |
|
156 | + foreach ($post_tags as $key => $post_tag) { |
|
157 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
158 | + $post_tags[$key]->post_type = array(); |
|
159 | 159 | } |
160 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
160 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
161 | 161 | } |
162 | 162 | return $post_tags; |
163 | 163 | } |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
177 | 177 | 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
178 | 178 | ), |
179 | - 'order_by' => array( 'name' => 'ASC' ), |
|
180 | - 'force_join' => array( 'Term_Taxonomy' ), |
|
179 | + 'order_by' => array('name' => 'ASC'), |
|
180 | + 'force_join' => array('Term_Taxonomy'), |
|
181 | 181 | ) |
182 | 182 | ); |
183 | - foreach ( $post_tags as $key => $post_tag ) { |
|
184 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
185 | - $post_tags[ $key ]->post_type = array(); |
|
183 | + foreach ($post_tags as $key => $post_tag) { |
|
184 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
185 | + $post_tags[$key]->post_type = array(); |
|
186 | 186 | } |
187 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
187 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
188 | 188 | } |
189 | 189 | return $post_tags; |
190 | 190 | } |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * @param EEM_Base $model |
201 | 201 | * @return array |
202 | 202 | */ |
203 | - public static function rest_api_query_params( $model_query_params, $querystring_query_params, $model ) { |
|
204 | - if ( $model === EEM_Term::instance() ) { |
|
205 | - $taxonomies = get_taxonomies( array( 'show_in_rest' => true ) ); |
|
206 | - if ( ! empty( $taxonomies ) ) { |
|
207 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array( 'IN', $taxonomies ); |
|
203 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) { |
|
204 | + if ($model === EEM_Term::instance()) { |
|
205 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
206 | + if ( ! empty($taxonomies)) { |
|
207 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | return $model_query_params; |
@@ -799,7 +799,6 @@ |
||
799 | 799 | |
800 | 800 | |
801 | 801 | /** |
802 | - |
|
803 | 802 | * |
804 | 803 | * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
805 | 804 | * very next day then this method will return true. |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
8 | 8 | |
9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | * @param \WP_REST_Request $request |
47 | 47 | * @return \WP_REST_Response|\WP_Error |
48 | 48 | */ |
49 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
49 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
50 | 50 | $controller = new Read(); |
51 | - try{ |
|
51 | + try { |
|
52 | 52 | $matches = $controller->parse_route( |
53 | 53 | $request->get_route(), |
54 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
55 | - array( 'version', 'model' ) |
|
54 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
55 | + array('version', 'model') |
|
56 | 56 | ); |
57 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
58 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
59 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
57 | + $controller->set_requested_version($matches['version']); |
|
58 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
59 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
60 | 60 | return $controller->send_response( |
61 | 61 | new \WP_Error( |
62 | 62 | 'endpoint_parsing_error', |
63 | 63 | sprintf( |
64 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
64 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
65 | 65 | $model_name_singular |
66 | 66 | ) |
67 | 67 | ) |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | } |
70 | 70 | return $controller->send_response( |
71 | 71 | $controller->get_entities_from_model( |
72 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
72 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
73 | 73 | $request |
74 | 74 | ) |
75 | 75 | ); |
76 | - } catch( \Exception $e ) { |
|
77 | - return $controller->send_response( $e ); |
|
76 | + } catch (\Exception $e) { |
|
77 | + return $controller->send_response($e); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -84,21 +84,21 @@ discard block |
||
84 | 84 | * @param \WP_REST_Request $request |
85 | 85 | * @return \WP_REST_Response|\WP_Error |
86 | 86 | */ |
87 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
87 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
88 | 88 | $controller = new Read(); |
89 | - try{ |
|
89 | + try { |
|
90 | 90 | $matches = $controller->parse_route( |
91 | 91 | $request->get_route(), |
92 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
93 | - array( 'version', 'model', 'id' ) ); |
|
94 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
95 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
96 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
92 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
93 | + array('version', 'model', 'id') ); |
|
94 | + $controller->set_requested_version($matches['version']); |
|
95 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
96 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
97 | 97 | return $controller->send_response( |
98 | 98 | new \WP_Error( |
99 | 99 | 'endpoint_parsing_error', |
100 | 100 | sprintf( |
101 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
101 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
102 | 102 | $model_name_singular |
103 | 103 | ) |
104 | 104 | ) |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | } |
107 | 107 | return $controller->send_response( |
108 | 108 | $controller->get_entity_from_model( |
109 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
109 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
110 | 110 | $request |
111 | 111 | ) |
112 | 112 | ); |
113 | - } catch( \Exception $e ) { |
|
114 | - return $controller->send_response( $e ); |
|
113 | + } catch (\Exception $e) { |
|
114 | + return $controller->send_response($e); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -123,40 +123,40 @@ discard block |
||
123 | 123 | * @param \WP_REST_Request $request |
124 | 124 | * @return \WP_REST_Response|\WP_Error |
125 | 125 | */ |
126 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
126 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
127 | 127 | $controller = new Read(); |
128 | - try{ |
|
128 | + try { |
|
129 | 129 | $matches = $controller->parse_route( |
130 | 130 | $request->get_route(), |
131 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
132 | - array( 'version', 'model', 'id', 'related_model' ) |
|
131 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
132 | + array('version', 'model', 'id', 'related_model') |
|
133 | 133 | ); |
134 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
135 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
136 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
134 | + $controller->set_requested_version($matches['version']); |
|
135 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
136 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
137 | 137 | return $controller->send_response( |
138 | 138 | new \WP_Error( |
139 | 139 | 'endpoint_parsing_error', |
140 | 140 | sprintf( |
141 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
141 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
142 | 142 | $main_model_name_singular |
143 | 143 | ) |
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
147 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
148 | 148 | //assume the related model name is plural and try to find the model's name |
149 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
149 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
151 | 151 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
152 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
152 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
153 | 153 | } |
154 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
154 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
155 | 155 | return $controller->send_response( |
156 | 156 | new \WP_Error( |
157 | 157 | 'endpoint_parsing_error', |
158 | 158 | sprintf( |
159 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
159 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
160 | 160 | $related_model_name_singular |
161 | 161 | ) |
162 | 162 | ) |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | |
166 | 166 | return $controller->send_response( |
167 | 167 | $controller->get_entities_from_relation( |
168 | - $request->get_param( 'id' ), |
|
169 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
168 | + $request->get_param('id'), |
|
169 | + $main_model->related_settings_for($related_model_name_singular), |
|
170 | 170 | $request |
171 | 171 | ) |
172 | 172 | ); |
173 | - } catch( \Exception $e ) { |
|
174 | - return $controller->send_response( $e ); |
|
173 | + } catch (\Exception $e) { |
|
174 | + return $controller->send_response($e); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -184,28 +184,28 @@ discard block |
||
184 | 184 | * @param \WP_REST_Request $request |
185 | 185 | * @return array|\WP_Error |
186 | 186 | */ |
187 | - public function get_entities_from_model( $model, $request) { |
|
188 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
189 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
190 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
187 | + public function get_entities_from_model($model, $request) { |
|
188 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
189 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
190 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
191 | 191 | return new \WP_Error( |
192 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
192 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
193 | 193 | sprintf( |
194 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
194 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
195 | 195 | $model_name_plural, |
196 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
196 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
197 | 197 | ), |
198 | - array( 'status' => 403 ) |
|
198 | + array('status' => 403) |
|
199 | 199 | ); |
200 | 200 | } |
201 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
202 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
201 | + if ( ! $request->get_header('no_rest_headers')) { |
|
202 | + $this->_set_headers_from_query_params($model, $query_params); |
|
203 | 203 | } |
204 | 204 | /** @type array $results */ |
205 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
205 | + $results = $model->get_all_wpdb_results($query_params); |
|
206 | 206 | $nice_results = array( ); |
207 | - foreach ( $results as $result ) { |
|
208 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
207 | + foreach ($results as $result) { |
|
208 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
209 | 209 | $model, |
210 | 210 | $result, |
211 | 211 | $request |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | * @param \WP_REST_Request $request |
222 | 222 | * @return \WP_Error|array |
223 | 223 | */ |
224 | - protected function _get_entities_from_relation( $primary_model_query_params, $relation, $request ) { |
|
225 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
224 | + protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) { |
|
225 | + $context = $this->validate_context($request->get_param('caps')); |
|
226 | 226 | $model = $relation->get_this_model(); |
227 | 227 | $related_model = $relation->get_other_model(); |
228 | - if( ! isset( $primary_model_query_params[0]) ) { |
|
228 | + if ( ! isset($primary_model_query_params[0])) { |
|
229 | 229 | $primary_model_query_params[0] = array(); |
230 | 230 | } |
231 | 231 | //check if they can access the 1st model object |
@@ -233,60 +233,60 @@ discard block |
||
233 | 233 | 0 => $primary_model_query_params[0], |
234 | 234 | 'limit' => 1 |
235 | 235 | ); |
236 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
237 | - $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included( $primary_model_query_params ); |
|
236 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
237 | + $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
238 | 238 | } |
239 | 239 | $restricted_query_params = $primary_model_query_params; |
240 | - $restricted_query_params[ 'caps' ] = $context; |
|
241 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
242 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
240 | + $restricted_query_params['caps'] = $context; |
|
241 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
242 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
243 | 243 | |
244 | - if( |
|
244 | + if ( |
|
245 | 245 | ! ( |
246 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
247 | - && $model->exists( $restricted_query_params ) |
|
246 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
247 | + && $model->exists($restricted_query_params) |
|
248 | 248 | ) |
249 | - ){ |
|
250 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
251 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
252 | - }else{ |
|
253 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
249 | + ) { |
|
250 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
251 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
252 | + } else { |
|
253 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
254 | 254 | } |
255 | 255 | return new \WP_Error( |
256 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
256 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
257 | 257 | sprintf( |
258 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
258 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
259 | 259 | $related_model_name_maybe_plural, |
260 | 260 | $relation->get_this_model()->get_this_model_name(), |
261 | 261 | implode( |
262 | 262 | ',', |
263 | 263 | array_keys( |
264 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
264 | + Capabilities::get_missing_permissions($related_model, $context) |
|
265 | 265 | ) |
266 | 266 | ) |
267 | 267 | ), |
268 | - array( 'status' => 403 ) |
|
268 | + array('status' => 403) |
|
269 | 269 | ); |
270 | 270 | } |
271 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
272 | - foreach( $primary_model_query_params[0] as $where_condition_key => $where_condition_value ) { |
|
273 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $where_condition_key ] = $where_condition_value; |
|
271 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
272 | + foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
273 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$where_condition_key] = $where_condition_value; |
|
274 | 274 | } |
275 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
276 | - $query_params[ 'caps' ] = $context; |
|
277 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
278 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
275 | + $query_params['default_where_conditions'] = 'none'; |
|
276 | + $query_params['caps'] = $context; |
|
277 | + if ( ! $request->get_header('no_rest_headers')) { |
|
278 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
279 | 279 | } |
280 | 280 | /** @type array $results */ |
281 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
281 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
282 | 282 | $nice_results = array(); |
283 | - foreach( $results as $result ) { |
|
283 | + foreach ($results as $result) { |
|
284 | 284 | $nice_result = $this->create_entity_from_wpdb_result( |
285 | 285 | $relation->get_other_model(), |
286 | 286 | $result, |
287 | 287 | $request |
288 | 288 | ); |
289 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
289 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
290 | 290 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
291 | 291 | //if there are conflicts we prefer the properties from the main model |
292 | 292 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -294,18 +294,18 @@ discard block |
||
294 | 294 | $result, |
295 | 295 | $request |
296 | 296 | ); |
297 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
297 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
298 | 298 | //but keep the meta stuff from the main model |
299 | - if( isset( $nice_result['meta'] ) ){ |
|
299 | + if (isset($nice_result['meta'])) { |
|
300 | 300 | $joined_result['meta'] = $nice_result['meta']; |
301 | 301 | } |
302 | 302 | $nice_result = $joined_result; |
303 | 303 | } |
304 | 304 | $nice_results[] = $nice_result; |
305 | 305 | } |
306 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
307 | - return array_shift( $nice_results ); |
|
308 | - }else{ |
|
306 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
307 | + return array_shift($nice_results); |
|
308 | + } else { |
|
309 | 309 | return $nice_results; |
310 | 310 | } |
311 | 311 | } |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | * @return array|\WP_Error |
325 | 325 | * @throws \EE_Error |
326 | 326 | */ |
327 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
328 | - if( ! $relation->get_this_model()->has_primary_key_field() ) { |
|
327 | + public function get_entities_from_relation($id, $relation, $request) { |
|
328 | + if ( ! $relation->get_this_model()->has_primary_key_field()) { |
|
329 | 329 | throw new \EE_Error( |
330 | 330 | sprintf( |
331 | - __( 'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', 'event_espresso'), |
|
331 | + __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', 'event_espresso'), |
|
332 | 332 | $relation->get_this_model()->get_this_model_name() |
333 | 333 | ) |
334 | 334 | ); |
@@ -352,30 +352,30 @@ discard block |
||
352 | 352 | * @param array $query_params |
353 | 353 | * @return void |
354 | 354 | */ |
355 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
356 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
357 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
355 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
356 | + $this->_set_debug_info('model query params', $query_params); |
|
357 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
358 | 358 | //normally the limit to a 2-part array, where the 2nd item is the limit |
359 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
360 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
359 | + if ( ! isset($query_params['limit'])) { |
|
360 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
361 | 361 | } |
362 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
363 | - $limit_parts = $query_params[ 'limit' ]; |
|
362 | + if (is_array($query_params['limit'])) { |
|
363 | + $limit_parts = $query_params['limit']; |
|
364 | 364 | } else { |
365 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
366 | - if( count( $limit_parts ) == 1 ){ |
|
367 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
365 | + $limit_parts = explode(',', $query_params['limit']); |
|
366 | + if (count($limit_parts) == 1) { |
|
367 | + $limit_parts = array(0, $limit_parts[0]); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | //remove the group by and having parts of the query, as those will |
371 | 371 | //make the sql query return an array of values, instead of just a single value |
372 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
373 | - $count = $model->count( $query_params, null, true ); |
|
372 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
373 | + $count = $model->count($query_params, null, true); |
|
374 | 374 | |
375 | - $pages = $count / $limit_parts[ 1 ]; |
|
376 | - $this->_set_response_header( 'Total', $count, false ); |
|
377 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
378 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
375 | + $pages = $count / $limit_parts[1]; |
|
376 | + $this->_set_response_header('Total', $count, false); |
|
377 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
378 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | |
@@ -388,50 +388,50 @@ discard block |
||
388 | 388 | * @param string $deprecated no longer used |
389 | 389 | * @return array ready for being converted into json for sending to client |
390 | 390 | */ |
391 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
392 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
391 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
392 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
393 | 393 | //ok so this was called in the old style, where the 3rd arg was |
394 | 394 | //$include, and the 4th arg was $context |
395 | 395 | //now setup the request just to avoid fatal errors, although we won't be able |
396 | 396 | //to truly make use of it because it's kinda devoid of info |
397 | 397 | $rest_request = new \WP_REST_Request(); |
398 | - $rest_request->set_param( 'include', $rest_request ); |
|
399 | - $rest_request->set_param( 'caps', $deprecated ); |
|
398 | + $rest_request->set_param('include', $rest_request); |
|
399 | + $rest_request->set_param('caps', $deprecated); |
|
400 | 400 | } |
401 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
402 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
401 | + if ($rest_request->get_param('caps') == null) { |
|
402 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
403 | 403 | } |
404 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
405 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
406 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
407 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
408 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array, $db_row ); |
|
404 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
405 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
406 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
407 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
408 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
409 | 409 | $entity_array = apply_filters( |
410 | 410 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
411 | 411 | $entity_array, |
412 | 412 | $model, |
413 | - $rest_request->get_param( 'caps' ), |
|
413 | + $rest_request->get_param('caps'), |
|
414 | 414 | $rest_request, |
415 | 415 | $this |
416 | 416 | ); |
417 | 417 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
418 | 418 | $entity_array, |
419 | 419 | $model, |
420 | - $rest_request->get_param( 'caps' ), |
|
420 | + $rest_request->get_param('caps'), |
|
421 | 421 | $this->get_model_version_info(), |
422 | 422 | $model->get_index_primary_key_string( |
423 | - $model->deduce_fields_n_values_from_cols_n_values($db_row ) |
|
423 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
424 | 424 | ) |
425 | 425 | ); |
426 | 426 | $this->_set_debug_info( |
427 | 427 | 'inaccessible fields', |
428 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
428 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
429 | 429 | ); |
430 | 430 | return apply_filters( |
431 | 431 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
432 | 432 | $result_without_inaccessible_fields, |
433 | 433 | $model, |
434 | - $rest_request->get_param( 'caps' ) |
|
434 | + $rest_request->get_param('caps') |
|
435 | 435 | ); |
436 | 436 | } |
437 | 437 | |
@@ -443,39 +443,39 @@ discard block |
||
443 | 443 | * @param array $db_row |
444 | 444 | * @return array entity mostly ready for converting to JSON and sending in the response |
445 | 445 | */ |
446 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
447 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
448 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
449 | - foreach( $result as $field_name => $raw_field_value ) { |
|
446 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
447 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
448 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
449 | + foreach ($result as $field_name => $raw_field_value) { |
|
450 | 450 | $field_obj = $model->field_settings_for($field_name); |
451 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
452 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
453 | - unset( $result[ $field_name ] ); |
|
454 | - }elseif( |
|
455 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
456 | - ){ |
|
457 | - $result[ $field_name ] = array( |
|
458 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
459 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
451 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
452 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
453 | + unset($result[$field_name]); |
|
454 | + }elseif ( |
|
455 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
456 | + ) { |
|
457 | + $result[$field_name] = array( |
|
458 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
459 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
460 | 460 | ); |
461 | - }elseif( |
|
462 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
463 | - ){ |
|
464 | - $result[ $field_name ] = array( |
|
465 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
466 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
461 | + }elseif ( |
|
462 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
463 | + ) { |
|
464 | + $result[$field_name] = array( |
|
465 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
466 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
467 | 467 | ); |
468 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
469 | - if( $field_value instanceof \DateTime ) { |
|
468 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
469 | + if ($field_value instanceof \DateTime) { |
|
470 | 470 | $timezone = $field_value->getTimezone(); |
471 | - $field_value->setTimezone( new \DateTimeZone( 'UTC' ) ); |
|
472 | - $result[ $field_name . '_gmt' ] = Model_Data_Translator::prepare_field_value_for_json( |
|
471 | + $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
472 | + $result[$field_name.'_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
473 | 473 | $field_obj, |
474 | 474 | $field_value, |
475 | 475 | $this->get_model_version_info()->requested_version() |
476 | 476 | ); |
477 | - $field_value->setTimezone( $timezone ); |
|
478 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
477 | + $field_value->setTimezone($timezone); |
|
478 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
479 | 479 | $field_obj, |
480 | 480 | $field_value, |
481 | 481 | $this->get_model_version_info()->requested_version() |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | } |
484 | 484 | |
485 | 485 | } else { |
486 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
486 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
487 | 487 | $field_obj, |
488 | - $field_obj->prepare_for_get( $field_value ), |
|
488 | + $field_obj->prepare_for_get($field_value), |
|
489 | 489 | $this->get_model_version_info()->requested_version() |
490 | 490 | ); |
491 | 491 | } |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | * @param array $entity_array |
501 | 501 | * @return array modified entity |
502 | 502 | */ |
503 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
504 | - if( $model instanceof \EEM_CPT_Base ) { |
|
505 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
503 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
504 | + if ($model instanceof \EEM_CPT_Base) { |
|
505 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
506 | 506 | } |
507 | 507 | return $entity_array; |
508 | 508 | } |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @param array $entity_array |
517 | 517 | * @return array the _links item in the entity |
518 | 518 | */ |
519 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
519 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
520 | 520 | //add basic links |
521 | 521 | $links = array(); |
522 | - if( $model->has_primary_key_field() ) { |
|
522 | + if ($model->has_primary_key_field()) { |
|
523 | 523 | $links['self'] = array( |
524 | 524 | array( |
525 | 525 | 'href' => $this->get_versioned_link_to( |
526 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
526 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
527 | 527 | ) |
528 | 528 | ) |
529 | 529 | ); |
@@ -531,33 +531,33 @@ discard block |
||
531 | 531 | $links['collection'] = array( |
532 | 532 | array( |
533 | 533 | 'href' => $this->get_versioned_link_to( |
534 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
534 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
535 | 535 | ) |
536 | 536 | ) |
537 | 537 | ); |
538 | 538 | |
539 | 539 | //add link to the wp core endpoint, if wp api is active |
540 | 540 | global $wp_rest_server; |
541 | - if( $model instanceof \EEM_CPT_Base && |
|
541 | + if ($model instanceof \EEM_CPT_Base && |
|
542 | 542 | $wp_rest_server instanceof \WP_REST_Server && |
543 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) && |
|
544 | - $model->has_primary_key_field() ) { |
|
545 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
543 | + $wp_rest_server->get_route_options('/wp/v2/posts') && |
|
544 | + $model->has_primary_key_field()) { |
|
545 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
546 | 546 | array( |
547 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
547 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
548 | 548 | 'single' => true |
549 | 549 | ) |
550 | 550 | ); |
551 | 551 | } |
552 | 552 | |
553 | 553 | //add links to related models |
554 | - if( $model->has_primary_key_field() ) { |
|
555 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
556 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
557 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
554 | + if ($model->has_primary_key_field()) { |
|
555 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
556 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
557 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
558 | 558 | array( |
559 | 559 | 'href' => $this->get_versioned_link_to( |
560 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
560 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
561 | 561 | ), |
562 | 562 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
563 | 563 | ) |
@@ -575,52 +575,52 @@ discard block |
||
575 | 575 | * @param array $db_row |
576 | 576 | * @return array the modified entity |
577 | 577 | */ |
578 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array, $db_row = array() ) { |
|
578 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array, $db_row = array()) { |
|
579 | 579 | //if $db_row not included, hope the entity array has what we need |
580 | - if( ! $db_row ) { |
|
580 | + if ( ! $db_row) { |
|
581 | 581 | $db_row = $entity_array; |
582 | 582 | } |
583 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
584 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
583 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
584 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
585 | 585 | //if they passed in * or didn't specify any includes, return everything |
586 | - if( ! in_array( '*', $includes_for_this_model ) |
|
587 | - && ! empty( $includes_for_this_model ) ) { |
|
588 | - if( $model->has_primary_key_field() ) { |
|
586 | + if ( ! in_array('*', $includes_for_this_model) |
|
587 | + && ! empty($includes_for_this_model)) { |
|
588 | + if ($model->has_primary_key_field()) { |
|
589 | 589 | //always include the primary key. ya just gotta know that at least |
590 | 590 | $includes_for_this_model[] = $model->primary_key_name(); |
591 | 591 | } |
592 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
592 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
593 | 593 | $includes_for_this_model[] = '_calculated_fields'; |
594 | 594 | } |
595 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
595 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
596 | 596 | } |
597 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
598 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
597 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
598 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
599 | 599 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
600 | - $rest_request->get_param( 'include' ), |
|
600 | + $rest_request->get_param('include'), |
|
601 | 601 | $relation_name |
602 | 602 | ); |
603 | 603 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
604 | - $rest_request->get_param( 'calculate' ), |
|
604 | + $rest_request->get_param('calculate'), |
|
605 | 605 | $relation_name |
606 | 606 | ); |
607 | 607 | //did they specify they wanted to include a related model, or |
608 | 608 | //specific fields from a related model? |
609 | 609 | //or did they specify to calculate a field from a related model? |
610 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
610 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
611 | 611 | //if so, we should include at least some part of the related model |
612 | 612 | $pretend_related_request = new \WP_REST_Request(); |
613 | 613 | $pretend_related_request->set_query_params( |
614 | 614 | array( |
615 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
615 | + 'caps' => $rest_request->get_param('caps'), |
|
616 | 616 | 'include' => $related_fields_to_include, |
617 | 617 | 'calculate' => $related_fields_to_calculate, |
618 | 618 | ) |
619 | 619 | ); |
620 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
620 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
621 | 621 | $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
622 | 622 | $model->get_index_primary_key_string( |
623 | - $model->deduce_fields_n_values_from_cols_n_values( $db_row ) |
|
623 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
624 | 624 | ) |
625 | 625 | ); |
626 | 626 | $related_results = $this->_get_entities_from_relation( |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | $relation_obj, |
629 | 629 | $pretend_related_request |
630 | 630 | ); |
631 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
631 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
632 | 632 | ? null |
633 | 633 | : $related_results; |
634 | 634 | } |
@@ -642,8 +642,8 @@ discard block |
||
642 | 642 | * @param array $arr |
643 | 643 | * @return array |
644 | 644 | */ |
645 | - private function _remove_model_names_from_array( $arr ) { |
|
646 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
645 | + private function _remove_model_names_from_array($arr) { |
|
646 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
647 | 647 | } |
648 | 648 | /** |
649 | 649 | * Gets the calculated fields for the response |
@@ -653,15 +653,15 @@ discard block |
||
653 | 653 | * @param \WP_REST_Request $rest_request |
654 | 654 | * @return \stdClass the _calculations item in the entity |
655 | 655 | */ |
656 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
656 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
657 | 657 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
658 | - $rest_request->get_param( 'calculate' ), |
|
658 | + $rest_request->get_param('calculate'), |
|
659 | 659 | '' |
660 | 660 | ); |
661 | 661 | //note: setting calculate=* doesn't do anything |
662 | 662 | $calculated_fields_to_return = new \stdClass(); |
663 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
664 | - try{ |
|
663 | + foreach ($calculated_fields as $field_to_calculate) { |
|
664 | + try { |
|
665 | 665 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
666 | 666 | null, |
667 | 667 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -673,10 +673,10 @@ discard block |
||
673 | 673 | ), |
674 | 674 | $this->get_model_version_info()->requested_version() |
675 | 675 | ); |
676 | - } catch( Rest_Exception $e ) { |
|
676 | + } catch (Rest_Exception $e) { |
|
677 | 677 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
678 | 678 | $this->_set_response_header( |
679 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
679 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
680 | 680 | $e->getMessage(), |
681 | 681 | true |
682 | 682 | ); |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
691 | 691 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
692 | 692 | */ |
693 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
693 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
694 | 694 | return rest_url( |
695 | 695 | \EED_Core_Rest_Api::ee_api_namespace |
696 | 696 | . $this->get_model_version_info()->requested_version() |
@@ -706,11 +706,11 @@ discard block |
||
706 | 706 | * @param \EE_Model_Relation_Base $relation_obj |
707 | 707 | * @return string |
708 | 708 | */ |
709 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
710 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
711 | - return strtolower( $relation_name ); |
|
712 | - }else{ |
|
713 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
709 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
710 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
711 | + return strtolower($relation_name); |
|
712 | + } else { |
|
713 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
@@ -723,43 +723,43 @@ discard block |
||
723 | 723 | * @param \WP_REST_Request $request |
724 | 724 | * @return array|\WP_Error |
725 | 725 | */ |
726 | - public function get_entity_from_model( $model, $request ) { |
|
727 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
728 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
726 | + public function get_entity_from_model($model, $request) { |
|
727 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
728 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
729 | 729 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
730 | 730 | } |
731 | 731 | $restricted_query_params = $query_params; |
732 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
733 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
734 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
735 | - if ( ! empty ( $model_rows ) ) { |
|
732 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
733 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
734 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
735 | + if ( ! empty ($model_rows)) { |
|
736 | 736 | return $this->create_entity_from_wpdb_result( |
737 | 737 | $model, |
738 | - array_shift( $model_rows ), |
|
738 | + array_shift($model_rows), |
|
739 | 739 | $request ); |
740 | 740 | } else { |
741 | 741 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
742 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
743 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
744 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
742 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
743 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
744 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
745 | 745 | //you got shafted- it existed but we didn't want to tell you! |
746 | 746 | return new \WP_Error( |
747 | 747 | 'rest_user_cannot_read', |
748 | 748 | sprintf( |
749 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
750 | - strtolower( $model->get_this_model_name() ), |
|
749 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
750 | + strtolower($model->get_this_model_name()), |
|
751 | 751 | Capabilities::get_missing_permissions_string( |
752 | 752 | $model, |
753 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
753 | + $this->validate_context($request->get_param('caps')) ) |
|
754 | 754 | ), |
755 | - array( 'status' => 403 ) |
|
755 | + array('status' => 403) |
|
756 | 756 | ); |
757 | 757 | } else { |
758 | 758 | //it's not you. It just doesn't exist |
759 | 759 | return new \WP_Error( |
760 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
761 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
762 | - array( 'status' => 404 ) |
|
760 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
761 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
762 | + array('status' => 404) |
|
763 | 763 | ); |
764 | 764 | } |
765 | 765 | } |
@@ -772,14 +772,14 @@ discard block |
||
772 | 772 | * @param string $context |
773 | 773 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
774 | 774 | */ |
775 | - public function validate_context( $context ) { |
|
776 | - if( ! $context ) { |
|
775 | + public function validate_context($context) { |
|
776 | + if ( ! $context) { |
|
777 | 777 | $context = \EEM_Base::caps_read; |
778 | 778 | } |
779 | 779 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
780 | - if( in_array( $context, $valid_contexts ) ){ |
|
780 | + if (in_array($context, $valid_contexts)) { |
|
781 | 781 | return $context; |
782 | - }else{ |
|
782 | + } else { |
|
783 | 783 | return \EEM_Base::caps_read; |
784 | 784 | } |
785 | 785 | } |
@@ -798,87 +798,87 @@ discard block |
||
798 | 798 | * that absolutely no results should be returned |
799 | 799 | * @throws \EE_Error |
800 | 800 | */ |
801 | - public function create_model_query_params( $model, $query_parameters ) { |
|
801 | + public function create_model_query_params($model, $query_parameters) { |
|
802 | 802 | $model_query_params = array( ); |
803 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
804 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
805 | - $query_parameters[ 'where' ], |
|
803 | + if (isset($query_parameters['where'])) { |
|
804 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
805 | + $query_parameters['where'], |
|
806 | 806 | $model, |
807 | 807 | $this->get_model_version_info()->requested_version() |
808 | 808 | ); |
809 | 809 | } |
810 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
811 | - $order_by = $query_parameters[ 'order_by' ]; |
|
812 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
813 | - $order_by = $query_parameters[ 'orderby' ]; |
|
814 | - }else{ |
|
810 | + if (isset($query_parameters['order_by'])) { |
|
811 | + $order_by = $query_parameters['order_by']; |
|
812 | + } elseif (isset($query_parameters['orderby'])) { |
|
813 | + $order_by = $query_parameters['orderby']; |
|
814 | + } else { |
|
815 | 815 | $order_by = null; |
816 | 816 | } |
817 | - if( $order_by !== null ){ |
|
818 | - if( is_array( $order_by ) ) { |
|
819 | - $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json( $order_by ); |
|
817 | + if ($order_by !== null) { |
|
818 | + if (is_array($order_by)) { |
|
819 | + $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
820 | 820 | } else { |
821 | 821 | //it's a single item |
822 | - $order_by = Model_Data_Translator::prepare_field_name_from_json( $order_by ); |
|
822 | + $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
823 | 823 | } |
824 | - $model_query_params[ 'order_by' ] = $order_by; |
|
824 | + $model_query_params['order_by'] = $order_by; |
|
825 | 825 | } |
826 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
827 | - $group_by = $query_parameters[ 'group_by' ]; |
|
828 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
829 | - $group_by = $query_parameters[ 'groupby' ]; |
|
830 | - }else{ |
|
831 | - $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
|
826 | + if (isset($query_parameters['group_by'])) { |
|
827 | + $group_by = $query_parameters['group_by']; |
|
828 | + } elseif (isset($query_parameters['groupby'])) { |
|
829 | + $group_by = $query_parameters['groupby']; |
|
830 | + } else { |
|
831 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
832 | 832 | } |
833 | 833 | //make sure they're all real names |
834 | - if( is_array( $group_by ) ) { |
|
835 | - $group_by = Model_Data_Translator::prepare_field_names_from_json( $group_by ); |
|
834 | + if (is_array($group_by)) { |
|
835 | + $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
836 | 836 | } |
837 | - if( $group_by !== null ){ |
|
838 | - $model_query_params[ 'group_by' ] = $group_by; |
|
837 | + if ($group_by !== null) { |
|
838 | + $model_query_params['group_by'] = $group_by; |
|
839 | 839 | } |
840 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
841 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
842 | - $query_parameters[ 'having' ], |
|
840 | + if (isset($query_parameters['having'])) { |
|
841 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
842 | + $query_parameters['having'], |
|
843 | 843 | $model, |
844 | 844 | $this->get_model_version_info()->requested_version() |
845 | 845 | ); |
846 | 846 | } |
847 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
848 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
847 | + if (isset($query_parameters['order'])) { |
|
848 | + $model_query_params['order'] = $query_parameters['order']; |
|
849 | 849 | } |
850 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
851 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
850 | + if (isset($query_parameters['mine'])) { |
|
851 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
852 | 852 | } |
853 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
853 | + if (isset($query_parameters['limit'])) { |
|
854 | 854 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
855 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
856 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
857 | - }else { |
|
858 | - $limit_array = $query_parameters[ 'limit' ]; |
|
855 | + if ( ! is_array($query_parameters['limit'])) { |
|
856 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
857 | + } else { |
|
858 | + $limit_array = $query_parameters['limit']; |
|
859 | 859 | } |
860 | 860 | $sanitized_limit = array(); |
861 | - foreach( $limit_array as $key => $limit_part ) { |
|
862 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
861 | + foreach ($limit_array as $key => $limit_part) { |
|
862 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
863 | 863 | throw new \EE_Error( |
864 | 864 | sprintf( |
865 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
866 | - json_encode( $query_parameters[ 'limit' ] ) |
|
865 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
866 | + json_encode($query_parameters['limit']) |
|
867 | 867 | ) |
868 | 868 | ); |
869 | 869 | } |
870 | - $sanitized_limit[] = (int)$limit_part; |
|
870 | + $sanitized_limit[] = (int) $limit_part; |
|
871 | 871 | } |
872 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
873 | - }else{ |
|
874 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
872 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
873 | + } else { |
|
874 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
875 | 875 | } |
876 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
877 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
878 | - }else{ |
|
879 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
876 | + if (isset($query_parameters['caps'])) { |
|
877 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
878 | + } else { |
|
879 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
880 | 880 | } |
881 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
881 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | |
@@ -890,13 +890,13 @@ discard block |
||
890 | 890 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
891 | 891 | * @return array |
892 | 892 | */ |
893 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
893 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
894 | 894 | $model_ready_query_params = array(); |
895 | - foreach( $query_params as $key => $value ) { |
|
896 | - if( is_array( $value ) ) { |
|
897 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
898 | - }else{ |
|
899 | - $model_ready_query_params[ $key ] = $value; |
|
895 | + foreach ($query_params as $key => $value) { |
|
896 | + if (is_array($value)) { |
|
897 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
898 | + } else { |
|
899 | + $model_ready_query_params[$key] = $value; |
|
900 | 900 | } |
901 | 901 | } |
902 | 902 | return $model_ready_query_params; |
@@ -910,13 +910,13 @@ discard block |
||
910 | 910 | * @param $query_params |
911 | 911 | * @return array |
912 | 912 | */ |
913 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
913 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
914 | 914 | $model_ready_query_params = array(); |
915 | - foreach( $query_params as $key => $value ) { |
|
916 | - if( is_array( $value ) ) { |
|
917 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
915 | + foreach ($query_params as $key => $value) { |
|
916 | + if (is_array($value)) { |
|
917 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
918 | 918 | } else { |
919 | - $model_ready_query_params[ $key ] = $value; |
|
919 | + $model_ready_query_params[$key] = $value; |
|
920 | 920 | } |
921 | 921 | } |
922 | 922 | return $model_ready_query_params; |
@@ -931,33 +931,33 @@ discard block |
||
931 | 931 | * we only return strings starting with that and a period; if no prefix was specified |
932 | 932 | * we return all items containing NO periods |
933 | 933 | */ |
934 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
935 | - if( is_string( $string_to_explode ) ) { |
|
936 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
937 | - } else if( is_array( $string_to_explode ) ) { |
|
934 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
935 | + if (is_string($string_to_explode)) { |
|
936 | + $exploded_contents = explode(',', $string_to_explode); |
|
937 | + } else if (is_array($string_to_explode)) { |
|
938 | 938 | $exploded_contents = $string_to_explode; |
939 | 939 | } else { |
940 | 940 | $exploded_contents = array(); |
941 | 941 | } |
942 | 942 | //if the string was empty, we want an empty array |
943 | - $exploded_contents = array_filter( $exploded_contents ); |
|
943 | + $exploded_contents = array_filter($exploded_contents); |
|
944 | 944 | $contents_with_prefix = array(); |
945 | - foreach( $exploded_contents as $item ) { |
|
946 | - $item = trim( $item ); |
|
945 | + foreach ($exploded_contents as $item) { |
|
946 | + $item = trim($item); |
|
947 | 947 | //if no prefix was provided, so we look for items with no "." in them |
948 | - if( ! $prefix ) { |
|
948 | + if ( ! $prefix) { |
|
949 | 949 | //does this item have a period? |
950 | - if( strpos( $item, '.' ) === false ) { |
|
950 | + if (strpos($item, '.') === false) { |
|
951 | 951 | //if not, then its what we're looking for |
952 | 952 | $contents_with_prefix[] = $item; |
953 | 953 | } |
954 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
954 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
955 | 955 | //this item has the prefix and a period, grab it |
956 | 956 | $contents_with_prefix[] = substr( |
957 | 957 | $item, |
958 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
958 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
959 | 959 | ); |
960 | - } else if( $item === $prefix ) { |
|
960 | + } else if ($item === $prefix) { |
|
961 | 961 | //this item is JUST the prefix |
962 | 962 | //so let's grab everything after, which is a blank string |
963 | 963 | $contents_with_prefix[] = ''; |
@@ -980,33 +980,33 @@ discard block |
||
980 | 980 | * the fields for that model, with the model's name removed from each. |
981 | 981 | * If $include_string was blank or '*' returns an empty array |
982 | 982 | */ |
983 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
984 | - if( is_array( $include_string ) ) { |
|
985 | - $include_string = implode( ',', $include_string ); |
|
983 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
984 | + if (is_array($include_string)) { |
|
985 | + $include_string = implode(',', $include_string); |
|
986 | 986 | } |
987 | - if( $include_string === '*' || $include_string === '' ) { |
|
987 | + if ($include_string === '*' || $include_string === '') { |
|
988 | 988 | return array(); |
989 | 989 | } |
990 | - $includes = explode( ',', $include_string ); |
|
990 | + $includes = explode(',', $include_string); |
|
991 | 991 | $extracted_fields_to_include = array(); |
992 | - if( $model_name ){ |
|
993 | - foreach( $includes as $field_to_include ) { |
|
994 | - $field_to_include = trim( $field_to_include ); |
|
995 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
992 | + if ($model_name) { |
|
993 | + foreach ($includes as $field_to_include) { |
|
994 | + $field_to_include = trim($field_to_include); |
|
995 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
996 | 996 | //found the model name at the exact start |
997 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
997 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
998 | 998 | $extracted_fields_to_include[] = $field_sans_model_name; |
999 | - }elseif( $field_to_include == $model_name ){ |
|
999 | + }elseif ($field_to_include == $model_name) { |
|
1000 | 1000 | $extracted_fields_to_include[] = '*'; |
1001 | 1001 | } |
1002 | 1002 | } |
1003 | - }else{ |
|
1003 | + } else { |
|
1004 | 1004 | //look for ones with no period |
1005 | - foreach( $includes as $field_to_include ) { |
|
1006 | - $field_to_include = trim( $field_to_include ); |
|
1005 | + foreach ($includes as $field_to_include) { |
|
1006 | + $field_to_include = trim($field_to_include); |
|
1007 | 1007 | if ( |
1008 | - strpos( $field_to_include, '.' ) === false |
|
1009 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
1008 | + strpos($field_to_include, '.') === false |
|
1009 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
1010 | 1010 | ) { |
1011 | 1011 | $extracted_fields_to_include[] = $field_to_include; |
1012 | 1012 | } |
@@ -111,7 +111,7 @@ |
||
111 | 111 | //we only care to do this for frontend reads and when the user can't edit the item |
112 | 112 | if ( |
113 | 113 | $request_type !== \EEM_Base::caps_read |
114 | - || $model->exists( |
|
114 | + || $model->exists( |
|
115 | 115 | $model->alter_query_params_to_restrict_by_ID( |
116 | 116 | $primary_key_string, |
117 | 117 | array( |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
24 | 24 | * @return boolean |
25 | 25 | */ |
26 | - public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) { |
|
26 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) { |
|
27 | 27 | if ( |
28 | 28 | apply_filters( |
29 | 29 | 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | ) { |
35 | 35 | return true; |
36 | 36 | } |
37 | - foreach ( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) { |
|
38 | - if ( $restriction_obj instanceof \EE_Return_None_Where_Conditions ) { |
|
37 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
38 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
39 | 39 | return false; |
40 | 40 | } |
41 | 41 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param string $request_type one of the constants on WP_JSON_Server |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) { |
|
66 | - return $model->caps_missing( $request_type ); |
|
65 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) { |
|
66 | + return $model->caps_missing($request_type); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) { |
|
80 | - return implode( ',', array_keys( self::get_missing_permissions( $model, $model_context ) ) ); |
|
79 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) { |
|
80 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | //if they didn't provide the primary key string, we'll just hope we can figure it out |
104 | 104 | //from the entity (although it's preferred client code does it, because the entity might be missing |
105 | 105 | //necessary fields for creating the primary key string, or they could be named differently) |
106 | - if ( $primary_key_string === null ) { |
|
106 | + if ($primary_key_string === null) { |
|
107 | 107 | $primary_key_string = $model->get_index_primary_key_string( |
108 | - $model->deduce_fields_n_values_from_cols_n_values( $entity ) |
|
108 | + $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | //we only care to do this for frontend reads and when the user can't edit the item |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | ) { |
124 | 124 | return $entity; |
125 | 125 | } |
126 | - foreach ( $model->field_settings() as $field_name => $field_obj ) { |
|
126 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
127 | 127 | if ( |
128 | - $model_version_info->field_has_rendered_format( $field_obj ) |
|
129 | - && isset( $entity[ $field_name ] ) |
|
130 | - && is_array( $entity[ $field_name ] ) |
|
131 | - && isset( $entity[ $field_name ]['raw'] ) |
|
128 | + $model_version_info->field_has_rendered_format($field_obj) |
|
129 | + && isset($entity[$field_name]) |
|
130 | + && is_array($entity[$field_name]) |
|
131 | + && isset($entity[$field_name]['raw']) |
|
132 | 132 | ) { |
133 | - unset( $entity[ $field_name ]['raw'] ); |
|
133 | + unset($entity[$field_name]['raw']); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | //theoretically we may want to filter out specific fields for specific models |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @since 4.6.0 |
601 | 601 | * @global WPDB $wpdb |
602 | 602 | * |
603 | - * @return mixed null|int WP_user ID or NULL |
|
603 | + * @return integer|null null|int WP_user ID or NULL |
|
604 | 604 | */ |
605 | 605 | public static function get_default_creator_id() { |
606 | 606 | global $wpdb; |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @static |
760 | 760 | * @deprecated instead use TableManager::dropTable() |
761 | 761 | * @param string $table_name |
762 | - * @return bool | int |
|
762 | + * @return integer | int |
|
763 | 763 | */ |
764 | 764 | public static function delete_unused_db_table( $table_name ) { |
765 | 765 | return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | * @deprecated instead use TableManager::dropIndex() |
776 | 776 | * @param string $table_name |
777 | 777 | * @param string $index_name |
778 | - * @return bool | int |
|
778 | + * @return integer | int |
|
779 | 779 | */ |
780 | 780 | public static function drop_index( $table_name, $index_name ) { |
781 | 781 | return \EEH_Activation::getTableManager()->dropIndex( $table_name, $index_name ); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | if ( is_array( $hooks_to_fire_at_time ) ) { |
252 | 252 | foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) { |
253 | 253 | if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] ) |
254 | - && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
254 | + && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
255 | 255 | ) { |
256 | 256 | unset( $crons[ $timestamp ][ $hook_name ] ); |
257 | 257 | } |
@@ -736,13 +736,13 @@ discard block |
||
736 | 736 | |
737 | 737 | |
738 | 738 | /** |
739 | - * delete_db_table_if_empty |
|
740 | - * |
|
741 | - * @access public |
|
742 | - * @static |
|
743 | - * @param string $table_name |
|
744 | - * @return bool | int |
|
745 | - */ |
|
739 | + * delete_db_table_if_empty |
|
740 | + * |
|
741 | + * @access public |
|
742 | + * @static |
|
743 | + * @param string $table_name |
|
744 | + * @return bool | int |
|
745 | + */ |
|
746 | 746 | public static function delete_db_table_if_empty( $table_name ) { |
747 | 747 | if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) { |
748 | 748 | return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
@@ -1103,14 +1103,14 @@ discard block |
||
1103 | 1103 | $QSG_ID = reset( $id_col ); |
1104 | 1104 | } else { |
1105 | 1105 | //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
1106 | - EE_Log::instance()->log( |
|
1107 | - __FILE__, |
|
1108 | - __FUNCTION__, |
|
1109 | - sprintf( |
|
1110 | - __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1111 | - $QST_ID ), |
|
1112 | - 'error' ); |
|
1113 | - continue; |
|
1106 | + EE_Log::instance()->log( |
|
1107 | + __FILE__, |
|
1108 | + __FUNCTION__, |
|
1109 | + sprintf( |
|
1110 | + __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1111 | + $QST_ID ), |
|
1112 | + 'error' ); |
|
1113 | + continue; |
|
1114 | 1114 | } |
1115 | 1115 | } |
1116 | 1116 | |
@@ -1118,8 +1118,8 @@ discard block |
||
1118 | 1118 | $wpdb->insert( |
1119 | 1119 | \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group_question' ), |
1120 | 1120 | array( 'QSG_ID' => $QSG_ID, |
1121 | - 'QST_ID' => $QST_ID, |
|
1122 | - 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
1121 | + 'QST_ID' => $QST_ID, |
|
1122 | + 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
1123 | 1123 | ), |
1124 | 1124 | array( '%d', '%d', '%d' ) |
1125 | 1125 | ); |
@@ -1663,8 +1663,8 @@ discard block |
||
1663 | 1663 | } |
1664 | 1664 | } |
1665 | 1665 | } |
1666 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1667 | - remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
1666 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1667 | + remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
1668 | 1668 | |
1669 | 1669 | if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) { |
1670 | 1670 | $db_update_sans_ee4 = array(); |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * EEH_Activation Helper |
4 | 4 | * |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @return \EventEspresso\core\services\database\TableAnalysis |
55 | 55 | */ |
56 | 56 | public static function getTableAnalysis() { |
57 | - if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis ) { |
|
58 | - self::$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | 59 | } |
60 | 60 | return self::$table_analysis; |
61 | 61 | } |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @return \EventEspresso\core\services\database\TableManager |
67 | 67 | */ |
68 | 68 | public static function getTableManager() { |
69 | - if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager ) { |
|
70 | - self::$table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | 71 | } |
72 | 72 | return self::$table_manager; |
73 | 73 | } |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @param $table_name |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - public static function ensure_table_name_has_prefix( $table_name ) { |
|
86 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( $table_name ); |
|
85 | + public static function ensure_table_name_has_prefix($table_name) { |
|
86 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return boolean success, whether the database and folders are setup properly |
112 | 112 | * @throws \EE_Error |
113 | 113 | */ |
114 | - public static function initialize_db_and_folders(){ |
|
114 | + public static function initialize_db_and_folders() { |
|
115 | 115 | $good_filesystem = EEH_Activation::create_upload_directories(); |
116 | 116 | $good_db = EEH_Activation::create_database_tables(); |
117 | 117 | return $good_filesystem && $good_db; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @throws \EE_Error |
129 | 129 | */ |
130 | - public static function initialize_db_content(){ |
|
130 | + public static function initialize_db_content() { |
|
131 | 131 | //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
132 | - if( EEH_Activation::$_initialized_db_content_already_in_this_request ) { |
|
132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | EEH_Activation::remove_cron_tasks(); |
147 | 147 | EEH_Activation::create_cron_tasks(); |
148 | 148 | // remove all TXN locks since that is being done via extra meta now |
149 | - delete_option( 'ee_locked_transactions' ); |
|
149 | + delete_option('ee_locked_transactions'); |
|
150 | 150 | //also, check for CAF default db content |
151 | - do_action( 'AHEE__EEH_Activation__initialize_db_content' ); |
|
151 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
152 | 152 | //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
153 | 153 | //which users really won't care about on initial activation |
154 | 154 | EE_Error::overwrite_success(); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return array |
169 | 169 | * @throws \EE_Error |
170 | 170 | */ |
171 | - public static function get_cron_tasks( $which_to_include ) { |
|
171 | + public static function get_cron_tasks($which_to_include) { |
|
172 | 172 | $cron_tasks = apply_filters( |
173 | 173 | 'FHEE__EEH_Activation__get_cron_tasks', |
174 | 174 | array( |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
178 | 178 | ) |
179 | 179 | ); |
180 | - if ( $which_to_include === 'old' ) { |
|
180 | + if ($which_to_include === 'old') { |
|
181 | 181 | $cron_tasks = array_filter( |
182 | 182 | $cron_tasks, |
183 | - function ( $value ) { |
|
183 | + function($value) { |
|
184 | 184 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
185 | 185 | } |
186 | 186 | ); |
187 | - } elseif ( $which_to_include === 'current' ) { |
|
188 | - $cron_tasks = array_filter( $cron_tasks ); |
|
189 | - } elseif ( WP_DEBUG && $which_to_include !== 'all' ) { |
|
187 | + } elseif ($which_to_include === 'current') { |
|
188 | + $cron_tasks = array_filter($cron_tasks); |
|
189 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
190 | 190 | throw new EE_Error( |
191 | 191 | sprintf( |
192 | 192 | __( |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public static function create_cron_tasks() { |
211 | 211 | |
212 | - foreach( EEH_Activation::get_cron_tasks( 'current' ) as $hook_name => $frequency ) { |
|
213 | - if( ! wp_next_scheduled( $hook_name ) ) { |
|
214 | - wp_schedule_event( time(), $frequency, $hook_name ); |
|
212 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
213 | + if ( ! wp_next_scheduled($hook_name)) { |
|
214 | + wp_schedule_event(time(), $frequency, $hook_name); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
226 | 226 | * @throws \EE_Error |
227 | 227 | */ |
228 | - public static function remove_cron_tasks( $remove_all = true ) { |
|
228 | + public static function remove_cron_tasks($remove_all = true) { |
|
229 | 229 | $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
230 | 230 | $crons = _get_cron_array(); |
231 | - $crons = is_array( $crons ) ? $crons : array(); |
|
231 | + $crons = is_array($crons) ? $crons : array(); |
|
232 | 232 | /* reminder of what $crons look like: |
233 | 233 | * Top-level keys are timestamps, and their values are arrays. |
234 | 234 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
@@ -246,23 +246,23 @@ discard block |
||
246 | 246 | * ... |
247 | 247 | * ... |
248 | 248 | */ |
249 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks( $cron_tasks_to_remove ); |
|
250 | - foreach ( $crons as $timestamp => $hooks_to_fire_at_time ) { |
|
251 | - if ( is_array( $hooks_to_fire_at_time ) ) { |
|
252 | - foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) { |
|
253 | - if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
254 | - && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
249 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
250 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
251 | + if (is_array($hooks_to_fire_at_time)) { |
|
252 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
253 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
254 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
255 | 255 | ) { |
256 | - unset( $crons[ $timestamp ][ $hook_name ] ); |
|
256 | + unset($crons[$timestamp][$hook_name]); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | //also take care of any empty cron timestamps. |
260 | - if ( empty( $hooks_to_fire_at_time ) ) { |
|
261 | - unset( $crons[ $timestamp ] ); |
|
260 | + if (empty($hooks_to_fire_at_time)) { |
|
261 | + unset($crons[$timestamp]); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
265 | - _set_cron_array( $crons ); |
|
265 | + _set_cron_array($crons); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public static function CPT_initialization() { |
279 | 279 | // register Custom Post Types |
280 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
280 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
281 | 281 | flush_rewrite_rules(); |
282 | 282 | } |
283 | 283 | |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @return void |
296 | 296 | */ |
297 | 297 | public static function reset_and_update_config() { |
298 | - do_action( 'AHEE__EE_Config___load_core_config__start', array( 'EEH_Activation', 'load_calendar_config' ) ); |
|
299 | - add_filter( 'FHEE__EE_Config___load_core_config__config_settings', array( 'EEH_Activation', 'migrate_old_config_data' ), 10, 3 ); |
|
298 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
299 | + add_filter('FHEE__EE_Config___load_core_config__config_settings', array('EEH_Activation', 'migrate_old_config_data'), 10, 3); |
|
300 | 300 | //EE_Config::reset(); |
301 | 301 | } |
302 | 302 | |
@@ -309,28 +309,28 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public static function load_calendar_config() { |
311 | 311 | // grab array of all plugin folders and loop thru it |
312 | - $plugins = glob( WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR ); |
|
313 | - if ( empty( $plugins ) ) { |
|
312 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
313 | + if (empty($plugins)) { |
|
314 | 314 | return; |
315 | 315 | } |
316 | - foreach ( $plugins as $plugin_path ) { |
|
316 | + foreach ($plugins as $plugin_path) { |
|
317 | 317 | // grab plugin folder name from path |
318 | - $plugin = basename( $plugin_path ); |
|
318 | + $plugin = basename($plugin_path); |
|
319 | 319 | // drill down to Espresso plugins |
320 | 320 | // then to calendar related plugins |
321 | 321 | if ( |
322 | - strpos( $plugin, 'espresso' ) !== FALSE |
|
323 | - || strpos( $plugin, 'Espresso' ) !== FALSE |
|
324 | - || strpos( $plugin, 'ee4' ) !== FALSE |
|
325 | - || strpos( $plugin, 'EE4' ) !== FALSE |
|
326 | - || strpos( $plugin, 'calendar' ) !== false |
|
322 | + strpos($plugin, 'espresso') !== FALSE |
|
323 | + || strpos($plugin, 'Espresso') !== FALSE |
|
324 | + || strpos($plugin, 'ee4') !== FALSE |
|
325 | + || strpos($plugin, 'EE4') !== FALSE |
|
326 | + || strpos($plugin, 'calendar') !== false |
|
327 | 327 | ) { |
328 | 328 | // this is what we are looking for |
329 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
329 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
330 | 330 | // does it exist in this folder ? |
331 | - if ( is_readable( $calendar_config )) { |
|
331 | + if (is_readable($calendar_config)) { |
|
332 | 332 | // YEAH! let's load it |
333 | - require_once( $calendar_config ); |
|
333 | + require_once($calendar_config); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
@@ -346,21 +346,21 @@ discard block |
||
346 | 346 | * @param \EE_Config $EE_Config |
347 | 347 | * @return \stdClass |
348 | 348 | */ |
349 | - public static function migrate_old_config_data( $settings = array(), $config = '', EE_Config $EE_Config ) { |
|
350 | - $convert_from_array = array( 'addons' ); |
|
349 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) { |
|
350 | + $convert_from_array = array('addons'); |
|
351 | 351 | // in case old settings were saved as an array |
352 | - if ( is_array( $settings ) && in_array( $config, $convert_from_array )) { |
|
352 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
353 | 353 | // convert existing settings to an object |
354 | 354 | $config_array = $settings; |
355 | 355 | $settings = new stdClass(); |
356 | - foreach ( $config_array as $key => $value ){ |
|
357 | - if ( $key === 'calendar' && class_exists( 'EE_Calendar_Config' )) { |
|
358 | - $EE_Config->set_config( 'addons', 'EE_Calendar', 'EE_Calendar_Config', $value ); |
|
356 | + foreach ($config_array as $key => $value) { |
|
357 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
358 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
359 | 359 | } else { |
360 | 360 | $settings->{$key} = $value; |
361 | 361 | } |
362 | 362 | } |
363 | - add_filter( 'FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true' ); |
|
363 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
364 | 364 | } |
365 | 365 | return $settings; |
366 | 366 | } |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public static function deactivate_event_espresso() { |
378 | 378 | // check permissions |
379 | - if ( current_user_can( 'activate_plugins' )) { |
|
380 | - deactivate_plugins( EE_PLUGIN_BASENAME, TRUE ); |
|
379 | + if (current_user_can('activate_plugins')) { |
|
380 | + deactivate_plugins(EE_PLUGIN_BASENAME, TRUE); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
@@ -399,25 +399,25 @@ discard block |
||
399 | 399 | $critical_pages = array( |
400 | 400 | array( |
401 | 401 | 'id' =>'reg_page_id', |
402 | - 'name' => __( 'Registration Checkout', 'event_espresso' ), |
|
402 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
403 | 403 | 'post' => NULL, |
404 | 404 | 'code' => 'ESPRESSO_CHECKOUT' |
405 | 405 | ), |
406 | 406 | array( |
407 | 407 | 'id' => 'txn_page_id', |
408 | - 'name' => __( 'Transactions', 'event_espresso' ), |
|
408 | + 'name' => __('Transactions', 'event_espresso'), |
|
409 | 409 | 'post' => NULL, |
410 | 410 | 'code' => 'ESPRESSO_TXN_PAGE' |
411 | 411 | ), |
412 | 412 | array( |
413 | 413 | 'id' => 'thank_you_page_id', |
414 | - 'name' => __( 'Thank You', 'event_espresso' ), |
|
414 | + 'name' => __('Thank You', 'event_espresso'), |
|
415 | 415 | 'post' => NULL, |
416 | 416 | 'code' => 'ESPRESSO_THANK_YOU' |
417 | 417 | ), |
418 | 418 | array( |
419 | 419 | 'id' => 'cancel_page_id', |
420 | - 'name' => __( 'Registration Cancelled', 'event_espresso' ), |
|
420 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
421 | 421 | 'post' => NULL, |
422 | 422 | 'code' => 'ESPRESSO_CANCELLED' |
423 | 423 | ), |
@@ -425,62 +425,62 @@ discard block |
||
425 | 425 | |
426 | 426 | $EE_Core_Config = EE_Registry::instance()->CFG->core; |
427 | 427 | |
428 | - foreach ( $critical_pages as $critical_page ) { |
|
428 | + foreach ($critical_pages as $critical_page) { |
|
429 | 429 | // is critical page ID set in config ? |
430 | - if ( $EE_Core_Config->{$critical_page[ 'id' ]} !== FALSE ) { |
|
430 | + if ($EE_Core_Config->{$critical_page['id']} !== FALSE) { |
|
431 | 431 | // attempt to find post by ID |
432 | - $critical_page['post'] = get_post( $EE_Core_Config->{$critical_page[ 'id' ]} ); |
|
432 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']} ); |
|
433 | 433 | } |
434 | 434 | // no dice? |
435 | - if ( $critical_page['post'] === null ) { |
|
435 | + if ($critical_page['post'] === null) { |
|
436 | 436 | // attempt to find post by title |
437 | - $critical_page['post'] = self::get_page_by_ee_shortcode( $critical_page['code'] ); |
|
437 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
438 | 438 | // still nothing? |
439 | - if ( $critical_page['post'] === null ) { |
|
440 | - $critical_page = EEH_Activation::create_critical_page( $critical_page ); |
|
439 | + if ($critical_page['post'] === null) { |
|
440 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
441 | 441 | // REALLY? Still nothing ??!?!? |
442 | - if ( $critical_page['post'] === null ) { |
|
443 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
444 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
442 | + if ($critical_page['post'] === null) { |
|
443 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
444 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
445 | 445 | break; |
446 | 446 | } |
447 | 447 | } |
448 | 448 | } |
449 | 449 | // track post_shortcodes |
450 | - if ( $critical_page['post'] ) { |
|
451 | - EEH_Activation::_track_critical_page_post_shortcodes( $critical_page ); |
|
450 | + if ($critical_page['post']) { |
|
451 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
452 | 452 | } |
453 | 453 | // check that Post ID matches critical page ID in config |
454 | 454 | if ( |
455 | - isset( $critical_page['post']->ID ) |
|
456 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page[ 'id' ]} |
|
455 | + isset($critical_page['post']->ID) |
|
456 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
457 | 457 | ) { |
458 | 458 | //update Config with post ID |
459 | - $EE_Core_Config->{$critical_page[ 'id' ]} = $critical_page['post']->ID; |
|
460 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE ) ) { |
|
461 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
462 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
459 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
460 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
461 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
462 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | 466 | $critical_page_problem = |
467 | - ! isset( $critical_page['post']->post_status ) |
|
467 | + ! isset($critical_page['post']->post_status) |
|
468 | 468 | || $critical_page['post']->post_status !== 'publish' |
469 | - || strpos( $critical_page['post']->post_content, $critical_page['code'] ) === FALSE |
|
469 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === FALSE |
|
470 | 470 | ? TRUE |
471 | 471 | : $critical_page_problem; |
472 | 472 | |
473 | 473 | } |
474 | 474 | |
475 | - if ( $critical_page_problem ) { |
|
475 | + if ($critical_page_problem) { |
|
476 | 476 | $msg = sprintf( |
477 | - __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso' ), |
|
478 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' . __('Event Espresso Critical Pages Settings', 'event_espresso') . '</a>' |
|
477 | + __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso'), |
|
478 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'.__('Event Espresso Critical Pages Settings', 'event_espresso').'</a>' |
|
479 | 479 | ); |
480 | - EE_Error::add_persistent_admin_notice( 'critical_page_problem', $msg ); |
|
480 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
481 | 481 | } |
482 | - if ( EE_Error::has_notices() ) { |
|
483 | - EE_Error::get_notices( FALSE, TRUE, TRUE ); |
|
482 | + if (EE_Error::has_notices()) { |
|
483 | + EE_Error::get_notices(FALSE, TRUE, TRUE); |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | * parameter to the shortcode |
493 | 493 | * @return WP_Post or NULl |
494 | 494 | */ |
495 | - public static function get_page_by_ee_shortcode($ee_shortcode){ |
|
495 | + public static function get_page_by_ee_shortcode($ee_shortcode) { |
|
496 | 496 | global $wpdb; |
497 | 497 | $shortcode_and_opening_bracket = '['.$ee_shortcode; |
498 | 498 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
499 | - if($post_id){ |
|
499 | + if ($post_id) { |
|
500 | 500 | return get_post($post_id); |
501 | - }else{ |
|
501 | + } else { |
|
502 | 502 | return NULL; |
503 | 503 | } |
504 | 504 | |
@@ -515,32 +515,32 @@ discard block |
||
515 | 515 | * @param array $critical_page |
516 | 516 | * @return array |
517 | 517 | */ |
518 | - public static function create_critical_page( $critical_page ) { |
|
518 | + public static function create_critical_page($critical_page) { |
|
519 | 519 | |
520 | 520 | $post_args = array( |
521 | 521 | 'post_title' => $critical_page['name'], |
522 | 522 | 'post_status' => 'publish', |
523 | 523 | 'post_type' => 'page', |
524 | 524 | 'comment_status' => 'closed', |
525 | - 'post_content' => '[' . $critical_page['code'] . ']' |
|
525 | + 'post_content' => '['.$critical_page['code'].']' |
|
526 | 526 | ); |
527 | 527 | |
528 | - $post_id = wp_insert_post( $post_args ); |
|
529 | - if ( ! $post_id ) { |
|
528 | + $post_id = wp_insert_post($post_args); |
|
529 | + if ( ! $post_id) { |
|
530 | 530 | $msg = sprintf( |
531 | - __( 'The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso' ), |
|
531 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
532 | 532 | $critical_page['name'] |
533 | 533 | ); |
534 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
534 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
535 | 535 | return $critical_page; |
536 | 536 | } |
537 | 537 | // get newly created post's details |
538 | - if ( ! $critical_page['post'] = get_post( $post_id )) { |
|
538 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
539 | 539 | $msg = sprintf( |
540 | - __( 'The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso' ), |
|
540 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
541 | 541 | $critical_page['name'] |
542 | 542 | ); |
543 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
543 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | return $critical_page; |
@@ -559,35 +559,35 @@ discard block |
||
559 | 559 | * @param array $critical_page |
560 | 560 | * @return void |
561 | 561 | */ |
562 | - private static function _track_critical_page_post_shortcodes( $critical_page = array() ) { |
|
562 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) { |
|
563 | 563 | // check the goods |
564 | - if ( ! $critical_page['post'] instanceof WP_Post ) { |
|
564 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
565 | 565 | $msg = sprintf( |
566 | - __( 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso' ), |
|
566 | + __('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso'), |
|
567 | 567 | $critical_page['name'] |
568 | 568 | ); |
569 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
569 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
570 | 570 | return; |
571 | 571 | } |
572 | 572 | $EE_Core_Config = EE_Registry::instance()->CFG->core; |
573 | 573 | // map shortcode to post |
574 | - $EE_Core_Config->post_shortcodes[ $critical_page['post']->post_name ][ $critical_page['code'] ] = $critical_page['post']->ID; |
|
574 | + $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
575 | 575 | // and make sure it's NOT added to the WP "Posts Page" |
576 | 576 | // name of the WP Posts Page |
577 | 577 | $posts_page = EE_Config::get_page_for_posts(); |
578 | - if ( isset( $EE_Core_Config->post_shortcodes[ $posts_page ] )) { |
|
579 | - unset( $EE_Core_Config->post_shortcodes[ $posts_page ][ $critical_page['code'] ] ); |
|
578 | + if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
579 | + unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
580 | 580 | } |
581 | - if ( $posts_page !== 'posts' && isset( $EE_Core_Config->post_shortcodes['posts'] )) { |
|
582 | - unset( $EE_Core_Config->post_shortcodes['posts'][ $critical_page['code'] ] ); |
|
581 | + if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
582 | + unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
583 | 583 | } |
584 | 584 | // update post_shortcode CFG |
585 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE )) { |
|
585 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
586 | 586 | $msg = sprintf( |
587 | - __( 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso' ), |
|
587 | + __('The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso'), |
|
588 | 588 | $critical_page['name'] |
589 | 589 | ); |
590 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
590 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
@@ -605,24 +605,24 @@ discard block |
||
605 | 605 | public static function get_default_creator_id() { |
606 | 606 | global $wpdb; |
607 | 607 | |
608 | - if ( ! empty( self::$_default_creator_id ) ) { |
|
608 | + if ( ! empty(self::$_default_creator_id)) { |
|
609 | 609 | return self::$_default_creator_id; |
610 | 610 | }/**/ |
611 | 611 | |
612 | - $role_to_check = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator' ); |
|
612 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
613 | 613 | |
614 | 614 | //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
615 | - $pre_filtered_id = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check ); |
|
616 | - if ( $pre_filtered_id !== false ) { |
|
615 | + $pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check); |
|
616 | + if ($pre_filtered_id !== false) { |
|
617 | 617 | return (int) $pre_filtered_id; |
618 | 618 | } |
619 | 619 | |
620 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'capabilities' ); |
|
621 | - $query = $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%' . $role_to_check . '%' ); |
|
622 | - $user_id = $wpdb->get_var( $query ); |
|
623 | - $user_id = apply_filters( 'FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id ); |
|
624 | - if ( $user_id && (int)$user_id ) { |
|
625 | - self::$_default_creator_id = (int)$user_id; |
|
620 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
621 | + $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%'.$role_to_check.'%'); |
|
622 | + $user_id = $wpdb->get_var($query); |
|
623 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
624 | + if ($user_id && (int) $user_id) { |
|
625 | + self::$_default_creator_id = (int) $user_id; |
|
626 | 626 | return self::$_default_creator_id; |
627 | 627 | } else { |
628 | 628 | return NULL; |
@@ -651,28 +651,28 @@ discard block |
||
651 | 651 | * @return void |
652 | 652 | * @throws EE_Error if there are database errors |
653 | 653 | */ |
654 | - public static function create_table( $table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false ) { |
|
655 | - if( apply_filters( 'FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql ) ){ |
|
654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) { |
|
655 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql)) { |
|
656 | 656 | return; |
657 | 657 | } |
658 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
659 | - if ( ! function_exists( 'dbDelta' )) { |
|
660 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
658 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
659 | + if ( ! function_exists('dbDelta')) { |
|
660 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
661 | 661 | } |
662 | 662 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
663 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix( $table_name ); |
|
663 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
664 | 664 | // do we need to first delete an existing version of this table ? |
665 | - if ( $drop_pre_existing_table && $tableAnalysis->tableExists( $wp_table_name ) ){ |
|
665 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
666 | 666 | // ok, delete the table... but ONLY if it's empty |
667 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty( $wp_table_name ); |
|
667 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
668 | 668 | // table is NOT empty, are you SURE you want to delete this table ??? |
669 | - if ( ! $deleted_safely && defined( 'EE_DROP_BAD_TABLES' ) && EE_DROP_BAD_TABLES ){ |
|
670 | - \EEH_Activation::getTableManager()->dropTable( $wp_table_name ); |
|
671 | - } else if ( ! $deleted_safely ) { |
|
669 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
670 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
671 | + } else if ( ! $deleted_safely) { |
|
672 | 672 | // so we should be more cautious rather than just dropping tables so easily |
673 | 673 | EE_Error::add_persistent_admin_notice( |
674 | - 'bad_table_' . $wp_table_name . '_detected', |
|
675 | - sprintf( __( 'Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso' ), |
|
674 | + 'bad_table_'.$wp_table_name.'_detected', |
|
675 | + sprintf(__('Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso'), |
|
676 | 676 | $wp_table_name, |
677 | 677 | "<pre>define( 'EE_DROP_BAD_TABLES', TRUE );</pre>", |
678 | 678 | '<b>wp-config.php</b>', |
@@ -680,8 +680,8 @@ discard block |
||
680 | 680 | TRUE ); |
681 | 681 | } |
682 | 682 | } |
683 | - $engine = str_replace( 'ENGINE=', '', $engine ); |
|
684 | - \EEH_Activation::getTableManager()->createTable( $table_name, $sql, $engine ); |
|
683 | + $engine = str_replace('ENGINE=', '', $engine); |
|
684 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -699,8 +699,8 @@ discard block |
||
699 | 699 | * 'VARCHAR(10)' |
700 | 700 | * @return bool|int |
701 | 701 | */ |
702 | - public static function add_column_if_it_doesnt_exist($table_name,$column_name,$column_info='INT UNSIGNED NOT NULL'){ |
|
703 | - return \EEH_Activation::getTableManager()->addColumn( $table_name, $column_name, $column_info ); |
|
702 | + public static function add_column_if_it_doesnt_exist($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') { |
|
703 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | |
@@ -716,8 +716,8 @@ discard block |
||
716 | 716 | * @param string $table_name, without prefixed $wpdb->prefix |
717 | 717 | * @return array of database column names |
718 | 718 | */ |
719 | - public static function get_fields_on_table( $table_name = NULL ) { |
|
720 | - return \EEH_Activation::getTableManager()->getTableColumns( $table_name ); |
|
719 | + public static function get_fields_on_table($table_name = NULL) { |
|
720 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
721 | 721 | } |
722 | 722 | |
723 | 723 | |
@@ -731,8 +731,8 @@ discard block |
||
731 | 731 | * @param string $table_name |
732 | 732 | * @return bool |
733 | 733 | */ |
734 | - public static function db_table_is_empty( $table_name ) { |
|
735 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ); |
|
734 | + public static function db_table_is_empty($table_name) { |
|
735 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | |
@@ -745,9 +745,9 @@ discard block |
||
745 | 745 | * @param string $table_name |
746 | 746 | * @return bool | int |
747 | 747 | */ |
748 | - public static function delete_db_table_if_empty( $table_name ) { |
|
749 | - if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) { |
|
750 | - return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
|
748 | + public static function delete_db_table_if_empty($table_name) { |
|
749 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
750 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
751 | 751 | } |
752 | 752 | return false; |
753 | 753 | } |
@@ -763,8 +763,8 @@ discard block |
||
763 | 763 | * @param string $table_name |
764 | 764 | * @return bool | int |
765 | 765 | */ |
766 | - public static function delete_unused_db_table( $table_name ) { |
|
767 | - return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
|
766 | + public static function delete_unused_db_table($table_name) { |
|
767 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -779,8 +779,8 @@ discard block |
||
779 | 779 | * @param string $index_name |
780 | 780 | * @return bool | int |
781 | 781 | */ |
782 | - public static function drop_index( $table_name, $index_name ) { |
|
783 | - return \EEH_Activation::getTableManager()->dropIndex( $table_name, $index_name ); |
|
782 | + public static function drop_index($table_name, $index_name) { |
|
783 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -794,27 +794,27 @@ discard block |
||
794 | 794 | * @return boolean success (whether database is setup properly or not) |
795 | 795 | */ |
796 | 796 | public static function create_database_tables() { |
797 | - EE_Registry::instance()->load_core( 'Data_Migration_Manager' ); |
|
797 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
798 | 798 | //find the migration script that sets the database to be compatible with the code |
799 | 799 | $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
800 | - if( $dms_name ){ |
|
801 | - $current_data_migration_script = EE_Registry::instance()->load_dms( $dms_name ); |
|
802 | - $current_data_migration_script->set_migrating( false ); |
|
800 | + if ($dms_name) { |
|
801 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
802 | + $current_data_migration_script->set_migrating(false); |
|
803 | 803 | $current_data_migration_script->schema_changes_before_migration(); |
804 | 804 | $current_data_migration_script->schema_changes_after_migration(); |
805 | - if( $current_data_migration_script->get_errors() ){ |
|
806 | - if( WP_DEBUG ){ |
|
807 | - foreach( $current_data_migration_script->get_errors() as $error ){ |
|
808 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__ ); |
|
805 | + if ($current_data_migration_script->get_errors()) { |
|
806 | + if (WP_DEBUG) { |
|
807 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
808 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
809 | 809 | } |
810 | - }else{ |
|
811 | - EE_Error::add_error( __( 'There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso' ) ); |
|
810 | + } else { |
|
811 | + EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso')); |
|
812 | 812 | } |
813 | 813 | return false; |
814 | 814 | } |
815 | 815 | EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
816 | - }else{ |
|
817 | - EE_Error::add_error( __( 'Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
816 | + } else { |
|
817 | + EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
818 | 818 | return false; |
819 | 819 | } |
820 | 820 | return true; |
@@ -834,27 +834,27 @@ discard block |
||
834 | 834 | public static function initialize_system_questions() { |
835 | 835 | // QUESTION GROUPS |
836 | 836 | global $wpdb; |
837 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group' ); |
|
837 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
838 | 838 | $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
839 | 839 | // what we have |
840 | - $question_groups = $wpdb->get_col( $SQL ); |
|
840 | + $question_groups = $wpdb->get_col($SQL); |
|
841 | 841 | // check the response |
842 | - $question_groups = is_array( $question_groups ) ? $question_groups : array(); |
|
842 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
843 | 843 | // what we should have |
844 | - $QSG_systems = array( 1, 2 ); |
|
844 | + $QSG_systems = array(1, 2); |
|
845 | 845 | // loop thru what we should have and compare to what we have |
846 | - foreach ( $QSG_systems as $QSG_system ) { |
|
846 | + foreach ($QSG_systems as $QSG_system) { |
|
847 | 847 | // reset values array |
848 | 848 | $QSG_values = array(); |
849 | 849 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
850 | - if ( ! in_array( "$QSG_system", $question_groups )) { |
|
850 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
851 | 851 | // add it |
852 | - switch ( $QSG_system ) { |
|
852 | + switch ($QSG_system) { |
|
853 | 853 | |
854 | 854 | case 1: |
855 | 855 | $QSG_values = array( |
856 | - 'QSG_name' => __( 'Personal Information', 'event_espresso' ), |
|
857 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
856 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
857 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
858 | 858 | 'QSG_desc' => '', |
859 | 859 | 'QSG_order' => 1, |
860 | 860 | 'QSG_show_group_name' => 1, |
@@ -866,8 +866,8 @@ discard block |
||
866 | 866 | |
867 | 867 | case 2: |
868 | 868 | $QSG_values = array( |
869 | - 'QSG_name' => __( 'Address Information','event_espresso' ), |
|
870 | - 'QSG_identifier' => 'address-information-' . time(), |
|
869 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
870 | + 'QSG_identifier' => 'address-information-'.time(), |
|
871 | 871 | 'QSG_desc' => '', |
872 | 872 | 'QSG_order' => 2, |
873 | 873 | 'QSG_show_group_name' => 1, |
@@ -879,14 +879,14 @@ discard block |
||
879 | 879 | |
880 | 880 | } |
881 | 881 | // make sure we have some values before inserting them |
882 | - if ( ! empty( $QSG_values )) { |
|
882 | + if ( ! empty($QSG_values)) { |
|
883 | 883 | // insert system question |
884 | 884 | $wpdb->insert( |
885 | 885 | $table_name, |
886 | 886 | $QSG_values, |
887 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d' ) |
|
887 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
888 | 888 | ); |
889 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
889 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
890 | 890 | } |
891 | 891 | } |
892 | 892 | } |
@@ -895,10 +895,10 @@ discard block |
||
895 | 895 | |
896 | 896 | // QUESTIONS |
897 | 897 | global $wpdb; |
898 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question' ); |
|
898 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
899 | 899 | $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
900 | 900 | // what we have |
901 | - $questions = $wpdb->get_col( $SQL ); |
|
901 | + $questions = $wpdb->get_col($SQL); |
|
902 | 902 | // what we should have |
903 | 903 | $QST_systems = array( |
904 | 904 | 'fname', |
@@ -915,25 +915,25 @@ discard block |
||
915 | 915 | $order_for_group_1 = 1; |
916 | 916 | $order_for_group_2 = 1; |
917 | 917 | // loop thru what we should have and compare to what we have |
918 | - foreach ( $QST_systems as $QST_system ) { |
|
918 | + foreach ($QST_systems as $QST_system) { |
|
919 | 919 | // reset values array |
920 | 920 | $QST_values = array(); |
921 | 921 | // if we don't have what we should have |
922 | - if ( ! in_array( $QST_system, $questions )) { |
|
922 | + if ( ! in_array($QST_system, $questions)) { |
|
923 | 923 | // add it |
924 | - switch ( $QST_system ) { |
|
924 | + switch ($QST_system) { |
|
925 | 925 | |
926 | 926 | case 'fname': |
927 | 927 | $QST_values = array( |
928 | - 'QST_display_text' => __( 'First Name', 'event_espresso' ), |
|
929 | - 'QST_admin_label' => __( 'First Name - System Question', 'event_espresso' ), |
|
928 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
929 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
930 | 930 | 'QST_system' => 'fname', |
931 | 931 | 'QST_type' => 'TEXT', |
932 | 932 | 'QST_required' => 1, |
933 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
933 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
934 | 934 | 'QST_order' => 1, |
935 | 935 | 'QST_admin_only' => 0, |
936 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
936 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
937 | 937 | 'QST_wp_user' => self::get_default_creator_id(), |
938 | 938 | 'QST_deleted' => 0 |
939 | 939 | ); |
@@ -941,15 +941,15 @@ discard block |
||
941 | 941 | |
942 | 942 | case 'lname': |
943 | 943 | $QST_values = array( |
944 | - 'QST_display_text' => __( 'Last Name', 'event_espresso' ), |
|
945 | - 'QST_admin_label' => __( 'Last Name - System Question', 'event_espresso' ), |
|
944 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
945 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
946 | 946 | 'QST_system' => 'lname', |
947 | 947 | 'QST_type' => 'TEXT', |
948 | 948 | 'QST_required' => 1, |
949 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
949 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
950 | 950 | 'QST_order' => 2, |
951 | 951 | 'QST_admin_only' => 0, |
952 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
952 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
953 | 953 | 'QST_wp_user' => self::get_default_creator_id(), |
954 | 954 | 'QST_deleted' => 0 |
955 | 955 | ); |
@@ -957,15 +957,15 @@ discard block |
||
957 | 957 | |
958 | 958 | case 'email': |
959 | 959 | $QST_values = array( |
960 | - 'QST_display_text' => __( 'Email Address', 'event_espresso' ), |
|
961 | - 'QST_admin_label' => __( 'Email Address - System Question', 'event_espresso' ), |
|
960 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
961 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
962 | 962 | 'QST_system' => 'email', |
963 | 963 | 'QST_type' => 'EMAIL', |
964 | 964 | 'QST_required' => 1, |
965 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
965 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
966 | 966 | 'QST_order' => 3, |
967 | 967 | 'QST_admin_only' => 0, |
968 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
968 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
969 | 969 | 'QST_wp_user' => self::get_default_creator_id(), |
970 | 970 | 'QST_deleted' => 0 |
971 | 971 | ); |
@@ -973,15 +973,15 @@ discard block |
||
973 | 973 | |
974 | 974 | case 'address': |
975 | 975 | $QST_values = array( |
976 | - 'QST_display_text' => __( 'Address', 'event_espresso' ), |
|
977 | - 'QST_admin_label' => __( 'Address - System Question', 'event_espresso' ), |
|
976 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
977 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
978 | 978 | 'QST_system' => 'address', |
979 | 979 | 'QST_type' => 'TEXT', |
980 | 980 | 'QST_required' => 0, |
981 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
981 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
982 | 982 | 'QST_order' => 4, |
983 | 983 | 'QST_admin_only' => 0, |
984 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
984 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
985 | 985 | 'QST_wp_user' => self::get_default_creator_id(), |
986 | 986 | 'QST_deleted' => 0 |
987 | 987 | ); |
@@ -989,15 +989,15 @@ discard block |
||
989 | 989 | |
990 | 990 | case 'address2': |
991 | 991 | $QST_values = array( |
992 | - 'QST_display_text' => __( 'Address2', 'event_espresso' ), |
|
993 | - 'QST_admin_label' => __( 'Address2 - System Question', 'event_espresso' ), |
|
992 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
993 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
994 | 994 | 'QST_system' => 'address2', |
995 | 995 | 'QST_type' => 'TEXT', |
996 | 996 | 'QST_required' => 0, |
997 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
997 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
998 | 998 | 'QST_order' => 5, |
999 | 999 | 'QST_admin_only' => 0, |
1000 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
1000 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1001 | 1001 | 'QST_wp_user' => self::get_default_creator_id(), |
1002 | 1002 | 'QST_deleted' => 0 |
1003 | 1003 | ); |
@@ -1005,15 +1005,15 @@ discard block |
||
1005 | 1005 | |
1006 | 1006 | case 'city': |
1007 | 1007 | $QST_values = array( |
1008 | - 'QST_display_text' => __( 'City', 'event_espresso' ), |
|
1009 | - 'QST_admin_label' => __( 'City - System Question', 'event_espresso' ), |
|
1008 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1009 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1010 | 1010 | 'QST_system' => 'city', |
1011 | 1011 | 'QST_type' => 'TEXT', |
1012 | 1012 | 'QST_required' => 0, |
1013 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1013 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1014 | 1014 | 'QST_order' => 6, |
1015 | 1015 | 'QST_admin_only' => 0, |
1016 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
1016 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1017 | 1017 | 'QST_wp_user' => self::get_default_creator_id(), |
1018 | 1018 | 'QST_deleted' => 0 |
1019 | 1019 | ); |
@@ -1021,12 +1021,12 @@ discard block |
||
1021 | 1021 | |
1022 | 1022 | case 'state': |
1023 | 1023 | $QST_values = array( |
1024 | - 'QST_display_text' => __( 'State/Province', 'event_espresso' ), |
|
1025 | - 'QST_admin_label' => __( 'State/Province - System Question', 'event_espresso' ), |
|
1024 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1025 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1026 | 1026 | 'QST_system' => 'state', |
1027 | 1027 | 'QST_type' => 'STATE', |
1028 | 1028 | 'QST_required' => 0, |
1029 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1029 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1030 | 1030 | 'QST_order' => 7, |
1031 | 1031 | 'QST_admin_only' => 0, |
1032 | 1032 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1036,12 +1036,12 @@ discard block |
||
1036 | 1036 | |
1037 | 1037 | case 'country' : |
1038 | 1038 | $QST_values = array( |
1039 | - 'QST_display_text' => __( 'Country', 'event_espresso' ), |
|
1040 | - 'QST_admin_label' => __( 'Country - System Question', 'event_espresso' ), |
|
1039 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1040 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1041 | 1041 | 'QST_system' => 'country', |
1042 | 1042 | 'QST_type' => 'COUNTRY', |
1043 | 1043 | 'QST_required' => 0, |
1044 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1044 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1045 | 1045 | 'QST_order' => 8, |
1046 | 1046 | 'QST_admin_only' => 0, |
1047 | 1047 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1051,15 +1051,15 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | case 'zip': |
1053 | 1053 | $QST_values = array( |
1054 | - 'QST_display_text' => __( 'Zip/Postal Code', 'event_espresso' ), |
|
1055 | - 'QST_admin_label' => __( 'Zip/Postal Code - System Question', 'event_espresso' ), |
|
1054 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1055 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1056 | 1056 | 'QST_system' => 'zip', |
1057 | 1057 | 'QST_type' => 'TEXT', |
1058 | 1058 | 'QST_required' => 0, |
1059 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1059 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1060 | 1060 | 'QST_order' => 9, |
1061 | 1061 | 'QST_admin_only' => 0, |
1062 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
1062 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1063 | 1063 | 'QST_wp_user' => self::get_default_creator_id(), |
1064 | 1064 | 'QST_deleted' => 0 |
1065 | 1065 | ); |
@@ -1067,49 +1067,49 @@ discard block |
||
1067 | 1067 | |
1068 | 1068 | case 'phone': |
1069 | 1069 | $QST_values = array( |
1070 | - 'QST_display_text' => __( 'Phone Number', 'event_espresso' ), |
|
1071 | - 'QST_admin_label' => __( 'Phone Number - System Question', 'event_espresso' ), |
|
1070 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1071 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1072 | 1072 | 'QST_system' => 'phone', |
1073 | 1073 | 'QST_type' => 'TEXT', |
1074 | 1074 | 'QST_required' => 0, |
1075 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1075 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1076 | 1076 | 'QST_order' => 10, |
1077 | 1077 | 'QST_admin_only' => 0, |
1078 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
1078 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1079 | 1079 | 'QST_wp_user' => self::get_default_creator_id(), |
1080 | 1080 | 'QST_deleted' => 0 |
1081 | 1081 | ); |
1082 | 1082 | break; |
1083 | 1083 | |
1084 | 1084 | } |
1085 | - if ( ! empty( $QST_values )) { |
|
1085 | + if ( ! empty($QST_values)) { |
|
1086 | 1086 | // insert system question |
1087 | 1087 | $wpdb->insert( |
1088 | 1088 | $table_name, |
1089 | 1089 | $QST_values, |
1090 | - array( '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d' ) |
|
1090 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1091 | 1091 | ); |
1092 | 1092 | $QST_ID = $wpdb->insert_id; |
1093 | 1093 | |
1094 | 1094 | // QUESTION GROUP QUESTIONS |
1095 | - if( in_array( $QST_system, array( 'fname', 'lname', 'email' ) ) ) { |
|
1095 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1096 | 1096 | $system_question_we_want = EEM_Question_Group::system_personal; |
1097 | 1097 | } else { |
1098 | 1098 | $system_question_we_want = EEM_Question_Group::system_address; |
1099 | 1099 | } |
1100 | - if( isset( $QSG_IDs[ $system_question_we_want ] ) ) { |
|
1101 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1100 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1101 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1102 | 1102 | } else { |
1103 | - $id_col = EEM_Question_Group::instance()->get_col( array( array( 'QSG_system' => $system_question_we_want ) ) ); |
|
1104 | - if( is_array( $id_col ) ) { |
|
1105 | - $QSG_ID = reset( $id_col ); |
|
1103 | + $id_col = EEM_Question_Group::instance()->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1104 | + if (is_array($id_col)) { |
|
1105 | + $QSG_ID = reset($id_col); |
|
1106 | 1106 | } else { |
1107 | 1107 | //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
1108 | 1108 | EE_Log::instance()->log( |
1109 | 1109 | __FILE__, |
1110 | 1110 | __FUNCTION__, |
1111 | 1111 | sprintf( |
1112 | - __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1112 | + __('Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1113 | 1113 | $QST_ID ), |
1114 | 1114 | 'error' ); |
1115 | 1115 | continue; |
@@ -1118,12 +1118,12 @@ discard block |
||
1118 | 1118 | |
1119 | 1119 | // add system questions to groups |
1120 | 1120 | $wpdb->insert( |
1121 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group_question' ), |
|
1122 | - array( 'QSG_ID' => $QSG_ID, |
|
1121 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1122 | + array('QSG_ID' => $QSG_ID, |
|
1123 | 1123 | 'QST_ID' => $QST_ID, |
1124 | - 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
1124 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++ |
|
1125 | 1125 | ), |
1126 | - array( '%d', '%d', '%d' ) |
|
1126 | + array('%d', '%d', '%d') |
|
1127 | 1127 | ); |
1128 | 1128 | } |
1129 | 1129 | } |
@@ -1139,11 +1139,11 @@ discard block |
||
1139 | 1139 | * |
1140 | 1140 | * @throws \EE_Error |
1141 | 1141 | */ |
1142 | - public static function insert_default_payment_methods(){ |
|
1143 | - if( ! EEM_Payment_Method::instance()->count_active( EEM_Payment_Method::scope_cart ) ){ |
|
1144 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
1145 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' ); |
|
1146 | - }else{ |
|
1142 | + public static function insert_default_payment_methods() { |
|
1143 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1144 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1145 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1146 | + } else { |
|
1147 | 1147 | EEM_Payment_Method::instance()->verify_button_urls(); |
1148 | 1148 | } |
1149 | 1149 | } |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | |
1160 | 1160 | global $wpdb; |
1161 | 1161 | |
1162 | - if ( \EEH_Activation::getTableAnalysis()->tableExists( EEM_Status::instance()->table() ) ) { |
|
1162 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1163 | 1163 | |
1164 | 1164 | $table_name = EEM_Status::instance()->table(); |
1165 | 1165 | |
@@ -1235,33 +1235,33 @@ discard block |
||
1235 | 1235 | $folders = array( |
1236 | 1236 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1237 | 1237 | EVENT_ESPRESSO_GATEWAY_DIR, |
1238 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/' |
|
1238 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/' |
|
1241 | 1241 | ); |
1242 | - foreach ( $folders as $folder ) { |
|
1242 | + foreach ($folders as $folder) { |
|
1243 | 1243 | try { |
1244 | - EEH_File::ensure_folder_exists_and_is_writable( $folder ); |
|
1245 | - @ chmod( $folder, 0755 ); |
|
1246 | - } catch( EE_Error $e ){ |
|
1244 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1245 | + @ chmod($folder, 0755); |
|
1246 | + } catch (EE_Error $e) { |
|
1247 | 1247 | EE_Error::add_error( |
1248 | 1248 | sprintf( |
1249 | - __( 'Could not create the folder at "%1$s" because: %2$s', 'event_espresso' ), |
|
1249 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1250 | 1250 | $folder, |
1251 | - '<br />' . $e->getMessage() |
|
1251 | + '<br />'.$e->getMessage() |
|
1252 | 1252 | ), |
1253 | 1253 | __FILE__, __FUNCTION__, __LINE__ |
1254 | 1254 | ); |
1255 | 1255 | //indicate we'll need to fix this later |
1256 | - update_option( EEH_Activation::upload_directories_incomplete_option_name, true ); |
|
1256 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1257 | 1257 | return FALSE; |
1258 | 1258 | } |
1259 | 1259 | } |
1260 | 1260 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1261 | 1261 | //is disabled, there might be activation errors recorded in there |
1262 | - EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs/' ); |
|
1262 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1263 | 1263 | //remember EE's folders are all good |
1264 | - delete_option( EEH_Activation::upload_directories_incomplete_option_name ); |
|
1264 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1265 | 1265 | return TRUE; |
1266 | 1266 | } |
1267 | 1267 | |
@@ -1274,7 +1274,7 @@ discard block |
||
1274 | 1274 | * @return boolean |
1275 | 1275 | */ |
1276 | 1276 | public static function upload_directories_incomplete() { |
1277 | - return get_option( EEH_Activation::upload_directories_incomplete_option_name, false ); |
|
1277 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | 1280 | |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | */ |
1292 | 1292 | public static function generate_default_message_templates() { |
1293 | 1293 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
1294 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
1294 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1295 | 1295 | /* |
1296 | 1296 | * This first method is taking care of ensuring any default messengers |
1297 | 1297 | * that should be made active and have templates generated are done. |
@@ -1327,22 +1327,22 @@ discard block |
||
1327 | 1327 | $active_messengers = $message_resource_manager->active_messengers(); |
1328 | 1328 | $installed_message_types = $message_resource_manager->installed_message_types(); |
1329 | 1329 | $templates_created = false; |
1330 | - foreach ( $active_messengers as $active_messenger ) { |
|
1330 | + foreach ($active_messengers as $active_messenger) { |
|
1331 | 1331 | $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
1332 | 1332 | $default_message_type_names_to_activate = array(); |
1333 | 1333 | // looping through each default message type reported by the messenger |
1334 | 1334 | // and setup the actual message types to activate. |
1335 | - foreach ( $default_message_type_names_for_messenger as $default_message_type_name_for_messenger ) { |
|
1335 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1336 | 1336 | // if already active or has already been activated before we skip |
1337 | 1337 | // (otherwise we might reactivate something user's intentionally deactivated.) |
1338 | 1338 | // we also skip if the message type is not installed. |
1339 | 1339 | if ( |
1340 | - $message_resource_manager->has_message_type_been_activated_for_messenger( $default_message_type_name_for_messenger, $active_messenger->name ) |
|
1340 | + $message_resource_manager->has_message_type_been_activated_for_messenger($default_message_type_name_for_messenger, $active_messenger->name) |
|
1341 | 1341 | || $message_resource_manager->is_message_type_active_for_messenger( |
1342 | 1342 | $active_messenger->name, |
1343 | 1343 | $default_message_type_name_for_messenger |
1344 | 1344 | ) |
1345 | - || ! isset( $installed_message_types[ $default_message_type_name_for_messenger ] ) |
|
1345 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1346 | 1346 | ) { |
1347 | 1347 | continue; |
1348 | 1348 | } |
@@ -1355,7 +1355,7 @@ discard block |
||
1355 | 1355 | false |
1356 | 1356 | ); |
1357 | 1357 | //activate the templates for these message types |
1358 | - if ( ! empty( $default_message_type_names_to_activate ) ) { |
|
1358 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1359 | 1359 | $templates_created = EEH_MSG_Template::generate_new_templates( |
1360 | 1360 | $active_messenger->name, |
1361 | 1361 | $default_message_type_names_for_messenger, |
@@ -1382,18 +1382,18 @@ discard block |
||
1382 | 1382 | EE_Message_Resource_Manager $message_resource_manager |
1383 | 1383 | ) { |
1384 | 1384 | /** @type EE_messenger[] $messengers_to_generate */ |
1385 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation( $message_resource_manager ); |
|
1385 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1386 | 1386 | $installed_message_types = $message_resource_manager->installed_message_types(); |
1387 | 1387 | $templates_generated = false; |
1388 | - foreach ( $messengers_to_generate as $messenger_to_generate ) { |
|
1388 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1389 | 1389 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
1390 | 1390 | //verify the default message types match an installed message type. |
1391 | - foreach ( $default_message_type_names_for_messenger as $key => $name ) { |
|
1391 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1392 | 1392 | if ( |
1393 | - ! isset( $installed_message_types[ $name ] ) |
|
1394 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( $name, $messenger_to_generate->name ) |
|
1393 | + ! isset($installed_message_types[$name]) |
|
1394 | + || $message_resource_manager->has_message_type_been_activated_for_messenger($name, $messenger_to_generate->name) |
|
1395 | 1395 | ) { |
1396 | - unset( $default_message_type_names_for_messenger[ $key ] ); |
|
1396 | + unset($default_message_type_names_for_messenger[$key]); |
|
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | // in previous iterations, the active_messengers option in the db |
@@ -1407,7 +1407,7 @@ discard block |
||
1407 | 1407 | false |
1408 | 1408 | ); |
1409 | 1409 | //create any templates needing created (or will reactivate templates already generated as necessary). |
1410 | - if ( ! empty( $default_message_type_names_for_messenger ) ) { |
|
1410 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1411 | 1411 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
1412 | 1412 | $messenger_to_generate->name, |
1413 | 1413 | $default_message_type_names_for_messenger, |
@@ -1439,18 +1439,18 @@ discard block |
||
1439 | 1439 | $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
1440 | 1440 | |
1441 | 1441 | $messengers_to_generate = array(); |
1442 | - foreach ( $installed_messengers as $installed_messenger ) { |
|
1442 | + foreach ($installed_messengers as $installed_messenger) { |
|
1443 | 1443 | //if installed messenger is a messenger that should be activated on install |
1444 | 1444 | //and is not already active |
1445 | 1445 | //and has never been activated |
1446 | 1446 | if ( |
1447 | 1447 | ! $installed_messenger->activate_on_install |
1448 | - || isset( $active_messengers[ $installed_messenger->name ] ) |
|
1449 | - || isset( $has_activated[ $installed_messenger->name ] ) |
|
1448 | + || isset($active_messengers[$installed_messenger->name]) |
|
1449 | + || isset($has_activated[$installed_messenger->name]) |
|
1450 | 1450 | ) { |
1451 | 1451 | continue; |
1452 | 1452 | } |
1453 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1453 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1454 | 1454 | } |
1455 | 1455 | return $messengers_to_generate; |
1456 | 1456 | } |
@@ -1475,9 +1475,9 @@ discard block |
||
1475 | 1475 | */ |
1476 | 1476 | public static function validate_messages_system() { |
1477 | 1477 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
1478 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
1478 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1479 | 1479 | $message_resource_manager->validate_active_message_types_are_installed(); |
1480 | - do_action( 'AHEE__EEH_Activation__validate_messages_system' ); |
|
1480 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | |
@@ -1490,12 +1490,12 @@ discard block |
||
1490 | 1490 | * @static |
1491 | 1491 | * @return void |
1492 | 1492 | */ |
1493 | - public static function create_no_ticket_prices_array(){ |
|
1493 | + public static function create_no_ticket_prices_array() { |
|
1494 | 1494 | // this creates an array for tracking events that have no active ticket prices created |
1495 | 1495 | // this allows us to warn admins of the situation so that it can be corrected |
1496 | - $espresso_no_ticket_prices = get_option( 'ee_no_ticket_prices', FALSE ); |
|
1497 | - if ( ! $espresso_no_ticket_prices ) { |
|
1498 | - add_option( 'ee_no_ticket_prices', array(), '', FALSE ); |
|
1496 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', FALSE); |
|
1497 | + if ( ! $espresso_no_ticket_prices) { |
|
1498 | + add_option('ee_no_ticket_prices', array(), '', FALSE); |
|
1499 | 1499 | } |
1500 | 1500 | } |
1501 | 1501 | |
@@ -1520,24 +1520,24 @@ discard block |
||
1520 | 1520 | * @global wpdb $wpdb |
1521 | 1521 | * @throws \EE_Error |
1522 | 1522 | */ |
1523 | - public static function delete_all_espresso_cpt_data(){ |
|
1523 | + public static function delete_all_espresso_cpt_data() { |
|
1524 | 1524 | global $wpdb; |
1525 | 1525 | //get all the CPT post_types |
1526 | 1526 | $ee_post_types = array(); |
1527 | - foreach(EE_Registry::instance()->non_abstract_db_models as $model_name){ |
|
1528 | - if ( method_exists( $model_name, 'instance' )) { |
|
1529 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
1530 | - if ( $model_obj instanceof EEM_CPT_Base ) { |
|
1531 | - $ee_post_types[] = $wpdb->prepare("%s",$model_obj->post_type()); |
|
1527 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1528 | + if (method_exists($model_name, 'instance')) { |
|
1529 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1530 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1531 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1532 | 1532 | } |
1533 | 1533 | } |
1534 | 1534 | } |
1535 | 1535 | //get all our CPTs |
1536 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",",$ee_post_types).")"; |
|
1536 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1537 | 1537 | $cpt_ids = $wpdb->get_col($query); |
1538 | 1538 | //delete each post meta and term relations too |
1539 | - foreach($cpt_ids as $post_id){ |
|
1540 | - wp_delete_post($post_id,true); |
|
1539 | + foreach ($cpt_ids as $post_id) { |
|
1540 | + wp_delete_post($post_id, true); |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | 1543 | |
@@ -1549,12 +1549,12 @@ discard block |
||
1549 | 1549 | public static function drop_espresso_tables() { |
1550 | 1550 | $tables = array(); |
1551 | 1551 | // load registry |
1552 | - foreach( EE_Registry::instance()->non_abstract_db_models as $model_name ){ |
|
1553 | - if ( method_exists( $model_name, 'instance' )) { |
|
1554 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
1555 | - if ( $model_obj instanceof EEM_Base ) { |
|
1556 | - foreach ( $model_obj->get_tables() as $table ) { |
|
1557 | - if ( strpos( $table->get_table_name(), 'esp_' ) |
|
1552 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1553 | + if (method_exists($model_name, 'instance')) { |
|
1554 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1555 | + if ($model_obj instanceof EEM_Base) { |
|
1556 | + foreach ($model_obj->get_tables() as $table) { |
|
1557 | + if (strpos($table->get_table_name(), 'esp_') |
|
1558 | 1558 | && |
1559 | 1559 | ( |
1560 | 1560 | is_main_site()//main site? nuke them all |
@@ -1577,10 +1577,10 @@ discard block |
||
1577 | 1577 | 'esp_promotion_rule', |
1578 | 1578 | 'esp_rule' |
1579 | 1579 | ); |
1580 | - foreach( $tables_without_models as $table ){ |
|
1580 | + foreach ($tables_without_models as $table) { |
|
1581 | 1581 | $tables[] = $table; |
1582 | 1582 | } |
1583 | - return \EEH_Activation::getTableManager()->dropTables( $tables ); |
|
1583 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1584 | 1584 | } |
1585 | 1585 | |
1586 | 1586 | /** |
@@ -1592,8 +1592,8 @@ discard block |
||
1592 | 1592 | * @param array $table_names |
1593 | 1593 | * @return array of table names which we deleted |
1594 | 1594 | */ |
1595 | - public static function drop_tables( $table_names ) { |
|
1596 | - return \EEH_Activation::getTableManager()->dropTables( $table_names ); |
|
1595 | + public static function drop_tables($table_names) { |
|
1596 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1597 | 1597 | } |
1598 | 1598 | /** |
1599 | 1599 | * plugin_uninstall |
@@ -1603,7 +1603,7 @@ discard block |
||
1603 | 1603 | * @param bool $remove_all |
1604 | 1604 | * @return void |
1605 | 1605 | */ |
1606 | - public static function delete_all_espresso_tables_and_data( $remove_all = true ) { |
|
1606 | + public static function delete_all_espresso_tables_and_data($remove_all = true) { |
|
1607 | 1607 | global $wpdb; |
1608 | 1608 | self::drop_espresso_tables(); |
1609 | 1609 | |
@@ -1641,50 +1641,50 @@ discard block |
||
1641 | 1641 | 'ee_job_parameters_' => false, |
1642 | 1642 | 'ee_upload_directories_incomplete' => true, |
1643 | 1643 | ); |
1644 | - if( is_main_site() ) { |
|
1645 | - $wp_options_to_delete[ 'ee_network_config' ] = true; |
|
1644 | + if (is_main_site()) { |
|
1645 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1646 | 1646 | } |
1647 | 1647 | |
1648 | 1648 | $undeleted_options = array(); |
1649 | - foreach ( $wp_options_to_delete as $option_name => $no_wildcard ) { |
|
1649 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1650 | 1650 | |
1651 | - if( $no_wildcard ){ |
|
1652 | - if( ! delete_option( $option_name ) ){ |
|
1651 | + if ($no_wildcard) { |
|
1652 | + if ( ! delete_option($option_name)) { |
|
1653 | 1653 | $undeleted_options[] = $option_name; |
1654 | 1654 | } |
1655 | - }else{ |
|
1656 | - $option_names_to_delete_from_wildcard = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'" ); |
|
1657 | - foreach($option_names_to_delete_from_wildcard as $option_name_from_wildcard ){ |
|
1658 | - if( ! delete_option( $option_name_from_wildcard ) ){ |
|
1655 | + } else { |
|
1656 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1657 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1658 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1659 | 1659 | $undeleted_options[] = $option_name_from_wildcard; |
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | } |
1663 | 1663 | } |
1664 | 1664 | //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
1665 | - remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
1665 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1666 | 1666 | |
1667 | - if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) { |
|
1667 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1668 | 1668 | $db_update_sans_ee4 = array(); |
1669 | - foreach($espresso_db_update as $version => $times_activated){ |
|
1670 | - if( (string)$version[0] === '3'){//if its NON EE4 |
|
1669 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1670 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
1671 | 1671 | $db_update_sans_ee4[$version] = $times_activated; |
1672 | 1672 | } |
1673 | 1673 | } |
1674 | - update_option( 'espresso_db_update', $db_update_sans_ee4 ); |
|
1674 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | $errors = ''; |
1678 | - if ( ! empty( $undeleted_options )) { |
|
1678 | + if ( ! empty($undeleted_options)) { |
|
1679 | 1679 | $errors .= sprintf( |
1680 | - __( 'The following wp-options could not be deleted: %s%s', 'event_espresso' ), |
|
1680 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1681 | 1681 | '<br/>', |
1682 | - implode( ',<br/>', $undeleted_options ) |
|
1682 | + implode(',<br/>', $undeleted_options) |
|
1683 | 1683 | ); |
1684 | 1684 | |
1685 | 1685 | } |
1686 | - if ( ! empty( $errors ) ) { |
|
1687 | - EE_Error::add_attention( $errors, __FILE__, __FUNCTION__, __LINE__ ); |
|
1686 | + if ( ! empty($errors)) { |
|
1687 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1688 | 1688 | } |
1689 | 1689 | } |
1690 | 1690 | |
@@ -1694,10 +1694,10 @@ discard block |
||
1694 | 1694 | */ |
1695 | 1695 | public static function last_wpdb_error_code() { |
1696 | 1696 | global $wpdb; |
1697 | - if( $wpdb->use_mysqli ) { |
|
1698 | - return mysqli_errno( $wpdb->dbh ); |
|
1697 | + if ($wpdb->use_mysqli) { |
|
1698 | + return mysqli_errno($wpdb->dbh); |
|
1699 | 1699 | } else { |
1700 | - return mysql_errno( $wpdb->dbh ); |
|
1700 | + return mysql_errno($wpdb->dbh); |
|
1701 | 1701 | } |
1702 | 1702 | } |
1703 | 1703 | |
@@ -1708,14 +1708,14 @@ discard block |
||
1708 | 1708 | * @param string $table_name with or without $wpdb->prefix |
1709 | 1709 | * @return boolean |
1710 | 1710 | */ |
1711 | - public static function table_exists( $table_name ){ |
|
1712 | - return \EEH_Activation::getTableAnalysis()->tableExists( $table_name ); |
|
1711 | + public static function table_exists($table_name) { |
|
1712 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1713 | 1713 | } |
1714 | 1714 | |
1715 | 1715 | /** |
1716 | 1716 | * Resets the cache on EEH_Activation |
1717 | 1717 | */ |
1718 | - public static function reset(){ |
|
1718 | + public static function reset() { |
|
1719 | 1719 | self::$_default_creator_id = NULL; |
1720 | 1720 | self::$_initialized_db_content_already_in_this_request = false; |
1721 | 1721 | } |