@@ -328,7 +328,7 @@ |
||
328 | 328 | * @param int $TXN_ID |
329 | 329 | * @param int $ATT_ID |
330 | 330 | * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required |
331 | - * @return mixed array on success, FALSE on fail |
|
331 | + * @return null|EE_Base_Class array on success, FALSE on fail |
|
332 | 332 | */ |
333 | 333 | public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) { |
334 | 334 | return $this->get_one(array( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | -require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' ); |
|
3 | -require_once ( EE_CLASSES . 'EE_Registration.class.php' ); |
|
2 | +require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
3 | +require_once (EE_CLASSES.'EE_Registration.class.php'); |
|
4 | 4 | /** |
5 | 5 | * |
6 | 6 | * Registration Model |
@@ -101,31 +101,31 @@ discard block |
||
101 | 101 | * 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) |
102 | 102 | * @return \EEM_Registration |
103 | 103 | */ |
104 | - protected function __construct( $timezone = null ) { |
|
105 | - $this->singular_item = __('Registration','event_espresso'); |
|
106 | - $this->plural_item = __('Registrations','event_espresso'); |
|
104 | + protected function __construct($timezone = null) { |
|
105 | + $this->singular_item = __('Registration', 'event_espresso'); |
|
106 | + $this->plural_item = __('Registrations', 'event_espresso'); |
|
107 | 107 | |
108 | 108 | $this->_tables = array( |
109 | - 'Registration'=>new EE_Primary_Table('esp_registration','REG_ID') |
|
109 | + 'Registration'=>new EE_Primary_Table('esp_registration', 'REG_ID') |
|
110 | 110 | ); |
111 | 111 | $this->_fields = array( |
112 | 112 | 'Registration'=>array( |
113 | - 'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID','event_espresso')), |
|
114 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'), |
|
115 | - 'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID','event_espresso'), false, 0, 'Attendee'), |
|
116 | - 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso'), false, 0, 'Transaction'), |
|
117 | - 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID','event_espresso'), false, 0, 'Ticket'), |
|
118 | - 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'), |
|
119 | - 'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred','event_espresso'), false, EE_Datetime_Field::now, $timezone ), |
|
120 | - 'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total','event_espresso'), false, 0), |
|
121 | - 'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration','event_espresso'), false, 0), |
|
122 | - 'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration','event_espresso'), false, ''), |
|
123 | - 'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration','event_espresso'), false, ''), |
|
124 | - 'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration','event_espresso'), false, ''), |
|
125 | - 'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ','event_espresso'), true, 1), |
|
126 | - 'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group','event_espresso'), false, 1), |
|
127 | - 'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending','event_espresso'), false, false), |
|
128 | - 'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false ) |
|
113 | + 'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')), |
|
114 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
115 | + 'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'), |
|
116 | + 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
117 | + 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false, 0, 'Ticket'), |
|
118 | + 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'), |
|
119 | + 'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
120 | + 'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total', 'event_espresso'), false, 0), |
|
121 | + 'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration', 'event_espresso'), false, 0), |
|
122 | + 'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration', 'event_espresso'), false, ''), |
|
123 | + 'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration', 'event_espresso'), false, ''), |
|
124 | + 'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration', 'event_espresso'), false, ''), |
|
125 | + 'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ', 'event_espresso'), true, 1), |
|
126 | + 'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group', 'event_espresso'), false, 1), |
|
127 | + 'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending', 'event_espresso'), false, false), |
|
128 | + 'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false) |
|
129 | 129 | ) |
130 | 130 | ); |
131 | 131 | $this->_model_relations = array( |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | 'Answer'=>new EE_Has_Many_Relation(), |
138 | 138 | 'Checkin'=>new EE_Has_Many_Relation(), |
139 | 139 | 'Registration_Payment' => new EE_Has_Many_Relation(), |
140 | - 'Payment'=>new EE_HABTM_Relation( 'Registration_Payment' ), |
|
141 | - 'Message' => new EE_Has_Many_Any_Relation( false ) //allow deletes even if there are messages in the queue related |
|
140 | + 'Payment'=>new EE_HABTM_Relation('Registration_Payment'), |
|
141 | + 'Message' => new EE_Has_Many_Any_Relation(false) //allow deletes even if there are messages in the queue related |
|
142 | 142 | ); |
143 | 143 | $this->_model_chain_to_wp_user = 'Event'; |
144 | 144 | |
145 | - parent::__construct( $timezone ); |
|
145 | + parent::__construct($timezone); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | * @param bool $translated If true will return the values as singular localized strings |
218 | 218 | * @return array |
219 | 219 | */ |
220 | - public static function reg_status_array( $exclude = array(), $translated = FALSE ) { |
|
221 | - EEM_Registration::instance()->_get_registration_status_array( $exclude ); |
|
222 | - return $translated ? EEM_Status::instance()->localized_status( self::$_reg_status, FALSE, 'sentence') : self::$_reg_status; |
|
220 | + public static function reg_status_array($exclude = array(), $translated = FALSE) { |
|
221 | + EEM_Registration::instance()->_get_registration_status_array($exclude); |
|
222 | + return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, FALSE, 'sentence') : self::$_reg_status; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | |
@@ -230,18 +230,18 @@ discard block |
||
230 | 230 | * @param array $exclude |
231 | 231 | * @return array |
232 | 232 | */ |
233 | - private function _get_registration_status_array( $exclude = array() ) { |
|
233 | + private function _get_registration_status_array($exclude = array()) { |
|
234 | 234 | //in the very rare circumstance that we are deleting a model's table's data |
235 | 235 | //and the table hasn't actually been created, this could have an error |
236 | 236 | /** @type WPDB $wpdb */ |
237 | 237 | global $wpdb; |
238 | - if( EEH_Activation::table_exists( $wpdb->prefix . 'esp_status' ) ){ |
|
239 | - $SQL = 'SELECT STS_ID, STS_code FROM '. $wpdb->prefix . 'esp_status WHERE STS_type = "registration"'; |
|
240 | - $results = $wpdb->get_results( $SQL ); |
|
238 | + if (EEH_Activation::table_exists($wpdb->prefix.'esp_status')) { |
|
239 | + $SQL = 'SELECT STS_ID, STS_code FROM '.$wpdb->prefix.'esp_status WHERE STS_type = "registration"'; |
|
240 | + $results = $wpdb->get_results($SQL); |
|
241 | 241 | self::$_reg_status = array(); |
242 | - foreach ( $results as $status ) { |
|
243 | - if ( ! in_array( $status->STS_ID, $exclude )) { |
|
244 | - self::$_reg_status[ $status->STS_ID ] = $status->STS_code; |
|
242 | + foreach ($results as $status) { |
|
243 | + if ( ! in_array($status->STS_ID, $exclude)) { |
|
244 | + self::$_reg_status[$status->STS_ID] = $status->STS_code; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
@@ -256,15 +256,15 @@ discard block |
||
256 | 256 | * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
257 | 257 | * @return wpdb results array |
258 | 258 | */ |
259 | - public function get_reg_months_and_years( $where_params ) { |
|
259 | + public function get_reg_months_and_years($where_params) { |
|
260 | 260 | $query_params[0] = $where_params; |
261 | 261 | $query_params['group_by'] = array('reg_year', 'reg_month'); |
262 | - $query_params['order_by'] = array( 'REG_date' => 'DESC' ); |
|
262 | + $query_params['order_by'] = array('REG_date' => 'DESC'); |
|
263 | 263 | $columns_to_select = array( |
264 | 264 | 'reg_year' => array('YEAR(REG_date)', '%s'), |
265 | 265 | 'reg_month' => array('MONTHNAME(REG_date)', '%s') |
266 | 266 | ); |
267 | - return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select ); |
|
267 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @param int $ATT_ID |
277 | 277 | * @return EE_Registration[] |
278 | 278 | */ |
279 | - public function get_all_registrations_for_attendee( $ATT_ID = 0 ) { |
|
280 | - if ( ! $ATT_ID ) { |
|
279 | + public function get_all_registrations_for_attendee($ATT_ID = 0) { |
|
280 | + if ( ! $ATT_ID) { |
|
281 | 281 | return FALSE; |
282 | 282 | } |
283 | - return $this->get_all( array( array( 'ATT_ID' => $ATT_ID ))); |
|
283 | + return $this->get_all(array(array('ATT_ID' => $ATT_ID))); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param string $REG_url_link |
292 | 292 | * @return EE_Registration |
293 | 293 | */ |
294 | - public function get_registration_for_reg_url_link($REG_url_link){ |
|
295 | - if(!$REG_url_link){ |
|
294 | + public function get_registration_for_reg_url_link($REG_url_link) { |
|
295 | + if ( ! $REG_url_link) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | return $this->get_one(array(array('REG_url_link'=>$REG_url_link))); |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required |
311 | 311 | * @return mixed array on success, FALSE on fail |
312 | 312 | */ |
313 | - public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) { |
|
313 | + public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) { |
|
314 | 314 | return $this->get_one(array( |
315 | 315 | array( |
316 | 316 | 'TXN_ID'=>$TXN_ID, |
317 | 317 | 'ATT_ID'=>$ATT_ID |
318 | 318 | ), |
319 | - 'limit'=>array( min( ( $att_nmbr-1 ), 0 ), 1 ) |
|
319 | + 'limit'=>array(min(($att_nmbr - 1), 0), 1) |
|
320 | 320 | )); |
321 | 321 | } |
322 | 322 | |
@@ -328,16 +328,16 @@ discard block |
||
328 | 328 | * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
329 | 329 | * @return stdClass[] with properties regDate and total |
330 | 330 | */ |
331 | - public function get_registrations_per_day_report( $period = '-1 month' ) { |
|
331 | + public function get_registrations_per_day_report($period = '-1 month') { |
|
332 | 332 | |
333 | - $sql_date = $this->convert_datetime_for_query( 'REG_date', date("Y-m-d H:i:s", strtotime($period) ), 'Y-m-d H:i:s', 'UTC' ); |
|
334 | - $where = array( 'REG_date' => array( '>=', $sql_date ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ); |
|
333 | + $sql_date = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC'); |
|
334 | + $where = array('REG_date' => array('>=', $sql_date), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)); |
|
335 | 335 | |
336 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_day_report' ) ) { |
|
336 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
337 | 337 | $where['Event.EVT_wp_user'] = get_current_user_id(); |
338 | 338 | } |
339 | 339 | |
340 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'REG_date' ); |
|
340 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date'); |
|
341 | 341 | |
342 | 342 | $results = $this->_get_all_wpdb_results( |
343 | 343 | array( |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | ), |
348 | 348 | OBJECT, |
349 | 349 | array( |
350 | - 'regDate'=>array( 'DATE(' . $query_interval . ')','%s'), |
|
351 | - 'total'=>array('count(REG_ID)','%d') |
|
350 | + 'regDate'=>array('DATE('.$query_interval.')', '%s'), |
|
351 | + 'total'=>array('count(REG_ID)', '%d') |
|
352 | 352 | )); |
353 | 353 | return $results; |
354 | 354 | } |
@@ -363,22 +363,22 @@ discard block |
||
363 | 363 | * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID |
364 | 364 | * (i.e. RAP) |
365 | 365 | */ |
366 | - public function get_registrations_per_day_and_per_status_report( $period = '-1 month' ) { |
|
366 | + public function get_registrations_per_day_and_per_status_report($period = '-1 month') { |
|
367 | 367 | global $wpdb; |
368 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
368 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
369 | 369 | $event_table = $wpdb->posts; |
370 | - $sql_date = date("Y-m-d H:i:s", strtotime($period) ); |
|
370 | + $sql_date = date("Y-m-d H:i:s", strtotime($period)); |
|
371 | 371 | |
372 | 372 | //prepare the query interval for displaying offset |
373 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'dates.REG_date' ); |
|
373 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date'); |
|
374 | 374 | |
375 | 375 | //inner date query |
376 | 376 | $inner_date_query = "SELECT DISTINCT REG_date from $registration_table "; |
377 | 377 | $inner_where = " WHERE"; |
378 | 378 | //exclude events not authored by user if permissions in effect |
379 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
379 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
380 | 380 | $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; |
381 | - $inner_where .= " post_author = " . get_current_user_id() . " AND"; |
|
381 | + $inner_where .= " post_author = ".get_current_user_id()." AND"; |
|
382 | 382 | } |
383 | 383 | $inner_where .= " REG_date >= '$sql_date'"; |
384 | 384 | $inner_date_query .= $inner_where; |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | $select_parts = array(); |
391 | 391 | |
392 | 392 | //loop through registration stati to do parts for each status. |
393 | - foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) { |
|
394 | - if ( $STS_ID === EEM_Registration::status_id_incomplete ) { |
|
393 | + foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
394 | + if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
395 | 395 | continue; |
396 | 396 | } |
397 | 397 | $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | } |
400 | 400 | |
401 | 401 | //setup the selects |
402 | - $select .= implode(', ', $select_parts ); |
|
402 | + $select .= implode(', ', $select_parts); |
|
403 | 403 | $select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; |
404 | 404 | |
405 | 405 | //setup the joins |
406 | - $join .= implode( " LEFT JOIN ", $join_parts ); |
|
406 | + $join .= implode(" LEFT JOIN ", $join_parts); |
|
407 | 407 | |
408 | 408 | //now let's put it all together |
409 | - $query = $select . $join . ' GROUP BY Registration_REG_date'; |
|
409 | + $query = $select.$join.' GROUP BY Registration_REG_date'; |
|
410 | 410 | |
411 | 411 | //and execute it |
412 | 412 | $results = $wpdb->get_results( |
@@ -427,23 +427,23 @@ discard block |
||
427 | 427 | * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
428 | 428 | * @return stdClass[] each with properties event_name, reg_limit, and total |
429 | 429 | */ |
430 | - public function get_registrations_per_event_report( $period = '-1 month' ) { |
|
430 | + public function get_registrations_per_event_report($period = '-1 month') { |
|
431 | 431 | |
432 | - $date_sql = $this->convert_datetime_for_query( 'REG_date', date( "Y-m-d H:i:s", strtotime( $period )), 'Y-m-d H:i:s', 'UTC' ); |
|
433 | - $where = array( 'REG_date' => array( '>=', $date_sql ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ); |
|
432 | + $date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC'); |
|
433 | + $where = array('REG_date' => array('>=', $date_sql), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)); |
|
434 | 434 | |
435 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
435 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
436 | 436 | $where['Event.EVT_wp_user'] = get_current_user_id(); |
437 | 437 | } |
438 | 438 | $results = $this->_get_all_wpdb_results(array( |
439 | 439 | $where, |
440 | 440 | 'group_by'=>'Event.EVT_name', |
441 | 441 | 'order_by'=>'Event.EVT_name', |
442 | - 'limit'=>array(0,24)), |
|
442 | + 'limit'=>array(0, 24)), |
|
443 | 443 | OBJECT, |
444 | 444 | array( |
445 | - 'event_name'=>array('Event_CPT.post_title','%s'), |
|
446 | - 'total'=>array('COUNT(REG_ID)','%s') |
|
445 | + 'event_name'=>array('Event_CPT.post_title', '%s'), |
|
446 | + 'total'=>array('COUNT(REG_ID)', '%s') |
|
447 | 447 | ) |
448 | 448 | ); |
449 | 449 | |
@@ -461,19 +461,19 @@ discard block |
||
461 | 461 | * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID |
462 | 462 | * (i.e. RAP) |
463 | 463 | */ |
464 | - public function get_registrations_per_event_and_per_status_report( $period = '-1 month' ) { |
|
464 | + public function get_registrations_per_event_and_per_status_report($period = '-1 month') { |
|
465 | 465 | global $wpdb; |
466 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
466 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
467 | 467 | $event_table = $wpdb->posts; |
468 | - $sql_date = date("Y-m-d H:i:s", strtotime($period) ); |
|
468 | + $sql_date = date("Y-m-d H:i:s", strtotime($period)); |
|
469 | 469 | |
470 | 470 | //inner date query |
471 | 471 | $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
472 | 472 | $inner_where = " WHERE"; |
473 | 473 | //exclude events not authored by user if permissions in effect |
474 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
474 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
475 | 475 | $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; |
476 | - $inner_where .= " post_author = " . get_current_user_id() . " AND"; |
|
476 | + $inner_where .= " post_author = ".get_current_user_id()." AND"; |
|
477 | 477 | } |
478 | 478 | $inner_where .= " REG_date >= '$sql_date'"; |
479 | 479 | $inner_date_query .= $inner_where; |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | $select_parts = array(); |
486 | 486 | |
487 | 487 | //loop through registration stati to do parts for each status. |
488 | - foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) { |
|
489 | - if ( $STS_ID === EEM_Registration::status_id_incomplete ) { |
|
488 | + foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
489 | + if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
490 | 490 | continue; |
491 | 491 | } |
492 | 492 | $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; |
@@ -494,14 +494,14 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | //setup the selects |
497 | - $select .= implode( ', ', $select_parts ); |
|
497 | + $select .= implode(', ', $select_parts); |
|
498 | 498 | $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; |
499 | 499 | |
500 | 500 | //setup remaining joins |
501 | - $join .= implode( " LEFT JOIN ", $join_parts ); |
|
501 | + $join .= implode(" LEFT JOIN ", $join_parts); |
|
502 | 502 | |
503 | 503 | //now put it all together |
504 | - $query = $select . $join . ' GROUP BY Registration_Event'; |
|
504 | + $query = $select.$join.' GROUP BY Registration_Event'; |
|
505 | 505 | |
506 | 506 | //and execute |
507 | 507 | $results = $wpdb->get_results( |
@@ -517,11 +517,11 @@ discard block |
||
517 | 517 | * @param int $TXN_ID |
518 | 518 | * @return EE_Registration |
519 | 519 | */ |
520 | - public function get_primary_registration_for_transaction_ID( $TXN_ID = 0){ |
|
521 | - if( ! $TXN_ID ){ |
|
520 | + public function get_primary_registration_for_transaction_ID($TXN_ID = 0) { |
|
521 | + if ( ! $TXN_ID) { |
|
522 | 522 | return false; |
523 | 523 | } |
524 | - return $this->get_one(array(array('TXN_ID'=>$TXN_ID,'REG_count'=> EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
524 | + return $this->get_one(array(array('TXN_ID'=>$TXN_ID, 'REG_count'=> EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | * @param boolean $for_incomplete_payments |
534 | 534 | * @return int |
535 | 535 | */ |
536 | - public function get_event_registration_count ( $EVT_ID, $for_incomplete_payments = FALSE ) { |
|
536 | + public function get_event_registration_count($EVT_ID, $for_incomplete_payments = FALSE) { |
|
537 | 537 | // we only count approved registrations towards registration limits |
538 | - $query_params = array( array( 'EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved ) ); |
|
539 | - if( $for_incomplete_payments ){ |
|
540 | - $query_params[0]['Transaction.STS_ID']=array('!=', EEM_Transaction::complete_status_code); |
|
538 | + $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved)); |
|
539 | + if ($for_incomplete_payments) { |
|
540 | + $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | return $this->count($query_params); |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | /** @type WPDB $wpdb */ |
554 | 554 | global $wpdb; |
555 | 555 | return $wpdb->query( |
556 | - 'DELETE r FROM ' . $this->table() . ' r LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' ); |
|
556 | + 'DELETE r FROM '.$this->table().' r LEFT JOIN '.EEM_Transaction::instance()->table().' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' ); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | * @param boolean $checked_in whether to count registrations checked IN or OUT |
564 | 564 | * @return int |
565 | 565 | */ |
566 | - public function count_registrations_checked_into_datetime( $DTT_ID, $checked_in = true) { |
|
566 | + public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true) { |
|
567 | 567 | global $wpdb; |
568 | 568 | //subquery to get latest checkin |
569 | 569 | $query = $wpdb->prepare( |
570 | 570 | 'SELECT ' |
571 | 571 | . 'COUNT( DISTINCT checkins.REG_ID ) ' |
572 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
572 | + . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN' |
|
573 | 573 | . '( SELECT ' |
574 | 574 | . 'max( CHK_timestamp ) AS latest_checkin, ' |
575 | 575 | . 'REG_ID AS REG_ID ' |
576 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' ' |
|
576 | + . 'FROM '.EEM_Checkin::instance()->table().' ' |
|
577 | 577 | . 'WHERE DTT_ID=%d ' |
578 | 578 | . 'GROUP BY REG_ID' |
579 | 579 | . ') AS most_recent_checkin_per_reg ' |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | $DTT_ID, |
585 | 585 | $checked_in |
586 | 586 | ); |
587 | - return (int)$wpdb->get_var( $query ); |
|
587 | + return (int) $wpdb->get_var($query); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -594,18 +594,18 @@ discard block |
||
594 | 594 | * @param boolean $checked_in whether to count registrations checked IN or OUT |
595 | 595 | * @return int |
596 | 596 | */ |
597 | - public function count_registrations_checked_into_event( $EVT_ID, $checked_in = true ) { |
|
597 | + public function count_registrations_checked_into_event($EVT_ID, $checked_in = true) { |
|
598 | 598 | global $wpdb; |
599 | 599 | //subquery to get latest checkin |
600 | 600 | $query = $wpdb->prepare( |
601 | 601 | 'SELECT ' |
602 | 602 | . 'COUNT( DISTINCT checkins.REG_ID ) ' |
603 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
603 | + . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN' |
|
604 | 604 | . '( SELECT ' |
605 | 605 | . 'max( CHK_timestamp ) AS latest_checkin, ' |
606 | 606 | . 'REG_ID AS REG_ID ' |
607 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c ' |
|
608 | - . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d ' |
|
607 | + . 'FROM '.EEM_Checkin::instance()->table().' AS c ' |
|
608 | + . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d ' |
|
609 | 609 | . 'ON c.DTT_ID=d.DTT_ID ' |
610 | 610 | . 'WHERE d.EVT_ID=%d ' |
611 | 611 | . 'GROUP BY REG_ID' |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | $EVT_ID, |
618 | 618 | $checked_in |
619 | 619 | ); |
620 | - return (int)$wpdb->get_var( $query ); |
|
620 | + return (int) $wpdb->get_var($query); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | |
@@ -632,15 +632,15 @@ discard block |
||
632 | 632 | * @param array $attendee_ids |
633 | 633 | * @return EE_Registration[] |
634 | 634 | */ |
635 | - public function get_latest_registration_for_each_of_given_contacts( $attendee_ids = array() ) { |
|
635 | + public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array()) { |
|
636 | 636 | //first do a native wp_query to get the latest REG_ID's matching these attendees. |
637 | 637 | global $wpdb; |
638 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
638 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
639 | 639 | $attendee_table = $wpdb->posts; |
640 | - $attendee_ids = is_array( $attendee_ids ) |
|
641 | - ? array_map( 'absint', $attendee_ids ) |
|
642 | - : array( (int) $attendee_ids ); |
|
643 | - $attendee_ids = implode( ',', $attendee_ids ); |
|
640 | + $attendee_ids = is_array($attendee_ids) |
|
641 | + ? array_map('absint', $attendee_ids) |
|
642 | + : array((int) $attendee_ids); |
|
643 | + $attendee_ids = implode(',', $attendee_ids); |
|
644 | 644 | |
645 | 645 | |
646 | 646 | //first we do a query to get the registration ids |
@@ -665,24 +665,24 @@ discard block |
||
665 | 665 | ARRAY_A |
666 | 666 | ); |
667 | 667 | |
668 | - if ( empty( $registration_ids ) ) { |
|
668 | + if (empty($registration_ids)) { |
|
669 | 669 | return array(); |
670 | 670 | } |
671 | 671 | |
672 | 672 | $ids_for_model_query = array(); |
673 | 673 | //let's flatten the ids so they can be used in the model query. |
674 | - foreach ( $registration_ids as $registration_id ) { |
|
675 | - if ( isset( $registration_id['registration_id'] ) ) { |
|
674 | + foreach ($registration_ids as $registration_id) { |
|
675 | + if (isset($registration_id['registration_id'])) { |
|
676 | 676 | $ids_for_model_query[] = $registration_id['registration_id']; |
677 | 677 | } |
678 | 678 | } |
679 | 679 | |
680 | 680 | //construct query |
681 | 681 | $_where = array( |
682 | - 'REG_ID' => array( 'IN', $ids_for_model_query ) |
|
682 | + 'REG_ID' => array('IN', $ids_for_model_query) |
|
683 | 683 | ); |
684 | 684 | |
685 | - return $this->get_all( array( $_where ) ); |
|
685 | + return $this->get_all(array($_where)); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * Sum all the deleted items. |
147 | 147 | * @param array $query_params like EEM_Base::get_all |
148 | 148 | * @param string $field_to_sum |
149 | - * @return int |
|
149 | + * @return double |
|
150 | 150 | */ |
151 | 151 | public function sum_deleted($query_params = null, $field_to_sum = null){ |
152 | 152 | $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
196 | 196 | * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
197 | 197 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
198 | - * @return boolean success |
|
198 | + * @return integer success |
|
199 | 199 | */ |
200 | 200 | public function delete_permanently($query_params = array(), $allow_blocking = true){ |
201 | 201 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
@@ -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 | * EEM_Soft_Delete_Base |
5 | 5 | * |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | * @subpackage includes/models/ |
26 | 26 | * @author Michael Nelson |
27 | 27 | */ |
28 | -abstract class EEM_Soft_Delete_Base extends EEM_Base{ |
|
28 | +abstract class EEM_Soft_Delete_Base extends EEM_Base { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param null $timezone |
32 | 32 | */ |
33 | 33 | protected function __construct($timezone = NULL) { |
34 | - if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ){ |
|
34 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
35 | 35 | $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
36 | 36 | } |
37 | 37 | parent::__construct($timezone); |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | * @return string |
43 | 43 | * @throws EE_Error |
44 | 44 | */ |
45 | - public function deleted_field_name(){ |
|
45 | + public function deleted_field_name() { |
|
46 | 46 | $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field'); |
47 | - if($field){ |
|
47 | + if ($field) { |
|
48 | 48 | return $field->get_name(); |
49 | - }else{ |
|
50 | - throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this))); |
|
49 | + } else { |
|
50 | + throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this))); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param array $query_params like EEM_Base::get_all's $query_params |
58 | 58 | * @return EE_Soft_Delete_Base_Class |
59 | 59 | */ |
60 | - public function get_one_deleted($query_params = array()){ |
|
60 | + public function get_one_deleted($query_params = array()) { |
|
61 | 61 | $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
62 | 62 | return parent::get_one($query_params); |
63 | 63 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param array $query_params like EEM_base::get_all's $query_params |
68 | 68 | * @return EE_Soft_Delete_Base_Class |
69 | 69 | */ |
70 | - public function get_one_deleted_or_undeleted($query_params = array()){ |
|
70 | + public function get_one_deleted_or_undeleted($query_params = array()) { |
|
71 | 71 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
72 | 72 | return parent::get_one($query_params); |
73 | 73 | } |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param int|string $id |
78 | 78 | * @return EE_Soft_Delete_Base_Class |
79 | 79 | */ |
80 | - public function get_one_by_ID_but_ignore_deleted($id){ |
|
80 | + public function get_one_by_ID_but_ignore_deleted($id) { |
|
81 | 81 | return $this->get_one( |
82 | 82 | $this->alter_query_params_to_restrict_by_ID( |
83 | 83 | $id, |
84 | - array( 'default_where_conditions' => 'default' ) |
|
84 | + array('default_where_conditions' => 'default') |
|
85 | 85 | ) |
86 | 86 | ); |
87 | 87 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
94 | 94 | * @return int |
95 | 95 | */ |
96 | - public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE){ |
|
96 | + public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE) { |
|
97 | 97 | $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
98 | 98 | return parent::count($query_params, $field_to_count, $distinct); |
99 | 99 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @param array $query_params like EEM_Base::get_all's $query_params |
104 | 104 | * @return array like EEM_Base::get_all's $query_params |
105 | 105 | */ |
106 | - protected function _alter_query_params_so_only_trashed_items_included($query_params){ |
|
107 | - $deletedFlagFieldName=$this->deleted_field_name(); |
|
108 | - $query_params[0][$deletedFlagFieldName]=true; |
|
106 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) { |
|
107 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
108 | + $query_params[0][$deletedFlagFieldName] = true; |
|
109 | 109 | return $query_params; |
110 | 110 | } |
111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param array $query_params |
115 | 115 | * @return array |
116 | 116 | */ |
117 | - public function alter_query_params_so_deleted_and_undeleted_items_included( $query_params = array() ){ |
|
117 | + public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) { |
|
118 | 118 | return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
119 | 119 | } |
120 | 120 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @param array $query_params |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){ |
|
127 | - if( ! isset( $query_params[ 'default_where_conditions' ] ) ) { |
|
126 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) { |
|
127 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
128 | 128 | $query_params['default_where_conditions'] = 'minimum'; |
129 | 129 | } |
130 | 130 | return $query_params; |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
138 | 138 | * @return int |
139 | 139 | */ |
140 | - public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE){ |
|
140 | + public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE) { |
|
141 | 141 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
142 | - return parent::count($query_params,$field_to_count, $distinct); |
|
142 | + return parent::count($query_params, $field_to_count, $distinct); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param string $field_to_sum |
149 | 149 | * @return int |
150 | 150 | */ |
151 | - public function sum_deleted($query_params = null, $field_to_sum = null){ |
|
151 | + public function sum_deleted($query_params = null, $field_to_sum = null) { |
|
152 | 152 | $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
153 | 153 | return parent::sum($query_params, $field_to_sum); |
154 | 154 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param string $field_to_sum |
160 | 160 | * @return int |
161 | 161 | */ |
162 | - public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null){ |
|
162 | + public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) { |
|
163 | 163 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
164 | 164 | parent::sum($query_params, $field_to_sum); |
165 | 165 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @param array $query_params like EEM_Base::get_all |
170 | 170 | * @return EE_Soft_Delete_Base_Class[] |
171 | 171 | */ |
172 | - public function get_all_deleted_and_undeleted($query_params = array()){ |
|
172 | + public function get_all_deleted_and_undeleted($query_params = array()) { |
|
173 | 173 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
174 | 174 | return parent::get_all($query_params); |
175 | 175 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param array $query_params like EEM_Base::get_all |
180 | 180 | * @return EE_Soft_Delete_Base_Class[] |
181 | 181 | */ |
182 | - public function get_all_deleted($query_params = array()){ |
|
182 | + public function get_all_deleted($query_params = array()) { |
|
183 | 183 | $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
184 | 184 | return parent::get_all($query_params); |
185 | 185 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
198 | 198 | * @return boolean success |
199 | 199 | */ |
200 | - public function delete_permanently($query_params = array(), $allow_blocking = true){ |
|
200 | + public function delete_permanently($query_params = array(), $allow_blocking = true) { |
|
201 | 201 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
202 | 202 | return parent::delete_permanently($query_params, $allow_blocking); |
203 | 203 | } |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @param mixed $ID int if primary key is an int, string otherwise |
209 | 209 | * @return boolean success |
210 | 210 | */ |
211 | - public function restore_by_ID($ID=FALSE){ |
|
212 | - return $this->delete_or_restore_by_ID(false,$ID); |
|
211 | + public function restore_by_ID($ID = FALSE) { |
|
212 | + return $this->delete_or_restore_by_ID(false, $ID); |
|
213 | 213 | } |
214 | 214 | /** |
215 | 215 | * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However, |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | * @param mixed $ID int if primary key is an int, string otherwise |
219 | 219 | * @return boolean |
220 | 220 | */ |
221 | - public function delete_or_restore_by_ID($delete=true,$ID=FALSE){ |
|
222 | - if ( ! $ID ) { |
|
221 | + public function delete_or_restore_by_ID($delete = true, $ID = FALSE) { |
|
222 | + if ( ! $ID) { |
|
223 | 223 | return FALSE; |
224 | 224 | } |
225 | 225 | if ( |
226 | 226 | $this->delete_or_restore( |
227 | 227 | $delete, |
228 | - $this->alter_query_params_to_restrict_by_ID( $ID ) |
|
228 | + $this->alter_query_params_to_restrict_by_ID($ID) |
|
229 | 229 | ) |
230 | 230 | ) { |
231 | 231 | return TRUE; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param bool $block_deletes |
246 | 246 | * @return boolean |
247 | 247 | */ |
248 | - public function delete($query_params = array(), $block_deletes = false){ |
|
248 | + public function delete($query_params = array(), $block_deletes = false) { |
|
249 | 249 | //no matter what, we WON'T block soft deletes. |
250 | 250 | return $this->delete_or_restore(true, $query_params); |
251 | 251 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @param array $query_params like EEM_Base::get_all |
257 | 257 | * @return boolean |
258 | 258 | */ |
259 | - public function restore($query_params = array()){ |
|
259 | + public function restore($query_params = array()) { |
|
260 | 260 | return $this->delete_or_restore(false, $query_params); |
261 | 261 | } |
262 | 262 | /** |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | * @param array $query_params like EEM_Base::get_all |
266 | 266 | * @return boolean |
267 | 267 | */ |
268 | - function delete_or_restore($delete=true,$query_params = array()){ |
|
269 | - $deletedFlagFieldName=$this->deleted_field_name(); |
|
268 | + function delete_or_restore($delete = true, $query_params = array()) { |
|
269 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
270 | 270 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
271 | - if ( $this->update (array($deletedFlagFieldName=>$delete), $query_params )) { |
|
271 | + if ($this->update(array($deletedFlagFieldName=>$delete), $query_params)) { |
|
272 | 272 | return TRUE; |
273 | 273 | } else { |
274 | 274 | return FALSE; |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * be aware that model objects being used could get out-of-sync with the database |
287 | 287 | * @return int number of items updated |
288 | 288 | */ |
289 | - public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE ){ |
|
289 | + public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
290 | 290 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
291 | - return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync ); |
|
291 | + return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
292 | 292 | } |
293 | 293 | } |
@@ -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 | * |
4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return boolean success |
46 | 46 | * @throws \EE_Error |
47 | 47 | */ |
48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
51 | 51 | 'LIN_name' => $name, |
52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'LIN_quantity' => $quantity, |
55 | 55 | 'LIN_percent' => null, |
56 | 56 | 'LIN_is_taxable' => $taxable, |
57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $line_item, |
65 | 65 | $parent_line_item |
66 | 66 | ); |
67 | - return self::add_item( $parent_line_item, $line_item ); |
|
67 | + return self::add_item($parent_line_item, $line_item); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return boolean success |
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
91 | 91 | 'LIN_name' => $name, |
92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'LIN_percent' => $percentage_amount, |
95 | 95 | 'LIN_quantity' => NULL, |
96 | 96 | 'LIN_is_taxable' => $taxable, |
97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
100 | 100 | )); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
103 | 103 | $line_item |
104 | 104 | ); |
105 | - return self::add_item( $parent_line_item, $line_item ); |
|
105 | + return self::add_item($parent_line_item, $line_item); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @return \EE_Line_Item |
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
129 | 129 | } |
130 | 130 | // either increment the qty for an existing ticket |
131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
132 | 132 | // or add a new one |
133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
135 | 135 | } |
136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @return \EE_Line_Item |
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
151 | 151 | $line_item = null; |
152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
155 | 155 | if ( |
156 | 156 | $ticket_line_item instanceof EE_Line_Item |
157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
164 | + if ($line_item instanceof EE_Line_Item) { |
|
165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
166 | 166 | return $line_item; |
167 | 167 | } |
168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | * @throws \EE_Error |
181 | 181 | */ |
182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
183 | - if( ! $line_item->is_percent() ) { |
|
182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
183 | + if ( ! $line_item->is_percent()) { |
|
184 | 184 | $qty += $line_item->quantity(); |
185 | - $line_item->set_quantity( $qty ); |
|
186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
185 | + $line_item->set_quantity($qty); |
|
186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
187 | 187 | $line_item->save(); |
188 | 188 | } |
189 | - foreach( $line_item->children() as $child ) { |
|
190 | - if( $child->is_sub_line_item() ) { |
|
191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
189 | + foreach ($line_item->children() as $child) { |
|
190 | + if ($child->is_sub_line_item()) { |
|
191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
208 | - if( ! $line_item->is_percent() ) { |
|
207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
208 | + if ( ! $line_item->is_percent()) { |
|
209 | 209 | $qty = $line_item->quantity() - $qty; |
210 | - $qty = max( $qty, 0 ); |
|
211 | - $line_item->set_quantity( $qty ); |
|
212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
210 | + $qty = max($qty, 0); |
|
211 | + $line_item->set_quantity($qty); |
|
212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
213 | 213 | $line_item->save(); |
214 | 214 | } |
215 | - foreach( $line_item->children() as $child ) { |
|
216 | - if( $child->is_sub_line_item() ) { |
|
217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
215 | + foreach ($line_item->children() as $child) { |
|
216 | + if ($child->is_sub_line_item()) { |
|
217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | * @param int $new_quantity |
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
233 | - if( ! $line_item->is_percent() ) { |
|
234 | - $line_item->set_quantity( $new_quantity ); |
|
235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
233 | + if ( ! $line_item->is_percent()) { |
|
234 | + $line_item->set_quantity($new_quantity); |
|
235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
236 | 236 | $line_item->save(); |
237 | 237 | } |
238 | - foreach( $line_item->children() as $child ) { |
|
239 | - if( $child->is_sub_line_item() ) { |
|
240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
238 | + foreach ($line_item->children() as $child) { |
|
239 | + if ($child->is_sub_line_item()) { |
|
240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @return \EE_Line_Item |
253 | 253 | * @throws \EE_Error |
254 | 254 | */ |
255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
256 | 256 | $datetimes = $ticket->datetimes(); |
257 | - $first_datetime = reset( $datetimes ); |
|
258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
257 | + $first_datetime = reset($datetimes); |
|
258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
260 | 260 | } else { |
261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
262 | 262 | } |
263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
264 | 264 | // get event subtotal line |
265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
266 | 266 | // add $ticket to cart |
267 | - $line_item = EE_Line_Item::new_instance( array( |
|
267 | + $line_item = EE_Line_Item::new_instance(array( |
|
268 | 268 | 'LIN_name' => $ticket->name(), |
269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
270 | 270 | 'LIN_unit_price' => $ticket->price(), |
271 | 271 | 'LIN_quantity' => $qty, |
272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
273 | + 'LIN_order' => count($events_sub_total->children()), |
|
274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
276 | 276 | 'OBJ_ID' => $ticket->ID(), |
277 | 277 | 'OBJ_type' => 'Ticket' |
278 | - ) ); |
|
278 | + )); |
|
279 | 279 | $line_item = apply_filters( |
280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
281 | 281 | $line_item |
282 | 282 | ); |
283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
283 | + $events_sub_total->add_child_line_item($line_item); |
|
284 | 284 | //now add the sub-line items |
285 | 285 | $running_total_for_ticket = 0; |
286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
288 | 288 | $price_total = $price->is_percent() |
289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
290 | 290 | : $price->amount() * $qty; |
291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
292 | 292 | 'LIN_name' => $price->name(), |
293 | 293 | 'LIN_desc' => $price->desc(), |
294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
299 | 299 | 'OBJ_ID' => $price->ID(), |
300 | 300 | 'OBJ_type' => 'Price' |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | $sub_line_item = apply_filters( |
303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
304 | 304 | $sub_line_item |
305 | 305 | ); |
306 | - if ( $price->is_percent() ) { |
|
307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
306 | + if ($price->is_percent()) { |
|
307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
308 | 308 | } else { |
309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
310 | 310 | } |
311 | 311 | $running_total_for_ticket += $price_total; |
312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
312 | + $line_item->add_child_line_item($sub_line_item); |
|
313 | 313 | } |
314 | 314 | return $line_item; |
315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @return boolean |
330 | 330 | * @throws \EE_Error |
331 | 331 | */ |
332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | return FALSE; |
338 | 338 | } |
339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
352 | 352 | * @return bool success |
353 | 353 | * @throws \EE_Error |
354 | 354 | */ |
355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
356 | 356 | // validate incoming line_item |
357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
358 | 358 | throw new EE_Error( |
359 | 359 | sprintf( |
360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
361 | 361 | $ticket_line_item->type() |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
365 | + if ($ticket_line_item->quantity() < $qty) { |
|
366 | 366 | throw new EE_Error( |
367 | 367 | sprintf( |
368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
369 | 369 | $qty, |
370 | 370 | $ticket_line_item->quantity() |
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
377 | - if( |
|
375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
377 | + if ( |
|
378 | 378 | $child_line_item->is_sub_line_item() |
379 | 379 | && ! $child_line_item->is_percent() |
380 | 380 | && ! $child_line_item->is_cancellation() |
381 | 381 | ) { |
382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // get cancellation sub line item |
@@ -387,31 +387,31 @@ discard block |
||
387 | 387 | $ticket_line_item, |
388 | 388 | EEM_Line_Item::type_cancellation |
389 | 389 | ); |
390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
391 | 391 | // verify that this ticket was indeed previously cancelled |
392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
393 | 393 | // increment cancelled quantity |
394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
395 | 395 | } else { |
396 | 396 | // create cancellation sub line item |
397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
399 | 399 | 'LIN_desc' => sprintf( |
400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
401 | 401 | $ticket_line_item->name(), |
402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
403 | 403 | ), |
404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
405 | 405 | 'LIN_quantity' => $qty, |
406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
410 | - ) ); |
|
411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
410 | + )); |
|
411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
412 | 412 | } |
413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
414 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
415 | 415 | return true; |
416 | 416 | } |
417 | 417 | return false; |
@@ -429,12 +429,12 @@ discard block |
||
429 | 429 | * @return bool success |
430 | 430 | * @throws \EE_Error |
431 | 431 | */ |
432 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
432 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
433 | 433 | // validate incoming line_item |
434 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
434 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
435 | 435 | throw new EE_Error( |
436 | 436 | sprintf( |
437 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
437 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
438 | 438 | $ticket_line_item->type() |
439 | 439 | ) |
440 | 440 | ); |
@@ -444,37 +444,37 @@ discard block |
||
444 | 444 | $ticket_line_item, |
445 | 445 | EEM_Line_Item::type_cancellation |
446 | 446 | ); |
447 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
447 | + $cancellation_line_item = reset($cancellation_line_item); |
|
448 | 448 | // verify that this ticket was indeed previously cancelled |
449 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
449 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
452 | + if ($cancellation_line_item->quantity() > $qty) { |
|
453 | 453 | // decrement cancelled quantity |
454 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
455 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
454 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
455 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
456 | 456 | // decrement cancelled quantity in case anyone still has the object kicking around |
457 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
457 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
458 | 458 | // delete because quantity will end up as 0 |
459 | 459 | $cancellation_line_item->delete(); |
460 | 460 | // and attempt to destroy the object, |
461 | 461 | // even though PHP won't actually destroy it until it needs the memory |
462 | - unset( $cancellation_line_item ); |
|
462 | + unset($cancellation_line_item); |
|
463 | 463 | } else { |
464 | 464 | // what ?!?! negative quantity ?!?! |
465 | 465 | throw new EE_Error( |
466 | 466 | sprintf( |
467 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
468 | - 'event_espresso' ), |
|
467 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
468 | + 'event_espresso'), |
|
469 | 469 | $qty, |
470 | 470 | $cancellation_line_item->quantity() |
471 | 471 | ) |
472 | 472 | ); |
473 | 473 | } |
474 | 474 | // increment ticket quantity |
475 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
476 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
477 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
475 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
476 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
477 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
478 | 478 | return true; |
479 | 479 | } |
480 | 480 | return false; |
@@ -489,8 +489,8 @@ discard block |
||
489 | 489 | * @param EE_Line_Item $line_item |
490 | 490 | * @return \EE_Line_Item |
491 | 491 | */ |
492 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
493 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
492 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
493 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
494 | 494 | return $grand_total_line_item->recalculate_total_including_taxes(); |
495 | 495 | } |
496 | 496 | |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * @return \EE_Line_Item |
504 | 504 | * @throws \EE_Error |
505 | 505 | */ |
506 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
507 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
506 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
507 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
508 | 508 | return $pre_tax_subtotal instanceof EE_Line_Item |
509 | 509 | ? $pre_tax_subtotal |
510 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
510 | + : self::create_pre_tax_subtotal($total_line_item); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | |
@@ -519,9 +519,9 @@ discard block |
||
519 | 519 | * @return \EE_Line_Item |
520 | 520 | * @throws \EE_Error |
521 | 521 | */ |
522 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
523 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
524 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
522 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
523 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
524 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -534,12 +534,12 @@ discard block |
||
534 | 534 | * @return void |
535 | 535 | * @throws \EE_Error |
536 | 536 | */ |
537 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
538 | - if( $transaction ){ |
|
537 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
538 | + if ($transaction) { |
|
539 | 539 | /** @type EEM_Transaction $EEM_Transaction */ |
540 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
541 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
542 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
540 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
541 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
542 | + $line_item->set_TXN_ID($TXN_ID); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * @return \EE_Line_Item of type total |
555 | 555 | * @throws \EE_Error |
556 | 556 | */ |
557 | - public static function create_total_line_item( $transaction = NULL ){ |
|
558 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
557 | + public static function create_total_line_item($transaction = NULL) { |
|
558 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
559 | 559 | 'LIN_code' => 'total', |
560 | 560 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
561 | 561 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
566 | 566 | $total_line_item |
567 | 567 | ); |
568 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
569 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
570 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
568 | + self::set_TXN_ID($total_line_item, $transaction); |
|
569 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
570 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
571 | 571 | return $total_line_item; |
572 | 572 | } |
573 | 573 | |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | * @return EE_Line_Item |
582 | 582 | * @throws \EE_Error |
583 | 583 | */ |
584 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
585 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
584 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
585 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
586 | 586 | 'LIN_code' => 'pre-tax-subtotal', |
587 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
587 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
588 | 588 | 'LIN_type' => EEM_Line_Item::type_sub_total |
589 | - ) ); |
|
589 | + )); |
|
590 | 590 | $pre_tax_line_item = apply_filters( |
591 | 591 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
592 | 592 | $pre_tax_line_item |
593 | 593 | ); |
594 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
595 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
596 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
594 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
595 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
596 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
597 | 597 | return $pre_tax_line_item; |
598 | 598 | } |
599 | 599 | |
@@ -608,21 +608,21 @@ discard block |
||
608 | 608 | * @return EE_Line_Item |
609 | 609 | * @throws \EE_Error |
610 | 610 | */ |
611 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
611 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
612 | 612 | $tax_line_item = EE_Line_Item::new_instance(array( |
613 | 613 | 'LIN_code' => 'taxes', |
614 | 614 | 'LIN_name' => __('Taxes', 'event_espresso'), |
615 | 615 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
616 | - 'LIN_order' => 1000,//this should always come last |
|
616 | + 'LIN_order' => 1000, //this should always come last |
|
617 | 617 | )); |
618 | 618 | $tax_line_item = apply_filters( |
619 | 619 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
620 | 620 | $tax_line_item |
621 | 621 | ); |
622 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
623 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
622 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
623 | + $total_line_item->add_child_line_item($tax_line_item); |
|
624 | 624 | //and lastly, add the actual taxes |
625 | - self::apply_taxes( $total_line_item ); |
|
625 | + self::apply_taxes($total_line_item); |
|
626 | 626 | return $tax_line_item; |
627 | 627 | } |
628 | 628 | |
@@ -637,11 +637,11 @@ discard block |
||
637 | 637 | * @return EE_Line_Item |
638 | 638 | * @throws \EE_Error |
639 | 639 | */ |
640 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
640 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
641 | 641 | $event_line_item = EE_Line_Item::new_instance(array( |
642 | - 'LIN_code' => self::get_event_code( $event ), |
|
643 | - 'LIN_name' => self::get_event_name( $event ), |
|
644 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
642 | + 'LIN_code' => self::get_event_code($event), |
|
643 | + 'LIN_name' => self::get_event_name($event), |
|
644 | + 'LIN_desc' => self::get_event_desc($event), |
|
645 | 645 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
646 | 646 | 'OBJ_type' => 'Event', |
647 | 647 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -650,8 +650,8 @@ discard block |
||
650 | 650 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
651 | 651 | $event_line_item |
652 | 652 | ); |
653 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
654 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
653 | + self::set_TXN_ID($event_line_item, $transaction); |
|
654 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
655 | 655 | return $event_line_item; |
656 | 656 | } |
657 | 657 | |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | * @return string |
665 | 665 | * @throws \EE_Error |
666 | 666 | */ |
667 | - public static function get_event_code( $event ) { |
|
668 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
667 | + public static function get_event_code($event) { |
|
668 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -673,8 +673,8 @@ discard block |
||
673 | 673 | * @param EE_Event $event |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - public static function get_event_name( $event ) { |
|
677 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
676 | + public static function get_event_name($event) { |
|
677 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | * @param EE_Event $event |
683 | 683 | * @return string |
684 | 684 | */ |
685 | - public static function get_event_desc( $event ) { |
|
685 | + public static function get_event_desc($event) { |
|
686 | 686 | return $event instanceof EE_Event ? $event->short_description() : ''; |
687 | 687 | } |
688 | 688 | |
@@ -696,27 +696,27 @@ discard block |
||
696 | 696 | * @throws \EE_Error |
697 | 697 | * @return EE_Line_Item |
698 | 698 | */ |
699 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
699 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
700 | 700 | $first_datetime = $ticket->first_datetime(); |
701 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
701 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
702 | 702 | throw new EE_Error( |
703 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
703 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
704 | 704 | ); |
705 | 705 | } |
706 | 706 | $event = $first_datetime->event(); |
707 | - if ( ! $event instanceof EE_Event ) { |
|
707 | + if ( ! $event instanceof EE_Event) { |
|
708 | 708 | throw new EE_Error( |
709 | 709 | sprintf( |
710 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
710 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
711 | 711 | $ticket->ID() |
712 | 712 | ) |
713 | 713 | ); |
714 | 714 | } |
715 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
716 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
715 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
716 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
717 | 717 | throw new EE_Error( |
718 | 718 | sprintf( |
719 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
719 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
720 | 720 | $ticket->ID(), |
721 | 721 | $grand_total->ID() |
722 | 722 | ) |
@@ -735,31 +735,31 @@ discard block |
||
735 | 735 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
736 | 736 | * @throws \EE_Error |
737 | 737 | */ |
738 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
738 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
739 | 739 | /** @type EE_Event $event */ |
740 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
740 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
741 | 741 | $event_line_item = NULL; |
742 | 742 | $found = false; |
743 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
743 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
744 | 744 | // default event subtotal, we should only ever find this the first time this method is called |
745 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
745 | + if ( ! $event_line_item->OBJ_ID()) { |
|
746 | 746 | // let's use this! but first... set the event details |
747 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
747 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
748 | 748 | $found = true; |
749 | 749 | break; |
750 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
750 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
751 | 751 | // found existing line item for this event in the cart, so break out of loop and use this one |
752 | 752 | $found = true; |
753 | 753 | break; |
754 | 754 | } |
755 | 755 | } |
756 | - if ( ! $found ) { |
|
756 | + if ( ! $found) { |
|
757 | 757 | //there is no event sub-total yet, so add it |
758 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
758 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
759 | 759 | // create a new "event" subtotal below that |
760 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
760 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
761 | 761 | // and set the event details |
762 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
762 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
763 | 763 | } |
764 | 764 | return $event_line_item; |
765 | 765 | } |
@@ -780,13 +780,13 @@ discard block |
||
780 | 780 | EE_Event $event, |
781 | 781 | $transaction = null |
782 | 782 | ) { |
783 | - if ( $event instanceof EE_Event ) { |
|
784 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
785 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
786 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
787 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
783 | + if ($event instanceof EE_Event) { |
|
784 | + $event_line_item->set_code(self::get_event_code($event)); |
|
785 | + $event_line_item->set_name(self::get_event_name($event)); |
|
786 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
787 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
788 | 788 | } |
789 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
789 | + self::set_TXN_ID($event_line_item, $transaction); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | |
@@ -799,19 +799,19 @@ discard block |
||
799 | 799 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
800 | 800 | * @throws \EE_Error |
801 | 801 | */ |
802 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
802 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
803 | 803 | /** @type EEM_Price $EEM_Price */ |
804 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
804 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
805 | 805 | // get array of taxes via Price Model |
806 | 806 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
807 | - ksort( $ordered_taxes ); |
|
808 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
807 | + ksort($ordered_taxes); |
|
808 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
809 | 809 | //just to be safe, remove its old tax line items |
810 | 810 | $taxes_line_item->delete_children_line_items(); |
811 | 811 | //loop thru taxes |
812 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
813 | - foreach ( $taxes as $tax ) { |
|
814 | - if ( $tax instanceof EE_Price ) { |
|
812 | + foreach ($ordered_taxes as $order => $taxes) { |
|
813 | + foreach ($taxes as $tax) { |
|
814 | + if ($tax instanceof EE_Price) { |
|
815 | 815 | $tax_line_item = EE_Line_Item::new_instance( |
816 | 816 | array( |
817 | 817 | 'LIN_name' => $tax->name(), |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
830 | 830 | $tax_line_item |
831 | 831 | ); |
832 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
832 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
833 | 833 | } |
834 | 834 | } |
835 | 835 | } |
@@ -846,10 +846,10 @@ discard block |
||
846 | 846 | * @return float |
847 | 847 | * @throws \EE_Error |
848 | 848 | */ |
849 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
850 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
851 | - if( ! $taxes_subtotal->children()){ |
|
852 | - self::apply_taxes( $total_line_item ); |
|
849 | + public static function ensure_taxes_applied($total_line_item) { |
|
850 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
851 | + if ( ! $taxes_subtotal->children()) { |
|
852 | + self::apply_taxes($total_line_item); |
|
853 | 853 | } |
854 | 854 | return $taxes_subtotal->total(); |
855 | 855 | } |
@@ -863,16 +863,16 @@ discard block |
||
863 | 863 | * @return bool |
864 | 864 | * @throws \EE_Error |
865 | 865 | */ |
866 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
866 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
867 | 867 | $deleted = 0; |
868 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
869 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
870 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
871 | - if ( $child_line_item->ID() ) { |
|
868 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
869 | + if ($child_line_item instanceof EE_Line_Item) { |
|
870 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
871 | + if ($child_line_item->ID()) { |
|
872 | 872 | $child_line_item->delete(); |
873 | - unset( $child_line_item ); |
|
873 | + unset($child_line_item); |
|
874 | 874 | } else { |
875 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
875 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
876 | 876 | } |
877 | 877 | $deleted++; |
878 | 878 | } |
@@ -894,9 +894,9 @@ discard block |
||
894 | 894 | * @param array|bool|string $line_item_codes |
895 | 895 | * @return int number of items successfully removed |
896 | 896 | */ |
897 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
897 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
898 | 898 | |
899 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
899 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
900 | 900 | EE_Error::doing_it_wrong( |
901 | 901 | 'EEH_Line_Item::delete_items', |
902 | 902 | __( |
@@ -906,20 +906,20 @@ discard block |
||
906 | 906 | '4.6.18' |
907 | 907 | ); |
908 | 908 | } |
909 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
909 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
910 | 910 | |
911 | 911 | // check if only a single line_item_id was passed |
912 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
912 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
913 | 913 | // place single line_item_id in an array to appear as multiple line_item_ids |
914 | - $line_item_codes = array ( $line_item_codes ); |
|
914 | + $line_item_codes = array($line_item_codes); |
|
915 | 915 | } |
916 | 916 | $removals = 0; |
917 | 917 | // cycle thru line_item_ids |
918 | - foreach ( $line_item_codes as $line_item_id ) { |
|
918 | + foreach ($line_item_codes as $line_item_id) { |
|
919 | 919 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
920 | 920 | } |
921 | 921 | |
922 | - if ( $removals > 0 ) { |
|
922 | + if ($removals > 0) { |
|
923 | 923 | $total_line_item->recalculate_taxes_and_tax_total(); |
924 | 924 | return $removals; |
925 | 925 | } else { |
@@ -952,33 +952,33 @@ discard block |
||
952 | 952 | $code = null, |
953 | 953 | $add_to_existing_line_item = false |
954 | 954 | ) { |
955 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
955 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
956 | 956 | $taxable_total = $total_line_item->taxable_total(); |
957 | 957 | |
958 | - if( $add_to_existing_line_item ) { |
|
959 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
958 | + if ($add_to_existing_line_item) { |
|
959 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
960 | 960 | EEM_Line_Item::instance()->delete( |
961 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
961 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
962 | 962 | ); |
963 | 963 | } else { |
964 | 964 | $new_tax = null; |
965 | 965 | $tax_subtotal->delete_children_line_items(); |
966 | 966 | } |
967 | - if( $new_tax ) { |
|
968 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
969 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
967 | + if ($new_tax) { |
|
968 | + $new_tax->set_total($new_tax->total() + $amount); |
|
969 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
970 | 970 | } else { |
971 | 971 | //no existing tax item. Create it |
972 | - $new_tax = EE_Line_Item::new_instance( array( |
|
972 | + $new_tax = EE_Line_Item::new_instance(array( |
|
973 | 973 | 'TXN_ID' => $total_line_item->TXN_ID(), |
974 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
974 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
975 | 975 | 'LIN_desc' => $description ? $description : '', |
976 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
976 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
977 | 977 | 'LIN_total' => $amount, |
978 | 978 | 'LIN_parent' => $tax_subtotal->ID(), |
979 | 979 | 'LIN_type' => EEM_Line_Item::type_tax, |
980 | 980 | 'LIN_code' => $code |
981 | - ) ); |
|
981 | + )); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | $new_tax = apply_filters( |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | $total_line_item |
988 | 988 | ); |
989 | 989 | $new_tax->save(); |
990 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
990 | + $tax_subtotal->set_total($new_tax->total()); |
|
991 | 991 | $tax_subtotal->save(); |
992 | 992 | $total_line_item->recalculate_total_including_taxes(); |
993 | 993 | return $new_tax; |
@@ -1009,14 +1009,14 @@ discard block |
||
1009 | 1009 | $code_substring_for_whitelist = null |
1010 | 1010 | ) { |
1011 | 1011 | $whitelisted = false; |
1012 | - if( $code_substring_for_whitelist !== null ) { |
|
1013 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1012 | + if ($code_substring_for_whitelist !== null) { |
|
1013 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1014 | 1014 | } |
1015 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1016 | - $line_item->set_is_taxable( $taxable ); |
|
1015 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1016 | + $line_item->set_is_taxable($taxable); |
|
1017 | 1017 | } |
1018 | - foreach( $line_item->children() as $child_line_item ) { |
|
1019 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1018 | + foreach ($line_item->children() as $child_line_item) { |
|
1019 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1030 | 1030 | * @return EE_Line_Item[] |
1031 | 1031 | */ |
1032 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1033 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1032 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1033 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | * @param string $obj_type |
1044 | 1044 | * @return EE_Line_Item[] |
1045 | 1045 | */ |
1046 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1046 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1047 | 1047 | return self::_get_descendants_by_type_and_object_type( |
1048 | 1048 | $parent_line_item, |
1049 | 1049 | EEM_Line_Item::type_sub_total, |
@@ -1060,8 +1060,8 @@ discard block |
||
1060 | 1060 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1061 | 1061 | * @return EE_Line_Item[] |
1062 | 1062 | */ |
1063 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1064 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1063 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1064 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @param string $obj_type |
1075 | 1075 | * @return EE_Line_Item[] |
1076 | 1076 | */ |
1077 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1078 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1077 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1078 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
@@ -1086,8 +1086,8 @@ discard block |
||
1086 | 1086 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1087 | 1087 | * @return EE_Line_Item[] |
1088 | 1088 | */ |
1089 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1090 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1089 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1090 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
@@ -1098,8 +1098,8 @@ discard block |
||
1098 | 1098 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1099 | 1099 | * @return EE_Line_Item[] |
1100 | 1100 | */ |
1101 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1102 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1101 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1102 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | |
@@ -1112,8 +1112,8 @@ discard block |
||
1112 | 1112 | * @param string $line_item_type one of the EEM_Line_Item constants |
1113 | 1113 | * @return EE_Line_Item[] |
1114 | 1114 | */ |
1115 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1116 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1115 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1116 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | |
@@ -1132,8 +1132,8 @@ discard block |
||
1132 | 1132 | $obj_type = null |
1133 | 1133 | ) { |
1134 | 1134 | $objects = array(); |
1135 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1136 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1135 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1136 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1137 | 1137 | if ( |
1138 | 1138 | $child_line_item->type() === $line_item_type |
1139 | 1139 | && ( |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | $OBJ_type = '', |
1174 | 1174 | $OBJ_IDs = array() |
1175 | 1175 | ) { |
1176 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1176 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1177 | 1177 | } |
1178 | 1178 | |
1179 | 1179 | |
@@ -1192,12 +1192,12 @@ discard block |
||
1192 | 1192 | $OBJ_IDs |
1193 | 1193 | ) { |
1194 | 1194 | $objects = array(); |
1195 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1196 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1195 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1196 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1197 | 1197 | if ( |
1198 | - is_array( $OBJ_IDs ) |
|
1198 | + is_array($OBJ_IDs) |
|
1199 | 1199 | && $child_line_item->OBJ_type() === $OBJ_type |
1200 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1200 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1201 | 1201 | ) { |
1202 | 1202 | $objects[] = $child_line_item; |
1203 | 1203 | } else { |
@@ -1227,8 +1227,8 @@ discard block |
||
1227 | 1227 | * @param string $type like one of the EEM_Line_Item::type_* |
1228 | 1228 | * @return EE_Line_Item |
1229 | 1229 | */ |
1230 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1231 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1230 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1231 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1242,8 +1242,8 @@ discard block |
||
1242 | 1242 | * @param string $code any value used for LIN_code |
1243 | 1243 | * @return EE_Line_Item |
1244 | 1244 | */ |
1245 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1246 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1245 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1246 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | |
@@ -1257,15 +1257,15 @@ discard block |
||
1257 | 1257 | * @param string $value any value stored in $search_field |
1258 | 1258 | * @return EE_Line_Item |
1259 | 1259 | */ |
1260 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1261 | - foreach( $parent_line_item->children() as $child ){ |
|
1262 | - if ( $child->get( $search_field ) == $value ){ |
|
1260 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1261 | + foreach ($parent_line_item->children() as $child) { |
|
1262 | + if ($child->get($search_field) == $value) { |
|
1263 | 1263 | return $child; |
1264 | 1264 | } |
1265 | 1265 | } |
1266 | - foreach( $parent_line_item->children() as $child ){ |
|
1267 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1268 | - if ( $descendant_found ){ |
|
1266 | + foreach ($parent_line_item->children() as $child) { |
|
1267 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1268 | + if ($descendant_found) { |
|
1269 | 1269 | return $descendant_found; |
1270 | 1270 | } |
1271 | 1271 | } |
@@ -1282,24 +1282,24 @@ discard block |
||
1282 | 1282 | * @return \EE_Line_Item |
1283 | 1283 | * @throws \EE_Error |
1284 | 1284 | */ |
1285 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1286 | - if ( $line_item->TXN_ID() ) { |
|
1287 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1288 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1285 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1286 | + if ($line_item->TXN_ID()) { |
|
1287 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1288 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1289 | 1289 | return $total_line_item; |
1290 | 1290 | } |
1291 | 1291 | } else { |
1292 | 1292 | $line_item_parent = $line_item->parent(); |
1293 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1294 | - if ( $line_item_parent->is_total() ) { |
|
1293 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1294 | + if ($line_item_parent->is_total()) { |
|
1295 | 1295 | return $line_item_parent; |
1296 | 1296 | } |
1297 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1297 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1298 | 1298 | } |
1299 | 1299 | } |
1300 | 1300 | throw new EE_Error( |
1301 | 1301 | sprintf( |
1302 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1302 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1303 | 1303 | $line_item->ID() |
1304 | 1304 | ) |
1305 | 1305 | ); |
@@ -1316,31 +1316,31 @@ discard block |
||
1316 | 1316 | * @return void |
1317 | 1317 | * @throws \EE_Error |
1318 | 1318 | */ |
1319 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1319 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1320 | 1320 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1321 | - if ( ! $indentation ) { |
|
1322 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1321 | + if ( ! $indentation) { |
|
1322 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1323 | 1323 | } |
1324 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1324 | + for ($i = 0; $i < $indentation; $i++) { |
|
1325 | 1325 | echo ". "; |
1326 | 1326 | } |
1327 | 1327 | $breakdown = ''; |
1328 | - if ( $line_item->is_line_item()){ |
|
1329 | - if ( $line_item->is_percent() ) { |
|
1328 | + if ($line_item->is_line_item()) { |
|
1329 | + if ($line_item->is_percent()) { |
|
1330 | 1330 | $breakdown = "{$line_item->percent()}%"; |
1331 | 1331 | } else { |
1332 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1332 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1333 | 1333 | } |
1334 | 1334 | } |
1335 | - echo $line_item->name() . " ( ID:{$line_item->ID()} ) : {$line_item->type()} " . '$' . "{$line_item->total()}"; |
|
1336 | - if ( $breakdown ) { |
|
1335 | + echo $line_item->name()." ( ID:{$line_item->ID()} ) : {$line_item->type()} ".'$'."{$line_item->total()}"; |
|
1336 | + if ($breakdown) { |
|
1337 | 1337 | echo " ( {$breakdown} )"; |
1338 | 1338 | } |
1339 | - if( $line_item->is_taxable() ){ |
|
1339 | + if ($line_item->is_taxable()) { |
|
1340 | 1340 | echo " * taxable"; |
1341 | 1341 | } |
1342 | - if( $line_item->children() ){ |
|
1343 | - foreach($line_item->children() as $child){ |
|
1342 | + if ($line_item->children()) { |
|
1343 | + foreach ($line_item->children() as $child) { |
|
1344 | 1344 | self::visualize($child, $indentation + 1); |
1345 | 1345 | } |
1346 | 1346 | } |
@@ -1381,97 +1381,97 @@ discard block |
||
1381 | 1381 | * is theirs, which can be done with |
1382 | 1382 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1383 | 1383 | */ |
1384 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1384 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1385 | 1385 | //init running grand total if not already |
1386 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1387 | - $running_totals[ 'total' ] = 0; |
|
1386 | + if ( ! isset($running_totals['total'])) { |
|
1387 | + $running_totals['total'] = 0; |
|
1388 | 1388 | } |
1389 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1390 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1389 | + if ( ! isset($running_totals['taxable'])) { |
|
1390 | + $running_totals['taxable'] = array('total' => 0); |
|
1391 | 1391 | } |
1392 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1393 | - switch ( $child_line_item->type() ) { |
|
1392 | + foreach ($line_item->children() as $child_line_item) { |
|
1393 | + switch ($child_line_item->type()) { |
|
1394 | 1394 | |
1395 | 1395 | case EEM_Line_Item::type_sub_total : |
1396 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1396 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1397 | 1397 | //combine arrays but preserve numeric keys |
1398 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1399 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1400 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1398 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1399 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1400 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1401 | 1401 | break; |
1402 | 1402 | |
1403 | 1403 | case EEM_Line_Item::type_tax_sub_total : |
1404 | 1404 | |
1405 | 1405 | //find how much the taxes percentage is |
1406 | - if ( $child_line_item->percent() !== 0 ) { |
|
1406 | + if ($child_line_item->percent() !== 0) { |
|
1407 | 1407 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1408 | 1408 | } else { |
1409 | 1409 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1410 | 1410 | } |
1411 | 1411 | //and apply to all the taxable totals, and add to the pretax totals |
1412 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1412 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1413 | 1413 | //"total" and "taxable" array key is an exception |
1414 | - if ( $line_item_id === 'taxable' ) { |
|
1414 | + if ($line_item_id === 'taxable') { |
|
1415 | 1415 | continue; |
1416 | 1416 | } |
1417 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1418 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1417 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1418 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1419 | 1419 | } |
1420 | 1420 | break; |
1421 | 1421 | |
1422 | 1422 | case EEM_Line_Item::type_line_item : |
1423 | 1423 | |
1424 | 1424 | // ticket line items or ???? |
1425 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1425 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1426 | 1426 | // kk it's a ticket |
1427 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1427 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1428 | 1428 | //huh? that shouldn't happen. |
1429 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1429 | + $running_totals['total'] += $child_line_item->total(); |
|
1430 | 1430 | } else { |
1431 | 1431 | //its not in our running totals yet. great. |
1432 | - if ( $child_line_item->is_taxable() ) { |
|
1432 | + if ($child_line_item->is_taxable()) { |
|
1433 | 1433 | $taxable_amount = $child_line_item->unit_price(); |
1434 | 1434 | } else { |
1435 | 1435 | $taxable_amount = 0; |
1436 | 1436 | } |
1437 | 1437 | // are we only calculating totals for some tickets? |
1438 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1439 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1440 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1438 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1439 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1440 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1441 | 1441 | ? $child_line_item->unit_price() |
1442 | 1442 | : 0; |
1443 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1443 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1444 | 1444 | ? $taxable_amount |
1445 | 1445 | : 0; |
1446 | 1446 | } else { |
1447 | 1447 | $quantity = $child_line_item->quantity(); |
1448 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1449 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1448 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1449 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1450 | 1450 | } |
1451 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1452 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1451 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1452 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1453 | 1453 | } |
1454 | 1454 | } else { |
1455 | 1455 | // it's some other type of item added to the cart |
1456 | 1456 | // it should affect the running totals |
1457 | 1457 | // basically we want to convert it into a PERCENT modifier. Because |
1458 | 1458 | // more clearly affect all registration's final price equally |
1459 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1460 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1459 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1460 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1461 | 1461 | : 1; |
1462 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1462 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1463 | 1463 | //the "taxable" array key is an exception |
1464 | - if ( $line_item_id === 'taxable' ) { |
|
1464 | + if ($line_item_id === 'taxable') { |
|
1465 | 1465 | continue; |
1466 | 1466 | } |
1467 | 1467 | // update the running totals |
1468 | 1468 | // yes this actually even works for the running grand total! |
1469 | - $running_totals[ $line_item_id ] = |
|
1469 | + $running_totals[$line_item_id] = |
|
1470 | 1470 | $line_items_percent_of_running_total * $this_running_total; |
1471 | 1471 | |
1472 | - if ( $child_line_item->is_taxable() ) { |
|
1473 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1474 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1472 | + if ($child_line_item->is_taxable()) { |
|
1473 | + $running_totals['taxable'][$line_item_id] = |
|
1474 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1475 | 1475 | } |
1476 | 1476 | } |
1477 | 1477 | } |
@@ -1489,16 +1489,16 @@ discard block |
||
1489 | 1489 | * @return float | null |
1490 | 1490 | * @throws \OutOfRangeException |
1491 | 1491 | */ |
1492 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1492 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1493 | 1493 | static $final_prices_per_ticket_line_item = array(); |
1494 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1494 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1495 | 1495 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1496 | 1496 | $total_line_item |
1497 | 1497 | ); |
1498 | 1498 | } |
1499 | 1499 | //ok now find this new registration's final price |
1500 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1501 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1500 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1501 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1502 | 1502 | } |
1503 | 1503 | $message = sprintf( |
1504 | 1504 | __( |
@@ -1507,10 +1507,10 @@ discard block |
||
1507 | 1507 | ), |
1508 | 1508 | $ticket_line_item->ID() |
1509 | 1509 | ); |
1510 | - if ( WP_DEBUG ) { |
|
1511 | - throw new \OutOfRangeException( $message ); |
|
1510 | + if (WP_DEBUG) { |
|
1511 | + throw new \OutOfRangeException($message); |
|
1512 | 1512 | } else { |
1513 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1513 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1514 | 1514 | } |
1515 | 1515 | return null; |
1516 | 1516 | } |
@@ -1526,15 +1526,15 @@ discard block |
||
1526 | 1526 | * @return \EE_Line_Item |
1527 | 1527 | * @throws \EE_Error |
1528 | 1528 | */ |
1529 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1530 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1531 | - foreach ( $line_item->children() as $child_li ) { |
|
1532 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1529 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1530 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1531 | + foreach ($line_item->children() as $child_li) { |
|
1532 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1533 | 1533 | } |
1534 | 1534 | //if this is the grand total line item, make sure the totals all add up |
1535 | 1535 | //(we could have duplicated this logic AS we copied the line items, but |
1536 | 1536 | //it seems DRYer this way) |
1537 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1537 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1538 | 1538 | $copy_li->recalculate_total_including_taxes(); |
1539 | 1539 | } |
1540 | 1540 | return $copy_li; |
@@ -1551,24 +1551,24 @@ discard block |
||
1551 | 1551 | * @throws \EE_Error |
1552 | 1552 | * @param EE_Registration[] $registrations |
1553 | 1553 | */ |
1554 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1554 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1555 | 1555 | $new_li_fields = $line_item->model_field_array(); |
1556 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1556 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1557 | 1557 | $line_item->OBJ_type() === 'Ticket' |
1558 | 1558 | ) { |
1559 | 1559 | $count = 0; |
1560 | - foreach ( $registrations as $registration ) { |
|
1561 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1562 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1560 | + foreach ($registrations as $registration) { |
|
1561 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1562 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1563 | 1563 | ) { |
1564 | 1564 | $count++; |
1565 | 1565 | } |
1566 | 1566 | } |
1567 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1567 | + $new_li_fields['LIN_quantity'] = $count; |
|
1568 | 1568 | } |
1569 | 1569 | //don't set the total. We'll leave that up to the code that calculates it |
1570 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1571 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1570 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1571 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | |
@@ -1581,19 +1581,19 @@ discard block |
||
1581 | 1581 | * @return \EE_Line_Item|null |
1582 | 1582 | * @throws \EE_Error |
1583 | 1583 | */ |
1584 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1585 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1586 | - if ( $copied_li === null ) { |
|
1584 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1585 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1586 | + if ($copied_li === null) { |
|
1587 | 1587 | return null; |
1588 | 1588 | } |
1589 | 1589 | //if this is an event subtotal, we want to only include it if it |
1590 | 1590 | //has a non-zero total and at least one ticket line item child |
1591 | 1591 | $ticket_children = 0; |
1592 | - foreach ( $line_item->children() as $child_li ) { |
|
1593 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1594 | - if ( $child_li_copy !== null ) { |
|
1595 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1596 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1592 | + foreach ($line_item->children() as $child_li) { |
|
1593 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1594 | + if ($child_li_copy !== null) { |
|
1595 | + $copied_li->add_child_line_item($child_li_copy); |
|
1596 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1597 | 1597 | $child_li_copy->OBJ_type() === 'Ticket' |
1598 | 1598 | ) { |
1599 | 1599 | $ticket_children++; |
@@ -1623,8 +1623,8 @@ discard block |
||
1623 | 1623 | * @return EE_Line_Item |
1624 | 1624 | * @throws \EE_Error |
1625 | 1625 | */ |
1626 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1627 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1626 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1627 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1628 | 1628 | $line_item->OBJ_type() === 'Ticket' && |
1629 | 1629 | $line_item->quantity() === 0 |
1630 | 1630 | ) { |
@@ -1632,8 +1632,8 @@ discard block |
||
1632 | 1632 | } |
1633 | 1633 | $new_li_fields = $line_item->model_field_array(); |
1634 | 1634 | //don't set the total. We'll leave that up to the code that calculates it |
1635 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1636 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1635 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1636 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | |
@@ -1645,9 +1645,9 @@ discard block |
||
1645 | 1645 | * @return \EE_Line_Item |
1646 | 1646 | * @throws \EE_Error |
1647 | 1647 | */ |
1648 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1649 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1650 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1648 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1649 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1650 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1651 | 1651 | } |
1652 | 1652 | |
1653 | 1653 | |
@@ -1658,9 +1658,9 @@ discard block |
||
1658 | 1658 | * @return \EE_Line_Item |
1659 | 1659 | * @throws \EE_Error |
1660 | 1660 | */ |
1661 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1662 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
1663 | - return self::create_total_line_item( $transaction ); |
|
1661 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1662 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
1663 | + return self::create_total_line_item($transaction); |
|
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | |
@@ -1672,9 +1672,9 @@ discard block |
||
1672 | 1672 | * @return \EE_Line_Item |
1673 | 1673 | * @throws \EE_Error |
1674 | 1674 | */ |
1675 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1676 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1677 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1675 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1676 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1677 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | |
@@ -1686,9 +1686,9 @@ discard block |
||
1686 | 1686 | * @return \EE_Line_Item |
1687 | 1687 | * @throws \EE_Error |
1688 | 1688 | */ |
1689 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1690 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1691 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1689 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1690 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
1691 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1692 | 1692 | } |
1693 | 1693 | |
1694 | 1694 | |
@@ -1700,9 +1700,9 @@ discard block |
||
1700 | 1700 | * @return \EE_Line_Item |
1701 | 1701 | * @throws \EE_Error |
1702 | 1702 | */ |
1703 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1704 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1705 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1703 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1704 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
1705 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | 1708 |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * @ version 4.0 |
13 | 13 | * |
14 | 14 | */ |
15 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
16 | -require_once( EE_INTERFACES . 'EEI_Interfaces.php' ); |
|
15 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
16 | +require_once(EE_INTERFACES.'EEI_Interfaces.php'); |
|
17 | 17 | /** |
18 | 18 | * |
19 | 19 | * Class EEH_File |
@@ -52,30 +52,30 @@ discard block |
||
52 | 52 | * @throws EE_Error if filesystem credentials are required |
53 | 53 | * @return WP_Filesystem_Base |
54 | 54 | */ |
55 | - private static function _get_wp_filesystem( $filepath = null) { |
|
56 | - if( apply_filters( |
|
55 | + private static function _get_wp_filesystem($filepath = null) { |
|
56 | + if (apply_filters( |
|
57 | 57 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
58 | - $filepath && EEH_File::is_in_uploads_folder( $filepath ), |
|
59 | - $filepath ) ) { |
|
60 | - if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) { |
|
61 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
58 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
59 | + $filepath )) { |
|
60 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
61 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
62 | 62 | $method = 'direct'; |
63 | - $wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); |
|
63 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
64 | 64 | //check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
65 | - if ( ! defined('FS_CHMOD_DIR') ) { |
|
66 | - define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) ); |
|
65 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
66 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
67 | 67 | } |
68 | - if ( ! defined('FS_CHMOD_FILE') ) { |
|
69 | - define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) ); |
|
68 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
69 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
70 | 70 | } |
71 | - require_once( $wp_filesystem_direct_file ); |
|
72 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() ); |
|
71 | + require_once($wp_filesystem_direct_file); |
|
72 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
73 | 73 | } |
74 | 74 | return EEH_File::$_wp_filesystem_direct; |
75 | 75 | } |
76 | 76 | global $wp_filesystem; |
77 | 77 | // no filesystem setup ??? |
78 | - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { |
|
78 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
79 | 79 | // if some eager beaver's just trying to get in there too early... |
80 | 80 | // let them do it, because we are one of those eager beavers! :P |
81 | 81 | /** |
@@ -88,34 +88,34 @@ discard block |
||
88 | 88 | * and there may be troubles if the WP files are owned by a different user |
89 | 89 | * than the server user. But both of these issues should exist in 4.4 and earlier too |
90 | 90 | */ |
91 | - if ( FALSE && ! did_action( 'wp_loaded' )) { |
|
91 | + if (FALSE && ! did_action('wp_loaded')) { |
|
92 | 92 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
93 | - if ( WP_DEBUG ) { |
|
94 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
93 | + if (WP_DEBUG) { |
|
94 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
95 | 95 | } |
96 | - throw new EE_Error( $msg ); |
|
96 | + throw new EE_Error($msg); |
|
97 | 97 | } else { |
98 | 98 | // should be loaded if we are past the wp_loaded hook... |
99 | - if ( ! function_exists( 'WP_Filesystem' )) { |
|
100 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
101 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
99 | + if ( ! function_exists('WP_Filesystem')) { |
|
100 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
101 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
102 | 102 | } |
103 | 103 | // turn on output buffering so that we can capture the credentials form |
104 | 104 | ob_start(); |
105 | - $credentials = request_filesystem_credentials( '' ); |
|
105 | + $credentials = request_filesystem_credentials(''); |
|
106 | 106 | // store credentials form for the time being |
107 | 107 | EEH_File::$_credentials_form = ob_get_clean(); |
108 | 108 | // basically check for direct or previously configured access |
109 | - if ( ! WP_Filesystem( $credentials ) ) { |
|
109 | + if ( ! WP_Filesystem($credentials)) { |
|
110 | 110 | // if credentials do NOT exist |
111 | - if ( $credentials === FALSE ) { |
|
112 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
113 | - throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
114 | - } elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
115 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
111 | + if ($credentials === FALSE) { |
|
112 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
113 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
114 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
115 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
116 | 116 | throw new EE_Error( |
117 | 117 | sprintf( |
118 | - __( 'WP Filesystem Error: $1%s', 'event_espresso' ), |
|
118 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
119 | 119 | $wp_filesystem->errors->get_error_message() ) ); |
120 | 120 | } |
121 | 121 | } |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * display_request_filesystem_credentials_form |
129 | 129 | */ |
130 | 130 | public static function display_request_filesystem_credentials_form() { |
131 | - if ( ! empty( EEH_File::$_credentials_form )) { |
|
132 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
131 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
132 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -147,29 +147,29 @@ discard block |
||
147 | 147 | * @throws EE_Error if filesystem credentials are required |
148 | 148 | * @return bool |
149 | 149 | */ |
150 | - public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) { |
|
150 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') { |
|
151 | 151 | // load WP_Filesystem and set file permissions |
152 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
153 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
154 | - if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) { |
|
155 | - $file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name; |
|
156 | - $file_name .= ! empty( $file_ext ) ? ' file' : ' folder'; |
|
152 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
153 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
154 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
155 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
156 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
157 | 157 | $msg = sprintf( |
158 | - __( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ), |
|
158 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
159 | 159 | $file_name, |
160 | 160 | '<br />' |
161 | 161 | ); |
162 | - if ( EEH_File::exists( $full_file_path )) { |
|
163 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file ); |
|
162 | + if (EEH_File::exists($full_file_path)) { |
|
163 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
164 | 164 | } else { |
165 | 165 | // no file permissions means the file was not found |
166 | 166 | $msg .= sprintf( |
167 | - __( 'Please ensure the following path is correct: "%s".', 'event_espresso' ), |
|
167 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
168 | 168 | $full_file_path |
169 | 169 | ); |
170 | 170 | } |
171 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
172 | - throw new EE_Error( $msg . '||' . $msg ); |
|
171 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
172 | + throw new EE_Error($msg.'||'.$msg); |
|
173 | 173 | } |
174 | 174 | return FALSE; |
175 | 175 | } |
@@ -187,24 +187,24 @@ discard block |
||
187 | 187 | * @throws EE_Error if filesystem credentials are required |
188 | 188 | * @return string |
189 | 189 | */ |
190 | - private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){ |
|
190 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') { |
|
191 | 191 | // load WP_Filesystem and set file permissions |
192 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
192 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
193 | 193 | // check file permissions |
194 | - $perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
195 | - if ( $perms ) { |
|
194 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
195 | + if ($perms) { |
|
196 | 196 | // file permissions exist, but way be set incorrectly |
197 | - $type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : ''; |
|
198 | - $type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder'; |
|
197 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
198 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
199 | 199 | return sprintf( |
200 | - __( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ), |
|
200 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
201 | 201 | $type_of_file, |
202 | 202 | $perms |
203 | 203 | ); |
204 | 204 | } else { |
205 | 205 | // file exists but file permissions could not be read ?!?! |
206 | 206 | return sprintf( |
207 | - __( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ), |
|
207 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
208 | 208 | $full_file_path |
209 | 209 | ); |
210 | 210 | } |
@@ -222,35 +222,35 @@ discard block |
||
222 | 222 | * can't write to it |
223 | 223 | * @return bool false if folder isn't writable; true if it exists and is writeable, |
224 | 224 | */ |
225 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ){ |
|
226 | - if ( empty( $folder )) { |
|
225 | + public static function ensure_folder_exists_and_is_writable($folder = '') { |
|
226 | + if (empty($folder)) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | // remove ending DS |
230 | - $folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' )); |
|
231 | - $parent_folder = EEH_File::get_parent_folder( $folder ); |
|
230 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
231 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
232 | 232 | // add DS to folder |
233 | - $folder = EEH_File::end_with_directory_separator( $folder ); |
|
234 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $folder ); |
|
235 | - if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
233 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
234 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
235 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
236 | 236 | //ok so it doesn't exist. Does its parent? Can we write to it? |
237 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
237 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | - if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) { |
|
240 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
241 | 241 | return false; |
242 | 242 | } else { |
243 | - if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
244 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
245 | - $msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder ); |
|
246 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder ); |
|
247 | - throw new EE_Error( $msg ); |
|
243 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
244 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
245 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
246 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
247 | + throw new EE_Error($msg); |
|
248 | 248 | } |
249 | 249 | return false; |
250 | 250 | } |
251 | - EEH_File::add_index_file( $folder ); |
|
251 | + EEH_File::add_index_file($folder); |
|
252 | 252 | } |
253 | - } elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
253 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | return true; |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | * @throws EE_Error if filesystem credentials are required |
266 | 266 | * @return bool |
267 | 267 | */ |
268 | - public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){ |
|
268 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') { |
|
269 | 269 | // load WP_Filesystem and set file permissions |
270 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_path ); |
|
271 | - $full_path = EEH_File::standardise_directory_separators( $full_path ); |
|
272 | - if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) { |
|
273 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
274 | - $msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder ); |
|
275 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path ); |
|
276 | - throw new EE_Error( $msg ); |
|
270 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
271 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
272 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
273 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
274 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
275 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
276 | + throw new EE_Error($msg); |
|
277 | 277 | } |
278 | 278 | return FALSE; |
279 | 279 | } |
@@ -290,25 +290,25 @@ discard block |
||
290 | 290 | * @throws EE_Error if filesystem credentials are required |
291 | 291 | * @return bool |
292 | 292 | */ |
293 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) { |
|
293 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') { |
|
294 | 294 | // load WP_Filesystem and set file permissions |
295 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
296 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
297 | - $parent_folder = EEH_File::get_parent_folder( $full_file_path ); |
|
298 | - if ( ! EEH_File::exists( $full_file_path )) { |
|
299 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
295 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
296 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
297 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
298 | + if ( ! EEH_File::exists($full_file_path)) { |
|
299 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
300 | 300 | return false; |
301 | 301 | } |
302 | - if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
303 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
304 | - $msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path ); |
|
305 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
306 | - throw new EE_Error( $msg ); |
|
302 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
303 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
304 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
305 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
306 | + throw new EE_Error($msg); |
|
307 | 307 | } |
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | } |
311 | - if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) { |
|
311 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
312 | 312 | return false; |
313 | 313 | } |
314 | 314 | return true; |
@@ -320,12 +320,12 @@ discard block |
||
320 | 320 | * @param string $file_or_folder_path |
321 | 321 | * @return string parent folder, ENDING with a directory separator |
322 | 322 | */ |
323 | - public static function get_parent_folder( $file_or_folder_path ) { |
|
323 | + public static function get_parent_folder($file_or_folder_path) { |
|
324 | 324 | //find the last DS, ignoring a DS on the very end |
325 | 325 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
326 | 326 | //parent folder, "/var/something/" |
327 | - $ds = strlen($file_or_folder_path) > 1 ? strrpos( $file_or_folder_path, DS, -2 ) : $file_or_folder_path; |
|
328 | - return substr( $file_or_folder_path, 0, $ds + 1 ); |
|
327 | + $ds = strlen($file_or_folder_path) > 1 ? strrpos($file_or_folder_path, DS, -2) : $file_or_folder_path; |
|
328 | + return substr($file_or_folder_path, 0, $ds + 1); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // public static function ensure_folder_exists_recursively( $folder ) { |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | * @throws EE_Error if filesystem credentials are required |
341 | 341 | * @return string |
342 | 342 | */ |
343 | - public static function get_file_contents( $full_file_path = '' ){ |
|
344 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
345 | - if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) { |
|
343 | + public static function get_file_contents($full_file_path = '') { |
|
344 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
345 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
346 | 346 | // load WP_Filesystem and set file permissions |
347 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
348 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
347 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
348 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
349 | 349 | } |
350 | 350 | return ''; |
351 | 351 | } |
@@ -360,26 +360,26 @@ discard block |
||
360 | 360 | * @throws EE_Error if filesystem credentials are required |
361 | 361 | * @return bool |
362 | 362 | */ |
363 | - public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){ |
|
364 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
365 | - $file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : ''; |
|
366 | - $folder = EEH_File::remove_filename_from_filepath( $full_file_path ); |
|
367 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
368 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
369 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path ); |
|
370 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
371 | - throw new EE_Error( $msg ); |
|
363 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') { |
|
364 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
365 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
366 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
367 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
368 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
369 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
370 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
371 | + throw new EE_Error($msg); |
|
372 | 372 | } |
373 | 373 | return FALSE; |
374 | 374 | } |
375 | 375 | // load WP_Filesystem and set file permissions |
376 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
376 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
377 | 377 | // write the file |
378 | - if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) { |
|
379 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
380 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path ); |
|
381 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' ); |
|
382 | - throw new EE_Error( $msg ); |
|
378 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
379 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
380 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
381 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
382 | + throw new EE_Error($msg); |
|
383 | 383 | } |
384 | 384 | return FALSE; |
385 | 385 | } |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | * @throws EE_Error if filesystem credentials are required |
396 | 396 | * @return boolean |
397 | 397 | */ |
398 | - public static function delete( $filepath, $recursive = false, $type = false ) { |
|
398 | + public static function delete($filepath, $recursive = false, $type = false) { |
|
399 | 399 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
400 | - return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE; |
|
400 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @throws EE_Error if filesystem credentials are required |
410 | 410 | * @return bool |
411 | 411 | */ |
412 | - public static function exists( $full_file_path = '' ) { |
|
413 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
414 | - return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE; |
|
412 | + public static function exists($full_file_path = '') { |
|
413 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
414 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | * @throws EE_Error if filesystem credentials are required |
425 | 425 | * @return bool |
426 | 426 | */ |
427 | - public static function is_readable( $full_file_path = '' ) { |
|
428 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
429 | - if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
427 | + public static function is_readable($full_file_path = '') { |
|
428 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
429 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
430 | 430 | return true; |
431 | 431 | } else { |
432 | 432 | return false; |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $full_file_path |
443 | 443 | * @return string |
444 | 444 | */ |
445 | - public static function remove_filename_from_filepath( $full_file_path = '' ) { |
|
446 | - return pathinfo( $full_file_path, PATHINFO_DIRNAME ); |
|
445 | + public static function remove_filename_from_filepath($full_file_path = '') { |
|
446 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $full_file_path |
454 | 454 | * @return string |
455 | 455 | */ |
456 | - public static function get_filename_from_filepath( $full_file_path = '' ) { |
|
457 | - return pathinfo( $full_file_path, PATHINFO_BASENAME ); |
|
456 | + public static function get_filename_from_filepath($full_file_path = '') { |
|
457 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | * @param string $full_file_path |
465 | 465 | * @return string |
466 | 466 | */ |
467 | - public static function get_file_extension( $full_file_path = '' ) { |
|
468 | - return pathinfo( $full_file_path, PATHINFO_EXTENSION ); |
|
467 | + public static function get_file_extension($full_file_path = '') { |
|
468 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | |
@@ -476,10 +476,10 @@ discard block |
||
476 | 476 | * @throws EE_Error if filesystem credentials are required |
477 | 477 | * @return bool |
478 | 478 | */ |
479 | - public static function add_htaccess_deny_from_all( $folder = '' ) { |
|
480 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
481 | - if ( ! EEH_File::exists( $folder . '.htaccess' ) ) { |
|
482 | - if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) { |
|
479 | + public static function add_htaccess_deny_from_all($folder = '') { |
|
480 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
481 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
482 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
483 | 483 | return FALSE; |
484 | 484 | } |
485 | 485 | } |
@@ -493,10 +493,10 @@ discard block |
||
493 | 493 | * @throws EE_Error if filesystem credentials are required |
494 | 494 | * @return boolean |
495 | 495 | */ |
496 | - public static function add_index_file( $folder ) { |
|
497 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
498 | - if ( ! EEH_File::exists( $folder . 'index.php' ) ) { |
|
499 | - if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) { |
|
496 | + public static function add_index_file($folder) { |
|
497 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
498 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
499 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
500 | 500 | return false; |
501 | 501 | } |
502 | 502 | } |
@@ -511,11 +511,11 @@ discard block |
||
511 | 511 | * @param string $file_path |
512 | 512 | * @return string |
513 | 513 | */ |
514 | - public static function get_classname_from_filepath_with_standard_filename( $file_path ){ |
|
514 | + public static function get_classname_from_filepath_with_standard_filename($file_path) { |
|
515 | 515 | //extract file from path |
516 | - $filename = basename( $file_path ); |
|
516 | + $filename = basename($file_path); |
|
517 | 517 | //now remove the first period and everything after |
518 | - $pos_of_first_period = strpos( $filename,'.' ); |
|
518 | + $pos_of_first_period = strpos($filename, '.'); |
|
519 | 519 | return substr($filename, 0, $pos_of_first_period); |
520 | 520 | } |
521 | 521 | |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | * @param string $file_path |
528 | 528 | * @return string |
529 | 529 | */ |
530 | - public static function standardise_directory_separators( $file_path ){ |
|
531 | - return str_replace( array( '\\', '/' ), DS, $file_path ); |
|
530 | + public static function standardise_directory_separators($file_path) { |
|
531 | + return str_replace(array('\\', '/'), DS, $file_path); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * @param string $file_path |
540 | 540 | * @return string |
541 | 541 | */ |
542 | - public static function end_with_directory_separator( $file_path ){ |
|
543 | - return rtrim( $file_path, '/\\' ) . DS; |
|
542 | + public static function end_with_directory_separator($file_path) { |
|
543 | + return rtrim($file_path, '/\\').DS; |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param $file_path |
551 | 551 | * @return string |
552 | 552 | */ |
553 | - public static function standardise_and_end_with_directory_separator( $file_path ){ |
|
554 | - return self::end_with_directory_separator( self::standardise_directory_separators( $file_path )); |
|
553 | + public static function standardise_and_end_with_directory_separator($file_path) { |
|
554 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | |
@@ -568,21 +568,21 @@ discard block |
||
568 | 568 | * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
569 | 569 | * and values are their filepaths |
570 | 570 | */ |
571 | - public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){ |
|
571 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) { |
|
572 | 572 | $class_to_folder_path = array(); |
573 | - foreach( $folder_paths as $folder_path ){ |
|
574 | - $folder_path = self::standardise_and_end_with_directory_separator( $folder_path ); |
|
573 | + foreach ($folder_paths as $folder_path) { |
|
574 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
575 | 575 | // load WP_Filesystem and set file permissions |
576 | - $files_in_folder = glob( $folder_path . '*' ); |
|
576 | + $files_in_folder = glob($folder_path.'*'); |
|
577 | 577 | $class_to_folder_path = array(); |
578 | - if ( $files_in_folder ) { |
|
579 | - foreach( $files_in_folder as $file_path ){ |
|
578 | + if ($files_in_folder) { |
|
579 | + foreach ($files_in_folder as $file_path) { |
|
580 | 580 | //only add files, not folders |
581 | - if ( ! is_dir( $file_path )) { |
|
582 | - if ( $index_numerically ) { |
|
581 | + if ( ! is_dir($file_path)) { |
|
582 | + if ($index_numerically) { |
|
583 | 583 | $class_to_folder_path[] = $file_path; |
584 | 584 | } else { |
585 | - $classname = self::get_classname_from_filepath_with_standard_filename( $file_path ); |
|
585 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
586 | 586 | $class_to_folder_path[$classname] = $file_path; |
587 | 587 | } |
588 | 588 | } |
@@ -602,39 +602,39 @@ discard block |
||
602 | 602 | * @throws EE_Error if filesystem credentials are required |
603 | 603 | * @return boolean success |
604 | 604 | */ |
605 | - public static function copy( $source_file, $destination_file, $overwrite = FALSE ){ |
|
606 | - $full_source_path = EEH_File::standardise_directory_separators( $source_file ); |
|
607 | - if( ! EEH_File::exists( $full_source_path ) ){ |
|
608 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
609 | - $msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path ); |
|
610 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path ); |
|
611 | - throw new EE_Error( $msg ); |
|
605 | + public static function copy($source_file, $destination_file, $overwrite = FALSE) { |
|
606 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
607 | + if ( ! EEH_File::exists($full_source_path)) { |
|
608 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
609 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
610 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
611 | + throw new EE_Error($msg); |
|
612 | 612 | } |
613 | 613 | return FALSE; |
614 | 614 | } |
615 | 615 | |
616 | - $full_dest_path = EEH_File::standardise_directory_separators( $destination_file ); |
|
617 | - $folder = EEH_File::remove_filename_from_filepath( $full_dest_path ); |
|
618 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
619 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
620 | - $msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path ); |
|
621 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path ); |
|
622 | - throw new EE_Error( $msg ); |
|
616 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
617 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
618 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
619 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
620 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
621 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
622 | + throw new EE_Error($msg); |
|
623 | 623 | } |
624 | 624 | return FALSE; |
625 | 625 | } |
626 | 626 | |
627 | 627 | // load WP_Filesystem and set file permissions |
628 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file ); |
|
628 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
629 | 629 | // write the file |
630 | 630 | if ( ! $wp_filesystem->copy( |
631 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), |
|
632 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), |
|
631 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
632 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
633 | 633 | $overwrite )) { |
634 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
635 | - $msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path ); |
|
636 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' ); |
|
637 | - throw new EE_Error( $msg ); |
|
634 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
635 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
636 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
637 | + throw new EE_Error($msg); |
|
638 | 638 | } |
639 | 639 | return FALSE; |
640 | 640 | } |
@@ -646,9 +646,9 @@ discard block |
||
646 | 646 | * @param string $filepath |
647 | 647 | * @return boolean |
648 | 648 | */ |
649 | - public static function is_in_uploads_folder( $filepath ) { |
|
649 | + public static function is_in_uploads_folder($filepath) { |
|
650 | 650 | $uploads = wp_upload_dir(); |
651 | - return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false; |
|
651 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -663,9 +663,9 @@ discard block |
||
663 | 663 | * @return string the remote filepath (eg the filepath the filesystem method, eg |
664 | 664 | * ftp or ssh, will use to access the folder |
665 | 665 | */ |
666 | - public static function convert_local_filepath_to_remote_filepath( $local_filepath ) { |
|
667 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath ); |
|
668 | - return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath ); |
|
666 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) { |
|
667 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
668 | + return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath); |
|
669 | 669 | } |
670 | 670 | } |
671 | 671 | // End of file EEH_File.helper.php |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * @param \EE_Dependency_Map $dependency_map |
185 | 185 | * @return \EE_Registry instance |
186 | 186 | */ |
187 | - public static function instance( \EE_Dependency_Map $dependency_map = null ) { |
|
187 | + public static function instance(\EE_Dependency_Map $dependency_map = null) { |
|
188 | 188 | // check if class object is instantiated |
189 | - if ( ! self::$_instance instanceof EE_Registry ) { |
|
190 | - self::$_instance = new EE_Registry( $dependency_map ); |
|
189 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
190 | + self::$_instance = new EE_Registry($dependency_map); |
|
191 | 191 | } |
192 | 192 | return self::$_instance; |
193 | 193 | } |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | * @param \EE_Dependency_Map $dependency_map |
203 | 203 | * @return \EE_Registry |
204 | 204 | */ |
205 | - protected function __construct( \EE_Dependency_Map $dependency_map ) { |
|
205 | + protected function __construct(\EE_Dependency_Map $dependency_map) { |
|
206 | 206 | $this->_dependency_map = $dependency_map; |
207 | - add_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', array( $this, 'initialize' ) ); |
|
207 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -232,19 +232,19 @@ discard block |
||
232 | 232 | $this->modules = new stdClass(); |
233 | 233 | $this->shortcodes = new stdClass(); |
234 | 234 | $this->widgets = new stdClass(); |
235 | - $this->load_core( 'Base', array(), true ); |
|
235 | + $this->load_core('Base', array(), true); |
|
236 | 236 | // add our request and response objects to the cache |
237 | - $request_loader = $this->_dependency_map->class_loader( 'EE_Request' ); |
|
237 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
238 | 238 | $this->_set_cached_class( |
239 | 239 | $request_loader(), |
240 | 240 | 'EE_Request' |
241 | 241 | ); |
242 | - $response_loader = $this->_dependency_map->class_loader( 'EE_Response' ); |
|
242 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
243 | 243 | $this->_set_cached_class( |
244 | 244 | $response_loader(), |
245 | 245 | 'EE_Response' |
246 | 246 | ); |
247 | - add_action( 'AHEE__EE_System__set_hooks_for_core', array( $this, 'init' ) ); |
|
247 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function init() { |
259 | 259 | // Get current page protocol |
260 | - $protocol = isset( $_SERVER[ 'HTTPS' ] ) ? 'https://' : 'http://'; |
|
260 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
261 | 261 | // Output admin-ajax.php URL with same protocol as current page |
262 | - self::$i18n_js_strings[ 'ajax_url' ] = admin_url( 'admin-ajax.php', $protocol ); |
|
263 | - self::$i18n_js_strings[ 'wp_debug' ] = defined( 'WP_DEBUG' ) ? WP_DEBUG : false; |
|
262 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
263 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | |
@@ -271,14 +271,14 @@ discard block |
||
271 | 271 | * @return string |
272 | 272 | */ |
273 | 273 | public static function localize_i18n_js_strings() { |
274 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
275 | - foreach ( $i18n_js_strings as $key => $value ) { |
|
276 | - if ( is_scalar( $value ) ) { |
|
277 | - $i18n_js_strings[ $key ] = html_entity_decode( (string)$value, ENT_QUOTES, 'UTF-8' ); |
|
274 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
275 | + foreach ($i18n_js_strings as $key => $value) { |
|
276 | + if (is_scalar($value)) { |
|
277 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode( $i18n_js_strings ) . '; /* ]]> */'; |
|
281 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | /** |
287 | 287 | * @param mixed string | EED_Module $module |
288 | 288 | */ |
289 | - public function add_module( $module ) { |
|
290 | - if ( $module instanceof EED_Module ) { |
|
291 | - $module_class = get_class( $module ); |
|
289 | + public function add_module($module) { |
|
290 | + if ($module instanceof EED_Module) { |
|
291 | + $module_class = get_class($module); |
|
292 | 292 | $this->modules->{$module_class} = $module; |
293 | 293 | } else { |
294 | - if ( ! class_exists( 'EE_Module_Request_Router' ) ) { |
|
295 | - $this->load_core( 'Module_Request_Router' ); |
|
294 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
295 | + $this->load_core('Module_Request_Router'); |
|
296 | 296 | } |
297 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory( $module ); |
|
297 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | * @param string $module_name |
305 | 305 | * @return mixed EED_Module | NULL |
306 | 306 | */ |
307 | - public function get_module( $module_name = '' ) { |
|
308 | - return isset( $this->modules->{$module_name} ) ? $this->modules->{$module_name} : null; |
|
307 | + public function get_module($module_name = '') { |
|
308 | + return isset($this->modules->{$module_name} ) ? $this->modules->{$module_name} : null; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -319,20 +319,20 @@ discard block |
||
319 | 319 | * @param bool $load_only |
320 | 320 | * @return mixed |
321 | 321 | */ |
322 | - public function load_core( $class_name, $arguments = array(), $load_only = false ) { |
|
322 | + public function load_core($class_name, $arguments = array(), $load_only = false) { |
|
323 | 323 | $core_paths = apply_filters( |
324 | 324 | 'FHEE__EE_Registry__load_core__core_paths', |
325 | 325 | array( |
326 | 326 | EE_CORE, |
327 | 327 | EE_ADMIN, |
328 | 328 | EE_CPTS, |
329 | - EE_CORE . 'data_migration_scripts' . DS, |
|
330 | - EE_CORE . 'request_stack' . DS, |
|
331 | - EE_CORE . 'middleware' . DS, |
|
329 | + EE_CORE.'data_migration_scripts'.DS, |
|
330 | + EE_CORE.'request_stack'.DS, |
|
331 | + EE_CORE.'middleware'.DS, |
|
332 | 332 | ) |
333 | 333 | ); |
334 | 334 | // retrieve instantiated class |
335 | - return $this->_load( $core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only ); |
|
335 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -346,15 +346,15 @@ discard block |
||
346 | 346 | * @param bool $load_only |
347 | 347 | * @return mixed |
348 | 348 | */ |
349 | - public function load_service( $class_name, $arguments = array(), $load_only = false ) { |
|
349 | + public function load_service($class_name, $arguments = array(), $load_only = false) { |
|
350 | 350 | $service_paths = apply_filters( |
351 | 351 | 'FHEE__EE_Registry__load_service__service_paths', |
352 | 352 | array( |
353 | - EE_CORE . 'services' . DS, |
|
353 | + EE_CORE.'services'.DS, |
|
354 | 354 | ) |
355 | 355 | ); |
356 | 356 | // retrieve instantiated class |
357 | - return $this->_load( $service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only ); |
|
357 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | * @param mixed $arguments |
368 | 368 | * @return EE_Data_Migration_Script_Base|mixed |
369 | 369 | */ |
370 | - public function load_dms( $class_name, $arguments = array() ) { |
|
370 | + public function load_dms($class_name, $arguments = array()) { |
|
371 | 371 | // retrieve instantiated class |
372 | - return $this->_load( EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false ); |
|
372 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
385 | 385 | * @return EE_Base_Class | bool |
386 | 386 | */ |
387 | - public function load_class( $class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false ) { |
|
388 | - $paths = apply_filters( 'FHEE__EE_Registry__load_class__paths', array( |
|
387 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) { |
|
388 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
389 | 389 | EE_CORE, |
390 | 390 | EE_CLASSES, |
391 | 391 | EE_BUSINESS |
392 | - ) ); |
|
392 | + )); |
|
393 | 393 | // retrieve instantiated class |
394 | - return $this->_load( $paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only ); |
|
394 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | |
@@ -404,11 +404,11 @@ discard block |
||
404 | 404 | * @param bool $load_only |
405 | 405 | * @return EEH_Base | bool |
406 | 406 | */ |
407 | - public function load_helper( $class_name, $arguments = array(), $load_only = true ) { |
|
407 | + public function load_helper($class_name, $arguments = array(), $load_only = true) { |
|
408 | 408 | // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
409 | - $helper_paths = apply_filters( 'FHEE__EE_Registry__load_helper__helper_paths', array( EE_HELPERS ) ); |
|
409 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
410 | 410 | // retrieve instantiated class |
411 | - return $this->_load( $helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only ); |
|
411 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | |
@@ -423,16 +423,16 @@ discard block |
||
423 | 423 | * @param bool $cache whether to cache the object or not. |
424 | 424 | * @return mixed |
425 | 425 | */ |
426 | - public function load_lib( $class_name, $arguments = array(), $load_only = false, $cache = true ) { |
|
426 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) { |
|
427 | 427 | $paths = array( |
428 | 428 | EE_LIBRARIES, |
429 | - EE_LIBRARIES . 'messages' . DS, |
|
430 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
431 | - EE_LIBRARIES . 'qtips' . DS, |
|
432 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
429 | + EE_LIBRARIES.'messages'.DS, |
|
430 | + EE_LIBRARIES.'shortcodes'.DS, |
|
431 | + EE_LIBRARIES.'qtips'.DS, |
|
432 | + EE_LIBRARIES.'payment_methods'.DS, |
|
433 | 433 | ); |
434 | 434 | // retrieve instantiated class |
435 | - return $this->_load( $paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only ); |
|
435 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | |
@@ -445,13 +445,13 @@ discard block |
||
445 | 445 | * @param bool $load_only |
446 | 446 | * @return EEM_Base | bool |
447 | 447 | */ |
448 | - public function load_model( $class_name, $arguments = array(), $load_only = false ) { |
|
449 | - $paths = apply_filters( 'FHEE__EE_Registry__load_model__paths', array( |
|
448 | + public function load_model($class_name, $arguments = array(), $load_only = false) { |
|
449 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
450 | 450 | EE_MODELS, |
451 | 451 | EE_CORE |
452 | - ) ); |
|
452 | + )); |
|
453 | 453 | // retrieve instantiated class |
454 | - return $this->_load( $paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only ); |
|
454 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | * @param bool $load_only |
465 | 465 | * @return mixed | bool |
466 | 466 | */ |
467 | - public function load_model_class( $class_name, $arguments = array(), $load_only = true ) { |
|
467 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) { |
|
468 | 468 | $paths = array( |
469 | - EE_MODELS . 'fields' . DS, |
|
470 | - EE_MODELS . 'helpers' . DS, |
|
471 | - EE_MODELS . 'relations' . DS, |
|
472 | - EE_MODELS . 'strategies' . DS |
|
469 | + EE_MODELS.'fields'.DS, |
|
470 | + EE_MODELS.'helpers'.DS, |
|
471 | + EE_MODELS.'relations'.DS, |
|
472 | + EE_MODELS.'strategies'.DS |
|
473 | 473 | ); |
474 | 474 | // retrieve instantiated class |
475 | - return $this->_load( $paths, 'EE_', $class_name, '', $arguments, false, true, $load_only ); |
|
475 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
483 | 483 | * @return boolean |
484 | 484 | */ |
485 | - public function is_model_name( $model_name ) { |
|
486 | - return isset( $this->models[ $model_name ] ) ? true : false; |
|
485 | + public function is_model_name($model_name) { |
|
486 | + return isset($this->models[$model_name]) ? true : false; |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | * @param bool $load_only |
499 | 499 | * @return mixed |
500 | 500 | */ |
501 | - public function load_file( $path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true ) { |
|
501 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) { |
|
502 | 502 | // retrieve instantiated class |
503 | - return $this->_load( $path_to_file, '', $file_name, $type, $arguments, false, true, $load_only ); |
|
503 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -515,9 +515,9 @@ discard block |
||
515 | 515 | * @param bool $load_only |
516 | 516 | * @return EE_Addon |
517 | 517 | */ |
518 | - public function load_addon( $path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false ) { |
|
518 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) { |
|
519 | 519 | // retrieve instantiated class |
520 | - return $this->_load( $path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only ); |
|
520 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | |
@@ -548,35 +548,35 @@ discard block |
||
548 | 548 | $load_only = false, |
549 | 549 | $addon = false |
550 | 550 | ) { |
551 | - $class_name = $this->_dependency_map->get_alias( $class_name ); |
|
552 | - if ( ! class_exists( $class_name ) ) { |
|
551 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
552 | + if ( ! class_exists($class_name)) { |
|
553 | 553 | // maybe the class is registered with a preceding \ |
554 | - $class_name = strpos( $class_name, '\\' ) !== 0 ? '\\' . $class_name : $class_name; |
|
554 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name; |
|
555 | 555 | // still doesn't exist ? |
556 | - if ( ! class_exists( $class_name ) ) { |
|
556 | + if ( ! class_exists($class_name)) { |
|
557 | 557 | return null; |
558 | 558 | } |
559 | 559 | } |
560 | 560 | // if we're only loading the class and it already exists, then let's just return true immediately |
561 | - if ( $load_only ) { |
|
561 | + if ($load_only) { |
|
562 | 562 | return true; |
563 | 563 | } |
564 | 564 | $addon = $addon ? 'addon' : ''; |
565 | 565 | // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
566 | 566 | // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
567 | 567 | // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
568 | - if ( $this->_cache_on && $cache && ! $load_only ) { |
|
568 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
569 | 569 | // return object if it's already cached |
570 | - $cached_class = $this->_get_cached_class( $class_name, $addon ); |
|
571 | - if ( $cached_class !== null ) { |
|
570 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
571 | + if ($cached_class !== null) { |
|
572 | 572 | return $cached_class; |
573 | 573 | } |
574 | 574 | } |
575 | 575 | // instantiate the requested object |
576 | - $class_obj = $this->_create_object( $class_name, $arguments, $addon, $from_db ); |
|
577 | - if ( $this->_cache_on && $cache ) { |
|
576 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
577 | + if ($this->_cache_on && $cache) { |
|
578 | 578 | // save it for later... kinda like gum { : $ |
579 | - $this->_set_cached_class( $class_obj, $class_name, $addon, $from_db ); |
|
579 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
580 | 580 | } |
581 | 581 | $this->_cache_on = true; |
582 | 582 | return $class_obj; |
@@ -611,47 +611,47 @@ discard block |
||
611 | 611 | $load_only = false |
612 | 612 | ) { |
613 | 613 | // strip php file extension |
614 | - $class_name = str_replace( '.php', '', trim( $class_name ) ); |
|
614 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
615 | 615 | // does the class have a prefix ? |
616 | - if ( ! empty( $class_prefix ) && $class_prefix != 'addon' ) { |
|
616 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
617 | 617 | // make sure $class_prefix is uppercase |
618 | - $class_prefix = strtoupper( trim( $class_prefix ) ); |
|
618 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
619 | 619 | // add class prefix ONCE!!! |
620 | - $class_name = $class_prefix . str_replace( $class_prefix, '', $class_name ); |
|
620 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
621 | 621 | } |
622 | - $class_name = $this->_dependency_map->get_alias( $class_name ); |
|
623 | - $class_exists = class_exists( $class_name ); |
|
622 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
623 | + $class_exists = class_exists($class_name); |
|
624 | 624 | // if we're only loading the class and it already exists, then let's just return true immediately |
625 | - if ( $load_only && $class_exists ) { |
|
625 | + if ($load_only && $class_exists) { |
|
626 | 626 | return true; |
627 | 627 | } |
628 | 628 | // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
629 | 629 | // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
630 | 630 | // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
631 | - if ( $this->_cache_on && $cache && ! $load_only ) { |
|
631 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
632 | 632 | // return object if it's already cached |
633 | - $cached_class = $this->_get_cached_class( $class_name, $class_prefix ); |
|
634 | - if ( $cached_class !== null ) { |
|
633 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
634 | + if ($cached_class !== null) { |
|
635 | 635 | return $cached_class; |
636 | 636 | } |
637 | 637 | } |
638 | 638 | // if the class doesn't already exist.. then we need to try and find the file and load it |
639 | - if ( ! $class_exists ) { |
|
639 | + if ( ! $class_exists) { |
|
640 | 640 | // get full path to file |
641 | - $path = $this->_resolve_path( $class_name, $type, $file_paths ); |
|
641 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
642 | 642 | // load the file |
643 | - $loaded = $this->_require_file( $path, $class_name, $type, $file_paths ); |
|
643 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
644 | 644 | // if loading failed, or we are only loading a file but NOT instantiating an object |
645 | - if ( ! $loaded || $load_only ) { |
|
645 | + if ( ! $loaded || $load_only) { |
|
646 | 646 | // return boolean if only loading, or null if an object was expected |
647 | 647 | return $load_only ? $loaded : null; |
648 | 648 | } |
649 | 649 | } |
650 | 650 | // instantiate the requested object |
651 | - $class_obj = $this->_create_object( $class_name, $arguments, $type, $from_db ); |
|
652 | - if ( $this->_cache_on && $cache ) { |
|
651 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
652 | + if ($this->_cache_on && $cache) { |
|
653 | 653 | // save it for later... kinda like gum { : $ |
654 | - $this->_set_cached_class( $class_obj, $class_name, $class_prefix, $from_db ); |
|
654 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
655 | 655 | } |
656 | 656 | $this->_cache_on = true; |
657 | 657 | return $class_obj; |
@@ -674,21 +674,21 @@ discard block |
||
674 | 674 | * @param string $class_prefix |
675 | 675 | * @return mixed |
676 | 676 | */ |
677 | - protected function _get_cached_class( $class_name, $class_prefix = '' ) { |
|
678 | - if ( isset( $this->_class_abbreviations[ $class_name ] ) ) { |
|
679 | - $class_abbreviation = $this->_class_abbreviations[ $class_name ]; |
|
677 | + protected function _get_cached_class($class_name, $class_prefix = '') { |
|
678 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
679 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
680 | 680 | } else { |
681 | 681 | // have to specify something, but not anything that will conflict |
682 | 682 | $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
683 | 683 | } |
684 | 684 | // check if class has already been loaded, and return it if it has been |
685 | - if ( isset( $this->{$class_abbreviation} ) && ! is_null( $this->{$class_abbreviation} ) ) { |
|
685 | + if (isset($this->{$class_abbreviation} ) && ! is_null($this->{$class_abbreviation} )) { |
|
686 | 686 | return $this->{$class_abbreviation}; |
687 | - } else if ( isset ( $this->{$class_name} ) ) { |
|
687 | + } else if (isset ($this->{$class_name} )) { |
|
688 | 688 | return $this->{$class_name}; |
689 | - } else if ( isset ( $this->LIB->{$class_name} ) ) { |
|
689 | + } else if (isset ($this->LIB->{$class_name} )) { |
|
690 | 690 | return $this->LIB->{$class_name}; |
691 | - } else if ( $class_prefix == 'addon' && isset ( $this->addons->{$class_name} ) ) { |
|
691 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name} )) { |
|
692 | 692 | return $this->addons->{$class_name}; |
693 | 693 | } |
694 | 694 | return null; |
@@ -709,20 +709,20 @@ discard block |
||
709 | 709 | * @param array $file_paths |
710 | 710 | * @return string | bool |
711 | 711 | */ |
712 | - protected function _resolve_path( $class_name, $type = '', $file_paths = array() ) { |
|
712 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) { |
|
713 | 713 | // make sure $file_paths is an array |
714 | - $file_paths = is_array( $file_paths ) ? $file_paths : array( $file_paths ); |
|
714 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
715 | 715 | // cycle thru paths |
716 | - foreach ( $file_paths as $key => $file_path ) { |
|
716 | + foreach ($file_paths as $key => $file_path) { |
|
717 | 717 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
718 | - $file_path = $file_path ? str_replace( array( '/', '\\' ), DS, $file_path ) : EE_CLASSES; |
|
718 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
719 | 719 | // prep file type |
720 | - $type = ! empty( $type ) ? trim( $type, '.' ) . '.' : ''; |
|
720 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
721 | 721 | // build full file path |
722 | - $file_paths[ $key ] = rtrim( $file_path, DS ) . DS . $class_name . '.' . $type . 'php'; |
|
722 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
723 | 723 | //does the file exist and can be read ? |
724 | - if ( is_readable( $file_paths[ $key ] ) ) { |
|
725 | - return $file_paths[ $key ]; |
|
724 | + if (is_readable($file_paths[$key])) { |
|
725 | + return $file_paths[$key]; |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | return false; |
@@ -744,29 +744,29 @@ discard block |
||
744 | 744 | * @return boolean |
745 | 745 | * @throws \EE_Error |
746 | 746 | */ |
747 | - protected function _require_file( $path, $class_name, $type = '', $file_paths = array() ) { |
|
747 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) { |
|
748 | 748 | // don't give up! you gotta... |
749 | 749 | try { |
750 | 750 | //does the file exist and can it be read ? |
751 | - if ( ! $path ) { |
|
751 | + if ( ! $path) { |
|
752 | 752 | // so sorry, can't find the file |
753 | - throw new EE_Error ( |
|
753 | + throw new EE_Error( |
|
754 | 754 | sprintf( |
755 | - __( 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso' ), |
|
756 | - trim( $type, '.' ), |
|
755 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
756 | + trim($type, '.'), |
|
757 | 757 | $class_name, |
758 | - '<br />' . implode( ',<br />', $file_paths ) |
|
758 | + '<br />'.implode(',<br />', $file_paths) |
|
759 | 759 | ) |
760 | 760 | ); |
761 | 761 | } |
762 | 762 | // get the file |
763 | - require_once( $path ); |
|
763 | + require_once($path); |
|
764 | 764 | // if the class isn't already declared somewhere |
765 | - if ( class_exists( $class_name, false ) === false ) { |
|
765 | + if (class_exists($class_name, false) === false) { |
|
766 | 766 | // so sorry, not a class |
767 | 767 | throw new EE_Error( |
768 | 768 | sprintf( |
769 | - __( 'The %s file %s does not appear to contain the %s Class.', 'event_espresso' ), |
|
769 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
770 | 770 | $type, |
771 | 771 | $path, |
772 | 772 | $class_name |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | ); |
775 | 775 | } |
776 | 776 | |
777 | - } catch ( EE_Error $e ) { |
|
777 | + } catch (EE_Error $e) { |
|
778 | 778 | $e->get_error(); |
779 | 779 | return false; |
780 | 780 | } |
@@ -806,61 +806,61 @@ discard block |
||
806 | 806 | * @return null | object |
807 | 807 | * @throws \EE_Error |
808 | 808 | */ |
809 | - protected function _create_object( $class_name, $arguments = array(), $type = '', $from_db = false ) { |
|
809 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) { |
|
810 | 810 | $class_obj = null; |
811 | 811 | $instantiation_mode = '0) none'; |
812 | 812 | // don't give up! you gotta... |
813 | 813 | try { |
814 | 814 | // create reflection |
815 | - $reflector = $this->get_ReflectionClass( $class_name ); |
|
815 | + $reflector = $this->get_ReflectionClass($class_name); |
|
816 | 816 | // make sure arguments are an array |
817 | - $arguments = is_array( $arguments ) ? $arguments : array( $arguments ); |
|
817 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
818 | 818 | // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
819 | 819 | // else wrap it in an additional array so that it doesn't get split into multiple parameters |
820 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed( $arguments ) |
|
820 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
821 | 821 | ? $arguments |
822 | - : array( $arguments ); |
|
822 | + : array($arguments); |
|
823 | 823 | // attempt to inject dependencies ? |
824 | - if ( $this->_dependency_map->has( $class_name ) ) { |
|
825 | - $arguments = $this->_resolve_dependencies( $reflector, $class_name, $arguments ); |
|
824 | + if ($this->_dependency_map->has($class_name)) { |
|
825 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
826 | 826 | } |
827 | 827 | // instantiate the class if possible |
828 | - if ( $reflector->isAbstract() ) { |
|
828 | + if ($reflector->isAbstract()) { |
|
829 | 829 | // nothing to instantiate, loading file was enough |
830 | 830 | // does not throw an exception so $instantiation_mode is unused |
831 | 831 | // $instantiation_mode = "1) no constructor abstract class"; |
832 | 832 | $class_obj = true; |
833 | - } else if ( $reflector->getConstructor() === null && $reflector->isInstantiable() && empty( $arguments ) ) { |
|
833 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
834 | 834 | // no constructor = static methods only... nothing to instantiate, loading file was enough |
835 | 835 | $instantiation_mode = "2) no constructor but instantiable"; |
836 | 836 | $class_obj = $reflector->newInstance(); |
837 | - } else if ( $from_db && method_exists( $class_name, 'new_instance_from_db' ) ) { |
|
837 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
838 | 838 | $instantiation_mode = "3) new_instance_from_db()"; |
839 | - $class_obj = call_user_func_array( array( $class_name, 'new_instance_from_db' ), $arguments ); |
|
840 | - } else if ( method_exists( $class_name, 'new_instance' ) ) { |
|
839 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
840 | + } else if (method_exists($class_name, 'new_instance')) { |
|
841 | 841 | $instantiation_mode = "4) new_instance()"; |
842 | - $class_obj = call_user_func_array( array( $class_name, 'new_instance' ), $arguments ); |
|
843 | - } else if ( method_exists( $class_name, 'instance' ) ) { |
|
842 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
843 | + } else if (method_exists($class_name, 'instance')) { |
|
844 | 844 | $instantiation_mode = "5) instance()"; |
845 | - $class_obj = call_user_func_array( array( $class_name, 'instance' ), $arguments ); |
|
846 | - } else if ( $reflector->isInstantiable() ) { |
|
845 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
846 | + } else if ($reflector->isInstantiable()) { |
|
847 | 847 | $instantiation_mode = "6) constructor"; |
848 | - $class_obj = $reflector->newInstanceArgs( $arguments ); |
|
848 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
849 | 849 | } else { |
850 | 850 | // heh ? something's not right ! |
851 | 851 | throw new EE_Error( |
852 | 852 | sprintf( |
853 | - __( 'The %s file %s could not be instantiated.', 'event_espresso' ), |
|
853 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
854 | 854 | $type, |
855 | 855 | $class_name |
856 | 856 | ) |
857 | 857 | ); |
858 | 858 | } |
859 | - } catch ( Exception $e ) { |
|
860 | - if ( ! $e instanceof EE_Error ) { |
|
859 | + } catch (Exception $e) { |
|
860 | + if ( ! $e instanceof EE_Error) { |
|
861 | 861 | $e = new EE_Error( |
862 | 862 | sprintf( |
863 | - __( 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso' ), |
|
863 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
864 | 864 | $class_name, |
865 | 865 | '<br />', |
866 | 866 | $e->getMessage(), |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param array $array |
881 | 881 | * @return bool |
882 | 882 | */ |
883 | - protected function _array_is_numerically_and_sequentially_indexed( array $array ) { |
|
884 | - return ! empty( $array ) ? array_keys( $array ) === range( 0, count( $array ) - 1 ) : true; |
|
883 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) { |
|
884 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | |
@@ -896,14 +896,14 @@ discard block |
||
896 | 896 | * @param string $class_name |
897 | 897 | * @return ReflectionClass |
898 | 898 | */ |
899 | - public function get_ReflectionClass( $class_name ) { |
|
899 | + public function get_ReflectionClass($class_name) { |
|
900 | 900 | if ( |
901 | - ! isset( $this->_reflectors[ $class_name ] ) |
|
902 | - || ! $this->_reflectors[ $class_name ] instanceof ReflectionClass |
|
901 | + ! isset($this->_reflectors[$class_name]) |
|
902 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
903 | 903 | ) { |
904 | - $this->_reflectors[ $class_name ] = new ReflectionClass( $class_name ); |
|
904 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
905 | 905 | } |
906 | - return $this->_reflectors[ $class_name ]; |
|
906 | + return $this->_reflectors[$class_name]; |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | |
@@ -928,50 +928,50 @@ discard block |
||
928 | 928 | * @return array |
929 | 929 | * @throws \ReflectionException |
930 | 930 | */ |
931 | - protected function _resolve_dependencies( ReflectionClass $reflector, $class_name, $arguments = array() ) { |
|
931 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) { |
|
932 | 932 | // let's examine the constructor |
933 | 933 | $constructor = $reflector->getConstructor(); |
934 | 934 | // whu? huh? nothing? |
935 | - if ( ! $constructor ) { |
|
935 | + if ( ! $constructor) { |
|
936 | 936 | return $arguments; |
937 | 937 | } |
938 | 938 | // get constructor parameters |
939 | 939 | $params = $constructor->getParameters(); |
940 | 940 | // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
941 | - $argument_keys = array_keys( $arguments ); |
|
941 | + $argument_keys = array_keys($arguments); |
|
942 | 942 | // now loop thru all of the constructors expected parameters |
943 | - foreach ( $params as $index => $param ) { |
|
943 | + foreach ($params as $index => $param) { |
|
944 | 944 | // is this a dependency for a specific class ? |
945 | 945 | $param_class = $param->getClass() ? $param->getClass()->name : null; |
946 | 946 | if ( |
947 | 947 | // param is not even a class |
948 | - empty( $param_class ) |
|
948 | + empty($param_class) |
|
949 | 949 | // and something already exists in the incoming arguments for this param |
950 | - && isset( $argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ] ) |
|
950 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
951 | 951 | ) { |
952 | 952 | // so let's skip this argument and move on to the next |
953 | 953 | continue; |
954 | 954 | } else if ( |
955 | 955 | // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
956 | - ! empty( $param_class ) |
|
957 | - && isset( $argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ] ) |
|
958 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
956 | + ! empty($param_class) |
|
957 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
958 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
959 | 959 | ) { |
960 | 960 | // skip this argument and move on to the next |
961 | 961 | continue; |
962 | 962 | } else if ( |
963 | 963 | // parameter is type hinted as a class, and should be injected |
964 | - ! empty( $param_class ) |
|
965 | - && $this->_dependency_map->has_dependency_for_class( $class_name, $param_class ) |
|
964 | + ! empty($param_class) |
|
965 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
966 | 966 | ) { |
967 | - $arguments = $this->_resolve_dependency( $class_name, $param_class, $arguments, $index ); |
|
967 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
968 | 968 | } else { |
969 | 969 | try { |
970 | - $arguments[ $index ] = $param->getDefaultValue(); |
|
971 | - } catch ( ReflectionException $e ) { |
|
970 | + $arguments[$index] = $param->getDefaultValue(); |
|
971 | + } catch (ReflectionException $e) { |
|
972 | 972 | throw new ReflectionException( |
973 | 973 | sprintf( |
974 | - __( '%1$s for parameter "$%2$s"', 'event_espresso' ), |
|
974 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
975 | 975 | $e->getMessage(), |
976 | 976 | $param->getName() |
977 | 977 | ) |
@@ -993,30 +993,30 @@ discard block |
||
993 | 993 | * @param mixed $index |
994 | 994 | * @return array |
995 | 995 | */ |
996 | - protected function _resolve_dependency( $class_name, $param_class , $arguments, $index ) { |
|
996 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) { |
|
997 | 997 | $dependency = null; |
998 | 998 | // should dependency be loaded from cache ? |
999 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( $class_name, $param_class ) |
|
999 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1000 | 1000 | !== EE_Dependency_Map::load_new_object |
1001 | 1001 | ? true |
1002 | 1002 | : false; |
1003 | 1003 | // we might have a dependency... |
1004 | 1004 | // let's MAYBE try and find it in our cache if that's what's been requested |
1005 | - $cached_class = $cache_on ? $this->_get_cached_class( $param_class ) : null; |
|
1005 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1006 | 1006 | // and grab it if it exists |
1007 | - if ( $cached_class instanceof $param_class ) { |
|
1007 | + if ($cached_class instanceof $param_class) { |
|
1008 | 1008 | $dependency = $cached_class; |
1009 | - } else if ( $param_class != $class_name ) { |
|
1009 | + } else if ($param_class != $class_name) { |
|
1010 | 1010 | // obtain the loader method from the dependency map |
1011 | - $loader = $this->_dependency_map->class_loader( $param_class ); |
|
1011 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1012 | 1012 | // is loader a custom closure ? |
1013 | - if ( $loader instanceof Closure ) { |
|
1013 | + if ($loader instanceof Closure) { |
|
1014 | 1014 | $dependency = $loader(); |
1015 | 1015 | } else { |
1016 | 1016 | // set the cache on property for the recursive loading call |
1017 | 1017 | $this->_cache_on = $cache_on; |
1018 | 1018 | // if not, then let's try and load it via the registry |
1019 | - if ( method_exists( $this, $loader ) ) { |
|
1019 | + if (method_exists($this, $loader)) { |
|
1020 | 1020 | $dependency = $this->{$loader}($param_class); |
1021 | 1021 | } else { |
1022 | 1022 | $dependency = $this->create($param_class, array(), $cache_on); |
@@ -1024,12 +1024,12 @@ discard block |
||
1024 | 1024 | } |
1025 | 1025 | } |
1026 | 1026 | // did we successfully find the correct dependency ? |
1027 | - if ( $dependency instanceof $param_class ) { |
|
1027 | + if ($dependency instanceof $param_class) { |
|
1028 | 1028 | // then let's inject it into the incoming array of arguments at the correct location |
1029 | - if ( isset( $argument_keys[ $index ] ) ) { |
|
1030 | - $arguments[ $argument_keys[ $index ] ] = $dependency; |
|
1029 | + if (isset($argument_keys[$index])) { |
|
1030 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1031 | 1031 | } else { |
1032 | - $arguments[ $index ] = $dependency; |
|
1032 | + $arguments[$index] = $dependency; |
|
1033 | 1033 | } |
1034 | 1034 | } |
1035 | 1035 | return $arguments; |
@@ -1054,19 +1054,19 @@ discard block |
||
1054 | 1054 | * @param bool $from_db |
1055 | 1055 | * @return void |
1056 | 1056 | */ |
1057 | - protected function _set_cached_class( $class_obj, $class_name, $class_prefix = '', $from_db = false ) { |
|
1058 | - if ( empty( $class_obj ) ) { |
|
1057 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) { |
|
1058 | + if (empty($class_obj)) { |
|
1059 | 1059 | return; |
1060 | 1060 | } |
1061 | 1061 | // return newly instantiated class |
1062 | - if ( isset( $this->_class_abbreviations[ $class_name ] ) ) { |
|
1063 | - $class_abbreviation = $this->_class_abbreviations[ $class_name ]; |
|
1062 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1063 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1064 | 1064 | $this->{$class_abbreviation} = $class_obj; |
1065 | - } else if ( property_exists( $this, $class_name ) ) { |
|
1065 | + } else if (property_exists($this, $class_name)) { |
|
1066 | 1066 | $this->{$class_name} = $class_obj; |
1067 | - } else if ( $class_prefix == 'addon' ) { |
|
1067 | + } else if ($class_prefix == 'addon') { |
|
1068 | 1068 | $this->addons->{$class_name} = $class_obj; |
1069 | - } else if ( ! $from_db ) { |
|
1069 | + } else if ( ! $from_db) { |
|
1070 | 1070 | $this->LIB->{$class_name} = $class_obj; |
1071 | 1071 | } |
1072 | 1072 | } |
@@ -1083,12 +1083,12 @@ discard block |
||
1083 | 1083 | * @param array $arguments |
1084 | 1084 | * @return object |
1085 | 1085 | */ |
1086 | - public static function factory( $classname, $arguments = array() ) { |
|
1087 | - $loader = self::instance()->_dependency_map->class_loader( $classname ); |
|
1088 | - if ( $loader instanceof Closure ) { |
|
1089 | - return $loader( $arguments ); |
|
1090 | - } else if ( method_exists( EE_Registry::instance(), $loader ) ) { |
|
1091 | - return EE_Registry::instance()->{$loader}( $classname, $arguments ); |
|
1086 | + public static function factory($classname, $arguments = array()) { |
|
1087 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1088 | + if ($loader instanceof Closure) { |
|
1089 | + return $loader($arguments); |
|
1090 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1091 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1092 | 1092 | } |
1093 | 1093 | return null; |
1094 | 1094 | } |
@@ -1101,9 +1101,9 @@ discard block |
||
1101 | 1101 | * @param string $name |
1102 | 1102 | * @return EE_Addon |
1103 | 1103 | */ |
1104 | - public function get_addon_by_name( $name ) { |
|
1105 | - foreach ( $this->addons as $addon ) { |
|
1106 | - if ( $addon->name() == $name ) { |
|
1104 | + public function get_addon_by_name($name) { |
|
1105 | + foreach ($this->addons as $addon) { |
|
1106 | + if ($addon->name() == $name) { |
|
1107 | 1107 | return $addon; |
1108 | 1108 | } |
1109 | 1109 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
1119 | 1119 | */ |
1120 | 1120 | public function get_addons_by_name() { |
1121 | 1121 | $addons = array(); |
1122 | - foreach ( $this->addons as $addon ) { |
|
1123 | - $addons[ $addon->name() ] = $addon; |
|
1122 | + foreach ($this->addons as $addon) { |
|
1123 | + $addons[$addon->name()] = $addon; |
|
1124 | 1124 | } |
1125 | 1125 | return $addons; |
1126 | 1126 | } |
@@ -1135,16 +1135,16 @@ discard block |
||
1135 | 1135 | * @return \EEM_Base |
1136 | 1136 | * @throws \EE_Error |
1137 | 1137 | */ |
1138 | - public function reset_model( $model_name ) { |
|
1139 | - $model_class_name = strpos( $model_name, 'EEM_' ) !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1140 | - if( ! isset( $this->LIB->{$model_class_name} ) || ! $this->LIB->{$model_class_name} instanceof EEM_Base ) { |
|
1138 | + public function reset_model($model_name) { |
|
1139 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1140 | + if ( ! isset($this->LIB->{$model_class_name} ) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1141 | 1141 | return null; |
1142 | 1142 | } |
1143 | 1143 | //get that model reset it and make sure we nuke the old reference to it |
1144 | - if ( $this->LIB->{$model_class_name} instanceof $model_class_name && is_callable( array( $model_class_name, 'reset' ))) { |
|
1144 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1145 | 1145 | $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
1146 | 1146 | } else { |
1147 | - throw new EE_Error( sprintf( __( 'Model %s does not have a method "reset"', 'event_espresso' ), $model_name ) ); |
|
1147 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1148 | 1148 | } |
1149 | 1149 | return $this->LIB->{$model_class_name}; |
1150 | 1150 | } |
@@ -1181,13 +1181,13 @@ discard block |
||
1181 | 1181 | * |
1182 | 1182 | * @return EE_Registry |
1183 | 1183 | */ |
1184 | - public static function reset( $hard = false, $reinstantiate = true, $reset_models = true ) { |
|
1184 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) { |
|
1185 | 1185 | $instance = self::instance(); |
1186 | 1186 | EEH_Activation::reset(); |
1187 | 1187 | |
1188 | 1188 | //properties that get reset |
1189 | 1189 | $instance->_cache_on = true; |
1190 | - $instance->CFG = EE_Config::reset( $hard, $reinstantiate ); |
|
1190 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1191 | 1191 | $instance->CART = null; |
1192 | 1192 | $instance->MRM = null; |
1193 | 1193 | $instance->LIB = new stdClass(); |
@@ -1195,9 +1195,9 @@ discard block |
||
1195 | 1195 | //messages reset |
1196 | 1196 | EED_Messages::reset(); |
1197 | 1197 | |
1198 | - if ( $reset_models ) { |
|
1199 | - foreach ( array_keys( $instance->non_abstract_db_models ) as $model_name ) { |
|
1200 | - $instance->reset_model( $model_name ); |
|
1198 | + if ($reset_models) { |
|
1199 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1200 | + $instance->reset_model($model_name); |
|
1201 | 1201 | } |
1202 | 1202 | } |
1203 | 1203 | |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | * @param $a |
1220 | 1220 | * @param $b |
1221 | 1221 | */ |
1222 | - final function __call( $a, $b ) { |
|
1222 | + final function __call($a, $b) { |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | |
@@ -1227,7 +1227,7 @@ discard block |
||
1227 | 1227 | /** |
1228 | 1228 | * @param $a |
1229 | 1229 | */ |
1230 | - final function __get( $a ) { |
|
1230 | + final function __get($a) { |
|
1231 | 1231 | } |
1232 | 1232 | |
1233 | 1233 | |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | * @param $a |
1237 | 1237 | * @param $b |
1238 | 1238 | */ |
1239 | - final function __set( $a, $b ) { |
|
1239 | + final function __set($a, $b) { |
|
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | /** |
1245 | 1245 | * @param $a |
1246 | 1246 | */ |
1247 | - final function __isset( $a ) { |
|
1247 | + final function __isset($a) { |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | /** |
1253 | 1253 | * @param $a |
1254 | 1254 | */ |
1255 | - final function __unset( $a ) { |
|
1255 | + final function __unset($a) { |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | |
@@ -1299,7 +1299,7 @@ discard block |
||
1299 | 1299 | * @param $a |
1300 | 1300 | * @param $b |
1301 | 1301 | */ |
1302 | - final static function __callStatic( $a, $b ) { |
|
1302 | + final static function __callStatic($a, $b) { |
|
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | /** |
@@ -1308,9 +1308,9 @@ discard block |
||
1308 | 1308 | */ |
1309 | 1309 | public function cpt_models() { |
1310 | 1310 | $cpt_models = array(); |
1311 | - foreach( $this->non_abstract_db_models as $short_name => $classname ) { |
|
1312 | - if( is_subclass_of( $classname, 'EEM_CPT_Base' ) ) { |
|
1313 | - $cpt_models[ $short_name ] = $classname; |
|
1311 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1312 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1313 | + $cpt_models[$short_name] = $classname; |
|
1314 | 1314 | } |
1315 | 1315 | } |
1316 | 1316 | return $cpt_models; |
@@ -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_CPT_Base.model.php'); |
|
2 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * EEM_Event Model |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @author Michael Nelson, Brent Christensen |
12 | 12 | * |
13 | 13 | */ |
14 | -class EEM_Event extends EEM_CPT_Base{ |
|
14 | +class EEM_Event extends EEM_CPT_Base { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the event |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | * @param string $timezone |
52 | 52 | * @return EEM_Event |
53 | 53 | */ |
54 | - public static function instance( $timezone = NULL ){ |
|
54 | + public static function instance($timezone = NULL) { |
|
55 | 55 | |
56 | 56 | // check if instance of EEM_Event already exists |
57 | - if ( ! self::$_instance instanceof EEM_Event ) { |
|
57 | + if ( ! self::$_instance instanceof EEM_Event) { |
|
58 | 58 | // instantiate Espresso_model |
59 | - self::$_instance = new self( $timezone ); |
|
59 | + self::$_instance = new self($timezone); |
|
60 | 60 | } |
61 | 61 | //we might have a timezone set, let set_timezone decide what to do with it |
62 | - self::$_instance->set_timezone( $timezone ); |
|
62 | + self::$_instance->set_timezone($timezone); |
|
63 | 63 | // EEM_Event object |
64 | 64 | return self::$_instance; |
65 | 65 | } |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | * @param string $timezone |
71 | 71 | * @return EEM_Event |
72 | 72 | */ |
73 | - protected function __construct($timezone = null){ |
|
73 | + protected function __construct($timezone = null) { |
|
74 | 74 | |
75 | - EE_Registry::instance()->load_model( 'Registration' ); |
|
75 | + EE_Registry::instance()->load_model('Registration'); |
|
76 | 76 | |
77 | - $this->singular_item = __('Event','event_espresso'); |
|
78 | - $this->plural_item = __('Events','event_espresso'); |
|
77 | + $this->singular_item = __('Event', 'event_espresso'); |
|
78 | + $this->plural_item = __('Events', 'event_espresso'); |
|
79 | 79 | |
80 | 80 | // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
81 | 81 | // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
@@ -89,57 +89,57 @@ discard block |
||
89 | 89 | array( |
90 | 90 | EEM_Event::cancelled => array( |
91 | 91 | 'label' => __('Cancelled', 'event_espresso'), |
92 | - 'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', TRUE ) |
|
92 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', TRUE) |
|
93 | 93 | ), |
94 | 94 | EEM_Event::postponed => array( |
95 | 95 | 'label' => __('Postponed', 'event_espresso'), |
96 | - 'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', TRUE ) |
|
96 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', TRUE) |
|
97 | 97 | ), |
98 | 98 | EEM_Event::sold_out => array( |
99 | 99 | 'label' => __('Sold Out', 'event_espresso'), |
100 | - 'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', TRUE ) |
|
100 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', TRUE) |
|
101 | 101 | ) |
102 | 102 | ) |
103 | 103 | ); |
104 | 104 | |
105 | - self::$_default_reg_status = empty( self::$_default_reg_status ) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status; |
|
105 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status; |
|
106 | 106 | |
107 | 107 | $this->_tables = array( |
108 | - 'Event_CPT'=>new EE_Primary_Table( 'posts','ID' ), |
|
109 | - 'Event_Meta'=> new EE_Secondary_Table( 'esp_event_meta', 'EVTM_ID', 'EVT_ID' ) |
|
108 | + 'Event_CPT'=>new EE_Primary_Table('posts', 'ID'), |
|
109 | + 'Event_Meta'=> new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID') |
|
110 | 110 | ); |
111 | 111 | |
112 | 112 | $this->_fields = array( |
113 | 113 | 'Event_CPT'=>array( |
114 | - 'EVT_ID'=>new EE_Primary_Key_Int_Field( 'ID', __( 'Post ID for Event','event_espresso' )), |
|
115 | - 'EVT_name'=>new EE_Plain_Text_Field( 'post_title', __( 'Event Name','event_espresso' ), FALSE, '' ), |
|
116 | - 'EVT_desc'=>new EE_Post_Content_Field( 'post_content', __( 'Event Description', 'event_espresso' ), FALSE, '' ), |
|
117 | - 'EVT_slug'=>new EE_Slug_Field( 'post_name', __( 'Event Slug', 'event_espresso' ), FALSE, '' ), |
|
118 | - 'EVT_created'=>new EE_Datetime_Field( 'post_date', __( 'Date/Time Event Created', 'event_espresso' ), FALSE, EE_Datetime_Field::now ), |
|
119 | - 'EVT_short_desc'=>new EE_Simple_HTML_Field( 'post_excerpt', __( 'Event Short Description', 'event_espresso' ), FALSE,'' ), |
|
120 | - 'EVT_modified'=>new EE_Datetime_Field( 'post_modified', __( 'Date/Time Event Modified', 'event_espresso' ), FALSE, EE_Datetime_Field::now ), |
|
121 | - 'EVT_wp_user'=>new EE_WP_User_Field( 'post_author', __( 'Event Creator ID', 'event_espresso'), FALSE), |
|
122 | - 'parent'=>new EE_Integer_Field( 'post_parent', __( 'Event Parent ID', 'event_espresso' ), FALSE, 0 ), |
|
123 | - 'EVT_order'=>new EE_Integer_Field( 'menu_order', __( 'Event Menu Order', 'event_espresso' ), FALSE, 1 ), |
|
124 | - 'post_type'=>new EE_WP_Post_Type_Field('espresso_events'),// EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
125 | - 'status' => new EE_WP_Post_Status_Field( 'post_status', __( 'Event Status', 'event_espresso' ), FALSE, 'draft', $this->_custom_stati ) |
|
114 | + 'EVT_ID'=>new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')), |
|
115 | + 'EVT_name'=>new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), FALSE, ''), |
|
116 | + 'EVT_desc'=>new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'), FALSE, ''), |
|
117 | + 'EVT_slug'=>new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), FALSE, ''), |
|
118 | + 'EVT_created'=>new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'), FALSE, EE_Datetime_Field::now), |
|
119 | + 'EVT_short_desc'=>new EE_Simple_HTML_Field('post_excerpt', __('Event Short Description', 'event_espresso'), FALSE, ''), |
|
120 | + 'EVT_modified'=>new EE_Datetime_Field('post_modified', __('Date/Time Event Modified', 'event_espresso'), FALSE, EE_Datetime_Field::now), |
|
121 | + 'EVT_wp_user'=>new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'), FALSE), |
|
122 | + 'parent'=>new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), FALSE, 0), |
|
123 | + 'EVT_order'=>new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), FALSE, 1), |
|
124 | + 'post_type'=>new EE_WP_Post_Type_Field('espresso_events'), // EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
125 | + 'status' => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'), FALSE, 'draft', $this->_custom_stati) |
|
126 | 126 | ), |
127 | 127 | 'Event_Meta'=>array( |
128 | - 'EVTM_ID'=> new EE_DB_Only_Float_Field( 'EVTM_ID', __( 'Event Meta Row ID','event_espresso' ), FALSE ), |
|
129 | - 'EVT_ID_fk'=>new EE_DB_Only_Int_Field( 'EVT_ID', __( 'Foreign key to Event ID from Event Meta table', 'event_espresso' ), FALSE ), |
|
130 | - 'EVT_display_desc'=>new EE_Boolean_Field( 'EVT_display_desc', __( 'Display Description Flag', 'event_espresso' ), FALSE, 1 ), |
|
131 | - 'EVT_display_ticket_selector'=>new EE_Boolean_Field( 'EVT_display_ticket_selector', __( 'Display Ticket Selector Flag', 'event_espresso' ), FALSE, 1 ), |
|
132 | - 'EVT_visible_on'=>new EE_Datetime_Field( 'EVT_visible_on', __( 'Event Visible Date', 'event_espresso' ), TRUE, EE_Datetime_Field::now ), |
|
133 | - 'EVT_additional_limit'=>new EE_Integer_Field( 'EVT_additional_limit', __( 'Limit of Additional Registrations on Same Transaction', 'event_espresso' ), TRUE, 10 ), |
|
128 | + 'EVTM_ID'=> new EE_DB_Only_Float_Field('EVTM_ID', __('Event Meta Row ID', 'event_espresso'), FALSE), |
|
129 | + 'EVT_ID_fk'=>new EE_DB_Only_Int_Field('EVT_ID', __('Foreign key to Event ID from Event Meta table', 'event_espresso'), FALSE), |
|
130 | + 'EVT_display_desc'=>new EE_Boolean_Field('EVT_display_desc', __('Display Description Flag', 'event_espresso'), FALSE, 1), |
|
131 | + 'EVT_display_ticket_selector'=>new EE_Boolean_Field('EVT_display_ticket_selector', __('Display Ticket Selector Flag', 'event_espresso'), FALSE, 1), |
|
132 | + 'EVT_visible_on'=>new EE_Datetime_Field('EVT_visible_on', __('Event Visible Date', 'event_espresso'), TRUE, EE_Datetime_Field::now), |
|
133 | + 'EVT_additional_limit'=>new EE_Integer_Field('EVT_additional_limit', __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), TRUE, 10), |
|
134 | 134 | 'EVT_default_registration_status'=>new EE_Enum_Text_Field( |
135 | - 'EVT_default_registration_status', __( 'Default Registration Status on this Event', 'event_espresso' ), FALSE, EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
135 | + 'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), FALSE, EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
136 | 136 | ), |
137 | - 'EVT_member_only'=>new EE_Boolean_Field( 'EVT_member_only', __( 'Member-Only Event Flag', 'event_espresso' ), FALSE, FALSE ), |
|
138 | - 'EVT_phone'=> new EE_Plain_Text_Field('EVT_phone', __( 'Event Phone Number', 'event_espresso' ), FALSE ), |
|
139 | - 'EVT_allow_overflow'=>new EE_Boolean_Field( 'EVT_allow_overflow', __( 'Allow Overflow on Event', 'event_espresso' ), FALSE, FALSE ), |
|
140 | - 'EVT_timezone_string'=>new EE_Plain_Text_Field( 'EVT_timezone_string', __( 'Timezone (name) for Event times', 'event_espresso' ), FALSE ), |
|
141 | - 'EVT_external_URL'=>new EE_Plain_Text_Field( 'EVT_external_URL', __( 'URL of Event Page if hosted elsewhere', 'event_espresso' ), TRUE ), |
|
142 | - 'EVT_donations'=>new EE_Boolean_Field( 'EVT_donations', __( 'Accept Donations?', 'event_espresso' ), FALSE, FALSE ) |
|
137 | + 'EVT_member_only'=>new EE_Boolean_Field('EVT_member_only', __('Member-Only Event Flag', 'event_espresso'), FALSE, FALSE), |
|
138 | + 'EVT_phone'=> new EE_Plain_Text_Field('EVT_phone', __('Event Phone Number', 'event_espresso'), FALSE), |
|
139 | + 'EVT_allow_overflow'=>new EE_Boolean_Field('EVT_allow_overflow', __('Allow Overflow on Event', 'event_espresso'), FALSE, FALSE), |
|
140 | + 'EVT_timezone_string'=>new EE_Plain_Text_Field('EVT_timezone_string', __('Timezone (name) for Event times', 'event_espresso'), FALSE), |
|
141 | + 'EVT_external_URL'=>new EE_Plain_Text_Field('EVT_external_URL', __('URL of Event Page if hosted elsewhere', 'event_espresso'), TRUE), |
|
142 | + 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __('Accept Donations?', 'event_espresso'), FALSE, FALSE) |
|
143 | 143 | |
144 | 144 | )); |
145 | 145 | |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | 'WP_User' => new EE_Belongs_To_Relation(), |
155 | 155 | ); |
156 | 156 | //this model is generally available for reading |
157 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
158 | - parent::__construct( $timezone ); |
|
157 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
158 | + parent::__construct($timezone); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | /** |
164 | 164 | * @param string $default_reg_status |
165 | 165 | */ |
166 | - public static function set_default_reg_status( $default_reg_status ) { |
|
166 | + public static function set_default_reg_status($default_reg_status) { |
|
167 | 167 | self::$_default_reg_status = $default_reg_status; |
168 | 168 | //if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default. |
169 | - if ( self::$_instance instanceof EEM_Event ) { |
|
169 | + if (self::$_instance instanceof EEM_Event) { |
|
170 | 170 | self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field( |
171 | - 'EVT_default_registration_status', __( 'Default Registration Status on this Event', 'event_espresso' ), false, $default_reg_status, EEM_Registration::reg_status_array() |
|
171 | + 'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), false, $default_reg_status, EEM_Registration::reg_status_array() |
|
172 | 172 | ); |
173 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize( 'Event_Meta', 'EVT_default_registration_status', 'EEM_Event' ); |
|
173 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta', 'EVT_default_registration_status', 'EEM_Event'); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | * @return array |
184 | 184 | */ |
185 | 185 | public function get_all_question_groups() { |
186 | - return EE_Registry::instance()->load_model( 'Question_Group' )->get_all( array( |
|
187 | - array( 'QSG_deleted' => FALSE ), |
|
188 | - 'order_by' => array( 'QSG_order' => 'ASC' ) |
|
186 | + return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
187 | + array('QSG_deleted' => FALSE), |
|
188 | + 'order_by' => array('QSG_order' => 'ASC') |
|
189 | 189 | )); |
190 | 190 | } |
191 | 191 | |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | * @param int $EVT_ID |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function get_all_event_question_groups( $EVT_ID = 0 ) { |
|
205 | - if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) { |
|
206 | - EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
204 | + public function get_all_event_question_groups($EVT_ID = 0) { |
|
205 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
206 | + EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
207 | 207 | return FALSE; |
208 | 208 | } |
209 | - return EE_Registry::instance()->load_model( 'Event_Question_Group' )->get_all( array( |
|
210 | - array( 'EVT_ID' => $EVT_ID ) |
|
209 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
210 | + array('EVT_ID' => $EVT_ID) |
|
211 | 211 | )); |
212 | 212 | } |
213 | 213 | |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | * @param boolean $for_primary_attendee |
224 | 224 | * @return array |
225 | 225 | */ |
226 | - public function get_event_question_groups( $EVT_ID = 0, $for_primary_attendee = TRUE ) { |
|
227 | - if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) { |
|
228 | - EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
226 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = TRUE) { |
|
227 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
228 | + EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
229 | 229 | return FALSE; |
230 | 230 | } |
231 | - return EE_Registry::instance()->load_model( 'Event_Question_Group' )->get_all( array( |
|
232 | - array( 'EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee ) |
|
231 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array( |
|
232 | + array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee) |
|
233 | 233 | )); |
234 | 234 | } |
235 | 235 | |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | * @param EE_Registration $registration |
247 | 247 | * @return array |
248 | 248 | */ |
249 | - public function get_question_groups_for_event( $EVT_ID = 0, EE_Registration $registration ) { |
|
249 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) { |
|
250 | 250 | |
251 | - if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) { |
|
252 | - EE_Error::add_error( __( 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
251 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
252 | + EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
253 | 253 | return FALSE; |
254 | 254 | } |
255 | 255 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | 'QSG_deleted' => FALSE |
260 | 260 | ); |
261 | 261 | |
262 | - return EE_Registry::instance()->load_model( 'Question_Group' )->get_all( array( |
|
262 | + return EE_Registry::instance()->load_model('Question_Group')->get_all(array( |
|
263 | 263 | $where_params, |
264 | 264 | 'order_by' => array('QSG_order' => 'ASC') |
265 | 265 | )); |
@@ -279,16 +279,16 @@ discard block |
||
279 | 279 | * @param string $QSG_IDs csv list of $QSG IDs |
280 | 280 | * @return array |
281 | 281 | */ |
282 | - public function get_questions_in_groups( $QSG_IDs = '' ) { |
|
282 | + public function get_questions_in_groups($QSG_IDs = '') { |
|
283 | 283 | |
284 | - if ( empty( $QSG_IDs )) { |
|
285 | - EE_Error::add_error( __( 'An error occurred. No Question Group IDs were received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
284 | + if (empty($QSG_IDs)) { |
|
285 | + EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
286 | 286 | return FALSE; |
287 | 287 | } |
288 | 288 | |
289 | - return EE_Registry::instance()->load_model( 'Question' )->get_all( array( |
|
289 | + return EE_Registry::instance()->load_model('Question')->get_all(array( |
|
290 | 290 | array( |
291 | - 'Question_Group.QSG_ID' => array( 'IN', $QSG_IDs ), |
|
291 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
292 | 292 | 'QST_deleted' => FALSE, |
293 | 293 | 'QST_admin_only' => is_admin() |
294 | 294 | ), |
@@ -310,16 +310,16 @@ discard block |
||
310 | 310 | * @param string $QST_IDs csv list of $QST IDs |
311 | 311 | * @return array |
312 | 312 | */ |
313 | - public function get_options_for_question( $QST_IDs ) { |
|
313 | + public function get_options_for_question($QST_IDs) { |
|
314 | 314 | |
315 | - if ( empty( $QST_IDs )) { |
|
316 | - EE_Error::add_error( __( 'An error occurred. No Question IDs were received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
315 | + if (empty($QST_IDs)) { |
|
316 | + EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
317 | 317 | return FALSE; |
318 | 318 | } |
319 | 319 | |
320 | - return EE_Registry::instance()->load_model( 'Question_Option' )->get_all( array( |
|
320 | + return EE_Registry::instance()->load_model('Question_Option')->get_all(array( |
|
321 | 321 | array( |
322 | - 'Question.QST_ID' => array( 'IN', $QST_IDs ), |
|
322 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
323 | 323 | 'QSO_deleted' => FALSE |
324 | 324 | ), |
325 | 325 | 'order_by' => 'QSO_ID' |
@@ -339,46 +339,46 @@ discard block |
||
339 | 339 | * @throws EE_Error |
340 | 340 | * @return array |
341 | 341 | */ |
342 | - public function assemble_array_of_groups_questions_and_options( EE_Registration $registration, $EVT_ID = 0 ) { |
|
342 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) { |
|
343 | 343 | |
344 | - if ( empty( $EVT_ID ) ) { |
|
345 | - throw new EE_Error( __( 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', 'event_espresso' ) ); |
|
344 | + if (empty($EVT_ID)) { |
|
345 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', 'event_espresso')); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | $questions = array(); |
349 | 349 | |
350 | 350 | // get all question groups for event |
351 | - $qgs = $this->get_question_groups_for_event( $EVT_ID, $registration ); |
|
352 | - if ( !empty( $qgs ) ) { |
|
353 | - foreach ( $qgs as $qg ) { |
|
351 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
352 | + if ( ! empty($qgs)) { |
|
353 | + foreach ($qgs as $qg) { |
|
354 | 354 | $qsts = $qg->questions(); |
355 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
356 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
357 | - foreach ( $qsts as $qst ) { |
|
358 | - if ( $qst->is_system_question() ) |
|
355 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
356 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
357 | + foreach ($qsts as $qst) { |
|
358 | + if ($qst->is_system_question()) |
|
359 | 359 | continue; |
360 | - $answer = EEM_Answer::instance()->get_one( array( array( 'QST_ID' => $qst->ID(), 'REG_ID' => $registration->ID() ) ) ); |
|
360 | + $answer = EEM_Answer::instance()->get_one(array(array('QST_ID' => $qst->ID(), 'REG_ID' => $registration->ID()))); |
|
361 | 361 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
362 | 362 | $qst_name = $qstn_id = $qst->ID(); |
363 | 363 | $ans_id = $answer->ID(); |
364 | - $qst_name = !empty( $ans_id ) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
364 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
365 | 365 | $input_name = ''; |
366 | - $input_id = sanitize_key( $qst->display_text() ); |
|
366 | + $input_id = sanitize_key($qst->display_text()); |
|
367 | 367 | $input_class = ''; |
368 | 368 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
369 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' . $input_name . $qst_name; |
|
370 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
371 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
372 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
373 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
374 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
369 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'.$input_name.$qst_name; |
|
370 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
371 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
372 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
373 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
374 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
375 | 375 | //leave responses as-is, don't convert stuff into html entities please! |
376 | - $questions[ $qg->ID() ][ 'QSG_questions'][ $qst->ID() ][ 'htmlentities' ] = false; |
|
377 | - if ( $qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN' ) { |
|
378 | - $QSOs = $qst->options(TRUE,$answer->value()); |
|
379 | - if ( is_array( $QSOs ) ) { |
|
380 | - foreach ( $QSOs as $QSO_ID => $QSO ) { |
|
381 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
376 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
377 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
378 | + $QSOs = $qst->options(TRUE, $answer->value()); |
|
379 | + if (is_array($QSOs)) { |
|
380 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
381 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
@@ -402,9 +402,9 @@ discard block |
||
402 | 402 | * @param $QST |
403 | 403 | * @return string string |
404 | 404 | */ |
405 | - private function _generate_question_input_name( $QST ) { |
|
405 | + private function _generate_question_input_name($QST) { |
|
406 | 406 | |
407 | - if ( $QST->QST_system ) { |
|
407 | + if ($QST->QST_system) { |
|
408 | 408 | $qst_name = $QST->QST_system; |
409 | 409 | /* switch( $QST->QST_system ) { |
410 | 410 | |
@@ -471,36 +471,36 @@ discard block |
||
471 | 471 | * @param bool $count whether to return the count or not (default FALSE) |
472 | 472 | * @return array EE_Event objects |
473 | 473 | */ |
474 | - public function get_active_events( $query_params, $count = FALSE ) { |
|
475 | - if ( array_key_exists( 0, $query_params ) ) { |
|
474 | + public function get_active_events($query_params, $count = FALSE) { |
|
475 | + if (array_key_exists(0, $query_params)) { |
|
476 | 476 | $where_params = $query_params[0]; |
477 | - unset( $query_params[0] ); |
|
477 | + unset($query_params[0]); |
|
478 | 478 | } else { |
479 | 479 | $where_params = array(); |
480 | 480 | } |
481 | 481 | |
482 | 482 | //if we have count make sure we don't include group by |
483 | - if ( $count && isset( $query_params['group_by'] ) ) { |
|
484 | - unset( $query_params['group_by'] ); |
|
483 | + if ($count && isset($query_params['group_by'])) { |
|
484 | + unset($query_params['group_by']); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
488 | 488 | $where_params['status'] = 'publish'; |
489 | 489 | //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
490 | - if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) { |
|
491 | - $where_params['Datetime.DTT_EVT_start******'] = array('<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
490 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
491 | + $where_params['Datetime.DTT_EVT_start******'] = array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
492 | 492 | } else { |
493 | - $where_params['Datetime.DTT_EVT_start'] = array('<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
493 | + $where_params['Datetime.DTT_EVT_start'] = array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
494 | 494 | } |
495 | 495 | |
496 | - if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) { |
|
497 | - $where_params['Datetime.DTT_EVT_end*****'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
496 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
497 | + $where_params['Datetime.DTT_EVT_end*****'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
498 | 498 | } else { |
499 | - $where_params['Datetime.DTT_EVT_end'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
499 | + $where_params['Datetime.DTT_EVT_end'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
500 | 500 | } |
501 | 501 | $query_params[0] = $where_params; |
502 | 502 | // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
503 | - return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params ); |
|
503 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -515,30 +515,30 @@ discard block |
||
515 | 515 | * @param bool $count whether to return the count or not (default FALSE) |
516 | 516 | * @return array EE_Event objects |
517 | 517 | */ |
518 | - public function get_upcoming_events( $query_params, $count = FALSE ) { |
|
519 | - if ( array_key_exists( 0, $query_params ) ) { |
|
518 | + public function get_upcoming_events($query_params, $count = FALSE) { |
|
519 | + if (array_key_exists(0, $query_params)) { |
|
520 | 520 | $where_params = $query_params[0]; |
521 | - unset( $query_params[0] ); |
|
521 | + unset($query_params[0]); |
|
522 | 522 | } else { |
523 | 523 | $where_params = array(); |
524 | 524 | } |
525 | 525 | |
526 | 526 | //if we have count make sure we don't include group by |
527 | - if ( $count && isset( $query_params['group_by'] ) ) { |
|
528 | - unset( $query_params['group_by'] ); |
|
527 | + if ($count && isset($query_params['group_by'])) { |
|
528 | + unset($query_params['group_by']); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
532 | 532 | $where_params['status'] = 'publish'; |
533 | 533 | //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
534 | - if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) { |
|
535 | - $where_params['Datetime.DTT_EVT_start*****'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
534 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
535 | + $where_params['Datetime.DTT_EVT_start*****'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
536 | 536 | } else { |
537 | - $where_params['Datetime.DTT_EVT_start'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
537 | + $where_params['Datetime.DTT_EVT_start'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
538 | 538 | } |
539 | 539 | $query_params[0] = $where_params; |
540 | 540 | // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
541 | - return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params ); |
|
541 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | |
@@ -550,54 +550,54 @@ discard block |
||
550 | 550 | * @param bool $count whether to return the count or not (default FALSE) |
551 | 551 | * @return array EE_Event objects |
552 | 552 | */ |
553 | - public function get_expired_events( $query_params, $count = FALSE ) { |
|
553 | + public function get_expired_events($query_params, $count = FALSE) { |
|
554 | 554 | |
555 | - $where_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
555 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
556 | 556 | |
557 | 557 | //if we have count make sure we don't include group by |
558 | - if ( $count && isset( $query_params['group_by'] ) ) { |
|
559 | - unset( $query_params['group_by'] ); |
|
558 | + if ($count && isset($query_params['group_by'])) { |
|
559 | + unset($query_params['group_by']); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries. |
563 | - if ( isset( $where_params['status'] ) ) { |
|
564 | - unset( $where_params['status'] ); |
|
563 | + if (isset($where_params['status'])) { |
|
564 | + unset($where_params['status']); |
|
565 | 565 | } |
566 | 566 | $exclude_query = $query_params; |
567 | - if ( isset( $exclude_query[0] ) ) { |
|
568 | - unset( $exclude_query[0] ); |
|
567 | + if (isset($exclude_query[0])) { |
|
568 | + unset($exclude_query[0]); |
|
569 | 569 | } |
570 | - $exclude_query[0] = array( 'Datetime.DTT_EVT_end' => array( '>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ) ); |
|
570 | + $exclude_query[0] = array('Datetime.DTT_EVT_end' => array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'))); |
|
571 | 571 | //first get all events that have datetimes where its not expired. |
572 | - $event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' ); |
|
573 | - $event_ids = array_keys( $event_ids ); |
|
572 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
573 | + $event_ids = array_keys($event_ids); |
|
574 | 574 | |
575 | 575 | //if we have any additional query_params, let's add them to the 'AND' condition |
576 | 576 | $and_condition = array( |
577 | - 'Datetime.DTT_EVT_end' => array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ), |
|
578 | - 'EVT_ID' => array( 'NOT IN', $event_ids ) |
|
577 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
578 | + 'EVT_ID' => array('NOT IN', $event_ids) |
|
579 | 579 | ); |
580 | 580 | |
581 | - if ( isset( $where_params['OR'] ) ) { |
|
581 | + if (isset($where_params['OR'])) { |
|
582 | 582 | $and_condition['OR'] = $where_params['OR']; |
583 | - unset( $where_params['OR'] ); |
|
583 | + unset($where_params['OR']); |
|
584 | 584 | } |
585 | 585 | |
586 | - if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) { |
|
586 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
587 | 587 | $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
588 | - unset( $where_params['Datetime.DTT_EVT_end'] ); |
|
588 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
589 | 589 | } |
590 | 590 | |
591 | - if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) { |
|
591 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
592 | 592 | $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
593 | - unset( $where_params['Datetime.DTT_EVT_start'] ); |
|
593 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | //merge remaining $where params with the and conditions. |
597 | - $where_params['AND'] = array_merge( $and_condition, $where_params ); |
|
597 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
598 | 598 | $query_params[0] = $where_params; |
599 | 599 | // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
600 | - return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params ); |
|
600 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | |
@@ -608,40 +608,40 @@ discard block |
||
608 | 608 | * @param boolean $count whether to return the count or not (default FALSE) |
609 | 609 | * @return EE_Event[] array of EE_Event objects |
610 | 610 | */ |
611 | - public function get_inactive_events( $query_params, $count = FALSE ) { |
|
612 | - $where_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
611 | + public function get_inactive_events($query_params, $count = FALSE) { |
|
612 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
613 | 613 | |
614 | 614 | //let's add in specific query_params for inactive events. |
615 | - if ( isset( $where_params['status'] ) ) { |
|
616 | - unset( $where_params['status'] ); |
|
615 | + if (isset($where_params['status'])) { |
|
616 | + unset($where_params['status']); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | //if we have count make sure we don't include group by |
620 | - if ( $count && isset( $query_params['group_by'] ) ) { |
|
621 | - unset( $query_params['group_by'] ); |
|
620 | + if ($count && isset($query_params['group_by'])) { |
|
621 | + unset($query_params['group_by']); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | //if we have any additional query_params, let's add them to the 'AND' condition |
625 | - $where_params['AND']['status'] = array( '!=', 'publish' ); |
|
625 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
626 | 626 | |
627 | - if ( isset( $where_params['OR'] ) ) { |
|
627 | + if (isset($where_params['OR'])) { |
|
628 | 628 | $where_params['AND']['OR'] = $where_params['OR']; |
629 | - unset( $where_params['OR'] ); |
|
629 | + unset($where_params['OR']); |
|
630 | 630 | } |
631 | 631 | |
632 | - if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) { |
|
632 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
633 | 633 | $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
634 | - unset( $where_params['Datetime.DTT_EVT_end'] ); |
|
634 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
635 | 635 | } |
636 | 636 | |
637 | - if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) { |
|
637 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
638 | 638 | $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
639 | - unset( $where_params['Datetime.DTT_EVT_start'] ); |
|
639 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | $query_params[0] = $where_params; |
643 | 643 | // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY" |
644 | - return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params ); |
|
644 | + return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | |
@@ -649,13 +649,13 @@ discard block |
||
649 | 649 | * This is just injecting into the parent add_relationship_to so we do special handling on price relationships because we don't want to override any existing global default prices but instead insert NEW prices that get attached to the event. |
650 | 650 | * See parent for param descriptions |
651 | 651 | */ |
652 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $where_query = array()){ |
|
652 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
653 | 653 | |
654 | - if ( $relationName == 'Price' ) { |
|
654 | + if ($relationName == 'Price') { |
|
655 | 655 | //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
656 | 656 | $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
657 | 657 | //if EVT_ID = 0, then this is a default |
658 | - if ( $prc_chk->get('EVT_ID') == 0 ) { |
|
658 | + if ($prc_chk->get('EVT_ID') == 0) { |
|
659 | 659 | //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
660 | 660 | $prc_chk->set('PRC_ID', 0); |
661 | 661 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | } |
666 | 666 | |
667 | 667 | //otherwise carry on as normal |
668 | - return parent::add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $where_query); |
|
668 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
2 | -require_once ( EE_MODELS . 'EEM_Base.model.php' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
2 | +require_once (EE_MODELS.'EEM_Base.model.php'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Transaction Model |
@@ -67,36 +67,36 @@ discard block |
||
67 | 67 | * @return EEM_Transaction |
68 | 68 | * @throws \EE_Error |
69 | 69 | */ |
70 | - protected function __construct( $timezone ) { |
|
71 | - $this->singular_item = __('Transaction','event_espresso'); |
|
72 | - $this->plural_item = __('Transactions','event_espresso'); |
|
70 | + protected function __construct($timezone) { |
|
71 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
72 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
73 | 73 | |
74 | 74 | $this->_tables = array( |
75 | - 'TransactionTable'=>new EE_Primary_Table('esp_transaction','TXN_ID') |
|
75 | + 'TransactionTable'=>new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
76 | 76 | ); |
77 | 77 | $this->_fields = array( |
78 | 78 | 'TransactionTable'=>array( |
79 | - 'TXN_ID'=>new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso')), |
|
80 | - 'TXN_timestamp'=>new EE_Datetime_Field('TXN_timestamp', __('date when transaction was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ), |
|
81 | - 'TXN_total'=>new EE_Money_Field('TXN_total', __('Total value of Transaction','event_espresso'), false, 0), |
|
82 | - 'TXN_paid'=>new EE_Money_Field('TXN_paid', __('Amount paid towards transaction to date','event_espresso'), false, 0), |
|
83 | - 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Transaction::failed_status_code, 'Status'), |
|
84 | - 'TXN_session_data'=>new EE_Serialized_Text_Field('TXN_session_data', __('Serialized session data','event_espresso'), true, ''), |
|
85 | - 'TXN_hash_salt'=>new EE_Plain_Text_Field('TXN_hash_salt', __('Transaction Hash Salt','event_espresso'), true, ''), |
|
79 | + 'TXN_ID'=>new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
80 | + 'TXN_timestamp'=>new EE_Datetime_Field('TXN_timestamp', __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
81 | + 'TXN_total'=>new EE_Money_Field('TXN_total', __('Total value of Transaction', 'event_espresso'), false, 0), |
|
82 | + 'TXN_paid'=>new EE_Money_Field('TXN_paid', __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
83 | + 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Transaction::failed_status_code, 'Status'), |
|
84 | + 'TXN_session_data'=>new EE_Serialized_Text_Field('TXN_session_data', __('Serialized session data', 'event_espresso'), true, ''), |
|
85 | + 'TXN_hash_salt'=>new EE_Plain_Text_Field('TXN_hash_salt', __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
86 | 86 | 'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __("Last Used Payment Method", 'event_espresso'), true, NULL, 'Payment_Method'), |
87 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( 'TXN_reg_steps', __( 'Registration Steps', 'event_espresso' ), FALSE, array() ), |
|
87 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', __('Registration Steps', 'event_espresso'), FALSE, array()), |
|
88 | 88 | ) |
89 | 89 | ); |
90 | 90 | $this->_model_relations = array( |
91 | 91 | 'Registration'=>new EE_Has_Many_Relation(), |
92 | 92 | 'Payment'=>new EE_Has_Many_Relation(), |
93 | 93 | 'Status'=>new EE_Belongs_To_Relation(), |
94 | - 'Line_Item'=>new EE_Has_Many_Relation(false),//you can delete a transaction without needing to delete its line items |
|
94 | + 'Line_Item'=>new EE_Has_Many_Relation(false), //you can delete a transaction without needing to delete its line items |
|
95 | 95 | 'Payment_Method'=>new EE_Belongs_To_Relation(), |
96 | 96 | 'Message' => new EE_Has_Many_Relation() |
97 | 97 | ); |
98 | 98 | $this->_model_chain_to_wp_user = 'Registration.Event'; |
99 | - parent::__construct( $timezone ); |
|
99 | + parent::__construct($timezone); |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | |
@@ -107,22 +107,22 @@ discard block |
||
107 | 107 | * @param string $period |
108 | 108 | * @return \stdClass[] |
109 | 109 | */ |
110 | - public function get_revenue_per_day_report( $period = '-1 month' ) { |
|
111 | - $sql_date = $this->convert_datetime_for_query( 'TXN_timestamp', date( 'Y-m-d H:i:s', strtotime( $period ) ), 'Y-m-d H:i:s', 'UTC' ); |
|
110 | + public function get_revenue_per_day_report($period = '-1 month') { |
|
111 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), 'Y-m-d H:i:s', 'UTC'); |
|
112 | 112 | |
113 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'TXN_timestamp' ); |
|
113 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
114 | 114 | return $this->_get_all_wpdb_results( |
115 | 115 | array( |
116 | 116 | array( |
117 | - 'TXN_timestamp' => array( '>=', $sql_date ) |
|
117 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
118 | 118 | ), |
119 | 119 | 'group_by' => 'txnDate', |
120 | - 'order_by' => array( 'TXN_timestamp' => 'ASC' ) |
|
120 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
121 | 121 | ), |
122 | 122 | OBJECT, |
123 | 123 | array( |
124 | - 'txnDate' => array( 'DATE(' . $query_interval . ')', '%s' ), |
|
125 | - 'revenue' => array( 'SUM(TransactionTable.TXN_paid)', '%d' ) |
|
124 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
125 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
126 | 126 | ) |
127 | 127 | ); |
128 | 128 | } |
@@ -137,18 +137,18 @@ discard block |
||
137 | 137 | * @throws \EE_Error |
138 | 138 | * @return mixed |
139 | 139 | */ |
140 | - public function get_revenue_per_event_report( $period = '-1 month' ) { |
|
140 | + public function get_revenue_per_event_report($period = '-1 month') { |
|
141 | 141 | global $wpdb; |
142 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
143 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
142 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
143 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
144 | 144 | $event_table = $wpdb->posts; |
145 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
146 | - $sql_date = date( 'Y-m-d H:i:s', strtotime( $period ) ); |
|
145 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
146 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
147 | 147 | $approved_payment_status = EEM_Payment::status_id_approved; |
148 | 148 | $extra_event_on_join = ''; |
149 | 149 | //exclude events not authored by user if permissions in effect |
150 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
151 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
150 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
151 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $wpdb->get_results( |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | * @param string $reg_url_link |
189 | 189 | * @return EE_Transaction |
190 | 190 | */ |
191 | - public function get_transaction_from_reg_url_link( $reg_url_link = '' ){ |
|
192 | - return $this->get_one( array( |
|
191 | + public function get_transaction_from_reg_url_link($reg_url_link = '') { |
|
192 | + return $this->get_one(array( |
|
193 | 193 | array( |
194 | - 'Registration.REG_url_link' => ! empty( $reg_url_link ) ? $reg_url_link : EE_Registry::instance()->REQ->get( 'e_reg_url_link', '' ) |
|
194 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', '') |
|
195 | 195 | ) |
196 | 196 | )); |
197 | 197 | } |
@@ -208,16 +208,16 @@ discard block |
||
208 | 208 | * @return boolean |
209 | 209 | * @throws \EE_Error |
210 | 210 | */ |
211 | - public function update_based_on_payments( $transaction_obj_or_id, $save_txn = TRUE ){ |
|
211 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = TRUE) { |
|
212 | 212 | EE_Error::doing_it_wrong( |
213 | - __CLASS__ . '::' . __FUNCTION__, |
|
214 | - sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ), |
|
213 | + __CLASS__.'::'.__FUNCTION__, |
|
214 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
215 | 215 | '4.6.0' |
216 | 216 | ); |
217 | 217 | /** @type EE_Transaction_Processor $transaction_processor */ |
218 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
218 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
219 | 219 | return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
220 | - $this->ensure_is_obj( $transaction_obj_or_id ) |
|
220 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
221 | 221 | ); |
222 | 222 | } |
223 | 223 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | array( |
250 | 250 | 0 => array( |
251 | 251 | 'STS_ID' => EEM_Transaction::failed_status_code, |
252 | - 'TXN_timestamp' => array( '<', time() - $time_to_leave_alone ) |
|
252 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
253 | 253 | ) |
254 | 254 | ), |
255 | 255 | $time_to_leave_alone |
@@ -262,29 +262,29 @@ discard block |
||
262 | 262 | */ |
263 | 263 | $txn_ids = apply_filters( |
264 | 264 | 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
265 | - EEM_Transaction::instance()->get_col( $ids_query, 'TXN_ID' ), |
|
265 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
266 | 266 | $time_to_leave_alone |
267 | 267 | ); |
268 | 268 | //now that we have the ids to delete |
269 | - if ( ! empty( $txn_ids ) && is_array( $txn_ids ) ) { |
|
269 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
270 | 270 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
271 | - EEM_Transaction::unset_locked_transactions( $txn_ids ); |
|
271 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
272 | 272 | // let's get deletin'... |
273 | 273 | // Why no wpdb->prepare? Because the data is trusted. |
274 | 274 | // We got the ids from the original query to get them FROM |
275 | 275 | // the db (which is sanitized) so no need to prepare them again. |
276 | - $query = ' |
|
276 | + $query = ' |
|
277 | 277 | DELETE |
278 | - FROM ' . $this->table() . ' |
|
278 | + FROM ' . $this->table().' |
|
279 | 279 | WHERE |
280 | - TXN_ID IN ( ' . implode( ",", $txn_ids ) . ')'; |
|
281 | - $deleted = $wpdb->query( $query ); |
|
280 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
281 | + $deleted = $wpdb->query($query); |
|
282 | 282 | } |
283 | - if ( $deleted ) { |
|
283 | + if ($deleted) { |
|
284 | 284 | /** |
285 | 285 | * Allows code to do something after the transactions have been deleted. |
286 | 286 | */ |
287 | - do_action( 'AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids ); |
|
287 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
288 | 288 | } |
289 | 289 | return $deleted; |
290 | 290 | } |
@@ -295,17 +295,17 @@ discard block |
||
295 | 295 | * @param array $transaction_IDs |
296 | 296 | * @return bool |
297 | 297 | */ |
298 | - public static function unset_locked_transactions( array $transaction_IDs ) { |
|
299 | - $locked_transactions = get_option( 'ee_locked_transactions', array() ); |
|
298 | + public static function unset_locked_transactions(array $transaction_IDs) { |
|
299 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
300 | 300 | $update = false; |
301 | - foreach ( $transaction_IDs as $TXN_ID ) { |
|
302 | - if ( isset( $locked_transactions[ $TXN_ID ] ) ) { |
|
303 | - unset( $locked_transactions[ $TXN_ID ] ); |
|
301 | + foreach ($transaction_IDs as $TXN_ID) { |
|
302 | + if (isset($locked_transactions[$TXN_ID])) { |
|
303 | + unset($locked_transactions[$TXN_ID]); |
|
304 | 304 | $update = true; |
305 | 305 | } |
306 | 306 | } |
307 | - if ( $update ) { |
|
308 | - update_option( 'ee_locked_transactions', $locked_transactions ); |
|
307 | + if ($update) { |
|
308 | + update_option('ee_locked_transactions', $locked_transactions); |
|
309 | 309 | } |
310 | 310 | return $update; |
311 | 311 | } |
@@ -105,42 +105,42 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return EEM_Message |
107 | 107 | */ |
108 | - protected function __construct( $timezone = null ) { |
|
109 | - $this->singular_item = __('Message','event_espresso'); |
|
110 | - $this->plural_item = __('Messages','event_espresso'); |
|
108 | + protected function __construct($timezone = null) { |
|
109 | + $this->singular_item = __('Message', 'event_espresso'); |
|
110 | + $this->plural_item = __('Messages', 'event_espresso'); |
|
111 | 111 | |
112 | 112 | //used for token generator |
113 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
113 | + EE_Registry::instance()->load_helper('URL'); |
|
114 | 114 | |
115 | 115 | $this->_tables = array( |
116 | - 'Message'=>new EE_Primary_Table('esp_message','MSG_ID') |
|
116 | + 'Message'=>new EE_Primary_Table('esp_message', 'MSG_ID') |
|
117 | 117 | ); |
118 | 118 | |
119 | 119 | $allowed_priority = array( |
120 | - self::priority_high => __( 'high', 'event_espresso' ), |
|
121 | - self::priority_medium => __( 'medium', 'event_espresso' ), |
|
122 | - self::priority_low => __( 'low', 'event_espresso' ) |
|
120 | + self::priority_high => __('high', 'event_espresso'), |
|
121 | + self::priority_medium => __('medium', 'event_espresso'), |
|
122 | + self::priority_low => __('low', 'event_espresso') |
|
123 | 123 | ); |
124 | 124 | |
125 | 125 | $this->_fields = array( |
126 | 126 | 'Message'=>array( |
127 | - 'MSG_ID'=>new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID','event_espresso')), |
|
128 | - 'MSG_token' => new EE_Plain_Text_Field( 'MSG_token', __('Unique Token used to represent this row in publicly viewable contexts (eg. a url).', 'event_espresso' ), false, EEH_URL::generate_unique_token() ), |
|
129 | - 'GRP_ID'=>new EE_Foreign_Key_Int_Field( 'GRP_ID', __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso' ), true, 0, 'Message_Template_Group' ), |
|
130 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( 'TXN_ID', __( 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', 'event_espresso' ), true, 0, 'Transaction' ), |
|
131 | - 'MSG_messenger' => new EE_Plain_Text_Field('MSG_messenger', __( 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', 'event_espresso' ), false, 'email' ), |
|
132 | - 'MSG_message_type' => new EE_Plain_Text_Field( 'MSG_message_type', __( 'Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso' ), false, 'receipt' ), |
|
133 | - 'MSG_context' => new EE_Plain_Text_Field( 'MSG_context', __( 'Context', 'event_espresso' ), false ), |
|
134 | - 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( 'MSG_recipient_ID', __( 'Recipient ID', 'event_espresso' ), true, null, array( 'Registration', 'Attendee', 'WP_User' ) ), |
|
135 | - 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( 'MSG_recipient_type', __( 'Recipient Type', 'event_espresso' ), true, null, array( 'Registration', 'Attendee', 'WP_User' ) ), |
|
136 | - 'MSG_content' => new EE_Maybe_Serialized_Text_Field( 'MSG_content', __( 'Content', 'event_espresso' ), true, '' ), |
|
137 | - 'MSG_to' => new EE_Maybe_Serialized_Text_Field( 'MSG_to', __( 'Address To', 'event_espresso' ), true ), |
|
138 | - 'MSG_from' => new EE_Maybe_Serialized_Text_Field( 'MSG_from', __( 'Address From', 'event_espresso' ), true ), |
|
139 | - 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( 'MSG_subject', __( 'Subject', 'event_espresso' ), true, '' ), |
|
140 | - 'MSG_priority' => new EE_Enum_Integer_Field( 'MSG_priority', __( 'Priority', 'event_espresso' ), false, self::priority_low, $allowed_priority ), |
|
141 | - 'STS_ID' => new EE_Foreign_Key_String_Field( 'STS_ID', __( 'Status', 'event_espresso' ), false, self::status_incomplete, 'Status' ), |
|
142 | - 'MSG_created' => new EE_Datetime_Field( 'MSG_created', __( 'Created', 'event_espresso' ), false, EE_Datetime_Field::now ), |
|
143 | - 'MSG_modified' => new EE_Datetime_Field( 'MSG_modified', __( 'Modified', 'event_espresso' ), true, EE_Datetime_Field::now ) |
|
127 | + 'MSG_ID'=>new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')), |
|
128 | + 'MSG_token' => new EE_Plain_Text_Field('MSG_token', __('Unique Token used to represent this row in publicly viewable contexts (eg. a url).', 'event_espresso'), false, EEH_URL::generate_unique_token()), |
|
129 | + 'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), true, 0, 'Message_Template_Group'), |
|
130 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __('Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', 'event_espresso'), true, 0, 'Transaction'), |
|
131 | + 'MSG_messenger' => new EE_Plain_Text_Field('MSG_messenger', __('Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', 'event_espresso'), false, 'email'), |
|
132 | + 'MSG_message_type' => new EE_Plain_Text_Field('MSG_message_type', __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), false, 'receipt'), |
|
133 | + 'MSG_context' => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false), |
|
134 | + 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field('MSG_recipient_ID', __('Recipient ID', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')), |
|
135 | + 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field('MSG_recipient_type', __('Recipient Type', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')), |
|
136 | + 'MSG_content' => new EE_Maybe_Serialized_Text_Field('MSG_content', __('Content', 'event_espresso'), true, ''), |
|
137 | + 'MSG_to' => new EE_Maybe_Serialized_Text_Field('MSG_to', __('Address To', 'event_espresso'), true), |
|
138 | + 'MSG_from' => new EE_Maybe_Serialized_Text_Field('MSG_from', __('Address From', 'event_espresso'), true), |
|
139 | + 'MSG_subject' => new EE_Maybe_Serialized_Text_Field('MSG_subject', __('Subject', 'event_espresso'), true, ''), |
|
140 | + 'MSG_priority' => new EE_Enum_Integer_Field('MSG_priority', __('Priority', 'event_espresso'), false, self::priority_low, $allowed_priority), |
|
141 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status', 'event_espresso'), false, self::status_incomplete, 'Status'), |
|
142 | + 'MSG_created' => new EE_Datetime_Field('MSG_created', __('Created', 'event_espresso'), false, EE_Datetime_Field::now), |
|
143 | + 'MSG_modified' => new EE_Datetime_Field('MSG_modified', __('Modified', 'event_espresso'), true, EE_Datetime_Field::now) |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | $this->_model_relations = array( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
151 | 151 | 'Transaction' => new EE_Belongs_To_Relation() |
152 | 152 | ); |
153 | - parent::__construct( $timezone ); |
|
153 | + parent::__construct($timezone); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | public function create_default_object() { |
162 | 162 | /** @type EE_Message $message */ |
163 | 163 | $message = parent::create_default_object(); |
164 | - if ( $message instanceof EE_Message ) { |
|
165 | - return EE_Message_Factory::set_messenger_and_message_type( $message ); |
|
164 | + if ($message instanceof EE_Message) { |
|
165 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
166 | 166 | } |
167 | 167 | return null; |
168 | 168 | } |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | * @param mixed $cols_n_values |
174 | 174 | * @return \EE_Message |
175 | 175 | */ |
176 | - public function instantiate_class_from_array_or_object( $cols_n_values ) { |
|
176 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
177 | 177 | /** @type EE_Message $message */ |
178 | - $message = parent::instantiate_class_from_array_or_object( $cols_n_values ); |
|
179 | - if ( $message instanceof EE_Message ) { |
|
180 | - return EE_Message_Factory::set_messenger_and_message_type( $message ); |
|
178 | + $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
179 | + if ($message instanceof EE_Message) { |
|
180 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
181 | 181 | } |
182 | 182 | return null; |
183 | 183 | } |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | * @param string $message_type the message type slug |
191 | 191 | * @return boolean |
192 | 192 | */ |
193 | - public function message_sent_for_attendee( $attendee, $message_type ) { |
|
194 | - $attendee_ID = EEM_Attendee::instance()->ensure_is_ID( $attendee ); |
|
195 | - return $this->exists( array( array( |
|
193 | + public function message_sent_for_attendee($attendee, $message_type) { |
|
194 | + $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
195 | + return $this->exists(array(array( |
|
196 | 196 | 'Attendee.ATT_ID' => $attendee_ID, |
197 | 197 | 'MSG_message_type' => $message_type, |
198 | - 'STS_ID' => array( 'IN', $this->stati_indicating_sent() ) |
|
199 | - ) ) ); |
|
198 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()) |
|
199 | + ))); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | * @param string $message_type the message type slug |
209 | 209 | * @return boolean |
210 | 210 | */ |
211 | - public function message_sent_for_registration( $registration, $message_type ) { |
|
212 | - $registrationID = EEM_Registration::instance()->ensure_is_ID( $registration ); |
|
213 | - return $this->exists( array( array( |
|
211 | + public function message_sent_for_registration($registration, $message_type) { |
|
212 | + $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
213 | + return $this->exists(array(array( |
|
214 | 214 | 'Registration.REG_ID' => $registrationID, |
215 | 215 | 'MSG_message_type' => $message_type, |
216 | - 'STS_ID' => array( 'IN', $this->stati_indicating_sent() ) |
|
217 | - ) ) ); |
|
216 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()) |
|
217 | + ))); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | * @param string $token |
226 | 226 | * @return EE_Message |
227 | 227 | */ |
228 | - public function get_one_by_token( $token ) { |
|
229 | - return $this->get_one( array( array( |
|
228 | + public function get_one_by_token($token) { |
|
229 | + return $this->get_one(array(array( |
|
230 | 230 | 'MSG_token' => $token |
231 | - ) ) ); |
|
231 | + ))); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * Returns stati that indicate the message HAS been sent |
237 | 237 | * @return array of strings for possible stati |
238 | 238 | */ |
239 | - public function stati_indicating_sent(){ |
|
240 | - return apply_filters( 'FHEE__EEM_Message__stati_indicating_sent', array( self::status_sent ) ); |
|
239 | + public function stati_indicating_sent() { |
|
240 | + return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @return array of strings for possible stati. |
249 | 249 | */ |
250 | 250 | public function stati_indicating_to_send() { |
251 | - return apply_filters( 'FHEE__EEM_Message__stati_indicating_to_send', array( self::status_idle, self::status_resend ) ); |
|
251 | + return apply_filters('FHEE__EEM_Message__stati_indicating_to_send', array(self::status_idle, self::status_resend)); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | self::status_retry, |
263 | 263 | ); |
264 | 264 | //if WP_DEBUG is set, then let's include debug_only fails |
265 | - if ( WP_DEBUG ) { |
|
265 | + if (WP_DEBUG) { |
|
266 | 266 | $failed_stati[] = self::status_debug_only; |
267 | 267 | } |
268 | - return apply_filters( 'FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati ); |
|
268 | + return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | |
@@ -300,11 +300,11 @@ discard block |
||
300 | 300 | // the value, matches the corresponding EEM_Base child reference. |
301 | 301 | $expected_vars = $this->_expected_vars_for_query_inject(); |
302 | 302 | $query_params[0] = array(); |
303 | - foreach ( $expected_vars as $request_key => $model_name ) { |
|
304 | - $request_value = EE_Registry::instance()->REQ->get( $request_key ); |
|
305 | - if ( $request_value ) { |
|
303 | + foreach ($expected_vars as $request_key => $model_name) { |
|
304 | + $request_value = EE_Registry::instance()->REQ->get($request_key); |
|
305 | + if ($request_value) { |
|
306 | 306 | //special case |
307 | - switch ( $request_key ) { |
|
307 | + switch ($request_key) { |
|
308 | 308 | case '_REG_ID' : |
309 | 309 | $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
310 | 310 | 'Transaction.Registration.REG_ID' => $request_value, |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | ); |
317 | 317 | break; |
318 | 318 | default : |
319 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
319 | + $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value; |
|
320 | 320 | break; |
321 | 321 | } |
322 | 322 | } |
@@ -333,53 +333,53 @@ discard block |
||
333 | 333 | $expected_vars = $this->_expected_vars_for_query_inject(); |
334 | 334 | $pretty_label = ''; |
335 | 335 | $label_parts = array(); |
336 | - foreach ( $expected_vars as $request_key => $model_name ) { |
|
337 | - $model = EE_Registry::instance()->load_model( $model_name ); |
|
338 | - if ( $model_field_value = EE_Registry::instance()->REQ->get( $request_key ) ) { |
|
339 | - switch ( $request_key ) { |
|
336 | + foreach ($expected_vars as $request_key => $model_name) { |
|
337 | + $model = EE_Registry::instance()->load_model($model_name); |
|
338 | + if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) { |
|
339 | + switch ($request_key) { |
|
340 | 340 | case '_REG_ID' : |
341 | 341 | $label_parts[] = sprintf( |
342 | - esc_html__( 'Registration with the ID: %s', 'event_espresso' ), |
|
342 | + esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
343 | 343 | $model_field_value |
344 | 344 | ); |
345 | 345 | break; |
346 | 346 | case 'ATT_ID' : |
347 | 347 | /** @var EE_Attendee $attendee */ |
348 | - $attendee = $model->get_one_by_ID( $model_field_value ); |
|
348 | + $attendee = $model->get_one_by_ID($model_field_value); |
|
349 | 349 | $label_parts[] = $attendee instanceof EE_Attendee |
350 | - ? sprintf( esc_html__( 'Attendee %s', 'event_espresso' ), $attendee->full_name() ) |
|
351 | - : sprintf( esc_html__( 'Attendee ID: %s', 'event_espresso' ), $model_field_value ); |
|
350 | + ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
351 | + : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
352 | 352 | break; |
353 | 353 | case 'ID' : |
354 | 354 | /** @var EE_WP_User $wpUser */ |
355 | - $wpUser = $model->get_one_by_ID( $model_field_value ); |
|
355 | + $wpUser = $model->get_one_by_ID($model_field_value); |
|
356 | 356 | $label_parts[] = $wpUser instanceof EE_WP_User |
357 | - ? sprintf( esc_html__( 'WP User: %s', 'event_espresso' ), $wpUser->name() ) |
|
358 | - : sprintf( esc_html__( 'WP User ID: %s', 'event_espresso' ), $model_field_value ); |
|
357 | + ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
358 | + : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
359 | 359 | break; |
360 | 360 | case 'TXN_ID' : |
361 | 361 | $label_parts[] = sprintf( |
362 | - esc_html__( 'Transaction with the ID: %s', 'event_espresso' ), |
|
362 | + esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
363 | 363 | $model_field_value |
364 | 364 | ); |
365 | 365 | break; |
366 | 366 | case 'EVT_ID' : |
367 | 367 | /** @var EE_Event $Event */ |
368 | - $Event = $model->get_one_by_ID( $model_field_value ); |
|
368 | + $Event = $model->get_one_by_ID($model_field_value); |
|
369 | 369 | $label_parts[] = $Event instanceof EE_Event |
370 | - ? sprintf( esc_html__( 'for the Event: %s', 'event_espresso' ), $Event->name() ) |
|
371 | - : sprintf( esc_html__( 'for the Event with ID: %s', 'event_espresso' ), $model_field_value ); |
|
370 | + ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
371 | + : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
372 | 372 | break; |
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | - if ( $label_parts ) { |
|
377 | + if ($label_parts) { |
|
378 | 378 | |
379 | 379 | //prepend to the last element of $label_parts an "and". |
380 | - if ( count( $label_parts ) > 1 ) { |
|
381 | - $label_parts_index_to_prepend = count( $label_parts ) - 1; |
|
382 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
380 | + if (count($label_parts) > 1) { |
|
381 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
382 | + $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend]; |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $pretty_label .= sprintf( |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
389 | 389 | 'event_espresso' |
390 | 390 | ), |
391 | - implode( ', ', $label_parts ) |
|
391 | + implode(', ', $label_parts) |
|
392 | 392 | ); |
393 | 393 | } |
394 | 394 | return $pretty_label; |
@@ -438,20 +438,20 @@ discard block |
||
438 | 438 | * |
439 | 439 | * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
440 | 440 | */ |
441 | - public static function debug( $set_debug = null ) { |
|
441 | + public static function debug($set_debug = null) { |
|
442 | 442 | static $is_debugging = null; |
443 | 443 | |
444 | 444 | //initialize (use constant if set). |
445 | - if ( is_null( $set_debug ) && is_null( $is_debugging ) ) { |
|
446 | - $is_debugging = defined( 'EE_DEBUG_MESSAGES' ) && EE_DEBUG_MESSAGES; |
|
445 | + if (is_null($set_debug) && is_null($is_debugging)) { |
|
446 | + $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
447 | 447 | } |
448 | 448 | |
449 | - if ( ! is_null( $set_debug ) ) { |
|
450 | - $is_debugging = filter_var( $set_debug, FILTER_VALIDATE_BOOLEAN ); |
|
449 | + if ( ! is_null($set_debug)) { |
|
450 | + $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | //return filtered value |
454 | - return apply_filters( 'FHEE__EEM_Message__debug', $is_debugging ); |
|
454 | + return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 |
@@ -22,24 +22,24 @@ discard block |
||
22 | 22 | * @param null $timezone |
23 | 23 | * @throws \EE_Error |
24 | 24 | */ |
25 | - protected function __construct( $timezone = NULL ){ |
|
26 | - $this->singular_item = __('WP_User','event_espresso'); |
|
27 | - $this->plural_item = __('WP_Users','event_espresso'); |
|
25 | + protected function __construct($timezone = NULL) { |
|
26 | + $this->singular_item = __('WP_User', 'event_espresso'); |
|
27 | + $this->plural_item = __('WP_Users', 'event_espresso'); |
|
28 | 28 | global $wpdb; |
29 | 29 | $this->_tables = array( |
30 | - 'WP_User'=> new EE_Primary_Table( $wpdb->users, 'ID', true) |
|
30 | + 'WP_User'=> new EE_Primary_Table($wpdb->users, 'ID', true) |
|
31 | 31 | ); |
32 | 32 | $this->_fields = array( |
33 | 33 | 'WP_User'=>array( |
34 | - 'ID'=> new EE_Primary_Key_Int_Field('ID', __('WP_User ID','event_espresso')), |
|
35 | - 'user_login'=>new EE_Plain_Text_Field('user_login', __('User Login','event_espresso'), false, '' ), |
|
36 | - 'user_pass'=>new EE_Plain_Text_Field('user_pass', __('User Password','event_espresso'), false, '' ), |
|
37 | - 'user_nicename'=>new EE_Plain_Text_Field('user_nicename', __(' User Nice Name','event_espresso'), false, ''), |
|
38 | - 'user_email' => new EE_Email_Field('user_email', __( 'User Email', 'event_espresso' ), false), |
|
39 | - 'user_registered' => new EE_Datetime_Field( 'user_registered', __( 'Date User Registered', 'event_espresso' ), false, EE_Datetime_Field::now, $timezone ), |
|
40 | - 'user_activation_key' => new EE_Plain_Text_Field( 'user_activation_key', __( 'User Activation Key', 'event_espresso' ), false, '' ), |
|
41 | - 'user_status' => new EE_Integer_Field( 'user_status', __( 'User Status', 'event_espresso' ), false, 0 ), |
|
42 | - 'display_name' => new EE_Plain_Text_Field( 'display_name', __( 'Display Name', 'event_espresso' ), false, '' ) |
|
34 | + 'ID'=> new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')), |
|
35 | + 'user_login'=>new EE_Plain_Text_Field('user_login', __('User Login', 'event_espresso'), false, ''), |
|
36 | + 'user_pass'=>new EE_Plain_Text_Field('user_pass', __('User Password', 'event_espresso'), false, ''), |
|
37 | + 'user_nicename'=>new EE_Plain_Text_Field('user_nicename', __(' User Nice Name', 'event_espresso'), false, ''), |
|
38 | + 'user_email' => new EE_Email_Field('user_email', __('User Email', 'event_espresso'), false), |
|
39 | + 'user_registered' => new EE_Datetime_Field('user_registered', __('Date User Registered', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
40 | + 'user_activation_key' => new EE_Plain_Text_Field('user_activation_key', __('User Activation Key', 'event_espresso'), false, ''), |
|
41 | + 'user_status' => new EE_Integer_Field('user_status', __('User Status', 'event_espresso'), false, 0), |
|
42 | + 'display_name' => new EE_Plain_Text_Field('display_name', __('Display Name', 'event_espresso'), false, '') |
|
43 | 43 | )); |
44 | 44 | $this->_model_relations = array( |
45 | 45 | 'Attendee' => new EE_Has_Many_Relation(), |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | ); |
57 | 57 | $this->_wp_core_model = true; |
58 | 58 | $this->_caps_slug = 'users'; |
59 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
60 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
61 | - foreach( $this->_cap_contexts_to_cap_action_map as $context => $action ) { |
|
62 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
59 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
60 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
61 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
62 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
63 | 63 | } |
64 | 64 | //@todo: account for create_users controls whether they can create users at all |
65 | 65 | |
66 | - parent::__construct( $timezone ); |
|
66 | + parent::__construct($timezone); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |