@@ -257,7 +257,7 @@ |
||
| 257 | 257 | * @param int $TXN_ID |
| 258 | 258 | * @param int $ATT_ID |
| 259 | 259 | * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required |
| 260 | - * @return mixed array on success, FALSE on fail |
|
| 260 | + * @return EE_Base_Class|null array on success, FALSE on fail |
|
| 261 | 261 | */ |
| 262 | 262 | public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) { |
| 263 | 263 | 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 |
@@ -92,31 +92,31 @@ discard block |
||
| 92 | 92 | * 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) |
| 93 | 93 | * @return \EEM_Registration |
| 94 | 94 | */ |
| 95 | - protected function __construct( $timezone ) { |
|
| 96 | - $this->singular_item = __('Registration','event_espresso'); |
|
| 97 | - $this->plural_item = __('Registrations','event_espresso'); |
|
| 95 | + protected function __construct($timezone) { |
|
| 96 | + $this->singular_item = __('Registration', 'event_espresso'); |
|
| 97 | + $this->plural_item = __('Registrations', 'event_espresso'); |
|
| 98 | 98 | |
| 99 | 99 | $this->_tables = array( |
| 100 | - 'Registration'=>new EE_Primary_Table('esp_registration','REG_ID') |
|
| 100 | + 'Registration'=>new EE_Primary_Table('esp_registration', 'REG_ID') |
|
| 101 | 101 | ); |
| 102 | 102 | $this->_fields = array( |
| 103 | 103 | 'Registration'=>array( |
| 104 | - 'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID','event_espresso')), |
|
| 105 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'), |
|
| 106 | - 'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID','event_espresso'), false, 0, 'Attendee'), |
|
| 107 | - 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso'), false, 0, 'Transaction'), |
|
| 108 | - 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID','event_espresso'), false, 0, 'Ticket'), |
|
| 109 | - 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'), |
|
| 110 | - 'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred','event_espresso'), false, time(), $timezone ), |
|
| 111 | - 'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total','event_espresso'), false, 0), |
|
| 112 | - 'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration','event_espresso'), false, 0), |
|
| 113 | - 'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration','event_espresso'), false, ''), |
|
| 114 | - 'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration','event_espresso'), false, ''), |
|
| 115 | - 'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration','event_espresso'), false, ''), |
|
| 116 | - 'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ','event_espresso'), true, 1), |
|
| 117 | - 'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group','event_espresso'), false, 1), |
|
| 118 | - 'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending','event_espresso'), false, false), |
|
| 119 | - 'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false ) |
|
| 104 | + 'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')), |
|
| 105 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
| 106 | + 'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'), |
|
| 107 | + 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
| 108 | + 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false, 0, 'Ticket'), |
|
| 109 | + 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'), |
|
| 110 | + 'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred', 'event_espresso'), false, time(), $timezone), |
|
| 111 | + 'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total', 'event_espresso'), false, 0), |
|
| 112 | + 'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration', 'event_espresso'), false, 0), |
|
| 113 | + 'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration', 'event_espresso'), false, ''), |
|
| 114 | + 'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration', 'event_espresso'), false, ''), |
|
| 115 | + 'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration', 'event_espresso'), false, ''), |
|
| 116 | + 'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ', 'event_espresso'), true, 1), |
|
| 117 | + 'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group', 'event_espresso'), false, 1), |
|
| 118 | + 'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending', 'event_espresso'), false, false), |
|
| 119 | + 'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false) |
|
| 120 | 120 | ) |
| 121 | 121 | ); |
| 122 | 122 | $this->_model_relations = array( |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | 'Answer'=>new EE_Has_Many_Relation(), |
| 129 | 129 | 'Checkin'=>new EE_Has_Many_Relation(), |
| 130 | 130 | 'Registration_Payment' => new EE_Has_Many_Relation(), |
| 131 | - 'Payment'=>new EE_HABTM_Relation( 'Registration_Payment' ), |
|
| 131 | + 'Payment'=>new EE_HABTM_Relation('Registration_Payment'), |
|
| 132 | 132 | ); |
| 133 | 133 | $this->_model_chain_to_wp_user = 'Event'; |
| 134 | 134 | |
| 135 | - parent::__construct( $timezone ); |
|
| 135 | + parent::__construct($timezone); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | * @param bool $translated If true will return the values as singular localized strings |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - public static function reg_status_array( $exclude = array(), $translated = FALSE ) { |
|
| 169 | - EEM_Registration::instance()->_get_registration_status_array( $exclude ); |
|
| 170 | - return $translated ? EEM_Status::instance()->localized_status( self::$_reg_status, FALSE, 'sentence') : self::$_reg_status; |
|
| 168 | + public static function reg_status_array($exclude = array(), $translated = FALSE) { |
|
| 169 | + EEM_Registration::instance()->_get_registration_status_array($exclude); |
|
| 170 | + return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, FALSE, 'sentence') : self::$_reg_status; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -178,19 +178,19 @@ discard block |
||
| 178 | 178 | * @param array $exclude |
| 179 | 179 | * @return array |
| 180 | 180 | */ |
| 181 | - private function _get_registration_status_array( $exclude = array() ) { |
|
| 181 | + private function _get_registration_status_array($exclude = array()) { |
|
| 182 | 182 | //in the very rare circumstance that we are deleting a model's table's data |
| 183 | 183 | //and the table hasn't actually been created, this could have an error |
| 184 | 184 | /** @type WPDB $wpdb */ |
| 185 | 185 | global $wpdb; |
| 186 | - EE_Registry::instance()->load_helper( 'Activation' ); |
|
| 187 | - if( EEH_Activation::table_exists( $wpdb->prefix . 'esp_status' ) ){ |
|
| 188 | - $SQL = 'SELECT STS_ID, STS_code FROM '. $wpdb->prefix . 'esp_status WHERE STS_type = "registration"'; |
|
| 189 | - $results = $wpdb->get_results( $SQL ); |
|
| 186 | + EE_Registry::instance()->load_helper('Activation'); |
|
| 187 | + if (EEH_Activation::table_exists($wpdb->prefix.'esp_status')) { |
|
| 188 | + $SQL = 'SELECT STS_ID, STS_code FROM '.$wpdb->prefix.'esp_status WHERE STS_type = "registration"'; |
|
| 189 | + $results = $wpdb->get_results($SQL); |
|
| 190 | 190 | self::$_reg_status = array(); |
| 191 | - foreach ( $results as $status ) { |
|
| 192 | - if ( ! in_array( $status->STS_ID, $exclude )) { |
|
| 193 | - self::$_reg_status[ $status->STS_ID ] = $status->STS_code; |
|
| 191 | + foreach ($results as $status) { |
|
| 192 | + if ( ! in_array($status->STS_ID, $exclude)) { |
|
| 193 | + self::$_reg_status[$status->STS_ID] = $status->STS_code; |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -205,15 +205,15 @@ discard block |
||
| 205 | 205 | * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
| 206 | 206 | * @return wpdb results array |
| 207 | 207 | */ |
| 208 | - public function get_reg_months_and_years( $where_params ) { |
|
| 208 | + public function get_reg_months_and_years($where_params) { |
|
| 209 | 209 | $query_params[0] = $where_params; |
| 210 | 210 | $query_params['group_by'] = array('reg_year', 'reg_month'); |
| 211 | - $query_params['order_by'] = array( 'REG_date' => 'DESC' ); |
|
| 211 | + $query_params['order_by'] = array('REG_date' => 'DESC'); |
|
| 212 | 212 | $columns_to_select = array( |
| 213 | 213 | 'reg_year' => array('YEAR(REG_date)', '%s'), |
| 214 | 214 | 'reg_month' => array('MONTHNAME(REG_date)', '%s') |
| 215 | 215 | ); |
| 216 | - return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select ); |
|
| 216 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | * @param int $ATT_ID |
| 226 | 226 | * @return EE_Registration[] |
| 227 | 227 | */ |
| 228 | - public function get_all_registrations_for_attendee( $ATT_ID = 0 ) { |
|
| 229 | - if ( ! $ATT_ID ) { |
|
| 228 | + public function get_all_registrations_for_attendee($ATT_ID = 0) { |
|
| 229 | + if ( ! $ATT_ID) { |
|
| 230 | 230 | return FALSE; |
| 231 | 231 | } |
| 232 | - return $this->get_all( array( array( 'ATT_ID' => $ATT_ID ))); |
|
| 232 | + return $this->get_all(array(array('ATT_ID' => $ATT_ID))); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | * @param string $REG_url_link |
| 241 | 241 | * @return EE_Registration |
| 242 | 242 | */ |
| 243 | - public function get_registration_for_reg_url_link($REG_url_link){ |
|
| 244 | - if(!$REG_url_link){ |
|
| 243 | + public function get_registration_for_reg_url_link($REG_url_link) { |
|
| 244 | + if ( ! $REG_url_link) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | return $this->get_one(array(array('REG_url_link'=>$REG_url_link))); |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required |
| 260 | 260 | * @return mixed array on success, FALSE on fail |
| 261 | 261 | */ |
| 262 | - public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) { |
|
| 262 | + public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) { |
|
| 263 | 263 | return $this->get_one(array( |
| 264 | 264 | array( |
| 265 | 265 | 'TXN_ID'=>$TXN_ID, |
| 266 | 266 | 'ATT_ID'=>$ATT_ID |
| 267 | 267 | ), |
| 268 | - 'limit'=>array( min( ( $att_nmbr-1 ), 0 ), 1 ) |
|
| 268 | + 'limit'=>array(min(($att_nmbr - 1), 0), 1) |
|
| 269 | 269 | )); |
| 270 | 270 | } |
| 271 | 271 | |
@@ -277,12 +277,12 @@ discard block |
||
| 277 | 277 | * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
| 278 | 278 | * @return stdClass[] with properties regDate and total |
| 279 | 279 | */ |
| 280 | - public function get_registrations_per_day_report( $period = '-1 month' ) { |
|
| 280 | + public function get_registrations_per_day_report($period = '-1 month') { |
|
| 281 | 281 | |
| 282 | - $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' ); |
|
| 283 | - $where = array( 'REG_date' => array( '>=', $sql_date ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ); |
|
| 282 | + $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'); |
|
| 283 | + $where = array('REG_date' => array('>=', $sql_date), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)); |
|
| 284 | 284 | |
| 285 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_day_report' ) ) { |
|
| 285 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
| 286 | 286 | $where['Event.EVT_wp_user'] = get_current_user_id(); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -294,8 +294,8 @@ discard block |
||
| 294 | 294 | ), |
| 295 | 295 | OBJECT, |
| 296 | 296 | array( |
| 297 | - 'regDate'=>array('DATE(Registration.REG_date)','%s'), |
|
| 298 | - 'total'=>array('count(REG_ID)','%d') |
|
| 297 | + 'regDate'=>array('DATE(Registration.REG_date)', '%s'), |
|
| 298 | + 'total'=>array('count(REG_ID)', '%d') |
|
| 299 | 299 | )); |
| 300 | 300 | return $results; |
| 301 | 301 | } |
@@ -310,23 +310,23 @@ discard block |
||
| 310 | 310 | * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
| 311 | 311 | * @return stdClass[] each with properties event_name, reg_limit, and total |
| 312 | 312 | */ |
| 313 | - public function get_registrations_per_event_report( $period = '-1 month' ) { |
|
| 313 | + public function get_registrations_per_event_report($period = '-1 month') { |
|
| 314 | 314 | |
| 315 | - $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' ); |
|
| 316 | - $where = array( 'REG_date' => array( '>=', $date_sql ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ); |
|
| 315 | + $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'); |
|
| 316 | + $where = array('REG_date' => array('>=', $date_sql), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)); |
|
| 317 | 317 | |
| 318 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
| 318 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
| 319 | 319 | $where['Event.EVT_wp_user'] = get_current_user_id(); |
| 320 | 320 | } |
| 321 | 321 | $results = $this->_get_all_wpdb_results(array( |
| 322 | 322 | $where, |
| 323 | 323 | 'group_by'=>'Event.EVT_name', |
| 324 | 324 | 'order_by'=>'Event.EVT_name', |
| 325 | - 'limit'=>array(0,24)), |
|
| 325 | + 'limit'=>array(0, 24)), |
|
| 326 | 326 | OBJECT, |
| 327 | 327 | array( |
| 328 | - 'event_name'=>array('Event_CPT.post_title','%s'), |
|
| 329 | - 'total'=>array('COUNT(REG_ID)','%s') |
|
| 328 | + 'event_name'=>array('Event_CPT.post_title', '%s'), |
|
| 329 | + 'total'=>array('COUNT(REG_ID)', '%s') |
|
| 330 | 330 | ) |
| 331 | 331 | ); |
| 332 | 332 | |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | * @param int $TXN_ID |
| 341 | 341 | * @return EE_Registration |
| 342 | 342 | */ |
| 343 | - public function get_primary_registration_for_transaction_ID( $TXN_ID = 0){ |
|
| 344 | - if( ! $TXN_ID ){ |
|
| 343 | + public function get_primary_registration_for_transaction_ID($TXN_ID = 0) { |
|
| 344 | + if ( ! $TXN_ID) { |
|
| 345 | 345 | return false; |
| 346 | 346 | } |
| 347 | - return $this->get_one(array(array('TXN_ID'=>$TXN_ID,'REG_count'=> EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
| 347 | + return $this->get_one(array(array('TXN_ID'=>$TXN_ID, 'REG_count'=> EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | * @param boolean $for_incomplete_payments |
| 357 | 357 | * @return int |
| 358 | 358 | */ |
| 359 | - public function get_event_registration_count ( $EVT_ID, $for_incomplete_payments = FALSE ) { |
|
| 359 | + public function get_event_registration_count($EVT_ID, $for_incomplete_payments = FALSE) { |
|
| 360 | 360 | // we only count approved registrations towards registration limits |
| 361 | - $query_params = array( array( 'EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved ) ); |
|
| 362 | - if( $for_incomplete_payments ){ |
|
| 363 | - $query_params[0]['Transaction.STS_ID']=array('!=', EEM_Transaction::complete_status_code); |
|
| 361 | + $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved)); |
|
| 362 | + if ($for_incomplete_payments) { |
|
| 363 | + $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | return $this->count($query_params); |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | /** @type WPDB $wpdb */ |
| 377 | 377 | global $wpdb; |
| 378 | 378 | return $wpdb->query( |
| 379 | - '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' ); |
|
| 379 | + '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' ); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
@@ -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); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | /** |
| 279 | 279 | * Updates all the items of this model which match the $query params, regardless of whether |
| 280 | 280 | * they've been soft-deleted or not |
| 281 | - * @param array $field_n_values like EEM_Base::update's $fields_n_value |
|
| 281 | + * @param array $fields_n_values like EEM_Base::update's $fields_n_value |
|
| 282 | 282 | * @param array $query_params like EEM_base::get_all's $query_params |
| 283 | 283 | * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
| 284 | 284 | * in this model's entity map according to $fields_n_values that match $query_params. This |
@@ -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 | * @reutrn 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 | } |
@@ -17,7 +17,6 @@ |
||
| 17 | 17 | class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions{ |
| 18 | 18 | /** |
| 19 | 19 | * Gets the where default where conditions for a custom post type model |
| 20 | - * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment" |
|
| 21 | 20 | * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions) |
| 22 | 21 | */ |
| 23 | 22 | protected function _get_default_where_conditions() { |
@@ -3,17 +3,17 @@ |
||
| 3 | 3 | exit( 'No direct script access allowed' ); |
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | - * |
|
| 7 | - * Class EE_Default_Where_Conditions |
|
| 8 | - * |
|
| 9 | - * Strategy specifically for adding where conditions specific to CPT models. |
|
| 10 | - * |
|
| 11 | - * @package Event Espresso |
|
| 12 | - * @subpackage core/db_models |
|
| 13 | - * @author Mike Nelson |
|
| 14 | - * * @since 4.6.0 |
|
| 15 | - * |
|
| 16 | - */ |
|
| 6 | + * |
|
| 7 | + * Class EE_Default_Where_Conditions |
|
| 8 | + * |
|
| 9 | + * Strategy specifically for adding where conditions specific to CPT models. |
|
| 10 | + * |
|
| 11 | + * @package Event Espresso |
|
| 12 | + * @subpackage core/db_models |
|
| 13 | + * @author Mike Nelson |
|
| 14 | + * * @since 4.6.0 |
|
| 15 | + * |
|
| 16 | + */ |
|
| 17 | 17 | class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions{ |
| 18 | 18 | /** |
| 19 | 19 | * Gets the where default where conditions for a custom post type model |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * * @since 4.6.0 |
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | -class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions{ |
|
| 17 | +class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions { |
|
| 18 | 18 | /** |
| 19 | 19 | * Gets the where default where conditions for a custom post type model |
| 20 | 20 | * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment" |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return array_merge( |
| 26 | 26 | parent::_get_default_where_conditions(), |
| 27 | 27 | array( |
| 28 | - $status_field->get_name() => array('NOT IN',array('auto-draft','trash') ) |
|
| 28 | + $status_field->get_name() => array('NOT IN', array('auto-draft', 'trash')) |
|
| 29 | 29 | ) |
| 30 | 30 | ); |
| 31 | 31 | } |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param bool $routing |
| 57 | 57 | * @return Transactions_Admin_Page |
| 58 | 58 | */ |
| 59 | - public function __construct( $routing = TRUE ) { |
|
| 60 | - parent::__construct( $routing ); |
|
| 59 | + public function __construct($routing = TRUE) { |
|
| 60 | + parent::__construct($routing); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | 82 | protected function _ajax_hooks() { |
| 83 | - add_action('wp_ajax_espresso_apply_payment', array( $this, 'apply_payments_or_refunds')); |
|
| 84 | - add_action('wp_ajax_espresso_apply_refund', array( $this, 'apply_payments_or_refunds')); |
|
| 85 | - add_action('wp_ajax_espresso_delete_payment', array( $this, 'delete_payment')); |
|
| 83 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 84 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 85 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | 'buttons' => array( |
| 98 | 98 | 'add' => __('Add New Transaction', 'event_espresso'), |
| 99 | 99 | 'edit' => __('Edit Transaction', 'event_espresso'), |
| 100 | - 'delete' => __('Delete Transaction','event_espresso') |
|
| 100 | + 'delete' => __('Delete Transaction', 'event_espresso') |
|
| 101 | 101 | ) |
| 102 | 102 | ); |
| 103 | 103 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $this->_set_transaction_status_array(); |
| 115 | 115 | |
| 116 | - $txn_id = ! empty( $this->_req_data['TXN_ID'] ) && ! is_array( $this->_req_data['TXN_ID'] ) ? $this->_req_data['TXN_ID'] : 0; |
|
| 116 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 117 | 117 | |
| 118 | 118 | $this->_page_routes = array( |
| 119 | 119 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | 'filename' => 'transactions_overview_views_filters_search' |
| 186 | 186 | ), |
| 187 | 187 | ), |
| 188 | - 'help_tour' => array( 'Transactions_Overview_Help_Tour' ), |
|
| 188 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 189 | 189 | /** |
| 190 | 190 | * commented out because currently we are not displaying tips for transaction list table status but this |
| 191 | 191 | * may change in a later iteration so want to keep the code for then. |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | 'nav' => array( |
| 198 | 198 | 'label' => __('View Transaction', 'event_espresso'), |
| 199 | 199 | 'order' => 5, |
| 200 | - 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url, |
|
| 200 | + 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 201 | 201 | 'persistent' => FALSE |
| 202 | 202 | ), |
| 203 | 203 | 'help_tabs' => array( |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
| 219 | 219 | ), |
| 220 | 220 | ), |
| 221 | - 'qtips' => array( 'Transaction_Details_Tips' ), |
|
| 222 | - 'help_tour' => array( 'Transaction_Details_Help_Tour' ), |
|
| 221 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 222 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 223 | 223 | 'metaboxes' => array('_transaction_details_metaboxes'), |
| 224 | 224 | |
| 225 | 225 | 'require_nonce' => FALSE |
@@ -234,10 +234,10 @@ discard block |
||
| 234 | 234 | protected function _add_screen_options() {} |
| 235 | 235 | protected function _add_feature_pointers() {} |
| 236 | 236 | public function admin_init() { |
| 237 | - EE_Registry::$i18n_js_strings[ 'invalid_server_response' ] = __( 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', 'event_espresso' ); |
|
| 238 | - EE_Registry::$i18n_js_strings[ 'error_occurred' ] = __( 'An error occurred! Please refresh the page and try again.', 'event_espresso' ); |
|
| 239 | - EE_Registry::$i18n_js_strings[ 'txn_status_array' ] = self::$_txn_status; |
|
| 240 | - EE_Registry::$i18n_js_strings[ 'pay_status_array' ] = self::$_pay_status; |
|
| 237 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = __('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', 'event_espresso'); |
|
| 238 | + EE_Registry::$i18n_js_strings['error_occurred'] = __('An error occurred! Please refresh the page and try again.', 'event_espresso'); |
|
| 239 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 240 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 241 | 241 | } |
| 242 | 242 | public function admin_notices() {} |
| 243 | 243 | public function admin_footer_scripts() {} |
@@ -304,14 +304,14 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | public function load_scripts_styles() { |
| 306 | 306 | //enqueue style |
| 307 | - wp_register_style( 'espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 307 | + wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 308 | 308 | wp_enqueue_style('espresso_txn'); |
| 309 | 309 | |
| 310 | 310 | //scripts |
| 311 | 311 | add_filter('FHEE_load_accounting_js', '__return_true'); |
| 312 | 312 | |
| 313 | 313 | //scripts |
| 314 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array('ee_admin_js', 'ee-datepicker', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'ee-dialog', 'ee-accounting', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 314 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array('ee_admin_js', 'ee-datepicker', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'ee-dialog', 'ee-accounting', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 315 | 315 | wp_enqueue_script('espresso_txn'); |
| 316 | 316 | |
| 317 | 317 | } |
@@ -351,8 +351,8 @@ discard block |
||
| 351 | 351 | * @return void |
| 352 | 352 | */ |
| 353 | 353 | protected function _set_list_table_views_default() { |
| 354 | - $this->_views = array ( |
|
| 355 | - 'all' => array ( |
|
| 354 | + $this->_views = array( |
|
| 355 | + 'all' => array( |
|
| 356 | 356 | 'slug' => 'all', |
| 357 | 357 | 'label' => __('View All Transactions', 'event_espresso'), |
| 358 | 358 | 'count' => 0 |
@@ -380,20 +380,20 @@ discard block |
||
| 380 | 380 | * @return void |
| 381 | 381 | */ |
| 382 | 382 | private function _set_transaction_object() { |
| 383 | - if ( is_object( $this->_transaction) ) |
|
| 383 | + if (is_object($this->_transaction)) |
|
| 384 | 384 | return; //get out we've already set the object |
| 385 | 385 | |
| 386 | 386 | $TXN = EEM_Transaction::instance(); |
| 387 | 387 | |
| 388 | - $TXN_ID = ( ! empty( $this->_req_data['TXN_ID'] )) ? absint( $this->_req_data['TXN_ID'] ) : FALSE; |
|
| 388 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : FALSE; |
|
| 389 | 389 | |
| 390 | 390 | //get transaction object |
| 391 | 391 | $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
| 392 | - $this->_session = !empty( $this->_transaction ) ? $this->_transaction->get('TXN_session_data') : NULL; |
|
| 392 | + $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : NULL; |
|
| 393 | 393 | |
| 394 | - if ( empty( $this->_transaction ) ) { |
|
| 395 | - $error_msg = __('An error occurred and the details for Transaction ID #', 'event_espresso') . $TXN_ID . __(' could not be retrieved.', 'event_espresso'); |
|
| 396 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 394 | + if (empty($this->_transaction)) { |
|
| 395 | + $error_msg = __('An error occurred and the details for Transaction ID #', 'event_espresso').$TXN_ID.__(' could not be retrieved.', 'event_espresso'); |
|
| 396 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | ), |
| 420 | 420 | 'view_receipt' => array( |
| 421 | 421 | 'class' => 'dashicons dashicons-media-default', |
| 422 | - 'desc' => __('View Transaction Receipt', 'event_espresso' ) |
|
| 422 | + 'desc' => __('View Transaction Receipt', 'event_espresso') |
|
| 423 | 423 | ), |
| 424 | 424 | 'view_registration' => array( |
| 425 | 425 | 'class' => 'dashicons dashicons-clipboard', |
@@ -428,10 +428,10 @@ discard block |
||
| 428 | 428 | ) |
| 429 | 429 | ); |
| 430 | 430 | |
| 431 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_transactions_send_payment_reminder' ) ) { |
|
| 431 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) { |
|
| 432 | 432 | |
| 433 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 434 | - if ( EEH_MSG_Template::is_mt_active( 'payment_reminder' ) ) { |
|
| 433 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 434 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 435 | 435 | $items['send_payment_reminder'] = array( |
| 436 | 436 | 'class' => 'dashicons dashicons-email-alt', |
| 437 | 437 | 'desc' => __('Send Payment Reminder', 'event_espresso') |
@@ -452,29 +452,29 @@ discard block |
||
| 452 | 452 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 453 | 453 | array( |
| 454 | 454 | 'overpaid' => array( |
| 455 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 456 | - 'desc' => EEH_Template::pretty_status( EEM_Transaction::overpaid_status_code, FALSE, 'sentence' ) |
|
| 455 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 456 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, FALSE, 'sentence') |
|
| 457 | 457 | ), |
| 458 | 458 | 'complete' => array( |
| 459 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 460 | - 'desc' => EEH_Template::pretty_status( EEM_Transaction::complete_status_code, FALSE, 'sentence' ) |
|
| 459 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 460 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, FALSE, 'sentence') |
|
| 461 | 461 | ), |
| 462 | 462 | 'incomplete' => array( |
| 463 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 464 | - 'desc' => EEH_Template::pretty_status( EEM_Transaction::incomplete_status_code, FALSE, 'sentence' ) |
|
| 463 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 464 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, FALSE, 'sentence') |
|
| 465 | 465 | ), |
| 466 | 466 | 'abandoned' => array( |
| 467 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 468 | - 'desc' => EEH_Template::pretty_status( EEM_Transaction::abandoned_status_code, FALSE, 'sentence' ) |
|
| 467 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 468 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, FALSE, 'sentence') |
|
| 469 | 469 | ), |
| 470 | 470 | 'failed' => array( |
| 471 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 472 | - 'desc' => EEH_Template::pretty_status( EEM_Transaction::failed_status_code, FALSE, 'sentence' ) |
|
| 471 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 472 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, FALSE, 'sentence') |
|
| 473 | 473 | ) |
| 474 | 474 | ) |
| 475 | 475 | ); |
| 476 | 476 | |
| 477 | - return array_merge( $items, $more_items); |
|
| 477 | + return array_merge($items, $more_items); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | protected function _transactions_overview_list_table() { |
| 489 | 489 | $this->_admin_page_title = __('Transactions', 'event_espresso'); |
| 490 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'] ) : NULL; |
|
| 491 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf( __('%sViewing Transactions for the Event: %s%s', 'event_espresso'), '<h3>', '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), EVENTS_ADMIN_URL ) . '" title="' . esc_attr__('Click to Edit event', 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>' ) : ''; |
|
| 492 | - $this->_template_args['after_list_table'] = $this->_display_legend( $this->_transaction_legend_items() ); |
|
| 490 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : NULL; |
|
| 491 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(__('%sViewing Transactions for the Event: %s%s', 'event_espresso'), '<h3>', '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event', 'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : ''; |
|
| 492 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 493 | 493 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 494 | 494 | } |
| 495 | 495 | |
@@ -503,8 +503,8 @@ discard block |
||
| 503 | 503 | * @return void |
| 504 | 504 | */ |
| 505 | 505 | protected function _transaction_details() { |
| 506 | - do_action( 'AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction ); |
|
| 507 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 506 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 507 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 508 | 508 | |
| 509 | 509 | $this->_set_transaction_status_array(); |
| 510 | 510 | |
@@ -517,75 +517,75 @@ discard block |
||
| 517 | 517 | $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL; |
| 518 | 518 | |
| 519 | 519 | $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
| 520 | - $this->_template_args['txn_nmbr']['label'] = __( 'Transaction Number', 'event_espresso' ); |
|
| 520 | + $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso'); |
|
| 521 | 521 | |
| 522 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_datetime('TXN_timestamp', 'l F j, Y', 'g:i:s a' ); |
|
| 523 | - $this->_template_args['txn_datetime']['label'] = __( 'Date', 'event_espresso' ); |
|
| 522 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_datetime('TXN_timestamp', 'l F j, Y', 'g:i:s a'); |
|
| 523 | + $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso'); |
|
| 524 | 524 | |
| 525 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ]; |
|
| 526 | - $this->_template_args['txn_status']['label'] = __( 'Transaction Status', 'event_espresso' ); |
|
| 527 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 525 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 526 | + $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso'); |
|
| 527 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
| 528 | 528 | |
| 529 | 529 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
| 530 | 530 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
| 531 | 531 | |
| 532 | - if ( $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_transactions_send_payment_reminder' ) ) { |
|
| 533 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 534 | - $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active( 'payment_reminder' ) |
|
| 532 | + if ($attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) { |
|
| 533 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 534 | + $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 535 | 535 | && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
| 536 | 536 | && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
| 537 | - ? EEH_Template::get_button_or_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'send_payment_reminder', 'TXN_ID'=>$this->_transaction->ID(), 'redirect_to' => 'view_transaction' ), TXN_ADMIN_URL ), __(' Send Payment Reminder'), 'button secondary-button right', 'dashicons dashicons-email-alt' ) |
|
| 537 | + ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action'=>'send_payment_reminder', 'TXN_ID'=>$this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder'), 'button secondary-button right', 'dashicons dashicons-email-alt') |
|
| 538 | 538 | : ''; |
| 539 | 539 | } else { |
| 540 | 540 | $this->_template_args['send_payment_reminder_button'] = ''; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
| 544 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( $amount_due, TRUE ); |
|
| 545 | - if ( EE_Registry::instance()->CFG->currency->sign_b4 ) { |
|
| 546 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 544 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, TRUE); |
|
| 545 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 546 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due']; |
|
| 547 | 547 | } else { |
| 548 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 548 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign; |
|
| 549 | 549 | } |
| 550 | - $this->_template_args['amount_due_class'] = ''; |
|
| 550 | + $this->_template_args['amount_due_class'] = ''; |
|
| 551 | 551 | |
| 552 | - if ( $this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total') ) { |
|
| 552 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 553 | 553 | // paid in full |
| 554 | - $this->_template_args['amount_due'] = FALSE; |
|
| 555 | - } elseif ( $this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total') ) { |
|
| 554 | + $this->_template_args['amount_due'] = FALSE; |
|
| 555 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 556 | 556 | // overpaid |
| 557 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 558 | - } elseif (( $this->_transaction->get('TXN_total') > 0 ) && ( $this->_transaction->get('TXN_paid') > 0 )) { |
|
| 557 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 558 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 559 | 559 | // monies owing |
| 560 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 561 | - } elseif (( $this->_transaction->get('TXN_total') > 0 ) && ( $this->_transaction->get('TXN_paid') == 0 )) { |
|
| 560 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 561 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 562 | 562 | // no payments made yet |
| 563 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 564 | - } elseif ( $this->_transaction->get('TXN_total') == 0 ) { |
|
| 563 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 564 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 565 | 565 | // free event |
| 566 | - $this->_template_args['amount_due'] = FALSE; |
|
| 566 | + $this->_template_args['amount_due'] = FALSE; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | $payment_method = $this->_transaction->payment_method(); |
| 570 | 570 | |
| 571 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __( 'Unknown', 'event_espresso' ); |
|
| 571 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso'); |
|
| 572 | 572 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
| 573 | 573 | // link back to overview |
| 574 | - $this->_template_args['txn_overview_url'] = ! empty ( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL; |
|
| 574 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL; |
|
| 575 | 575 | |
| 576 | 576 | |
| 577 | 577 | //next and previous links |
| 578 | - $next_txn = $this->_transaction->next(null, array( array( 'STS_ID' => array( '!=', EEM_Transaction::failed_status_code ) ) ), 'TXN_ID' ); |
|
| 579 | - $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID'] ), TXN_ADMIN_URL ), 'dashicons dashicons-arrow-right ee-icon-size-22' ) : ''; |
|
| 580 | - $previous_txn = $this->_transaction->previous( null, array( array( 'STS_ID' => array( '!=', EEM_Transaction::failed_status_code ) ) ), 'TXN_ID' ); |
|
| 581 | - $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID'] ), TXN_ADMIN_URL ), 'dashicons dashicons-arrow-left ee-icon-size-22' ) : ''; |
|
| 578 | + $next_txn = $this->_transaction->next(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID'); |
|
| 579 | + $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : ''; |
|
| 580 | + $previous_txn = $this->_transaction->previous(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID'); |
|
| 581 | + $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
|
| 582 | 582 | |
| 583 | 583 | |
| 584 | 584 | // grab messages at the last second |
| 585 | 585 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 586 | 586 | // path to template |
| 587 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 588 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE ); |
|
| 587 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 588 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE); |
|
| 589 | 589 | |
| 590 | 590 | // the details template wrapper |
| 591 | 591 | $this->display_admin_page_with_sidebar(); |
@@ -604,18 +604,18 @@ discard block |
||
| 604 | 604 | |
| 605 | 605 | $this->_set_transaction_object(); |
| 606 | 606 | |
| 607 | - add_meta_box( 'edit-txn-details-mbox', __( 'Transaction Details', 'event_espresso' ), array( $this, 'txn_details_meta_box' ), $this->_wp_page_slug, 'normal', 'high' ); |
|
| 607 | + add_meta_box('edit-txn-details-mbox', __('Transaction Details', 'event_espresso'), array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 608 | 608 | add_meta_box( |
| 609 | 609 | 'edit-txn-attendees-mbox', |
| 610 | - __( 'Attendees Registered in this Transaction', 'event_espresso' ), |
|
| 611 | - array( $this, 'txn_attendees_meta_box' ), |
|
| 610 | + __('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 611 | + array($this, 'txn_attendees_meta_box'), |
|
| 612 | 612 | $this->_wp_page_slug, |
| 613 | 613 | 'normal', |
| 614 | 614 | 'high', |
| 615 | - array( 'TXN_ID' => $this->_transaction->ID() ) |
|
| 615 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 616 | 616 | ); |
| 617 | - add_meta_box( 'edit-txn-registrant-mbox', __( 'Primary Contact', 'event_espresso' ), array( $this, 'txn_registrant_side_meta_box' ), $this->_wp_page_slug, 'side', 'high' ); |
|
| 618 | - add_meta_box( 'edit-txn-billing-info-mbox', __( 'Billing Information', 'event_espresso' ), array( $this, 'txn_billing_info_side_meta_box' ), $this->_wp_page_slug, 'side', 'high' ); |
|
| 617 | + add_meta_box('edit-txn-registrant-mbox', __('Primary Contact', 'event_espresso'), array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 618 | + add_meta_box('edit-txn-billing-info-mbox', __('Billing Information', 'event_espresso'), array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 619 | 619 | |
| 620 | 620 | } |
| 621 | 621 | |
@@ -636,15 +636,15 @@ discard block |
||
| 636 | 636 | |
| 637 | 637 | //get line table |
| 638 | 638 | EEH_Autoloader::register_line_item_display_autoloaders(); |
| 639 | - $Line_Item_Display = new EE_Line_Item_Display( 'admin_table', 'EE_Admin_Table_Line_Item_Display_Strategy' ); |
|
| 640 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( $this->_transaction->total_line_item() ); |
|
| 639 | + $Line_Item_Display = new EE_Line_Item_Display('admin_table', 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 640 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 641 | 641 | $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
| 642 | 642 | |
| 643 | 643 | // process taxes |
| 644 | - $taxes = $this->_transaction->get_many_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_tax ))); |
|
| 645 | - $this->_template_args['taxes'] = ! empty( $taxes ) ? $taxes : FALSE; |
|
| 644 | + $taxes = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 645 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : FALSE; |
|
| 646 | 646 | |
| 647 | - $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), FALSE, FALSE ); |
|
| 647 | + $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), FALSE, FALSE); |
|
| 648 | 648 | $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
| 649 | 649 | $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
| 650 | 650 | |
@@ -652,63 +652,63 @@ discard block |
||
| 652 | 652 | |
| 653 | 653 | // process payment details |
| 654 | 654 | $payments = $this->_transaction->get_many_related('Payment'); |
| 655 | - if( ! empty( $payments ) ) { |
|
| 656 | - $this->_template_args[ 'payments' ] = $payments; |
|
| 657 | - $this->_template_args[ 'existing_reg_payments' ] = $this->_get_registration_payment_IDs( $payments ); |
|
| 655 | + if ( ! empty($payments)) { |
|
| 656 | + $this->_template_args['payments'] = $payments; |
|
| 657 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 658 | 658 | } else { |
| 659 | - $this->_template_args[ 'payments' ] = false; |
|
| 660 | - $this->_template_args[ 'existing_reg_payments' ] = array(); |
|
| 659 | + $this->_template_args['payments'] = false; |
|
| 660 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - $this->_template_args['edit_payment_url'] = add_query_arg( array( 'action' => 'edit_payment' ), TXN_ADMIN_URL ); |
|
| 664 | - $this->_template_args['delete_payment_url'] = add_query_arg( array( 'action' => 'espresso_delete_payment' ), TXN_ADMIN_URL ); |
|
| 663 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 664 | + $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), TXN_ADMIN_URL); |
|
| 665 | 665 | |
| 666 | - if ( isset( $txn_details['invoice_number'] )) { |
|
| 666 | + if (isset($txn_details['invoice_number'])) { |
|
| 667 | 667 | $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
| 668 | - $this->_template_args['txn_details']['invoice_number']['label'] = __( 'Invoice Number', 'event_espresso' ); |
|
| 668 | + $this->_template_args['txn_details']['invoice_number']['label'] = __('Invoice Number', 'event_espresso'); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
| 672 | - $this->_template_args['txn_details']['registration_session']['label'] = __( 'Registration Session', 'event_espresso' ); |
|
| 672 | + $this->_template_args['txn_details']['registration_session']['label'] = __('Registration Session', 'event_espresso'); |
|
| 673 | 673 | |
| 674 | - $this->_template_args['txn_details']['ip_address']['value'] = isset( $this->_session['ip_address'] ) ? $this->_session['ip_address'] : ''; |
|
| 675 | - $this->_template_args['txn_details']['ip_address']['label'] = __( 'Transaction placed from IP', 'event_espresso' ); |
|
| 674 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 675 | + $this->_template_args['txn_details']['ip_address']['label'] = __('Transaction placed from IP', 'event_espresso'); |
|
| 676 | 676 | |
| 677 | - $this->_template_args['txn_details']['user_agent']['value'] = isset( $this->_session['user_agent'] ) ? $this->_session['user_agent'] : ''; |
|
| 678 | - $this->_template_args['txn_details']['user_agent']['label'] = __( 'Registrant User Agent', 'event_espresso' ); |
|
| 677 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 678 | + $this->_template_args['txn_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso'); |
|
| 679 | 679 | |
| 680 | 680 | $reg_steps = '<ul>'; |
| 681 | - foreach ( $this->_transaction->reg_steps() as $reg_step => $reg_step_status ) { |
|
| 682 | - if ( $reg_step_status === true ) { |
|
| 683 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf( __( '%1$s : Completed', 'event_espresso' ), ucwords( str_replace( '_', ' ', $reg_step ) ) ) . '</li>'; |
|
| 684 | - } else if ( is_numeric( $reg_step_status ) && $reg_step_status !== false ) { |
|
| 685 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 686 | - __( '%1$s : Initiated %2$s', 'event_espresso' ), |
|
| 687 | - ucwords( str_replace( '_', ' ', $reg_step ) ), |
|
| 688 | - gmdate( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), ( $reg_step_status + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ) |
|
| 689 | - ) . '</li>'; |
|
| 681 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 682 | + if ($reg_step_status === true) { |
|
| 683 | + $reg_steps .= '<li style="color:#70cc50">'.sprintf(__('%1$s : Completed', 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 684 | + } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 685 | + $reg_steps .= '<li style="color:#2EA2CC">'.sprintf( |
|
| 686 | + __('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 687 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 688 | + gmdate(get_option('date_format').' '.get_option('time_format'), ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 689 | + ).'</li>'; |
|
| 690 | 690 | } else { |
| 691 | - $reg_steps .= '<li style="color:#E76700">' . sprintf( __( '%1$s : Never Initiated', 'event_espresso' ), ucwords( str_replace( '_', ' ', $reg_step ) ) ) . '</li>'; |
|
| 691 | + $reg_steps .= '<li style="color:#E76700">'.sprintf(__('%1$s : Never Initiated', 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 692 | 692 | } |
| 693 | 693 | } |
| 694 | 694 | $reg_steps .= '</ul>'; |
| 695 | 695 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
| 696 | - $this->_template_args['txn_details']['reg_steps']['label'] = __( 'Registration Step Progress', 'event_espresso' ); |
|
| 696 | + $this->_template_args['txn_details']['reg_steps']['label'] = __('Registration Step Progress', 'event_espresso'); |
|
| 697 | 697 | |
| 698 | 698 | |
| 699 | 699 | $this->_get_registrations_to_apply_payment_to(); |
| 700 | - $this->_get_payment_methods( $payments ); |
|
| 700 | + $this->_get_payment_methods($payments); |
|
| 701 | 701 | $this->_get_payment_status_array(); |
| 702 | 702 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
| 703 | 703 | |
| 704 | - $this->_template_args['transaction_form_url'] = add_query_arg( array( 'action' => 'edit_transaction', 'process' => 'transaction' ), TXN_ADMIN_URL ); |
|
| 705 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( array( 'page' => 'espresso_transactions', 'action' => 'espresso_apply_payment' ), WP_AJAX_URL ); |
|
| 706 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( array( 'page' => 'espresso_transactions', 'action' => 'espresso_delete_payment' ), WP_AJAX_URL ); |
|
| 704 | + $this->_template_args['transaction_form_url'] = add_query_arg(array('action' => 'edit_transaction', 'process' => 'transaction'), TXN_ADMIN_URL); |
|
| 705 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array('page' => 'espresso_transactions', 'action' => 'espresso_apply_payment'), WP_AJAX_URL); |
|
| 706 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array('page' => 'espresso_transactions', 'action' => 'espresso_delete_payment'), WP_AJAX_URL); |
|
| 707 | 707 | |
| 708 | 708 | // 'espresso_delete_payment_nonce' |
| 709 | 709 | |
| 710 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 711 | - echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE ); |
|
| 710 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 711 | + echo EEH_Template::display_template($template_path, $this->_template_args, TRUE); |
|
| 712 | 712 | |
| 713 | 713 | } |
| 714 | 714 | |
@@ -723,27 +723,27 @@ discard block |
||
| 723 | 723 | * @param EE_Payment[] $payments |
| 724 | 724 | * @return array |
| 725 | 725 | */ |
| 726 | - protected function _get_registration_payment_IDs( $payments = array() ) { |
|
| 726 | + protected function _get_registration_payment_IDs($payments = array()) { |
|
| 727 | 727 | $existing_reg_payments = array(); |
| 728 | 728 | // get all reg payments for these payments |
| 729 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( array( |
|
| 729 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 730 | 730 | array( |
| 731 | 731 | 'PAY_ID' => array( |
| 732 | 732 | 'IN', |
| 733 | - array_keys( $payments ) |
|
| 733 | + array_keys($payments) |
|
| 734 | 734 | ) |
| 735 | 735 | ) |
| 736 | - ) ); |
|
| 737 | - if ( ! empty( $reg_payments ) ) { |
|
| 738 | - foreach ( $payments as $payment ) { |
|
| 739 | - if ( ! $payment instanceof EE_Payment ) { |
|
| 736 | + )); |
|
| 737 | + if ( ! empty($reg_payments)) { |
|
| 738 | + foreach ($payments as $payment) { |
|
| 739 | + if ( ! $payment instanceof EE_Payment) { |
|
| 740 | 740 | continue; |
| 741 | - } else if ( ! isset( $existing_reg_payments[ $payment->ID() ] ) ) { |
|
| 742 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 741 | + } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 742 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 743 | 743 | } |
| 744 | - foreach ( $reg_payments as $reg_payment ) { |
|
| 745 | - if ( $reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID() ) { |
|
| 746 | - $existing_reg_payments[ $payment->ID() ][ ] = $reg_payment->registration_ID(); |
|
| 744 | + foreach ($reg_payments as $reg_payment) { |
|
| 745 | + if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 746 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 747 | 747 | } |
| 748 | 748 | } |
| 749 | 749 | } |
@@ -780,39 +780,39 @@ discard block |
||
| 780 | 780 | $registrations_to_apply_payment_to .= '<br /><div class="admin-primary-mbox-tbl-wrap">'; |
| 781 | 781 | $registrations_to_apply_payment_to .= '<table class="admin-primary-mbox-tbl">'; |
| 782 | 782 | $registrations_to_apply_payment_to .= '<thead><tr>'; |
| 783 | - $registrations_to_apply_payment_to .= '<td>' . __( 'ID', 'event_espresso' ) . '</td>'; |
|
| 784 | - $registrations_to_apply_payment_to .= '<td>' . __( 'Registrant', 'event_espresso' ) . '</td>'; |
|
| 785 | - $registrations_to_apply_payment_to .= '<td>' . __( 'Ticket', 'event_espresso' ) . '</td>'; |
|
| 786 | - $registrations_to_apply_payment_to .= '<td>' . __( 'Event', 'event_espresso' ) . '</td>'; |
|
| 787 | - $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-cntr">' . __( 'Paid', 'event_espresso' ) . '</td>'; |
|
| 788 | - $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-cntr">' . __( 'Owing', 'event_espresso' ) . '</td>'; |
|
| 789 | - $registrations_to_apply_payment_to .= '<td class="jst-cntr">' . __( 'Apply', 'event_espresso' ) . '</td>'; |
|
| 783 | + $registrations_to_apply_payment_to .= '<td>'.__('ID', 'event_espresso').'</td>'; |
|
| 784 | + $registrations_to_apply_payment_to .= '<td>'.__('Registrant', 'event_espresso').'</td>'; |
|
| 785 | + $registrations_to_apply_payment_to .= '<td>'.__('Ticket', 'event_espresso').'</td>'; |
|
| 786 | + $registrations_to_apply_payment_to .= '<td>'.__('Event', 'event_espresso').'</td>'; |
|
| 787 | + $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-cntr">'.__('Paid', 'event_espresso').'</td>'; |
|
| 788 | + $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-cntr">'.__('Owing', 'event_espresso').'</td>'; |
|
| 789 | + $registrations_to_apply_payment_to .= '<td class="jst-cntr">'.__('Apply', 'event_espresso').'</td>'; |
|
| 790 | 790 | $registrations_to_apply_payment_to .= '</tr></thead><tbody>'; |
| 791 | 791 | // get registrations for TXN |
| 792 | - $registrations = $this->_transaction->registrations( $query_params ); |
|
| 793 | - foreach ( $registrations as $registration ) { |
|
| 794 | - if ( $registration instanceof EE_Registration ) { |
|
| 792 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 793 | + foreach ($registrations as $registration) { |
|
| 794 | + if ($registration instanceof EE_Registration) { |
|
| 795 | 795 | $owing = $registration->final_price() - $registration->paid(); |
| 796 | - $taxable = $registration->ticket()->taxable() ? ' <span class="smaller-text lt-grey-text"> ' . __( '+ tax', 'event_espresso' ) . '</span>' : ''; |
|
| 797 | - $checked = empty( $existing_reg_payments ) || in_array( $registration->ID(), $existing_reg_payments ) ? ' checked="checked"' : ''; |
|
| 798 | - $registrations_to_apply_payment_to .= '<tr id="apply-payment-registration-row-' . $registration->ID() . '">'; |
|
| 796 | + $taxable = $registration->ticket()->taxable() ? ' <span class="smaller-text lt-grey-text"> '.__('+ tax', 'event_espresso').'</span>' : ''; |
|
| 797 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) ? ' checked="checked"' : ''; |
|
| 798 | + $registrations_to_apply_payment_to .= '<tr id="apply-payment-registration-row-'.$registration->ID().'">'; |
|
| 799 | 799 | // add html for checkbox input and label |
| 800 | - $registrations_to_apply_payment_to .= '<td>' . $registration->ID() . '</td>'; |
|
| 801 | - $registrations_to_apply_payment_to .= '<td>' . $registration->attendee() instanceof EE_Attendee ? $registration->attendee()->full_name() : __( 'Unknown Attendee', 'event_espresso' ) . '</td>'; |
|
| 802 | - $registrations_to_apply_payment_to .= '<td>' . $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable . '</td>'; |
|
| 803 | - $registrations_to_apply_payment_to .= '<td>' . $registration->event_name() . '</td>'; |
|
| 804 | - $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-rght">' . $registration->pretty_paid() . '</td>'; |
|
| 805 | - $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-rght">' . EEH_Template::format_currency( $owing ) . '</td>'; |
|
| 800 | + $registrations_to_apply_payment_to .= '<td>'.$registration->ID().'</td>'; |
|
| 801 | + $registrations_to_apply_payment_to .= '<td>'.$registration->attendee() instanceof EE_Attendee ? $registration->attendee()->full_name() : __('Unknown Attendee', 'event_espresso').'</td>'; |
|
| 802 | + $registrations_to_apply_payment_to .= '<td>'.$registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable.'</td>'; |
|
| 803 | + $registrations_to_apply_payment_to .= '<td>'.$registration->event_name().'</td>'; |
|
| 804 | + $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-rght">'.$registration->pretty_paid().'</td>'; |
|
| 805 | + $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-rght">'.EEH_Template::format_currency($owing).'</td>'; |
|
| 806 | 806 | $registrations_to_apply_payment_to .= '<td class="jst-cntr">'; |
| 807 | 807 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
| 808 | - $registrations_to_apply_payment_to .= '<input type="checkbox" value="' . $registration->ID() . '" name="txn_admin_payment[registrations]"' . $checked . $disabled . '>'; |
|
| 808 | + $registrations_to_apply_payment_to .= '<input type="checkbox" value="'.$registration->ID().'" name="txn_admin_payment[registrations]"'.$checked.$disabled.'>'; |
|
| 809 | 809 | $registrations_to_apply_payment_to .= '</td>'; |
| 810 | 810 | $registrations_to_apply_payment_to .= '</tr>'; |
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | $registrations_to_apply_payment_to .= '</tbody></table></div>'; |
| 814 | - $registrations_to_apply_payment_to .= '<p class="clear description">' . __( 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', 'event_espresso' ) . '</p></div>'; |
|
| 815 | - $this->_template_args[ 'registrations_to_apply_payment_to' ] = $registrations_to_apply_payment_to; |
|
| 814 | + $registrations_to_apply_payment_to .= '<p class="clear description">'.__('The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', 'event_espresso').'</p></div>'; |
|
| 815 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -829,9 +829,9 @@ discard block |
||
| 829 | 829 | $statuses = EEM_Registration::reg_status_array(array(), TRUE); |
| 830 | 830 | //let's add a "don't change" option. |
| 831 | 831 | $status_array['NAN'] = __('Leave the Same', 'event_espresso'); |
| 832 | - $status_array = array_merge( $status_array, $statuses ); |
|
| 833 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( 'txn_reg_status_change[reg_status]', $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status' ); |
|
| 834 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( 'delete_txn_reg_status_change[reg_status]', $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status' ); |
|
| 832 | + $status_array = array_merge($status_array, $statuses); |
|
| 833 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 834 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 835 | 835 | |
| 836 | 836 | } |
| 837 | 837 | |
@@ -846,21 +846,21 @@ discard block |
||
| 846 | 846 | * @param EE_Payment[] to show on this page |
| 847 | 847 | * @return void |
| 848 | 848 | */ |
| 849 | - private function _get_payment_methods( $payments = array() ) { |
|
| 849 | + private function _get_payment_methods($payments = array()) { |
|
| 850 | 850 | $payment_methods_of_payments = array(); |
| 851 | - foreach( $payments as $payment ){ |
|
| 852 | - if( $payment instanceof EE_Payment ){ |
|
| 853 | - $payment_methods_of_payments[] = $payment->get( 'PMD_ID' ); |
|
| 851 | + foreach ($payments as $payment) { |
|
| 852 | + if ($payment instanceof EE_Payment) { |
|
| 853 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | - if( $payment_methods_of_payments ){ |
|
| 857 | - $query_args = array( array( 'OR*payment_method_for_payment' => array( |
|
| 858 | - 'PMD_ID' => array( 'IN', $payment_methods_of_payments ), |
|
| 859 | - 'PMD_scope' => array( 'LIKE', '%' . EEM_Payment_Method::scope_admin . '%' ) ) ) ); |
|
| 860 | - }else{ |
|
| 861 | - $query_args = array( array( 'PMD_scope' => array( 'LIKE', '%' . EEM_Payment_Method::scope_admin . '%' ) ) ); |
|
| 856 | + if ($payment_methods_of_payments) { |
|
| 857 | + $query_args = array(array('OR*payment_method_for_payment' => array( |
|
| 858 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 859 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%') ))); |
|
| 860 | + } else { |
|
| 861 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 862 | 862 | } |
| 863 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all( $query_args ); |
|
| 863 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | |
@@ -874,46 +874,46 @@ discard block |
||
| 874 | 874 | * @param array $metabox |
| 875 | 875 | * @return void |
| 876 | 876 | */ |
| 877 | - public function txn_attendees_meta_box( $post, $metabox = array( 'args' => array() )) { |
|
| 877 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) { |
|
| 878 | 878 | |
| 879 | - extract( $metabox['args'] ); |
|
| 879 | + extract($metabox['args']); |
|
| 880 | 880 | $this->_template_args['post'] = $post; |
| 881 | 881 | $this->_template_args['event_attendees'] = array(); |
| 882 | 882 | // process items in cart |
| 883 | - $line_items = $this->_transaction->get_many_related('Line_Item', array( array( 'LIN_type' => 'line-item' ) ) ); |
|
| 884 | - if ( ! empty( $line_items )) { |
|
| 885 | - foreach ( $line_items as $item ) { |
|
| 886 | - if ( $item instanceof EE_Line_Item ) { |
|
| 887 | - switch( $item->OBJ_type() ) { |
|
| 883 | + $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 884 | + if ( ! empty($line_items)) { |
|
| 885 | + foreach ($line_items as $item) { |
|
| 886 | + if ($item instanceof EE_Line_Item) { |
|
| 887 | + switch ($item->OBJ_type()) { |
|
| 888 | 888 | |
| 889 | 889 | case 'Event' : |
| 890 | 890 | break; |
| 891 | 891 | |
| 892 | 892 | case 'Ticket' : |
| 893 | 893 | $ticket = $item->ticket(); |
| 894 | - if ( empty( $ticket )) { |
|
| 894 | + if (empty($ticket)) { |
|
| 895 | 895 | continue; //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
| 896 | 896 | } |
| 897 | - $ticket_price = EEH_Template::format_currency( $item->get( 'LIN_unit_price' )); |
|
| 897 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 898 | 898 | $event = $ticket->get_first_related('Registration')->get_first_related('Event'); |
| 899 | - $event_name = $event instanceof EE_Event ? $event->get('EVT_name') . ' - ' . $item->get('LIN_name') : ''; |
|
| 899 | + $event_name = $event instanceof EE_Event ? $event->get('EVT_name').' - '.$item->get('LIN_name') : ''; |
|
| 900 | 900 | |
| 901 | - $registrations = $ticket->get_many_related('Registration', array( array('TXN_ID' => $this->_transaction->ID() ))); |
|
| 902 | - foreach( $registrations as $registration ) { |
|
| 903 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->get('REG_count'); |
|
| 904 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 905 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 901 | + $registrations = $ticket->get_many_related('Registration', array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 902 | + foreach ($registrations as $registration) { |
|
| 903 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->get('REG_count'); |
|
| 904 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 905 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 906 | 906 | // attendee info |
| 907 | 907 | $attendee = $registration->get_first_related('Attendee'); |
| 908 | - if ( $attendee instanceof EE_Attendee ) { |
|
| 908 | + if ($attendee instanceof EE_Attendee) { |
|
| 909 | 909 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
| 910 | 910 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
| 911 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event->get('EVT_name') . __(' Event', 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 912 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = implode(',<br>', $attendee->full_address_as_array() ); |
|
| 911 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:'.$attendee->email().'?subject='.$event->get('EVT_name').__(' Event', 'event_espresso').'">'.$attendee->email().'</a>'; |
|
| 912 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = implode(',<br>', $attendee->full_address_as_array()); |
|
| 913 | 913 | } else { |
| 914 | 914 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
| 915 | 915 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
| 916 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 916 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 917 | 917 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
| 918 | 918 | } |
| 919 | 919 | } |
@@ -923,12 +923,12 @@ discard block |
||
| 923 | 923 | } |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | - $this->_template_args['transaction_form_url'] = add_query_arg( array( 'action' => 'edit_transaction', 'process' => 'attendees' ), TXN_ADMIN_URL ); |
|
| 927 | - echo EEH_Template::display_template( TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', $this->_template_args, TRUE ); |
|
| 926 | + $this->_template_args['transaction_form_url'] = add_query_arg(array('action' => 'edit_transaction', 'process' => 'attendees'), TXN_ADMIN_URL); |
|
| 927 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', $this->_template_args, TRUE); |
|
| 928 | 928 | |
| 929 | 929 | } else { |
| 930 | 930 | echo sprintf( |
| 931 | - __( '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', 'event_espresso' ), |
|
| 931 | + __('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', 'event_espresso'), |
|
| 932 | 932 | '<p class="important-notice">', |
| 933 | 933 | '</p>' |
| 934 | 934 | ); |
@@ -947,20 +947,20 @@ discard block |
||
| 947 | 947 | */ |
| 948 | 948 | public function txn_registrant_side_meta_box() { |
| 949 | 949 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
| 950 | - if ( ! $primary_att instanceof EE_Attendee ) { |
|
| 950 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 951 | 951 | $this->_template_args['no_attendee_message'] = __('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', 'event_espresso'); |
| 952 | 952 | $primary_att = EEM_Attendee::instance()->create_default_object(); |
| 953 | 953 | } |
| 954 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 954 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 955 | 955 | $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
| 956 | 956 | $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
| 957 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 957 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 958 | 958 | $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
| 959 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'edit_attendee', 'post' => $primary_att->ID() ), REG_ADMIN_URL ); |
|
| 959 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_attendee', 'post' => $primary_att->ID()), REG_ADMIN_URL); |
|
| 960 | 960 | // get formatted address for registrant |
| 961 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 962 | - $this->_template_args[ 'formatted_address' ] = EEH_Address::format( $primary_att ); |
|
| 963 | - echo EEH_Template::display_template( TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', $this->_template_args, TRUE ); |
|
| 961 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 962 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 963 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', $this->_template_args, TRUE); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | |
@@ -976,12 +976,12 @@ discard block |
||
| 976 | 976 | |
| 977 | 977 | $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
| 978 | 978 | $this->_template_args['billing_form_url'] = add_query_arg( |
| 979 | - array( 'action' => 'edit_transaction', 'process' => 'billing' ), |
|
| 979 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 980 | 980 | TXN_ADMIN_URL |
| 981 | 981 | ); |
| 982 | 982 | |
| 983 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 984 | - echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );/**/ |
|
| 983 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 984 | + echo EEH_Template::display_template($template_path, $this->_template_args, TRUE); /**/ |
|
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | |
@@ -994,43 +994,43 @@ discard block |
||
| 994 | 994 | * @return void |
| 995 | 995 | */ |
| 996 | 996 | public function apply_payments_or_refunds() { |
| 997 | - $json_response_data = array( 'return_data' => FALSE ); |
|
| 997 | + $json_response_data = array('return_data' => FALSE); |
|
| 998 | 998 | $valid_data = $this->_validate_payment_request_data(); |
| 999 | - if ( ! empty( $valid_data ) ) { |
|
| 1000 | - $PAY_ID = $valid_data[ 'PAY_ID' ]; |
|
| 999 | + if ( ! empty($valid_data)) { |
|
| 1000 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1001 | 1001 | //save the new payment |
| 1002 | - $payment = $this->_create_payment_from_request_data( $valid_data ); |
|
| 1002 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1003 | 1003 | // get the TXN for this payment |
| 1004 | 1004 | $transaction = $payment->transaction(); |
| 1005 | 1005 | // verify transaction |
| 1006 | - if ( $transaction instanceof EE_Transaction ) { |
|
| 1006 | + if ($transaction instanceof EE_Transaction) { |
|
| 1007 | 1007 | // calculate_total_payments_and_update_status |
| 1008 | - $this->_process_transaction_payments( $transaction ); |
|
| 1009 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to( $payment ); |
|
| 1010 | - $this->_remove_existing_registration_payments( $payment, $PAY_ID ); |
|
| 1008 | + $this->_process_transaction_payments($transaction); |
|
| 1009 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1010 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1011 | 1011 | // apply payment to registrations (if applicable) |
| 1012 | - if ( ! empty( $REG_IDs ) ) { |
|
| 1013 | - $this->_update_registration_payments( $transaction, $payment, $REG_IDs ); |
|
| 1012 | + if ( ! empty($REG_IDs)) { |
|
| 1013 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1014 | 1014 | $this->_maybe_send_notifications(); |
| 1015 | 1015 | // now process status changes for the same registrations |
| 1016 | - $this->_process_registration_status_change( $transaction, $REG_IDs ); |
|
| 1016 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1017 | 1017 | } |
| 1018 | - $this->_maybe_send_notifications( $payment ); |
|
| 1018 | + $this->_maybe_send_notifications($payment); |
|
| 1019 | 1019 | //prepare to render page |
| 1020 | - $json_response_data[ 'return_data' ] = $this->_build_payment_json_response( $payment, $REG_IDs ); |
|
| 1021 | - do_action( 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, $payment ); |
|
| 1020 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1021 | + do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, $payment); |
|
| 1022 | 1022 | } else { |
| 1023 | 1023 | EE_Error::add_error( |
| 1024 | - __( 'A valid Transaction for this payment could not be retrieved.', 'event_espresso' ), |
|
| 1024 | + __('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1025 | 1025 | __FILE__, __FUNCTION__, __LINE__ |
| 1026 | 1026 | ); |
| 1027 | 1027 | } |
| 1028 | 1028 | } else { |
| 1029 | - EE_Error::add_error( __( 'The payment form data could not be processed. Please try again.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1029 | + EE_Error::add_error(__('The payment form data could not be processed. Please try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | - $notices = EE_Error::get_notices( FALSE, FALSE, FALSE ); |
|
| 1033 | - echo json_encode( array_merge( $json_response_data, $notices )); |
|
| 1032 | + $notices = EE_Error::get_notices(FALSE, FALSE, FALSE); |
|
| 1033 | + echo json_encode(array_merge($json_response_data, $notices)); |
|
| 1034 | 1034 | die(); |
| 1035 | 1035 | } |
| 1036 | 1036 | |
@@ -1042,30 +1042,30 @@ discard block |
||
| 1042 | 1042 | * @return array |
| 1043 | 1043 | */ |
| 1044 | 1044 | protected function _validate_payment_request_data() { |
| 1045 | - if ( ! isset( $this->_req_data[ 'txn_admin_payment' ] ) ) { |
|
| 1045 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1046 | 1046 | return false; |
| 1047 | 1047 | } |
| 1048 | 1048 | $payment_form = $this->_generate_payment_form_section(); |
| 1049 | 1049 | try { |
| 1050 | - if ( $payment_form->was_submitted() ) { |
|
| 1050 | + if ($payment_form->was_submitted()) { |
|
| 1051 | 1051 | $payment_form->receive_form_submission(); |
| 1052 | - if ( ! $payment_form->is_valid() ) { |
|
| 1052 | + if ( ! $payment_form->is_valid()) { |
|
| 1053 | 1053 | $submission_error_messages = array(); |
| 1054 | - foreach ( $payment_form->get_validation_errors_accumulated() as $validation_error ) { |
|
| 1055 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
| 1054 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1055 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1056 | 1056 | $submission_error_messages[] = sprintf( |
| 1057 | - _x( '%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso' ), |
|
| 1057 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1058 | 1058 | $validation_error->get_form_section()->html_label_text(), |
| 1059 | 1059 | $validation_error->getMessage() |
| 1060 | 1060 | ); |
| 1061 | 1061 | } |
| 1062 | 1062 | } |
| 1063 | - EE_Error::add_error( join( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1063 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1064 | 1064 | return array(); |
| 1065 | 1065 | } |
| 1066 | 1066 | } |
| 1067 | - } catch ( EE_Error $e ) { |
|
| 1068 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1067 | + } catch (EE_Error $e) { |
|
| 1068 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1069 | 1069 | return array(); |
| 1070 | 1070 | } |
| 1071 | 1071 | return $payment_form->valid_data(); |
@@ -1087,63 +1087,63 @@ discard block |
||
| 1087 | 1087 | array( |
| 1088 | 1088 | 'default' => 0, |
| 1089 | 1089 | 'required' => false, |
| 1090 | - 'html_label_text' => __( 'Payment ID', 'event_espresso' ), |
|
| 1091 | - 'validation_strategies' => array( new EE_Int_Normalization() ) |
|
| 1090 | + 'html_label_text' => __('Payment ID', 'event_espresso'), |
|
| 1091 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1092 | 1092 | ) |
| 1093 | 1093 | ), |
| 1094 | 1094 | 'TXN_ID' => new EE_Text_Input( |
| 1095 | 1095 | array( |
| 1096 | 1096 | 'default' => 0, |
| 1097 | 1097 | 'required' => true, |
| 1098 | - 'html_label_text' => __( 'Transaction ID', 'event_espresso' ), |
|
| 1099 | - 'validation_strategies' => array( new EE_Int_Normalization() ) |
|
| 1098 | + 'html_label_text' => __('Transaction ID', 'event_espresso'), |
|
| 1099 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1100 | 1100 | ) |
| 1101 | 1101 | ), |
| 1102 | 1102 | 'type' => new EE_Text_Input( |
| 1103 | 1103 | array( |
| 1104 | 1104 | 'default' => 1, |
| 1105 | 1105 | 'required' => true, |
| 1106 | - 'html_label_text' => __( 'Payment or Refund', 'event_espresso' ), |
|
| 1107 | - 'validation_strategies' => array( new EE_Int_Normalization() ) |
|
| 1106 | + 'html_label_text' => __('Payment or Refund', 'event_espresso'), |
|
| 1107 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1108 | 1108 | ) |
| 1109 | 1109 | ), |
| 1110 | 1110 | 'amount' => new EE_Text_Input( |
| 1111 | 1111 | array( |
| 1112 | 1112 | 'default' => 0, |
| 1113 | 1113 | 'required' => true, |
| 1114 | - 'html_label_text' => __( 'Payment amount', 'event_espresso' ), |
|
| 1115 | - 'validation_strategies' => array( new EE_Float_Normalization() ) |
|
| 1114 | + 'html_label_text' => __('Payment amount', 'event_espresso'), |
|
| 1115 | + 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1116 | 1116 | ) |
| 1117 | 1117 | ), |
| 1118 | 1118 | 'status' => new EE_Text_Input( |
| 1119 | 1119 | array( |
| 1120 | 1120 | 'default' => EEM_Payment::status_id_approved, |
| 1121 | 1121 | 'required' => true, |
| 1122 | - 'html_label_text' => __( 'Payment status', 'event_espresso' ), |
|
| 1122 | + 'html_label_text' => __('Payment status', 'event_espresso'), |
|
| 1123 | 1123 | ) |
| 1124 | 1124 | ), |
| 1125 | 1125 | 'PMD_ID' => new EE_Text_Input( |
| 1126 | 1126 | array( |
| 1127 | 1127 | 'default' => 2, |
| 1128 | 1128 | 'required' => true, |
| 1129 | - 'html_label_text' => __( 'Payment Method', 'event_espresso' ), |
|
| 1130 | - 'validation_strategies' => array( new EE_Int_Normalization() ) |
|
| 1129 | + 'html_label_text' => __('Payment Method', 'event_espresso'), |
|
| 1130 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1131 | 1131 | ) |
| 1132 | 1132 | ), |
| 1133 | 1133 | 'date' => new EE_Text_Input( |
| 1134 | 1134 | array( |
| 1135 | 1135 | 'default' => time(), |
| 1136 | 1136 | 'required' => true, |
| 1137 | - 'html_label_text' => __( 'Payment date', 'event_espresso' ), |
|
| 1137 | + 'html_label_text' => __('Payment date', 'event_espresso'), |
|
| 1138 | 1138 | ) |
| 1139 | 1139 | ), |
| 1140 | 1140 | 'txn_id_chq_nmbr' => new EE_Text_Input( |
| 1141 | 1141 | array( |
| 1142 | 1142 | 'default' => '', |
| 1143 | 1143 | 'required' => false, |
| 1144 | - 'html_label_text' => __( 'Transaction or Cheque Number', 'event_espresso' ), |
|
| 1144 | + 'html_label_text' => __('Transaction or Cheque Number', 'event_espresso'), |
|
| 1145 | 1145 | 'validation_strategies' => array( |
| 1146 | - new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
|
| 1146 | + new EE_Max_Length_Validation_Strategy(__('Input too long', 'event_espresso'), 100), |
|
| 1147 | 1147 | ) |
| 1148 | 1148 | ) |
| 1149 | 1149 | ), |
@@ -1151,9 +1151,9 @@ discard block |
||
| 1151 | 1151 | array( |
| 1152 | 1152 | 'default' => '', |
| 1153 | 1153 | 'required' => false, |
| 1154 | - 'html_label_text' => __( 'Purchase Order Number', 'event_espresso' ), |
|
| 1154 | + 'html_label_text' => __('Purchase Order Number', 'event_espresso'), |
|
| 1155 | 1155 | 'validation_strategies' => array( |
| 1156 | - new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
|
| 1156 | + new EE_Max_Length_Validation_Strategy(__('Input too long', 'event_espresso'), 100), |
|
| 1157 | 1157 | ) |
| 1158 | 1158 | ) |
| 1159 | 1159 | ), |
@@ -1161,9 +1161,9 @@ discard block |
||
| 1161 | 1161 | array( |
| 1162 | 1162 | 'default' => '', |
| 1163 | 1163 | 'required' => false, |
| 1164 | - 'html_label_text' => __( 'Extra Field for Accounting', 'event_espresso' ), |
|
| 1164 | + 'html_label_text' => __('Extra Field for Accounting', 'event_espresso'), |
|
| 1165 | 1165 | 'validation_strategies' => array( |
| 1166 | - new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
|
| 1166 | + new EE_Max_Length_Validation_Strategy(__('Input too long', 'event_espresso'), 100), |
|
| 1167 | 1167 | ) |
| 1168 | 1168 | ) |
| 1169 | 1169 | ), |
@@ -1180,34 +1180,34 @@ discard block |
||
| 1180 | 1180 | * @param array $valid_data |
| 1181 | 1181 | * @return EE_Payment |
| 1182 | 1182 | */ |
| 1183 | - protected function _create_payment_from_request_data( $valid_data ) { |
|
| 1184 | - $PAY_ID = $valid_data[ 'PAY_ID' ]; |
|
| 1183 | + protected function _create_payment_from_request_data($valid_data) { |
|
| 1184 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1185 | 1185 | // get payment amount |
| 1186 | - $amount = $valid_data[ 'amount' ] ? abs( $valid_data[ 'amount' ] ) : 0; |
|
| 1186 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1187 | 1187 | // payments have a type value of 1 and refunds have a type value of -1 |
| 1188 | 1188 | // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
| 1189 | - $amount = $valid_data[ 'type' ] < 0 ? $amount * -1 : $amount; |
|
| 1189 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1190 | 1190 | $payment = EE_Payment::new_instance( |
| 1191 | 1191 | array( |
| 1192 | - 'TXN_ID' => $valid_data[ 'TXN_ID' ], |
|
| 1193 | - 'STS_ID' => $valid_data[ 'status' ], |
|
| 1194 | - 'PAY_timestamp' => $valid_data[ 'date' ], |
|
| 1192 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1193 | + 'STS_ID' => $valid_data['status'], |
|
| 1194 | + 'PAY_timestamp' => $valid_data['date'], |
|
| 1195 | 1195 | 'PAY_source' => EEM_Payment_Method::scope_admin, |
| 1196 | - 'PMD_ID' => $valid_data[ 'PMD_ID' ], |
|
| 1196 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1197 | 1197 | 'PAY_amount' => $amount, |
| 1198 | - 'PAY_txn_id_chq_nmbr' => $valid_data[ 'txn_id_chq_nmbr' ], |
|
| 1199 | - 'PAY_po_number' => $valid_data[ 'po_number' ], |
|
| 1200 | - 'PAY_extra_accntng' => $valid_data[ 'accounting' ], |
|
| 1198 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1199 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1200 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1201 | 1201 | 'PAY_details' => $valid_data, |
| 1202 | 1202 | 'PAY_ID' => $PAY_ID |
| 1203 | 1203 | ), |
| 1204 | 1204 | '', |
| 1205 | - array( 'Y-m-d', 'H:i a' ) |
|
| 1205 | + array('Y-m-d', 'H:i a') |
|
| 1206 | 1206 | ); |
| 1207 | - if ( ! $payment->save() ) { |
|
| 1207 | + if ( ! $payment->save()) { |
|
| 1208 | 1208 | EE_Error::add_error( |
| 1209 | 1209 | sprintf( |
| 1210 | - __( 'Payment %1$d has not been successfully saved to the database.', 'event_espresso' ), |
|
| 1210 | + __('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1211 | 1211 | $payment->ID() |
| 1212 | 1212 | ), |
| 1213 | 1213 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1224,15 +1224,15 @@ discard block |
||
| 1224 | 1224 | * @param \EE_Transaction $transaction |
| 1225 | 1225 | * @return array |
| 1226 | 1226 | */ |
| 1227 | - protected function _process_transaction_payments( EE_Transaction $transaction ) { |
|
| 1227 | + protected function _process_transaction_payments(EE_Transaction $transaction) { |
|
| 1228 | 1228 | /** @type EE_Transaction_Payments $transaction_payments */ |
| 1229 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
| 1229 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1230 | 1230 | //update the transaction with this payment |
| 1231 | - if ( $transaction_payments->calculate_total_payments_and_update_status( $transaction ) ) { |
|
| 1232 | - EE_Error::add_success( __( 'The payment has been processed successfully.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1231 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1232 | + EE_Error::add_success(__('The payment has been processed successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1233 | 1233 | } else { |
| 1234 | 1234 | EE_Error::add_error( |
| 1235 | - __( 'The payment was processed successfully but the amount paid for the transaction was not updated.', 'event_espresso' ) |
|
| 1235 | + __('The payment was processed successfully but the amount paid for the transaction was not updated.', 'event_espresso') |
|
| 1236 | 1236 | , __FILE__, __FUNCTION__, __LINE__ |
| 1237 | 1237 | ); |
| 1238 | 1238 | } |
@@ -1248,19 +1248,19 @@ discard block |
||
| 1248 | 1248 | * @param \EE_Payment $payment |
| 1249 | 1249 | * @return array |
| 1250 | 1250 | */ |
| 1251 | - protected function _get_REG_IDs_to_apply_payment_to( EE_Payment $payment ) { |
|
| 1251 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) { |
|
| 1252 | 1252 | $REG_IDs = array(); |
| 1253 | 1253 | // grab array of IDs for specific registrations to apply changes to |
| 1254 | - if ( isset( $this->_req_data[ 'txn_admin_payment' ][ 'registrations' ] ) ) { |
|
| 1255 | - $REG_IDs = (array)$this->_req_data[ 'txn_admin_payment' ][ 'registrations' ]; |
|
| 1254 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1255 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1256 | 1256 | } |
| 1257 | 1257 | //nothing specified ? then get all reg IDs |
| 1258 | - if ( empty( $REG_IDs ) ) { |
|
| 1258 | + if (empty($REG_IDs)) { |
|
| 1259 | 1259 | $registrations = $payment->transaction()->registrations(); |
| 1260 | - $REG_IDs = ! empty( $registrations ) ? array_keys( $registrations ) : $this->_get_existing_reg_payment_REG_IDs( $payment ); |
|
| 1260 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | // ensure that REG_IDs are integers and NOT strings |
| 1263 | - return array_map( 'intval', $REG_IDs ); |
|
| 1263 | + return array_map('intval', $REG_IDs); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | |
@@ -1277,7 +1277,7 @@ discard block |
||
| 1277 | 1277 | /** |
| 1278 | 1278 | * @param array $existing_reg_payment_REG_IDs |
| 1279 | 1279 | */ |
| 1280 | - public function set_existing_reg_payment_REG_IDs( $existing_reg_payment_REG_IDs = null ) { |
|
| 1280 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) { |
|
| 1281 | 1281 | $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
@@ -1292,13 +1292,13 @@ discard block |
||
| 1292 | 1292 | * @param \EE_Payment $payment |
| 1293 | 1293 | * @return array |
| 1294 | 1294 | */ |
| 1295 | - protected function _get_existing_reg_payment_REG_IDs( EE_Payment $payment ) { |
|
| 1296 | - if ( $this->existing_reg_payment_REG_IDs() === null ) { |
|
| 1295 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) { |
|
| 1296 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1297 | 1297 | // let's get any existing reg payment records for this payment |
| 1298 | - $existing_reg_payment_REG_IDs = $payment->get_many_related( 'Registration' ); |
|
| 1298 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1299 | 1299 | // but we only want the REG IDs, so grab the array keys |
| 1300 | - $existing_reg_payment_REG_IDs = ! empty( $existing_reg_payment_REG_IDs ) ? array_keys( $existing_reg_payment_REG_IDs ) : array(); |
|
| 1301 | - $this->set_existing_reg_payment_REG_IDs( $existing_reg_payment_REG_IDs ); |
|
| 1300 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1301 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | return $this->existing_reg_payment_REG_IDs(); |
| 1304 | 1304 | } |
@@ -1317,23 +1317,23 @@ discard block |
||
| 1317 | 1317 | * @param int $PAY_ID |
| 1318 | 1318 | * @return bool; |
| 1319 | 1319 | */ |
| 1320 | - protected function _remove_existing_registration_payments( EE_Payment $payment, $PAY_ID = 0 ) { |
|
| 1320 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) { |
|
| 1321 | 1321 | // newly created payments will have nothing recorded for $PAY_ID |
| 1322 | - if ( $PAY_ID == 0 ) { |
|
| 1322 | + if ($PAY_ID == 0) { |
|
| 1323 | 1323 | return false; |
| 1324 | 1324 | } |
| 1325 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs( $payment ); |
|
| 1326 | - if ( empty( $existing_reg_payment_REG_IDs )) { |
|
| 1325 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1326 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1327 | 1327 | return false; |
| 1328 | 1328 | } |
| 1329 | 1329 | /** @type EE_Transaction_Payments $transaction_payments */ |
| 1330 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
| 1330 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1331 | 1331 | return $transaction_payments->delete_registration_payments_and_update_registrations( |
| 1332 | 1332 | $payment, |
| 1333 | 1333 | array( |
| 1334 | 1334 | array( |
| 1335 | 1335 | 'PAY_ID' => $payment->ID(), |
| 1336 | - 'REG_ID' => array( 'IN', $existing_reg_payment_REG_IDs ), |
|
| 1336 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1337 | 1337 | ) |
| 1338 | 1338 | ) |
| 1339 | 1339 | ); |
@@ -1352,25 +1352,25 @@ discard block |
||
| 1352 | 1352 | * @param array $REG_IDs |
| 1353 | 1353 | * @return bool |
| 1354 | 1354 | */ |
| 1355 | - protected function _update_registration_payments( EE_Transaction $transaction, EE_Payment $payment, $REG_IDs = array() ) { |
|
| 1355 | + protected function _update_registration_payments(EE_Transaction $transaction, EE_Payment $payment, $REG_IDs = array()) { |
|
| 1356 | 1356 | // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
| 1357 | 1357 | // so let's do that using our set of REG_IDs from the form |
| 1358 | 1358 | $registration_query_where_params = array( |
| 1359 | - 'REG_ID' => array( 'IN', $REG_IDs ) |
|
| 1359 | + 'REG_ID' => array('IN', $REG_IDs) |
|
| 1360 | 1360 | ); |
| 1361 | 1361 | // but add in some conditions regarding payment, |
| 1362 | 1362 | // so that we don't apply payments to registrations that are free or have already been paid for |
| 1363 | 1363 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
| 1364 | - if ( ! $payment->is_a_refund() ) { |
|
| 1365 | - $registration_query_where_params[ 'REG_final_price' ] = array( '!=', 0 ); |
|
| 1366 | - $registration_query_where_params[ 'REG_final_price*' ] = array( '!=', 'REG_paid', true ); |
|
| 1364 | + if ( ! $payment->is_a_refund()) { |
|
| 1365 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1366 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1367 | 1367 | } |
| 1368 | 1368 | //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
| 1369 | - $registrations = $transaction->registrations( array( $registration_query_where_params ) ); |
|
| 1370 | - if ( ! empty( $registrations ) ) { |
|
| 1369 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1370 | + if ( ! empty($registrations)) { |
|
| 1371 | 1371 | /** @type EE_Payment_Processor $payment_processor */ |
| 1372 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
| 1373 | - $payment_processor->process_registration_payments( $transaction, $payment, $registrations ); |
|
| 1372 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1373 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | } |
| 1376 | 1376 | |
@@ -1386,22 +1386,22 @@ discard block |
||
| 1386 | 1386 | * @param array $REG_IDs |
| 1387 | 1387 | * @return bool |
| 1388 | 1388 | */ |
| 1389 | - protected function _process_registration_status_change( EE_Transaction $transaction, $REG_IDs = array() ) { |
|
| 1389 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) { |
|
| 1390 | 1390 | // first if there is no change in status then we get out. |
| 1391 | 1391 | if ( |
| 1392 | - ! isset( $this->_req_data['txn_reg_status_change'], $this->_req_data[ 'txn_reg_status_change' ][ 'reg_status' ] ) |
|
| 1392 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1393 | 1393 | || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
| 1394 | 1394 | ) { |
| 1395 | 1395 | //no error message, no change requested, just nothing to do man. |
| 1396 | 1396 | return FALSE; |
| 1397 | 1397 | } |
| 1398 | 1398 | /** @type EE_Transaction_Processor $transaction_processor */ |
| 1399 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1399 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1400 | 1400 | // made it here dude? Oh WOW. K, let's take care of changing the statuses |
| 1401 | 1401 | return $transaction_processor->manually_update_registration_statuses( |
| 1402 | 1402 | $transaction, |
| 1403 | - sanitize_text_field( $this->_req_data[ 'txn_reg_status_change' ][ 'reg_status' ] ), |
|
| 1404 | - array( array( 'REG_ID' => array( 'IN', $REG_IDs ) ) ) |
|
| 1403 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1404 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1405 | 1405 | ); |
| 1406 | 1406 | } |
| 1407 | 1407 | |
@@ -1416,16 +1416,16 @@ discard block |
||
| 1416 | 1416 | * @param bool | null $delete_txn_reg_status_change |
| 1417 | 1417 | * @return array |
| 1418 | 1418 | */ |
| 1419 | - protected function _build_payment_json_response( EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null ) { |
|
| 1419 | + protected function _build_payment_json_response(EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null) { |
|
| 1420 | 1420 | // was the payment deleted ? |
| 1421 | - if ( is_bool( $delete_txn_reg_status_change )) { |
|
| 1421 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 1422 | 1422 | return array( |
| 1423 | 1423 | 'PAY_ID' => $payment->ID(), |
| 1424 | 1424 | 'amount' => $payment->amount(), |
| 1425 | 1425 | 'total_paid' => $payment->transaction()->paid(), |
| 1426 | 1426 | 'txn_status' => $payment->transaction()->status_ID(), |
| 1427 | 1427 | 'pay_status' => $payment->STS_ID(), |
| 1428 | - 'registrations' => $this->_registration_payment_data_array( $REG_IDs ), |
|
| 1428 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1429 | 1429 | 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
| 1430 | 1430 | ); |
| 1431 | 1431 | } else { |
@@ -1437,16 +1437,16 @@ discard block |
||
| 1437 | 1437 | 'pay_status' => $payment->STS_ID(), |
| 1438 | 1438 | 'PAY_ID' => $payment->ID(), |
| 1439 | 1439 | 'STS_ID' => $payment->STS_ID(), |
| 1440 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 1441 | - 'date' => $payment->timestamp( 'Y-m-d', 'h:i a' ), |
|
| 1442 | - 'method' => strtoupper( $payment->source() ), |
|
| 1440 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1441 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1442 | + 'method' => strtoupper($payment->source()), |
|
| 1443 | 1443 | 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
| 1444 | - 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : __( "Unknown", 'event_espresso' ), |
|
| 1444 | + 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : __("Unknown", 'event_espresso'), |
|
| 1445 | 1445 | 'gateway_response' => $payment->gateway_response(), |
| 1446 | 1446 | 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
| 1447 | 1447 | 'po_number' => $payment->po_number(), |
| 1448 | 1448 | 'extra_accntng' => $payment->extra_accntng(), |
| 1449 | - 'registrations' => $this->_registration_payment_data_array( $REG_IDs ), |
|
| 1449 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1450 | 1450 | ); |
| 1451 | 1451 | } |
| 1452 | 1452 | } |
@@ -1461,42 +1461,42 @@ discard block |
||
| 1461 | 1461 | * @return void |
| 1462 | 1462 | */ |
| 1463 | 1463 | public function delete_payment() { |
| 1464 | - $json_response_data = array( 'return_data' => FALSE ); |
|
| 1465 | - $PAY_ID = isset( $this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID'] ) ? absint( $this->_req_data['delete_txn_admin_payment']['PAY_ID'] ) : 0; |
|
| 1466 | - if ( $PAY_ID ) { |
|
| 1467 | - $delete_txn_reg_status_change = isset( $this->_req_data[ 'delete_txn_reg_status_change' ] ) ? $this->_req_data[ 'delete_txn_reg_status_change' ] : false; |
|
| 1468 | - $payment = EEM_Payment::instance()->get_one_by_ID( $PAY_ID ); |
|
| 1469 | - if ( $payment instanceof EE_Payment ) { |
|
| 1470 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs( $payment ); |
|
| 1464 | + $json_response_data = array('return_data' => FALSE); |
|
| 1465 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1466 | + if ($PAY_ID) { |
|
| 1467 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1468 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1469 | + if ($payment instanceof EE_Payment) { |
|
| 1470 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1471 | 1471 | /** @type EE_Transaction_Payments $transaction_payments */ |
| 1472 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
| 1473 | - if ( $transaction_payments->delete_payment_and_update_transaction( $payment )) { |
|
| 1474 | - EE_Error::add_success( __( 'The Payment was successfully deleted.', 'event_espresso' ) ); |
|
| 1475 | - $json_response_data['return_data'] = $this->_build_payment_json_response( $payment, $REG_IDs, $delete_txn_reg_status_change ); |
|
| 1476 | - if ( $delete_txn_reg_status_change ) { |
|
| 1472 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1473 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1474 | + EE_Error::add_success(__('The Payment was successfully deleted.', 'event_espresso')); |
|
| 1475 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, $delete_txn_reg_status_change); |
|
| 1476 | + if ($delete_txn_reg_status_change) { |
|
| 1477 | 1477 | $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
| 1478 | 1478 | //MAKE sure we also add the delete_txn_req_status_change to the |
| 1479 | 1479 | //$_REQUEST global because that's how messages will be looking for it. |
| 1480 | 1480 | $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
| 1481 | 1481 | $this->_maybe_send_notifications(); |
| 1482 | - $this->_process_registration_status_change( $payment->transaction(), $REG_IDs ); |
|
| 1482 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1483 | 1483 | //$this->_maybe_send_notifications( $payment ); |
| 1484 | 1484 | } |
| 1485 | 1485 | } |
| 1486 | 1486 | } else { |
| 1487 | 1487 | EE_Error::add_error( |
| 1488 | - __( 'Valid Payment data could not be retrieved from the database.', 'event_espresso' ), |
|
| 1488 | + __('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1489 | 1489 | __FILE__, __FUNCTION__, __LINE__ |
| 1490 | 1490 | ); |
| 1491 | 1491 | } |
| 1492 | 1492 | } else { |
| 1493 | 1493 | EE_Error::add_error( |
| 1494 | - __( 'A valid Payment ID was not received, therefore payment form data could not be loaded.', 'event_espresso' ), |
|
| 1494 | + __('A valid Payment ID was not received, therefore payment form data could not be loaded.', 'event_espresso'), |
|
| 1495 | 1495 | __FILE__, __FUNCTION__, __LINE__ |
| 1496 | 1496 | ); |
| 1497 | 1497 | } |
| 1498 | - $notices = EE_Error::get_notices( FALSE, FALSE, FALSE ); |
|
| 1499 | - echo json_encode( array_merge( $json_response_data, $notices )); |
|
| 1498 | + $notices = EE_Error::get_notices(FALSE, FALSE, FALSE); |
|
| 1499 | + echo json_encode(array_merge($json_response_data, $notices)); |
|
| 1500 | 1500 | die(); |
| 1501 | 1501 | } |
| 1502 | 1502 | |
@@ -1510,17 +1510,17 @@ discard block |
||
| 1510 | 1510 | * @param array $REG_IDs |
| 1511 | 1511 | * @return array |
| 1512 | 1512 | */ |
| 1513 | - protected function _registration_payment_data_array( $REG_IDs ) { |
|
| 1513 | + protected function _registration_payment_data_array($REG_IDs) { |
|
| 1514 | 1514 | $registration_payment_data = array(); |
| 1515 | 1515 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
| 1516 | - if ( ! empty( $REG_IDs ) ) { |
|
| 1517 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
| 1518 | - $registrations = EEM_Registration::instance()->get_all( array( array( 'REG_ID' => array( 'IN', $REG_IDs ) ) ) ); |
|
| 1519 | - foreach ( $registrations as $registration ) { |
|
| 1520 | - if ( $registration instanceof EE_Registration ) { |
|
| 1521 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 1516 | + if ( ! empty($REG_IDs)) { |
|
| 1517 | + EE_Registry::instance()->load_helper('Template'); |
|
| 1518 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1519 | + foreach ($registrations as $registration) { |
|
| 1520 | + if ($registration instanceof EE_Registration) { |
|
| 1521 | + $registration_payment_data[$registration->ID()] = array( |
|
| 1522 | 1522 | 'paid' => $registration->pretty_paid(), |
| 1523 | - 'owing' => EEH_Template::format_currency( $registration->final_price() - $registration->paid() ), |
|
| 1523 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1524 | 1524 | ); |
| 1525 | 1525 | } |
| 1526 | 1526 | } |
@@ -1540,30 +1540,30 @@ discard block |
||
| 1540 | 1540 | * @access protected |
| 1541 | 1541 | * @param \EE_Payment | null $payment |
| 1542 | 1542 | */ |
| 1543 | - protected function _maybe_send_notifications( $payment = null ) { |
|
| 1544 | - switch ( $payment instanceof EE_Payment ) { |
|
| 1543 | + protected function _maybe_send_notifications($payment = null) { |
|
| 1544 | + switch ($payment instanceof EE_Payment) { |
|
| 1545 | 1545 | // payment notifications |
| 1546 | 1546 | case true : |
| 1547 | 1547 | if ( |
| 1548 | 1548 | isset( |
| 1549 | - $this->_req_data[ 'txn_payments' ], |
|
| 1550 | - $this->_req_data[ 'txn_payments' ][ 'send_notifications' ] |
|
| 1549 | + $this->_req_data['txn_payments'], |
|
| 1550 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 1551 | 1551 | ) && |
| 1552 | - filter_var( $this->_req_data[ 'txn_payments' ][ 'send_notifications' ], FILTER_VALIDATE_BOOLEAN ) |
|
| 1552 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1553 | 1553 | ) { |
| 1554 | - $this->_process_payment_notification( $payment ); |
|
| 1554 | + $this->_process_payment_notification($payment); |
|
| 1555 | 1555 | } |
| 1556 | 1556 | break; |
| 1557 | 1557 | // registration notifications |
| 1558 | 1558 | case false : |
| 1559 | 1559 | if ( |
| 1560 | 1560 | isset( |
| 1561 | - $this->_req_data[ 'txn_reg_status_change' ], |
|
| 1562 | - $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ] |
|
| 1561 | + $this->_req_data['txn_reg_status_change'], |
|
| 1562 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1563 | 1563 | ) && |
| 1564 | - filter_var( $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ], FILTER_VALIDATE_BOOLEAN ) |
|
| 1564 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1565 | 1565 | ) { |
| 1566 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
|
| 1566 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1567 | 1567 | } |
| 1568 | 1568 | break; |
| 1569 | 1569 | } |
@@ -1579,11 +1579,11 @@ discard block |
||
| 1579 | 1579 | * @return void |
| 1580 | 1580 | */ |
| 1581 | 1581 | protected function _send_payment_reminder() { |
| 1582 | - $TXN_ID = ( ! empty( $this->_req_data['TXN_ID'] )) ? absint( $this->_req_data['TXN_ID'] ) : FALSE; |
|
| 1583 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
| 1584 | - $query_args = isset($this->_req_data['redirect_to'] ) ? array('action' => $this->_req_data['redirect_to'], 'TXN_ID' => $this->_req_data['TXN_ID'] ) : array(); |
|
| 1585 | - do_action( 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', $transaction ); |
|
| 1586 | - $this->_redirect_after_action( FALSE, __('payment reminder', 'event_espresso'), __('sent', 'event_espresso'), $query_args, TRUE ); |
|
| 1582 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : FALSE; |
|
| 1583 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1584 | + $query_args = isset($this->_req_data['redirect_to']) ? array('action' => $this->_req_data['redirect_to'], 'TXN_ID' => $this->_req_data['TXN_ID']) : array(); |
|
| 1585 | + do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', $transaction); |
|
| 1586 | + $this->_redirect_after_action(FALSE, __('payment reminder', 'event_espresso'), __('sent', 'event_espresso'), $query_args, TRUE); |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | |
@@ -1597,36 +1597,36 @@ discard block |
||
| 1597 | 1597 | * @param string $view |
| 1598 | 1598 | * @return mixed int = count || array of transaction objects |
| 1599 | 1599 | */ |
| 1600 | - public function get_transactions( $perpage, $count = FALSE, $view = '' ) { |
|
| 1600 | + public function get_transactions($perpage, $count = FALSE, $view = '') { |
|
| 1601 | 1601 | |
| 1602 | 1602 | $TXN = EEM_Transaction::instance(); |
| 1603 | 1603 | |
| 1604 | - $start_date = isset( $this->_req_data['txn-filter-start-date'] ) ? wp_strip_all_tags( $this->_req_data['txn-filter-start-date'] ) : date( 'm/d/Y', strtotime( '-10 year' )); |
|
| 1605 | - $end_date = isset( $this->_req_data['txn-filter-end-date'] ) ? wp_strip_all_tags( $this->_req_data['txn-filter-end-date'] ) : date( 'm/d/Y' ); |
|
| 1604 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', strtotime('-10 year')); |
|
| 1605 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1606 | 1606 | |
| 1607 | 1607 | //make sure our timestamps start and end right at the boundaries for each day |
| 1608 | - $start_date = date( 'Y-m-d', strtotime( $start_date ) ) . ' 00:00:00'; |
|
| 1609 | - $end_date = date( 'Y-m-d', strtotime( $end_date ) ) . ' 23:59:59'; |
|
| 1608 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 1609 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 1610 | 1610 | |
| 1611 | 1611 | |
| 1612 | 1612 | //convert to timestamps |
| 1613 | - $start_date = strtotime( $start_date ); |
|
| 1614 | - $end_date = strtotime( $end_date ); |
|
| 1613 | + $start_date = strtotime($start_date); |
|
| 1614 | + $end_date = strtotime($end_date); |
|
| 1615 | 1615 | |
| 1616 | 1616 | //makes sure start date is the lowest value and vice versa |
| 1617 | - $start_date = min( $start_date, $end_date ); |
|
| 1618 | - $end_date = max( $start_date, $end_date ); |
|
| 1617 | + $start_date = min($start_date, $end_date); |
|
| 1618 | + $end_date = max($start_date, $end_date); |
|
| 1619 | 1619 | |
| 1620 | 1620 | //convert to correct format for query |
| 1621 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( 'TXN_timestamp', date( 'Y-m-d H:i:s', $start_date ), 'Y-m-d H:i:s' ); |
|
| 1622 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( 'TXN_timestamp', date( 'Y-m-d H:i:s', $end_date ), 'Y-m-d H:i:s' ); |
|
| 1621 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1622 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1623 | 1623 | |
| 1624 | 1624 | |
| 1625 | 1625 | |
| 1626 | 1626 | //set orderby |
| 1627 | 1627 | $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
| 1628 | 1628 | |
| 1629 | - switch ( $this->_req_data['orderby'] ) { |
|
| 1629 | + switch ($this->_req_data['orderby']) { |
|
| 1630 | 1630 | case 'TXN_ID': |
| 1631 | 1631 | $orderby = 'TXN_ID'; |
| 1632 | 1632 | break; |
@@ -1640,66 +1640,66 @@ discard block |
||
| 1640 | 1640 | $orderby = 'TXN_timestamp'; |
| 1641 | 1641 | } |
| 1642 | 1642 | |
| 1643 | - $sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'DESC'; |
|
| 1644 | - $current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
|
| 1645 | - $per_page = isset( $perpage ) && !empty( $perpage ) ? $perpage : 10; |
|
| 1646 | - $per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page; |
|
| 1643 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1644 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1645 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1646 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1647 | 1647 | |
| 1648 | - $offset = ($current_page-1)*$per_page; |
|
| 1649 | - $limit = array( $offset, $per_page ); |
|
| 1648 | + $offset = ($current_page - 1) * $per_page; |
|
| 1649 | + $limit = array($offset, $per_page); |
|
| 1650 | 1650 | |
| 1651 | 1651 | $_where = array( |
| 1652 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date) ), |
|
| 1652 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1653 | 1653 | 'Registration.REG_count' => 1 |
| 1654 | 1654 | ); |
| 1655 | 1655 | |
| 1656 | - if ( isset( $this->_req_data['EVT_ID'] ) ) { |
|
| 1656 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 1657 | 1657 | $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | - if ( isset( $this->_req_data['s'] ) ) { |
|
| 1661 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1660 | + if (isset($this->_req_data['s'])) { |
|
| 1661 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1662 | 1662 | $_where['OR'] = array( |
| 1663 | - 'Registration.Event.EVT_name' => array( 'LIKE', $search_string ), |
|
| 1664 | - 'Registration.Event.EVT_desc' => array( 'LIKE', $search_string ), |
|
| 1665 | - 'Registration.Event.EVT_short_desc' => array( 'LIKE' , $search_string ), |
|
| 1666 | - 'Registration.Attendee.ATT_full_name' => array( 'LIKE', $search_string ), |
|
| 1667 | - 'Registration.Attendee.ATT_fname' => array( 'LIKE', $search_string ), |
|
| 1668 | - 'Registration.Attendee.ATT_lname' => array( 'LIKE', $search_string ), |
|
| 1669 | - 'Registration.Attendee.ATT_short_bio' => array( 'LIKE', $search_string ), |
|
| 1670 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string ), |
|
| 1671 | - 'Registration.Attendee.ATT_address' => array( 'LIKE', $search_string ), |
|
| 1672 | - 'Registration.Attendee.ATT_address2' => array( 'LIKE', $search_string ), |
|
| 1673 | - 'Registration.Attendee.ATT_city' => array( 'LIKE', $search_string ), |
|
| 1674 | - 'Registration.REG_final_price' => array( 'LIKE', $search_string ), |
|
| 1675 | - 'Registration.REG_code' => array( 'LIKE', $search_string ), |
|
| 1676 | - 'Registration.REG_count' => array( 'LIKE' , $search_string ), |
|
| 1677 | - 'Registration.REG_group_size' => array( 'LIKE' , $search_string ), |
|
| 1678 | - 'Registration.Ticket.TKT_name' => array( 'LIKE', $search_string ), |
|
| 1679 | - 'Registration.Ticket.TKT_description' => array( 'LIKE', $search_string ), |
|
| 1680 | - 'Payment.PAY_source' => array('LIKE', $search_string ), |
|
| 1681 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string ), |
|
| 1682 | - 'TXN_session_data' => array( 'LIKE', $search_string ), |
|
| 1683 | - 'Payment.PAY_txn_id_chq_nmbr' => array( 'LIKE', $search_string ) |
|
| 1663 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1664 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1665 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1666 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1667 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1668 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1669 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1670 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1671 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1672 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1673 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1674 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1675 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1676 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1677 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1678 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1679 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1680 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1681 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1682 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1683 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1684 | 1684 | ); |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | //failed transactions |
| 1688 | - $failed = ( ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'failed' && ! $count ) || ( $count && $view == 'failed' ) ? TRUE: FALSE; |
|
| 1689 | - $abandoned = ( ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'abandoned' && ! $count ) || ( $count && $view == 'abandoned' ) ? TRUE: FALSE; |
|
| 1688 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? TRUE : FALSE; |
|
| 1689 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? TRUE : FALSE; |
|
| 1690 | 1690 | |
| 1691 | - if ( $failed ) { |
|
| 1692 | - $_where[ 'STS_ID' ] = EEM_Transaction::failed_status_code; |
|
| 1693 | - } else if ( $abandoned ) { |
|
| 1691 | + if ($failed) { |
|
| 1692 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1693 | + } else if ($abandoned) { |
|
| 1694 | 1694 | $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
| 1695 | 1695 | } else { |
| 1696 | - $_where['STS_ID'] = array( '!=', EEM_Transaction::failed_status_code ); |
|
| 1697 | - $_where['STS_ID*'] = array( '!=', EEM_Transaction::abandoned_status_code ); |
|
| 1696 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1697 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | - $query_params = array( $_where, 'order_by' => array( $orderby => $sort ), 'limit' => $limit ); |
|
| 1700 | + $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); |
|
| 1701 | 1701 | |
| 1702 | - $transactions = $count ? $TXN->count( array($_where), 'TXN_ID', TRUE ) : $TXN->get_all($query_params); |
|
| 1702 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', TRUE) : $TXN->get_all($query_params); |
|
| 1703 | 1703 | |
| 1704 | 1704 | |
| 1705 | 1705 | return $transactions; |
@@ -47,25 +47,25 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | - * date format |
|
| 51 | - * |
|
| 52 | - * pattern or format for displaying dates |
|
| 53 | - * |
|
| 54 | - * @access protected |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 50 | + * date format |
|
| 51 | + * |
|
| 52 | + * pattern or format for displaying dates |
|
| 53 | + * |
|
| 54 | + * @access protected |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | 57 | protected $_dt_frmt; |
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * time format |
|
| 63 | - * |
|
| 64 | - * pattern or format for displaying time |
|
| 65 | - * |
|
| 66 | - * @access protected |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 61 | + /** |
|
| 62 | + * time format |
|
| 63 | + * |
|
| 64 | + * pattern or format for displaying time |
|
| 65 | + * |
|
| 66 | + * @access protected |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | protected $_tm_frmt; |
| 70 | 70 | |
| 71 | 71 | |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | - * Gets the field's original value when this object was constructed during this request. |
|
| 209 | - * This can be helpful when determining if a model object has changed or not |
|
| 210 | - * |
|
| 211 | - * @param string $field_name |
|
| 212 | - * @return mixed|null |
|
| 213 | - */ |
|
| 208 | + * Gets the field's original value when this object was constructed during this request. |
|
| 209 | + * This can be helpful when determining if a model object has changed or not |
|
| 210 | + * |
|
| 211 | + * @param string $field_name |
|
| 212 | + * @return mixed|null |
|
| 213 | + */ |
|
| 214 | 214 | public function get_original( $field_name ){ |
| 215 | 215 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
| 216 | 216 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
@@ -1310,28 +1310,28 @@ discard block |
||
| 1310 | 1310 | return $result ? true : false; |
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | - /** |
|
| 1314 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1315 | - * related model objects |
|
| 1316 | - */ |
|
| 1317 | - public function refresh_cache_of_related_objects() { |
|
| 1318 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1319 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1320 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1321 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1322 | - //this relation only stores a single model object, not an array |
|
| 1323 | - //but let's make it consistent |
|
| 1324 | - $related_objects = array( $related_objects ); |
|
| 1325 | - } |
|
| 1326 | - foreach( $related_objects as $related_object ) { |
|
| 1327 | - //only refresh their cache if they're in memory |
|
| 1328 | - if( $related_object instanceof EE_Base_Class ) { |
|
| 1313 | + /** |
|
| 1314 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1315 | + * related model objects |
|
| 1316 | + */ |
|
| 1317 | + public function refresh_cache_of_related_objects() { |
|
| 1318 | + foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1319 | + if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1320 | + $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1321 | + if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1322 | + //this relation only stores a single model object, not an array |
|
| 1323 | + //but let's make it consistent |
|
| 1324 | + $related_objects = array( $related_objects ); |
|
| 1325 | + } |
|
| 1326 | + foreach( $related_objects as $related_object ) { |
|
| 1327 | + //only refresh their cache if they're in memory |
|
| 1328 | + if( $related_object instanceof EE_Base_Class ) { |
|
| 1329 | 1329 | $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | 1335 | |
| 1336 | 1336 | |
| 1337 | 1337 | |
@@ -1681,9 +1681,9 @@ discard block |
||
| 1681 | 1681 | $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
| 1682 | 1682 | //clear cache so future get_many_related and get_first_related() return new results. |
| 1683 | 1683 | $this->clear_cache( $relationName, $otherObject, TRUE ); |
| 1684 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1685 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1686 | - } |
|
| 1684 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1685 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1686 | + } |
|
| 1687 | 1687 | } else { |
| 1688 | 1688 | //this thing doesn't exist in the DB, so just cache it |
| 1689 | 1689 | if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
@@ -1697,18 +1697,18 @@ discard block |
||
| 1697 | 1697 | } |
| 1698 | 1698 | $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
| 1699 | 1699 | } |
| 1700 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1701 | - //fix the reciprocal relation too |
|
| 1702 | - if( $otherObject->ID() ) { |
|
| 1703 | - //its saved so assumed relations exist in the DB, so we can just |
|
| 1704 | - //clear the cache so future queries use the updated info in the DB |
|
| 1705 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1706 | - } else { |
|
| 1707 | - |
|
| 1708 | - //it's not saved, so it caches relations like this |
|
| 1709 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1710 | - } |
|
| 1711 | - } |
|
| 1700 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1701 | + //fix the reciprocal relation too |
|
| 1702 | + if( $otherObject->ID() ) { |
|
| 1703 | + //its saved so assumed relations exist in the DB, so we can just |
|
| 1704 | + //clear the cache so future queries use the updated info in the DB |
|
| 1705 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1706 | + } else { |
|
| 1707 | + |
|
| 1708 | + //it's not saved, so it caches relations like this |
|
| 1709 | + $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1712 | 1712 | return $otherObject; |
| 1713 | 1713 | } |
| 1714 | 1714 | |
@@ -1738,9 +1738,9 @@ discard block |
||
| 1738 | 1738 | //this doesn't exist in the DB, just remove it from the cache |
| 1739 | 1739 | $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
| 1740 | 1740 | } |
| 1741 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1742 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1743 | - } |
|
| 1741 | + if( $otherObject instanceof EE_Base_Class ) { |
|
| 1742 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1743 | + } |
|
| 1744 | 1744 | return $otherObject; |
| 1745 | 1745 | } |
| 1746 | 1746 | |
@@ -1759,11 +1759,11 @@ discard block |
||
| 1759 | 1759 | //this doesn't exist in the DB, just remove it from the cache |
| 1760 | 1760 | $otherObjects = $this->clear_cache( $relationName, null, true ); |
| 1761 | 1761 | } |
| 1762 | - if( is_array( $otherObjects ) ) { |
|
| 1763 | - foreach ( $otherObjects as $otherObject ) { |
|
| 1764 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1765 | - } |
|
| 1766 | - } |
|
| 1762 | + if( is_array( $otherObjects ) ) { |
|
| 1763 | + foreach ( $otherObjects as $otherObject ) { |
|
| 1764 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1765 | + } |
|
| 1766 | + } |
|
| 1767 | 1767 | return $otherObjects; |
| 1768 | 1768 | } |
| 1769 | 1769 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Event Espresso |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * ------------------------------------------------------------------------ |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | -abstract class EE_Base_Class{ |
|
| 27 | +abstract class EE_Base_Class { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * This is an array of the original properties and values provided during construction |
@@ -117,60 +117,60 @@ discard block |
||
| 117 | 117 | * @throws EE_Error |
| 118 | 118 | * @return \EE_Base_Class |
| 119 | 119 | */ |
| 120 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
| 120 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
| 121 | 121 | |
| 122 | - $className=get_class($this); |
|
| 122 | + $className = get_class($this); |
|
| 123 | 123 | |
| 124 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
| 125 | - $model=$this->get_model(); |
|
| 126 | - $model_fields = $model->field_settings( FALSE ); |
|
| 124 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 125 | + $model = $this->get_model(); |
|
| 126 | + $model_fields = $model->field_settings(FALSE); |
|
| 127 | 127 | // ensure $fieldValues is an array |
| 128 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
| 128 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 129 | 129 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 130 | 130 | // verify client code has not passed any invalid field names |
| 131 | - foreach($fieldValues as $field_name=> $field_value){ |
|
| 132 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
| 133 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
| 131 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
| 132 | + if ( ! isset($model_fields[$field_name])) { |
|
| 133 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 137 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
| 138 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 137 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
| 138 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 139 | 139 | |
| 140 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
| 140 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 141 | 141 | $this->_dt_frmt = $date_formats[0]; |
| 142 | 142 | $this->_tm_frmt = $date_formats[1]; |
| 143 | 143 | } else { |
| 144 | 144 | //set default formats for date and time |
| 145 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
| 146 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
| 145 | + $this->_dt_frmt = get_option('date_format'); |
|
| 146 | + $this->_tm_frmt = get_option('time_format'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | //if db model is instantiating |
| 150 | - if ( $bydb ){ |
|
| 150 | + if ($bydb) { |
|
| 151 | 151 | //client code has indicated these field values are from the database |
| 152 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 153 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
| 152 | + foreach ($model_fields as $fieldName => $field) { |
|
| 153 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 154 | 154 | } |
| 155 | 155 | } else { |
| 156 | 156 | //we're constructing a brand |
| 157 | 157 | //new instance of the model object. Generally, this means we'll need to do more field validation |
| 158 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 159 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
| 158 | + foreach ($model_fields as $fieldName => $field) { |
|
| 159 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | //remember what values were passed to this constructor |
| 164 | 164 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
| 165 | 165 | //remember in entity mapper |
| 166 | - if($model->has_primary_key_field() && $this->ID() && ! $bydb ){ |
|
| 166 | + if ($model->has_primary_key_field() && $this->ID() && ! $bydb) { |
|
| 167 | 167 | $model->add_to_entity_map($this); |
| 168 | 168 | } |
| 169 | 169 | //setup all the relations |
| 170 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
| 171 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 170 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
| 171 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 172 | 172 | $this->_model_relations[$relation_name] = NULL; |
| 173 | - }else{ |
|
| 173 | + } else { |
|
| 174 | 174 | $this->_model_relations[$relation_name] = array(); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * Action done at the end of each model object construction |
| 179 | 179 | * @param EE_Base_Class $this the model object just created |
| 180 | 180 | */ |
| 181 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
| 181 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param boolean $allow_persist |
| 199 | 199 | * @return boolean |
| 200 | 200 | */ |
| 201 | - function set_allow_persist( $allow_persist ) { |
|
| 201 | + function set_allow_persist($allow_persist) { |
|
| 202 | 202 | return $this->_allow_persist = $allow_persist; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | * @param string $field_name |
| 212 | 212 | * @return mixed|null |
| 213 | 213 | */ |
| 214 | - public function get_original( $field_name ){ |
|
| 215 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
| 216 | - $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
|
| 217 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
| 218 | - }else{ |
|
| 214 | + public function get_original($field_name) { |
|
| 215 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
| 216 | + $field_settings = $this->get_Model()->field_settings_for($field_name)) { |
|
| 217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 218 | + } else { |
|
| 219 | 219 | return NULL; |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param EE_Base_Class $obj |
| 226 | 226 | * @return string |
| 227 | 227 | */ |
| 228 | - public function get_class($obj){ |
|
| 228 | + public function get_class($obj) { |
|
| 229 | 229 | return get_class($obj); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -238,19 +238,19 @@ discard block |
||
| 238 | 238 | * @param mixed $field_value |
| 239 | 239 | * @param bool $use_default |
| 240 | 240 | */ |
| 241 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
| 242 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
| 243 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 241 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
| 242 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 243 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 244 | 244 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
| 245 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 246 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 247 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
| 248 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
| 245 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 246 | + $field_obj->set_timezone($this->_timezone); |
|
| 247 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 248 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
| 252 | 252 | //should the value be null? |
| 253 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
| 253 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
| 254 | 254 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -260,19 +260,19 @@ discard block |
||
| 260 | 260 | * object. |
| 261 | 261 | * @since 4.6.10+ |
| 262 | 262 | */ |
| 263 | - if ( $field_obj instanceof EE_Datetime_Field && ! is_null( $this->_fields[$field_name] ) && ! $this->_fields[$field_name] instanceof DateTime ) { |
|
| 264 | - empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
|
| 263 | + if ($field_obj instanceof EE_Datetime_Field && ! is_null($this->_fields[$field_name]) && ! $this->_fields[$field_name] instanceof DateTime) { |
|
| 264 | + empty($this->_fields[$field_name]) ? $this->set($field_name, time()) : $this->set($field_name, $this->_fields[$field_name]); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - }else{ |
|
| 267 | + } else { |
|
| 268 | 268 | $this->_fields[$field_name] = $holder_of_value; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | //if we're not in the constructor... |
| 272 | 272 | //now check if what we set was a primary key |
| 273 | - if($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 273 | + if ($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 274 | 274 | $field_name == $this->_get_primary_key_name(get_class($this)) && |
| 275 | - $field_value){ |
|
| 275 | + $field_value) { |
|
| 276 | 276 | //if so, we want all this object's fields to be filled either with |
| 277 | 277 | //what we've explicitly set on this model |
| 278 | 278 | //or what we have in the db |
@@ -280,20 +280,20 @@ discard block |
||
| 280 | 280 | $fields_on_model = $this->_get_model(get_class($this))->field_settings(); |
| 281 | 281 | |
| 282 | 282 | $obj_in_db = $this->_get_model(get_class($this))->get_one_by_ID($field_value); |
| 283 | - foreach($fields_on_model as $field_obj){ |
|
| 284 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 285 | - && $field_obj->get_name() != $field_name ){ |
|
| 283 | + foreach ($fields_on_model as $field_obj) { |
|
| 284 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 285 | + && $field_obj->get_name() != $field_name) { |
|
| 286 | 286 | |
| 287 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
| 287 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | //oh this model object has an ID? well make sure its in the entity mapper |
| 291 | 291 | $this->get_model()->add_to_entity_map($this); |
| 292 | 292 | } |
| 293 | 293 | //let's unset any cache for this field_name from the $_cached_properties property. |
| 294 | - $this->_clear_cached_property( $field_name ); |
|
| 295 | - }else{ |
|
| 296 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
| 294 | + $this->_clear_cached_property($field_name); |
|
| 295 | + } else { |
|
| 296 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | } |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | * @param mixed $field_value The value to set. |
| 313 | 313 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
| 314 | 314 | */ |
| 315 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
| 316 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 317 | - $this->set( $field_name, $field_value ); |
|
| 315 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
| 316 | + if ($this->get_model()->has_field($field_name)) { |
|
| 317 | + $this->set($field_name, $field_value); |
|
| 318 | 318 | return true; |
| 319 | 319 | } else { |
| 320 | 320 | //ensure this object is saved first so that extra meta can be properly related. |
| 321 | 321 | $this->save(); |
| 322 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
| 322 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
@@ -343,12 +343,12 @@ discard block |
||
| 343 | 343 | * @param string $field_name expecting the fully qualified field name. |
| 344 | 344 | * @return mixed|null value for the field if found. null if not found. |
| 345 | 345 | */ |
| 346 | - public function get_field_or_extra_meta( $field_name ) { |
|
| 347 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 348 | - $column_value = $this->get( $field_name ); |
|
| 346 | + public function get_field_or_extra_meta($field_name) { |
|
| 347 | + if ($this->get_model()->has_field($field_name)) { |
|
| 348 | + $column_value = $this->get($field_name); |
|
| 349 | 349 | } else { |
| 350 | 350 | //This isn't a column in the main table, let's see if it is in the extra meta. |
| 351 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
| 351 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 352 | 352 | } |
| 353 | 353 | return $column_value; |
| 354 | 354 | } |
@@ -367,19 +367,19 @@ discard block |
||
| 367 | 367 | * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
| 368 | 368 | * @return void |
| 369 | 369 | */ |
| 370 | - public function set_timezone( $timezone = '' ) { |
|
| 370 | + public function set_timezone($timezone = '') { |
|
| 371 | 371 | EE_Registry::instance()->load_helper('DTT_Helper'); |
| 372 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 372 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 373 | 373 | //make sure we clear all cached properties because they won't be relevant now |
| 374 | 374 | $this->_clear_cached_properties(); |
| 375 | 375 | |
| 376 | 376 | //make sure we update field settings and the date for all EE_Datetime_Fields |
| 377 | - $model_fields = $this->get_model()->field_settings( false ); |
|
| 378 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
| 379 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 380 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 381 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
| 382 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
| 377 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 378 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 379 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 380 | + $field_obj->set_timezone($this->_timezone); |
|
| 381 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 382 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @param string $format should be a format recognizable by PHP date() functions. |
| 410 | 410 | */ |
| 411 | - public function set_date_format( $format ) { |
|
| 411 | + public function set_date_format($format) { |
|
| 412 | 412 | $this->_dt_frmt = $format; |
| 413 | 413 | //clear cached_properties because they won't be relevant now. |
| 414 | 414 | $this->_clear_cached_properties(); |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @since 4.6 |
| 425 | 425 | * @param string $format should be a format recognizable by PHP date() functions. |
| 426 | 426 | */ |
| 427 | - public function set_time_format( $format ) { |
|
| 427 | + public function set_time_format($format) { |
|
| 428 | 428 | $this->_tm_frmt = $format; |
| 429 | 429 | //clear cached_properties because they won't be relevant now. |
| 430 | 430 | $this->_clear_cached_properties(); |
@@ -441,8 +441,8 @@ discard block |
||
| 441 | 441 | * |
| 442 | 442 | * @return mixed string|array |
| 443 | 443 | */ |
| 444 | - public function get_format( $full = true ) { |
|
| 445 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
| 444 | + public function get_format($full = true) { |
|
| 445 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -460,17 +460,17 @@ discard block |
||
| 460 | 460 | * @throws EE_Error |
| 461 | 461 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
| 462 | 462 | */ |
| 463 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
| 463 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
| 464 | 464 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
| 465 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
| 465 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 466 | 466 | return FALSE; |
| 467 | 467 | } |
| 468 | 468 | // also get "how" the object is related, or throw an error |
| 469 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
| 470 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
| 469 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 470 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
| 471 | 471 | } |
| 472 | 472 | // how many things are related ? |
| 473 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
| 473 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 474 | 474 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
| 475 | 475 | // so for these model objects just set it to be cached |
| 476 | 476 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -478,26 +478,26 @@ discard block |
||
| 478 | 478 | } else { |
| 479 | 479 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
| 480 | 480 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
| 481 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
| 481 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 482 | 482 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
| 483 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
| 483 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
| 484 | 484 | } |
| 485 | 485 | // first check for a cache_id which is normally empty |
| 486 | - if ( ! empty( $cache_id )) { |
|
| 486 | + if ( ! empty($cache_id)) { |
|
| 487 | 487 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
| 488 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
| 488 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 489 | 489 | $return = $cache_id; |
| 490 | - } elseif ( $object_to_cache->ID() ) { |
|
| 490 | + } elseif ($object_to_cache->ID()) { |
|
| 491 | 491 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
| 492 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
| 492 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 493 | 493 | $return = $object_to_cache->ID(); |
| 494 | 494 | } else { |
| 495 | 495 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
| 496 | 496 | $this->_model_relations[$relationName][] = $object_to_cache; |
| 497 | 497 | // move the internal pointer to the end of the array |
| 498 | - end( $this->_model_relations[$relationName] ); |
|
| 498 | + end($this->_model_relations[$relationName]); |
|
| 499 | 499 | // and grab the key so that we can return it |
| 500 | - $return = key( $this->_model_relations[$relationName] ); |
|
| 500 | + $return = key($this->_model_relations[$relationName]); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | } |
@@ -515,11 +515,11 @@ discard block |
||
| 515 | 515 | * @param null $cache_type |
| 516 | 516 | * @return void |
| 517 | 517 | */ |
| 518 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
| 518 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
| 519 | 519 | //first make sure this property exists |
| 520 | 520 | $this->get_model()->field_settings_for($fieldname); |
| 521 | 521 | |
| 522 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
| 522 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 523 | 523 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
| 524 | 524 | } |
| 525 | 525 | |
@@ -534,34 +534,34 @@ discard block |
||
| 534 | 534 | * It can also accept certain pre-defined "schema" strings to define how to output the property. see the field's prepare_for_pretty_echoing for what strings can be used |
| 535 | 535 | * @return mixed whatever the value for the property is we're retrieving |
| 536 | 536 | */ |
| 537 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
| 537 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
| 538 | 538 | //verify the field exists |
| 539 | 539 | $this->get_model()->field_settings_for($fieldname); |
| 540 | 540 | |
| 541 | 541 | $cache_type = $pretty ? 'pretty' : 'standard'; |
| 542 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
| 542 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
| 543 | 543 | |
| 544 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
| 544 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 545 | 545 | return $this->_cached_properties[$fieldname][$cache_type]; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
| 549 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 549 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 550 | 550 | /** |
| 551 | 551 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
| 552 | 552 | * formats are correct. |
| 553 | 553 | */ |
| 554 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 555 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 556 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
| 557 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
| 554 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 555 | + $field_obj->set_timezone($this->_timezone); |
|
| 556 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
| 557 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | - if( ! isset($this->_fields[$fieldname])){ |
|
| 560 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 561 | 561 | $this->_fields[$fieldname] = NULL; |
| 562 | 562 | } |
| 563 | - $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
| 564 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
| 563 | + $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 564 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 565 | 565 | return $value; |
| 566 | 566 | } |
| 567 | 567 | return FALSE; |
@@ -587,9 +587,9 @@ discard block |
||
| 587 | 587 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
| 588 | 588 | * @return void |
| 589 | 589 | */ |
| 590 | - protected function _clear_cached_property( $property_name ) { |
|
| 591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
| 592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
| 590 | + protected function _clear_cached_property($property_name) { |
|
| 591 | + if (isset($this->_cached_properties[$property_name])) |
|
| 592 | + unset($this->_cached_properties[$property_name]); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @param string $model_name name of the related thing, eg 'Attendee', |
| 601 | 601 | * @return EE_Base_Class |
| 602 | 602 | */ |
| 603 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
| 603 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
| 604 | 604 | $other_model_instance = self::_get_model_instance_with_name(self::_get_model_classname($model_name), $this->_timezone); |
| 605 | 605 | $model_obj = $other_model_instance->ensure_is_obj($object_or_id); |
| 606 | 606 | return $model_obj; |
@@ -620,55 +620,55 @@ discard block |
||
| 620 | 620 | * @throws EE_Error |
| 621 | 621 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
| 622 | 622 | */ |
| 623 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
| 623 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
| 624 | 624 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
| 625 | 625 | $index_in_cache = ''; |
| 626 | - if( ! $relationship_to_model){ |
|
| 627 | - throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache",'event_espresso'),$relationName,get_class($this))); |
|
| 626 | + if ( ! $relationship_to_model) { |
|
| 627 | + throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), $relationName, get_class($this))); |
|
| 628 | 628 | } |
| 629 | - if($clear_all){ |
|
| 629 | + if ($clear_all) { |
|
| 630 | 630 | $obj_removed = true; |
| 631 | 631 | $this->_model_relations[$relationName] = null; |
| 632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
| 632 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 633 | 633 | $obj_removed = $this->_model_relations[$relationName]; |
| 634 | 634 | $this->_model_relations[$relationName] = null; |
| 635 | - }else{ |
|
| 636 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
| 635 | + } else { |
|
| 636 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
| 637 | 637 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
| 638 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
| 638 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
| 639 | 639 | $index_found_at = NULL; |
| 640 | 640 | //find this object in the array even though it has a different key |
| 641 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
| 642 | - if( $obj instanceof EE_Base_Class && ( $obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID() )) { |
|
| 641 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
| 642 | + if ($obj instanceof EE_Base_Class && ($obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID())) { |
|
| 643 | 643 | $index_found_at = $index; |
| 644 | 644 | break; |
| 645 | 645 | } |
| 646 | 646 | } |
| 647 | - if($index_found_at){ |
|
| 647 | + if ($index_found_at) { |
|
| 648 | 648 | $index_in_cache = $index_found_at; |
| 649 | - }else{ |
|
| 649 | + } else { |
|
| 650 | 650 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
| 651 | 651 | //if it wasn't in it to begin with. So we're done |
| 652 | 652 | return $object_to_remove_or_index_into_array; |
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
| 655 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 656 | 656 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
| 657 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
| 658 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
| 657 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 658 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 659 | 659 | $index_in_cache = $index; |
| 660 | 660 | } |
| 661 | 661 | } |
| 662 | - }else{ |
|
| 662 | + } else { |
|
| 663 | 663 | $index_in_cache = $object_to_remove_or_index_into_array; |
| 664 | 664 | } |
| 665 | 665 | //supposedly we've found it. But it could just be that the client code |
| 666 | 666 | //provided a bad index/object |
| 667 | - if(isset( $this->_model_relations[$relationName]) && |
|
| 668 | - isset( $this->_model_relations[$relationName][$index_in_cache])){ |
|
| 667 | + if (isset($this->_model_relations[$relationName]) && |
|
| 668 | + isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
| 669 | 669 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
| 670 | 670 | unset($this->_model_relations[$relationName][$index_in_cache]); |
| 671 | - }else{ |
|
| 671 | + } else { |
|
| 672 | 672 | //that thing was never cached anyways. |
| 673 | 673 | $obj_removed = NULL; |
| 674 | 674 | } |
@@ -687,24 +687,24 @@ discard block |
||
| 687 | 687 | * @param string $current_cache_id - the ID that was used when originally caching the object |
| 688 | 688 | * @return boolean TRUE on success, FALSE on fail |
| 689 | 689 | */ |
| 690 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 690 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 691 | 691 | // verify that incoming object is of the correct type |
| 692 | - $obj_class = 'EE_' . $relationName; |
|
| 693 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
| 692 | + $obj_class = 'EE_'.$relationName; |
|
| 693 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 694 | 694 | /* @type EE_Base_Class $newly_saved_object*/ |
| 695 | 695 | // now get the type of relation |
| 696 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
| 696 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 697 | 697 | // if this is a 1:1 relationship |
| 698 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
| 698 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 699 | 699 | // then just replace the cached object with the newly saved object |
| 700 | 700 | $this->_model_relations[$relationName] = $newly_saved_object; |
| 701 | 701 | return TRUE; |
| 702 | 702 | // or if it's some kind of sordid feral polyamorous relationship... |
| 703 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
| 703 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
| 704 | 704 | // then remove the current cached item |
| 705 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
| 705 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 706 | 706 | // and cache the newly saved object using it's new ID |
| 707 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
| 707 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 708 | 708 | return TRUE; |
| 709 | 709 | } |
| 710 | 710 | } |
@@ -720,11 +720,11 @@ discard block |
||
| 720 | 720 | * @param string $relationName |
| 721 | 721 | * @return EE_Base_Class |
| 722 | 722 | */ |
| 723 | - public function get_one_from_cache($relationName){ |
|
| 724 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
| 725 | - if(is_array($cached_array_or_object)){ |
|
| 723 | + public function get_one_from_cache($relationName) { |
|
| 724 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
| 725 | + if (is_array($cached_array_or_object)) { |
|
| 726 | 726 | return array_shift($cached_array_or_object); |
| 727 | - }else{ |
|
| 727 | + } else { |
|
| 728 | 728 | return $cached_array_or_object; |
| 729 | 729 | } |
| 730 | 730 | } |
@@ -739,14 +739,14 @@ discard block |
||
| 739 | 739 | * @throws \EE_Error |
| 740 | 740 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
| 741 | 741 | */ |
| 742 | - public function get_all_from_cache($relationName){ |
|
| 743 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
| 744 | - if(is_array($cached_array_or_object)){ |
|
| 742 | + public function get_all_from_cache($relationName) { |
|
| 743 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 744 | + if (is_array($cached_array_or_object)) { |
|
| 745 | 745 | $objects = $cached_array_or_object; |
| 746 | - }elseif($cached_array_or_object){ |
|
| 746 | + }elseif ($cached_array_or_object) { |
|
| 747 | 747 | //if the result is not an array, but exists, make it an array |
| 748 | 748 | $objects = array($cached_array_or_object); |
| 749 | - }else{ |
|
| 749 | + } else { |
|
| 750 | 750 | //if nothing was found, return an empty array |
| 751 | 751 | $objects = array(); |
| 752 | 752 | } |
@@ -754,15 +754,15 @@ discard block |
||
| 754 | 754 | //basically, if this model object was stored in the session, and these cached model objects |
| 755 | 755 | //already have IDs, let's make sure they're in their model's entity mapper |
| 756 | 756 | //otherwise we will have duplicates next time we call EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
| 757 | - foreach( $objects as $model_object ){ |
|
| 758 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
| 759 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
| 757 | + foreach ($objects as $model_object) { |
|
| 758 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 759 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 760 | 760 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
| 761 | - if( $model_object->ID() ){ |
|
| 762 | - $model->add_to_entity_map( $model_object ); |
|
| 761 | + if ($model_object->ID()) { |
|
| 762 | + $model->add_to_entity_map($model_object); |
|
| 763 | 763 | } |
| 764 | - }else{ |
|
| 765 | - throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
|
| 764 | + } else { |
|
| 765 | + throw new EE_Error(sprintf(__('Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso'), $relationName, gettype($model_object))); |
|
| 766 | 766 | } |
| 767 | 767 | } |
| 768 | 768 | return $objects; |
@@ -781,13 +781,13 @@ discard block |
||
| 781 | 781 | * |
| 782 | 782 | * @return array|EE_Base_Class[] |
| 783 | 783 | */ |
| 784 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 785 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 786 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 787 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 784 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 785 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 786 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 787 | + if (empty($field) || empty($current_value)) { |
|
| 788 | 788 | return array(); |
| 789 | 789 | } |
| 790 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 790 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | |
@@ -806,13 +806,13 @@ discard block |
||
| 806 | 806 | * |
| 807 | 807 | * @return array|EE_Base_Class[] |
| 808 | 808 | */ |
| 809 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 810 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 811 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 812 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 809 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 810 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 811 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 812 | + if (empty($field) || empty($current_value)) { |
|
| 813 | 813 | return array(); |
| 814 | 814 | } |
| 815 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 815 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * |
| 831 | 831 | * @return array|EE_Base_Class |
| 832 | 832 | */ |
| 833 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 834 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 835 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 836 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 833 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 834 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 835 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 836 | + if (empty($field) || empty($current_value)) { |
|
| 837 | 837 | return array(); |
| 838 | 838 | } |
| 839 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
| 839 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | |
@@ -855,13 +855,13 @@ discard block |
||
| 855 | 855 | * |
| 856 | 856 | * @return array|EE_Base_Class |
| 857 | 857 | */ |
| 858 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 859 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 860 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 861 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 858 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 859 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
| 860 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 861 | + if (empty($field) || empty($current_value)) { |
|
| 862 | 862 | return array(); |
| 863 | 863 | } |
| 864 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
| 864 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | |
@@ -875,25 +875,25 @@ discard block |
||
| 875 | 875 | * @param string $field_name |
| 876 | 876 | * @param mixed $field_value_from_db |
| 877 | 877 | */ |
| 878 | - public function set_from_db($field_name,$field_value_from_db){ |
|
| 878 | + public function set_from_db($field_name, $field_value_from_db) { |
|
| 879 | 879 | $field_obj = $this->get_model()->field_settings_for($field_name); |
| 880 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 880 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 881 | 881 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
| 882 | 882 | //eg, a CPT model object could have an entry in the posts table, but no |
| 883 | 883 | //entry in the meta table. Meaning that all its columns in the meta table |
| 884 | 884 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
| 885 | - if($field_value_from_db === NULL ){ |
|
| 886 | - if( $field_obj->is_nullable()){ |
|
| 885 | + if ($field_value_from_db === NULL) { |
|
| 886 | + if ($field_obj->is_nullable()) { |
|
| 887 | 887 | //if the field allows nulls, then let it be null |
| 888 | 888 | $field_value = NULL; |
| 889 | - }else{ |
|
| 889 | + } else { |
|
| 890 | 890 | $field_value = $field_obj->get_default_value(); |
| 891 | 891 | } |
| 892 | - }else{ |
|
| 893 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
| 892 | + } else { |
|
| 893 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 894 | 894 | } |
| 895 | 895 | $this->_fields[$field_name] = $field_value; |
| 896 | - $this->_clear_cached_property( $field_name ); |
|
| 896 | + $this->_clear_cached_property($field_name); |
|
| 897 | 897 | } |
| 898 | 898 | } |
| 899 | 899 | |
@@ -905,8 +905,8 @@ discard block |
||
| 905 | 905 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
| 906 | 906 | * @return boolean |
| 907 | 907 | */ |
| 908 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
| 909 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
| 908 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
| 909 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | |
@@ -936,11 +936,11 @@ discard block |
||
| 936 | 936 | * just null is returned (because that indicates that likely |
| 937 | 937 | * this field is nullable). |
| 938 | 938 | */ |
| 939 | - public function get_DateTime_object( $field_name ) { |
|
| 940 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
| 939 | + public function get_DateTime_object($field_name) { |
|
| 940 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 941 | 941 | |
| 942 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
| 943 | - EE_Error::add_error( sprintf( __('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso' ), $field_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 942 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 943 | + EE_Error::add_error(sprintf(__('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso'), $field_name), __FILE__, __FUNCTION__, __LINE__); |
|
| 944 | 944 | return false; |
| 945 | 945 | } |
| 946 | 946 | |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
| 957 | 957 | * @return void |
| 958 | 958 | */ |
| 959 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
| 959 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
| 960 | 960 | echo $this->get_pretty($field_name, $extra_cache_ref); |
| 961 | 961 | } |
| 962 | 962 | /** |
@@ -965,8 +965,8 @@ discard block |
||
| 965 | 965 | * @param string $field_name |
| 966 | 966 | * @return void |
| 967 | 967 | */ |
| 968 | - public function f($field_name){ |
|
| 969 | - $this->e($field_name,'form_input'); |
|
| 968 | + public function f($field_name) { |
|
| 969 | + $this->e($field_name, 'form_input'); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -975,8 +975,8 @@ discard block |
||
| 975 | 975 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
| 976 | 976 | * @return mixed |
| 977 | 977 | */ |
| 978 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
| 979 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
| 978 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
| 979 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
@@ -993,37 +993,37 @@ discard block |
||
| 993 | 993 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
| 994 | 994 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
| 995 | 995 | */ |
| 996 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
| 996 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
| 997 | 997 | |
| 998 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 998 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 999 | 999 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
| 1000 | 1000 | |
| 1001 | 1001 | //validate field for datetime and returns field settings if valid. |
| 1002 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
| 1002 | + $field = $this->_get_dtt_field_settings($field_name); |
|
| 1003 | 1003 | |
| 1004 | 1004 | //clear cached property if either formats are not null. |
| 1005 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
| 1006 | - $this->_clear_cached_property( $field_name ); |
|
| 1005 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
| 1006 | + $this->_clear_cached_property($field_name); |
|
| 1007 | 1007 | //reset format properties because they are used in get() |
| 1008 | 1008 | $this->_dt_frmt = $in_dt_frmt; |
| 1009 | 1009 | $this->_tm_frmt = $in_tm_frmt; |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - if ( $echo ) |
|
| 1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
| 1012 | + if ($echo) |
|
| 1013 | + $field->set_pretty_date_format($in_dt_frmt); |
|
| 1014 | 1014 | else |
| 1015 | - $field->set_date_format( $in_dt_frmt ); |
|
| 1015 | + $field->set_date_format($in_dt_frmt); |
|
| 1016 | 1016 | |
| 1017 | - if ( $echo ) |
|
| 1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
| 1017 | + if ($echo) |
|
| 1018 | + $field->set_pretty_time_format($in_tm_frmt); |
|
| 1019 | 1019 | else |
| 1020 | - $field->set_time_format( $in_tm_frmt ); |
|
| 1020 | + $field->set_time_format($in_tm_frmt); |
|
| 1021 | 1021 | |
| 1022 | 1022 | //set timezone in field object |
| 1023 | - $field->set_timezone( $this->_timezone ); |
|
| 1023 | + $field->set_timezone($this->_timezone); |
|
| 1024 | 1024 | |
| 1025 | 1025 | //set the output returned |
| 1026 | - switch ( $date_or_time ) { |
|
| 1026 | + switch ($date_or_time) { |
|
| 1027 | 1027 | |
| 1028 | 1028 | case 'D' : |
| 1029 | 1029 | $field->set_date_time_output('date'); |
@@ -1038,11 +1038,11 @@ discard block |
||
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | |
| 1041 | - if ( $echo ) { |
|
| 1042 | - $this->e( $field_name, $date_or_time ); |
|
| 1041 | + if ($echo) { |
|
| 1042 | + $this->e($field_name, $date_or_time); |
|
| 1043 | 1043 | return ''; |
| 1044 | 1044 | } |
| 1045 | - return $this->get( $field_name, $date_or_time ); |
|
| 1045 | + return $this->get($field_name, $date_or_time); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | |
@@ -1052,8 +1052,8 @@ discard block |
||
| 1052 | 1052 | * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
| 1053 | 1053 | * @return string datetime value formatted |
| 1054 | 1054 | */ |
| 1055 | - public function get_date( $field_name, $format = NULL ) { |
|
| 1056 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
| 1055 | + public function get_date($field_name, $format = NULL) { |
|
| 1056 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | |
@@ -1062,8 +1062,8 @@ discard block |
||
| 1062 | 1062 | * @param $field_name |
| 1063 | 1063 | * @param null $format |
| 1064 | 1064 | */ |
| 1065 | - public function e_date( $field_name, $format = NULL ) { |
|
| 1066 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
| 1065 | + public function e_date($field_name, $format = NULL) { |
|
| 1066 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | |
@@ -1073,8 +1073,8 @@ discard block |
||
| 1073 | 1073 | * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
| 1074 | 1074 | * @return string datetime value formatted |
| 1075 | 1075 | */ |
| 1076 | - public function get_time( $field_name, $format = NULL ) { |
|
| 1077 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
| 1076 | + public function get_time($field_name, $format = NULL) { |
|
| 1077 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | |
@@ -1083,8 +1083,8 @@ discard block |
||
| 1083 | 1083 | * @param $field_name |
| 1084 | 1084 | * @param null $format |
| 1085 | 1085 | */ |
| 1086 | - public function e_time( $field_name, $format = NULL ) { |
|
| 1087 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
| 1086 | + public function e_time($field_name, $format = NULL) { |
|
| 1087 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | |
@@ -1097,8 +1097,8 @@ discard block |
||
| 1097 | 1097 | * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
| 1098 | 1098 | * @return string datetime value formatted |
| 1099 | 1099 | */ |
| 1100 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1101 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
| 1100 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1101 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1108,8 +1108,8 @@ discard block |
||
| 1108 | 1108 | * @param null $dt_frmt |
| 1109 | 1109 | * @param null $tm_frmt |
| 1110 | 1110 | */ |
| 1111 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1112 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1111 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1112 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | |
@@ -1124,10 +1124,10 @@ discard block |
||
| 1124 | 1124 | * @return string Date and time string in set locale or false if no field exists for the given |
| 1125 | 1125 | * field name. |
| 1126 | 1126 | */ |
| 1127 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
| 1128 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
| 1129 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1130 | - return date_i18n( $format, EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) ); |
|
| 1127 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
| 1128 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
| 1129 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
| 1130 | + return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | |
@@ -1139,14 +1139,14 @@ discard block |
||
| 1139 | 1139 | * @throws EE_Error |
| 1140 | 1140 | * @return EE_Datetime_Field |
| 1141 | 1141 | */ |
| 1142 | - protected function _get_dtt_field_settings( $field_name ) { |
|
| 1142 | + protected function _get_dtt_field_settings($field_name) { |
|
| 1143 | 1143 | $field = $this->get_model()->field_settings_for($field_name); |
| 1144 | 1144 | |
| 1145 | 1145 | //check if field is dtt |
| 1146 | - if ( $field instanceof EE_Datetime_Field ) { |
|
| 1146 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1147 | 1147 | return $field; |
| 1148 | 1148 | } else { |
| 1149 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
| 1149 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | 1152 | |
@@ -1167,8 +1167,8 @@ discard block |
||
| 1167 | 1167 | * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
| 1168 | 1168 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
| 1169 | 1169 | */ |
| 1170 | - protected function _set_time_for( $time, $fieldname ) { |
|
| 1171 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
| 1170 | + protected function _set_time_for($time, $fieldname) { |
|
| 1171 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | |
@@ -1182,8 +1182,8 @@ discard block |
||
| 1182 | 1182 | * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
| 1183 | 1183 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
| 1184 | 1184 | */ |
| 1185 | - protected function _set_date_for( $date, $fieldname ) { |
|
| 1186 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
| 1185 | + protected function _set_date_for($date, $fieldname) { |
|
| 1186 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | |
@@ -1199,21 +1199,21 @@ discard block |
||
| 1199 | 1199 | * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
| 1200 | 1200 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
| 1201 | 1201 | */ |
| 1202 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
| 1203 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
| 1204 | - $field->set_timezone( $this->_timezone ); |
|
| 1205 | - $field->set_date_format( $this->_dt_frmt ); |
|
| 1206 | - $field->set_time_format( $this->_tm_frmt ); |
|
| 1202 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
| 1203 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1204 | + $field->set_timezone($this->_timezone); |
|
| 1205 | + $field->set_date_format($this->_dt_frmt); |
|
| 1206 | + $field->set_time_format($this->_tm_frmt); |
|
| 1207 | 1207 | |
| 1208 | - switch ( $what ) { |
|
| 1208 | + switch ($what) { |
|
| 1209 | 1209 | case 'T' : |
| 1210 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( $datetime_value, $this->_fields[$fieldname] ); |
|
| 1210 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time($datetime_value, $this->_fields[$fieldname]); |
|
| 1211 | 1211 | break; |
| 1212 | 1212 | case 'D' : |
| 1213 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( $datetime_value, $this->_fields[$fieldname] ); |
|
| 1213 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date($datetime_value, $this->_fields[$fieldname]); |
|
| 1214 | 1214 | break; |
| 1215 | 1215 | case 'B' : |
| 1216 | - $this->_fields[$fieldname] = $field->prepare_for_set( $datetime_value ); |
|
| 1216 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1217 | 1217 | break; |
| 1218 | 1218 | } |
| 1219 | 1219 | |
@@ -1236,25 +1236,25 @@ discard block |
||
| 1236 | 1236 | * @throws EE_Error |
| 1237 | 1237 | * @return string timestamp |
| 1238 | 1238 | */ |
| 1239 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
| 1239 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
| 1240 | 1240 | EE_Registry::instance()->load_helper('DTT_Helper'); |
| 1241 | 1241 | $timezone = EEH_DTT_Helper::get_timezone(); |
| 1242 | 1242 | |
| 1243 | - if ( $timezone == $this->_timezone ) |
|
| 1243 | + if ($timezone == $this->_timezone) |
|
| 1244 | 1244 | return ''; |
| 1245 | 1245 | |
| 1246 | 1246 | $original_timezone = $this->_timezone; |
| 1247 | - $this->set_timezone( $timezone ); |
|
| 1247 | + $this->set_timezone($timezone); |
|
| 1248 | 1248 | |
| 1249 | 1249 | $fn = (array) $field_name; |
| 1250 | - $args = array_merge( $fn, (array) $args ); |
|
| 1250 | + $args = array_merge($fn, (array) $args); |
|
| 1251 | 1251 | |
| 1252 | - if ( !method_exists( $this, $callback ) ) |
|
| 1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
| 1252 | + if ( ! method_exists($this, $callback)) |
|
| 1253 | + throw new EE_Error(sprintf(__('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback)); |
|
| 1254 | 1254 | $args = (array) $args; |
| 1255 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
| 1255 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
| 1256 | 1256 | |
| 1257 | - $this->set_timezone( $original_timezone ); |
|
| 1257 | + $this->set_timezone($original_timezone); |
|
| 1258 | 1258 | return $return; |
| 1259 | 1259 | } |
| 1260 | 1260 | |
@@ -1265,15 +1265,15 @@ discard block |
||
| 1265 | 1265 | * Deletes this model object. That may mean just 'soft deleting' it though. |
| 1266 | 1266 | * @return boolean | int |
| 1267 | 1267 | */ |
| 1268 | - public function delete(){ |
|
| 1268 | + public function delete() { |
|
| 1269 | 1269 | /** |
| 1270 | 1270 | * Called just before SOFT deleting a model object (if soft deleting is |
| 1271 | 1271 | * possible for this model; otherwise a regular hard delete it performed) |
| 1272 | 1272 | * |
| 1273 | 1273 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1274 | 1274 | */ |
| 1275 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
| 1276 | - $result = $this->get_model()->delete_by_ID( $this->ID() ); |
|
| 1275 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1276 | + $result = $this->get_model()->delete_by_ID($this->ID()); |
|
| 1277 | 1277 | $this->refresh_cache_of_related_objects(); |
| 1278 | 1278 | /** |
| 1279 | 1279 | * Called just after SOFT deleting a model object (if soft deleting is |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1282 | 1282 | * @param boolean $result |
| 1283 | 1283 | */ |
| 1284 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
| 1284 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1285 | 1285 | return $result; |
| 1286 | 1286 | } |
| 1287 | 1287 | |
@@ -1291,22 +1291,22 @@ discard block |
||
| 1291 | 1291 | * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
| 1292 | 1292 | * @return bool |
| 1293 | 1293 | */ |
| 1294 | - public function delete_permanently(){ |
|
| 1294 | + public function delete_permanently() { |
|
| 1295 | 1295 | /** |
| 1296 | 1296 | * Called just before HARD deleting a model object |
| 1297 | 1297 | * |
| 1298 | 1298 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1299 | 1299 | */ |
| 1300 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this ); |
|
| 1301 | - $model=$this->get_model(); |
|
| 1302 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
| 1300 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1301 | + $model = $this->get_model(); |
|
| 1302 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1303 | 1303 | $this->refresh_cache_of_related_objects(); |
| 1304 | 1304 | /** |
| 1305 | 1305 | * Called just after HARD deleting a model object |
| 1306 | 1306 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1307 | 1307 | * @param boolean $result |
| 1308 | 1308 | */ |
| 1309 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result ); |
|
| 1309 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1310 | 1310 | return $result ? true : false; |
| 1311 | 1311 | } |
| 1312 | 1312 | |
@@ -1315,18 +1315,18 @@ discard block |
||
| 1315 | 1315 | * related model objects |
| 1316 | 1316 | */ |
| 1317 | 1317 | public function refresh_cache_of_related_objects() { |
| 1318 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1319 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1320 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1321 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1318 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1319 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1320 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1321 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1322 | 1322 | //this relation only stores a single model object, not an array |
| 1323 | 1323 | //but let's make it consistent |
| 1324 | - $related_objects = array( $related_objects ); |
|
| 1324 | + $related_objects = array($related_objects); |
|
| 1325 | 1325 | } |
| 1326 | - foreach( $related_objects as $related_object ) { |
|
| 1326 | + foreach ($related_objects as $related_object) { |
|
| 1327 | 1327 | //only refresh their cache if they're in memory |
| 1328 | - if( $related_object instanceof EE_Base_Class ) { |
|
| 1329 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1328 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1329 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1330 | 1330 | } |
| 1331 | 1331 | } |
| 1332 | 1332 | } |
@@ -1346,17 +1346,17 @@ discard block |
||
| 1346 | 1346 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
| 1347 | 1347 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
| 1348 | 1348 | */ |
| 1349 | - public function save($set_cols_n_values=array()) { |
|
| 1349 | + public function save($set_cols_n_values = array()) { |
|
| 1350 | 1350 | /** |
| 1351 | 1351 | * Filters the fields we're about to save on the model object |
| 1352 | 1352 | * |
| 1353 | 1353 | * @param array $set_cols_n_values |
| 1354 | 1354 | * @param EE_Base_Class $model_object |
| 1355 | 1355 | */ |
| 1356 | - $set_cols_n_values = apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
| 1356 | + $set_cols_n_values = apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
| 1357 | 1357 | //set attributes as provided in $set_cols_n_values |
| 1358 | - foreach($set_cols_n_values as $column=>$value){ |
|
| 1359 | - $this->set($column,$value); |
|
| 1358 | + foreach ($set_cols_n_values as $column=>$value) { |
|
| 1359 | + $this->set($column, $value); |
|
| 1360 | 1360 | } |
| 1361 | 1361 | /** |
| 1362 | 1362 | * Saving a model object. |
@@ -1364,8 +1364,8 @@ discard block |
||
| 1364 | 1364 | * Before we perform a save, this action is fired. |
| 1365 | 1365 | * @param EE_Base_Class $model_object the model object about to be saved. |
| 1366 | 1366 | */ |
| 1367 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
| 1368 | - if( ! $this->allow_persist() ) { |
|
| 1367 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1368 | + if ( ! $this->allow_persist()) { |
|
| 1369 | 1369 | return 0; |
| 1370 | 1370 | } |
| 1371 | 1371 | //now get current attribute values |
@@ -1375,61 +1375,61 @@ discard block |
||
| 1375 | 1375 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
| 1376 | 1376 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
| 1377 | 1377 | //does this model have an autoincrement PK? |
| 1378 | - if($this->get_model()->has_primary_key_field()){ |
|
| 1379 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
| 1378 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1379 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1380 | 1380 | //ok check if it's set, if so: update; if not, insert |
| 1381 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
| 1382 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
| 1381 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1382 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1383 | 1383 | } else { |
| 1384 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
| 1385 | - $results = $this->get_model()->insert( $save_cols_n_values, true); |
|
| 1386 | - if($results){ |
|
| 1384 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1385 | + $results = $this->get_model()->insert($save_cols_n_values, true); |
|
| 1386 | + if ($results) { |
|
| 1387 | 1387 | //if successful, set the primary key |
| 1388 | 1388 | //but don't use the normal SET method, because it will check if |
| 1389 | 1389 | //an item with the same ID exists in the mapper & db, then |
| 1390 | 1390 | //will find it in the db (because we just added it) and THAT object |
| 1391 | 1391 | //will get added to the mapper before we can add this one! |
| 1392 | 1392 | //but if we just avoid using the SET method, all that headache can be avoided |
| 1393 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
| 1393 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1394 | 1394 | $this->_fields[$pk_field_name] = $results; |
| 1395 | 1395 | $this->_clear_cached_property($pk_field_name); |
| 1396 | - $this->get_model()->add_to_entity_map( $this ); |
|
| 1396 | + $this->get_model()->add_to_entity_map($this); |
|
| 1397 | 1397 | $this->_update_cached_related_model_objs_fks(); |
| 1398 | 1398 | } |
| 1399 | 1399 | } |
| 1400 | - }else{//PK is NOT auto-increment |
|
| 1400 | + } else {//PK is NOT auto-increment |
|
| 1401 | 1401 | //so check if one like it already exists in the db |
| 1402 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
| 1403 | - if( ! $this->in_entity_map() && WP_DEBUG ){ |
|
| 1402 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1403 | + if ( ! $this->in_entity_map() && WP_DEBUG) { |
|
| 1404 | 1404 | throw new EE_Error( |
| 1405 | 1405 | sprintf( |
| 1406 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
| 1406 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
| 1407 | 1407 | get_class($this), |
| 1408 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 1409 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
| 1408 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 1409 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
| 1410 | 1410 | '<br />' |
| 1411 | 1411 | ) |
| 1412 | 1412 | ); |
| 1413 | 1413 | } |
| 1414 | 1414 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
| 1415 | - }else{ |
|
| 1415 | + } else { |
|
| 1416 | 1416 | $results = $this->get_model()->insert($save_cols_n_values); |
| 1417 | 1417 | $this->_update_cached_related_model_objs_fks(); |
| 1418 | 1418 | } |
| 1419 | 1419 | } |
| 1420 | - }else{//there is NO primary key |
|
| 1420 | + } else {//there is NO primary key |
|
| 1421 | 1421 | $already_in_db = false; |
| 1422 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
| 1422 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1423 | 1423 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
| 1424 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
| 1424 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1425 | 1425 | $already_in_db = true; |
| 1426 | 1426 | } |
| 1427 | 1427 | } |
| 1428 | - if( $already_in_db ){ |
|
| 1429 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
| 1430 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
| 1431 | - }else{ |
|
| 1432 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
| 1428 | + if ($already_in_db) { |
|
| 1429 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
| 1430 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1431 | + } else { |
|
| 1432 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1433 | 1433 | } |
| 1434 | 1434 | } |
| 1435 | 1435 | //restore the old assumption about values being prepared by the model object |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
| 1443 | 1443 | * the new ID (or 0 if an error occurred and it wasn't updated) |
| 1444 | 1444 | */ |
| 1445 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
| 1445 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1446 | 1446 | return $results; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
@@ -1454,13 +1454,13 @@ discard block |
||
| 1454 | 1454 | * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
| 1455 | 1455 | * @return void |
| 1456 | 1456 | */ |
| 1457 | - protected function _update_cached_related_model_objs_fks(){ |
|
| 1458 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
| 1459 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
| 1460 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
| 1461 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( $this->get_model()->get_this_model_name() ); |
|
| 1462 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
| 1463 | - if( $related_model_obj_in_cache->ID() ){ |
|
| 1457 | + protected function _update_cached_related_model_objs_fks() { |
|
| 1458 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1459 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1460 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1461 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to($this->get_model()->get_this_model_name()); |
|
| 1462 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1463 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1464 | 1464 | $related_model_obj_in_cache->save(); |
| 1465 | 1465 | } |
| 1466 | 1466 | } |
@@ -1476,21 +1476,21 @@ discard block |
||
| 1476 | 1476 | * and this object and properly setup |
| 1477 | 1477 | * @return int ID of new model object on save; 0 on failure+ |
| 1478 | 1478 | */ |
| 1479 | - public function save_new_cached_related_model_objs(){ |
|
| 1479 | + public function save_new_cached_related_model_objs() { |
|
| 1480 | 1480 | //make sure this has been saved |
| 1481 | - if( ! $this->ID()){ |
|
| 1481 | + if ( ! $this->ID()) { |
|
| 1482 | 1482 | $id = $this->save(); |
| 1483 | - }else{ |
|
| 1483 | + } else { |
|
| 1484 | 1484 | $id = $this->ID(); |
| 1485 | 1485 | } |
| 1486 | 1486 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
| 1487 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
| 1487 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1488 | 1488 | |
| 1489 | 1489 | |
| 1490 | - if($this->_model_relations[$relationName]){ |
|
| 1490 | + if ($this->_model_relations[$relationName]) { |
|
| 1491 | 1491 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
| 1492 | 1492 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
| 1493 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
| 1493 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1494 | 1494 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1495 | 1495 | //but ONLY if it DOES NOT exist in the DB |
| 1496 | 1496 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1499,8 +1499,8 @@ discard block |
||
| 1499 | 1499 | $this->_add_relation_to($related_model_obj, $relationName); |
| 1500 | 1500 | $related_model_obj->save_new_cached_related_model_objs(); |
| 1501 | 1501 | // } |
| 1502 | - }else{ |
|
| 1503 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
| 1502 | + } else { |
|
| 1503 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1504 | 1504 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1505 | 1505 | //but ONLY if it DOES NOT exist in the DB |
| 1506 | 1506 | // if( ! $related_model_obj->ID()){ |
@@ -1521,8 +1521,8 @@ discard block |
||
| 1521 | 1521 | * @return \EEM_Base | \EEM_CPT_Base |
| 1522 | 1522 | */ |
| 1523 | 1523 | public function get_model() { |
| 1524 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
| 1525 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
| 1524 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1525 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | |
@@ -1532,10 +1532,10 @@ discard block |
||
| 1532 | 1532 | * @param $classname |
| 1533 | 1533 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
| 1534 | 1534 | */ |
| 1535 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
| 1535 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
| 1536 | 1536 | //TODO: will not work for Term_Relationships because they have no PK! |
| 1537 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1538 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
| 1537 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1538 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1539 | 1539 | $id = $props_n_values[$primary_id_ref]; |
| 1540 | 1540 | return self::_get_model($classname)->get_from_entity_map($id); |
| 1541 | 1541 | } |
@@ -1552,24 +1552,24 @@ discard block |
||
| 1552 | 1552 | * @param null $timezone |
| 1553 | 1553 | * @return mixed (EE_Base_Class|bool) |
| 1554 | 1554 | */ |
| 1555 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
|
| 1556 | - if( self::_get_model( $classname )->has_primary_key_field()){ |
|
| 1557 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1555 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL) { |
|
| 1556 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1557 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1558 | 1558 | |
| 1559 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
| 1560 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
|
| 1561 | - }else{ |
|
| 1559 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1560 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID($props_n_values[$primary_id_ref]); |
|
| 1561 | + } else { |
|
| 1562 | 1562 | $existing = null; |
| 1563 | 1563 | } |
| 1564 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
| 1564 | + }elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1565 | 1565 | //no primary key on this model, but there's still a matching item in the DB |
| 1566 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
|
| 1567 | - }else{ |
|
| 1566 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID(self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)); |
|
| 1567 | + } else { |
|
| 1568 | 1568 | $existing = null; |
| 1569 | 1569 | } |
| 1570 | - if ( $existing ) { |
|
| 1571 | - foreach ( $props_n_values as $property => $field_value ) { |
|
| 1572 | - $existing->set( $property, $field_value ); |
|
| 1570 | + if ($existing) { |
|
| 1571 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1572 | + $existing->set($property, $field_value); |
|
| 1573 | 1573 | } |
| 1574 | 1574 | return $existing; |
| 1575 | 1575 | } else { |
@@ -1587,13 +1587,13 @@ discard block |
||
| 1587 | 1587 | * @throws EE_Error |
| 1588 | 1588 | * @return EEM_Base |
| 1589 | 1589 | */ |
| 1590 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
| 1590 | + protected static function _get_model($classname, $timezone = NULL) { |
|
| 1591 | 1591 | //find model for this class |
| 1592 | - if( ! $classname ){ |
|
| 1593 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"),$classname)); |
|
| 1592 | + if ( ! $classname) { |
|
| 1593 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"), $classname)); |
|
| 1594 | 1594 | } |
| 1595 | - $modelName=self::_get_model_classname($classname); |
|
| 1596 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
| 1595 | + $modelName = self::_get_model_classname($classname); |
|
| 1596 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | |
@@ -1604,10 +1604,10 @@ discard block |
||
| 1604 | 1604 | * @param null $timezone |
| 1605 | 1605 | * @return EEM_Base |
| 1606 | 1606 | */ |
| 1607 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
| 1608 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
| 1609 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
| 1610 | - $model->set_timezone( $timezone ); |
|
| 1607 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
| 1608 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1609 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1610 | + $model->set_timezone($timezone); |
|
| 1611 | 1611 | return $model; |
| 1612 | 1612 | } |
| 1613 | 1613 | |
@@ -1619,10 +1619,10 @@ discard block |
||
| 1619 | 1619 | * @param null $model_name |
| 1620 | 1620 | * @return string like EEM_Attendee |
| 1621 | 1621 | */ |
| 1622 | - private static function _get_model_classname( $model_name = null){ |
|
| 1623 | - if(strpos($model_name,"EE_")===0){ |
|
| 1624 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
| 1625 | - }else{ |
|
| 1622 | + private static function _get_model_classname($model_name = null) { |
|
| 1623 | + if (strpos($model_name, "EE_") === 0) { |
|
| 1624 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1625 | + } else { |
|
| 1626 | 1626 | $model_classname = "EEM_".$model_name; |
| 1627 | 1627 | } |
| 1628 | 1628 | return $model_classname; |
@@ -1636,11 +1636,11 @@ discard block |
||
| 1636 | 1636 | * @throws EE_Error |
| 1637 | 1637 | * @return string |
| 1638 | 1638 | */ |
| 1639 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
| 1640 | - if( ! $classname){ |
|
| 1641 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),$classname)); |
|
| 1639 | + protected static function _get_primary_key_name($classname = NULL) { |
|
| 1640 | + if ( ! $classname) { |
|
| 1641 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), $classname)); |
|
| 1642 | 1642 | } |
| 1643 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
| 1643 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | |
@@ -1652,12 +1652,12 @@ discard block |
||
| 1652 | 1652 | * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
| 1653 | 1653 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
| 1654 | 1654 | */ |
| 1655 | - public function ID(){ |
|
| 1655 | + public function ID() { |
|
| 1656 | 1656 | //now that we know the name of the variable, use a variable variable to get its value and return its |
| 1657 | - if( $this->get_model()->has_primary_key_field() ) { |
|
| 1658 | - return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
|
| 1659 | - }else{ |
|
| 1660 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
| 1657 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1658 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1659 | + } else { |
|
| 1660 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | } |
| 1663 | 1663 | |
@@ -1675,38 +1675,38 @@ discard block |
||
| 1675 | 1675 | * @throws EE_Error |
| 1676 | 1676 | * @return EE_Base_Class the object the relation was added to |
| 1677 | 1677 | */ |
| 1678 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
| 1678 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
| 1679 | 1679 | //if this thing exists in the DB, save the relation to the DB |
| 1680 | - if( $this->ID() ){ |
|
| 1681 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
| 1680 | + if ($this->ID()) { |
|
| 1681 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
| 1682 | 1682 | //clear cache so future get_many_related and get_first_related() return new results. |
| 1683 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
| 1684 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1685 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1683 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
| 1684 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1685 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1686 | 1686 | } |
| 1687 | 1687 | } else { |
| 1688 | 1688 | //this thing doesn't exist in the DB, so just cache it |
| 1689 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
| 1690 | - throw new EE_Error( sprintf( |
|
| 1691 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
| 1689 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1690 | + throw new EE_Error(sprintf( |
|
| 1691 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
| 1692 | 1692 | $otherObjectModelObjectOrID, |
| 1693 | - get_class( $this ) |
|
| 1693 | + get_class($this) |
|
| 1694 | 1694 | )); |
| 1695 | 1695 | } else { |
| 1696 | 1696 | $otherObject = $otherObjectModelObjectOrID; |
| 1697 | 1697 | } |
| 1698 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
| 1698 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1699 | 1699 | } |
| 1700 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1700 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1701 | 1701 | //fix the reciprocal relation too |
| 1702 | - if( $otherObject->ID() ) { |
|
| 1702 | + if ($otherObject->ID()) { |
|
| 1703 | 1703 | //its saved so assumed relations exist in the DB, so we can just |
| 1704 | 1704 | //clear the cache so future queries use the updated info in the DB |
| 1705 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1705 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1706 | 1706 | } else { |
| 1707 | 1707 | |
| 1708 | 1708 | //it's not saved, so it caches relations like this |
| 1709 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1709 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1710 | 1710 | } |
| 1711 | 1711 | } |
| 1712 | 1712 | return $otherObject; |
@@ -1729,17 +1729,17 @@ discard block |
||
| 1729 | 1729 | * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
| 1730 | 1730 | * @return EE_Base_Class the relation was removed from |
| 1731 | 1731 | */ |
| 1732 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
| 1733 | - if ( $this->ID() ) { |
|
| 1732 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
| 1733 | + if ($this->ID()) { |
|
| 1734 | 1734 | //if this exists in the DB, save the relation change to the DB too |
| 1735 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
| 1736 | - $this->clear_cache( $relationName, $otherObject ); |
|
| 1735 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
| 1736 | + $this->clear_cache($relationName, $otherObject); |
|
| 1737 | 1737 | } else { |
| 1738 | 1738 | //this doesn't exist in the DB, just remove it from the cache |
| 1739 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
| 1739 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 1740 | 1740 | } |
| 1741 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1742 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1741 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1742 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1743 | 1743 | } |
| 1744 | 1744 | return $otherObject; |
| 1745 | 1745 | } |
@@ -1750,18 +1750,18 @@ discard block |
||
| 1750 | 1750 | * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
| 1751 | 1751 | * @return EE_Base_Class |
| 1752 | 1752 | */ |
| 1753 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
| 1754 | - if ( $this->ID() ) { |
|
| 1753 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
| 1754 | + if ($this->ID()) { |
|
| 1755 | 1755 | //if this exists in the DB, save the relation change to the DB too |
| 1756 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
| 1757 | - $this->clear_cache( $relationName, null, true ); |
|
| 1756 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 1757 | + $this->clear_cache($relationName, null, true); |
|
| 1758 | 1758 | } else { |
| 1759 | 1759 | //this doesn't exist in the DB, just remove it from the cache |
| 1760 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
| 1760 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 1761 | 1761 | } |
| 1762 | - if( is_array( $otherObjects ) ) { |
|
| 1763 | - foreach ( $otherObjects as $otherObject ) { |
|
| 1764 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1762 | + if (is_array($otherObjects)) { |
|
| 1763 | + foreach ($otherObjects as $otherObject) { |
|
| 1764 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1765 | 1765 | } |
| 1766 | 1766 | } |
| 1767 | 1767 | return $otherObjects; |
@@ -1779,26 +1779,26 @@ discard block |
||
| 1779 | 1779 | * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
| 1780 | 1780 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
| 1781 | 1781 | */ |
| 1782 | - public function get_many_related($relationName,$query_params = array()){ |
|
| 1783 | - if($this->ID()){//this exists in the DB, so get the related things from either the cache or the DB |
|
| 1782 | + public function get_many_related($relationName, $query_params = array()) { |
|
| 1783 | + if ($this->ID()) {//this exists in the DB, so get the related things from either the cache or the DB |
|
| 1784 | 1784 | //if there are query parameters, forget about caching the related model objects. |
| 1785 | - if( $query_params ){ |
|
| 1785 | + if ($query_params) { |
|
| 1786 | 1786 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1787 | - }else{ |
|
| 1787 | + } else { |
|
| 1788 | 1788 | //did we already cache the result of this query? |
| 1789 | 1789 | $cached_results = $this->get_all_from_cache($relationName); |
| 1790 | - if ( ! $cached_results ){ |
|
| 1790 | + if ( ! $cached_results) { |
|
| 1791 | 1791 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1792 | 1792 | //if no query parameters were passed, then we got all the related model objects |
| 1793 | 1793 | //for that relation. We can cache them then. |
| 1794 | - foreach($related_model_objects as $related_model_object){ |
|
| 1794 | + foreach ($related_model_objects as $related_model_object) { |
|
| 1795 | 1795 | $this->cache($relationName, $related_model_object); |
| 1796 | 1796 | } |
| 1797 | - }else{ |
|
| 1797 | + } else { |
|
| 1798 | 1798 | $related_model_objects = $cached_results; |
| 1799 | 1799 | } |
| 1800 | 1800 | } |
| 1801 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
| 1801 | + } else {//this doesn't exist itn eh DB, so just get the related things from the cache |
|
| 1802 | 1802 | $related_model_objects = $this->get_all_from_cache($relationName); |
| 1803 | 1803 | } |
| 1804 | 1804 | return $related_model_objects; |
@@ -1815,8 +1815,8 @@ discard block |
||
| 1815 | 1815 | * @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; |
| 1816 | 1816 | * @return int |
| 1817 | 1817 | */ |
| 1818 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
| 1819 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
| 1818 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
| 1819 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | |
@@ -1830,7 +1830,7 @@ discard block |
||
| 1830 | 1830 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
| 1831 | 1831 | * @return int |
| 1832 | 1832 | */ |
| 1833 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
| 1833 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
| 1834 | 1834 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
| 1835 | 1835 | } |
| 1836 | 1836 | |
@@ -1842,34 +1842,34 @@ discard block |
||
| 1842 | 1842 | * @param array $query_params like EEM_Base::get_all |
| 1843 | 1843 | * @return EE_Base_Class (not an array, a single object) |
| 1844 | 1844 | */ |
| 1845 | - public function get_first_related($relationName,$query_params = array()){ |
|
| 1846 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
| 1845 | + public function get_first_related($relationName, $query_params = array()) { |
|
| 1846 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 1847 | 1847 | |
| 1848 | 1848 | //if they've provided some query parameters, don't bother trying to cache the result |
| 1849 | 1849 | //also make sure we're not caching the result of get_first_related |
| 1850 | 1850 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
| 1851 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 1852 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 1853 | - }else{ |
|
| 1851 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 1852 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 1853 | + } else { |
|
| 1854 | 1854 | //first, check if we've already cached the result of this query |
| 1855 | 1855 | $cached_result = $this->get_one_from_cache($relationName); |
| 1856 | - if ( ! $cached_result ){ |
|
| 1856 | + if ( ! $cached_result) { |
|
| 1857 | 1857 | |
| 1858 | 1858 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 1859 | - $this->cache($relationName,$related_model_object); |
|
| 1860 | - }else{ |
|
| 1859 | + $this->cache($relationName, $related_model_object); |
|
| 1860 | + } else { |
|
| 1861 | 1861 | $related_model_object = $cached_result; |
| 1862 | 1862 | } |
| 1863 | 1863 | } |
| 1864 | - }else{ |
|
| 1864 | + } else { |
|
| 1865 | 1865 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
| 1866 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 1867 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 1868 | - }else{ |
|
| 1866 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 1867 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 1868 | + } else { |
|
| 1869 | 1869 | $related_model_object = null; |
| 1870 | 1870 | } |
| 1871 | 1871 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
| 1872 | - if( ! $related_model_object){ |
|
| 1872 | + if ( ! $related_model_object) { |
|
| 1873 | 1873 | $related_model_object = $this->get_one_from_cache($relationName); |
| 1874 | 1874 | } |
| 1875 | 1875 | |
@@ -1888,12 +1888,12 @@ discard block |
||
| 1888 | 1888 | * @param array $query_params like EEM_Base::get_all's |
| 1889 | 1889 | * @return int how many deleted |
| 1890 | 1890 | */ |
| 1891 | - public function delete_related($relationName,$query_params = array()){ |
|
| 1892 | - if($this->ID()){ |
|
| 1893 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 1894 | - }else{ |
|
| 1891 | + public function delete_related($relationName, $query_params = array()) { |
|
| 1892 | + if ($this->ID()) { |
|
| 1893 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 1894 | + } else { |
|
| 1895 | 1895 | $count = count($this->get_all_from_cache($relationName)); |
| 1896 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 1896 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 1897 | 1897 | } |
| 1898 | 1898 | return $count; |
| 1899 | 1899 | } |
@@ -1908,13 +1908,13 @@ discard block |
||
| 1908 | 1908 | * @param array $query_params like EEM_Base::get_all's |
| 1909 | 1909 | * @return int how many deleted (including those soft deleted) |
| 1910 | 1910 | */ |
| 1911 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
| 1912 | - if($this->ID()){ |
|
| 1913 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 1914 | - }else{ |
|
| 1911 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
| 1912 | + if ($this->ID()) { |
|
| 1913 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 1914 | + } else { |
|
| 1915 | 1915 | $count = count($this->get_all_from_cache($relationName)); |
| 1916 | 1916 | } |
| 1917 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 1917 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 1918 | 1918 | return $count; |
| 1919 | 1919 | } |
| 1920 | 1920 | |
@@ -1930,7 +1930,7 @@ discard block |
||
| 1930 | 1930 | * @param string $field_name property to check |
| 1931 | 1931 | * @return bool TRUE if existing,FALSE if not. |
| 1932 | 1932 | */ |
| 1933 | - public function is_set( $field_name ) { |
|
| 1933 | + public function is_set($field_name) { |
|
| 1934 | 1934 | return isset($this->_fields[$field_name]); |
| 1935 | 1935 | } |
| 1936 | 1936 | |
@@ -1942,12 +1942,12 @@ discard block |
||
| 1942 | 1942 | * @throws EE_Error |
| 1943 | 1943 | * @return bool TRUE if existing, throw EE_Error if not. |
| 1944 | 1944 | */ |
| 1945 | - protected function _property_exists( $properties ) { |
|
| 1945 | + protected function _property_exists($properties) { |
|
| 1946 | 1946 | |
| 1947 | - foreach ( (array) $properties as $property_name ) { |
|
| 1947 | + foreach ((array) $properties as $property_name) { |
|
| 1948 | 1948 | //first make sure this property exists |
| 1949 | - if ( ! $this->_fields[ $property_name ] ) |
|
| 1950 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
| 1949 | + if ( ! $this->_fields[$property_name]) |
|
| 1950 | + throw new EE_Error(sprintf(__('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name)); |
|
| 1951 | 1951 | } |
| 1952 | 1952 | |
| 1953 | 1953 | return TRUE; |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | $fields = $this->get_model()->field_settings(FALSE); |
| 1965 | 1965 | $properties = array(); |
| 1966 | 1966 | //remove prepended underscore |
| 1967 | - foreach ( $fields as $field_name => $settings ) { |
|
| 1967 | + foreach ($fields as $field_name => $settings) { |
|
| 1968 | 1968 | $properties[$field_name] = $this->get($field_name); |
| 1969 | 1969 | } |
| 1970 | 1970 | return $properties; |
@@ -1994,14 +1994,14 @@ discard block |
||
| 1994 | 1994 | * @throws EE_Error |
| 1995 | 1995 | * @return mixed whatever the plugin which calls add_filter decides |
| 1996 | 1996 | */ |
| 1997 | - public function __call($methodName,$args){ |
|
| 1998 | - $className=get_class($this); |
|
| 1999 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
| 2000 | - if(!has_filter($tagName)){ |
|
| 2001 | - throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}","event_espresso"), |
|
| 2002 | - $methodName,$className,$tagName)); |
|
| 1997 | + public function __call($methodName, $args) { |
|
| 1998 | + $className = get_class($this); |
|
| 1999 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2000 | + if ( ! has_filter($tagName)) { |
|
| 2001 | + throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", "event_espresso"), |
|
| 2002 | + $methodName, $className, $tagName)); |
|
| 2003 | 2003 | } |
| 2004 | - return apply_filters($tagName,null,$this,$args); |
|
| 2004 | + return apply_filters($tagName, null, $this, $args); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | |
@@ -2016,22 +2016,22 @@ discard block |
||
| 2016 | 2016 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
| 2017 | 2017 | * NOTE: if the values haven't changed, returns 0 |
| 2018 | 2018 | */ |
| 2019 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
| 2020 | - $query_params = array(array( |
|
| 2019 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
| 2020 | + $query_params = array(array( |
|
| 2021 | 2021 | 'EXM_key'=>$meta_key, |
| 2022 | 2022 | 'OBJ_ID'=>$this->ID(), |
| 2023 | 2023 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
| 2024 | - if($previous_value !== NULL){ |
|
| 2024 | + if ($previous_value !== NULL) { |
|
| 2025 | 2025 | $query_params[0]['EXM_value'] = $meta_value; |
| 2026 | 2026 | } |
| 2027 | 2027 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
| 2028 | - if( ! $existing_rows_like_that){ |
|
| 2028 | + if ( ! $existing_rows_like_that) { |
|
| 2029 | 2029 | return $this->add_extra_meta($meta_key, $meta_value); |
| 2030 | - }else{ |
|
| 2031 | - foreach( $existing_rows_like_that as $existing_row){ |
|
| 2032 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
| 2030 | + } else { |
|
| 2031 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2032 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2033 | 2033 | } |
| 2034 | - return count( $existing_rows_like_that ); |
|
| 2034 | + return count($existing_rows_like_that); |
|
| 2035 | 2035 | } |
| 2036 | 2036 | } |
| 2037 | 2037 | |
@@ -2044,10 +2044,10 @@ discard block |
||
| 2044 | 2044 | * @param boolean $unique |
| 2045 | 2045 | * @return boolean |
| 2046 | 2046 | */ |
| 2047 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
| 2048 | - if($unique){ |
|
| 2049 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key,'OBJ_ID'=>$this->ID(),'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
| 2050 | - if($existing_extra_meta){ |
|
| 2047 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
| 2048 | + if ($unique) { |
|
| 2049 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key, 'OBJ_ID'=>$this->ID(), 'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
| 2050 | + if ($existing_extra_meta) { |
|
| 2051 | 2051 | return false; |
| 2052 | 2052 | } |
| 2053 | 2053 | } |
@@ -2067,12 +2067,12 @@ discard block |
||
| 2067 | 2067 | * @param string $meta_value |
| 2068 | 2068 | * @return int number of extra meta rows deleted |
| 2069 | 2069 | */ |
| 2070 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
| 2071 | - $query_params = array(array( |
|
| 2070 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
| 2071 | + $query_params = array(array( |
|
| 2072 | 2072 | 'EXM_key'=>$meta_key, |
| 2073 | 2073 | 'OBJ_ID'=>$this->ID(), |
| 2074 | 2074 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
| 2075 | - if($meta_value !== NULL){ |
|
| 2075 | + if ($meta_value !== NULL) { |
|
| 2076 | 2076 | $query_params[0]['EXM_value'] = $meta_value; |
| 2077 | 2077 | } |
| 2078 | 2078 | $count_deleted = EEM_Extra_Meta::instance()->delete($query_params); |
@@ -2088,25 +2088,25 @@ discard block |
||
| 2088 | 2088 | * @param mixed $default if we don't find anything, what should we return? |
| 2089 | 2089 | * @return mixed single value if $single; array if ! $single |
| 2090 | 2090 | */ |
| 2091 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
| 2092 | - if($single){ |
|
| 2093 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2094 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2091 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
| 2092 | + if ($single) { |
|
| 2093 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2094 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2095 | 2095 | return $result->value(); |
| 2096 | - }else{ |
|
| 2096 | + } else { |
|
| 2097 | 2097 | return $default; |
| 2098 | 2098 | } |
| 2099 | - }else{ |
|
| 2100 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2101 | - if($results){ |
|
| 2099 | + } else { |
|
| 2100 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2101 | + if ($results) { |
|
| 2102 | 2102 | $values = array(); |
| 2103 | - foreach($results as $result){ |
|
| 2104 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2103 | + foreach ($results as $result) { |
|
| 2104 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2105 | 2105 | $values[$result->ID()] = $result->value(); |
| 2106 | 2106 | } |
| 2107 | 2107 | } |
| 2108 | 2108 | return $values; |
| 2109 | - }else{ |
|
| 2109 | + } else { |
|
| 2110 | 2110 | return $default; |
| 2111 | 2111 | } |
| 2112 | 2112 | } |
@@ -2123,20 +2123,20 @@ discard block |
||
| 2123 | 2123 | * @param boolean $one_of_each_key |
| 2124 | 2124 | * @return array |
| 2125 | 2125 | */ |
| 2126 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
| 2126 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
| 2127 | 2127 | $return_array = array(); |
| 2128 | - if($one_of_each_key){ |
|
| 2128 | + if ($one_of_each_key) { |
|
| 2129 | 2129 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
| 2130 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2131 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2130 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2131 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2132 | 2132 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
| 2133 | 2133 | } |
| 2134 | 2134 | } |
| 2135 | - }else{ |
|
| 2135 | + } else { |
|
| 2136 | 2136 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
| 2137 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2138 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2139 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
| 2137 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2138 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2139 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2140 | 2140 | $return_array[$extra_meta_obj->key()] = array(); |
| 2141 | 2141 | } |
| 2142 | 2142 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2149,19 +2149,19 @@ discard block |
||
| 2149 | 2149 | * Gets a pretty nice displayable nice for this model object. Often overridden |
| 2150 | 2150 | * @return string |
| 2151 | 2151 | */ |
| 2152 | - public function name(){ |
|
| 2152 | + public function name() { |
|
| 2153 | 2153 | //find a field that's not a text field |
| 2154 | 2154 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
| 2155 | - if($field_we_can_use){ |
|
| 2155 | + if ($field_we_can_use) { |
|
| 2156 | 2156 | return $this->get($field_we_can_use->get_name()); |
| 2157 | - }else{ |
|
| 2157 | + } else { |
|
| 2158 | 2158 | $first_few_properties = $this->model_field_array(); |
| 2159 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
| 2159 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2160 | 2160 | $name_parts = array(); |
| 2161 | - foreach( $first_few_properties as $name=> $value ){ |
|
| 2161 | + foreach ($first_few_properties as $name=> $value) { |
|
| 2162 | 2162 | $name_parts[] = "$name:$value"; |
| 2163 | 2163 | } |
| 2164 | - return implode(",",$name_parts); |
|
| 2164 | + return implode(",", $name_parts); |
|
| 2165 | 2165 | } |
| 2166 | 2166 | } |
| 2167 | 2167 | |
@@ -2170,11 +2170,11 @@ discard block |
||
| 2170 | 2170 | * Checks if this model object has been proven to already be in the entity map |
| 2171 | 2171 | * @return boolean |
| 2172 | 2172 | */ |
| 2173 | - public function in_entity_map(){ |
|
| 2174 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
| 2173 | + public function in_entity_map() { |
|
| 2174 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2175 | 2175 | //well, if we looked, did we find it in the entity map? |
| 2176 | 2176 | return TRUE; |
| 2177 | - }else{ |
|
| 2177 | + } else { |
|
| 2178 | 2178 | return FALSE; |
| 2179 | 2179 | } |
| 2180 | 2180 | } |
@@ -2185,21 +2185,21 @@ discard block |
||
| 2185 | 2185 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
| 2186 | 2186 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
| 2187 | 2187 | */ |
| 2188 | - public function refresh_from_db(){ |
|
| 2189 | - if( $this->ID() && $this->in_entity_map() ){ |
|
| 2190 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
| 2191 | - }else{ |
|
| 2188 | + public function refresh_from_db() { |
|
| 2189 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2190 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2191 | + } else { |
|
| 2192 | 2192 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
| 2193 | 2193 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
| 2194 | 2194 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
| 2195 | 2195 | //absolutely nothing in it for this ID |
| 2196 | - if( WP_DEBUG ) { |
|
| 2196 | + if (WP_DEBUG) { |
|
| 2197 | 2197 | throw new EE_Error( |
| 2198 | 2198 | sprintf( |
| 2199 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
| 2199 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
| 2200 | 2200 | $this->ID(), |
| 2201 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 2202 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
| 2201 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 2202 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
| 2203 | 2203 | ) |
| 2204 | 2204 | ); |
| 2205 | 2205 | } |
@@ -2211,8 +2211,8 @@ discard block |
||
| 2211 | 2211 | * (probably a bad assumption they have made, oh well) |
| 2212 | 2212 | * @return string |
| 2213 | 2213 | */ |
| 2214 | - public function __toString(){ |
|
| 2215 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
| 2214 | + public function __toString() { |
|
| 2215 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2216 | 2216 | } |
| 2217 | 2217 | |
| 2218 | 2218 | /** |
@@ -2244,16 +2244,16 @@ discard block |
||
| 2244 | 2244 | * @return array |
| 2245 | 2245 | */ |
| 2246 | 2246 | public function __sleep() { |
| 2247 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 2248 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 2249 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2250 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
| 2251 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
| 2252 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
| 2247 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2248 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2249 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
| 2250 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
| 2251 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
| 2252 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2253 | 2253 | } |
| 2254 | 2254 | } |
| 2255 | 2255 | } |
| 2256 | - return array_keys( get_object_vars( $this ) ); |
|
| 2256 | + return array_keys(get_object_vars($this)); |
|
| 2257 | 2257 | } |
| 2258 | 2258 | |
| 2259 | 2259 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
| 3 | 5 | /** |
| 4 | 6 | * |
@@ -170,7 +172,7 @@ discard block |
||
| 170 | 172 | foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
| 171 | 173 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
| 172 | 174 | $this->_model_relations[$relation_name] = NULL; |
| 173 | - }else{ |
|
| 175 | + } else{ |
|
| 174 | 176 | $this->_model_relations[$relation_name] = array(); |
| 175 | 177 | } |
| 176 | 178 | } |
@@ -215,7 +217,7 @@ discard block |
||
| 215 | 217 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
| 216 | 218 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
| 217 | 219 | return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
| 218 | - }else{ |
|
| 220 | + } else{ |
|
| 219 | 221 | return NULL; |
| 220 | 222 | } |
| 221 | 223 | } |
@@ -264,7 +266,7 @@ discard block |
||
| 264 | 266 | empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
| 265 | 267 | } |
| 266 | 268 | |
| 267 | - }else{ |
|
| 269 | + } else{ |
|
| 268 | 270 | $this->_fields[$field_name] = $holder_of_value; |
| 269 | 271 | } |
| 270 | 272 | |
@@ -292,7 +294,7 @@ discard block |
||
| 292 | 294 | } |
| 293 | 295 | //let's unset any cache for this field_name from the $_cached_properties property. |
| 294 | 296 | $this->_clear_cached_property( $field_name ); |
| 295 | - }else{ |
|
| 297 | + } else{ |
|
| 296 | 298 | throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
| 297 | 299 | } |
| 298 | 300 | |
@@ -588,8 +590,9 @@ discard block |
||
| 588 | 590 | * @return void |
| 589 | 591 | */ |
| 590 | 592 | protected function _clear_cached_property( $property_name ) { |
| 591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
| 592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
| 593 | + if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
| 594 | + unset( $this->_cached_properties[ $property_name ] ); |
|
| 595 | + } |
|
| 593 | 596 | } |
| 594 | 597 | |
| 595 | 598 | |
@@ -629,10 +632,10 @@ discard block |
||
| 629 | 632 | if($clear_all){ |
| 630 | 633 | $obj_removed = true; |
| 631 | 634 | $this->_model_relations[$relationName] = null; |
| 632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
| 635 | + } elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
| 633 | 636 | $obj_removed = $this->_model_relations[$relationName]; |
| 634 | 637 | $this->_model_relations[$relationName] = null; |
| 635 | - }else{ |
|
| 638 | + } else{ |
|
| 636 | 639 | if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
| 637 | 640 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
| 638 | 641 | if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
@@ -646,20 +649,20 @@ discard block |
||
| 646 | 649 | } |
| 647 | 650 | if($index_found_at){ |
| 648 | 651 | $index_in_cache = $index_found_at; |
| 649 | - }else{ |
|
| 652 | + } else{ |
|
| 650 | 653 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
| 651 | 654 | //if it wasn't in it to begin with. So we're done |
| 652 | 655 | return $object_to_remove_or_index_into_array; |
| 653 | 656 | } |
| 654 | 657 | } |
| 655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
| 658 | + } elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
| 656 | 659 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
| 657 | 660 | foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
| 658 | 661 | if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
| 659 | 662 | $index_in_cache = $index; |
| 660 | 663 | } |
| 661 | 664 | } |
| 662 | - }else{ |
|
| 665 | + } else{ |
|
| 663 | 666 | $index_in_cache = $object_to_remove_or_index_into_array; |
| 664 | 667 | } |
| 665 | 668 | //supposedly we've found it. But it could just be that the client code |
@@ -668,7 +671,7 @@ discard block |
||
| 668 | 671 | isset( $this->_model_relations[$relationName][$index_in_cache])){ |
| 669 | 672 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
| 670 | 673 | unset($this->_model_relations[$relationName][$index_in_cache]); |
| 671 | - }else{ |
|
| 674 | + } else{ |
|
| 672 | 675 | //that thing was never cached anyways. |
| 673 | 676 | $obj_removed = NULL; |
| 674 | 677 | } |
@@ -724,7 +727,7 @@ discard block |
||
| 724 | 727 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
| 725 | 728 | if(is_array($cached_array_or_object)){ |
| 726 | 729 | return array_shift($cached_array_or_object); |
| 727 | - }else{ |
|
| 730 | + } else{ |
|
| 728 | 731 | return $cached_array_or_object; |
| 729 | 732 | } |
| 730 | 733 | } |
@@ -743,10 +746,10 @@ discard block |
||
| 743 | 746 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
| 744 | 747 | if(is_array($cached_array_or_object)){ |
| 745 | 748 | $objects = $cached_array_or_object; |
| 746 | - }elseif($cached_array_or_object){ |
|
| 749 | + } elseif($cached_array_or_object){ |
|
| 747 | 750 | //if the result is not an array, but exists, make it an array |
| 748 | 751 | $objects = array($cached_array_or_object); |
| 749 | - }else{ |
|
| 752 | + } else{ |
|
| 750 | 753 | //if nothing was found, return an empty array |
| 751 | 754 | $objects = array(); |
| 752 | 755 | } |
@@ -761,7 +764,7 @@ discard block |
||
| 761 | 764 | if( $model_object->ID() ){ |
| 762 | 765 | $model->add_to_entity_map( $model_object ); |
| 763 | 766 | } |
| 764 | - }else{ |
|
| 767 | + } else{ |
|
| 765 | 768 | throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
| 766 | 769 | } |
| 767 | 770 | } |
@@ -886,10 +889,10 @@ discard block |
||
| 886 | 889 | if( $field_obj->is_nullable()){ |
| 887 | 890 | //if the field allows nulls, then let it be null |
| 888 | 891 | $field_value = NULL; |
| 889 | - }else{ |
|
| 892 | + } else{ |
|
| 890 | 893 | $field_value = $field_obj->get_default_value(); |
| 891 | 894 | } |
| 892 | - }else{ |
|
| 895 | + } else{ |
|
| 893 | 896 | $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
| 894 | 897 | } |
| 895 | 898 | $this->_fields[$field_name] = $field_value; |
@@ -1009,15 +1012,17 @@ discard block |
||
| 1009 | 1012 | $this->_tm_frmt = $in_tm_frmt; |
| 1010 | 1013 | } |
| 1011 | 1014 | |
| 1012 | - if ( $echo ) |
|
| 1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
| 1014 | - else |
|
| 1015 | - $field->set_date_format( $in_dt_frmt ); |
|
| 1015 | + if ( $echo ) { |
|
| 1016 | + $field->set_pretty_date_format( $in_dt_frmt ); |
|
| 1017 | + } else { |
|
| 1018 | + $field->set_date_format( $in_dt_frmt ); |
|
| 1019 | + } |
|
| 1016 | 1020 | |
| 1017 | - if ( $echo ) |
|
| 1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
| 1019 | - else |
|
| 1020 | - $field->set_time_format( $in_tm_frmt ); |
|
| 1021 | + if ( $echo ) { |
|
| 1022 | + $field->set_pretty_time_format( $in_tm_frmt ); |
|
| 1023 | + } else { |
|
| 1024 | + $field->set_time_format( $in_tm_frmt ); |
|
| 1025 | + } |
|
| 1021 | 1026 | |
| 1022 | 1027 | //set timezone in field object |
| 1023 | 1028 | $field->set_timezone( $this->_timezone ); |
@@ -1240,8 +1245,9 @@ discard block |
||
| 1240 | 1245 | EE_Registry::instance()->load_helper('DTT_Helper'); |
| 1241 | 1246 | $timezone = EEH_DTT_Helper::get_timezone(); |
| 1242 | 1247 | |
| 1243 | - if ( $timezone == $this->_timezone ) |
|
| 1244 | - return ''; |
|
| 1248 | + if ( $timezone == $this->_timezone ) { |
|
| 1249 | + return ''; |
|
| 1250 | + } |
|
| 1245 | 1251 | |
| 1246 | 1252 | $original_timezone = $this->_timezone; |
| 1247 | 1253 | $this->set_timezone( $timezone ); |
@@ -1249,8 +1255,9 @@ discard block |
||
| 1249 | 1255 | $fn = (array) $field_name; |
| 1250 | 1256 | $args = array_merge( $fn, (array) $args ); |
| 1251 | 1257 | |
| 1252 | - if ( !method_exists( $this, $callback ) ) |
|
| 1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
| 1258 | + if ( !method_exists( $this, $callback ) ) { |
|
| 1259 | + throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
| 1260 | + } |
|
| 1254 | 1261 | $args = (array) $args; |
| 1255 | 1262 | $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
| 1256 | 1263 | |
@@ -1397,7 +1404,7 @@ discard block |
||
| 1397 | 1404 | $this->_update_cached_related_model_objs_fks(); |
| 1398 | 1405 | } |
| 1399 | 1406 | } |
| 1400 | - }else{//PK is NOT auto-increment |
|
| 1407 | + } else{//PK is NOT auto-increment |
|
| 1401 | 1408 | //so check if one like it already exists in the db |
| 1402 | 1409 | if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
| 1403 | 1410 | if( ! $this->in_entity_map() && WP_DEBUG ){ |
@@ -1412,12 +1419,12 @@ discard block |
||
| 1412 | 1419 | ); |
| 1413 | 1420 | } |
| 1414 | 1421 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
| 1415 | - }else{ |
|
| 1422 | + } else{ |
|
| 1416 | 1423 | $results = $this->get_model()->insert($save_cols_n_values); |
| 1417 | 1424 | $this->_update_cached_related_model_objs_fks(); |
| 1418 | 1425 | } |
| 1419 | 1426 | } |
| 1420 | - }else{//there is NO primary key |
|
| 1427 | + } else{//there is NO primary key |
|
| 1421 | 1428 | $already_in_db = false; |
| 1422 | 1429 | foreach($this->get_model()->unique_indexes() as $index){ |
| 1423 | 1430 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
@@ -1428,7 +1435,7 @@ discard block |
||
| 1428 | 1435 | if( $already_in_db ){ |
| 1429 | 1436 | $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
| 1430 | 1437 | $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
| 1431 | - }else{ |
|
| 1438 | + } else{ |
|
| 1432 | 1439 | $results = $this->get_model()->insert( $save_cols_n_values ); |
| 1433 | 1440 | } |
| 1434 | 1441 | } |
@@ -1480,7 +1487,7 @@ discard block |
||
| 1480 | 1487 | //make sure this has been saved |
| 1481 | 1488 | if( ! $this->ID()){ |
| 1482 | 1489 | $id = $this->save(); |
| 1483 | - }else{ |
|
| 1490 | + } else{ |
|
| 1484 | 1491 | $id = $this->ID(); |
| 1485 | 1492 | } |
| 1486 | 1493 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
@@ -1499,7 +1506,7 @@ discard block |
||
| 1499 | 1506 | $this->_add_relation_to($related_model_obj, $relationName); |
| 1500 | 1507 | $related_model_obj->save_new_cached_related_model_objs(); |
| 1501 | 1508 | // } |
| 1502 | - }else{ |
|
| 1509 | + } else{ |
|
| 1503 | 1510 | foreach($this->_model_relations[$relationName] as $related_model_obj){ |
| 1504 | 1511 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1505 | 1512 | //but ONLY if it DOES NOT exist in the DB |
@@ -1558,13 +1565,13 @@ discard block |
||
| 1558 | 1565 | |
| 1559 | 1566 | if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
| 1560 | 1567 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
| 1561 | - }else{ |
|
| 1568 | + } else{ |
|
| 1562 | 1569 | $existing = null; |
| 1563 | 1570 | } |
| 1564 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
| 1571 | + } elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
| 1565 | 1572 | //no primary key on this model, but there's still a matching item in the DB |
| 1566 | 1573 | $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
| 1567 | - }else{ |
|
| 1574 | + } else{ |
|
| 1568 | 1575 | $existing = null; |
| 1569 | 1576 | } |
| 1570 | 1577 | if ( $existing ) { |
@@ -1622,7 +1629,7 @@ discard block |
||
| 1622 | 1629 | private static function _get_model_classname( $model_name = null){ |
| 1623 | 1630 | if(strpos($model_name,"EE_")===0){ |
| 1624 | 1631 | $model_classname=str_replace("EE_","EEM_",$model_name); |
| 1625 | - }else{ |
|
| 1632 | + } else{ |
|
| 1626 | 1633 | $model_classname = "EEM_".$model_name; |
| 1627 | 1634 | } |
| 1628 | 1635 | return $model_classname; |
@@ -1656,7 +1663,7 @@ discard block |
||
| 1656 | 1663 | //now that we know the name of the variable, use a variable variable to get its value and return its |
| 1657 | 1664 | if( $this->get_model()->has_primary_key_field() ) { |
| 1658 | 1665 | return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
| 1659 | - }else{ |
|
| 1666 | + } else{ |
|
| 1660 | 1667 | return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
| 1661 | 1668 | } |
| 1662 | 1669 | } |
@@ -1784,7 +1791,7 @@ discard block |
||
| 1784 | 1791 | //if there are query parameters, forget about caching the related model objects. |
| 1785 | 1792 | if( $query_params ){ |
| 1786 | 1793 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1787 | - }else{ |
|
| 1794 | + } else{ |
|
| 1788 | 1795 | //did we already cache the result of this query? |
| 1789 | 1796 | $cached_results = $this->get_all_from_cache($relationName); |
| 1790 | 1797 | if ( ! $cached_results ){ |
@@ -1794,11 +1801,11 @@ discard block |
||
| 1794 | 1801 | foreach($related_model_objects as $related_model_object){ |
| 1795 | 1802 | $this->cache($relationName, $related_model_object); |
| 1796 | 1803 | } |
| 1797 | - }else{ |
|
| 1804 | + } else{ |
|
| 1798 | 1805 | $related_model_objects = $cached_results; |
| 1799 | 1806 | } |
| 1800 | 1807 | } |
| 1801 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
| 1808 | + } else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
| 1802 | 1809 | $related_model_objects = $this->get_all_from_cache($relationName); |
| 1803 | 1810 | } |
| 1804 | 1811 | return $related_model_objects; |
@@ -1850,22 +1857,22 @@ discard block |
||
| 1850 | 1857 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
| 1851 | 1858 | if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
| 1852 | 1859 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 1853 | - }else{ |
|
| 1860 | + } else{ |
|
| 1854 | 1861 | //first, check if we've already cached the result of this query |
| 1855 | 1862 | $cached_result = $this->get_one_from_cache($relationName); |
| 1856 | 1863 | if ( ! $cached_result ){ |
| 1857 | 1864 | |
| 1858 | 1865 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 1859 | 1866 | $this->cache($relationName,$related_model_object); |
| 1860 | - }else{ |
|
| 1867 | + } else{ |
|
| 1861 | 1868 | $related_model_object = $cached_result; |
| 1862 | 1869 | } |
| 1863 | 1870 | } |
| 1864 | - }else{ |
|
| 1871 | + } else{ |
|
| 1865 | 1872 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
| 1866 | 1873 | if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
| 1867 | 1874 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 1868 | - }else{ |
|
| 1875 | + } else{ |
|
| 1869 | 1876 | $related_model_object = null; |
| 1870 | 1877 | } |
| 1871 | 1878 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
@@ -1891,7 +1898,7 @@ discard block |
||
| 1891 | 1898 | public function delete_related($relationName,$query_params = array()){ |
| 1892 | 1899 | if($this->ID()){ |
| 1893 | 1900 | $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
| 1894 | - }else{ |
|
| 1901 | + } else{ |
|
| 1895 | 1902 | $count = count($this->get_all_from_cache($relationName)); |
| 1896 | 1903 | $this->clear_cache($relationName,NULL,TRUE); |
| 1897 | 1904 | } |
@@ -1911,7 +1918,7 @@ discard block |
||
| 1911 | 1918 | public function delete_related_permanently($relationName,$query_params = array()){ |
| 1912 | 1919 | if($this->ID()){ |
| 1913 | 1920 | $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
| 1914 | - }else{ |
|
| 1921 | + } else{ |
|
| 1915 | 1922 | $count = count($this->get_all_from_cache($relationName)); |
| 1916 | 1923 | } |
| 1917 | 1924 | $this->clear_cache($relationName,NULL,TRUE); |
@@ -1946,8 +1953,9 @@ discard block |
||
| 1946 | 1953 | |
| 1947 | 1954 | foreach ( (array) $properties as $property_name ) { |
| 1948 | 1955 | //first make sure this property exists |
| 1949 | - if ( ! $this->_fields[ $property_name ] ) |
|
| 1950 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
| 1956 | + if ( ! $this->_fields[ $property_name ] ) { |
|
| 1957 | + throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
| 1958 | + } |
|
| 1951 | 1959 | } |
| 1952 | 1960 | |
| 1953 | 1961 | return TRUE; |
@@ -2027,7 +2035,7 @@ discard block |
||
| 2027 | 2035 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
| 2028 | 2036 | if( ! $existing_rows_like_that){ |
| 2029 | 2037 | return $this->add_extra_meta($meta_key, $meta_value); |
| 2030 | - }else{ |
|
| 2038 | + } else{ |
|
| 2031 | 2039 | foreach( $existing_rows_like_that as $existing_row){ |
| 2032 | 2040 | $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
| 2033 | 2041 | } |
@@ -2093,10 +2101,10 @@ discard block |
||
| 2093 | 2101 | $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
| 2094 | 2102 | if ( $result instanceof EE_Extra_Meta ){ |
| 2095 | 2103 | return $result->value(); |
| 2096 | - }else{ |
|
| 2104 | + } else{ |
|
| 2097 | 2105 | return $default; |
| 2098 | 2106 | } |
| 2099 | - }else{ |
|
| 2107 | + } else{ |
|
| 2100 | 2108 | $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
| 2101 | 2109 | if($results){ |
| 2102 | 2110 | $values = array(); |
@@ -2106,7 +2114,7 @@ discard block |
||
| 2106 | 2114 | } |
| 2107 | 2115 | } |
| 2108 | 2116 | return $values; |
| 2109 | - }else{ |
|
| 2117 | + } else{ |
|
| 2110 | 2118 | return $default; |
| 2111 | 2119 | } |
| 2112 | 2120 | } |
@@ -2132,7 +2140,7 @@ discard block |
||
| 2132 | 2140 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
| 2133 | 2141 | } |
| 2134 | 2142 | } |
| 2135 | - }else{ |
|
| 2143 | + } else{ |
|
| 2136 | 2144 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
| 2137 | 2145 | foreach($extra_meta_objs as $extra_meta_obj){ |
| 2138 | 2146 | if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
@@ -2154,7 +2162,7 @@ discard block |
||
| 2154 | 2162 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
| 2155 | 2163 | if($field_we_can_use){ |
| 2156 | 2164 | return $this->get($field_we_can_use->get_name()); |
| 2157 | - }else{ |
|
| 2165 | + } else{ |
|
| 2158 | 2166 | $first_few_properties = $this->model_field_array(); |
| 2159 | 2167 | $first_few_properties = array_slice($first_few_properties,0,3); |
| 2160 | 2168 | $name_parts = array(); |
@@ -2174,7 +2182,7 @@ discard block |
||
| 2174 | 2182 | if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
| 2175 | 2183 | //well, if we looked, did we find it in the entity map? |
| 2176 | 2184 | return TRUE; |
| 2177 | - }else{ |
|
| 2185 | + } else{ |
|
| 2178 | 2186 | return FALSE; |
| 2179 | 2187 | } |
| 2180 | 2188 | } |
@@ -2188,7 +2196,7 @@ discard block |
||
| 2188 | 2196 | public function refresh_from_db(){ |
| 2189 | 2197 | if( $this->ID() && $this->in_entity_map() ){ |
| 2190 | 2198 | $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
| 2191 | - }else{ |
|
| 2199 | + } else{ |
|
| 2192 | 2200 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
| 2193 | 2201 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
| 2194 | 2202 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | * @param bool $delete true=>delete, false=>restore |
| 34 | 34 | * @return bool |
| 35 | 35 | */ |
| 36 | - public function delete_or_restore( $delete = TRUE ) { |
|
| 36 | + public function delete_or_restore($delete = TRUE) { |
|
| 37 | 37 | $model = $this->get_model(); |
| 38 | - return $model->delete_or_restore_by_ID( $delete, $this->ID() ); |
|
| 38 | + return $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | * @return boolean |
| 46 | 46 | */ |
| 47 | 47 | public function restore() { |
| 48 | - return $this->delete_or_restore( FALSE ); |
|
| 48 | + return $this->delete_or_restore(FALSE); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -define('EE_Event_Category_Taxonomy','espresso_event_category'); |
|
| 2 | +define('EE_Event_Category_Taxonomy', 'espresso_event_category'); |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * EEM_CPT_Base |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @author Mike Nelson |
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | -abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base{ |
|
| 19 | +abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var string post_status_publish - the wp post status for published cpts |
@@ -69,55 +69,55 @@ discard block |
||
| 69 | 69 | * @param string $timezone |
| 70 | 70 | * @throws \EE_Error |
| 71 | 71 | */ |
| 72 | - protected function __construct( $timezone = NULL ){ |
|
| 72 | + protected function __construct($timezone = NULL) { |
|
| 73 | 73 | |
| 74 | 74 | //adds a relationship to Term_Taxonomy for all these models. For this to work |
| 75 | 75 | //Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
| 76 | 76 | //eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
| 77 | 77 | //with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
| 78 | 78 | //must also be new EE_HABTM_Relation('Term_Relationship'); |
| 79 | - $this->_model_relations['Term_Taxonomy'] =new EE_HABTM_Relation('Term_Relationship'); |
|
| 79 | + $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
| 80 | 80 | $primary_table_name = NULL; |
| 81 | 81 | //add the common _status field to all CPT primary tables. |
| 82 | - foreach ( $this->_tables as $alias => $table_obj ) { |
|
| 83 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
| 82 | + foreach ($this->_tables as $alias => $table_obj) { |
|
| 83 | + if ($table_obj instanceof EE_Primary_Table) { |
|
| 84 | 84 | $primary_table_name = $alias; |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | //set default wp post statuses if child has not already set. |
| 88 | - if ( ! isset( $this->_fields[$primary_table_name]['status'] )) { |
|
| 88 | + if ( ! isset($this->_fields[$primary_table_name]['status'])) { |
|
| 89 | 89 | $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status', __("Event Status", "event_espresso"), false, 'draft'); |
| 90 | 90 | } |
| 91 | - if( ! isset( $this->_fields[$primary_table_name]['to_ping'])){ |
|
| 92 | - $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __( 'To Ping', 'event_espresso' ), FALSE, ''); |
|
| 91 | + if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) { |
|
| 92 | + $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __('To Ping', 'event_espresso'), FALSE, ''); |
|
| 93 | 93 | } |
| 94 | - if( ! isset( $this->_fields[$primary_table_name]['pinged'])){ |
|
| 95 | - $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __( 'Pinged', 'event_espresso' ), FALSE, ''); |
|
| 94 | + if ( ! isset($this->_fields[$primary_table_name]['pinged'])) { |
|
| 95 | + $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __('Pinged', 'event_espresso'), FALSE, ''); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if( ! isset( $this->_fields[$primary_table_name]['comment_status'])){ |
|
| 99 | - $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso' ), FALSE, 'open'); |
|
| 98 | + if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) { |
|
| 99 | + $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso'), FALSE, 'open'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if( ! isset( $this->_fields[$primary_table_name]['ping_status'])){ |
|
| 102 | + if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) { |
|
| 103 | 103 | $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status', __('Ping Status', 'event_espresso'), FALSE, 'open'); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if( ! isset( $this->_fields[$primary_table_name]['post_content_filtered'])){ |
|
| 107 | - $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __( 'Post Content Filtered', 'event_espresso' ), FALSE, ''); |
|
| 106 | + if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) { |
|
| 107 | + $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __('Post Content Filtered', 'event_espresso'), FALSE, ''); |
|
| 108 | 108 | } |
| 109 | - if( ! isset( $this->_model_relations[ 'Post_Meta' ] ) ) { |
|
| 109 | + if ( ! isset($this->_model_relations['Post_Meta'])) { |
|
| 110 | 110 | //don't block deletes though because we want to maintain the current behaviour |
| 111 | - $this->_model_relations[ 'Post_Meta' ] = new EE_Has_Many_Relation( false ); |
|
| 111 | + $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
| 112 | 112 | } |
| 113 | - if( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions ){ |
|
| 113 | + if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
| 114 | 114 | //nothing was set during child constructor, so set default |
| 115 | - $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions( $this->post_type() ); |
|
| 115 | + $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
| 116 | 116 | } |
| 117 | - if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ) { |
|
| 117 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
| 118 | 118 | //nothing was set during child constructor, so set default |
| 119 | 119 | //it's ok for child classes to specify this, but generally this is more DRY |
| 120 | - $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions( $this->post_type() ); |
|
| 120 | + $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
| 121 | 121 | } |
| 122 | 122 | parent::__construct($timezone); |
| 123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function public_event_stati() { |
| 132 | 132 | // @see wp-includes/post.php |
| 133 | - return get_post_stati( array( 'public' => TRUE )); |
|
| 133 | + return get_post_stati(array('public' => TRUE)); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @return string |
| 142 | 142 | * @throws EE_Error |
| 143 | 143 | */ |
| 144 | - public function deleted_field_name(){ |
|
| 144 | + public function deleted_field_name() { |
|
| 145 | 145 | throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name", "event_espresso"))); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | * @return string |
| 153 | 153 | * @throws EE_Error |
| 154 | 154 | */ |
| 155 | - public function post_status_field_name(){ |
|
| 155 | + public function post_status_field_name() { |
|
| 156 | 156 | $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
| 157 | - if($field){ |
|
| 157 | + if ($field) { |
|
| 158 | 158 | return $field->get_name(); |
| 159 | - }else{ |
|
| 160 | - throw new EE_Error(sprintf(__('We are trying to find the post status 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))); |
|
| 159 | + } else { |
|
| 160 | + throw new EE_Error(sprintf(__('We are trying to find the post status 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))); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | * @param array $query_params like EEM_Base::get_all's $query_params |
| 169 | 169 | * @return array like EEM_Base::get_all's $query_params |
| 170 | 170 | */ |
| 171 | - protected function _alter_query_params_so_only_trashed_items_included($query_params){ |
|
| 172 | - $post_status_field_name=$this->post_status_field_name(); |
|
| 173 | - $query_params[0][$post_status_field_name]=self::post_status_trashed; |
|
| 171 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) { |
|
| 172 | + $post_status_field_name = $this->post_status_field_name(); |
|
| 173 | + $query_params[0][$post_status_field_name] = self::post_status_trashed; |
|
| 174 | 174 | return $query_params; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param array $query_params |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){ |
|
| 185 | - $query_params[ 'default_where_conditions' ] = 'minimum'; |
|
| 184 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) { |
|
| 185 | + $query_params['default_where_conditions'] = 'minimum'; |
|
| 186 | 186 | return $query_params; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | * @param array $query_params like EEM_Base::get_all |
| 195 | 195 | * @return boolean success |
| 196 | 196 | */ |
| 197 | - function delete_or_restore($delete=true,$query_params = array()){ |
|
| 198 | - $post_status_field_name=$this->post_status_field_name(); |
|
| 197 | + function delete_or_restore($delete = true, $query_params = array()) { |
|
| 198 | + $post_status_field_name = $this->post_status_field_name(); |
|
| 199 | 199 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 200 | 200 | $new_status = $delete ? self::post_status_trashed : 'draft'; |
| 201 | - if ( $this->update (array($post_status_field_name=>$new_status), $query_params )) { |
|
| 201 | + if ($this->update(array($post_status_field_name=>$new_status), $query_params)) { |
|
| 202 | 202 | return TRUE; |
| 203 | 203 | } else { |
| 204 | 204 | return FALSE; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public function meta_table() { |
| 217 | 217 | $meta_table = $this->_get_other_tables(); |
| 218 | - $meta_table = reset( $meta_table ); |
|
| 218 | + $meta_table = reset($meta_table); |
|
| 219 | 219 | return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : NULL; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no db only fields) |
| 228 | 228 | * @return array |
| 229 | 229 | */ |
| 230 | - public function get_meta_table_fields( $all = FALSE ) { |
|
| 230 | + public function get_meta_table_fields($all = FALSE) { |
|
| 231 | 231 | $all_fields = $fields_to_return = array(); |
| 232 | - foreach ( $this->_tables as $alias => $table_obj ) { |
|
| 233 | - if ( $table_obj instanceof EE_Secondary_Table ) |
|
| 234 | - $all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields ); |
|
| 232 | + foreach ($this->_tables as $alias => $table_obj) { |
|
| 233 | + if ($table_obj instanceof EE_Secondary_Table) |
|
| 234 | + $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( !$all ) { |
|
| 238 | - foreach ( $all_fields as $name => $obj ) { |
|
| 239 | - if ( $obj instanceof EE_DB_Only_Field_Base ) |
|
| 237 | + if ( ! $all) { |
|
| 238 | + foreach ($all_fields as $name => $obj) { |
|
| 239 | + if ($obj instanceof EE_DB_Only_Field_Base) |
|
| 240 | 240 | continue; |
| 241 | 241 | $fields_to_return[] = $name; |
| 242 | 242 | } |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | * @param int $parent_term_taxonomy_id |
| 260 | 260 | * @return EE_Term_Taxonomy |
| 261 | 261 | */ |
| 262 | - function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description ='',$parent_term_taxonomy_id = null){ |
|
| 262 | + function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description = '', $parent_term_taxonomy_id = null) { |
|
| 263 | 263 | //create term |
| 264 | - require_once( EE_MODELS . 'EEM_Term.model.php'); |
|
| 264 | + require_once(EE_MODELS.'EEM_Term.model.php'); |
|
| 265 | 265 | //first, check for a term by the same name or slug |
| 266 | 266 | $category_slug = sanitize_title($category_name); |
| 267 | - $term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name,'slug'=>$category_slug)))); |
|
| 268 | - if( ! $term ){ |
|
| 267 | + $term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name, 'slug'=>$category_slug)))); |
|
| 268 | + if ( ! $term) { |
|
| 269 | 269 | $term = EE_Term::new_instance(array( |
| 270 | 270 | 'name'=>$category_name, |
| 271 | 271 | 'slug'=>$category_slug |
@@ -273,10 +273,10 @@ discard block |
||
| 273 | 273 | $term->save(); |
| 274 | 274 | } |
| 275 | 275 | //make sure there's a term-taxonomy entry too |
| 276 | - require_once( EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
| 277 | - $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(),'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
| 276 | + require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php'); |
|
| 277 | + $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(), 'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
| 278 | 278 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
| 279 | - if( ! $term_taxonomy ){ |
|
| 279 | + if ( ! $term_taxonomy) { |
|
| 280 | 280 | $term_taxonomy = EE_Term_Taxonomy::new_instance(array( |
| 281 | 281 | 'term_id'=>$term->ID(), |
| 282 | 282 | 'taxonomy'=>EE_Event_Category_Taxonomy, |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | 'parent'=>$parent_term_taxonomy_id |
| 286 | 286 | )); |
| 287 | 287 | $term_taxonomy->save(); |
| 288 | - }else{ |
|
| 288 | + } else { |
|
| 289 | 289 | $term_taxonomy->set_count($term_taxonomy->count() + 1); |
| 290 | 290 | $term_taxonomy->save(); |
| 291 | 291 | } |
@@ -300,11 +300,11 @@ discard block |
||
| 300 | 300 | * @param string $category_name name of the event category (term) |
| 301 | 301 | * @return bool |
| 302 | 302 | */ |
| 303 | - function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name){ |
|
| 303 | + function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) { |
|
| 304 | 304 | //find the term_taxonomy by that name |
| 305 | - $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name,'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
| 305 | + $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name, 'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
| 306 | 306 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
| 307 | - if( $term_taxonomy ){ |
|
| 307 | + if ($term_taxonomy) { |
|
| 308 | 308 | $term_taxonomy->set_count($term_taxonomy->count() - 1); |
| 309 | 309 | $term_taxonomy->save(); |
| 310 | 310 | } |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | * @param string|array $attr Optional. Query string or array of attributes. |
| 325 | 325 | * @return string HTML image element |
| 326 | 326 | */ |
| 327 | - public function get_feature_image( $id, $size = 'thumbnail', $attr = '' ) { |
|
| 328 | - return get_the_post_thumbnail( $id, $size, $attr ); |
|
| 327 | + public function get_feature_image($id, $size = 'thumbnail', $attr = '') { |
|
| 328 | + return get_the_post_thumbnail($id, $size, $attr); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @global array $wp_post_statuses set in wp core for storing all the post stati |
| 339 | 339 | * @return array |
| 340 | 340 | */ |
| 341 | - public function get_post_statuses(){ |
|
| 341 | + public function get_post_statuses() { |
|
| 342 | 342 | global $wp_post_statuses; |
| 343 | 343 | $statuses = array(); |
| 344 | - foreach($wp_post_statuses as $post_status => $args_object){ |
|
| 344 | + foreach ($wp_post_statuses as $post_status => $args_object) { |
|
| 345 | 345 | $statuses[$post_status] = $args_object->label; |
| 346 | 346 | } |
| 347 | 347 | return $statuses; |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | public function get_status_array() { |
| 357 | 357 | $statuses = $this->get_post_statuses(); |
| 358 | 358 | //first the global filter |
| 359 | - $statuses = apply_filters( 'FHEE_EEM_CPT_Base__get_status_array', $statuses ); |
|
| 359 | + $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
| 360 | 360 | //now the class specific filter |
| 361 | - $statuses = apply_filters( 'FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses ); |
|
| 361 | + $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses); |
|
| 362 | 362 | return $statuses; |
| 363 | 363 | } |
| 364 | 364 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | public function get_custom_post_statuses() { |
| 372 | 372 | $new_stati = array(); |
| 373 | - foreach ( $this->_custom_stati as $status => $props ) { |
|
| 373 | + foreach ($this->_custom_stati as $status => $props) { |
|
| 374 | 374 | $new_stati[$status] = $props['label']; |
| 375 | 375 | } |
| 376 | 376 | return $new_stati; |
@@ -386,24 +386,24 @@ discard block |
||
| 386 | 386 | * @param WP_Post|array $post |
| 387 | 387 | * @return EE_CPT_Base |
| 388 | 388 | */ |
| 389 | - public function instantiate_class_from_post_object_orig($post){ |
|
| 390 | - $post = (array)$post; |
|
| 389 | + public function instantiate_class_from_post_object_orig($post) { |
|
| 390 | + $post = (array) $post; |
|
| 391 | 391 | $has_all_necessary_fields_for_table = true; |
| 392 | 392 | //check if the post has fields on the meta table already |
| 393 | - foreach($this->_get_other_tables() as $table_obj){ |
|
| 393 | + foreach ($this->_get_other_tables() as $table_obj) { |
|
| 394 | 394 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
| 395 | - foreach($fields_for_that_table as $field_obj){ |
|
| 396 | - if( ! isset($post[$field_obj->get_table_column()]) |
|
| 397 | - && ! isset($post[$field_obj->get_qualified_column()])){ |
|
| 395 | + foreach ($fields_for_that_table as $field_obj) { |
|
| 396 | + if ( ! isset($post[$field_obj->get_table_column()]) |
|
| 397 | + && ! isset($post[$field_obj->get_qualified_column()])) { |
|
| 398 | 398 | $has_all_necessary_fields_for_table = false; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | //if we don't have all the fields we need, then just fetch the proper model from the DB |
| 403 | - if( ! $has_all_necessary_fields_for_table){ |
|
| 403 | + if ( ! $has_all_necessary_fields_for_table) { |
|
| 404 | 404 | |
| 405 | 405 | return $this->get_one_by_ID($post['ID']); |
| 406 | - }else{ |
|
| 406 | + } else { |
|
| 407 | 407 | return $this->instantiate_class_from_array_or_object($post); |
| 408 | 408 | } |
| 409 | 409 | } |
@@ -414,30 +414,30 @@ discard block |
||
| 414 | 414 | * @param null $post |
| 415 | 415 | * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
| 416 | 416 | */ |
| 417 | - public function instantiate_class_from_post_object( $post = NULL ){ |
|
| 418 | - if ( empty( $post )) { |
|
| 417 | + public function instantiate_class_from_post_object($post = NULL) { |
|
| 418 | + if (empty($post)) { |
|
| 419 | 419 | global $post; |
| 420 | 420 | } |
| 421 | - $post = (array)$post; |
|
| 421 | + $post = (array) $post; |
|
| 422 | 422 | $tables_needing_to_be_queried = array(); |
| 423 | 423 | //check if the post has fields on the meta table already |
| 424 | - foreach($this->get_tables() as $table_obj){ |
|
| 424 | + foreach ($this->get_tables() as $table_obj) { |
|
| 425 | 425 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
| 426 | - foreach($fields_for_that_table as $field_obj){ |
|
| 427 | - if( ! isset($post[$field_obj->get_table_column()]) |
|
| 428 | - && ! isset($post[$field_obj->get_qualified_column()])){ |
|
| 426 | + foreach ($fields_for_that_table as $field_obj) { |
|
| 427 | + if ( ! isset($post[$field_obj->get_table_column()]) |
|
| 428 | + && ! isset($post[$field_obj->get_qualified_column()])) { |
|
| 429 | 429 | $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj; |
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | //if we don't have all the fields we need, then just fetch the proper model from the DB |
| 434 | - if( $tables_needing_to_be_queried){ |
|
| 435 | - if(count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table){ |
|
| 434 | + if ($tables_needing_to_be_queried) { |
|
| 435 | + if (count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table) { |
|
| 436 | 436 | //so we're only missing data from a secondary table. Well that's not too hard to query for |
| 437 | 437 | $table_to_query = reset($tables_needing_to_be_queried); |
| 438 | - $missing_data = $this->_do_wpdb_query( 'get_row', array( 'SELECT * FROM ' . $table_to_query->get_table_name() . ' WHERE ' . $table_to_query->get_fk_on_table() . ' = ' . $post['ID'], ARRAY_A )); |
|
| 439 | - if ( ! empty( $missing_data )) { |
|
| 440 | - $post = array_merge( $post, $missing_data ); |
|
| 438 | + $missing_data = $this->_do_wpdb_query('get_row', array('SELECT * FROM '.$table_to_query->get_table_name().' WHERE '.$table_to_query->get_fk_on_table().' = '.$post['ID'], ARRAY_A)); |
|
| 439 | + if ( ! empty($missing_data)) { |
|
| 440 | + $post = array_merge($post, $missing_data); |
|
| 441 | 441 | } |
| 442 | 442 | } else { |
| 443 | 443 | return $this->get_one_by_ID($post['ID']); |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | * @throws EE_Error |
| 455 | 455 | * @return string |
| 456 | 456 | */ |
| 457 | - public function post_type(){ |
|
| 457 | + public function post_type() { |
|
| 458 | 458 | $post_type_field = NULL; |
| 459 | - foreach($this->field_settings(true) as $field_obj){ |
|
| 460 | - if($field_obj instanceof EE_WP_Post_Type_Field){ |
|
| 461 | - $post_type_field = $field_obj;break; |
|
| 459 | + foreach ($this->field_settings(true) as $field_obj) { |
|
| 460 | + if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
| 461 | + $post_type_field = $field_obj; break; |
|
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | - if($post_type_field == NULL){ |
|
| 465 | - throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"),get_class($this))); |
|
| 464 | + if ($post_type_field == NULL) { |
|
| 465 | + throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"), get_class($this))); |
|
| 466 | 466 | } |
| 467 | 467 | return $post_type_field->get_default_value(); |
| 468 | 468 | } |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | exit( 'No direct script access allowed' ); |
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | - * |
|
| 7 | - * Class EE_CPT_Minimum_Where_Conditions |
|
| 8 | - * |
|
| 9 | - * Strategy specifically for adding where conditions specific to CPT models. |
|
| 10 | - * But only sets the minimum, so any row of the right type will get used |
|
| 11 | - * |
|
| 12 | - * @package Event Espresso |
|
| 13 | - * @subpackage core/db_models |
|
| 14 | - * @author Mike Nelson |
|
| 15 | - * @since 4.8.29.rc.010 |
|
| 16 | - * |
|
| 17 | - */ |
|
| 6 | + * |
|
| 7 | + * Class EE_CPT_Minimum_Where_Conditions |
|
| 8 | + * |
|
| 9 | + * Strategy specifically for adding where conditions specific to CPT models. |
|
| 10 | + * But only sets the minimum, so any row of the right type will get used |
|
| 11 | + * |
|
| 12 | + * @package Event Espresso |
|
| 13 | + * @subpackage core/db_models |
|
| 14 | + * @author Mike Nelson |
|
| 15 | + * @since 4.8.29.rc.010 |
|
| 16 | + * |
|
| 17 | + */ |
|
| 18 | 18 | class EE_CPT_Minimum_Where_Conditions extends EE_Default_Where_Conditions{ |
| 19 | 19 | |
| 20 | 20 | protected $_post_type; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * @since 4.8.29.rc.010 |
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | -class EE_CPT_Minimum_Where_Conditions extends EE_Default_Where_Conditions{ |
|
| 18 | +class EE_CPT_Minimum_Where_Conditions extends EE_Default_Where_Conditions { |
|
| 19 | 19 | |
| 20 | 20 | protected $_post_type; |
| 21 | 21 | protected $_meta_field; |
| 22 | - function __construct($post_type, $meta_field_to_chk = ''){ |
|
| 22 | + function __construct($post_type, $meta_field_to_chk = '') { |
|
| 23 | 23 | $this->_post_type = $post_type; |
| 24 | 24 | $this->_meta_field = $meta_field_to_chk; |
| 25 | 25 | } |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * @param string $column column name |
| 30 | 30 | * @return EE_Model_Field_Base |
| 31 | 31 | */ |
| 32 | - protected function _get_field_on_column($column){ |
|
| 32 | + protected function _get_field_on_column($column) { |
|
| 33 | 33 | $all_fields = $this->_model->field_settings(true); |
| 34 | - foreach($all_fields as $field_name => $field_obj){ |
|
| 35 | - if($column == $field_obj->get_table_column()){ |
|
| 34 | + foreach ($all_fields as $field_name => $field_obj) { |
|
| 35 | + if ($column == $field_obj->get_table_column()) { |
|
| 36 | 36 | return $field_obj; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | exit( 'No direct script access allowed' ); |
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | - * |
|
| 7 | - * Class EE_Default_Where_Conditions |
|
| 8 | - * |
|
| 9 | - * Strategy to be used for getting default where conditions for EEM_Base children. |
|
| 10 | - * Should be initialized and set on construction of model |
|
| 11 | - * |
|
| 12 | - * @package Event Espresso |
|
| 13 | - * @subpackage core/db_models |
|
| 14 | - * @author Mike Nelson |
|
| 15 | - * @since 4.6.0 |
|
| 16 | - * |
|
| 17 | - */ |
|
| 6 | + * |
|
| 7 | + * Class EE_Default_Where_Conditions |
|
| 8 | + * |
|
| 9 | + * Strategy to be used for getting default where conditions for EEM_Base children. |
|
| 10 | + * Should be initialized and set on construction of model |
|
| 11 | + * |
|
| 12 | + * @package Event Espresso |
|
| 13 | + * @subpackage core/db_models |
|
| 14 | + * @author Mike Nelson |
|
| 15 | + * @since 4.6.0 |
|
| 16 | + * |
|
| 17 | + */ |
|
| 18 | 18 | class EE_Default_Where_Conditions{ |
| 19 | 19 | /** |
| 20 | 20 | * This const can be used in EE_Default_Where_Conditions values, and at the time of querying it will be |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @since 4.6.0 |
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | -class EE_Default_Where_Conditions{ |
|
| 18 | +class EE_Default_Where_Conditions { |
|
| 19 | 19 | /** |
| 20 | 20 | * This const can be used in EE_Default_Where_Conditions values, and at the time of querying it will be |
| 21 | 21 | * replaced with the current user's ID (because we don't want to use the current user's ID at time of |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * onto any field names |
| 48 | 48 | * @param array $custom_where_conditions |
| 49 | 49 | */ |
| 50 | - public function __construct( $custom_where_conditions = array() ) { |
|
| 50 | + public function __construct($custom_where_conditions = array()) { |
|
| 51 | 51 | $this->_where_conditions_provided = $custom_where_conditions; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * for querying of the model. |
| 57 | 57 | * @param EEM_Base $model |
| 58 | 58 | */ |
| 59 | - function _finalize_construct(EEM_Base $model){ |
|
| 59 | + function _finalize_construct(EEM_Base $model) { |
|
| 60 | 60 | $this->_model = $model; |
| 61 | 61 | } |
| 62 | 62 | /** |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | * @param string $model_relation_chain |
| 72 | 72 | * @return array like what's expected in EEM_Base::get_all()'s $query_params[0] |
| 73 | 73 | */ |
| 74 | - function get_default_where_conditions( $model_relation_chain = '' ){ |
|
| 75 | - return $this->prepare_where_conditions_for_querying( array_merge( $this->_get_default_where_conditions(), $this->get_where_conditions_provided() ), $model_relation_chain ); |
|
| 74 | + function get_default_where_conditions($model_relation_chain = '') { |
|
| 75 | + return $this->prepare_where_conditions_for_querying(array_merge($this->_get_default_where_conditions(), $this->get_where_conditions_provided()), $model_relation_chain); |
|
| 76 | 76 | } |
| 77 | 77 | /** |
| 78 | 78 | * Gets the default where conditions that are specific to this child of EE_Default_Where_Conditions. |
| 79 | 79 | * Adding model relation chains is handled by the public method get_default_where_conditions |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - protected function _get_default_where_conditions(){ |
|
| 82 | + protected function _get_default_where_conditions() { |
|
| 83 | 83 | return array(); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -93,33 +93,33 @@ discard block |
||
| 93 | 93 | * @return array |
| 94 | 94 | * @throws \EE_Error |
| 95 | 95 | */ |
| 96 | - public function prepare_where_conditions_for_querying( $where_conditions, $model_relation_chain ) { |
|
| 96 | + public function prepare_where_conditions_for_querying($where_conditions, $model_relation_chain) { |
|
| 97 | 97 | $where_conditions_with_model_relation_chain_prefixes = array(); |
| 98 | - if( ! is_array( $where_conditions ) ){ |
|
| 98 | + if ( ! is_array($where_conditions)) { |
|
| 99 | 99 | $where_conditions = array(); |
| 100 | 100 | } |
| 101 | - foreach( $where_conditions as $key => $value ) { |
|
| 102 | - if( in_array( $key, array( 'OR', 'AND', 'NOT' ) ) || |
|
| 103 | - strpos( $key, 'OR*' ) !== false || |
|
| 104 | - strpos( $key, 'AND*' ) !== false || |
|
| 105 | - strpos( $key, 'NOT*' ) !== false ){ |
|
| 106 | - $where_conditions_with_model_relation_chain_prefixes[ $key ] = $this->prepare_where_conditions_for_querying( $value, $model_relation_chain ); |
|
| 107 | - }else{ |
|
| 108 | - if($model_relation_chain != '' && $model_relation_chain[strlen($model_relation_chain)-1] !='.'){ |
|
| 109 | - $model_relation_chain=$model_relation_chain."."; |
|
| 101 | + foreach ($where_conditions as $key => $value) { |
|
| 102 | + if (in_array($key, array('OR', 'AND', 'NOT')) || |
|
| 103 | + strpos($key, 'OR*') !== false || |
|
| 104 | + strpos($key, 'AND*') !== false || |
|
| 105 | + strpos($key, 'NOT*') !== false) { |
|
| 106 | + $where_conditions_with_model_relation_chain_prefixes[$key] = $this->prepare_where_conditions_for_querying($value, $model_relation_chain); |
|
| 107 | + } else { |
|
| 108 | + if ($model_relation_chain != '' && $model_relation_chain[strlen($model_relation_chain) - 1] != '.') { |
|
| 109 | + $model_relation_chain = $model_relation_chain."."; |
|
| 110 | 110 | } |
| 111 | 111 | //check for the current user id place holder, and if present change it |
| 112 | - if( $value === self::current_user_placeholder ){ |
|
| 112 | + if ($value === self::current_user_placeholder) { |
|
| 113 | 113 | $value = get_current_user_id(); |
| 114 | 114 | } |
| 115 | 115 | //check for user field placeholder |
| 116 | - if( $key == self::user_field_name_placeholder ) { |
|
| 117 | - if( ! $this->_model->wp_user_field_name() ) { |
|
| 118 | - throw new EE_Error( sprintf( __( 'There is no foreign key to the WP_User model on model %s. Please either modify your default where conditions, add a _model_chain_to_wp_user onto the model, or a proper EE_WP_User_Field onto the model', 'event_espresso' ), $this->_model->get_this_model_name() ) ); |
|
| 116 | + if ($key == self::user_field_name_placeholder) { |
|
| 117 | + if ( ! $this->_model->wp_user_field_name()) { |
|
| 118 | + throw new EE_Error(sprintf(__('There is no foreign key to the WP_User model on model %s. Please either modify your default where conditions, add a _model_chain_to_wp_user onto the model, or a proper EE_WP_User_Field onto the model', 'event_espresso'), $this->_model->get_this_model_name())); |
|
| 119 | 119 | } |
| 120 | 120 | $key = $this->_model->wp_user_field_name(); |
| 121 | 121 | } |
| 122 | - $where_conditions_with_model_relation_chain_prefixes[ $model_relation_chain . $key ] = $value; |
|
| 122 | + $where_conditions_with_model_relation_chain_prefixes[$model_relation_chain.$key] = $value; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | return $where_conditions_with_model_relation_chain_prefixes; |