@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class EE_SPCO_Reg_Step_Attendee_Information |
|
| 5 | - * |
|
| 6 | - * Description |
|
| 7 | - * |
|
| 8 | - * @package Event Espresso |
|
| 9 | - * @subpackage core |
|
| 10 | - * @author Brent Christensen |
|
| 11 | - * @since 4.5.0 |
|
| 12 | - * |
|
| 13 | - */ |
|
| 3 | + * |
|
| 4 | + * Class EE_SPCO_Reg_Step_Attendee_Information |
|
| 5 | + * |
|
| 6 | + * Description |
|
| 7 | + * |
|
| 8 | + * @package Event Espresso |
|
| 9 | + * @subpackage core |
|
| 10 | + * @author Brent Christensen |
|
| 11 | + * @since 4.5.0 |
|
| 12 | + * |
|
| 13 | + */ |
|
| 14 | 14 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step { |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -135,28 +135,28 @@ discard block |
||
| 135 | 135 | $registration instanceof EE_Registration |
| 136 | 136 | && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
| 137 | 137 | ) { |
| 138 | - $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
| 139 | - if ( ! $this->checkout->admin_request) { |
|
| 140 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
| 141 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
| 142 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
| 143 | - ) |
|
| 144 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
| 145 | - : 1; |
|
| 146 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 147 | - $this->checkout->cart->get_grand_total(), |
|
| 148 | - 'Ticket', |
|
| 149 | - array($registration->ticket()->ID()) |
|
| 150 | - ); |
|
| 151 | - $ticket_line_item = is_array($ticket_line_item) |
|
| 152 | - ? reset($ticket_line_item) |
|
| 153 | - : $ticket_line_item; |
|
| 154 | - $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
| 155 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 156 | - } |
|
| 157 | - if ($registration->is_primary_registrant()) { |
|
| 158 | - $primary_registrant = $registration->reg_url_link(); |
|
| 159 | - } |
|
| 138 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
| 139 | + if ( ! $this->checkout->admin_request) { |
|
| 140 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
| 141 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
| 142 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
| 143 | + ) |
|
| 144 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
| 145 | + : 1; |
|
| 146 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 147 | + $this->checkout->cart->get_grand_total(), |
|
| 148 | + 'Ticket', |
|
| 149 | + array($registration->ticket()->ID()) |
|
| 150 | + ); |
|
| 151 | + $ticket_line_item = is_array($ticket_line_item) |
|
| 152 | + ? reset($ticket_line_item) |
|
| 153 | + : $ticket_line_item; |
|
| 154 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
| 155 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 156 | + } |
|
| 157 | + if ($registration->is_primary_registrant()) { |
|
| 158 | + $primary_registrant = $registration->reg_url_link(); |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | // print_copy_info ? |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | // generate hidden input |
| 169 | 169 | if ( |
| 170 | 170 | isset( $subsections[ $primary_registrant ] ) |
| 171 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 171 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 172 | 172 | ) { |
| 173 | 173 | $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
| 174 | 174 | } |
@@ -196,42 +196,42 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | |
| 199 | - /** |
|
| 199 | + /** |
|
| 200 | 200 | * @param EE_Registration $registration |
| 201 | 201 | * @return EE_Form_Section_Base |
| 202 | 202 | * @throws \EE_Error |
| 203 | 203 | */ |
| 204 | 204 | private function _registrations_reg_form( EE_Registration $registration ) { |
| 205 | 205 | static $attendee_nmbr = 1; |
| 206 | - $form_args = array(); |
|
| 206 | + $form_args = array(); |
|
| 207 | 207 | // verify that registration has valid event |
| 208 | 208 | if ( $registration->event() instanceof EE_Event ) { |
| 209 | 209 | $question_groups = $registration->event()->question_groups( |
| 210 | - array( |
|
| 211 | - array( |
|
| 212 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 213 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
| 214 | - ), |
|
| 215 | - 'order_by' => array('QSG_order' => 'ASC') |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 210 | + array( |
|
| 211 | + array( |
|
| 212 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 213 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
| 214 | + ), |
|
| 215 | + 'order_by' => array('QSG_order' => 'ASC') |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | 218 | if ( $question_groups ) { |
| 219 | - // array of params to pass to parent constructor |
|
| 220 | - $form_args = array( |
|
| 221 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 222 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 223 | - 'html_style' => $this->checkout->admin_request |
|
| 224 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 225 | - : '', |
|
| 226 | - 'subsections' => array(), |
|
| 227 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 228 | - array( |
|
| 229 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 230 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
| 231 | - ) |
|
| 232 | - ) |
|
| 233 | - ); |
|
| 234 | - foreach ( $question_groups as $question_group ) { |
|
| 219 | + // array of params to pass to parent constructor |
|
| 220 | + $form_args = array( |
|
| 221 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 222 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 223 | + 'html_style' => $this->checkout->admin_request |
|
| 224 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 225 | + : '', |
|
| 226 | + 'subsections' => array(), |
|
| 227 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 228 | + array( |
|
| 229 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 230 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
| 231 | + ) |
|
| 232 | + ) |
|
| 233 | + ); |
|
| 234 | + foreach ( $question_groups as $question_group ) { |
|
| 235 | 235 | if ( $question_group instanceof EE_Question_Group ) { |
| 236 | 236 | $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
| 237 | 237 | $registration, |
@@ -239,19 +239,19 @@ discard block |
||
| 239 | 239 | ); |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - // add hidden input |
|
| 243 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 244 | - $registration |
|
| 245 | - ); |
|
| 246 | - // if we have question groups for additional attendees, then display the copy options |
|
| 242 | + // add hidden input |
|
| 243 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 244 | + $registration |
|
| 245 | + ); |
|
| 246 | + // if we have question groups for additional attendees, then display the copy options |
|
| 247 | 247 | $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
| 248 | - if ($registration->is_primary_registrant()) { |
|
| 249 | - // generate hidden input |
|
| 250 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
| 251 | - } |
|
| 252 | - } |
|
| 248 | + if ($registration->is_primary_registrant()) { |
|
| 249 | + // generate hidden input |
|
| 250 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | 253 | } |
| 254 | - $attendee_nmbr++; |
|
| 254 | + $attendee_nmbr++; |
|
| 255 | 255 | return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML(); |
| 256 | 256 | } |
| 257 | 257 | |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | if ( isset( $valid_data[ $reg_url_link ] ) ) { |
| 885 | 885 | // do we need to copy basic info from primary attendee ? |
| 886 | 886 | $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
| 887 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
| 887 | + && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
| 888 | 888 | ? true |
| 889 | 889 | : false; |
| 890 | 890 | // filter form input data for this registration |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | ) ) { |
| 1055 | 1055 | return true; |
| 1056 | 1056 | } |
| 1057 | - /* |
|
| 1057 | + /* |
|
| 1058 | 1058 | * $answer_cache_id is the key used to find the EE_Answer we want |
| 1059 | 1059 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1060 | 1060 | */ |
@@ -1062,7 +1062,7 @@ discard block |
||
| 1062 | 1062 | ? $form_input . '-' . $registration->reg_url_link() |
| 1063 | 1063 | : $form_input; |
| 1064 | 1064 | $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
| 1065 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1065 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1066 | 1066 | ? true |
| 1067 | 1067 | : false; |
| 1068 | 1068 | //rename form_inputs if they are EE_Attendee properties |
@@ -1182,7 +1182,7 @@ discard block |
||
| 1182 | 1182 | // then attempt to copy them from the primary attendee |
| 1183 | 1183 | if ( |
| 1184 | 1184 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
| 1185 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1185 | + && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1186 | 1186 | ) { |
| 1187 | 1187 | return $this->checkout->primary_attendee_obj; |
| 1188 | 1188 | } |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | } |
| 1301 | 1301 | foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
| 1302 | 1302 | if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
| 1303 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1303 | + || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1304 | 1304 | ) { |
| 1305 | 1305 | $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
| 1306 | 1306 | $critical_attendee_detail |
@@ -41,21 +41,21 @@ discard block |
||
| 41 | 41 | * @access public |
| 42 | 42 | * @param EE_Checkout $checkout |
| 43 | 43 | */ |
| 44 | - public function __construct( EE_Checkout $checkout ) { |
|
| 44 | + public function __construct(EE_Checkout $checkout) { |
|
| 45 | 45 | $this->_slug = 'attendee_information'; |
| 46 | 46 | $this->_name = __('Attendee Information', 'event_espresso'); |
| 47 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
| 47 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
| 48 | 48 | $this->checkout = $checkout; |
| 49 | 49 | $this->_reset_success_message(); |
| 50 | 50 | $this->set_instructions( |
| 51 | - __( 'Please answer the following registration questions before proceeding.', 'event_espresso' ) |
|
| 51 | + __('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | public function translate_js_strings() { |
| 58 | - EE_Registry::$i18n_js_strings['required_field'] = __( ' is a required question.', 'event_espresso' ); |
|
| 58 | + EE_Registry::$i18n_js_strings['required_field'] = __(' is a required question.', 'event_espresso'); |
|
| 59 | 59 | EE_Registry::$i18n_js_strings['required_multi_field'] = __( |
| 60 | 60 | ' is a required question. Please enter a value for at least one of the options.', |
| 61 | 61 | 'event_espresso' |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | // calculate taxes |
| 116 | 116 | $Line_Item_Display->display_line_item( |
| 117 | 117 | $this->checkout->cart->get_grand_total(), |
| 118 | - array( 'set_tax_rate' => true ) |
|
| 118 | + array('set_tax_rate' => true) |
|
| 119 | 119 | ); |
| 120 | 120 | /** @var $subsections EE_Form_Section_Proper[] */ |
| 121 | 121 | $subsections = array( |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | 'ticket_count' => array() |
| 128 | 128 | ); |
| 129 | 129 | // grab the saved registrations from the transaction |
| 130 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
| 131 | - if ( $registrations ) { |
|
| 132 | - foreach ( $registrations as $registration ) { |
|
| 130 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 131 | + if ($registrations) { |
|
| 132 | + foreach ($registrations as $registration) { |
|
| 133 | 133 | // can this registration be processed during this visit ? |
| 134 | 134 | if ( |
| 135 | 135 | $registration instanceof EE_Registration |
| 136 | - && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
|
| 136 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
| 137 | 137 | ) { |
| 138 | 138 | $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
| 139 | 139 | if ( ! $this->checkout->admin_request) { |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | // print_copy_info ? |
| 163 | - if ( $primary_registrant && ! $this->checkout->admin_request && count( $registrations ) > 1 ) { |
|
| 163 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
| 164 | 164 | // TODO: add admin option for toggling copy attendee info, then use that value to change $this->_print_copy_info |
| 165 | 165 | $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
| 166 | 166 | ? $this->_copy_attendee_info_form() |
| 167 | 167 | : $this->_auto_copy_attendee_info(); |
| 168 | 168 | // generate hidden input |
| 169 | 169 | if ( |
| 170 | - isset( $subsections[ $primary_registrant ] ) |
|
| 171 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
| 170 | + isset($subsections[$primary_registrant]) |
|
| 171 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
| 172 | 172 | ) { |
| 173 | - $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
|
| 173 | + $subsections[$primary_registrant]->add_subsections($copy_options, 'primary_registrant', false); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -182,8 +182,7 @@ discard block |
||
| 182 | 182 | 'html_id' => $this->reg_form_name(), |
| 183 | 183 | 'subsections' => $subsections, |
| 184 | 184 | 'layout_strategy' => $this->checkout->admin_request ? |
| 185 | - new EE_Div_Per_Section_Layout() : |
|
| 186 | - new EE_Template_Layout( |
|
| 185 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
| 187 | 186 | array( |
| 188 | 187 | 'layout_template_file' => $this->_template, // layout_template |
| 189 | 188 | 'template_args' => $template_args |
@@ -201,11 +200,11 @@ discard block |
||
| 201 | 200 | * @return EE_Form_Section_Base |
| 202 | 201 | * @throws \EE_Error |
| 203 | 202 | */ |
| 204 | - private function _registrations_reg_form( EE_Registration $registration ) { |
|
| 203 | + private function _registrations_reg_form(EE_Registration $registration) { |
|
| 205 | 204 | static $attendee_nmbr = 1; |
| 206 | 205 | $form_args = array(); |
| 207 | 206 | // verify that registration has valid event |
| 208 | - if ( $registration->event() instanceof EE_Event ) { |
|
| 207 | + if ($registration->event() instanceof EE_Event) { |
|
| 209 | 208 | $question_groups = $registration->event()->question_groups( |
| 210 | 209 | array( |
| 211 | 210 | array( |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | 'order_by' => array('QSG_order' => 'ASC') |
| 216 | 215 | ) |
| 217 | 216 | ); |
| 218 | - if ( $question_groups ) { |
|
| 217 | + if ($question_groups) { |
|
| 219 | 218 | // array of params to pass to parent constructor |
| 220 | 219 | $form_args = array( |
| 221 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 220 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
| 222 | 221 | 'html_class' => 'ee-reg-form-attendee-dv', |
| 223 | 222 | 'html_style' => $this->checkout->admin_request |
| 224 | 223 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -231,9 +230,9 @@ discard block |
||
| 231 | 230 | ) |
| 232 | 231 | ) |
| 233 | 232 | ); |
| 234 | - foreach ( $question_groups as $question_group ) { |
|
| 235 | - if ( $question_group instanceof EE_Question_Group ) { |
|
| 236 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
| 233 | + foreach ($question_groups as $question_group) { |
|
| 234 | + if ($question_group instanceof EE_Question_Group) { |
|
| 235 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
| 237 | 236 | $registration, |
| 238 | 237 | $question_group |
| 239 | 238 | ); |
@@ -252,7 +251,7 @@ discard block |
||
| 252 | 251 | } |
| 253 | 252 | } |
| 254 | 253 | $attendee_nmbr++; |
| 255 | - return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML(); |
|
| 254 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
| 256 | 255 | } |
| 257 | 256 | |
| 258 | 257 | |
@@ -273,7 +272,7 @@ discard block |
||
| 273 | 272 | // generate hidden input |
| 274 | 273 | return new EE_Hidden_Input( |
| 275 | 274 | array( |
| 276 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 275 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
| 277 | 276 | 'default' => $additional_attendee_reg_info |
| 278 | 277 | ) |
| 279 | 278 | ); |
@@ -287,26 +286,26 @@ discard block |
||
| 287 | 286 | * @return EE_Form_Section_Proper |
| 288 | 287 | * @throws \EE_Error |
| 289 | 288 | */ |
| 290 | - private function _question_group_reg_form( EE_Registration $registration, EE_Question_Group $question_group ){ |
|
| 289 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) { |
|
| 291 | 290 | // array of params to pass to parent constructor |
| 292 | 291 | $form_args = array( |
| 293 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
| 292 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier(), |
|
| 294 | 293 | 'html_class' => $this->checkout->admin_request |
| 295 | 294 | ? 'form-table ee-reg-form-qstn-grp-dv' |
| 296 | 295 | : 'ee-reg-form-qstn-grp-dv', |
| 297 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
| 296 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl', |
|
| 298 | 297 | 'subsections' => array( |
| 299 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header( $question_group ) |
|
| 298 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group) |
|
| 300 | 299 | ), |
| 301 | 300 | 'layout_strategy' => $this->checkout->admin_request |
| 302 | 301 | ? new EE_Admin_Two_Column_Layout() |
| 303 | 302 | : new EE_Div_Per_Section_Layout() |
| 304 | 303 | ); |
| 305 | 304 | // where params |
| 306 | - $query_params = array( 'QST_deleted' => 0 ); |
|
| 305 | + $query_params = array('QST_deleted' => 0); |
|
| 307 | 306 | // don't load admin only questions on the frontend |
| 308 | - if ( ! $this->checkout->admin_request ) { |
|
| 309 | - $query_params['QST_admin_only'] = array( '!=', true ); |
|
| 307 | + if ( ! $this->checkout->admin_request) { |
|
| 308 | + $query_params['QST_admin_only'] = array('!=', true); |
|
| 310 | 309 | } |
| 311 | 310 | $questions = $question_group->get_many_related( |
| 312 | 311 | 'Question', |
@@ -328,10 +327,10 @@ discard block |
||
| 328 | 327 | ) |
| 329 | 328 | ); |
| 330 | 329 | // loop thru questions |
| 331 | - foreach ( $questions as $question ) { |
|
| 332 | - if( $question instanceof EE_Question ){ |
|
| 330 | + foreach ($questions as $question) { |
|
| 331 | + if ($question instanceof EE_Question) { |
|
| 333 | 332 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
| 334 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question( $registration, $question ); |
|
| 333 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
| 335 | 334 | } |
| 336 | 335 | } |
| 337 | 336 | $form_args['subsections'] = apply_filters( |
@@ -352,7 +351,7 @@ discard block |
||
| 352 | 351 | ) |
| 353 | 352 | ); |
| 354 | 353 | // d( $form_args ); |
| 355 | - $question_group_reg_form = new EE_Form_Section_Proper( $form_args ); |
|
| 354 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
| 356 | 355 | return apply_filters( |
| 357 | 356 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
| 358 | 357 | $question_group_reg_form, |
@@ -369,11 +368,11 @@ discard block |
||
| 369 | 368 | * @param EE_Question_Group $question_group |
| 370 | 369 | * @return EE_Form_Section_HTML |
| 371 | 370 | */ |
| 372 | - private function _question_group_header( EE_Question_Group $question_group ){ |
|
| 371 | + private function _question_group_header(EE_Question_Group $question_group) { |
|
| 373 | 372 | $html = ''; |
| 374 | 373 | // group_name |
| 375 | - if ( $question_group->show_group_name() && $question_group->name() !== '' ) { |
|
| 376 | - if ( $this->checkout->admin_request ) { |
|
| 374 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
| 375 | + if ($this->checkout->admin_request) { |
|
| 377 | 376 | $html .= EEH_HTML::br(); |
| 378 | 377 | $html .= EEH_HTML::h3( |
| 379 | 378 | $question_group->name(), |
@@ -387,7 +386,7 @@ discard block |
||
| 387 | 386 | } |
| 388 | 387 | } |
| 389 | 388 | // group_desc |
| 390 | - if ( $question_group->show_group_desc() && $question_group->desc() !== '' ) { |
|
| 389 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
| 391 | 390 | $html .= EEH_HTML::p( |
| 392 | 391 | $question_group->desc(), |
| 393 | 392 | '', |
@@ -397,7 +396,7 @@ discard block |
||
| 397 | 396 | ); |
| 398 | 397 | |
| 399 | 398 | } |
| 400 | - return new EE_Form_Section_HTML( $html ); |
|
| 399 | + return new EE_Form_Section_HTML($html); |
|
| 401 | 400 | } |
| 402 | 401 | |
| 403 | 402 | |
@@ -407,7 +406,7 @@ discard block |
||
| 407 | 406 | * @return EE_Form_Section_Proper |
| 408 | 407 | * @throws \EE_Error |
| 409 | 408 | */ |
| 410 | - private function _copy_attendee_info_form(){ |
|
| 409 | + private function _copy_attendee_info_form() { |
|
| 411 | 410 | // array of params to pass to parent constructor |
| 412 | 411 | return new EE_Form_Section_Proper( |
| 413 | 412 | array( |
@@ -436,7 +435,7 @@ discard block |
||
| 436 | 435 | private function _auto_copy_attendee_info() { |
| 437 | 436 | return new EE_Form_Section_HTML( |
| 438 | 437 | EEH_Template::locate_template( |
| 439 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
| 438 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
| 440 | 439 | apply_filters( |
| 441 | 440 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
| 442 | 441 | array() |
@@ -460,32 +459,32 @@ discard block |
||
| 460 | 459 | $copy_attendee_info_inputs = array(); |
| 461 | 460 | $prev_ticket = NULL; |
| 462 | 461 | // grab the saved registrations from the transaction |
| 463 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
| 464 | - foreach ( $registrations as $registration ) { |
|
| 462 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 463 | + foreach ($registrations as $registration) { |
|
| 465 | 464 | // for all attendees other than the primary attendee |
| 466 | - if ( $registration instanceof EE_Registration && ! $registration->is_primary_registrant() ) { |
|
| 465 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
| 467 | 466 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
| 468 | - if ( $registration->ticket()->ID() !== $prev_ticket ) { |
|
| 467 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 469 | 468 | $item_name = $registration->ticket()->name(); |
| 470 | 469 | $item_name .= $registration->ticket()->description() !== '' |
| 471 | - ? ' - ' . $registration->ticket()->description() |
|
| 470 | + ? ' - '.$registration->ticket()->description() |
|
| 472 | 471 | : ''; |
| 473 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] = new EE_Form_Section_HTML( |
|
| 474 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 472 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = new EE_Form_Section_HTML( |
|
| 473 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
| 475 | 474 | ); |
| 476 | 475 | $prev_ticket = $registration->ticket()->ID(); |
| 477 | 476 | } |
| 478 | 477 | |
| 479 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = new |
|
| 478 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = new |
|
| 480 | 479 | EE_Checkbox_Multi_Input( |
| 481 | 480 | array( |
| 482 | 481 | $registration->ID() => sprintf( |
| 483 | - __( 'Attendee #%s', 'event_espresso' ), |
|
| 482 | + __('Attendee #%s', 'event_espresso'), |
|
| 484 | 483 | $registration->count() |
| 485 | 484 | ) |
| 486 | 485 | ), |
| 487 | 486 | array( |
| 488 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 487 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
| 489 | 488 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
| 490 | 489 | 'display_html_label_text' => false |
| 491 | 490 | ) |
@@ -505,7 +504,7 @@ discard block |
||
| 505 | 504 | * @return EE_Form_Input_Base |
| 506 | 505 | * @throws \EE_Error |
| 507 | 506 | */ |
| 508 | - private function _additional_primary_registrant_inputs( EE_Registration $registration ){ |
|
| 507 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) { |
|
| 509 | 508 | // generate hidden input |
| 510 | 509 | return new EE_Hidden_Input( |
| 511 | 510 | array( |
@@ -524,7 +523,7 @@ discard block |
||
| 524 | 523 | * @return EE_Form_Input_Base |
| 525 | 524 | * @throws \EE_Error |
| 526 | 525 | */ |
| 527 | - public function reg_form_question( EE_Registration $registration, EE_Question $question ){ |
|
| 526 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) { |
|
| 528 | 527 | |
| 529 | 528 | // if this question was for an attendee detail, then check for that answer |
| 530 | 529 | $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
@@ -533,32 +532,32 @@ discard block |
||
| 533 | 532 | ); |
| 534 | 533 | $answer = $answer_value === null |
| 535 | 534 | ? EEM_Answer::instance()->get_one( |
| 536 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
| 535 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 537 | 536 | ) |
| 538 | 537 | : null; |
| 539 | 538 | // if NOT returning to edit an existing registration |
| 540 | 539 | // OR if this question is for an attendee property |
| 541 | 540 | // OR we still don't have an EE_Answer object |
| 542 | - if( $answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link() ) { |
|
| 541 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
| 543 | 542 | // create an EE_Answer object for storing everything in |
| 544 | - $answer = EE_Answer::new_instance ( array( |
|
| 543 | + $answer = EE_Answer::new_instance(array( |
|
| 545 | 544 | 'QST_ID'=> $question->ID(), |
| 546 | 545 | 'REG_ID'=> $registration->ID() |
| 547 | 546 | )); |
| 548 | 547 | } |
| 549 | 548 | // verify instance |
| 550 | - if( $answer instanceof EE_Answer ){ |
|
| 551 | - if ( ! empty( $answer_value )) { |
|
| 552 | - $answer->set( 'ANS_value', $answer_value ); |
|
| 549 | + if ($answer instanceof EE_Answer) { |
|
| 550 | + if ( ! empty($answer_value)) { |
|
| 551 | + $answer->set('ANS_value', $answer_value); |
|
| 553 | 552 | } |
| 554 | - $answer->cache( 'Question', $question ); |
|
| 553 | + $answer->cache('Question', $question); |
|
| 555 | 554 | //remember system ID had a bug where sometimes it could be null |
| 556 | - $answer_cache_id =$question->is_system_question() |
|
| 557 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 558 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 559 | - $registration->cache( 'Answer', $answer, $answer_cache_id ); |
|
| 555 | + $answer_cache_id = $question->is_system_question() |
|
| 556 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
| 557 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
| 558 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
| 560 | 559 | } |
| 561 | - return $this->_generate_question_input( $registration, $question, $answer ); |
|
| 560 | + return $this->_generate_question_input($registration, $question, $answer); |
|
| 562 | 561 | |
| 563 | 562 | } |
| 564 | 563 | |
@@ -571,46 +570,46 @@ discard block |
||
| 571 | 570 | * @return EE_Form_Input_Base |
| 572 | 571 | * @throws \EE_Error |
| 573 | 572 | */ |
| 574 | - private function _generate_question_input( EE_Registration $registration, EE_Question $question, $answer ){ |
|
| 573 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) { |
|
| 575 | 574 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
| 576 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
| 575 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
| 577 | 576 | add_filter( |
| 578 | 577 | 'FHEE__EE_Question__generate_form_input__country_options', |
| 579 | - array( $this, 'use_cached_countries_for_form_input' ), |
|
| 578 | + array($this, 'use_cached_countries_for_form_input'), |
|
| 580 | 579 | 10, |
| 581 | 580 | 4 |
| 582 | 581 | ); |
| 583 | 582 | add_filter( |
| 584 | 583 | 'FHEE__EE_Question__generate_form_input__state_options', |
| 585 | - array( $this, 'use_cached_states_for_form_input' ), |
|
| 584 | + array($this, 'use_cached_states_for_form_input'), |
|
| 586 | 585 | 10, |
| 587 | 586 | 4 |
| 588 | 587 | ); |
| 589 | 588 | $input_constructor_args = array( |
| 590 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 591 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 592 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 593 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 589 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
| 590 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 591 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
| 592 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 594 | 593 | 'html_label_class' => 'ee-reg-qstn', |
| 595 | 594 | ); |
| 596 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 597 | - if ( $answer instanceof EE_Answer && $answer->ID() ) { |
|
| 598 | - $input_constructor_args[ 'html_name' ] .= '[' . $answer->ID() . ']'; |
|
| 599 | - $input_constructor_args[ 'html_id' ] .= '-' . $answer->ID(); |
|
| 600 | - $input_constructor_args[ 'html_label_id' ] .= '-' . $answer->ID(); |
|
| 595 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 596 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
| 597 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
| 598 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
| 599 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
| 601 | 600 | } |
| 602 | - $form_input = $question->generate_form_input( |
|
| 601 | + $form_input = $question->generate_form_input( |
|
| 603 | 602 | $registration, |
| 604 | 603 | $answer, |
| 605 | 604 | $input_constructor_args |
| 606 | 605 | ); |
| 607 | 606 | remove_filter( |
| 608 | 607 | 'FHEE__EE_Question__generate_form_input__country_options', |
| 609 | - array( $this, 'use_cached_countries_for_form_input' ) |
|
| 608 | + array($this, 'use_cached_countries_for_form_input') |
|
| 610 | 609 | ); |
| 611 | 610 | remove_filter( |
| 612 | 611 | 'FHEE__EE_Question__generate_form_input__state_options', |
| 613 | - array( $this, 'use_cached_states_for_form_input' ) |
|
| 612 | + array($this, 'use_cached_states_for_form_input') |
|
| 614 | 613 | ); |
| 615 | 614 | return $form_input; |
| 616 | 615 | } |
@@ -632,22 +631,22 @@ discard block |
||
| 632 | 631 | \EE_Registration $registration = null, |
| 633 | 632 | \EE_Answer $answer = null |
| 634 | 633 | ) { |
| 635 | - $country_options = array( '' => '' ); |
|
| 634 | + $country_options = array('' => ''); |
|
| 636 | 635 | // get possibly cached list of countries |
| 637 | 636 | $countries = $this->checkout->action === 'process_reg_step' |
| 638 | 637 | ? EEM_Country::instance()->get_all_countries() |
| 639 | 638 | : EEM_Country::instance()->get_all_active_countries(); |
| 640 | - if ( ! empty( $countries )) { |
|
| 641 | - foreach( $countries as $country ){ |
|
| 642 | - if ( $country instanceof EE_Country ) { |
|
| 643 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 639 | + if ( ! empty($countries)) { |
|
| 640 | + foreach ($countries as $country) { |
|
| 641 | + if ($country instanceof EE_Country) { |
|
| 642 | + $country_options[$country->ID()] = $country->name(); |
|
| 644 | 643 | } |
| 645 | 644 | } |
| 646 | 645 | } |
| 647 | - if( $question instanceof EE_Question |
|
| 648 | - && $registration instanceof EE_Registration ) { |
|
| 646 | + if ($question instanceof EE_Question |
|
| 647 | + && $registration instanceof EE_Registration) { |
|
| 649 | 648 | $answer = EEM_Answer::instance()->get_one( |
| 650 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
| 649 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 651 | 650 | ); |
| 652 | 651 | } else { |
| 653 | 652 | $answer = EE_Answer::new_instance(); |
@@ -680,14 +679,14 @@ discard block |
||
| 680 | 679 | \EE_Registration $registration = null, |
| 681 | 680 | \EE_Answer $answer = null |
| 682 | 681 | ) { |
| 683 | - $state_options = array( '' => array( '' => '')); |
|
| 682 | + $state_options = array('' => array('' => '')); |
|
| 684 | 683 | $states = $this->checkout->action === 'process_reg_step' |
| 685 | 684 | ? EEM_State::instance()->get_all_states() |
| 686 | 685 | : EEM_State::instance()->get_all_active_states(); |
| 687 | - if ( ! empty( $states )) { |
|
| 688 | - foreach( $states as $state ){ |
|
| 689 | - if ( $state instanceof EE_State ) { |
|
| 690 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
| 686 | + if ( ! empty($states)) { |
|
| 687 | + foreach ($states as $state) { |
|
| 688 | + if ($state instanceof EE_State) { |
|
| 689 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
| 691 | 690 | } |
| 692 | 691 | } |
| 693 | 692 | } |
@@ -715,24 +714,24 @@ discard block |
||
| 715 | 714 | * @throws \EE_Error |
| 716 | 715 | */ |
| 717 | 716 | public function process_reg_step() { |
| 718 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 717 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 719 | 718 | // grab validated data from form |
| 720 | 719 | $valid_data = $this->checkout->current_step->valid_data(); |
| 721 | 720 | // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
| 722 | 721 | // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
| 723 | 722 | // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
| 724 | - if ( empty( $valid_data )) { |
|
| 723 | + if (empty($valid_data)) { |
|
| 725 | 724 | EE_Error::add_error( |
| 726 | - __( 'No valid question responses were received.', 'event_espresso' ), |
|
| 725 | + __('No valid question responses were received.', 'event_espresso'), |
|
| 727 | 726 | __FILE__, |
| 728 | 727 | __FUNCTION__, |
| 729 | 728 | __LINE__ |
| 730 | 729 | ); |
| 731 | 730 | return false; |
| 732 | 731 | } |
| 733 | - if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg ) { |
|
| 732 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 734 | 733 | EE_Error::add_error( |
| 735 | - __( 'A valid transaction could not be initiated for processing your registrations.', 'event_espresso' ), |
|
| 734 | + __('A valid transaction could not be initiated for processing your registrations.', 'event_espresso'), |
|
| 736 | 735 | __FILE__, |
| 737 | 736 | __FUNCTION__, |
| 738 | 737 | __LINE__ |
@@ -740,11 +739,11 @@ discard block |
||
| 740 | 739 | return false; |
| 741 | 740 | } |
| 742 | 741 | // get cached registrations |
| 743 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
| 742 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 744 | 743 | // verify we got the goods |
| 745 | - if ( empty( $registrations )) { |
|
| 744 | + if (empty($registrations)) { |
|
| 746 | 745 | EE_Error::add_error( |
| 747 | - __( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ), |
|
| 746 | + __('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
| 748 | 747 | __FILE__, |
| 749 | 748 | __FUNCTION__, |
| 750 | 749 | __LINE__ |
@@ -752,15 +751,15 @@ discard block |
||
| 752 | 751 | return false; |
| 753 | 752 | } |
| 754 | 753 | // extract attendee info from form data and save to model objects |
| 755 | - $registrations_processed = $this->_process_registrations( $registrations, $valid_data ); |
|
| 754 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
| 756 | 755 | // if first pass thru SPCO, |
| 757 | 756 | // then let's check processed registrations against the total number of tickets in the cart |
| 758 | - if ( $registrations_processed === false ) { |
|
| 757 | + if ($registrations_processed === false) { |
|
| 759 | 758 | // but return immediately if the previous step exited early due to errors |
| 760 | 759 | return false; |
| 761 | - } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count ) { |
|
| 760 | + } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 762 | 761 | // generate a correctly translated string for all possible singular/plural combinations |
| 763 | - if ( $this->checkout->total_ticket_count === 1 && $registrations_processed !== 1 ) { |
|
| 762 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
| 764 | 763 | $error_msg = sprintf( |
| 765 | 764 | __( |
| 766 | 765 | 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
@@ -769,7 +768,7 @@ discard block |
||
| 769 | 768 | $this->checkout->total_ticket_count, |
| 770 | 769 | $registrations_processed |
| 771 | 770 | ); |
| 772 | - } else if ( $this->checkout->total_ticket_count !== 1 && $registrations_processed === 1 ) { |
|
| 771 | + } else if ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
| 773 | 772 | $error_msg = sprintf( |
| 774 | 773 | __( |
| 775 | 774 | 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
@@ -788,17 +787,17 @@ discard block |
||
| 788 | 787 | $registrations_processed |
| 789 | 788 | ); |
| 790 | 789 | } |
| 791 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 790 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 792 | 791 | return false; |
| 793 | 792 | } |
| 794 | 793 | // mark this reg step as completed |
| 795 | 794 | $this->set_completed(); |
| 796 | 795 | $this->_set_success_message( |
| 797 | - __( 'The Attendee Information Step has been successfully completed.', 'event_espresso' ) |
|
| 796 | + __('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
| 798 | 797 | ); |
| 799 | 798 | //do action in case a plugin wants to do something with the data submitted in step 1. |
| 800 | 799 | //passes EE_Single_Page_Checkout, and it's posted data |
| 801 | - do_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data ); |
|
| 800 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
| 802 | 801 | return true; |
| 803 | 802 | } |
| 804 | 803 | |
@@ -812,9 +811,9 @@ discard block |
||
| 812 | 811 | * @return boolean | int |
| 813 | 812 | * @throws \EE_Error |
| 814 | 813 | */ |
| 815 | - private function _process_registrations( $registrations = array(), $valid_data = array() ) { |
|
| 814 | + private function _process_registrations($registrations = array(), $valid_data = array()) { |
|
| 816 | 815 | // load resources and set some defaults |
| 817 | - EE_Registry::instance()->load_model( 'Attendee' ); |
|
| 816 | + EE_Registry::instance()->load_model('Attendee'); |
|
| 818 | 817 | // holder for primary registrant attendee object |
| 819 | 818 | $this->checkout->primary_attendee_obj = NULL; |
| 820 | 819 | // array for tracking reg form data for the primary registrant |
@@ -831,9 +830,9 @@ discard block |
||
| 831 | 830 | // attendee counter |
| 832 | 831 | $att_nmbr = 0; |
| 833 | 832 | // grab the saved registrations from the transaction |
| 834 | - foreach ( $registrations as $registration ) { |
|
| 833 | + foreach ($registrations as $registration) { |
|
| 835 | 834 | // verify EE_Registration object |
| 836 | - if ( ! $registration instanceof EE_Registration ) { |
|
| 835 | + if ( ! $registration instanceof EE_Registration) { |
|
| 837 | 836 | EE_Error::add_error( |
| 838 | 837 | __( |
| 839 | 838 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -848,12 +847,12 @@ discard block |
||
| 848 | 847 | /** @var string $reg_url_link */ |
| 849 | 848 | $reg_url_link = $registration->reg_url_link(); |
| 850 | 849 | // reg_url_link exists ? |
| 851 | - if ( ! empty( $reg_url_link ) ) { |
|
| 850 | + if ( ! empty($reg_url_link)) { |
|
| 852 | 851 | // should this registration be processed during this visit ? |
| 853 | - if ( $this->checkout->visit_allows_processing_of_this_registration( $registration ) ) { |
|
| 852 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
| 854 | 853 | // if NOT revisiting, then let's save the registration now, |
| 855 | 854 | // so that we have a REG_ID to use when generating other objects |
| 856 | - if ( ! $this->checkout->revisit ) { |
|
| 855 | + if ( ! $this->checkout->revisit) { |
|
| 857 | 856 | $registration->save(); |
| 858 | 857 | } |
| 859 | 858 | /** |
@@ -863,7 +862,7 @@ discard block |
||
| 863 | 862 | * @var bool if true is returned by the plugin then the |
| 864 | 863 | * registration processing is halted. |
| 865 | 864 | */ |
| 866 | - if ( apply_filters( |
|
| 865 | + if (apply_filters( |
|
| 867 | 866 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
| 868 | 867 | false, |
| 869 | 868 | $att_nmbr, |
@@ -871,38 +870,38 @@ discard block |
||
| 871 | 870 | $registrations, |
| 872 | 871 | $valid_data, |
| 873 | 872 | $this |
| 874 | - ) ) { |
|
| 873 | + )) { |
|
| 875 | 874 | return false; |
| 876 | 875 | } |
| 877 | 876 | |
| 878 | 877 | // Houston, we have a registration! |
| 879 | 878 | $att_nmbr++; |
| 880 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
| 879 | + $this->_attendee_data[$reg_url_link] = array(); |
|
| 881 | 880 | // grab any existing related answer objects |
| 882 | 881 | $this->_registration_answers = $registration->answers(); |
| 883 | 882 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
| 884 | - if ( isset( $valid_data[ $reg_url_link ] ) ) { |
|
| 883 | + if (isset($valid_data[$reg_url_link])) { |
|
| 885 | 884 | // do we need to copy basic info from primary attendee ? |
| 886 | - $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
|
| 887 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
| 885 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
| 886 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
| 888 | 887 | ? true |
| 889 | 888 | : false; |
| 890 | 889 | // filter form input data for this registration |
| 891 | - $valid_data[ $reg_url_link ] = (array)apply_filters( |
|
| 890 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
| 892 | 891 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
| 893 | - $valid_data[ $reg_url_link ] |
|
| 892 | + $valid_data[$reg_url_link] |
|
| 894 | 893 | ); |
| 895 | 894 | // EEH_Debug_Tools::printr( $valid_data[ $reg_url_link ], '$valid_data[ $reg_url_link ]', __FILE__, __LINE__ ); |
| 896 | - if ( isset( $valid_data['primary_attendee'] )) { |
|
| 897 | - $primary_registrant['line_item_id'] = ! empty( $valid_data['primary_attendee'] ) |
|
| 895 | + if (isset($valid_data['primary_attendee'])) { |
|
| 896 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
| 898 | 897 | ? $valid_data['primary_attendee'] |
| 899 | 898 | : false; |
| 900 | - unset( $valid_data['primary_attendee'] ); |
|
| 899 | + unset($valid_data['primary_attendee']); |
|
| 901 | 900 | } |
| 902 | 901 | // now loop through our array of valid post data && process attendee reg forms |
| 903 | - foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) { |
|
| 904 | - if ( ! in_array( $form_section, $non_input_form_sections )) { |
|
| 905 | - foreach ( $form_inputs as $form_input => $input_value ) { |
|
| 902 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
| 903 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
| 904 | + foreach ($form_inputs as $form_input => $input_value) { |
|
| 906 | 905 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
| 907 | 906 | // check for critical inputs |
| 908 | 907 | if ( |
@@ -916,16 +915,16 @@ discard block |
||
| 916 | 915 | // store a bit of data about the primary attendee |
| 917 | 916 | if ( |
| 918 | 917 | $att_nmbr === 1 |
| 919 | - && ! empty( $input_value ) |
|
| 918 | + && ! empty($input_value) |
|
| 920 | 919 | && $reg_url_link === $primary_registrant['line_item_id'] |
| 921 | 920 | ) { |
| 922 | - $primary_registrant[ $form_input ] = $input_value; |
|
| 921 | + $primary_registrant[$form_input] = $input_value; |
|
| 923 | 922 | } else if ( |
| 924 | 923 | $copy_primary |
| 925 | 924 | && $input_value === null |
| 926 | - && isset( $primary_registrant[ $form_input ] ) |
|
| 925 | + && isset($primary_registrant[$form_input]) |
|
| 927 | 926 | ) { |
| 928 | - $input_value = $primary_registrant[ $form_input ]; |
|
| 927 | + $input_value = $primary_registrant[$form_input]; |
|
| 929 | 928 | } |
| 930 | 929 | // now attempt to save the input data |
| 931 | 930 | if ( |
@@ -967,55 +966,55 @@ discard block |
||
| 967 | 966 | // have we met before? |
| 968 | 967 | $attendee = $this->_find_existing_attendee( |
| 969 | 968 | $registration, |
| 970 | - $this->_attendee_data[ $reg_url_link ] |
|
| 969 | + $this->_attendee_data[$reg_url_link] |
|
| 971 | 970 | ); |
| 972 | 971 | // did we find an already existing record for this attendee ? |
| 973 | - if ( $attendee instanceof EE_Attendee ) { |
|
| 972 | + if ($attendee instanceof EE_Attendee) { |
|
| 974 | 973 | $attendee = $this->_update_existing_attendee_data( |
| 975 | 974 | $attendee, |
| 976 | - $this->_attendee_data[ $reg_url_link ] |
|
| 975 | + $this->_attendee_data[$reg_url_link] |
|
| 977 | 976 | ); |
| 978 | 977 | } else { |
| 979 | 978 | // ensure critical details are set for additional attendees |
| 980 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
| 979 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
| 981 | 980 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
| 982 | - $this->_attendee_data[ $reg_url_link ] |
|
| 981 | + $this->_attendee_data[$reg_url_link] |
|
| 983 | 982 | ) |
| 984 | - : $this->_attendee_data[ $reg_url_link ]; |
|
| 983 | + : $this->_attendee_data[$reg_url_link]; |
|
| 985 | 984 | $attendee = $this->_create_new_attendee( |
| 986 | 985 | $registration, |
| 987 | - $this->_attendee_data[ $reg_url_link ] |
|
| 986 | + $this->_attendee_data[$reg_url_link] |
|
| 988 | 987 | ); |
| 989 | 988 | } |
| 990 | 989 | // who's #1 ? |
| 991 | - if ( $att_nmbr === 1 ) { |
|
| 990 | + if ($att_nmbr === 1) { |
|
| 992 | 991 | $this->checkout->primary_attendee_obj = $attendee; |
| 993 | 992 | } |
| 994 | 993 | } |
| 995 | 994 | // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
| 996 | 995 | // add relation to registration, set attendee ID, and cache attendee |
| 997 | - $this->_associate_attendee_with_registration( $registration, $attendee ); |
|
| 996 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
| 998 | 997 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
| 999 | - if ( ! $registration->attendee() instanceof EE_Attendee ) { |
|
| 1000 | - EE_Error::add_error( sprintf( __( 'Registration %s has an invalid or missing Attendee object.', 'event_espresso' ), $reg_url_link ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 998 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
| 999 | + EE_Error::add_error(sprintf(__('Registration %s has an invalid or missing Attendee object.', 'event_espresso'), $reg_url_link), __FILE__, __FUNCTION__, __LINE__); |
|
| 1001 | 1000 | return false; |
| 1002 | 1001 | } |
| 1003 | 1002 | /** @type EE_Registration_Processor $registration_processor */ |
| 1004 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
| 1003 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1005 | 1004 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
| 1006 | - $registration_processor->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
| 1005 | + $registration_processor->toggle_incomplete_registration_status_to_default($registration, false); |
|
| 1007 | 1006 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
| 1008 | 1007 | $this->checkout->transaction->toggle_failed_transaction_status(); |
| 1009 | 1008 | // if we've gotten this far, then let's save what we have |
| 1010 | 1009 | $registration->save(); |
| 1011 | 1010 | // add relation between TXN and registration |
| 1012 | - $this->_associate_registration_with_transaction( $registration ); |
|
| 1011 | + $this->_associate_registration_with_transaction($registration); |
|
| 1013 | 1012 | } // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) { |
| 1014 | 1013 | |
| 1015 | - } else { |
|
| 1016 | - EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1014 | + } else { |
|
| 1015 | + EE_Error::add_error(__('An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1017 | 1016 | // remove malformed data |
| 1018 | - unset( $valid_data[ $reg_url_link ] ); |
|
| 1017 | + unset($valid_data[$reg_url_link]); |
|
| 1019 | 1018 | return false; |
| 1020 | 1019 | } |
| 1021 | 1020 | |
@@ -1044,14 +1043,14 @@ discard block |
||
| 1044 | 1043 | // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
| 1045 | 1044 | // allow for plugins to hook in and do their own processing of the form input. |
| 1046 | 1045 | // For plugins to bypass normal processing here, they just need to return a boolean value. |
| 1047 | - if ( apply_filters( |
|
| 1046 | + if (apply_filters( |
|
| 1048 | 1047 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
| 1049 | 1048 | false, |
| 1050 | 1049 | $registration, |
| 1051 | 1050 | $form_input, |
| 1052 | 1051 | $input_value, |
| 1053 | 1052 | $this |
| 1054 | - ) ) { |
|
| 1053 | + )) { |
|
| 1055 | 1054 | return true; |
| 1056 | 1055 | } |
| 1057 | 1056 | /* |
@@ -1059,14 +1058,14 @@ discard block |
||
| 1059 | 1058 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1060 | 1059 | */ |
| 1061 | 1060 | $answer_cache_id = $this->checkout->reg_url_link |
| 1062 | - ? $form_input . '-' . $registration->reg_url_link() |
|
| 1061 | + ? $form_input.'-'.$registration->reg_url_link() |
|
| 1063 | 1062 | : $form_input; |
| 1064 | - $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
|
| 1065 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1063 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
| 1064 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
| 1066 | 1065 | ? true |
| 1067 | 1066 | : false; |
| 1068 | 1067 | //rename form_inputs if they are EE_Attendee properties |
| 1069 | - switch( (string)$form_input ) { |
|
| 1068 | + switch ((string) $form_input) { |
|
| 1070 | 1069 | |
| 1071 | 1070 | case 'state' : |
| 1072 | 1071 | case 'STA_ID' : |
@@ -1081,32 +1080,32 @@ discard block |
||
| 1081 | 1080 | break; |
| 1082 | 1081 | |
| 1083 | 1082 | default : |
| 1084 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1083 | + $ATT_input = 'ATT_'.$form_input; |
|
| 1085 | 1084 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
| 1086 | - $attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false; |
|
| 1087 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1085 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1086 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
| 1088 | 1087 | } |
| 1089 | 1088 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
| 1090 | 1089 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
| 1091 | 1090 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
| 1092 | 1091 | // if this form input has a corresponding attendee property |
| 1093 | - if ( $attendee_property ) { |
|
| 1094 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
| 1095 | - if ( $answer_is_obj ) { |
|
| 1092 | + if ($attendee_property) { |
|
| 1093 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
| 1094 | + if ($answer_is_obj) { |
|
| 1096 | 1095 | // and delete the corresponding answer since we won't be storing this data in that object |
| 1097 | - $registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' ); |
|
| 1098 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
| 1096 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
| 1097 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
| 1099 | 1098 | } |
| 1100 | 1099 | return true; |
| 1101 | - } elseif ( $answer_is_obj ) { |
|
| 1100 | + } elseif ($answer_is_obj) { |
|
| 1102 | 1101 | // save this data to the answer object |
| 1103 | - $this->_registration_answers[ $answer_cache_id ]->set_value( $input_value ); |
|
| 1104 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
| 1102 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
| 1103 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
| 1105 | 1104 | return $result !== false ? true : false; |
| 1106 | 1105 | } else { |
| 1107 | - foreach ( $this->_registration_answers as $answer ) { |
|
| 1108 | - if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) { |
|
| 1109 | - $answer->set_value( $input_value ); |
|
| 1106 | + foreach ($this->_registration_answers as $answer) { |
|
| 1107 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1108 | + $answer->set_value($input_value); |
|
| 1110 | 1109 | $result = $answer->save(); |
| 1111 | 1110 | return $result !== false ? true : false; |
| 1112 | 1111 | } |
@@ -1128,15 +1127,15 @@ discard block |
||
| 1128 | 1127 | $form_input = '', |
| 1129 | 1128 | $input_value = '' |
| 1130 | 1129 | ) { |
| 1131 | - if ( empty( $input_value ) ) { |
|
| 1130 | + if (empty($input_value)) { |
|
| 1132 | 1131 | // if the form input isn't marked as being required, then just return |
| 1133 | - if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) { |
|
| 1132 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1134 | 1133 | return true; |
| 1135 | 1134 | } |
| 1136 | - switch ( $form_input ) { |
|
| 1135 | + switch ($form_input) { |
|
| 1137 | 1136 | case 'fname' : |
| 1138 | 1137 | EE_Error::add_error( |
| 1139 | - __( 'First Name is a required value.', 'event_espresso' ), |
|
| 1138 | + __('First Name is a required value.', 'event_espresso'), |
|
| 1140 | 1139 | __FILE__, |
| 1141 | 1140 | __FUNCTION__, |
| 1142 | 1141 | __LINE__ |
@@ -1145,7 +1144,7 @@ discard block |
||
| 1145 | 1144 | break; |
| 1146 | 1145 | case 'lname' : |
| 1147 | 1146 | EE_Error::add_error( |
| 1148 | - __( 'Last Name is a required value.', 'event_espresso' ), |
|
| 1147 | + __('Last Name is a required value.', 'event_espresso'), |
|
| 1149 | 1148 | __FILE__, |
| 1150 | 1149 | __FUNCTION__, |
| 1151 | 1150 | __LINE__ |
@@ -1154,7 +1153,7 @@ discard block |
||
| 1154 | 1153 | break; |
| 1155 | 1154 | case 'email' : |
| 1156 | 1155 | EE_Error::add_error( |
| 1157 | - __( 'Please enter a valid email address.', 'event_espresso' ), |
|
| 1156 | + __('Please enter a valid email address.', 'event_espresso'), |
|
| 1158 | 1157 | __FILE__, |
| 1159 | 1158 | __FUNCTION__, |
| 1160 | 1159 | __LINE__ |
@@ -1176,30 +1175,30 @@ discard block |
||
| 1176 | 1175 | * @return boolean|EE_Attendee |
| 1177 | 1176 | * @throws \EE_Error |
| 1178 | 1177 | */ |
| 1179 | - private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
| 1178 | + private function _find_existing_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
| 1180 | 1179 | $existing_attendee = null; |
| 1181 | 1180 | // if none of the critical properties are set in the incoming attendee data... |
| 1182 | 1181 | // then attempt to copy them from the primary attendee |
| 1183 | 1182 | if ( |
| 1184 | 1183 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
| 1185 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1184 | + && ! isset($attendee_data['ATT_fname'], $attendee_data['ATT_email']) |
|
| 1186 | 1185 | ) { |
| 1187 | 1186 | return $this->checkout->primary_attendee_obj; |
| 1188 | 1187 | } |
| 1189 | 1188 | // does this attendee already exist in the db ? |
| 1190 | 1189 | // we're searching using a combination of first name, last name, AND email address |
| 1191 | - $ATT_fname = isset( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_fname'] ) |
|
| 1190 | + $ATT_fname = isset($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_fname']) |
|
| 1192 | 1191 | ? $attendee_data['ATT_fname'] |
| 1193 | 1192 | : ''; |
| 1194 | - $ATT_lname = isset( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_lname'] ) |
|
| 1193 | + $ATT_lname = isset($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_lname']) |
|
| 1195 | 1194 | ? $attendee_data['ATT_lname'] |
| 1196 | 1195 | : ''; |
| 1197 | - $ATT_email = isset( $attendee_data['ATT_email'] ) && ! empty( $attendee_data['ATT_email'] ) |
|
| 1196 | + $ATT_email = isset($attendee_data['ATT_email']) && ! empty($attendee_data['ATT_email']) |
|
| 1198 | 1197 | ? $attendee_data['ATT_email'] |
| 1199 | 1198 | : ''; |
| 1200 | 1199 | // but only if those have values |
| 1201 | - if ( $ATT_fname && $ATT_lname && $ATT_email ) { |
|
| 1202 | - $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( array( |
|
| 1200 | + if ($ATT_fname && $ATT_lname && $ATT_email) { |
|
| 1201 | + $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(array( |
|
| 1203 | 1202 | 'ATT_fname' => $ATT_fname, |
| 1204 | 1203 | 'ATT_lname' => $ATT_lname, |
| 1205 | 1204 | 'ATT_email' => $ATT_email |
@@ -1223,13 +1222,13 @@ discard block |
||
| 1223 | 1222 | * @return \EE_Attendee |
| 1224 | 1223 | * @throws \EE_Error |
| 1225 | 1224 | */ |
| 1226 | - private function _update_existing_attendee_data( EE_Attendee $existing_attendee, $attendee_data = array() ) { |
|
| 1225 | + private function _update_existing_attendee_data(EE_Attendee $existing_attendee, $attendee_data = array()) { |
|
| 1227 | 1226 | // first remove fname, lname, and email from attendee data |
| 1228 | - $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
| 1227 | + $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1229 | 1228 | // now loop thru what's left and add to attendee CPT |
| 1230 | - foreach ( $attendee_data as $property_name => $property_value ) { |
|
| 1231 | - if ( ! in_array( $property_name, $dont_set ) && EEM_Attendee::instance()->has_field( $property_name )) { |
|
| 1232 | - $existing_attendee->set( $property_name, $property_value ); |
|
| 1229 | + foreach ($attendee_data as $property_name => $property_value) { |
|
| 1230 | + if ( ! in_array($property_name, $dont_set) && EEM_Attendee::instance()->has_field($property_name)) { |
|
| 1231 | + $existing_attendee->set($property_name, $property_value); |
|
| 1233 | 1232 | } |
| 1234 | 1233 | } |
| 1235 | 1234 | // better save that now |
@@ -1247,11 +1246,11 @@ discard block |
||
| 1247 | 1246 | * @return void |
| 1248 | 1247 | * @throws \EE_Error |
| 1249 | 1248 | */ |
| 1250 | - private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) { |
|
| 1249 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) { |
|
| 1251 | 1250 | // add relation to attendee |
| 1252 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
| 1253 | - $registration->set_attendee_id( $attendee->ID() ); |
|
| 1254 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
| 1251 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1252 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1253 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1255 | 1254 | } |
| 1256 | 1255 | |
| 1257 | 1256 | |
@@ -1263,10 +1262,10 @@ discard block |
||
| 1263 | 1262 | * @return void |
| 1264 | 1263 | * @throws \EE_Error |
| 1265 | 1264 | */ |
| 1266 | - private function _associate_registration_with_transaction( EE_Registration $registration ) { |
|
| 1265 | + private function _associate_registration_with_transaction(EE_Registration $registration) { |
|
| 1267 | 1266 | // add relation to attendee |
| 1268 | - $this->checkout->transaction->_add_relation_to( $registration, 'Registration' ); |
|
| 1269 | - $this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration ); |
|
| 1267 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1268 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1270 | 1269 | } |
| 1271 | 1270 | |
| 1272 | 1271 | |
@@ -1279,14 +1278,14 @@ discard block |
||
| 1279 | 1278 | * @return array |
| 1280 | 1279 | * @throws \EE_Error |
| 1281 | 1280 | */ |
| 1282 | - private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) { |
|
| 1281 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) { |
|
| 1283 | 1282 | // bare minimum critical details include first name, last name, email address |
| 1284 | - $critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
| 1283 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1285 | 1284 | // add address info to critical details? |
| 1286 | - if ( apply_filters( |
|
| 1285 | + if (apply_filters( |
|
| 1287 | 1286 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
| 1288 | 1287 | false |
| 1289 | - ) ) { |
|
| 1288 | + )) { |
|
| 1290 | 1289 | $address_details = array( |
| 1291 | 1290 | 'ATT_address', |
| 1292 | 1291 | 'ATT_address2', |
@@ -1296,13 +1295,13 @@ discard block |
||
| 1296 | 1295 | 'ATT_zip', |
| 1297 | 1296 | 'ATT_phone' |
| 1298 | 1297 | ); |
| 1299 | - $critical_attendee_details = array_merge( $critical_attendee_details, $address_details ); |
|
| 1298 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1300 | 1299 | } |
| 1301 | - foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
|
| 1302 | - if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1303 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1300 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1301 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
| 1302 | + || empty($attendee_data[$critical_attendee_detail]) |
|
| 1304 | 1303 | ) { |
| 1305 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
| 1304 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
| 1306 | 1305 | $critical_attendee_detail |
| 1307 | 1306 | ); |
| 1308 | 1307 | } |
@@ -1320,11 +1319,11 @@ discard block |
||
| 1320 | 1319 | * @return \EE_Attendee |
| 1321 | 1320 | * @throws \EE_Error |
| 1322 | 1321 | */ |
| 1323 | - private function _create_new_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
| 1322 | + private function _create_new_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
| 1324 | 1323 | // create new attendee object |
| 1325 | - $new_attendee = EE_Attendee::new_instance( $attendee_data ); |
|
| 1324 | + $new_attendee = EE_Attendee::new_instance($attendee_data); |
|
| 1326 | 1325 | // set author to event creator |
| 1327 | - $new_attendee->set( 'ATT_author', $registration->event()->wp_user() ); |
|
| 1326 | + $new_attendee->set('ATT_author', $registration->event()->wp_user()); |
|
| 1328 | 1327 | $new_attendee->save(); |
| 1329 | 1328 | return $new_attendee; |
| 1330 | 1329 | } |
@@ -1341,7 +1340,7 @@ discard block |
||
| 1341 | 1340 | */ |
| 1342 | 1341 | public function update_reg_step() { |
| 1343 | 1342 | // save everything |
| 1344 | - if ( $this->process_reg_step() ) { |
|
| 1343 | + if ($this->process_reg_step()) { |
|
| 1345 | 1344 | $this->checkout->redirect = true; |
| 1346 | 1345 | $this->checkout->redirect_url = add_query_arg( |
| 1347 | 1346 | array( |
@@ -1350,7 +1349,7 @@ discard block |
||
| 1350 | 1349 | ), |
| 1351 | 1350 | $this->checkout->thank_you_page_url |
| 1352 | 1351 | ); |
| 1353 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
| 1352 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1354 | 1353 | return true; |
| 1355 | 1354 | } |
| 1356 | 1355 | return false; |
@@ -30,6 +30,7 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * |
| 32 | 32 | * @param string $status |
| 33 | + * @return void |
|
| 33 | 34 | */ |
| 34 | 35 | public function set_status($status); |
| 35 | 36 | |
@@ -37,6 +38,7 @@ discard block |
||
| 37 | 38 | * Sets the response from the gateway, which is displayable to the user. |
| 38 | 39 | * Eg, 'payment was approved', 'payment failed because invalid date', etc. |
| 39 | 40 | * @param string $response |
| 41 | + * @return void |
|
| 40 | 42 | */ |
| 41 | 43 | public function set_gateway_response($response); |
| 42 | 44 | |
@@ -44,6 +46,7 @@ discard block |
||
| 44 | 46 | * Sets the response details, usually the entire contents of an IPN request, |
| 45 | 47 | * or data about the direct payment data sent |
| 46 | 48 | * @param mixed $response_details |
| 49 | + * @return void |
|
| 47 | 50 | */ |
| 48 | 51 | public function set_details($response_details); |
| 49 | 52 | |
@@ -56,12 +59,14 @@ discard block |
||
| 56 | 59 | /** |
| 57 | 60 | * Sets the URl to redirect to, to process payment |
| 58 | 61 | * @param string $url |
| 62 | + * @return void |
|
| 59 | 63 | */ |
| 60 | 64 | public function set_redirect_url($url); |
| 61 | 65 | |
| 62 | 66 | /** |
| 63 | 67 | * Sets the argument which should be passed to the redirect url (ie, usually POST variables) |
| 64 | 68 | * @param array $args |
| 69 | + * @return void |
|
| 65 | 70 | */ |
| 66 | 71 | public function set_redirect_args($args); |
| 67 | 72 | |
@@ -80,25 +85,27 @@ discard block |
||
| 80 | 85 | /** |
| 81 | 86 | * Sets the amount for this payment |
| 82 | 87 | * @param float $amount |
| 88 | + * @return void |
|
| 83 | 89 | */ |
| 84 | 90 | public function set_amount($amount); |
| 85 | 91 | |
| 86 | 92 | /** |
| 87 | 93 | * Sets the ID of the gateway transaction |
| 88 | 94 | * @param string $txn_id |
| 95 | + * @return void |
|
| 89 | 96 | */ |
| 90 | 97 | public function set_txn_id_chq_nmbr($txn_id); |
| 91 | 98 | |
| 92 | 99 | /** |
| 93 | 100 | * Sets a string for some extra accounting info |
| 94 | 101 | * @param string $extra_accounting_info |
| 102 | + * @return void |
|
| 95 | 103 | */ |
| 96 | 104 | public function set_extra_accntng($extra_accounting_info); |
| 97 | 105 | |
| 98 | 106 | /** |
| 99 | 107 | * Gets the first event for this payment (it's possible that it could be for multiple) |
| 100 | 108 | * |
| 101 | - * @param EE_Payment $payment |
|
| 102 | 109 | * @return EE_Event|null |
| 103 | 110 | */ |
| 104 | 111 | public function get_first_event(); |
@@ -106,7 +113,6 @@ discard block |
||
| 106 | 113 | /** |
| 107 | 114 | * Gets the name of the first event for which is being paid |
| 108 | 115 | * |
| 109 | - * @param EE_Payment $payment |
|
| 110 | 116 | * @return string |
| 111 | 117 | */ |
| 112 | 118 | public function get_first_event_name(); |
@@ -139,22 +145,27 @@ discard block |
||
| 139 | 145 | interface EEMI_Payment { |
| 140 | 146 | /** |
| 141 | 147 | * returns a string for the approved status |
| 148 | + * @return string |
|
| 142 | 149 | */ |
| 143 | 150 | public function approved_status(); |
| 144 | 151 | /** |
| 145 | 152 | * returns a string for the pending status |
| 153 | + * @return string |
|
| 146 | 154 | */ |
| 147 | 155 | public function pending_status(); |
| 148 | 156 | /** |
| 149 | 157 | * returns a string for the cancelled status |
| 158 | + * @return string |
|
| 150 | 159 | */ |
| 151 | 160 | public function cancelled_status(); |
| 152 | 161 | /** |
| 153 | 162 | * returns a string for the failed status |
| 163 | + * @return string |
|
| 154 | 164 | */ |
| 155 | 165 | public function failed_status(); |
| 156 | 166 | /** |
| 157 | 167 | * returns a string for the declined status |
| 168 | + * @return string |
|
| 158 | 169 | */ |
| 159 | 170 | public function declined_status(); |
| 160 | 171 | |
@@ -208,6 +219,10 @@ discard block |
||
| 208 | 219 | * Interface for an event being registered for |
| 209 | 220 | */ |
| 210 | 221 | interface EEI_Event { |
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return boolean |
|
| 225 | + */ |
|
| 211 | 226 | public function name(); |
| 212 | 227 | } |
| 213 | 228 | |
@@ -95,34 +95,34 @@ |
||
| 95 | 95 | */ |
| 96 | 96 | public function set_extra_accntng($extra_accounting_info); |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 100 | - * |
|
| 101 | - * @param EE_Payment $payment |
|
| 102 | - * @return EE_Event|null |
|
| 103 | - */ |
|
| 104 | - public function get_first_event(); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Gets the name of the first event for which is being paid |
|
| 108 | - * |
|
| 109 | - * @param EE_Payment $payment |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function get_first_event_name(); |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Returns the payment's transaction's primary registration |
|
| 116 | - * |
|
| 117 | - * @return EE_Registration|null |
|
| 118 | - */ |
|
| 119 | - public function get_primary_registration(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
| 123 | - * @return EE_Attendee|null |
|
| 124 | - */ |
|
| 125 | - public function get_primary_attendee(); |
|
| 98 | + /** |
|
| 99 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 100 | + * |
|
| 101 | + * @param EE_Payment $payment |
|
| 102 | + * @return EE_Event|null |
|
| 103 | + */ |
|
| 104 | + public function get_first_event(); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Gets the name of the first event for which is being paid |
|
| 108 | + * |
|
| 109 | + * @param EE_Payment $payment |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function get_first_event_name(); |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Returns the payment's transaction's primary registration |
|
| 116 | + * |
|
| 117 | + * @return EE_Registration|null |
|
| 118 | + */ |
|
| 119 | + public function get_primary_registration(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
| 123 | + * @return EE_Attendee|null |
|
| 124 | + */ |
|
| 125 | + public function get_primary_attendee(); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -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 | /** |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | * @return EE_Payment |
| 21 | 21 | * @throws \EE_Error |
| 22 | 22 | */ |
| 23 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 24 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 25 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 24 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 25 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * @return EE_Payment |
| 35 | 35 | * @throws \EE_Error |
| 36 | 36 | */ |
| 37 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 38 | - return new self( $props_n_values, true, $timezone ); |
|
| 37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 38 | + return new self($props_n_values, true, $timezone); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | * @param int $TXN_ID |
| 48 | 48 | * @throws \EE_Error |
| 49 | 49 | */ |
| 50 | - public function set_transaction_id( $TXN_ID = 0 ) { |
|
| 51 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
| 50 | + public function set_transaction_id($TXN_ID = 0) { |
|
| 51 | + $this->set('TXN_ID', $TXN_ID); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @throws \EE_Error |
| 61 | 61 | */ |
| 62 | 62 | public function transaction() { |
| 63 | - return $this->get_first_related( 'Transaction' ); |
|
| 63 | + return $this->get_first_related('Transaction'); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @param string $STS_ID |
| 73 | 73 | * @throws \EE_Error |
| 74 | 74 | */ |
| 75 | - public function set_status( $STS_ID = '' ) { |
|
| 76 | - $this->set( 'STS_ID', $STS_ID ); |
|
| 75 | + public function set_status($STS_ID = '') { |
|
| 76 | + $this->set('STS_ID', $STS_ID); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @param int $timestamp |
| 86 | 86 | * @throws \EE_Error |
| 87 | 87 | */ |
| 88 | - public function set_timestamp( $timestamp = 0 ) { |
|
| 89 | - $this->set( 'PAY_timestamp', $timestamp ); |
|
| 88 | + public function set_timestamp($timestamp = 0) { |
|
| 89 | + $this->set('PAY_timestamp', $timestamp); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * @param string $PAY_source |
| 99 | 99 | * @throws \EE_Error |
| 100 | 100 | */ |
| 101 | - public function set_source( $PAY_source = '' ) { |
|
| 102 | - $this->set( 'PAY_source', $PAY_source ); |
|
| 101 | + public function set_source($PAY_source = '') { |
|
| 102 | + $this->set('PAY_source', $PAY_source); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | * @param float $amount |
| 112 | 112 | * @throws \EE_Error |
| 113 | 113 | */ |
| 114 | - public function set_amount( $amount = 0.00 ) { |
|
| 115 | - $this->set( 'PAY_amount', (float)$amount ); |
|
| 114 | + public function set_amount($amount = 0.00) { |
|
| 115 | + $this->set('PAY_amount', (float) $amount); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @param string $gateway_response |
| 125 | 125 | * @throws \EE_Error |
| 126 | 126 | */ |
| 127 | - public function set_gateway_response( $gateway_response = '' ) { |
|
| 128 | - $this->set( 'PAY_gateway_response', $gateway_response ); |
|
| 127 | + public function set_gateway_response($gateway_response = '') { |
|
| 128 | + $this->set('PAY_gateway_response', $gateway_response); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ), |
| 149 | 149 | '4.6.0' |
| 150 | 150 | ); |
| 151 | - return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' ); |
|
| 151 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * @param string $txn_id_chq_nmbr |
| 161 | 161 | * @throws \EE_Error |
| 162 | 162 | */ |
| 163 | - public function set_txn_id_chq_nmbr( $txn_id_chq_nmbr = '' ) { |
|
| 164 | - $this->set( 'PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr ); |
|
| 163 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') { |
|
| 164 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param string $po_number |
| 174 | 174 | * @throws \EE_Error |
| 175 | 175 | */ |
| 176 | - public function set_po_number( $po_number = '' ) { |
|
| 177 | - $this->set( 'PAY_po_number', $po_number ); |
|
| 176 | + public function set_po_number($po_number = '') { |
|
| 177 | + $this->set('PAY_po_number', $po_number); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | * @param string $extra_accntng |
| 187 | 187 | * @throws \EE_Error |
| 188 | 188 | */ |
| 189 | - public function set_extra_accntng( $extra_accntng = '' ) { |
|
| 190 | - $this->set( 'PAY_extra_accntng', $extra_accntng ); |
|
| 189 | + public function set_extra_accntng($extra_accntng = '') { |
|
| 190 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @param bool $via_admin |
| 200 | 200 | * @throws \EE_Error |
| 201 | 201 | */ |
| 202 | - public function set_payment_made_via_admin( $via_admin = false ) { |
|
| 203 | - if ( $via_admin ) { |
|
| 204 | - $this->set( 'PAY_source', EEM_Payment_Method::scope_admin ); |
|
| 202 | + public function set_payment_made_via_admin($via_admin = false) { |
|
| 203 | + if ($via_admin) { |
|
| 204 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 205 | 205 | } else { |
| 206 | - $this->set( 'PAY_source', EEM_Payment_Method::scope_cart ); |
|
| 206 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | * @param string|array $details |
| 217 | 217 | * @throws \EE_Error |
| 218 | 218 | */ |
| 219 | - public function set_details( $details = '' ) { |
|
| 220 | - if ( is_array( $details ) ) { |
|
| 221 | - array_walk_recursive( $details, array( $this, '_strip_all_tags_within_array' ) ); |
|
| 219 | + public function set_details($details = '') { |
|
| 220 | + if (is_array($details)) { |
|
| 221 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 222 | 222 | } else { |
| 223 | - $details = wp_strip_all_tags( $details ); |
|
| 223 | + $details = wp_strip_all_tags($details); |
|
| 224 | 224 | } |
| 225 | - $this->set( 'PAY_details', $details ); |
|
| 225 | + $this->set('PAY_details', $details); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param string $redirect_url |
| 234 | 234 | * @throws \EE_Error |
| 235 | 235 | */ |
| 236 | - public function set_redirect_url( $redirect_url ) { |
|
| 237 | - $this->set( 'PAY_redirect_url', $redirect_url ); |
|
| 236 | + public function set_redirect_url($redirect_url) { |
|
| 237 | + $this->set('PAY_redirect_url', $redirect_url); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -245,8 +245,8 @@ discard block |
||
| 245 | 245 | * @param array $redirect_args |
| 246 | 246 | * @throws \EE_Error |
| 247 | 247 | */ |
| 248 | - public function set_redirect_args( $redirect_args ) { |
|
| 249 | - $this->set( 'PAY_redirect_args', $redirect_args ); |
|
| 248 | + public function set_redirect_args($redirect_args) { |
|
| 249 | + $this->set('PAY_redirect_args', $redirect_args); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @throws \EE_Error |
| 259 | 259 | */ |
| 260 | 260 | public function TXN_ID() { |
| 261 | - return $this->get( 'TXN_ID' ); |
|
| 261 | + return $this->get('TXN_ID'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @throws \EE_Error |
| 271 | 271 | */ |
| 272 | 272 | public function status() { |
| 273 | - return $this->get( 'STS_ID' ); |
|
| 273 | + return $this->get('STS_ID'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @throws \EE_Error |
| 283 | 283 | */ |
| 284 | 284 | public function STS_ID() { |
| 285 | - return $this->get( 'STS_ID' ); |
|
| 285 | + return $this->get('STS_ID'); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | * @return string |
| 297 | 297 | * @throws \EE_Error |
| 298 | 298 | */ |
| 299 | - public function timestamp( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 300 | - return $this->get_i18n_datetime( 'PAY_timestamp', trim( $dt_frmt . ' ' . $tm_frmt) ); |
|
| 299 | + public function timestamp($dt_frmt = '', $tm_frmt = '') { |
|
| 300 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @throws \EE_Error |
| 310 | 310 | */ |
| 311 | 311 | public function source() { |
| 312 | - return $this->get( 'PAY_source' ); |
|
| 312 | + return $this->get('PAY_source'); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @throws \EE_Error |
| 323 | 323 | */ |
| 324 | 324 | public function amount() { |
| 325 | - return (float)$this->get( 'PAY_amount' ); |
|
| 325 | + return (float) $this->get('PAY_amount'); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * @throws \EE_Error |
| 333 | 333 | */ |
| 334 | 334 | public function amount_no_code() { |
| 335 | - return $this->get_pretty( 'PAY_amount', 'no_currency_code' ); |
|
| 335 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @throws \EE_Error |
| 345 | 345 | */ |
| 346 | 346 | public function gateway_response() { |
| 347 | - return $this->get( 'PAY_gateway_response' ); |
|
| 347 | + return $this->get('PAY_gateway_response'); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | * @throws \EE_Error |
| 357 | 357 | */ |
| 358 | 358 | public function txn_id_chq_nmbr() { |
| 359 | - return $this->get( 'PAY_txn_id_chq_nmbr' ); |
|
| 359 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @throws \EE_Error |
| 369 | 369 | */ |
| 370 | 370 | public function po_number() { |
| 371 | - return $this->get( 'PAY_po_number' ); |
|
| 371 | + return $this->get('PAY_po_number'); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * @throws \EE_Error |
| 381 | 381 | */ |
| 382 | 382 | public function extra_accntng() { |
| 383 | - return $this->get( 'PAY_extra_accntng' ); |
|
| 383 | + return $this->get('PAY_extra_accntng'); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @throws \EE_Error |
| 393 | 393 | */ |
| 394 | 394 | public function payment_made_via_admin() { |
| 395 | - return ( $this->get( 'PAY_source' ) === EEM_Payment_Method::scope_admin ); |
|
| 395 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | * @throws \EE_Error |
| 405 | 405 | */ |
| 406 | 406 | public function details() { |
| 407 | - return $this->get( 'PAY_details' ); |
|
| 407 | + return $this->get('PAY_details'); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @throws \EE_Error |
| 417 | 417 | */ |
| 418 | 418 | public function redirect_url() { |
| 419 | - return $this->get( 'PAY_redirect_url' ); |
|
| 419 | + return $this->get('PAY_redirect_url'); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * @throws \EE_Error |
| 429 | 429 | */ |
| 430 | 430 | public function redirect_args() { |
| 431 | - return $this->get( 'PAY_redirect_args' ); |
|
| 431 | + return $this->get('PAY_redirect_args'); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @return void |
| 441 | 441 | * @throws \EE_Error |
| 442 | 442 | */ |
| 443 | - public function e_pretty_status( $show_icons = false ) { |
|
| 444 | - echo $this->pretty_status( $show_icons ); |
|
| 443 | + public function e_pretty_status($show_icons = false) { |
|
| 444 | + echo $this->pretty_status($show_icons); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -453,14 +453,14 @@ discard block |
||
| 453 | 453 | * @return string |
| 454 | 454 | * @throws \EE_Error |
| 455 | 455 | */ |
| 456 | - public function pretty_status( $show_icons = false ) { |
|
| 456 | + public function pretty_status($show_icons = false) { |
|
| 457 | 457 | $status = EEM_Status::instance()->localized_status( |
| 458 | - array( $this->STS_ID() => __( 'unknown', 'event_espresso' ) ), |
|
| 458 | + array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
| 459 | 459 | false, |
| 460 | 460 | 'sentence' |
| 461 | 461 | ); |
| 462 | 462 | $icon = ''; |
| 463 | - switch ( $this->STS_ID() ) { |
|
| 463 | + switch ($this->STS_ID()) { |
|
| 464 | 464 | case EEM_Payment::status_id_approved: |
| 465 | 465 | $icon = $show_icons |
| 466 | 466 | ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | : ''; |
| 483 | 483 | break; |
| 484 | 484 | } |
| 485 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 485 | + return $icon.$status[$this->STS_ID()]; |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @throws \EE_Error |
| 495 | 495 | */ |
| 496 | 496 | public function is_approved() { |
| 497 | - return $this->status_is( EEM_Payment::status_id_approved ); |
|
| 497 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * @return boolean whether the status of this payment equals the status id |
| 509 | 509 | * @throws \EE_Error |
| 510 | 510 | */ |
| 511 | - protected function status_is( $STS_ID ) { |
|
| 511 | + protected function status_is($STS_ID) { |
|
| 512 | 512 | return $STS_ID === $this->STS_ID() ? true : false; |
| 513 | 513 | } |
| 514 | 514 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | * @throws \EE_Error |
| 522 | 522 | */ |
| 523 | 523 | public function is_pending() { |
| 524 | - return $this->status_is( EEM_Payment::status_id_pending ); |
|
| 524 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | * @throws \EE_Error |
| 534 | 534 | */ |
| 535 | 535 | public function is_cancelled() { |
| 536 | - return $this->status_is( EEM_Payment::status_id_cancelled ); |
|
| 536 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * @throws \EE_Error |
| 546 | 546 | */ |
| 547 | 547 | public function is_declined() { |
| 548 | - return $this->status_is( EEM_Payment::status_id_declined ); |
|
| 548 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | * @throws \EE_Error |
| 558 | 558 | */ |
| 559 | 559 | public function is_failed() { |
| 560 | - return $this->status_is( EEM_Payment::status_id_failed ); |
|
| 560 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | * @throws \EE_Error |
| 582 | 582 | */ |
| 583 | 583 | public function status_obj() { |
| 584 | - return $this->get_first_related( 'Status' ); |
|
| 584 | + return $this->get_first_related('Status'); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | |
@@ -593,8 +593,8 @@ discard block |
||
| 593 | 593 | * @return EE_Extra_Meta |
| 594 | 594 | * @throws \EE_Error |
| 595 | 595 | */ |
| 596 | - public function extra_meta( $query_params = array() ) { |
|
| 597 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
| 596 | + public function extra_meta($query_params = array()) { |
|
| 597 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @throws \EE_Error |
| 609 | 609 | */ |
| 610 | 610 | public function payment_method() { |
| 611 | - return $this->get_first_related( 'Payment_Method' ); |
|
| 611 | + return $this->get_first_related('Payment_Method'); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | |
@@ -626,18 +626,18 @@ discard block |
||
| 626 | 626 | * @return string html |
| 627 | 627 | * @throws \EE_Error |
| 628 | 628 | */ |
| 629 | - public function redirect_form( $inside_form_html = null ) { |
|
| 629 | + public function redirect_form($inside_form_html = null) { |
|
| 630 | 630 | $redirect_url = $this->redirect_url(); |
| 631 | - if ( ! empty( $redirect_url ) ) { |
|
| 631 | + if ( ! empty($redirect_url)) { |
|
| 632 | 632 | // what ? no inner form content? |
| 633 | - if ( $inside_form_html === null ) { |
|
| 633 | + if ($inside_form_html === null) { |
|
| 634 | 634 | $inside_form_html = EEH_HTML::p( |
| 635 | 635 | sprintf( |
| 636 | 636 | __( |
| 637 | 637 | 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
| 638 | 638 | 'event_espresso' |
| 639 | 639 | ), |
| 640 | - EEH_HTML::br( 2 ), |
|
| 640 | + EEH_HTML::br(2), |
|
| 641 | 641 | '<input type="submit" value="', |
| 642 | 642 | '">' |
| 643 | 643 | ), |
@@ -653,22 +653,22 @@ discard block |
||
| 653 | 653 | ); |
| 654 | 654 | //if it's a GET request, we need to remove all the GET params in the querystring |
| 655 | 655 | //and put them into the form instead |
| 656 | - if ( $method === 'GET' ) { |
|
| 657 | - $querystring = parse_url( $redirect_url, PHP_URL_QUERY ); |
|
| 656 | + if ($method === 'GET') { |
|
| 657 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 658 | 658 | $get_params = null; |
| 659 | - parse_str( $querystring, $get_params ); |
|
| 660 | - $inside_form_html .= $this->_args_as_inputs( $get_params ); |
|
| 661 | - $redirect_url = str_replace( '?' . $querystring, '', $redirect_url ); |
|
| 659 | + parse_str($querystring, $get_params); |
|
| 660 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 661 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
| 662 | 662 | } |
| 663 | - $form = EEH_HTML::nl( 1 ) |
|
| 663 | + $form = EEH_HTML::nl(1) |
|
| 664 | 664 | . '<form method="' |
| 665 | 665 | . $method |
| 666 | 666 | . '" name="gateway_form" action="' |
| 667 | 667 | . $redirect_url |
| 668 | 668 | . '">'; |
| 669 | - $form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs(); |
|
| 669 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
| 670 | 670 | $form .= $inside_form_html; |
| 671 | - $form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 ); |
|
| 671 | + $form .= EEH_HTML::nl( -1 ).'</form>'.EEH_HTML::nl( -1 ); |
|
| 672 | 672 | return $form; |
| 673 | 673 | } else { |
| 674 | 674 | return null; |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | * @throws \EE_Error |
| 686 | 686 | */ |
| 687 | 687 | public function redirect_args_as_inputs() { |
| 688 | - return $this->_args_as_inputs( $this->redirect_args() ); |
|
| 688 | + return $this->_args_as_inputs($this->redirect_args()); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | |
@@ -697,15 +697,15 @@ discard block |
||
| 697 | 697 | * @param array $args key-value pairs |
| 698 | 698 | * @return string |
| 699 | 699 | */ |
| 700 | - protected function _args_as_inputs( $args ) { |
|
| 700 | + protected function _args_as_inputs($args) { |
|
| 701 | 701 | $html = ''; |
| 702 | - if ( $args !== null && is_array( $args ) ) { |
|
| 703 | - foreach ( $args as $name => $value ) { |
|
| 704 | - $html .= EEH_HTML::nl( 0 ) |
|
| 702 | + if ($args !== null && is_array($args)) { |
|
| 703 | + foreach ($args as $name => $value) { |
|
| 704 | + $html .= EEH_HTML::nl(0) |
|
| 705 | 705 | . '<input type="hidden" name="' |
| 706 | 706 | . $name |
| 707 | 707 | . '" value="' |
| 708 | - . esc_attr( $value ) |
|
| 708 | + . esc_attr($value) |
|
| 709 | 709 | . '"/>'; |
| 710 | 710 | } |
| 711 | 711 | } |
@@ -734,14 +734,14 @@ discard block |
||
| 734 | 734 | * @access private |
| 735 | 735 | * @param mixed $item |
| 736 | 736 | */ |
| 737 | - private function _strip_all_tags_within_array( &$item ) { |
|
| 738 | - if ( is_object( $item ) ) { |
|
| 739 | - $item = (array)$item; |
|
| 737 | + private function _strip_all_tags_within_array(&$item) { |
|
| 738 | + if (is_object($item)) { |
|
| 739 | + $item = (array) $item; |
|
| 740 | 740 | } |
| 741 | - if ( is_array( $item ) ) { |
|
| 742 | - array_walk_recursive( $item, array( $this, '_strip_all_tags_within_array' ) ); |
|
| 741 | + if (is_array($item)) { |
|
| 742 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 743 | 743 | } else { |
| 744 | - $item = wp_strip_all_tags( $item ); |
|
| 744 | + $item = wp_strip_all_tags($item); |
|
| 745 | 745 | } |
| 746 | 746 | } |
| 747 | 747 | |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | $original_status = EEH_Array::is_set( |
| 759 | 759 | $this->_props_n_values_provided_in_constructor, |
| 760 | 760 | 'STS_ID', |
| 761 | - $this->get_model()->field_settings_for( 'STS_ID' )->get_default_value() |
|
| 761 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 762 | 762 | ); |
| 763 | 763 | $current_status = $this->status(); |
| 764 | 764 | if ( |
@@ -784,11 +784,11 @@ discard block |
||
| 784 | 784 | * @return mixed |
| 785 | 785 | * @throws \EE_Error |
| 786 | 786 | */ |
| 787 | - public function get_pretty( $field_name, $extra_cache_ref = null ) { |
|
| 788 | - if ( $field_name === 'PAY_gateway' ) { |
|
| 789 | - return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' ); |
|
| 787 | + public function get_pretty($field_name, $extra_cache_ref = null) { |
|
| 788 | + if ($field_name === 'PAY_gateway') { |
|
| 789 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 790 | 790 | } |
| 791 | - return $this->_get_cached_property( $field_name, true, $extra_cache_ref ); |
|
| 791 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | |
@@ -800,8 +800,8 @@ discard block |
||
| 800 | 800 | * @return EE_Registration_Payment[] |
| 801 | 801 | * @throws \EE_Error |
| 802 | 802 | */ |
| 803 | - public function registration_payments( $query_params = array() ) { |
|
| 804 | - return $this->get_many_related( 'Registration_Payment', $query_params ); |
|
| 803 | + public function registration_payments($query_params = array()) { |
|
| 804 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | public function get_primary_attendee() |
| 863 | 863 | { |
| 864 | 864 | $primary_reg = $this->get_primary_registration(); |
| 865 | - if( $primary_reg instanceof EE_Registration) { |
|
| 865 | + if ($primary_reg instanceof EE_Registration) { |
|
| 866 | 866 | return $primary_reg->attendee(); |
| 867 | 867 | } |
| 868 | 868 | return null; |
@@ -661,11 +661,11 @@ discard block |
||
| 661 | 661 | $redirect_url = str_replace( '?' . $querystring, '', $redirect_url ); |
| 662 | 662 | } |
| 663 | 663 | $form = EEH_HTML::nl( 1 ) |
| 664 | - . '<form method="' |
|
| 665 | - . $method |
|
| 666 | - . '" name="gateway_form" action="' |
|
| 667 | - . $redirect_url |
|
| 668 | - . '">'; |
|
| 664 | + . '<form method="' |
|
| 665 | + . $method |
|
| 666 | + . '" name="gateway_form" action="' |
|
| 667 | + . $redirect_url |
|
| 668 | + . '">'; |
|
| 669 | 669 | $form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs(); |
| 670 | 670 | $form .= $inside_form_html; |
| 671 | 671 | $form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 ); |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | if ( $args !== null && is_array( $args ) ) { |
| 703 | 703 | foreach ( $args as $name => $value ) { |
| 704 | 704 | $html .= EEH_HTML::nl( 0 ) |
| 705 | - . '<input type="hidden" name="' |
|
| 706 | - . $name |
|
| 707 | - . '" value="' |
|
| 708 | - . esc_attr( $value ) |
|
| 709 | - . '"/>'; |
|
| 705 | + . '<input type="hidden" name="' |
|
| 706 | + . $name |
|
| 707 | + . '" value="' |
|
| 708 | + . esc_attr( $value ) |
|
| 709 | + . '"/>'; |
|
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | return $html; |
@@ -806,64 +806,64 @@ discard block |
||
| 806 | 806 | |
| 807 | 807 | |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 811 | - * |
|
| 812 | - * @return EE_Event|null |
|
| 813 | - */ |
|
| 814 | - public function get_first_event() |
|
| 815 | - { |
|
| 816 | - $transaction = $this->transaction(); |
|
| 817 | - if ($transaction instanceof EE_Transaction) { |
|
| 818 | - $primary_registrant = $transaction->primary_registration(); |
|
| 819 | - if ($primary_registrant instanceof EE_Registration) { |
|
| 820 | - return $primary_registrant->event_obj(); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - return null; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Gets the name of the first event for which is being paid |
|
| 830 | - * |
|
| 831 | - * @return string |
|
| 832 | - */ |
|
| 833 | - public function get_first_event_name() |
|
| 834 | - { |
|
| 835 | - $event = $this->get_first_event(); |
|
| 836 | - return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * Returns the payment's transaction's primary registration |
|
| 843 | - * @return EE_Registration|null |
|
| 844 | - */ |
|
| 845 | - public function get_primary_registration() |
|
| 846 | - { |
|
| 847 | - if ($this->transaction() instanceof EE_Transaction) { |
|
| 848 | - return $this->transaction()->primary_registration(); |
|
| 849 | - } |
|
| 850 | - return null; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
| 857 | - * @return EE_Attendee|null |
|
| 858 | - */ |
|
| 859 | - public function get_primary_attendee() |
|
| 860 | - { |
|
| 861 | - $primary_reg = $this->get_primary_registration(); |
|
| 862 | - if( $primary_reg instanceof EE_Registration) { |
|
| 863 | - return $primary_reg->attendee(); |
|
| 864 | - } |
|
| 865 | - return null; |
|
| 866 | - } |
|
| 809 | + /** |
|
| 810 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 811 | + * |
|
| 812 | + * @return EE_Event|null |
|
| 813 | + */ |
|
| 814 | + public function get_first_event() |
|
| 815 | + { |
|
| 816 | + $transaction = $this->transaction(); |
|
| 817 | + if ($transaction instanceof EE_Transaction) { |
|
| 818 | + $primary_registrant = $transaction->primary_registration(); |
|
| 819 | + if ($primary_registrant instanceof EE_Registration) { |
|
| 820 | + return $primary_registrant->event_obj(); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + return null; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Gets the name of the first event for which is being paid |
|
| 830 | + * |
|
| 831 | + * @return string |
|
| 832 | + */ |
|
| 833 | + public function get_first_event_name() |
|
| 834 | + { |
|
| 835 | + $event = $this->get_first_event(); |
|
| 836 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * Returns the payment's transaction's primary registration |
|
| 843 | + * @return EE_Registration|null |
|
| 844 | + */ |
|
| 845 | + public function get_primary_registration() |
|
| 846 | + { |
|
| 847 | + if ($this->transaction() instanceof EE_Transaction) { |
|
| 848 | + return $this->transaction()->primary_registration(); |
|
| 849 | + } |
|
| 850 | + return null; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
| 857 | + * @return EE_Attendee|null |
|
| 858 | + */ |
|
| 859 | + public function get_primary_attendee() |
|
| 860 | + { |
|
| 861 | + $primary_reg = $this->get_primary_registration(); |
|
| 862 | + if( $primary_reg instanceof EE_Registration) { |
|
| 863 | + return $primary_reg->attendee(); |
|
| 864 | + } |
|
| 865 | + return null; |
|
| 866 | + } |
|
| 867 | 867 | } |
| 868 | 868 | /* End of file EE_Payment.class.php */ |
| 869 | 869 | /* Location: /includes/classes/EE_Payment.class.php */ |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * You can specify $default is case you haven't found the extra meta |
| 61 | 61 | * @param string $meta_key |
| 62 | 62 | * @param boolean $single |
| 63 | - * @param mixed $default if we don't find anything, what should we return? |
|
| 63 | + * @param boolean $default if we don't find anything, what should we return? |
|
| 64 | 64 | * @return mixed single value if $single; array if ! $single |
| 65 | 65 | */ |
| 66 | 66 | public function get_extra_meta($meta_key,$single = FALSE,$default = NULL); |
@@ -72,9 +72,7 @@ discard block |
||
| 72 | 72 | * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
| 73 | 73 | * to see what options are available. |
| 74 | 74 | * @param string $field_name |
| 75 | - * @param string $format This allows the user to specify an extra cache ref for the given property |
|
| 76 | - * (in cases where the same property may be used for different outputs |
|
| 77 | - * - i.e. datetime, money etc.) |
|
| 75 | + * @param string|null $extra_cache_ref |
|
| 78 | 76 | * @return mixed |
| 79 | 77 | * @throws \EE_Error |
| 80 | 78 | */ |
@@ -120,6 +118,7 @@ discard block |
||
| 120 | 118 | * |
| 121 | 119 | * @param EE_Request $request |
| 122 | 120 | * @param EE_Response $response |
| 121 | + * @return void |
|
| 123 | 122 | */ |
| 124 | 123 | public function handle_response( EE_Request $request, EE_Response $response ); |
| 125 | 124 | } |
@@ -203,26 +202,78 @@ discard block |
||
| 203 | 202 | * Interface EEI_Attendee |
| 204 | 203 | */ |
| 205 | 204 | interface EEI_Attendee { |
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 206 | 209 | public function fname(); |
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 207 | 214 | public function lname(); |
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 208 | 219 | public function full_name(); |
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 209 | 224 | public function email(); |
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 210 | 229 | public function phone(); |
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 211 | 234 | public function address(); |
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 212 | 239 | public function address2(); |
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 213 | 244 | public function city(); |
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @return string |
|
| 248 | + */ |
|
| 214 | 249 | public function state_ID(); |
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 215 | 254 | public function state_name(); |
| 216 | 255 | /** |
| 217 | 256 | * @return EE_State |
| 218 | 257 | */ |
| 219 | 258 | public function state_obj(); |
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 220 | 263 | public function country_ID(); |
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 221 | 268 | public function country_name(); |
| 222 | 269 | /** |
| 223 | 270 | * @return EE_Country |
| 224 | 271 | */ |
| 225 | 272 | public function country_obj(); |
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 226 | 277 | public function zip(); |
| 227 | 278 | } |
| 228 | 279 | |
@@ -234,9 +285,25 @@ discard block |
||
| 234 | 285 | * Interface EEI_Contact |
| 235 | 286 | */ |
| 236 | 287 | interface EEI_Contact { |
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @return string |
|
| 291 | + */ |
|
| 237 | 292 | public function fname(); |
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 238 | 297 | public function lname(); |
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 239 | 302 | public function email(); |
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 240 | 307 | public function phone(); |
| 241 | 308 | } |
| 242 | 309 | |
@@ -263,24 +330,64 @@ discard block |
||
| 263 | 330 | * Interface EEI_Address |
| 264 | 331 | */ |
| 265 | 332 | interface EEI_Address { |
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @return string |
|
| 336 | + */ |
|
| 266 | 337 | public function address(); |
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 267 | 342 | public function address2(); |
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @return string |
|
| 346 | + */ |
|
| 268 | 347 | public function city(); |
| 269 | 348 | /** |
| 270 | 349 | * @return EE_State |
| 271 | 350 | */ |
| 272 | 351 | public function state_obj(); |
| 273 | 352 | public function state_ID(); |
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 274 | 357 | public function state_name(); |
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 275 | 362 | public function state_abbrev(); |
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 276 | 367 | public function state(); |
| 277 | 368 | /** |
| 278 | 369 | * @return EE_Country |
| 279 | 370 | */ |
| 280 | 371 | public function country_obj(); |
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @return string |
|
| 375 | + */ |
|
| 281 | 376 | public function country_ID(); |
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 282 | 381 | public function country_name(); |
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @return string |
|
| 385 | + */ |
|
| 283 | 386 | public function country(); |
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 284 | 391 | public function zip(); |
| 285 | 392 | } |
| 286 | 393 | |
@@ -301,6 +408,7 @@ discard block |
||
| 301 | 408 | * @param string $zip |
| 302 | 409 | * @param string $country |
| 303 | 410 | * @param string $CNT_ISO |
| 411 | + * @return string|null |
|
| 304 | 412 | */ |
| 305 | 413 | public function format( $address, $address2, $city, $state, $zip, $country, $CNT_ISO ); |
| 306 | 414 | } |
@@ -413,7 +521,7 @@ discard block |
||
| 413 | 521 | /** |
| 414 | 522 | * @param EE_Line_Item $line_item |
| 415 | 523 | * @param array $options |
| 416 | - * @return mixed |
|
| 524 | + * @return string |
|
| 417 | 525 | */ |
| 418 | 526 | public function display_line_item( EE_Line_Item $line_item, $options = array() ); |
| 419 | 527 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | /** |
| 6 | 6 | * Interface EEI_Base |
| 7 | 7 | */ |
| 8 | -interface EEI_Base{ |
|
| 8 | +interface EEI_Base { |
|
| 9 | 9 | /** |
| 10 | 10 | * gets the unique ID of the model object. If it hasn't been saved yet |
| 11 | 11 | * to the database, this should be 0 or NULL |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
| 33 | 33 | * NOTE: if the values haven't changed, returns 0 |
| 34 | 34 | */ |
| 35 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL); |
|
| 35 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param boolean $unique |
| 44 | 44 | * @return boolean |
| 45 | 45 | */ |
| 46 | - public function add_extra_meta($meta_key,$meta_value,$unique = false); |
|
| 46 | + public function add_extra_meta($meta_key, $meta_value, $unique = false); |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string $meta_value |
| 53 | 53 | * @return int number of extra meta rows deleted |
| 54 | 54 | */ |
| 55 | - public function delete_extra_meta($meta_key,$meta_value = NULL); |
|
| 55 | + public function delete_extra_meta($meta_key, $meta_value = NULL); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param mixed $default if we don't find anything, what should we return? |
| 64 | 64 | * @return mixed single value if $single; array if ! $single |
| 65 | 65 | */ |
| 66 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL); |
|
| 66 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL); |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param EE_Response $response |
| 106 | 106 | * @return EE_Response |
| 107 | 107 | */ |
| 108 | - public function handle_request( EE_Request $request, EE_Response $response ); |
|
| 108 | + public function handle_request(EE_Request $request, EE_Response $response); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param EE_Request $request |
| 122 | 122 | * @param EE_Response $response |
| 123 | 123 | */ |
| 124 | - public function handle_response( EE_Request $request, EE_Response $response ); |
|
| 124 | + public function handle_response(EE_Request $request, EE_Response $response); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param string $country |
| 303 | 303 | * @param string $CNT_ISO |
| 304 | 304 | */ |
| 305 | - public function format( $address, $address2, $city, $state, $zip, $country, $CNT_ISO ); |
|
| 305 | + public function format($address, $address2, $city, $state, $zip, $country, $CNT_ISO); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -312,13 +312,13 @@ discard block |
||
| 312 | 312 | /** |
| 313 | 313 | * Interface EEHI_Line_Item |
| 314 | 314 | */ |
| 315 | -interface EEHI_Line_Item{ |
|
| 315 | +interface EEHI_Line_Item { |
|
| 316 | 316 | /** |
| 317 | 317 | * Adds an item to the purchase in the right spot |
| 318 | 318 | * @param EE_Line_Item $total_line_item |
| 319 | 319 | * @param EE_Line_Item $line_item |
| 320 | 320 | */ |
| 321 | - public function add_item( EE_Line_Item $total_line_item, EE_Line_Item $line_item ); |
|
| 321 | + public function add_item(EE_Line_Item $total_line_item, EE_Line_Item $line_item); |
|
| 322 | 322 | /** |
| 323 | 323 | * Overwrites the previous tax by clearing out the old taxes, and creates a new |
| 324 | 324 | * tax and updates the total line item accordingly |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * set the taxes to match $amount |
| 333 | 333 | * @return EE_Line_Item the new tax created |
| 334 | 334 | */ |
| 335 | - public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ); |
|
| 335 | + public function set_total_tax_to(EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false); |
|
| 336 | 336 | |
| 337 | 337 | /** |
| 338 | 338 | * Makes all the line items which are children of $line_item taxable (or not). |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * @param string $code_substring_for_whitelist if this string is part of the line item's code |
| 343 | 343 | * it will be whitelisted (ie, except from becoming taxable) |
| 344 | 344 | */ |
| 345 | - public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ); |
|
| 345 | + public static function set_line_items_taxable(EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null); |
|
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | 348 | * Adds a simple item ( unrelated to any other model object) to the total line item, |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | * @param boolean $code if set to a value, ensures there is only one line item with that code |
| 357 | 357 | * @return boolean success |
| 358 | 358 | */ |
| 359 | - public function add_unrelated_item( EE_Line_Item $total_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = null ); |
|
| 359 | + public function add_unrelated_item(EE_Line_Item $total_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = null); |
|
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * Gets the line item for the taxes subtotal |
| 363 | 363 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 364 | 364 | * @return \EE_Line_Item |
| 365 | 365 | */ |
| 366 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ); |
|
| 366 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | 371 | * Money-related helper |
| 372 | 372 | */ |
| 373 | -interface EEHI_Money{ |
|
| 373 | +interface EEHI_Money { |
|
| 374 | 374 | /** |
| 375 | 375 | * For comparing floats. Default operator is '=', but see the $operator below for all options. |
| 376 | 376 | * This should be used to compare floats instead of normal '==' because floats |
@@ -381,13 +381,13 @@ discard block |
||
| 381 | 381 | * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
| 382 | 382 | * @return boolean whether the equation is true or false |
| 383 | 383 | */ |
| 384 | - public function compare_floats( $float1, $float2, $operator='=' ); |
|
| 384 | + public function compare_floats($float1, $float2, $operator = '='); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Interface EEHI_Template |
| 389 | 389 | */ |
| 390 | -interface EEHI_Template{ |
|
| 390 | +interface EEHI_Template { |
|
| 391 | 391 | |
| 392 | 392 | /** |
| 393 | 393 | * EEH_Template::format_currency |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | * @param string $cur_code_span_class |
| 401 | 401 | * @return string the html output for the formatted money value |
| 402 | 402 | */ |
| 403 | - public static function format_currency( $amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code' ); |
|
| 403 | + public static function format_currency($amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code'); |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * @param array $options |
| 416 | 416 | * @return mixed |
| 417 | 417 | */ |
| 418 | - public function display_line_item( EE_Line_Item $line_item, $options = array() ); |
|
| 418 | + public function display_line_item(EE_Line_Item $line_item, $options = array()); |
|
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * @throws EE_Error |
| 433 | 433 | * @return bool |
| 434 | 434 | */ |
| 435 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ); |
|
| 435 | + public static function ensure_file_exists_and_is_writable($full_file_path = ''); |
|
| 436 | 436 | |
| 437 | 437 | /** |
| 438 | 438 | * ensure_folder_exists_and_is_writable |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @throws EE_Error |
| 442 | 442 | * @return bool |
| 443 | 443 | */ |
| 444 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ); |
|
| 444 | + public static function ensure_folder_exists_and_is_writable($folder = ''); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // End of file EEI_Interfaces.php |
@@ -67,18 +67,18 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 72 | - * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 73 | - * to see what options are available. |
|
| 74 | - * @param string $field_name |
|
| 75 | - * @param string $format This allows the user to specify an extra cache ref for the given property |
|
| 76 | - * (in cases where the same property may be used for different outputs |
|
| 77 | - * - i.e. datetime, money etc.) |
|
| 78 | - * @return mixed |
|
| 79 | - * @throws \EE_Error |
|
| 80 | - */ |
|
| 81 | - public function get_pretty($field_name, $extra_cache_ref); |
|
| 70 | + /** |
|
| 71 | + * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 72 | + * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 73 | + * to see what options are available. |
|
| 74 | + * @param string $field_name |
|
| 75 | + * @param string $format This allows the user to specify an extra cache ref for the given property |
|
| 76 | + * (in cases where the same property may be used for different outputs |
|
| 77 | + * - i.e. datetime, money etc.) |
|
| 78 | + * @return mixed |
|
| 79 | + * @throws \EE_Error |
|
| 80 | + */ |
|
| 81 | + public function get_pretty($field_name, $extra_cache_ref); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | |
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Retrieves all the pending payments on this transaction |
|
| 173 | - * @return EEI_Payment[] |
|
| 174 | - */ |
|
| 175 | - public function pending_payments(); |
|
| 171 | + /** |
|
| 172 | + * Retrieves all the pending payments on this transaction |
|
| 173 | + * @return EEI_Payment[] |
|
| 174 | + */ |
|
| 175 | + public function pending_payments(); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | interface EEI_Attendee { |
| 214 | 214 | public function fname(); |
| 215 | 215 | public function lname(); |
| 216 | - public function full_name(); |
|
| 216 | + public function full_name(); |
|
| 217 | 217 | public function email(); |
| 218 | 218 | public function phone(); |
| 219 | 219 | public function address(); |
@@ -334,23 +334,23 @@ discard block |
||
| 334 | 334 | * @param float $amount |
| 335 | 335 | * @param string $name |
| 336 | 336 | * @param string $description |
| 337 | - * @param string $code |
|
| 338 | - * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
| 339 | - * the same code is found, $amount will be added onto it; otherwise will simply |
|
| 340 | - * set the taxes to match $amount |
|
| 337 | + * @param string $code |
|
| 338 | + * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
| 339 | + * the same code is found, $amount will be added onto it; otherwise will simply |
|
| 340 | + * set the taxes to match $amount |
|
| 341 | 341 | * @return EE_Line_Item the new tax created |
| 342 | 342 | */ |
| 343 | 343 | public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ); |
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Makes all the line items which are children of $line_item taxable (or not). |
|
| 347 | - * Does NOT save the line items |
|
| 348 | - * @param EE_Line_Item $line_item |
|
| 349 | - * @param boolean $taxable |
|
| 350 | - * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
| 351 | - * it will be whitelisted (ie, except from becoming taxable) |
|
| 352 | - */ |
|
| 353 | - public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ); |
|
| 345 | + /** |
|
| 346 | + * Makes all the line items which are children of $line_item taxable (or not). |
|
| 347 | + * Does NOT save the line items |
|
| 348 | + * @param EE_Line_Item $line_item |
|
| 349 | + * @param boolean $taxable |
|
| 350 | + * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
| 351 | + * it will be whitelisted (ie, except from becoming taxable) |
|
| 352 | + */ |
|
| 353 | + public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ); |
|
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * Adds a simple item ( unrelated to any other model object) to the total line item, |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | interface EEHI_Money{ |
| 382 | 382 | /** |
| 383 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
| 384 | - * This should be used to compare floats instead of normal '==' because floats |
|
| 385 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
| 386 | - * but actually differ by 0.00000001. |
|
| 387 | - * @param float $float1 |
|
| 388 | - * @param float $float2 |
|
| 389 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
| 390 | - * @return boolean whether the equation is true or false |
|
| 391 | - */ |
|
| 383 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
| 384 | + * This should be used to compare floats instead of normal '==' because floats |
|
| 385 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
| 386 | + * but actually differ by 0.00000001. |
|
| 387 | + * @param float $float1 |
|
| 388 | + * @param float $float2 |
|
| 389 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
| 390 | + * @return boolean whether the equation is true or false |
|
| 391 | + */ |
|
| 392 | 392 | public function compare_floats( $float1, $float2, $operator='=' ); |
| 393 | 393 | } |
| 394 | 394 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | /** |
| 370 | 370 | * Gets the first event for this payment (it's possible that it could be for multiple) |
| 371 | 371 | * @param EEI_Payment $payment |
| 372 | - * @return EEI_Event|null |
|
| 372 | + * @return EE_Event|null |
|
| 373 | 373 | * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
| 374 | 374 | */ |
| 375 | 375 | protected function _get_first_event_for_payment( EEI_Payment $payment ) { |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | * Gets the order description that should generlly be sent to gateways |
| 431 | 431 | * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
| 432 | 432 | * @param EEI_Payment $payment |
| 433 | - * @return type |
|
| 433 | + * @return string |
|
| 434 | 434 | */ |
| 435 | 435 | protected function _format_order_description( EEI_Payment $payment ) { |
| 436 | 436 | return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | protected $_line_item; |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @var GatewayDataFormatterInterface |
|
| 79 | - */ |
|
| 80 | - protected $_gateway_data_formatter; |
|
| 77 | + /** |
|
| 78 | + * @var GatewayDataFormatterInterface |
|
| 79 | + */ |
|
| 80 | + protected $_gateway_data_formatter; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @var FormatterInterface |
|
| 84 | - */ |
|
| 85 | - protected $_unsupported_character_remover; |
|
| 82 | + /** |
|
| 83 | + * @var FormatterInterface |
|
| 84 | + */ |
|
| 85 | + protected $_unsupported_character_remover; |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * The ID of the payment method using this gateway |
@@ -211,75 +211,75 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Sets the gateway data formatter helper |
|
| 216 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 217 | - * @throws InvalidEntityException if it's not set properly |
|
| 218 | - */ |
|
| 214 | + /** |
|
| 215 | + * Sets the gateway data formatter helper |
|
| 216 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 217 | + * @throws InvalidEntityException if it's not set properly |
|
| 218 | + */ |
|
| 219 | 219 | public function set_gateway_data_formatter( GatewayDataFormatterInterface $gateway_data_formatter){ |
| 220 | - if( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 221 | - throw new InvalidEntityException( |
|
| 222 | - is_object($gateway_data_formatter) |
|
| 223 | - ? get_class($gateway_data_formatter) |
|
| 224 | - : esc_html__('Not an object','event_espresso'), |
|
| 225 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Gets the gateway data formatter |
|
| 233 | - * @return GatewayDataFormatterInterface |
|
| 234 | - * @throws InvalidEntityException if it's not set properly |
|
| 235 | - */ |
|
| 236 | - protected function _get_gateway_formatter(){ |
|
| 237 | - if( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 238 | - throw new InvalidEntityException( |
|
| 239 | - is_object($this->_gateway_data_formatter) |
|
| 240 | - ? get_class($this->_gateway_data_formatter) |
|
| 241 | - : esc_html__('Not an object','event_espresso'), |
|
| 242 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - return $this->_gateway_data_formatter; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Sets the helper which will remove unsupported characters for most gateways |
|
| 252 | - * @param FormatterInterface $formatter |
|
| 253 | - * @return FormatterInterface |
|
| 254 | - * @throws InvalidEntityException |
|
| 255 | - */ |
|
| 256 | - public function set_unsupported_character_remover( FormatterInterface $formatter){ |
|
| 257 | - if( ! $formatter instanceof FormatterInterface){ |
|
| 258 | - throw new InvalidEntityException( |
|
| 259 | - is_object($formatter) |
|
| 260 | - ? get_class($formatter) |
|
| 261 | - : esc_html__('Not an object','event_espresso'), |
|
| 262 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - $this->_unsupported_character_remover = $formatter; |
|
| 266 | - } |
|
| 267 | - /** |
|
| 268 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
| 269 | - * @return FormatterInterface |
|
| 270 | - * @throws InvalidEntityException |
|
| 271 | - */ |
|
| 272 | - protected function _get_unsupported_character_remover(){ |
|
| 273 | - if( ! $this->_unsupported_character_remover instanceof FormatterInterface){ |
|
| 274 | - throw new InvalidEntityException( |
|
| 275 | - is_object($this->_unsupported_character_remover) |
|
| 276 | - ? get_class($this->_unsupported_character_remover) |
|
| 277 | - : esc_html__('Not an object','event_espresso'), |
|
| 278 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - return $this->_unsupported_character_remover; |
|
| 282 | - } |
|
| 220 | + if( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 221 | + throw new InvalidEntityException( |
|
| 222 | + is_object($gateway_data_formatter) |
|
| 223 | + ? get_class($gateway_data_formatter) |
|
| 224 | + : esc_html__('Not an object','event_espresso'), |
|
| 225 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Gets the gateway data formatter |
|
| 233 | + * @return GatewayDataFormatterInterface |
|
| 234 | + * @throws InvalidEntityException if it's not set properly |
|
| 235 | + */ |
|
| 236 | + protected function _get_gateway_formatter(){ |
|
| 237 | + if( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 238 | + throw new InvalidEntityException( |
|
| 239 | + is_object($this->_gateway_data_formatter) |
|
| 240 | + ? get_class($this->_gateway_data_formatter) |
|
| 241 | + : esc_html__('Not an object','event_espresso'), |
|
| 242 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + return $this->_gateway_data_formatter; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Sets the helper which will remove unsupported characters for most gateways |
|
| 252 | + * @param FormatterInterface $formatter |
|
| 253 | + * @return FormatterInterface |
|
| 254 | + * @throws InvalidEntityException |
|
| 255 | + */ |
|
| 256 | + public function set_unsupported_character_remover( FormatterInterface $formatter){ |
|
| 257 | + if( ! $formatter instanceof FormatterInterface){ |
|
| 258 | + throw new InvalidEntityException( |
|
| 259 | + is_object($formatter) |
|
| 260 | + ? get_class($formatter) |
|
| 261 | + : esc_html__('Not an object','event_espresso'), |
|
| 262 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + $this->_unsupported_character_remover = $formatter; |
|
| 266 | + } |
|
| 267 | + /** |
|
| 268 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
| 269 | + * @return FormatterInterface |
|
| 270 | + * @throws InvalidEntityException |
|
| 271 | + */ |
|
| 272 | + protected function _get_unsupported_character_remover(){ |
|
| 273 | + if( ! $this->_unsupported_character_remover instanceof FormatterInterface){ |
|
| 274 | + throw new InvalidEntityException( |
|
| 275 | + is_object($this->_unsupported_character_remover) |
|
| 276 | + ? get_class($this->_unsupported_character_remover) |
|
| 277 | + : esc_html__('Not an object','event_espresso'), |
|
| 278 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + return $this->_unsupported_character_remover; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * Formats the amount so it can generally be sent to gateways |
| 301 | 301 | * @param float $amount |
| 302 | 302 | * @return string |
| 303 | - * @deprecated since 4.9.31 insetad use EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
| 303 | + * @deprecated since 4.9.31 insetad use EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
| 304 | 304 | */ |
| 305 | 305 | public function format_currency($amount){ |
| 306 | 306 | return $this->_get_gateway_formatter()->formatCurrency($amount); |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * Gets the first event for this payment (it's possible that it could be for multiple) |
| 371 | 371 | * @param EEI_Payment $payment |
| 372 | 372 | * @return EEI_Event|null |
| 373 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
| 373 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
| 374 | 374 | */ |
| 375 | 375 | protected function _get_first_event_for_payment( EEI_Payment $payment ) { |
| 376 | 376 | return $payment->get_first_event(); |
@@ -380,14 +380,14 @@ discard block |
||
| 380 | 380 | * Gets the name of the first event for which is being paid |
| 381 | 381 | * @param EEI_Payment $payment |
| 382 | 382 | * @return string |
| 383 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
| 383 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
| 384 | 384 | */ |
| 385 | 385 | protected function _get_first_event_name_for_payment( EEI_Payment $payment ) { |
| 386 | 386 | return $payment->get_first_event_name(); |
| 387 | 387 | } |
| 388 | 388 | /** |
| 389 | 389 | * Gets the text to use for a gateway's line item name when this is a partial payment |
| 390 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
| 390 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
| 391 | 391 | * @param EE_Payment $payment |
| 392 | 392 | * @return string |
| 393 | 393 | */ |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | /** |
| 398 | 398 | * Gets the text to use for a gateway's line item description when this is a partial payment |
| 399 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
| 399 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
| 400 | 400 | * @param EEI_Payment $payment |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
@@ -405,9 +405,9 @@ discard block |
||
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
| 408 | - * Gets the name to use for a line item when sending line items to the gateway |
|
| 409 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
| 410 | - * @param EEI_Line_Item $line_item |
|
| 408 | + * Gets the name to use for a line item when sending line items to the gateway |
|
| 409 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
| 410 | + * @param EEI_Line_Item $line_item |
|
| 411 | 411 | * @param EEI_Payment $payment |
| 412 | 412 | * @return string |
| 413 | 413 | */ |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | |
| 418 | 418 | /** |
| 419 | 419 | * Gets the description to use for a line item when sending line items to the gateway |
| 420 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
| 420 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
| 421 | 421 | * @param EEI_Line_Item $line_item |
| 422 | 422 | * @param EEI_Payment $payment |
| 423 | 423 | * @return string |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | |
| 429 | 429 | /** |
| 430 | 430 | * Gets the order description that should generlly be sent to gateways |
| 431 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
| 431 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
| 432 | 432 | * @param EEI_Payment $payment |
| 433 | 433 | * @return type |
| 434 | 434 | */ |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @subpackage core/libraries/payment_methods |
| 21 | 21 | * @author Mike Nelson |
| 22 | 22 | */ |
| 23 | -abstract class EE_Gateway{ |
|
| 23 | +abstract class EE_Gateway { |
|
| 24 | 24 | /** |
| 25 | 25 | * a constant used as a possible value for $_currencies_supported to indicate |
| 26 | 26 | * that ALL currencies are supported by this gateway |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * @return EE_Gateway |
| 110 | 110 | */ |
| 111 | - public function __construct(){ |
|
| 111 | + public function __construct() { |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | * beginning again) |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - public function __sleep(){ |
|
| 123 | + public function __sleep() { |
|
| 124 | 124 | $properties = get_object_vars($this); |
| 125 | - unset( $properties[ '_pay_model' ], $properties[ '_pay_log' ] ); |
|
| 125 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
| 126 | 126 | return array_keys($properties); |
| 127 | 127 | } |
| 128 | 128 | /** |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * see $_supports_sending_refunds |
| 131 | 131 | * @return boolean |
| 132 | 132 | */ |
| 133 | - public function supports_sending_refunds(){ |
|
| 133 | + public function supports_sending_refunds() { |
|
| 134 | 134 | return $this->_supports_sending_refunds; |
| 135 | 135 | } |
| 136 | 136 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * see $_supports_receiving_refunds |
| 139 | 139 | * @return boolean |
| 140 | 140 | */ |
| 141 | - public function supports_receiving_refunds(){ |
|
| 141 | + public function supports_receiving_refunds() { |
|
| 142 | 142 | return $this->_supports_receiving_refunds; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return EE_Payment for the refund |
| 154 | 154 | * @throws EE_Error |
| 155 | 155 | */ |
| 156 | - public function do_direct_refund( EE_Payment $payment, $refund_info = null ) { |
|
| 156 | + public function do_direct_refund(EE_Payment $payment, $refund_info = null) { |
|
| 157 | 157 | return NULL; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | * etc |
| 165 | 165 | * @param array $settings_array |
| 166 | 166 | */ |
| 167 | - public function set_settings($settings_array){ |
|
| 168 | - foreach($settings_array as $name => $value){ |
|
| 167 | + public function set_settings($settings_array) { |
|
| 168 | + foreach ($settings_array as $name => $value) { |
|
| 169 | 169 | $property_name = "_".$name; |
| 170 | 170 | $this->{$property_name} = $value; |
| 171 | 171 | } |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | * See this class description |
| 175 | 175 | * @param EEMI_Payment $payment_model |
| 176 | 176 | */ |
| 177 | - public function set_payment_model($payment_model){ |
|
| 177 | + public function set_payment_model($payment_model) { |
|
| 178 | 178 | $this->_pay_model = $payment_model; |
| 179 | 179 | } |
| 180 | 180 | /** |
| 181 | 181 | * See this class description |
| 182 | 182 | * @param EEMI_Payment_Log $payment_log_model |
| 183 | 183 | */ |
| 184 | - public function set_payment_log($payment_log_model){ |
|
| 184 | + public function set_payment_log($payment_log_model) { |
|
| 185 | 185 | $this->_pay_log = $payment_log_model; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * See this class description |
| 190 | 190 | * @param EEHI_Template $template_helper |
| 191 | 191 | */ |
| 192 | - public function set_template_helper($template_helper){ |
|
| 192 | + public function set_template_helper($template_helper) { |
|
| 193 | 193 | $this->_template = $template_helper; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * See this class description |
| 198 | 198 | * @param EEHI_Line_Item $line_item_helper |
| 199 | 199 | */ |
| 200 | - public function set_line_item_helper( $line_item_helper ){ |
|
| 200 | + public function set_line_item_helper($line_item_helper) { |
|
| 201 | 201 | $this->_line_item = $line_item_helper; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * See this class description |
| 206 | 206 | * @param EEHI_Money $money_helper |
| 207 | 207 | */ |
| 208 | - public function set_money_helper( $money_helper ){ |
|
| 208 | + public function set_money_helper($money_helper) { |
|
| 209 | 209 | $this->_money = $money_helper; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | * @param GatewayDataFormatterInterface $gateway_data_formatter |
| 217 | 217 | * @throws InvalidEntityException if it's not set properly |
| 218 | 218 | */ |
| 219 | - public function set_gateway_data_formatter( GatewayDataFormatterInterface $gateway_data_formatter){ |
|
| 220 | - if( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 219 | + public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) { |
|
| 220 | + if ( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 221 | 221 | throw new InvalidEntityException( |
| 222 | 222 | is_object($gateway_data_formatter) |
| 223 | 223 | ? get_class($gateway_data_formatter) |
| 224 | - : esc_html__('Not an object','event_espresso'), |
|
| 224 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 225 | 225 | '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
| 226 | 226 | ); |
| 227 | 227 | } |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | * @return GatewayDataFormatterInterface |
| 234 | 234 | * @throws InvalidEntityException if it's not set properly |
| 235 | 235 | */ |
| 236 | - protected function _get_gateway_formatter(){ |
|
| 237 | - if( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface){ |
|
| 236 | + protected function _get_gateway_formatter() { |
|
| 237 | + if ( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 238 | 238 | throw new InvalidEntityException( |
| 239 | 239 | is_object($this->_gateway_data_formatter) |
| 240 | 240 | ? get_class($this->_gateway_data_formatter) |
| 241 | - : esc_html__('Not an object','event_espresso'), |
|
| 241 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 242 | 242 | '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
| 243 | 243 | ); |
| 244 | 244 | } |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | * @return FormatterInterface |
| 254 | 254 | * @throws InvalidEntityException |
| 255 | 255 | */ |
| 256 | - public function set_unsupported_character_remover( FormatterInterface $formatter){ |
|
| 257 | - if( ! $formatter instanceof FormatterInterface){ |
|
| 256 | + public function set_unsupported_character_remover(FormatterInterface $formatter) { |
|
| 257 | + if ( ! $formatter instanceof FormatterInterface) { |
|
| 258 | 258 | throw new InvalidEntityException( |
| 259 | 259 | is_object($formatter) |
| 260 | 260 | ? get_class($formatter) |
| 261 | - : esc_html__('Not an object','event_espresso'), |
|
| 261 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 262 | 262 | '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
| 263 | 263 | ); |
| 264 | 264 | } |
@@ -269,12 +269,12 @@ discard block |
||
| 269 | 269 | * @return FormatterInterface |
| 270 | 270 | * @throws InvalidEntityException |
| 271 | 271 | */ |
| 272 | - protected function _get_unsupported_character_remover(){ |
|
| 273 | - if( ! $this->_unsupported_character_remover instanceof FormatterInterface){ |
|
| 272 | + protected function _get_unsupported_character_remover() { |
|
| 273 | + if ( ! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
| 274 | 274 | throw new InvalidEntityException( |
| 275 | 275 | is_object($this->_unsupported_character_remover) |
| 276 | 276 | ? get_class($this->_unsupported_character_remover) |
| 277 | - : esc_html__('Not an object','event_espresso'), |
|
| 277 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 278 | 278 | '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
| 279 | 279 | ); |
| 280 | 280 | } |
@@ -286,15 +286,15 @@ discard block |
||
| 286 | 286 | * @param $message |
| 287 | 287 | * @param $payment |
| 288 | 288 | */ |
| 289 | - public function log($message,$payment){ |
|
| 290 | - if($payment instanceof EEI_Payment){ |
|
| 291 | - $type='Payment'; |
|
| 289 | + public function log($message, $payment) { |
|
| 290 | + if ($payment instanceof EEI_Payment) { |
|
| 291 | + $type = 'Payment'; |
|
| 292 | 292 | $id = $payment->ID(); |
| 293 | - }else{ |
|
| 293 | + } else { |
|
| 294 | 294 | $type = 'Payment_Method'; |
| 295 | 295 | $id = $this->_ID; |
| 296 | 296 | } |
| 297 | - $this->_pay_log->gateway_log($message,$id,$type); |
|
| 297 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
| 298 | 298 | } |
| 299 | 299 | /** |
| 300 | 300 | * Formats the amount so it can generally be sent to gateways |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @return string |
| 303 | 303 | * @deprecated since 4.9.31 insetad use EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
| 304 | 304 | */ |
| 305 | - public function format_currency($amount){ |
|
| 305 | + public function format_currency($amount) { |
|
| 306 | 306 | return $this->_get_gateway_formatter()->formatCurrency($amount); |
| 307 | 307 | } |
| 308 | 308 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
| 312 | 312 | * @return mixed array or string |
| 313 | 313 | */ |
| 314 | - public function currencies_supported(){ |
|
| 314 | + public function currencies_supported() { |
|
| 315 | 315 | return $this->_currencies_supported; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -323,14 +323,14 @@ discard block |
||
| 323 | 323 | * @param EE_Transaction $transaction |
| 324 | 324 | * @return float |
| 325 | 325 | */ |
| 326 | - protected function _sum_items_and_taxes( EE_Transaction $transaction){ |
|
| 326 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) { |
|
| 327 | 327 | $total_line_item = $transaction->total_line_item(); |
| 328 | 328 | $total = 0; |
| 329 | - foreach($total_line_item->get_items() as $item_line_item ){ |
|
| 330 | - $total += max( $item_line_item->total(), 0 ); |
|
| 329 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
| 330 | + $total += max($item_line_item->total(), 0); |
|
| 331 | 331 | } |
| 332 | - foreach($total_line_item->tax_descendants() as $tax_line_item ){ |
|
| 333 | - $total += max( $tax_line_item->total(), 0 ); |
|
| 332 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 333 | + $total += max($tax_line_item->total(), 0); |
|
| 334 | 334 | } |
| 335 | 335 | return $total; |
| 336 | 336 | } |
@@ -341,9 +341,9 @@ discard block |
||
| 341 | 341 | * @param EEI_Payment $payment |
| 342 | 342 | * @return boolean |
| 343 | 343 | */ |
| 344 | - protected function _can_easily_itemize_transaction_for( EEI_Payment $payment ){ |
|
| 344 | + protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) { |
|
| 345 | 345 | return $this->_money->compare_floats( |
| 346 | - $this->_sum_items_and_taxes( $payment->transaction() ), |
|
| 346 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
| 347 | 347 | $payment->transaction()->total() ) && |
| 348 | 348 | $this->_money->compare_floats( |
| 349 | 349 | $payment->amount(), |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @param EE_Payment $payment |
| 362 | 362 | * @return void |
| 363 | 363 | */ |
| 364 | - public function update_txn_based_on_payment( $payment ){ |
|
| 364 | + public function update_txn_based_on_payment($payment) { |
|
| 365 | 365 | //maybe update the transaction or line items or registrations |
| 366 | 366 | //but most gateways don't need to do this, because they only update the payment |
| 367 | 367 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * @return EEI_Event|null |
| 373 | 373 | * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
| 374 | 374 | */ |
| 375 | - protected function _get_first_event_for_payment( EEI_Payment $payment ) { |
|
| 375 | + protected function _get_first_event_for_payment(EEI_Payment $payment) { |
|
| 376 | 376 | return $payment->get_first_event(); |
| 377 | 377 | } |
| 378 | 378 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * @return string |
| 383 | 383 | * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
| 384 | 384 | */ |
| 385 | - protected function _get_first_event_name_for_payment( EEI_Payment $payment ) { |
|
| 385 | + protected function _get_first_event_name_for_payment(EEI_Payment $payment) { |
|
| 386 | 386 | return $payment->get_first_event_name(); |
| 387 | 387 | } |
| 388 | 388 | /** |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | * @param EE_Payment $payment |
| 392 | 392 | * @return string |
| 393 | 393 | */ |
| 394 | - protected function _format_partial_payment_line_item_name( EEI_Payment $payment ){ |
|
| 394 | + protected function _format_partial_payment_line_item_name(EEI_Payment $payment) { |
|
| 395 | 395 | return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
| 396 | 396 | } |
| 397 | 397 | /** |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | * @param EEI_Payment $payment |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | - protected function _format_partial_payment_line_item_desc( EEI_Payment $payment ) { |
|
| 403 | + protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) { |
|
| 404 | 404 | return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
| 405 | 405 | } |
| 406 | 406 | |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | * @param EEI_Payment $payment |
| 412 | 412 | * @return string |
| 413 | 413 | */ |
| 414 | - protected function _format_line_item_name( EEI_Line_Item $line_item, EEI_Payment $payment ) { |
|
| 415 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment); |
|
| 414 | + protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) { |
|
| 415 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @param EEI_Payment $payment |
| 423 | 423 | * @return string |
| 424 | 424 | */ |
| 425 | - protected function _format_line_item_desc( EEI_Line_Item $line_item, EEI_Payment $payment ) { |
|
| 425 | + protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) { |
|
| 426 | 426 | return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
| 427 | 427 | } |
| 428 | 428 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * @param EEI_Payment $payment |
| 433 | 433 | * @return type |
| 434 | 434 | */ |
| 435 | - protected function _format_order_description( EEI_Payment $payment ) { |
|
| 435 | + protected function _format_order_description(EEI_Payment $payment) { |
|
| 436 | 436 | return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | \ No newline at end of file |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | //in which case, we need to generate teh invoice num per request right here... |
| 241 | 241 | $this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
| 242 | 242 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
| 243 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
| 243 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | if ($this->_test_transactions) { |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | $this->_log_clean_request($x_keys, $payment); |
| 346 | 346 | $post_url = $this->_get_server_url(); |
| 347 | 347 | $curl_request = curl_init($post_url); |
| 348 | - $post_body = implode("&",$x_keys); |
|
| 348 | + $post_body = implode("&",$x_keys); |
|
| 349 | 349 | curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
| 350 | 350 | curl_setopt($curl_request, CURLOPT_HEADER, 0); |
| 351 | 351 | curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * ------------------------------------------------------------------------ |
| 27 | 27 | */ |
| 28 | -class EEG_Aim extends EE_Onsite_Gateway{ |
|
| 28 | +class EEG_Aim extends EE_Onsite_Gateway { |
|
| 29 | 29 | |
| 30 | 30 | const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
| 31 | 31 | |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @param EEG_Aim $gateway_object |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - public function possibly_use_deprecated_aim_server( $url, EEG_Aim $gateway_object ) { |
|
| 161 | - if( $gateway_object->_server === 'authorize.net' |
|
| 162 | - && ! $gateway_object->_debug_mode ) { |
|
| 160 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) { |
|
| 161 | + if ($gateway_object->_server === 'authorize.net' |
|
| 162 | + && ! $gateway_object->_debug_mode) { |
|
| 163 | 163 | return 'https://secure.authorize.net/gateway/transact.dll'; |
| 164 | 164 | } else { |
| 165 | 165 | return $url; |
@@ -182,33 +182,33 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | |
| 184 | 184 | public function do_direct_payment($payment, $billing_info = null) { |
| 185 | - add_filter( 'FHEE__EEG_Aim___get_server_url', array( $this, 'possibly_use_deprecated_aim_server' ), 10, 2 ); |
|
| 185 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
| 186 | 186 | // Enable test mode if needed |
| 187 | 187 | //4007000000027 <-- test successful visa |
| 188 | 188 | //4222222222222 <-- test failure card number |
| 189 | 189 | |
| 190 | 190 | $item_num = 1; |
| 191 | 191 | $transaction = $payment->transaction(); |
| 192 | - $order_description = $this->_format_order_description( $payment ); |
|
| 192 | + $order_description = $this->_format_order_description($payment); |
|
| 193 | 193 | $primary_registrant = $transaction->primary_registration(); |
| 194 | 194 | //if we're are charging for the full amount, show the normal line items |
| 195 | 195 | //and the itemized total adds up properly |
| 196 | - if( $this->_can_easily_itemize_transaction_for( $payment ) ){ |
|
| 196 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
| 197 | 197 | $total_line_item = $transaction->total_line_item(); |
| 198 | 198 | foreach ($total_line_item->get_items() as $line_item) { |
| 199 | - if( $line_item->quantity() == 0 ){ |
|
| 199 | + if ($line_item->quantity() == 0) { |
|
| 200 | 200 | continue; |
| 201 | 201 | } |
| 202 | 202 | $this->addLineItem( |
| 203 | 203 | $item_num++, |
| 204 | - $this->_format_line_item_name( $line_item, $payment ), |
|
| 205 | - $this->_format_line_item_desc( $line_item, $payment ), |
|
| 204 | + $this->_format_line_item_name($line_item, $payment), |
|
| 205 | + $this->_format_line_item_desc($line_item, $payment), |
|
| 206 | 206 | $line_item->quantity(), |
| 207 | 207 | $line_item->unit_price(), |
| 208 | 208 | 'N'); |
| 209 | 209 | $order_description .= $line_item->desc().', '; |
| 210 | 210 | } |
| 211 | - foreach($total_line_item->tax_descendants() as $tax_line_item){ |
|
| 211 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 212 | 212 | $this->addLineItem($item_num++, $tax_line_item->name(), $tax_line_item->desc(), 1, $tax_line_item->total(), 'N'); |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | //start transaction |
| 220 | 220 | //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
| 221 | 221 | $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
| 222 | - $this->setField( 'solution_id', $partner_id ); |
|
| 222 | + $this->setField('solution_id', $partner_id); |
|
| 223 | 223 | $this->setField('amount', $this->format_currency($payment->amount())); |
| 224 | - $this->setField('description',substr(rtrim($order_description, ', '), 0, 255)); |
|
| 225 | - $this->_set_sensitive_billing_data( $billing_info ); |
|
| 224 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
| 225 | + $this->_set_sensitive_billing_data($billing_info); |
|
| 226 | 226 | $this->setField('first_name', $billing_info['first_name']); |
| 227 | 227 | $this->setField('last_name', $billing_info['last_name']); |
| 228 | 228 | $this->setField('email', $billing_info['email']); |
| 229 | 229 | $this->setField('company', $billing_info['company']); |
| 230 | 230 | $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
| 231 | 231 | $this->setField('city', $billing_info['city']); |
| 232 | - $this->setField('state', $billing_info['state'] ); |
|
| 233 | - $this->setField('country', $billing_info['country'] ); |
|
| 232 | + $this->setField('state', $billing_info['state']); |
|
| 233 | + $this->setField('country', $billing_info['country']); |
|
| 234 | 234 | $this->setField('zip', $billing_info['zip']); |
| 235 | 235 | $this->setField('fax', $billing_info['fax']); |
| 236 | 236 | $this->setField('cust_id', $primary_registrant->ID()); |
@@ -238,9 +238,9 @@ discard block |
||
| 238 | 238 | //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
| 239 | 239 | //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
| 240 | 240 | //in which case, we need to generate teh invoice num per request right here... |
| 241 | - $this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 241 | + $this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 242 | 242 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
| 243 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
| 243 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | if ($this->_test_transactions) { |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | //Capture response |
| 251 | 251 | $this->type = "AUTH_CAPTURE"; |
| 252 | 252 | $response = $this->_sendRequest($payment); |
| 253 | - if (!empty($response)){ |
|
| 253 | + if ( ! empty($response)) { |
|
| 254 | 254 | if ($this->_debug_mode) { |
| 255 | 255 | $txn_id = $response->invoice_number; |
| 256 | 256 | } else { |
@@ -259,15 +259,15 @@ discard block |
||
| 259 | 259 | $payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status(); |
| 260 | 260 | $payment->set_status($payment_status); |
| 261 | 261 | //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
| 262 | - $payment->set_amount( (float) $response->amount ); |
|
| 263 | - $payment->set_gateway_response(sprintf("%s (code: %s)",$response->response_reason_text,$response->response_reason_code)); |
|
| 264 | - $payment->set_txn_id_chq_nmbr( $txn_id ); |
|
| 262 | + $payment->set_amount((float) $response->amount); |
|
| 263 | + $payment->set_gateway_response(sprintf("%s (code: %s)", $response->response_reason_text, $response->response_reason_code)); |
|
| 264 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
| 265 | 265 | $payment->set_extra_accntng($primary_registrant->reg_code()); |
| 266 | - $payment->set_details(print_r($response,true)); |
|
| 266 | + $payment->set_details(print_r($response, true)); |
|
| 267 | 267 | } else { |
| 268 | 268 | $payment->set_status($this->_pay_model->failed_status()); |
| 269 | 269 | $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
| 270 | - $payment->set_details(print_r($response,true)); |
|
| 270 | + $payment->set_details(print_r($response, true)); |
|
| 271 | 271 | } |
| 272 | 272 | return $payment; |
| 273 | 273 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * what billing data gets sent |
| 279 | 279 | * @param array $billing_info |
| 280 | 280 | */ |
| 281 | - protected function _set_sensitive_billing_data( $billing_info ) { |
|
| 281 | + protected function _set_sensitive_billing_data($billing_info) { |
|
| 282 | 282 | $this->setField('card_num', $billing_info['credit_card']); |
| 283 | 283 | $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
| 284 | 284 | $this->setField('card_code', $billing_info['cvv']); |
@@ -336,23 +336,23 @@ discard block |
||
| 336 | 336 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
| 337 | 337 | $x_keys = array(); |
| 338 | 338 | foreach ($this->_x_post_fields as $key => $value) { |
| 339 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 339 | + $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 340 | 340 | } |
| 341 | 341 | // Add line items |
| 342 | 342 | foreach ($this->_additional_line_items as $key => $value) { |
| 343 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 343 | + $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 344 | 344 | } |
| 345 | 345 | $this->_log_clean_request($x_keys, $payment); |
| 346 | 346 | $post_url = $this->_get_server_url(); |
| 347 | 347 | $curl_request = curl_init($post_url); |
| 348 | - $post_body = implode("&",$x_keys); |
|
| 348 | + $post_body = implode("&", $x_keys); |
|
| 349 | 349 | curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
| 350 | 350 | curl_setopt($curl_request, CURLOPT_HEADER, 0); |
| 351 | 351 | curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
| 352 | 352 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
| 353 | 353 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
| 354 | 354 | if ($this->VERIFY_PEER) { |
| 355 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname( __DIR__ ) . '/ssl/cert.pem'); |
|
| 355 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
| 356 | 356 | } else { |
| 357 | 357 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
| 358 | 358 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $response = curl_exec($curl_request); |
| 365 | 365 | |
| 366 | 366 | curl_close($curl_request); |
| 367 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 367 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 368 | 368 | |
| 369 | 369 | return $this->_log_and_clean_response($response_obj, $payment); |
| 370 | 370 | } |
@@ -373,18 +373,18 @@ discard block |
||
| 373 | 373 | * @param array $request_array |
| 374 | 374 | * @param EEI_Payment $payment |
| 375 | 375 | */ |
| 376 | - protected function _log_clean_request($request_array,$payment){ |
|
| 377 | - $keys_to_filter_out = array( 'x_card_num', 'x_card_code', 'x_exp_date' ); |
|
| 378 | - foreach($request_array as $index => $keyvaltogether ) { |
|
| 379 | - foreach( $keys_to_filter_out as $key ) { |
|
| 380 | - if( strpos( $keyvaltogether, $key ) === 0 ){ |
|
| 376 | + protected function _log_clean_request($request_array, $payment) { |
|
| 377 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
| 378 | + foreach ($request_array as $index => $keyvaltogether) { |
|
| 379 | + foreach ($keys_to_filter_out as $key) { |
|
| 380 | + if (strpos($keyvaltogether, $key) === 0) { |
|
| 381 | 381 | //found it at the first character |
| 382 | 382 | //so its one of them |
| 383 | - unset( $request_array[ $index ] ); |
|
| 383 | + unset($request_array[$index]); |
|
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | - $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url() ),$payment); |
|
| 387 | + $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url()), $payment); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -396,9 +396,9 @@ discard block |
||
| 396 | 396 | * @param EE_Payment $payment |
| 397 | 397 | * @return \EE_AuthorizeNetAIM_Response |
| 398 | 398 | */ |
| 399 | - private function _log_and_clean_response($response_obj,$payment){ |
|
| 399 | + private function _log_and_clean_response($response_obj, $payment) { |
|
| 400 | 400 | $response_obj->account_number = ''; |
| 401 | - $this->log(array('AIM Response received:'=>$response_obj),$payment); |
|
| 401 | + $this->log(array('AIM Response received:'=>$response_obj), $payment); |
|
| 402 | 402 | return $response_obj; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | // Split Array |
| 498 | 498 | $this->response = $response; |
| 499 | 499 | if ($encap_char) { |
| 500 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 500 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 501 | 501 | } else { |
| 502 | 502 | $this->_response_array = explode($delimiter, $response); |
| 503 | 503 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | $this->held = ($this->response_code === self::HELD); |
| 568 | 568 | |
| 569 | 569 | if ($this->error || $this->declined || $this->held) { |
| 570 | - $this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />' . $this->response_reason_text . '<br /><span class="response_code">Response Code: ' . $this->response_code . '<br /></span><span class="response_subcode">Response Subcode: ' . $this->response_subcode . '</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> '; |
|
| 570 | + $this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />'.$this->response_reason_text.'<br /><span class="response_code">Response Code: '.$this->response_code.'<br /></span><span class="response_subcode">Response Subcode: '.$this->response_subcode.'</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> '; |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | 573 | /* $this->error_message = "AuthorizeNet Error: |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | -if ( ! class_exists( 'AuthorizeNetException' ) ) { |
|
| 589 | +if ( ! class_exists('AuthorizeNetException')) { |
|
| 590 | 590 | /** |
| 591 | 591 | * Class AuthorizeNetException |
| 592 | 592 | * |
@@ -602,8 +602,8 @@ discard block |
||
| 602 | 602 | * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
| 603 | 603 | * @since 5.1.0 |
| 604 | 604 | */ |
| 605 | - public function __construct( $message = "", $code = 0, Exception $previous = null ) { |
|
| 606 | - parent::__construct( $message, $code, $previous ); |
|
| 605 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
| 606 | + parent::__construct($message, $code, $previous); |
|
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
| 5 | 5 | |
@@ -25,2655 +25,2655 @@ discard block |
||
| 25 | 25 | abstract class EE_Base_Class |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This is an array of the original properties and values provided during construction |
|
| 30 | - * of this model object. (keys are model field names, values are their values). |
|
| 31 | - * This list is important to remember so that when we are merging data from the db, we know |
|
| 32 | - * which values to override and which to not override. |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $_props_n_values_provided_in_constructor; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Timezone |
|
| 40 | - * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 41 | - * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 42 | - * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 43 | - * access to it. |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $_timezone; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * date format |
|
| 53 | - * pattern or format for displaying dates |
|
| 54 | - * |
|
| 55 | - * @var string $_dt_frmt |
|
| 56 | - */ |
|
| 57 | - protected $_dt_frmt; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * time format |
|
| 63 | - * pattern or format for displaying time |
|
| 64 | - * |
|
| 65 | - * @var string $_tm_frmt |
|
| 66 | - */ |
|
| 67 | - protected $_tm_frmt; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 73 | - * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 74 | - * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 75 | - * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 76 | - * |
|
| 77 | - * @var array |
|
| 78 | - */ |
|
| 79 | - protected $_cached_properties = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 83 | - * single |
|
| 84 | - * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 85 | - * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 86 | - * all others have an array) |
|
| 87 | - * |
|
| 88 | - * @var array |
|
| 89 | - */ |
|
| 90 | - protected $_model_relations = array(); |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 94 | - * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 95 | - * |
|
| 96 | - * @var array |
|
| 97 | - */ |
|
| 98 | - protected $_fields = array(); |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 102 | - * For example, we might create model objects intended to only be used for the duration |
|
| 103 | - * of this request and to be thrown away, and if they were accidentally saved |
|
| 104 | - * it would be a bug. |
|
| 105 | - */ |
|
| 106 | - protected $_allow_persist = true; |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 112 | - * play nice |
|
| 113 | - * |
|
| 114 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 115 | - * layer of the model's _fields array, (eg, EVT_ID, |
|
| 116 | - * TXN_amount, QST_name, etc) and values are their values |
|
| 117 | - * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 118 | - * corresponding db model or not. |
|
| 119 | - * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 120 | - * be in when instantiating a EE_Base_Class object. |
|
| 121 | - * @param array $date_formats An array of date formats to set on construct where first |
|
| 122 | - * value is the date_format and second value is the time |
|
| 123 | - * format. |
|
| 124 | - * @throws EE_Error |
|
| 125 | - */ |
|
| 126 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
| 127 | - { |
|
| 128 | - $className = get_class($this); |
|
| 129 | - do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 130 | - $model = $this->get_model(); |
|
| 131 | - $model_fields = $model->field_settings(false); |
|
| 132 | - // ensure $fieldValues is an array |
|
| 133 | - $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 134 | - // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 135 | - // verify client code has not passed any invalid field names |
|
| 136 | - foreach ($fieldValues as $field_name => $field_value) { |
|
| 137 | - if ( ! isset($model_fields[$field_name])) { |
|
| 138 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 139 | - "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 143 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 144 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 145 | - list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 146 | - } else { |
|
| 147 | - //set default formats for date and time |
|
| 148 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 149 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 150 | - } |
|
| 151 | - //if db model is instantiating |
|
| 152 | - if ($bydb) { |
|
| 153 | - //client code has indicated these field values are from the database |
|
| 154 | - foreach ($model_fields as $fieldName => $field) { |
|
| 155 | - $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 156 | - } |
|
| 157 | - } else { |
|
| 158 | - //we're constructing a brand |
|
| 159 | - //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 160 | - foreach ($model_fields as $fieldName => $field) { |
|
| 161 | - $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - //remember what values were passed to this constructor |
|
| 165 | - $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 166 | - //remember in entity mapper |
|
| 167 | - if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 168 | - $model->add_to_entity_map($this); |
|
| 169 | - } |
|
| 170 | - //setup all the relations |
|
| 171 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 172 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 173 | - $this->_model_relations[$relation_name] = null; |
|
| 174 | - } else { |
|
| 175 | - $this->_model_relations[$relation_name] = array(); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - /** |
|
| 179 | - * Action done at the end of each model object construction |
|
| 180 | - * |
|
| 181 | - * @param EE_Base_Class $this the model object just created |
|
| 182 | - */ |
|
| 183 | - do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 190 | - * |
|
| 191 | - * @return boolean |
|
| 192 | - */ |
|
| 193 | - public function allow_persist() |
|
| 194 | - { |
|
| 195 | - return $this->_allow_persist; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 202 | - * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 203 | - * you got new information that somehow made you change your mind. |
|
| 204 | - * |
|
| 205 | - * @param boolean $allow_persist |
|
| 206 | - * @return boolean |
|
| 207 | - */ |
|
| 208 | - public function set_allow_persist($allow_persist) |
|
| 209 | - { |
|
| 210 | - return $this->_allow_persist = $allow_persist; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Gets the field's original value when this object was constructed during this request. |
|
| 217 | - * This can be helpful when determining if a model object has changed or not |
|
| 218 | - * |
|
| 219 | - * @param string $field_name |
|
| 220 | - * @return mixed|null |
|
| 221 | - * @throws \EE_Error |
|
| 222 | - */ |
|
| 223 | - public function get_original($field_name) |
|
| 224 | - { |
|
| 225 | - if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 226 | - && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 227 | - ) { |
|
| 228 | - return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 229 | - } else { |
|
| 230 | - return null; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param EE_Base_Class $obj |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_class($obj) |
|
| 241 | - { |
|
| 242 | - return get_class($obj); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Overrides parent because parent expects old models. |
|
| 249 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 250 | - * |
|
| 251 | - * @param string $field_name |
|
| 252 | - * @param mixed $field_value |
|
| 253 | - * @param bool $use_default |
|
| 254 | - * @throws \EE_Error |
|
| 255 | - */ |
|
| 256 | - public function set($field_name, $field_value, $use_default = false) |
|
| 257 | - { |
|
| 258 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 259 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 260 | - // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 261 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 262 | - $field_obj->set_timezone($this->_timezone); |
|
| 263 | - $field_obj->set_date_format($this->_dt_frmt); |
|
| 264 | - $field_obj->set_time_format($this->_tm_frmt); |
|
| 265 | - } |
|
| 266 | - $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 267 | - //should the value be null? |
|
| 268 | - if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 269 | - $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 270 | - /** |
|
| 271 | - * To save having to refactor all the models, if a default value is used for a |
|
| 272 | - * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 273 | - * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 274 | - * object. |
|
| 275 | - * |
|
| 276 | - * @since 4.6.10+ |
|
| 277 | - */ |
|
| 278 | - if ( |
|
| 279 | - $field_obj instanceof EE_Datetime_Field |
|
| 280 | - && $this->_fields[$field_name] !== null |
|
| 281 | - && ! $this->_fields[$field_name] instanceof DateTime |
|
| 282 | - ) { |
|
| 283 | - empty($this->_fields[$field_name]) |
|
| 284 | - ? $this->set($field_name, time()) |
|
| 285 | - : $this->set($field_name, $this->_fields[$field_name]); |
|
| 286 | - } |
|
| 287 | - } else { |
|
| 288 | - $this->_fields[$field_name] = $holder_of_value; |
|
| 289 | - } |
|
| 290 | - //if we're not in the constructor... |
|
| 291 | - //now check if what we set was a primary key |
|
| 292 | - if ( |
|
| 293 | - //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 294 | - $this->_props_n_values_provided_in_constructor |
|
| 295 | - && $field_value |
|
| 296 | - && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 297 | - ) { |
|
| 298 | - //if so, we want all this object's fields to be filled either with |
|
| 299 | - //what we've explicitly set on this model |
|
| 300 | - //or what we have in the db |
|
| 301 | - // echo "setting primary key!"; |
|
| 302 | - $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 303 | - $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 304 | - foreach ($fields_on_model as $field_obj) { |
|
| 305 | - if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 306 | - && $field_obj->get_name() !== $field_name |
|
| 307 | - ) { |
|
| 308 | - $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - //oh this model object has an ID? well make sure its in the entity mapper |
|
| 312 | - $this->get_model()->add_to_entity_map($this); |
|
| 313 | - } |
|
| 314 | - //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 315 | - $this->_clear_cached_property($field_name); |
|
| 316 | - } else { |
|
| 317 | - throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 318 | - "event_espresso"), $field_name)); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * This sets the field value on the db column if it exists for the given $column_name or |
|
| 326 | - * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 327 | - * |
|
| 328 | - * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 329 | - * @param string $field_name Must be the exact column name. |
|
| 330 | - * @param mixed $field_value The value to set. |
|
| 331 | - * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 332 | - * @throws \EE_Error |
|
| 333 | - */ |
|
| 334 | - public function set_field_or_extra_meta($field_name, $field_value) |
|
| 335 | - { |
|
| 336 | - if ($this->get_model()->has_field($field_name)) { |
|
| 337 | - $this->set($field_name, $field_value); |
|
| 338 | - return true; |
|
| 339 | - } else { |
|
| 340 | - //ensure this object is saved first so that extra meta can be properly related. |
|
| 341 | - $this->save(); |
|
| 342 | - return $this->update_extra_meta($field_name, $field_value); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * This retrieves the value of the db column set on this class or if that's not present |
|
| 350 | - * it will attempt to retrieve from extra_meta if found. |
|
| 351 | - * Example Usage: |
|
| 352 | - * Via EE_Message child class: |
|
| 353 | - * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 354 | - * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 355 | - * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 356 | - * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 357 | - * value for those extra fields dynamically via the EE_message object. |
|
| 358 | - * |
|
| 359 | - * @param string $field_name expecting the fully qualified field name. |
|
| 360 | - * @return mixed|null value for the field if found. null if not found. |
|
| 361 | - * @throws \EE_Error |
|
| 362 | - */ |
|
| 363 | - public function get_field_or_extra_meta($field_name) |
|
| 364 | - { |
|
| 365 | - if ($this->get_model()->has_field($field_name)) { |
|
| 366 | - $column_value = $this->get($field_name); |
|
| 367 | - } else { |
|
| 368 | - //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 369 | - $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 370 | - } |
|
| 371 | - return $column_value; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 378 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 379 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 380 | - * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 381 | - * |
|
| 382 | - * @access public |
|
| 383 | - * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 384 | - * @return void |
|
| 385 | - * @throws \EE_Error |
|
| 386 | - */ |
|
| 387 | - public function set_timezone($timezone = '') |
|
| 388 | - { |
|
| 389 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 390 | - //make sure we clear all cached properties because they won't be relevant now |
|
| 391 | - $this->_clear_cached_properties(); |
|
| 392 | - //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 393 | - $model_fields = $this->get_model()->field_settings(false); |
|
| 394 | - foreach ($model_fields as $field_name => $field_obj) { |
|
| 395 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 396 | - $field_obj->set_timezone($this->_timezone); |
|
| 397 | - if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 398 | - $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * This just returns whatever is set for the current timezone. |
|
| 408 | - * |
|
| 409 | - * @access public |
|
| 410 | - * @return string timezone string |
|
| 411 | - */ |
|
| 412 | - public function get_timezone() |
|
| 413 | - { |
|
| 414 | - return $this->_timezone; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 421 | - * internally instead of wp set date format options |
|
| 422 | - * |
|
| 423 | - * @since 4.6 |
|
| 424 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 425 | - */ |
|
| 426 | - public function set_date_format($format) |
|
| 427 | - { |
|
| 428 | - $this->_dt_frmt = $format; |
|
| 429 | - //clear cached_properties because they won't be relevant now. |
|
| 430 | - $this->_clear_cached_properties(); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 437 | - * class internally instead of wp set time format options. |
|
| 438 | - * |
|
| 439 | - * @since 4.6 |
|
| 440 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 441 | - */ |
|
| 442 | - public function set_time_format($format) |
|
| 443 | - { |
|
| 444 | - $this->_tm_frmt = $format; |
|
| 445 | - //clear cached_properties because they won't be relevant now. |
|
| 446 | - $this->_clear_cached_properties(); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * This returns the current internal set format for the date and time formats. |
|
| 453 | - * |
|
| 454 | - * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 455 | - * where the first value is the date format and the second value is the time format. |
|
| 456 | - * @return mixed string|array |
|
| 457 | - */ |
|
| 458 | - public function get_format($full = true) |
|
| 459 | - { |
|
| 460 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * cache |
|
| 467 | - * stores the passed model object on the current model object. |
|
| 468 | - * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 469 | - * |
|
| 470 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 471 | - * 'Registration' associated with this model object |
|
| 472 | - * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 473 | - * that could be a payment or a registration) |
|
| 474 | - * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 475 | - * items which will be stored in an array on this object |
|
| 476 | - * @throws EE_Error |
|
| 477 | - * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 478 | - * related thing, no array) |
|
| 479 | - */ |
|
| 480 | - public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 481 | - { |
|
| 482 | - // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 483 | - if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 484 | - return false; |
|
| 485 | - } |
|
| 486 | - // also get "how" the object is related, or throw an error |
|
| 487 | - if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 488 | - throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 489 | - $relationName, get_class($this))); |
|
| 490 | - } |
|
| 491 | - // how many things are related ? |
|
| 492 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 493 | - // 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 |
|
| 494 | - // so for these model objects just set it to be cached |
|
| 495 | - $this->_model_relations[$relationName] = $object_to_cache; |
|
| 496 | - $return = true; |
|
| 497 | - } else { |
|
| 498 | - // 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. |
|
| 499 | - // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 500 | - if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 501 | - // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 502 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 503 | - ? array($this->_model_relations[$relationName]) : array(); |
|
| 504 | - } |
|
| 505 | - // first check for a cache_id which is normally empty |
|
| 506 | - if ( ! empty($cache_id)) { |
|
| 507 | - // 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 |
|
| 508 | - $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 509 | - $return = $cache_id; |
|
| 510 | - } elseif ($object_to_cache->ID()) { |
|
| 511 | - // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 512 | - $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 513 | - $return = $object_to_cache->ID(); |
|
| 514 | - } else { |
|
| 515 | - // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 516 | - $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 517 | - // move the internal pointer to the end of the array |
|
| 518 | - end($this->_model_relations[$relationName]); |
|
| 519 | - // and grab the key so that we can return it |
|
| 520 | - $return = key($this->_model_relations[$relationName]); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - return $return; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * For adding an item to the cached_properties property. |
|
| 530 | - * |
|
| 531 | - * @access protected |
|
| 532 | - * @param string $fieldname the property item the corresponding value is for. |
|
| 533 | - * @param mixed $value The value we are caching. |
|
| 534 | - * @param string|null $cache_type |
|
| 535 | - * @return void |
|
| 536 | - * @throws \EE_Error |
|
| 537 | - */ |
|
| 538 | - protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 539 | - { |
|
| 540 | - //first make sure this property exists |
|
| 541 | - $this->get_model()->field_settings_for($fieldname); |
|
| 542 | - $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 543 | - $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 550 | - * This also SETS the cache if we return the actual property! |
|
| 551 | - * |
|
| 552 | - * @param string $fieldname the name of the property we're trying to retrieve |
|
| 553 | - * @param bool $pretty |
|
| 554 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 555 | - * (in cases where the same property may be used for different outputs |
|
| 556 | - * - i.e. datetime, money etc.) |
|
| 557 | - * It can also accept certain pre-defined "schema" strings |
|
| 558 | - * to define how to output the property. |
|
| 559 | - * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 560 | - * @return mixed whatever the value for the property is we're retrieving |
|
| 561 | - * @throws \EE_Error |
|
| 562 | - */ |
|
| 563 | - protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 564 | - { |
|
| 565 | - //verify the field exists |
|
| 566 | - $this->get_model()->field_settings_for($fieldname); |
|
| 567 | - $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 568 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 569 | - if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 570 | - return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 571 | - } |
|
| 572 | - $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 573 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 574 | - // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 575 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 576 | - $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 577 | - } |
|
| 578 | - if ( ! isset($this->_fields[$fieldname])) { |
|
| 579 | - $this->_fields[$fieldname] = null; |
|
| 580 | - } |
|
| 581 | - $value = $pretty |
|
| 582 | - ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 583 | - : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 584 | - $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 585 | - return $value; |
|
| 586 | - } |
|
| 587 | - return null; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 594 | - * |
|
| 595 | - * @param \EE_Datetime_Field $datetime_field |
|
| 596 | - * @param bool $pretty |
|
| 597 | - * @param null $date_or_time |
|
| 598 | - * @return void |
|
| 599 | - * @throws \EE_Error |
|
| 600 | - */ |
|
| 601 | - protected function _prepare_datetime_field( |
|
| 602 | - EE_Datetime_Field $datetime_field, |
|
| 603 | - $pretty = false, |
|
| 604 | - $date_or_time = null |
|
| 605 | - ) { |
|
| 606 | - $datetime_field->set_timezone($this->_timezone); |
|
| 607 | - $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 608 | - $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 609 | - //set the output returned |
|
| 610 | - switch ($date_or_time) { |
|
| 611 | - case 'D' : |
|
| 612 | - $datetime_field->set_date_time_output('date'); |
|
| 613 | - break; |
|
| 614 | - case 'T' : |
|
| 615 | - $datetime_field->set_date_time_output('time'); |
|
| 616 | - break; |
|
| 617 | - default : |
|
| 618 | - $datetime_field->set_date_time_output(); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * This just takes care of clearing out the cached_properties |
|
| 626 | - * |
|
| 627 | - * @return void |
|
| 628 | - */ |
|
| 629 | - protected function _clear_cached_properties() |
|
| 630 | - { |
|
| 631 | - $this->_cached_properties = array(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * This just clears out ONE property if it exists in the cache |
|
| 638 | - * |
|
| 639 | - * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 640 | - * @return void |
|
| 641 | - */ |
|
| 642 | - protected function _clear_cached_property($property_name) |
|
| 643 | - { |
|
| 644 | - if (isset($this->_cached_properties[$property_name])) { |
|
| 645 | - unset($this->_cached_properties[$property_name]); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Ensures that this related thing is a model object. |
|
| 653 | - * |
|
| 654 | - * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 655 | - * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 656 | - * @return EE_Base_Class |
|
| 657 | - * @throws \EE_Error |
|
| 658 | - */ |
|
| 659 | - protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 660 | - { |
|
| 661 | - $other_model_instance = self::_get_model_instance_with_name( |
|
| 662 | - self::_get_model_classname($model_name), |
|
| 663 | - $this->_timezone |
|
| 664 | - ); |
|
| 665 | - return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 672 | - * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 673 | - * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 674 | - * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 675 | - * |
|
| 676 | - * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 677 | - * Eg 'Registration' |
|
| 678 | - * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 679 | - * if you intend to use $clear_all = TRUE, or the relation only |
|
| 680 | - * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 681 | - * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 682 | - * this is HasMany or HABTM. |
|
| 683 | - * @throws EE_Error |
|
| 684 | - * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 685 | - * relation from all |
|
| 686 | - */ |
|
| 687 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 688 | - { |
|
| 689 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 690 | - $index_in_cache = ''; |
|
| 691 | - if ( ! $relationship_to_model) { |
|
| 692 | - throw new EE_Error( |
|
| 693 | - sprintf( |
|
| 694 | - __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 695 | - $relationName, |
|
| 696 | - get_class($this) |
|
| 697 | - ) |
|
| 698 | - ); |
|
| 699 | - } |
|
| 700 | - if ($clear_all) { |
|
| 701 | - $obj_removed = true; |
|
| 702 | - $this->_model_relations[$relationName] = null; |
|
| 703 | - } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 704 | - $obj_removed = $this->_model_relations[$relationName]; |
|
| 705 | - $this->_model_relations[$relationName] = null; |
|
| 706 | - } else { |
|
| 707 | - if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 708 | - && $object_to_remove_or_index_into_array->ID() |
|
| 709 | - ) { |
|
| 710 | - $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 711 | - if (is_array($this->_model_relations[$relationName]) |
|
| 712 | - && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 713 | - ) { |
|
| 714 | - $index_found_at = null; |
|
| 715 | - //find this object in the array even though it has a different key |
|
| 716 | - foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 717 | - if ( |
|
| 718 | - $obj instanceof EE_Base_Class |
|
| 719 | - && ( |
|
| 720 | - $obj == $object_to_remove_or_index_into_array |
|
| 721 | - || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 722 | - ) |
|
| 723 | - ) { |
|
| 724 | - $index_found_at = $index; |
|
| 725 | - break; |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - if ($index_found_at) { |
|
| 729 | - $index_in_cache = $index_found_at; |
|
| 730 | - } else { |
|
| 731 | - //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 732 | - //if it wasn't in it to begin with. So we're done |
|
| 733 | - return $object_to_remove_or_index_into_array; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 737 | - //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 738 | - foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 739 | - if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 740 | - $index_in_cache = $index; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - } else { |
|
| 744 | - $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 745 | - } |
|
| 746 | - //supposedly we've found it. But it could just be that the client code |
|
| 747 | - //provided a bad index/object |
|
| 748 | - if ( |
|
| 749 | - isset( |
|
| 750 | - $this->_model_relations[$relationName], |
|
| 751 | - $this->_model_relations[$relationName][$index_in_cache] |
|
| 752 | - ) |
|
| 753 | - ) { |
|
| 754 | - $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 755 | - unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 756 | - } else { |
|
| 757 | - //that thing was never cached anyways. |
|
| 758 | - $obj_removed = null; |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $obj_removed; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * update_cache_after_object_save |
|
| 768 | - * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 769 | - * obtained after being saved to the db |
|
| 770 | - * |
|
| 771 | - * @param string $relationName - the type of object that is cached |
|
| 772 | - * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 773 | - * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 774 | - * @return boolean TRUE on success, FALSE on fail |
|
| 775 | - * @throws \EE_Error |
|
| 776 | - */ |
|
| 777 | - public function update_cache_after_object_save( |
|
| 778 | - $relationName, |
|
| 779 | - EE_Base_Class $newly_saved_object, |
|
| 780 | - $current_cache_id = '' |
|
| 781 | - ) { |
|
| 782 | - // verify that incoming object is of the correct type |
|
| 783 | - $obj_class = 'EE_' . $relationName; |
|
| 784 | - if ($newly_saved_object instanceof $obj_class) { |
|
| 785 | - /* @type EE_Base_Class $newly_saved_object */ |
|
| 786 | - // now get the type of relation |
|
| 787 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 788 | - // if this is a 1:1 relationship |
|
| 789 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 790 | - // then just replace the cached object with the newly saved object |
|
| 791 | - $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 792 | - return true; |
|
| 793 | - // or if it's some kind of sordid feral polyamorous relationship... |
|
| 794 | - } elseif (is_array($this->_model_relations[$relationName]) |
|
| 795 | - && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 796 | - ) { |
|
| 797 | - // then remove the current cached item |
|
| 798 | - unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 799 | - // and cache the newly saved object using it's new ID |
|
| 800 | - $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 801 | - return true; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 811 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 812 | - * |
|
| 813 | - * @param string $relationName |
|
| 814 | - * @return EE_Base_Class |
|
| 815 | - */ |
|
| 816 | - public function get_one_from_cache($relationName) |
|
| 817 | - { |
|
| 818 | - $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 819 | - : null; |
|
| 820 | - if (is_array($cached_array_or_object)) { |
|
| 821 | - return array_shift($cached_array_or_object); |
|
| 822 | - } else { |
|
| 823 | - return $cached_array_or_object; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 831 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 832 | - * |
|
| 833 | - * @param string $relationName |
|
| 834 | - * @throws \EE_Error |
|
| 835 | - * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 836 | - */ |
|
| 837 | - public function get_all_from_cache($relationName) |
|
| 838 | - { |
|
| 839 | - $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 840 | - // if the result is not an array, but exists, make it an array |
|
| 841 | - $objects = is_array($objects) ? $objects : array($objects); |
|
| 842 | - //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 843 | - //basically, if this model object was stored in the session, and these cached model objects |
|
| 844 | - //already have IDs, let's make sure they're in their model's entity mapper |
|
| 845 | - //otherwise we will have duplicates next time we call |
|
| 846 | - // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 847 | - $model = EE_Registry::instance()->load_model($relationName); |
|
| 848 | - foreach ($objects as $model_object) { |
|
| 849 | - if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 850 | - //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 851 | - if ($model_object->ID()) { |
|
| 852 | - $model->add_to_entity_map($model_object); |
|
| 853 | - } |
|
| 854 | - } else { |
|
| 855 | - throw new EE_Error( |
|
| 856 | - sprintf( |
|
| 857 | - __( |
|
| 858 | - 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 859 | - 'event_espresso' |
|
| 860 | - ), |
|
| 861 | - $relationName, |
|
| 862 | - gettype($model_object) |
|
| 863 | - ) |
|
| 864 | - ); |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - return $objects; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 874 | - * matching the given query conditions. |
|
| 875 | - * |
|
| 876 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 877 | - * @param int $limit How many objects to return. |
|
| 878 | - * @param array $query_params Any additional conditions on the query. |
|
| 879 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 880 | - * you can indicate just the columns you want returned |
|
| 881 | - * @return array|EE_Base_Class[] |
|
| 882 | - * @throws \EE_Error |
|
| 883 | - */ |
|
| 884 | - public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 885 | - { |
|
| 886 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 887 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 888 | - : $field_to_order_by; |
|
| 889 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 890 | - if (empty($field) || empty($current_value)) { |
|
| 891 | - return array(); |
|
| 892 | - } |
|
| 893 | - return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 900 | - * matching the given query conditions. |
|
| 901 | - * |
|
| 902 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 903 | - * @param int $limit How many objects to return. |
|
| 904 | - * @param array $query_params Any additional conditions on the query. |
|
| 905 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 906 | - * you can indicate just the columns you want returned |
|
| 907 | - * @return array|EE_Base_Class[] |
|
| 908 | - * @throws \EE_Error |
|
| 909 | - */ |
|
| 910 | - public function previous_x( |
|
| 911 | - $field_to_order_by = null, |
|
| 912 | - $limit = 1, |
|
| 913 | - $query_params = array(), |
|
| 914 | - $columns_to_select = null |
|
| 915 | - ) { |
|
| 916 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 917 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 918 | - : $field_to_order_by; |
|
| 919 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 920 | - if (empty($field) || empty($current_value)) { |
|
| 921 | - return array(); |
|
| 922 | - } |
|
| 923 | - return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 930 | - * matching the given query conditions. |
|
| 931 | - * |
|
| 932 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 933 | - * @param array $query_params Any additional conditions on the query. |
|
| 934 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 935 | - * you can indicate just the columns you want returned |
|
| 936 | - * @return array|EE_Base_Class |
|
| 937 | - * @throws \EE_Error |
|
| 938 | - */ |
|
| 939 | - public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 940 | - { |
|
| 941 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 942 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 943 | - : $field_to_order_by; |
|
| 944 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 945 | - if (empty($field) || empty($current_value)) { |
|
| 946 | - return array(); |
|
| 947 | - } |
|
| 948 | - return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 955 | - * matching the given query conditions. |
|
| 956 | - * |
|
| 957 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 958 | - * @param array $query_params Any additional conditions on the query. |
|
| 959 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 960 | - * you can indicate just the column you want returned |
|
| 961 | - * @return array|EE_Base_Class |
|
| 962 | - * @throws \EE_Error |
|
| 963 | - */ |
|
| 964 | - public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 965 | - { |
|
| 966 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 967 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 968 | - : $field_to_order_by; |
|
| 969 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 970 | - if (empty($field) || empty($current_value)) { |
|
| 971 | - return array(); |
|
| 972 | - } |
|
| 973 | - return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Overrides parent because parent expects old models. |
|
| 980 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 981 | - * |
|
| 982 | - * @param string $field_name |
|
| 983 | - * @param mixed $field_value_from_db |
|
| 984 | - * @throws \EE_Error |
|
| 985 | - */ |
|
| 986 | - public function set_from_db($field_name, $field_value_from_db) |
|
| 987 | - { |
|
| 988 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 989 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 990 | - //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 991 | - //eg, a CPT model object could have an entry in the posts table, but no |
|
| 992 | - //entry in the meta table. Meaning that all its columns in the meta table |
|
| 993 | - //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 994 | - if ($field_value_from_db === null) { |
|
| 995 | - if ($field_obj->is_nullable()) { |
|
| 996 | - //if the field allows nulls, then let it be null |
|
| 997 | - $field_value = null; |
|
| 998 | - } else { |
|
| 999 | - $field_value = $field_obj->get_default_value(); |
|
| 1000 | - } |
|
| 1001 | - } else { |
|
| 1002 | - $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1003 | - } |
|
| 1004 | - $this->_fields[$field_name] = $field_value; |
|
| 1005 | - $this->_clear_cached_property($field_name); |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * verifies that the specified field is of the correct type |
|
| 1013 | - * |
|
| 1014 | - * @param string $field_name |
|
| 1015 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1016 | - * (in cases where the same property may be used for different outputs |
|
| 1017 | - * - i.e. datetime, money etc.) |
|
| 1018 | - * @return mixed |
|
| 1019 | - * @throws \EE_Error |
|
| 1020 | - */ |
|
| 1021 | - public function get($field_name, $extra_cache_ref = null) |
|
| 1022 | - { |
|
| 1023 | - return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1030 | - * |
|
| 1031 | - * @param string $field_name A valid fieldname |
|
| 1032 | - * @return mixed Whatever the raw value stored on the property is. |
|
| 1033 | - * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1034 | - */ |
|
| 1035 | - public function get_raw($field_name) |
|
| 1036 | - { |
|
| 1037 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1038 | - return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
| 1039 | - ? $this->_fields[$field_name]->format('U') |
|
| 1040 | - : $this->_fields[$field_name]; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * This is used to return the internal DateTime object used for a field that is a |
|
| 1047 | - * EE_Datetime_Field. |
|
| 1048 | - * |
|
| 1049 | - * @param string $field_name The field name retrieving the DateTime object. |
|
| 1050 | - * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1051 | - * @throws \EE_Error |
|
| 1052 | - * an error is set and false returned. If the field IS an |
|
| 1053 | - * EE_Datetime_Field and but the field value is null, then |
|
| 1054 | - * just null is returned (because that indicates that likely |
|
| 1055 | - * this field is nullable). |
|
| 1056 | - */ |
|
| 1057 | - public function get_DateTime_object($field_name) |
|
| 1058 | - { |
|
| 1059 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1060 | - if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1061 | - EE_Error::add_error( |
|
| 1062 | - sprintf( |
|
| 1063 | - __( |
|
| 1064 | - 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1065 | - 'event_espresso' |
|
| 1066 | - ), |
|
| 1067 | - $field_name |
|
| 1068 | - ), |
|
| 1069 | - __FILE__, |
|
| 1070 | - __FUNCTION__, |
|
| 1071 | - __LINE__ |
|
| 1072 | - ); |
|
| 1073 | - return false; |
|
| 1074 | - } |
|
| 1075 | - return $this->_fields[$field_name]; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * To be used in template to immediately echo out the value, and format it for output. |
|
| 1082 | - * Eg, should call stripslashes and whatnot before echoing |
|
| 1083 | - * |
|
| 1084 | - * @param string $field_name the name of the field as it appears in the DB |
|
| 1085 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1086 | - * (in cases where the same property may be used for different outputs |
|
| 1087 | - * - i.e. datetime, money etc.) |
|
| 1088 | - * @return void |
|
| 1089 | - * @throws \EE_Error |
|
| 1090 | - */ |
|
| 1091 | - public function e($field_name, $extra_cache_ref = null) |
|
| 1092 | - { |
|
| 1093 | - echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1100 | - * can be easily used as the value of form input. |
|
| 1101 | - * |
|
| 1102 | - * @param string $field_name |
|
| 1103 | - * @return void |
|
| 1104 | - * @throws \EE_Error |
|
| 1105 | - */ |
|
| 1106 | - public function f($field_name) |
|
| 1107 | - { |
|
| 1108 | - $this->e($field_name, 'form_input'); |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 1115 | - * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 1116 | - * to see what options are available. |
|
| 1117 | - * @param string $field_name |
|
| 1118 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1119 | - * (in cases where the same property may be used for different outputs |
|
| 1120 | - * - i.e. datetime, money etc.) |
|
| 1121 | - * @return mixed |
|
| 1122 | - * @throws \EE_Error |
|
| 1123 | - */ |
|
| 1124 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1125 | - { |
|
| 1126 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - /** |
|
| 1132 | - * This simply returns the datetime for the given field name |
|
| 1133 | - * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1134 | - * (and the equivalent e_date, e_time, e_datetime). |
|
| 1135 | - * |
|
| 1136 | - * @access protected |
|
| 1137 | - * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1138 | - * @param string $dt_frmt valid datetime format used for date |
|
| 1139 | - * (if '' then we just use the default on the field, |
|
| 1140 | - * if NULL we use the last-used format) |
|
| 1141 | - * @param string $tm_frmt Same as above except this is for time format |
|
| 1142 | - * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1143 | - * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1144 | - * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1145 | - * if field is not a valid dtt field, or void if echoing |
|
| 1146 | - * @throws \EE_Error |
|
| 1147 | - */ |
|
| 1148 | - protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1149 | - { |
|
| 1150 | - // clear cached property |
|
| 1151 | - $this->_clear_cached_property($field_name); |
|
| 1152 | - //reset format properties because they are used in get() |
|
| 1153 | - $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1154 | - $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1155 | - if ($echo) { |
|
| 1156 | - $this->e($field_name, $date_or_time); |
|
| 1157 | - return ''; |
|
| 1158 | - } |
|
| 1159 | - return $this->get($field_name, $date_or_time); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - |
|
| 1164 | - /** |
|
| 1165 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1166 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1167 | - * other echoes the pretty value for dtt) |
|
| 1168 | - * |
|
| 1169 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1170 | - * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1171 | - * @return string datetime value formatted |
|
| 1172 | - * @throws \EE_Error |
|
| 1173 | - */ |
|
| 1174 | - public function get_date($field_name, $format = '') |
|
| 1175 | - { |
|
| 1176 | - return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * @param $field_name |
|
| 1183 | - * @param string $format |
|
| 1184 | - * @throws \EE_Error |
|
| 1185 | - */ |
|
| 1186 | - public function e_date($field_name, $format = '') |
|
| 1187 | - { |
|
| 1188 | - $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1195 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1196 | - * other echoes the pretty value for dtt) |
|
| 1197 | - * |
|
| 1198 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1199 | - * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1200 | - * @return string datetime value formatted |
|
| 1201 | - * @throws \EE_Error |
|
| 1202 | - */ |
|
| 1203 | - public function get_time($field_name, $format = '') |
|
| 1204 | - { |
|
| 1205 | - return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * @param $field_name |
|
| 1212 | - * @param string $format |
|
| 1213 | - * @throws \EE_Error |
|
| 1214 | - */ |
|
| 1215 | - public function e_time($field_name, $format = '') |
|
| 1216 | - { |
|
| 1217 | - $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1224 | - * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1225 | - * other echoes the pretty value for dtt) |
|
| 1226 | - * |
|
| 1227 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1228 | - * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1229 | - * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1230 | - * @return string datetime value formatted |
|
| 1231 | - * @throws \EE_Error |
|
| 1232 | - */ |
|
| 1233 | - public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1234 | - { |
|
| 1235 | - return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * @param string $field_name |
|
| 1242 | - * @param string $dt_frmt |
|
| 1243 | - * @param string $tm_frmt |
|
| 1244 | - * @throws \EE_Error |
|
| 1245 | - */ |
|
| 1246 | - public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1247 | - { |
|
| 1248 | - $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - |
|
| 1252 | - |
|
| 1253 | - /** |
|
| 1254 | - * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1255 | - * |
|
| 1256 | - * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1257 | - * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1258 | - * on the object will be used. |
|
| 1259 | - * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1260 | - * @throws \EE_Error |
|
| 1261 | - * field name. |
|
| 1262 | - */ |
|
| 1263 | - public function get_i18n_datetime($field_name, $format = '') |
|
| 1264 | - { |
|
| 1265 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1266 | - return date_i18n( |
|
| 1267 | - $format, |
|
| 1268 | - EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1269 | - ); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - |
|
| 1274 | - /** |
|
| 1275 | - * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1276 | - * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1277 | - * thrown. |
|
| 1278 | - * |
|
| 1279 | - * @param string $field_name The field name being checked |
|
| 1280 | - * @throws EE_Error |
|
| 1281 | - * @return EE_Datetime_Field |
|
| 1282 | - */ |
|
| 1283 | - protected function _get_dtt_field_settings($field_name) |
|
| 1284 | - { |
|
| 1285 | - $field = $this->get_model()->field_settings_for($field_name); |
|
| 1286 | - //check if field is dtt |
|
| 1287 | - if ($field instanceof EE_Datetime_Field) { |
|
| 1288 | - return $field; |
|
| 1289 | - } else { |
|
| 1290 | - 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', |
|
| 1291 | - 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * NOTE ABOUT BELOW: |
|
| 1300 | - * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1301 | - * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1302 | - * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1303 | - * method and make sure you send the entire datetime value for setting. |
|
| 1304 | - */ |
|
| 1305 | - /** |
|
| 1306 | - * sets the time on a datetime property |
|
| 1307 | - * |
|
| 1308 | - * @access protected |
|
| 1309 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1310 | - * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1311 | - * @throws \EE_Error |
|
| 1312 | - */ |
|
| 1313 | - protected function _set_time_for($time, $fieldname) |
|
| 1314 | - { |
|
| 1315 | - $this->_set_date_time('T', $time, $fieldname); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - |
|
| 1320 | - /** |
|
| 1321 | - * sets the date on a datetime property |
|
| 1322 | - * |
|
| 1323 | - * @access protected |
|
| 1324 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1325 | - * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1326 | - * @throws \EE_Error |
|
| 1327 | - */ |
|
| 1328 | - protected function _set_date_for($date, $fieldname) |
|
| 1329 | - { |
|
| 1330 | - $this->_set_date_time('D', $date, $fieldname); |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1337 | - * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1338 | - * |
|
| 1339 | - * @access protected |
|
| 1340 | - * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1341 | - * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1342 | - * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1343 | - * EE_Datetime_Field property) |
|
| 1344 | - * @throws \EE_Error |
|
| 1345 | - */ |
|
| 1346 | - protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1347 | - { |
|
| 1348 | - $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1349 | - $field->set_timezone($this->_timezone); |
|
| 1350 | - $field->set_date_format($this->_dt_frmt); |
|
| 1351 | - $field->set_time_format($this->_tm_frmt); |
|
| 1352 | - switch ($what) { |
|
| 1353 | - case 'T' : |
|
| 1354 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1355 | - $datetime_value, |
|
| 1356 | - $this->_fields[$fieldname] |
|
| 1357 | - ); |
|
| 1358 | - break; |
|
| 1359 | - case 'D' : |
|
| 1360 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1361 | - $datetime_value, |
|
| 1362 | - $this->_fields[$fieldname] |
|
| 1363 | - ); |
|
| 1364 | - break; |
|
| 1365 | - case 'B' : |
|
| 1366 | - $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1367 | - break; |
|
| 1368 | - } |
|
| 1369 | - $this->_clear_cached_property($fieldname); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1376 | - * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1377 | - * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1378 | - * that could lead to some unexpected results! |
|
| 1379 | - * |
|
| 1380 | - * @access public |
|
| 1381 | - * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1382 | - * value being returned. |
|
| 1383 | - * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1384 | - * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1385 | - * @param string $prepend You can include something to prepend on the timestamp |
|
| 1386 | - * @param string $append You can include something to append on the timestamp |
|
| 1387 | - * @throws EE_Error |
|
| 1388 | - * @return string timestamp |
|
| 1389 | - */ |
|
| 1390 | - public function display_in_my_timezone( |
|
| 1391 | - $field_name, |
|
| 1392 | - $callback = 'get_datetime', |
|
| 1393 | - $args = null, |
|
| 1394 | - $prepend = '', |
|
| 1395 | - $append = '' |
|
| 1396 | - ) { |
|
| 1397 | - $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1398 | - if ($timezone === $this->_timezone) { |
|
| 1399 | - return ''; |
|
| 1400 | - } |
|
| 1401 | - $original_timezone = $this->_timezone; |
|
| 1402 | - $this->set_timezone($timezone); |
|
| 1403 | - $fn = (array)$field_name; |
|
| 1404 | - $args = array_merge($fn, (array)$args); |
|
| 1405 | - if ( ! method_exists($this, $callback)) { |
|
| 1406 | - throw new EE_Error( |
|
| 1407 | - sprintf( |
|
| 1408 | - __( |
|
| 1409 | - 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1410 | - 'event_espresso' |
|
| 1411 | - ), |
|
| 1412 | - $callback |
|
| 1413 | - ) |
|
| 1414 | - ); |
|
| 1415 | - } |
|
| 1416 | - $args = (array)$args; |
|
| 1417 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1418 | - $this->set_timezone($original_timezone); |
|
| 1419 | - return $return; |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * Deletes this model object. |
|
| 1426 | - * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1427 | - * override |
|
| 1428 | - * `EE_Base_Class::_delete` NOT this class. |
|
| 1429 | - * |
|
| 1430 | - * @return boolean | int |
|
| 1431 | - * @throws \EE_Error |
|
| 1432 | - */ |
|
| 1433 | - public function delete() |
|
| 1434 | - { |
|
| 1435 | - /** |
|
| 1436 | - * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1437 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1438 | - * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1439 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1440 | - * |
|
| 1441 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1442 | - */ |
|
| 1443 | - do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1444 | - $result = $this->_delete(); |
|
| 1445 | - /** |
|
| 1446 | - * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1447 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1448 | - * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1449 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1450 | - * |
|
| 1451 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1452 | - * @param boolean $result |
|
| 1453 | - */ |
|
| 1454 | - do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1455 | - return $result; |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * Calls the specific delete method for the instantiated class. |
|
| 1462 | - * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1463 | - * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1464 | - * `EE_Base_Class::delete` |
|
| 1465 | - * |
|
| 1466 | - * @return bool|int |
|
| 1467 | - * @throws \EE_Error |
|
| 1468 | - */ |
|
| 1469 | - protected function _delete() |
|
| 1470 | - { |
|
| 1471 | - return $this->delete_permanently(); |
|
| 1472 | - } |
|
| 1473 | - |
|
| 1474 | - |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1478 | - * error) |
|
| 1479 | - * |
|
| 1480 | - * @return bool | int |
|
| 1481 | - * @throws \EE_Error |
|
| 1482 | - */ |
|
| 1483 | - public function delete_permanently() |
|
| 1484 | - { |
|
| 1485 | - /** |
|
| 1486 | - * Called just before HARD deleting a model object |
|
| 1487 | - * |
|
| 1488 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1489 | - */ |
|
| 1490 | - do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1491 | - $model = $this->get_model(); |
|
| 1492 | - $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1493 | - $this->refresh_cache_of_related_objects(); |
|
| 1494 | - /** |
|
| 1495 | - * Called just after HARD deleting a model object |
|
| 1496 | - * |
|
| 1497 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1498 | - * @param boolean $result |
|
| 1499 | - */ |
|
| 1500 | - do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1501 | - return $result; |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1508 | - * related model objects |
|
| 1509 | - * |
|
| 1510 | - * @throws \EE_Error |
|
| 1511 | - */ |
|
| 1512 | - public function refresh_cache_of_related_objects() |
|
| 1513 | - { |
|
| 1514 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1515 | - if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1516 | - $related_objects = $this->_model_relations[$relation_name]; |
|
| 1517 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1518 | - //this relation only stores a single model object, not an array |
|
| 1519 | - //but let's make it consistent |
|
| 1520 | - $related_objects = array($related_objects); |
|
| 1521 | - } |
|
| 1522 | - foreach ($related_objects as $related_object) { |
|
| 1523 | - //only refresh their cache if they're in memory |
|
| 1524 | - if ($related_object instanceof EE_Base_Class) { |
|
| 1525 | - $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1536 | - * object just before saving. |
|
| 1537 | - * |
|
| 1538 | - * @access public |
|
| 1539 | - * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1540 | - * if provided during the save() method (often client code will change the fields' |
|
| 1541 | - * values before calling save) |
|
| 1542 | - * @throws \EE_Error |
|
| 1543 | - * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1544 | - * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1545 | - */ |
|
| 1546 | - public function save($set_cols_n_values = array()) |
|
| 1547 | - { |
|
| 1548 | - /** |
|
| 1549 | - * Filters the fields we're about to save on the model object |
|
| 1550 | - * |
|
| 1551 | - * @param array $set_cols_n_values |
|
| 1552 | - * @param EE_Base_Class $model_object |
|
| 1553 | - */ |
|
| 1554 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1555 | - $this); |
|
| 1556 | - //set attributes as provided in $set_cols_n_values |
|
| 1557 | - foreach ($set_cols_n_values as $column => $value) { |
|
| 1558 | - $this->set($column, $value); |
|
| 1559 | - } |
|
| 1560 | - /** |
|
| 1561 | - * Saving a model object. |
|
| 1562 | - * Before we perform a save, this action is fired. |
|
| 1563 | - * |
|
| 1564 | - * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1565 | - */ |
|
| 1566 | - do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1567 | - if ( ! $this->allow_persist()) { |
|
| 1568 | - return 0; |
|
| 1569 | - } |
|
| 1570 | - //now get current attribute values |
|
| 1571 | - $save_cols_n_values = $this->_fields; |
|
| 1572 | - //if the object already has an ID, update it. Otherwise, insert it |
|
| 1573 | - //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1574 | - $old_assumption_concerning_value_preparation = $this->get_model() |
|
| 1575 | - ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1576 | - $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
| 1577 | - //does this model have an autoincrement PK? |
|
| 1578 | - if ($this->get_model()->has_primary_key_field()) { |
|
| 1579 | - if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1580 | - //ok check if it's set, if so: update; if not, insert |
|
| 1581 | - if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1582 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1583 | - } else { |
|
| 1584 | - unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1585 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1586 | - if ($results) { |
|
| 1587 | - //if successful, set the primary key |
|
| 1588 | - //but don't use the normal SET method, because it will check if |
|
| 1589 | - //an item with the same ID exists in the mapper & db, then |
|
| 1590 | - //will find it in the db (because we just added it) and THAT object |
|
| 1591 | - //will get added to the mapper before we can add this one! |
|
| 1592 | - //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1593 | - $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1594 | - $this->_fields[$pk_field_name] = $results; |
|
| 1595 | - $this->_clear_cached_property($pk_field_name); |
|
| 1596 | - $this->get_model()->add_to_entity_map($this); |
|
| 1597 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1598 | - } |
|
| 1599 | - } |
|
| 1600 | - } else {//PK is NOT auto-increment |
|
| 1601 | - //so check if one like it already exists in the db |
|
| 1602 | - if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1603 | - if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1604 | - throw new EE_Error( |
|
| 1605 | - sprintf( |
|
| 1606 | - __('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', |
|
| 1607 | - 'event_espresso'), |
|
| 1608 | - get_class($this), |
|
| 1609 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 1610 | - get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
| 1611 | - '<br />' |
|
| 1612 | - ) |
|
| 1613 | - ); |
|
| 1614 | - } |
|
| 1615 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1616 | - } else { |
|
| 1617 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1618 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1619 | - } |
|
| 1620 | - } |
|
| 1621 | - } else {//there is NO primary key |
|
| 1622 | - $already_in_db = false; |
|
| 1623 | - foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1624 | - $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1625 | - if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1626 | - $already_in_db = true; |
|
| 1627 | - } |
|
| 1628 | - } |
|
| 1629 | - if ($already_in_db) { |
|
| 1630 | - $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1631 | - $this->get_model()->get_combined_primary_key_fields()); |
|
| 1632 | - $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1633 | - } else { |
|
| 1634 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1635 | - } |
|
| 1636 | - } |
|
| 1637 | - //restore the old assumption about values being prepared by the model object |
|
| 1638 | - $this->get_model() |
|
| 1639 | - ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1640 | - /** |
|
| 1641 | - * After saving the model object this action is called |
|
| 1642 | - * |
|
| 1643 | - * @param EE_Base_Class $model_object which was just saved |
|
| 1644 | - * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1645 | - * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1646 | - */ |
|
| 1647 | - do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1648 | - return $results; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1655 | - * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1656 | - * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1657 | - * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1658 | - * 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 |
|
| 1659 | - * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1660 | - * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1661 | - * |
|
| 1662 | - * @return void |
|
| 1663 | - * @throws \EE_Error |
|
| 1664 | - */ |
|
| 1665 | - protected function _update_cached_related_model_objs_fks() |
|
| 1666 | - { |
|
| 1667 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1668 | - if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1669 | - foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1670 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1671 | - $this->get_model()->get_this_model_name() |
|
| 1672 | - ); |
|
| 1673 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1674 | - if ($related_model_obj_in_cache->ID()) { |
|
| 1675 | - $related_model_obj_in_cache->save(); |
|
| 1676 | - } |
|
| 1677 | - } |
|
| 1678 | - } |
|
| 1679 | - } |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * Saves this model object and its NEW cached relations to the database. |
|
| 1686 | - * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1687 | - * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1688 | - * because otherwise, there's a potential for infinite looping of saving |
|
| 1689 | - * Saves the cached related model objects, and ensures the relation between them |
|
| 1690 | - * and this object and properly setup |
|
| 1691 | - * |
|
| 1692 | - * @return int ID of new model object on save; 0 on failure+ |
|
| 1693 | - * @throws \EE_Error |
|
| 1694 | - */ |
|
| 1695 | - public function save_new_cached_related_model_objs() |
|
| 1696 | - { |
|
| 1697 | - //make sure this has been saved |
|
| 1698 | - if ( ! $this->ID()) { |
|
| 1699 | - $id = $this->save(); |
|
| 1700 | - } else { |
|
| 1701 | - $id = $this->ID(); |
|
| 1702 | - } |
|
| 1703 | - //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1704 | - foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1705 | - if ($this->_model_relations[$relationName]) { |
|
| 1706 | - //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1707 | - //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1708 | - if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1709 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1710 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1711 | - /* @var $related_model_obj EE_Base_Class */ |
|
| 1712 | - $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1713 | - // if( ! $related_model_obj->ID()){ |
|
| 1714 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1715 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1716 | - // } |
|
| 1717 | - } else { |
|
| 1718 | - foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1719 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1720 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1721 | - // if( ! $related_model_obj->ID()){ |
|
| 1722 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1723 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1724 | - // } |
|
| 1725 | - } |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - return $id; |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * for getting a model while instantiated. |
|
| 1736 | - * |
|
| 1737 | - * @return \EEM_Base | \EEM_CPT_Base |
|
| 1738 | - */ |
|
| 1739 | - public function get_model() |
|
| 1740 | - { |
|
| 1741 | - $modelName = self::_get_model_classname(get_class($this)); |
|
| 1742 | - return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - |
|
| 1746 | - |
|
| 1747 | - /** |
|
| 1748 | - * @param $props_n_values |
|
| 1749 | - * @param $classname |
|
| 1750 | - * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1751 | - * @throws \EE_Error |
|
| 1752 | - */ |
|
| 1753 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1754 | - { |
|
| 1755 | - //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1756 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1757 | - if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1758 | - $id = $props_n_values[$primary_id_ref]; |
|
| 1759 | - return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1760 | - } |
|
| 1761 | - return false; |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1768 | - * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1769 | - * primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not |
|
| 1770 | - * we return false. |
|
| 1771 | - * |
|
| 1772 | - * @param array $props_n_values incoming array of properties and their values |
|
| 1773 | - * @param string $classname the classname of the child class |
|
| 1774 | - * @param null $timezone |
|
| 1775 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1776 | - * date_format and the second value is the time format |
|
| 1777 | - * @return mixed (EE_Base_Class|bool) |
|
| 1778 | - * @throws \EE_Error |
|
| 1779 | - */ |
|
| 1780 | - protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1781 | - { |
|
| 1782 | - $existing = null; |
|
| 1783 | - if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1784 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1785 | - if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1786 | - && ! empty($props_n_values[$primary_id_ref]) |
|
| 1787 | - ) { |
|
| 1788 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1789 | - $props_n_values[$primary_id_ref] |
|
| 1790 | - ); |
|
| 1791 | - } |
|
| 1792 | - } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1793 | - //no primary key on this model, but there's still a matching item in the DB |
|
| 1794 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1795 | - self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1796 | - ); |
|
| 1797 | - } |
|
| 1798 | - if ($existing) { |
|
| 1799 | - //set date formats if present before setting values |
|
| 1800 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1801 | - $existing->set_date_format($date_formats[0]); |
|
| 1802 | - $existing->set_time_format($date_formats[1]); |
|
| 1803 | - } else { |
|
| 1804 | - //set default formats for date and time |
|
| 1805 | - $existing->set_date_format(get_option('date_format')); |
|
| 1806 | - $existing->set_time_format(get_option('time_format')); |
|
| 1807 | - } |
|
| 1808 | - foreach ($props_n_values as $property => $field_value) { |
|
| 1809 | - $existing->set($property, $field_value); |
|
| 1810 | - } |
|
| 1811 | - return $existing; |
|
| 1812 | - } else { |
|
| 1813 | - return false; |
|
| 1814 | - } |
|
| 1815 | - } |
|
| 1816 | - |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Gets the EEM_*_Model for this class |
|
| 1821 | - * |
|
| 1822 | - * @access public now, as this is more convenient |
|
| 1823 | - * @param $classname |
|
| 1824 | - * @param null $timezone |
|
| 1825 | - * @throws EE_Error |
|
| 1826 | - * @return EEM_Base |
|
| 1827 | - */ |
|
| 1828 | - protected static function _get_model($classname, $timezone = null) |
|
| 1829 | - { |
|
| 1830 | - //find model for this class |
|
| 1831 | - if ( ! $classname) { |
|
| 1832 | - throw new EE_Error( |
|
| 1833 | - sprintf( |
|
| 1834 | - __( |
|
| 1835 | - "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1836 | - "event_espresso" |
|
| 1837 | - ), |
|
| 1838 | - $classname |
|
| 1839 | - ) |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1842 | - $modelName = self::_get_model_classname($classname); |
|
| 1843 | - return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - |
|
| 1847 | - |
|
| 1848 | - /** |
|
| 1849 | - * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1850 | - * |
|
| 1851 | - * @param string $model_classname |
|
| 1852 | - * @param null $timezone |
|
| 1853 | - * @return EEM_Base |
|
| 1854 | - */ |
|
| 1855 | - protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1856 | - { |
|
| 1857 | - $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1858 | - $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1859 | - $model->set_timezone($timezone); |
|
| 1860 | - return $model; |
|
| 1861 | - } |
|
| 1862 | - |
|
| 1863 | - |
|
| 1864 | - |
|
| 1865 | - /** |
|
| 1866 | - * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 1867 | - * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 1868 | - * |
|
| 1869 | - * @param null $model_name |
|
| 1870 | - * @return string like EEM_Attendee |
|
| 1871 | - */ |
|
| 1872 | - private static function _get_model_classname($model_name = null) |
|
| 1873 | - { |
|
| 1874 | - if (strpos($model_name, "EE_") === 0) { |
|
| 1875 | - $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1876 | - } else { |
|
| 1877 | - $model_classname = "EEM_" . $model_name; |
|
| 1878 | - } |
|
| 1879 | - return $model_classname; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * returns the name of the primary key attribute |
|
| 1886 | - * |
|
| 1887 | - * @param null $classname |
|
| 1888 | - * @throws EE_Error |
|
| 1889 | - * @return string |
|
| 1890 | - */ |
|
| 1891 | - protected static function _get_primary_key_name($classname = null) |
|
| 1892 | - { |
|
| 1893 | - if ( ! $classname) { |
|
| 1894 | - throw new EE_Error( |
|
| 1895 | - sprintf( |
|
| 1896 | - __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1897 | - $classname |
|
| 1898 | - ) |
|
| 1899 | - ); |
|
| 1900 | - } |
|
| 1901 | - return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - |
|
| 1905 | - |
|
| 1906 | - /** |
|
| 1907 | - * Gets the value of the primary key. |
|
| 1908 | - * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 1909 | - * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 1910 | - * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 1911 | - * |
|
| 1912 | - * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 1913 | - * @throws \EE_Error |
|
| 1914 | - */ |
|
| 1915 | - public function ID() |
|
| 1916 | - { |
|
| 1917 | - //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 1918 | - if ($this->get_model()->has_primary_key_field()) { |
|
| 1919 | - return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1920 | - } else { |
|
| 1921 | - return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1922 | - } |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - |
|
| 1926 | - |
|
| 1927 | - /** |
|
| 1928 | - * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 1929 | - * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 1930 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 1931 | - * |
|
| 1932 | - * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 1933 | - * @param string $relationName eg 'Events','Question',etc. |
|
| 1934 | - * an attendee to a group, you also want to specify which role they |
|
| 1935 | - * will have in that group. So you would use this parameter to |
|
| 1936 | - * specify array('role-column-name'=>'role-id') |
|
| 1937 | - * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 1938 | - * allow you to further constrict the relation to being added. |
|
| 1939 | - * However, keep in mind that the columns (keys) given must match a |
|
| 1940 | - * column on the JOIN table and currently only the HABTM models |
|
| 1941 | - * accept these additional conditions. Also remember that if an |
|
| 1942 | - * exact match isn't found for these extra cols/val pairs, then a |
|
| 1943 | - * NEW row is created in the join table. |
|
| 1944 | - * @param null $cache_id |
|
| 1945 | - * @throws EE_Error |
|
| 1946 | - * @return EE_Base_Class the object the relation was added to |
|
| 1947 | - */ |
|
| 1948 | - public function _add_relation_to( |
|
| 1949 | - $otherObjectModelObjectOrID, |
|
| 1950 | - $relationName, |
|
| 1951 | - $extra_join_model_fields_n_values = array(), |
|
| 1952 | - $cache_id = null |
|
| 1953 | - ) { |
|
| 1954 | - //if this thing exists in the DB, save the relation to the DB |
|
| 1955 | - if ($this->ID()) { |
|
| 1956 | - $otherObject = $this->get_model() |
|
| 1957 | - ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 1958 | - $extra_join_model_fields_n_values); |
|
| 1959 | - //clear cache so future get_many_related and get_first_related() return new results. |
|
| 1960 | - $this->clear_cache($relationName, $otherObject, true); |
|
| 1961 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 1962 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1963 | - } |
|
| 1964 | - } else { |
|
| 1965 | - //this thing doesn't exist in the DB, so just cache it |
|
| 1966 | - if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1967 | - throw new EE_Error(sprintf( |
|
| 1968 | - __('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', |
|
| 1969 | - 'event_espresso'), |
|
| 1970 | - $otherObjectModelObjectOrID, |
|
| 1971 | - get_class($this) |
|
| 1972 | - )); |
|
| 1973 | - } else { |
|
| 1974 | - $otherObject = $otherObjectModelObjectOrID; |
|
| 1975 | - } |
|
| 1976 | - $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1977 | - } |
|
| 1978 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 1979 | - //fix the reciprocal relation too |
|
| 1980 | - if ($otherObject->ID()) { |
|
| 1981 | - //its saved so assumed relations exist in the DB, so we can just |
|
| 1982 | - //clear the cache so future queries use the updated info in the DB |
|
| 1983 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1984 | - } else { |
|
| 1985 | - //it's not saved, so it caches relations like this |
|
| 1986 | - $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1987 | - } |
|
| 1988 | - } |
|
| 1989 | - return $otherObject; |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 1996 | - * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 1997 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 1998 | - * from the cache |
|
| 1999 | - * |
|
| 2000 | - * @param mixed $otherObjectModelObjectOrID |
|
| 2001 | - * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 2002 | - * to the DB yet |
|
| 2003 | - * @param string $relationName |
|
| 2004 | - * @param array $where_query |
|
| 2005 | - * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2006 | - * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2007 | - * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2008 | - * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2009 | - * created in the join table. |
|
| 2010 | - * @return EE_Base_Class the relation was removed from |
|
| 2011 | - * @throws \EE_Error |
|
| 2012 | - */ |
|
| 2013 | - public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2014 | - { |
|
| 2015 | - if ($this->ID()) { |
|
| 2016 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2017 | - $otherObject = $this->get_model() |
|
| 2018 | - ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2019 | - $where_query); |
|
| 2020 | - $this->clear_cache($relationName, $otherObject); |
|
| 2021 | - } else { |
|
| 2022 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2023 | - $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2024 | - } |
|
| 2025 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 2026 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2027 | - } |
|
| 2028 | - return $otherObject; |
|
| 2029 | - } |
|
| 2030 | - |
|
| 2031 | - |
|
| 2032 | - |
|
| 2033 | - /** |
|
| 2034 | - * Removes ALL the related things for the $relationName. |
|
| 2035 | - * |
|
| 2036 | - * @param string $relationName |
|
| 2037 | - * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2038 | - * @return EE_Base_Class |
|
| 2039 | - * @throws \EE_Error |
|
| 2040 | - */ |
|
| 2041 | - public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2042 | - { |
|
| 2043 | - if ($this->ID()) { |
|
| 2044 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2045 | - $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2046 | - $this->clear_cache($relationName, null, true); |
|
| 2047 | - } else { |
|
| 2048 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2049 | - $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2050 | - } |
|
| 2051 | - if (is_array($otherObjects)) { |
|
| 2052 | - foreach ($otherObjects as $otherObject) { |
|
| 2053 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2054 | - } |
|
| 2055 | - } |
|
| 2056 | - return $otherObjects; |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - |
|
| 2060 | - |
|
| 2061 | - /** |
|
| 2062 | - * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2063 | - * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2064 | - * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2065 | - * because we want to get even deleted items etc. |
|
| 2066 | - * |
|
| 2067 | - * @param string $relationName key in the model's _model_relations array |
|
| 2068 | - * @param array $query_params like EEM_Base::get_all |
|
| 2069 | - * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2070 | - * @throws \EE_Error |
|
| 2071 | - * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2072 | - * you want IDs |
|
| 2073 | - */ |
|
| 2074 | - public function get_many_related($relationName, $query_params = array()) |
|
| 2075 | - { |
|
| 2076 | - if ($this->ID()) { |
|
| 2077 | - //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2078 | - //if there are query parameters, forget about caching the related model objects. |
|
| 2079 | - if ($query_params) { |
|
| 2080 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2081 | - } else { |
|
| 2082 | - //did we already cache the result of this query? |
|
| 2083 | - $cached_results = $this->get_all_from_cache($relationName); |
|
| 2084 | - if ( ! $cached_results) { |
|
| 2085 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2086 | - //if no query parameters were passed, then we got all the related model objects |
|
| 2087 | - //for that relation. We can cache them then. |
|
| 2088 | - foreach ($related_model_objects as $related_model_object) { |
|
| 2089 | - $this->cache($relationName, $related_model_object); |
|
| 2090 | - } |
|
| 2091 | - } else { |
|
| 2092 | - $related_model_objects = $cached_results; |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - } else { |
|
| 2096 | - //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2097 | - $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2098 | - } |
|
| 2099 | - return $related_model_objects; |
|
| 2100 | - } |
|
| 2101 | - |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2106 | - * unless otherwise specified in the $query_params |
|
| 2107 | - * |
|
| 2108 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2109 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2110 | - * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2111 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2112 | - * that by the setting $distinct to TRUE; |
|
| 2113 | - * @return int |
|
| 2114 | - */ |
|
| 2115 | - public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2116 | - { |
|
| 2117 | - return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - |
|
| 2121 | - |
|
| 2122 | - /** |
|
| 2123 | - * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2124 | - * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2125 | - * |
|
| 2126 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2127 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2128 | - * @param string $field_to_sum name of field to count by. |
|
| 2129 | - * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2130 | - * change it) |
|
| 2131 | - * @return int |
|
| 2132 | - */ |
|
| 2133 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2134 | - { |
|
| 2135 | - return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - |
|
| 2139 | - |
|
| 2140 | - /** |
|
| 2141 | - * Gets the first (ie, one) related model object of the specified type. |
|
| 2142 | - * |
|
| 2143 | - * @param string $relationName key in the model's _model_relations array |
|
| 2144 | - * @param array $query_params like EEM_Base::get_all |
|
| 2145 | - * @return EE_Base_Class (not an array, a single object) |
|
| 2146 | - * @throws \EE_Error |
|
| 2147 | - */ |
|
| 2148 | - public function get_first_related($relationName, $query_params = array()) |
|
| 2149 | - { |
|
| 2150 | - if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2151 | - //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2152 | - //also make sure we're not caching the result of get_first_related |
|
| 2153 | - //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2154 | - if ($query_params |
|
| 2155 | - || ! $this->get_model()->related_settings_for($relationName) |
|
| 2156 | - instanceof |
|
| 2157 | - EE_Belongs_To_Relation |
|
| 2158 | - ) { |
|
| 2159 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2160 | - } else { |
|
| 2161 | - //first, check if we've already cached the result of this query |
|
| 2162 | - $cached_result = $this->get_one_from_cache($relationName); |
|
| 2163 | - if ( ! $cached_result) { |
|
| 2164 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2165 | - $this->cache($relationName, $related_model_object); |
|
| 2166 | - } else { |
|
| 2167 | - $related_model_object = $cached_result; |
|
| 2168 | - } |
|
| 2169 | - } |
|
| 2170 | - } else { |
|
| 2171 | - $related_model_object = null; |
|
| 2172 | - //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2173 | - if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2174 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2175 | - } |
|
| 2176 | - //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 |
|
| 2177 | - if ( ! $related_model_object) { |
|
| 2178 | - $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2179 | - } |
|
| 2180 | - } |
|
| 2181 | - return $related_model_object; |
|
| 2182 | - } |
|
| 2183 | - |
|
| 2184 | - |
|
| 2185 | - |
|
| 2186 | - /** |
|
| 2187 | - * Does a delete on all related objects of type $relationName and removes |
|
| 2188 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2189 | - * of blocking related model objects) does nothing. If the related model objects are |
|
| 2190 | - * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2191 | - * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2192 | - * |
|
| 2193 | - * @param string $relationName |
|
| 2194 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2195 | - * @return int how many deleted |
|
| 2196 | - * @throws \EE_Error |
|
| 2197 | - */ |
|
| 2198 | - public function delete_related($relationName, $query_params = array()) |
|
| 2199 | - { |
|
| 2200 | - if ($this->ID()) { |
|
| 2201 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2202 | - } else { |
|
| 2203 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2204 | - $this->clear_cache($relationName, null, true); |
|
| 2205 | - } |
|
| 2206 | - return $count; |
|
| 2207 | - } |
|
| 2208 | - |
|
| 2209 | - |
|
| 2210 | - |
|
| 2211 | - /** |
|
| 2212 | - * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2213 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2214 | - * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2215 | - * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2216 | - * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2217 | - * |
|
| 2218 | - * @param string $relationName |
|
| 2219 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2220 | - * @return int how many deleted (including those soft deleted) |
|
| 2221 | - * @throws \EE_Error |
|
| 2222 | - */ |
|
| 2223 | - public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2224 | - { |
|
| 2225 | - if ($this->ID()) { |
|
| 2226 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2227 | - } else { |
|
| 2228 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2229 | - } |
|
| 2230 | - $this->clear_cache($relationName, null, true); |
|
| 2231 | - return $count; |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - |
|
| 2235 | - |
|
| 2236 | - /** |
|
| 2237 | - * is_set |
|
| 2238 | - * Just a simple utility function children can use for checking if property exists |
|
| 2239 | - * |
|
| 2240 | - * @access public |
|
| 2241 | - * @param string $field_name property to check |
|
| 2242 | - * @return bool TRUE if existing,FALSE if not. |
|
| 2243 | - */ |
|
| 2244 | - public function is_set($field_name) |
|
| 2245 | - { |
|
| 2246 | - return isset($this->_fields[$field_name]); |
|
| 2247 | - } |
|
| 2248 | - |
|
| 2249 | - |
|
| 2250 | - |
|
| 2251 | - /** |
|
| 2252 | - * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2253 | - * EE_Error exception if they don't |
|
| 2254 | - * |
|
| 2255 | - * @param mixed (string|array) $properties properties to check |
|
| 2256 | - * @throws EE_Error |
|
| 2257 | - * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2258 | - */ |
|
| 2259 | - protected function _property_exists($properties) |
|
| 2260 | - { |
|
| 2261 | - foreach ((array)$properties as $property_name) { |
|
| 2262 | - //first make sure this property exists |
|
| 2263 | - if ( ! $this->_fields[$property_name]) { |
|
| 2264 | - throw new EE_Error( |
|
| 2265 | - sprintf( |
|
| 2266 | - __( |
|
| 2267 | - 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2268 | - 'event_espresso' |
|
| 2269 | - ), |
|
| 2270 | - $property_name |
|
| 2271 | - ) |
|
| 2272 | - ); |
|
| 2273 | - } |
|
| 2274 | - } |
|
| 2275 | - return true; |
|
| 2276 | - } |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - |
|
| 2280 | - /** |
|
| 2281 | - * This simply returns an array of model fields for this object |
|
| 2282 | - * |
|
| 2283 | - * @return array |
|
| 2284 | - * @throws \EE_Error |
|
| 2285 | - */ |
|
| 2286 | - public function model_field_array() |
|
| 2287 | - { |
|
| 2288 | - $fields = $this->get_model()->field_settings(false); |
|
| 2289 | - $properties = array(); |
|
| 2290 | - //remove prepended underscore |
|
| 2291 | - foreach ($fields as $field_name => $settings) { |
|
| 2292 | - $properties[$field_name] = $this->get($field_name); |
|
| 2293 | - } |
|
| 2294 | - return $properties; |
|
| 2295 | - } |
|
| 2296 | - |
|
| 2297 | - |
|
| 2298 | - |
|
| 2299 | - /** |
|
| 2300 | - * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2301 | - * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2302 | - * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2303 | - * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2304 | - * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2305 | - * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2306 | - * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2307 | - * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2308 | - * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2309 | - * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2310 | - * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2311 | - * return $previousReturnValue.$returnString; |
|
| 2312 | - * } |
|
| 2313 | - * require('EE_Answer.class.php'); |
|
| 2314 | - * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2315 | - * echo $answer->my_callback('monkeys',100); |
|
| 2316 | - * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2317 | - * |
|
| 2318 | - * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2319 | - * @param array $args array of original arguments passed to the function |
|
| 2320 | - * @throws EE_Error |
|
| 2321 | - * @return mixed whatever the plugin which calls add_filter decides |
|
| 2322 | - */ |
|
| 2323 | - public function __call($methodName, $args) |
|
| 2324 | - { |
|
| 2325 | - $className = get_class($this); |
|
| 2326 | - $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2327 | - if ( ! has_filter($tagName)) { |
|
| 2328 | - throw new EE_Error( |
|
| 2329 | - sprintf( |
|
| 2330 | - __( |
|
| 2331 | - "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;}", |
|
| 2332 | - "event_espresso" |
|
| 2333 | - ), |
|
| 2334 | - $methodName, |
|
| 2335 | - $className, |
|
| 2336 | - $tagName |
|
| 2337 | - ) |
|
| 2338 | - ); |
|
| 2339 | - } |
|
| 2340 | - return apply_filters($tagName, null, $this, $args); |
|
| 2341 | - } |
|
| 2342 | - |
|
| 2343 | - |
|
| 2344 | - |
|
| 2345 | - /** |
|
| 2346 | - * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2347 | - * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2348 | - * |
|
| 2349 | - * @param string $meta_key |
|
| 2350 | - * @param string $meta_value |
|
| 2351 | - * @param string $previous_value |
|
| 2352 | - * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2353 | - * @throws \EE_Error |
|
| 2354 | - * NOTE: if the values haven't changed, returns 0 |
|
| 2355 | - */ |
|
| 2356 | - public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2357 | - { |
|
| 2358 | - $query_params = array( |
|
| 2359 | - array( |
|
| 2360 | - 'EXM_key' => $meta_key, |
|
| 2361 | - 'OBJ_ID' => $this->ID(), |
|
| 2362 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2363 | - ), |
|
| 2364 | - ); |
|
| 2365 | - if ($previous_value !== null) { |
|
| 2366 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2367 | - } |
|
| 2368 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2369 | - if ( ! $existing_rows_like_that) { |
|
| 2370 | - return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2371 | - } else { |
|
| 2372 | - foreach ($existing_rows_like_that as $existing_row) { |
|
| 2373 | - $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2374 | - } |
|
| 2375 | - return count($existing_rows_like_that); |
|
| 2376 | - } |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2383 | - * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2384 | - * extra meta row was entered, false if not |
|
| 2385 | - * |
|
| 2386 | - * @param string $meta_key |
|
| 2387 | - * @param string $meta_value |
|
| 2388 | - * @param boolean $unique |
|
| 2389 | - * @return boolean |
|
| 2390 | - * @throws \EE_Error |
|
| 2391 | - */ |
|
| 2392 | - public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2393 | - { |
|
| 2394 | - if ($unique) { |
|
| 2395 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2396 | - array( |
|
| 2397 | - array( |
|
| 2398 | - 'EXM_key' => $meta_key, |
|
| 2399 | - 'OBJ_ID' => $this->ID(), |
|
| 2400 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2401 | - ), |
|
| 2402 | - ) |
|
| 2403 | - ); |
|
| 2404 | - if ($existing_extra_meta) { |
|
| 2405 | - return false; |
|
| 2406 | - } |
|
| 2407 | - } |
|
| 2408 | - $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2409 | - array( |
|
| 2410 | - 'EXM_key' => $meta_key, |
|
| 2411 | - 'EXM_value' => $meta_value, |
|
| 2412 | - 'OBJ_ID' => $this->ID(), |
|
| 2413 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2414 | - ) |
|
| 2415 | - ); |
|
| 2416 | - $new_extra_meta->save(); |
|
| 2417 | - return true; |
|
| 2418 | - } |
|
| 2419 | - |
|
| 2420 | - |
|
| 2421 | - |
|
| 2422 | - /** |
|
| 2423 | - * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2424 | - * is specified, only deletes extra meta records with that value. |
|
| 2425 | - * |
|
| 2426 | - * @param string $meta_key |
|
| 2427 | - * @param string $meta_value |
|
| 2428 | - * @return int number of extra meta rows deleted |
|
| 2429 | - * @throws \EE_Error |
|
| 2430 | - */ |
|
| 2431 | - public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2432 | - { |
|
| 2433 | - $query_params = array( |
|
| 2434 | - array( |
|
| 2435 | - 'EXM_key' => $meta_key, |
|
| 2436 | - 'OBJ_ID' => $this->ID(), |
|
| 2437 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2438 | - ), |
|
| 2439 | - ); |
|
| 2440 | - if ($meta_value !== null) { |
|
| 2441 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2442 | - } |
|
| 2443 | - return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2444 | - } |
|
| 2445 | - |
|
| 2446 | - |
|
| 2447 | - |
|
| 2448 | - /** |
|
| 2449 | - * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2450 | - * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2451 | - * You can specify $default is case you haven't found the extra meta |
|
| 2452 | - * |
|
| 2453 | - * @param string $meta_key |
|
| 2454 | - * @param boolean $single |
|
| 2455 | - * @param mixed $default if we don't find anything, what should we return? |
|
| 2456 | - * @return mixed single value if $single; array if ! $single |
|
| 2457 | - * @throws \EE_Error |
|
| 2458 | - */ |
|
| 2459 | - public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2460 | - { |
|
| 2461 | - if ($single) { |
|
| 2462 | - $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2463 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2464 | - return $result->value(); |
|
| 2465 | - } else { |
|
| 2466 | - return $default; |
|
| 2467 | - } |
|
| 2468 | - } else { |
|
| 2469 | - $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2470 | - if ($results) { |
|
| 2471 | - $values = array(); |
|
| 2472 | - foreach ($results as $result) { |
|
| 2473 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2474 | - $values[$result->ID()] = $result->value(); |
|
| 2475 | - } |
|
| 2476 | - } |
|
| 2477 | - return $values; |
|
| 2478 | - } else { |
|
| 2479 | - return $default; |
|
| 2480 | - } |
|
| 2481 | - } |
|
| 2482 | - } |
|
| 2483 | - |
|
| 2484 | - |
|
| 2485 | - |
|
| 2486 | - /** |
|
| 2487 | - * Returns a simple array of all the extra meta associated with this model object. |
|
| 2488 | - * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2489 | - * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2490 | - * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2491 | - * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2492 | - * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2493 | - * finally the extra meta's value as each sub-value. (eg |
|
| 2494 | - * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2495 | - * |
|
| 2496 | - * @param boolean $one_of_each_key |
|
| 2497 | - * @return array |
|
| 2498 | - * @throws \EE_Error |
|
| 2499 | - */ |
|
| 2500 | - public function all_extra_meta_array($one_of_each_key = true) |
|
| 2501 | - { |
|
| 2502 | - $return_array = array(); |
|
| 2503 | - if ($one_of_each_key) { |
|
| 2504 | - $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2505 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2506 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2507 | - $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2508 | - } |
|
| 2509 | - } |
|
| 2510 | - } else { |
|
| 2511 | - $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2512 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2513 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2514 | - if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2515 | - $return_array[$extra_meta_obj->key()] = array(); |
|
| 2516 | - } |
|
| 2517 | - $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - } |
|
| 2521 | - return $return_array; |
|
| 2522 | - } |
|
| 2523 | - |
|
| 2524 | - |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2528 | - * |
|
| 2529 | - * @return string |
|
| 2530 | - * @throws \EE_Error |
|
| 2531 | - */ |
|
| 2532 | - public function name() |
|
| 2533 | - { |
|
| 2534 | - //find a field that's not a text field |
|
| 2535 | - $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2536 | - if ($field_we_can_use) { |
|
| 2537 | - return $this->get($field_we_can_use->get_name()); |
|
| 2538 | - } else { |
|
| 2539 | - $first_few_properties = $this->model_field_array(); |
|
| 2540 | - $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2541 | - $name_parts = array(); |
|
| 2542 | - foreach ($first_few_properties as $name => $value) { |
|
| 2543 | - $name_parts[] = "$name:$value"; |
|
| 2544 | - } |
|
| 2545 | - return implode(",", $name_parts); |
|
| 2546 | - } |
|
| 2547 | - } |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - |
|
| 2551 | - /** |
|
| 2552 | - * in_entity_map |
|
| 2553 | - * Checks if this model object has been proven to already be in the entity map |
|
| 2554 | - * |
|
| 2555 | - * @return boolean |
|
| 2556 | - * @throws \EE_Error |
|
| 2557 | - */ |
|
| 2558 | - public function in_entity_map() |
|
| 2559 | - { |
|
| 2560 | - if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2561 | - //well, if we looked, did we find it in the entity map? |
|
| 2562 | - return true; |
|
| 2563 | - } else { |
|
| 2564 | - return false; |
|
| 2565 | - } |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * refresh_from_db |
|
| 2572 | - * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2573 | - * |
|
| 2574 | - * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2575 | - * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2576 | - */ |
|
| 2577 | - public function refresh_from_db() |
|
| 2578 | - { |
|
| 2579 | - if ($this->ID() && $this->in_entity_map()) { |
|
| 2580 | - $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2581 | - } else { |
|
| 2582 | - //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2583 | - //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2584 | - //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2585 | - //absolutely nothing in it for this ID |
|
| 2586 | - if (WP_DEBUG) { |
|
| 2587 | - throw new EE_Error( |
|
| 2588 | - sprintf( |
|
| 2589 | - __('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.', |
|
| 2590 | - 'event_espresso'), |
|
| 2591 | - $this->ID(), |
|
| 2592 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2593 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2594 | - ) |
|
| 2595 | - ); |
|
| 2596 | - } |
|
| 2597 | - } |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - /** |
|
| 2603 | - * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2604 | - * (probably a bad assumption they have made, oh well) |
|
| 2605 | - * |
|
| 2606 | - * @return string |
|
| 2607 | - */ |
|
| 2608 | - public function __toString() |
|
| 2609 | - { |
|
| 2610 | - try { |
|
| 2611 | - return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2612 | - } catch (Exception $e) { |
|
| 2613 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2614 | - return ''; |
|
| 2615 | - } |
|
| 2616 | - } |
|
| 2617 | - |
|
| 2618 | - |
|
| 2619 | - |
|
| 2620 | - /** |
|
| 2621 | - * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2622 | - * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2623 | - * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2624 | - * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2625 | - * Instead, those related model objects should be directly serialized and stored. |
|
| 2626 | - * Eg, the following won't work: |
|
| 2627 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2628 | - * $att = $reg->attendee(); |
|
| 2629 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2630 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2631 | - * //END REQUEST |
|
| 2632 | - * //START NEXT REQUEST |
|
| 2633 | - * $reg = get_option( 'my_option' ); |
|
| 2634 | - * $reg->attendee()->save(); |
|
| 2635 | - * And would need to be replace with: |
|
| 2636 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2637 | - * $att = $reg->attendee(); |
|
| 2638 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2639 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2640 | - * //END REQUEST |
|
| 2641 | - * //START NEXT REQUEST |
|
| 2642 | - * $att = get_option( 'my_option' ); |
|
| 2643 | - * $att->save(); |
|
| 2644 | - * |
|
| 2645 | - * @return array |
|
| 2646 | - * @throws \EE_Error |
|
| 2647 | - */ |
|
| 2648 | - public function __sleep() |
|
| 2649 | - { |
|
| 2650 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2651 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2652 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2653 | - if ( |
|
| 2654 | - $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2655 | - && $this->get_one_from_cache($relation_name)->ID() |
|
| 2656 | - ) { |
|
| 2657 | - $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2658 | - } |
|
| 2659 | - } |
|
| 2660 | - } |
|
| 2661 | - $this->_props_n_values_provided_in_constructor = array(); |
|
| 2662 | - return array_keys(get_object_vars($this)); |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - |
|
| 2667 | - /** |
|
| 2668 | - * restore _props_n_values_provided_in_constructor |
|
| 2669 | - * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2670 | - * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2671 | - * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2672 | - */ |
|
| 2673 | - public function __wakeup() |
|
| 2674 | - { |
|
| 2675 | - $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2676 | - } |
|
| 28 | + /** |
|
| 29 | + * This is an array of the original properties and values provided during construction |
|
| 30 | + * of this model object. (keys are model field names, values are their values). |
|
| 31 | + * This list is important to remember so that when we are merging data from the db, we know |
|
| 32 | + * which values to override and which to not override. |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $_props_n_values_provided_in_constructor; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Timezone |
|
| 40 | + * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 41 | + * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 42 | + * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 43 | + * access to it. |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $_timezone; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * date format |
|
| 53 | + * pattern or format for displaying dates |
|
| 54 | + * |
|
| 55 | + * @var string $_dt_frmt |
|
| 56 | + */ |
|
| 57 | + protected $_dt_frmt; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * time format |
|
| 63 | + * pattern or format for displaying time |
|
| 64 | + * |
|
| 65 | + * @var string $_tm_frmt |
|
| 66 | + */ |
|
| 67 | + protected $_tm_frmt; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 73 | + * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 74 | + * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 75 | + * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 76 | + * |
|
| 77 | + * @var array |
|
| 78 | + */ |
|
| 79 | + protected $_cached_properties = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 83 | + * single |
|
| 84 | + * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 85 | + * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 86 | + * all others have an array) |
|
| 87 | + * |
|
| 88 | + * @var array |
|
| 89 | + */ |
|
| 90 | + protected $_model_relations = array(); |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 94 | + * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 95 | + * |
|
| 96 | + * @var array |
|
| 97 | + */ |
|
| 98 | + protected $_fields = array(); |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 102 | + * For example, we might create model objects intended to only be used for the duration |
|
| 103 | + * of this request and to be thrown away, and if they were accidentally saved |
|
| 104 | + * it would be a bug. |
|
| 105 | + */ |
|
| 106 | + protected $_allow_persist = true; |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 112 | + * play nice |
|
| 113 | + * |
|
| 114 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 115 | + * layer of the model's _fields array, (eg, EVT_ID, |
|
| 116 | + * TXN_amount, QST_name, etc) and values are their values |
|
| 117 | + * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 118 | + * corresponding db model or not. |
|
| 119 | + * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 120 | + * be in when instantiating a EE_Base_Class object. |
|
| 121 | + * @param array $date_formats An array of date formats to set on construct where first |
|
| 122 | + * value is the date_format and second value is the time |
|
| 123 | + * format. |
|
| 124 | + * @throws EE_Error |
|
| 125 | + */ |
|
| 126 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
| 127 | + { |
|
| 128 | + $className = get_class($this); |
|
| 129 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 130 | + $model = $this->get_model(); |
|
| 131 | + $model_fields = $model->field_settings(false); |
|
| 132 | + // ensure $fieldValues is an array |
|
| 133 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 134 | + // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 135 | + // verify client code has not passed any invalid field names |
|
| 136 | + foreach ($fieldValues as $field_name => $field_value) { |
|
| 137 | + if ( ! isset($model_fields[$field_name])) { |
|
| 138 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 139 | + "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 143 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 144 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 145 | + list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 146 | + } else { |
|
| 147 | + //set default formats for date and time |
|
| 148 | + $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 149 | + $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 150 | + } |
|
| 151 | + //if db model is instantiating |
|
| 152 | + if ($bydb) { |
|
| 153 | + //client code has indicated these field values are from the database |
|
| 154 | + foreach ($model_fields as $fieldName => $field) { |
|
| 155 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 156 | + } |
|
| 157 | + } else { |
|
| 158 | + //we're constructing a brand |
|
| 159 | + //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 160 | + foreach ($model_fields as $fieldName => $field) { |
|
| 161 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + //remember what values were passed to this constructor |
|
| 165 | + $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 166 | + //remember in entity mapper |
|
| 167 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 168 | + $model->add_to_entity_map($this); |
|
| 169 | + } |
|
| 170 | + //setup all the relations |
|
| 171 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 172 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 173 | + $this->_model_relations[$relation_name] = null; |
|
| 174 | + } else { |
|
| 175 | + $this->_model_relations[$relation_name] = array(); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + /** |
|
| 179 | + * Action done at the end of each model object construction |
|
| 180 | + * |
|
| 181 | + * @param EE_Base_Class $this the model object just created |
|
| 182 | + */ |
|
| 183 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 190 | + * |
|
| 191 | + * @return boolean |
|
| 192 | + */ |
|
| 193 | + public function allow_persist() |
|
| 194 | + { |
|
| 195 | + return $this->_allow_persist; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 202 | + * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 203 | + * you got new information that somehow made you change your mind. |
|
| 204 | + * |
|
| 205 | + * @param boolean $allow_persist |
|
| 206 | + * @return boolean |
|
| 207 | + */ |
|
| 208 | + public function set_allow_persist($allow_persist) |
|
| 209 | + { |
|
| 210 | + return $this->_allow_persist = $allow_persist; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Gets the field's original value when this object was constructed during this request. |
|
| 217 | + * This can be helpful when determining if a model object has changed or not |
|
| 218 | + * |
|
| 219 | + * @param string $field_name |
|
| 220 | + * @return mixed|null |
|
| 221 | + * @throws \EE_Error |
|
| 222 | + */ |
|
| 223 | + public function get_original($field_name) |
|
| 224 | + { |
|
| 225 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 226 | + && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 227 | + ) { |
|
| 228 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 229 | + } else { |
|
| 230 | + return null; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param EE_Base_Class $obj |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_class($obj) |
|
| 241 | + { |
|
| 242 | + return get_class($obj); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Overrides parent because parent expects old models. |
|
| 249 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 250 | + * |
|
| 251 | + * @param string $field_name |
|
| 252 | + * @param mixed $field_value |
|
| 253 | + * @param bool $use_default |
|
| 254 | + * @throws \EE_Error |
|
| 255 | + */ |
|
| 256 | + public function set($field_name, $field_value, $use_default = false) |
|
| 257 | + { |
|
| 258 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 259 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 260 | + // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 261 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 262 | + $field_obj->set_timezone($this->_timezone); |
|
| 263 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 264 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 265 | + } |
|
| 266 | + $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 267 | + //should the value be null? |
|
| 268 | + if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 269 | + $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 270 | + /** |
|
| 271 | + * To save having to refactor all the models, if a default value is used for a |
|
| 272 | + * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 273 | + * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 274 | + * object. |
|
| 275 | + * |
|
| 276 | + * @since 4.6.10+ |
|
| 277 | + */ |
|
| 278 | + if ( |
|
| 279 | + $field_obj instanceof EE_Datetime_Field |
|
| 280 | + && $this->_fields[$field_name] !== null |
|
| 281 | + && ! $this->_fields[$field_name] instanceof DateTime |
|
| 282 | + ) { |
|
| 283 | + empty($this->_fields[$field_name]) |
|
| 284 | + ? $this->set($field_name, time()) |
|
| 285 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
| 286 | + } |
|
| 287 | + } else { |
|
| 288 | + $this->_fields[$field_name] = $holder_of_value; |
|
| 289 | + } |
|
| 290 | + //if we're not in the constructor... |
|
| 291 | + //now check if what we set was a primary key |
|
| 292 | + if ( |
|
| 293 | + //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 294 | + $this->_props_n_values_provided_in_constructor |
|
| 295 | + && $field_value |
|
| 296 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 297 | + ) { |
|
| 298 | + //if so, we want all this object's fields to be filled either with |
|
| 299 | + //what we've explicitly set on this model |
|
| 300 | + //or what we have in the db |
|
| 301 | + // echo "setting primary key!"; |
|
| 302 | + $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 303 | + $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 304 | + foreach ($fields_on_model as $field_obj) { |
|
| 305 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 306 | + && $field_obj->get_name() !== $field_name |
|
| 307 | + ) { |
|
| 308 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + //oh this model object has an ID? well make sure its in the entity mapper |
|
| 312 | + $this->get_model()->add_to_entity_map($this); |
|
| 313 | + } |
|
| 314 | + //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 315 | + $this->_clear_cached_property($field_name); |
|
| 316 | + } else { |
|
| 317 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 318 | + "event_espresso"), $field_name)); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * This sets the field value on the db column if it exists for the given $column_name or |
|
| 326 | + * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 327 | + * |
|
| 328 | + * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 329 | + * @param string $field_name Must be the exact column name. |
|
| 330 | + * @param mixed $field_value The value to set. |
|
| 331 | + * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 332 | + * @throws \EE_Error |
|
| 333 | + */ |
|
| 334 | + public function set_field_or_extra_meta($field_name, $field_value) |
|
| 335 | + { |
|
| 336 | + if ($this->get_model()->has_field($field_name)) { |
|
| 337 | + $this->set($field_name, $field_value); |
|
| 338 | + return true; |
|
| 339 | + } else { |
|
| 340 | + //ensure this object is saved first so that extra meta can be properly related. |
|
| 341 | + $this->save(); |
|
| 342 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * This retrieves the value of the db column set on this class or if that's not present |
|
| 350 | + * it will attempt to retrieve from extra_meta if found. |
|
| 351 | + * Example Usage: |
|
| 352 | + * Via EE_Message child class: |
|
| 353 | + * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 354 | + * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 355 | + * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 356 | + * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 357 | + * value for those extra fields dynamically via the EE_message object. |
|
| 358 | + * |
|
| 359 | + * @param string $field_name expecting the fully qualified field name. |
|
| 360 | + * @return mixed|null value for the field if found. null if not found. |
|
| 361 | + * @throws \EE_Error |
|
| 362 | + */ |
|
| 363 | + public function get_field_or_extra_meta($field_name) |
|
| 364 | + { |
|
| 365 | + if ($this->get_model()->has_field($field_name)) { |
|
| 366 | + $column_value = $this->get($field_name); |
|
| 367 | + } else { |
|
| 368 | + //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 369 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 370 | + } |
|
| 371 | + return $column_value; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 378 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 379 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 380 | + * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 381 | + * |
|
| 382 | + * @access public |
|
| 383 | + * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 384 | + * @return void |
|
| 385 | + * @throws \EE_Error |
|
| 386 | + */ |
|
| 387 | + public function set_timezone($timezone = '') |
|
| 388 | + { |
|
| 389 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 390 | + //make sure we clear all cached properties because they won't be relevant now |
|
| 391 | + $this->_clear_cached_properties(); |
|
| 392 | + //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 393 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 394 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 395 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 396 | + $field_obj->set_timezone($this->_timezone); |
|
| 397 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 398 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * This just returns whatever is set for the current timezone. |
|
| 408 | + * |
|
| 409 | + * @access public |
|
| 410 | + * @return string timezone string |
|
| 411 | + */ |
|
| 412 | + public function get_timezone() |
|
| 413 | + { |
|
| 414 | + return $this->_timezone; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 421 | + * internally instead of wp set date format options |
|
| 422 | + * |
|
| 423 | + * @since 4.6 |
|
| 424 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 425 | + */ |
|
| 426 | + public function set_date_format($format) |
|
| 427 | + { |
|
| 428 | + $this->_dt_frmt = $format; |
|
| 429 | + //clear cached_properties because they won't be relevant now. |
|
| 430 | + $this->_clear_cached_properties(); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 437 | + * class internally instead of wp set time format options. |
|
| 438 | + * |
|
| 439 | + * @since 4.6 |
|
| 440 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 441 | + */ |
|
| 442 | + public function set_time_format($format) |
|
| 443 | + { |
|
| 444 | + $this->_tm_frmt = $format; |
|
| 445 | + //clear cached_properties because they won't be relevant now. |
|
| 446 | + $this->_clear_cached_properties(); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * This returns the current internal set format for the date and time formats. |
|
| 453 | + * |
|
| 454 | + * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 455 | + * where the first value is the date format and the second value is the time format. |
|
| 456 | + * @return mixed string|array |
|
| 457 | + */ |
|
| 458 | + public function get_format($full = true) |
|
| 459 | + { |
|
| 460 | + return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * cache |
|
| 467 | + * stores the passed model object on the current model object. |
|
| 468 | + * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 469 | + * |
|
| 470 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 471 | + * 'Registration' associated with this model object |
|
| 472 | + * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 473 | + * that could be a payment or a registration) |
|
| 474 | + * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 475 | + * items which will be stored in an array on this object |
|
| 476 | + * @throws EE_Error |
|
| 477 | + * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 478 | + * related thing, no array) |
|
| 479 | + */ |
|
| 480 | + public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 481 | + { |
|
| 482 | + // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 483 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 484 | + return false; |
|
| 485 | + } |
|
| 486 | + // also get "how" the object is related, or throw an error |
|
| 487 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 488 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 489 | + $relationName, get_class($this))); |
|
| 490 | + } |
|
| 491 | + // how many things are related ? |
|
| 492 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 493 | + // 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 |
|
| 494 | + // so for these model objects just set it to be cached |
|
| 495 | + $this->_model_relations[$relationName] = $object_to_cache; |
|
| 496 | + $return = true; |
|
| 497 | + } else { |
|
| 498 | + // 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. |
|
| 499 | + // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 500 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 501 | + // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 502 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 503 | + ? array($this->_model_relations[$relationName]) : array(); |
|
| 504 | + } |
|
| 505 | + // first check for a cache_id which is normally empty |
|
| 506 | + if ( ! empty($cache_id)) { |
|
| 507 | + // 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 |
|
| 508 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 509 | + $return = $cache_id; |
|
| 510 | + } elseif ($object_to_cache->ID()) { |
|
| 511 | + // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 512 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 513 | + $return = $object_to_cache->ID(); |
|
| 514 | + } else { |
|
| 515 | + // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 516 | + $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 517 | + // move the internal pointer to the end of the array |
|
| 518 | + end($this->_model_relations[$relationName]); |
|
| 519 | + // and grab the key so that we can return it |
|
| 520 | + $return = key($this->_model_relations[$relationName]); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + return $return; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * For adding an item to the cached_properties property. |
|
| 530 | + * |
|
| 531 | + * @access protected |
|
| 532 | + * @param string $fieldname the property item the corresponding value is for. |
|
| 533 | + * @param mixed $value The value we are caching. |
|
| 534 | + * @param string|null $cache_type |
|
| 535 | + * @return void |
|
| 536 | + * @throws \EE_Error |
|
| 537 | + */ |
|
| 538 | + protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 539 | + { |
|
| 540 | + //first make sure this property exists |
|
| 541 | + $this->get_model()->field_settings_for($fieldname); |
|
| 542 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 543 | + $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 550 | + * This also SETS the cache if we return the actual property! |
|
| 551 | + * |
|
| 552 | + * @param string $fieldname the name of the property we're trying to retrieve |
|
| 553 | + * @param bool $pretty |
|
| 554 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 555 | + * (in cases where the same property may be used for different outputs |
|
| 556 | + * - i.e. datetime, money etc.) |
|
| 557 | + * It can also accept certain pre-defined "schema" strings |
|
| 558 | + * to define how to output the property. |
|
| 559 | + * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 560 | + * @return mixed whatever the value for the property is we're retrieving |
|
| 561 | + * @throws \EE_Error |
|
| 562 | + */ |
|
| 563 | + protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 564 | + { |
|
| 565 | + //verify the field exists |
|
| 566 | + $this->get_model()->field_settings_for($fieldname); |
|
| 567 | + $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 568 | + $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 569 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 570 | + return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 571 | + } |
|
| 572 | + $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 573 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 574 | + // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 575 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 576 | + $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 577 | + } |
|
| 578 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 579 | + $this->_fields[$fieldname] = null; |
|
| 580 | + } |
|
| 581 | + $value = $pretty |
|
| 582 | + ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 583 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 584 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 585 | + return $value; |
|
| 586 | + } |
|
| 587 | + return null; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 594 | + * |
|
| 595 | + * @param \EE_Datetime_Field $datetime_field |
|
| 596 | + * @param bool $pretty |
|
| 597 | + * @param null $date_or_time |
|
| 598 | + * @return void |
|
| 599 | + * @throws \EE_Error |
|
| 600 | + */ |
|
| 601 | + protected function _prepare_datetime_field( |
|
| 602 | + EE_Datetime_Field $datetime_field, |
|
| 603 | + $pretty = false, |
|
| 604 | + $date_or_time = null |
|
| 605 | + ) { |
|
| 606 | + $datetime_field->set_timezone($this->_timezone); |
|
| 607 | + $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 608 | + $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 609 | + //set the output returned |
|
| 610 | + switch ($date_or_time) { |
|
| 611 | + case 'D' : |
|
| 612 | + $datetime_field->set_date_time_output('date'); |
|
| 613 | + break; |
|
| 614 | + case 'T' : |
|
| 615 | + $datetime_field->set_date_time_output('time'); |
|
| 616 | + break; |
|
| 617 | + default : |
|
| 618 | + $datetime_field->set_date_time_output(); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * This just takes care of clearing out the cached_properties |
|
| 626 | + * |
|
| 627 | + * @return void |
|
| 628 | + */ |
|
| 629 | + protected function _clear_cached_properties() |
|
| 630 | + { |
|
| 631 | + $this->_cached_properties = array(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * This just clears out ONE property if it exists in the cache |
|
| 638 | + * |
|
| 639 | + * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 640 | + * @return void |
|
| 641 | + */ |
|
| 642 | + protected function _clear_cached_property($property_name) |
|
| 643 | + { |
|
| 644 | + if (isset($this->_cached_properties[$property_name])) { |
|
| 645 | + unset($this->_cached_properties[$property_name]); |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Ensures that this related thing is a model object. |
|
| 653 | + * |
|
| 654 | + * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 655 | + * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 656 | + * @return EE_Base_Class |
|
| 657 | + * @throws \EE_Error |
|
| 658 | + */ |
|
| 659 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 660 | + { |
|
| 661 | + $other_model_instance = self::_get_model_instance_with_name( |
|
| 662 | + self::_get_model_classname($model_name), |
|
| 663 | + $this->_timezone |
|
| 664 | + ); |
|
| 665 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 672 | + * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 673 | + * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 674 | + * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 675 | + * |
|
| 676 | + * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 677 | + * Eg 'Registration' |
|
| 678 | + * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 679 | + * if you intend to use $clear_all = TRUE, or the relation only |
|
| 680 | + * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 681 | + * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 682 | + * this is HasMany or HABTM. |
|
| 683 | + * @throws EE_Error |
|
| 684 | + * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 685 | + * relation from all |
|
| 686 | + */ |
|
| 687 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 688 | + { |
|
| 689 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 690 | + $index_in_cache = ''; |
|
| 691 | + if ( ! $relationship_to_model) { |
|
| 692 | + throw new EE_Error( |
|
| 693 | + sprintf( |
|
| 694 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 695 | + $relationName, |
|
| 696 | + get_class($this) |
|
| 697 | + ) |
|
| 698 | + ); |
|
| 699 | + } |
|
| 700 | + if ($clear_all) { |
|
| 701 | + $obj_removed = true; |
|
| 702 | + $this->_model_relations[$relationName] = null; |
|
| 703 | + } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 704 | + $obj_removed = $this->_model_relations[$relationName]; |
|
| 705 | + $this->_model_relations[$relationName] = null; |
|
| 706 | + } else { |
|
| 707 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 708 | + && $object_to_remove_or_index_into_array->ID() |
|
| 709 | + ) { |
|
| 710 | + $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 711 | + if (is_array($this->_model_relations[$relationName]) |
|
| 712 | + && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 713 | + ) { |
|
| 714 | + $index_found_at = null; |
|
| 715 | + //find this object in the array even though it has a different key |
|
| 716 | + foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 717 | + if ( |
|
| 718 | + $obj instanceof EE_Base_Class |
|
| 719 | + && ( |
|
| 720 | + $obj == $object_to_remove_or_index_into_array |
|
| 721 | + || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 722 | + ) |
|
| 723 | + ) { |
|
| 724 | + $index_found_at = $index; |
|
| 725 | + break; |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + if ($index_found_at) { |
|
| 729 | + $index_in_cache = $index_found_at; |
|
| 730 | + } else { |
|
| 731 | + //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 732 | + //if it wasn't in it to begin with. So we're done |
|
| 733 | + return $object_to_remove_or_index_into_array; |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 737 | + //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 738 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 739 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 740 | + $index_in_cache = $index; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + } else { |
|
| 744 | + $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 745 | + } |
|
| 746 | + //supposedly we've found it. But it could just be that the client code |
|
| 747 | + //provided a bad index/object |
|
| 748 | + if ( |
|
| 749 | + isset( |
|
| 750 | + $this->_model_relations[$relationName], |
|
| 751 | + $this->_model_relations[$relationName][$index_in_cache] |
|
| 752 | + ) |
|
| 753 | + ) { |
|
| 754 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 755 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 756 | + } else { |
|
| 757 | + //that thing was never cached anyways. |
|
| 758 | + $obj_removed = null; |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $obj_removed; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * update_cache_after_object_save |
|
| 768 | + * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 769 | + * obtained after being saved to the db |
|
| 770 | + * |
|
| 771 | + * @param string $relationName - the type of object that is cached |
|
| 772 | + * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 773 | + * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 774 | + * @return boolean TRUE on success, FALSE on fail |
|
| 775 | + * @throws \EE_Error |
|
| 776 | + */ |
|
| 777 | + public function update_cache_after_object_save( |
|
| 778 | + $relationName, |
|
| 779 | + EE_Base_Class $newly_saved_object, |
|
| 780 | + $current_cache_id = '' |
|
| 781 | + ) { |
|
| 782 | + // verify that incoming object is of the correct type |
|
| 783 | + $obj_class = 'EE_' . $relationName; |
|
| 784 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 785 | + /* @type EE_Base_Class $newly_saved_object */ |
|
| 786 | + // now get the type of relation |
|
| 787 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 788 | + // if this is a 1:1 relationship |
|
| 789 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 790 | + // then just replace the cached object with the newly saved object |
|
| 791 | + $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 792 | + return true; |
|
| 793 | + // or if it's some kind of sordid feral polyamorous relationship... |
|
| 794 | + } elseif (is_array($this->_model_relations[$relationName]) |
|
| 795 | + && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 796 | + ) { |
|
| 797 | + // then remove the current cached item |
|
| 798 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 799 | + // and cache the newly saved object using it's new ID |
|
| 800 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 801 | + return true; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 811 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 812 | + * |
|
| 813 | + * @param string $relationName |
|
| 814 | + * @return EE_Base_Class |
|
| 815 | + */ |
|
| 816 | + public function get_one_from_cache($relationName) |
|
| 817 | + { |
|
| 818 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 819 | + : null; |
|
| 820 | + if (is_array($cached_array_or_object)) { |
|
| 821 | + return array_shift($cached_array_or_object); |
|
| 822 | + } else { |
|
| 823 | + return $cached_array_or_object; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 831 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 832 | + * |
|
| 833 | + * @param string $relationName |
|
| 834 | + * @throws \EE_Error |
|
| 835 | + * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 836 | + */ |
|
| 837 | + public function get_all_from_cache($relationName) |
|
| 838 | + { |
|
| 839 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 840 | + // if the result is not an array, but exists, make it an array |
|
| 841 | + $objects = is_array($objects) ? $objects : array($objects); |
|
| 842 | + //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 843 | + //basically, if this model object was stored in the session, and these cached model objects |
|
| 844 | + //already have IDs, let's make sure they're in their model's entity mapper |
|
| 845 | + //otherwise we will have duplicates next time we call |
|
| 846 | + // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 847 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 848 | + foreach ($objects as $model_object) { |
|
| 849 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 850 | + //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 851 | + if ($model_object->ID()) { |
|
| 852 | + $model->add_to_entity_map($model_object); |
|
| 853 | + } |
|
| 854 | + } else { |
|
| 855 | + throw new EE_Error( |
|
| 856 | + sprintf( |
|
| 857 | + __( |
|
| 858 | + 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 859 | + 'event_espresso' |
|
| 860 | + ), |
|
| 861 | + $relationName, |
|
| 862 | + gettype($model_object) |
|
| 863 | + ) |
|
| 864 | + ); |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + return $objects; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 874 | + * matching the given query conditions. |
|
| 875 | + * |
|
| 876 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 877 | + * @param int $limit How many objects to return. |
|
| 878 | + * @param array $query_params Any additional conditions on the query. |
|
| 879 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 880 | + * you can indicate just the columns you want returned |
|
| 881 | + * @return array|EE_Base_Class[] |
|
| 882 | + * @throws \EE_Error |
|
| 883 | + */ |
|
| 884 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 885 | + { |
|
| 886 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 887 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 888 | + : $field_to_order_by; |
|
| 889 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 890 | + if (empty($field) || empty($current_value)) { |
|
| 891 | + return array(); |
|
| 892 | + } |
|
| 893 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 900 | + * matching the given query conditions. |
|
| 901 | + * |
|
| 902 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 903 | + * @param int $limit How many objects to return. |
|
| 904 | + * @param array $query_params Any additional conditions on the query. |
|
| 905 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 906 | + * you can indicate just the columns you want returned |
|
| 907 | + * @return array|EE_Base_Class[] |
|
| 908 | + * @throws \EE_Error |
|
| 909 | + */ |
|
| 910 | + public function previous_x( |
|
| 911 | + $field_to_order_by = null, |
|
| 912 | + $limit = 1, |
|
| 913 | + $query_params = array(), |
|
| 914 | + $columns_to_select = null |
|
| 915 | + ) { |
|
| 916 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 917 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 918 | + : $field_to_order_by; |
|
| 919 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 920 | + if (empty($field) || empty($current_value)) { |
|
| 921 | + return array(); |
|
| 922 | + } |
|
| 923 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 930 | + * matching the given query conditions. |
|
| 931 | + * |
|
| 932 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 933 | + * @param array $query_params Any additional conditions on the query. |
|
| 934 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 935 | + * you can indicate just the columns you want returned |
|
| 936 | + * @return array|EE_Base_Class |
|
| 937 | + * @throws \EE_Error |
|
| 938 | + */ |
|
| 939 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 940 | + { |
|
| 941 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 942 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 943 | + : $field_to_order_by; |
|
| 944 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 945 | + if (empty($field) || empty($current_value)) { |
|
| 946 | + return array(); |
|
| 947 | + } |
|
| 948 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 955 | + * matching the given query conditions. |
|
| 956 | + * |
|
| 957 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 958 | + * @param array $query_params Any additional conditions on the query. |
|
| 959 | + * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 960 | + * you can indicate just the column you want returned |
|
| 961 | + * @return array|EE_Base_Class |
|
| 962 | + * @throws \EE_Error |
|
| 963 | + */ |
|
| 964 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 965 | + { |
|
| 966 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 967 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 968 | + : $field_to_order_by; |
|
| 969 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 970 | + if (empty($field) || empty($current_value)) { |
|
| 971 | + return array(); |
|
| 972 | + } |
|
| 973 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Overrides parent because parent expects old models. |
|
| 980 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 981 | + * |
|
| 982 | + * @param string $field_name |
|
| 983 | + * @param mixed $field_value_from_db |
|
| 984 | + * @throws \EE_Error |
|
| 985 | + */ |
|
| 986 | + public function set_from_db($field_name, $field_value_from_db) |
|
| 987 | + { |
|
| 988 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 989 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 990 | + //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 991 | + //eg, a CPT model object could have an entry in the posts table, but no |
|
| 992 | + //entry in the meta table. Meaning that all its columns in the meta table |
|
| 993 | + //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 994 | + if ($field_value_from_db === null) { |
|
| 995 | + if ($field_obj->is_nullable()) { |
|
| 996 | + //if the field allows nulls, then let it be null |
|
| 997 | + $field_value = null; |
|
| 998 | + } else { |
|
| 999 | + $field_value = $field_obj->get_default_value(); |
|
| 1000 | + } |
|
| 1001 | + } else { |
|
| 1002 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1003 | + } |
|
| 1004 | + $this->_fields[$field_name] = $field_value; |
|
| 1005 | + $this->_clear_cached_property($field_name); |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * verifies that the specified field is of the correct type |
|
| 1013 | + * |
|
| 1014 | + * @param string $field_name |
|
| 1015 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1016 | + * (in cases where the same property may be used for different outputs |
|
| 1017 | + * - i.e. datetime, money etc.) |
|
| 1018 | + * @return mixed |
|
| 1019 | + * @throws \EE_Error |
|
| 1020 | + */ |
|
| 1021 | + public function get($field_name, $extra_cache_ref = null) |
|
| 1022 | + { |
|
| 1023 | + return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1030 | + * |
|
| 1031 | + * @param string $field_name A valid fieldname |
|
| 1032 | + * @return mixed Whatever the raw value stored on the property is. |
|
| 1033 | + * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1034 | + */ |
|
| 1035 | + public function get_raw($field_name) |
|
| 1036 | + { |
|
| 1037 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1038 | + return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
| 1039 | + ? $this->_fields[$field_name]->format('U') |
|
| 1040 | + : $this->_fields[$field_name]; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * This is used to return the internal DateTime object used for a field that is a |
|
| 1047 | + * EE_Datetime_Field. |
|
| 1048 | + * |
|
| 1049 | + * @param string $field_name The field name retrieving the DateTime object. |
|
| 1050 | + * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1051 | + * @throws \EE_Error |
|
| 1052 | + * an error is set and false returned. If the field IS an |
|
| 1053 | + * EE_Datetime_Field and but the field value is null, then |
|
| 1054 | + * just null is returned (because that indicates that likely |
|
| 1055 | + * this field is nullable). |
|
| 1056 | + */ |
|
| 1057 | + public function get_DateTime_object($field_name) |
|
| 1058 | + { |
|
| 1059 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1060 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1061 | + EE_Error::add_error( |
|
| 1062 | + sprintf( |
|
| 1063 | + __( |
|
| 1064 | + 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1065 | + 'event_espresso' |
|
| 1066 | + ), |
|
| 1067 | + $field_name |
|
| 1068 | + ), |
|
| 1069 | + __FILE__, |
|
| 1070 | + __FUNCTION__, |
|
| 1071 | + __LINE__ |
|
| 1072 | + ); |
|
| 1073 | + return false; |
|
| 1074 | + } |
|
| 1075 | + return $this->_fields[$field_name]; |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * To be used in template to immediately echo out the value, and format it for output. |
|
| 1082 | + * Eg, should call stripslashes and whatnot before echoing |
|
| 1083 | + * |
|
| 1084 | + * @param string $field_name the name of the field as it appears in the DB |
|
| 1085 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1086 | + * (in cases where the same property may be used for different outputs |
|
| 1087 | + * - i.e. datetime, money etc.) |
|
| 1088 | + * @return void |
|
| 1089 | + * @throws \EE_Error |
|
| 1090 | + */ |
|
| 1091 | + public function e($field_name, $extra_cache_ref = null) |
|
| 1092 | + { |
|
| 1093 | + echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1100 | + * can be easily used as the value of form input. |
|
| 1101 | + * |
|
| 1102 | + * @param string $field_name |
|
| 1103 | + * @return void |
|
| 1104 | + * @throws \EE_Error |
|
| 1105 | + */ |
|
| 1106 | + public function f($field_name) |
|
| 1107 | + { |
|
| 1108 | + $this->e($field_name, 'form_input'); |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 1115 | + * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 1116 | + * to see what options are available. |
|
| 1117 | + * @param string $field_name |
|
| 1118 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1119 | + * (in cases where the same property may be used for different outputs |
|
| 1120 | + * - i.e. datetime, money etc.) |
|
| 1121 | + * @return mixed |
|
| 1122 | + * @throws \EE_Error |
|
| 1123 | + */ |
|
| 1124 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1125 | + { |
|
| 1126 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + /** |
|
| 1132 | + * This simply returns the datetime for the given field name |
|
| 1133 | + * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1134 | + * (and the equivalent e_date, e_time, e_datetime). |
|
| 1135 | + * |
|
| 1136 | + * @access protected |
|
| 1137 | + * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1138 | + * @param string $dt_frmt valid datetime format used for date |
|
| 1139 | + * (if '' then we just use the default on the field, |
|
| 1140 | + * if NULL we use the last-used format) |
|
| 1141 | + * @param string $tm_frmt Same as above except this is for time format |
|
| 1142 | + * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1143 | + * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1144 | + * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1145 | + * if field is not a valid dtt field, or void if echoing |
|
| 1146 | + * @throws \EE_Error |
|
| 1147 | + */ |
|
| 1148 | + protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1149 | + { |
|
| 1150 | + // clear cached property |
|
| 1151 | + $this->_clear_cached_property($field_name); |
|
| 1152 | + //reset format properties because they are used in get() |
|
| 1153 | + $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1154 | + $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1155 | + if ($echo) { |
|
| 1156 | + $this->e($field_name, $date_or_time); |
|
| 1157 | + return ''; |
|
| 1158 | + } |
|
| 1159 | + return $this->get($field_name, $date_or_time); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + |
|
| 1164 | + /** |
|
| 1165 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1166 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1167 | + * other echoes the pretty value for dtt) |
|
| 1168 | + * |
|
| 1169 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1170 | + * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1171 | + * @return string datetime value formatted |
|
| 1172 | + * @throws \EE_Error |
|
| 1173 | + */ |
|
| 1174 | + public function get_date($field_name, $format = '') |
|
| 1175 | + { |
|
| 1176 | + return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * @param $field_name |
|
| 1183 | + * @param string $format |
|
| 1184 | + * @throws \EE_Error |
|
| 1185 | + */ |
|
| 1186 | + public function e_date($field_name, $format = '') |
|
| 1187 | + { |
|
| 1188 | + $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1195 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1196 | + * other echoes the pretty value for dtt) |
|
| 1197 | + * |
|
| 1198 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1199 | + * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1200 | + * @return string datetime value formatted |
|
| 1201 | + * @throws \EE_Error |
|
| 1202 | + */ |
|
| 1203 | + public function get_time($field_name, $format = '') |
|
| 1204 | + { |
|
| 1205 | + return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * @param $field_name |
|
| 1212 | + * @param string $format |
|
| 1213 | + * @throws \EE_Error |
|
| 1214 | + */ |
|
| 1215 | + public function e_time($field_name, $format = '') |
|
| 1216 | + { |
|
| 1217 | + $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1224 | + * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1225 | + * other echoes the pretty value for dtt) |
|
| 1226 | + * |
|
| 1227 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1228 | + * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1229 | + * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1230 | + * @return string datetime value formatted |
|
| 1231 | + * @throws \EE_Error |
|
| 1232 | + */ |
|
| 1233 | + public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1234 | + { |
|
| 1235 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * @param string $field_name |
|
| 1242 | + * @param string $dt_frmt |
|
| 1243 | + * @param string $tm_frmt |
|
| 1244 | + * @throws \EE_Error |
|
| 1245 | + */ |
|
| 1246 | + public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1247 | + { |
|
| 1248 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + |
|
| 1252 | + |
|
| 1253 | + /** |
|
| 1254 | + * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1255 | + * |
|
| 1256 | + * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1257 | + * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1258 | + * on the object will be used. |
|
| 1259 | + * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1260 | + * @throws \EE_Error |
|
| 1261 | + * field name. |
|
| 1262 | + */ |
|
| 1263 | + public function get_i18n_datetime($field_name, $format = '') |
|
| 1264 | + { |
|
| 1265 | + $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1266 | + return date_i18n( |
|
| 1267 | + $format, |
|
| 1268 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1269 | + ); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + |
|
| 1274 | + /** |
|
| 1275 | + * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1276 | + * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1277 | + * thrown. |
|
| 1278 | + * |
|
| 1279 | + * @param string $field_name The field name being checked |
|
| 1280 | + * @throws EE_Error |
|
| 1281 | + * @return EE_Datetime_Field |
|
| 1282 | + */ |
|
| 1283 | + protected function _get_dtt_field_settings($field_name) |
|
| 1284 | + { |
|
| 1285 | + $field = $this->get_model()->field_settings_for($field_name); |
|
| 1286 | + //check if field is dtt |
|
| 1287 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1288 | + return $field; |
|
| 1289 | + } else { |
|
| 1290 | + 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', |
|
| 1291 | + 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * NOTE ABOUT BELOW: |
|
| 1300 | + * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1301 | + * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1302 | + * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1303 | + * method and make sure you send the entire datetime value for setting. |
|
| 1304 | + */ |
|
| 1305 | + /** |
|
| 1306 | + * sets the time on a datetime property |
|
| 1307 | + * |
|
| 1308 | + * @access protected |
|
| 1309 | + * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1310 | + * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1311 | + * @throws \EE_Error |
|
| 1312 | + */ |
|
| 1313 | + protected function _set_time_for($time, $fieldname) |
|
| 1314 | + { |
|
| 1315 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + |
|
| 1320 | + /** |
|
| 1321 | + * sets the date on a datetime property |
|
| 1322 | + * |
|
| 1323 | + * @access protected |
|
| 1324 | + * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1325 | + * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1326 | + * @throws \EE_Error |
|
| 1327 | + */ |
|
| 1328 | + protected function _set_date_for($date, $fieldname) |
|
| 1329 | + { |
|
| 1330 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1337 | + * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1338 | + * |
|
| 1339 | + * @access protected |
|
| 1340 | + * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1341 | + * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1342 | + * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1343 | + * EE_Datetime_Field property) |
|
| 1344 | + * @throws \EE_Error |
|
| 1345 | + */ |
|
| 1346 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1347 | + { |
|
| 1348 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1349 | + $field->set_timezone($this->_timezone); |
|
| 1350 | + $field->set_date_format($this->_dt_frmt); |
|
| 1351 | + $field->set_time_format($this->_tm_frmt); |
|
| 1352 | + switch ($what) { |
|
| 1353 | + case 'T' : |
|
| 1354 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1355 | + $datetime_value, |
|
| 1356 | + $this->_fields[$fieldname] |
|
| 1357 | + ); |
|
| 1358 | + break; |
|
| 1359 | + case 'D' : |
|
| 1360 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1361 | + $datetime_value, |
|
| 1362 | + $this->_fields[$fieldname] |
|
| 1363 | + ); |
|
| 1364 | + break; |
|
| 1365 | + case 'B' : |
|
| 1366 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1367 | + break; |
|
| 1368 | + } |
|
| 1369 | + $this->_clear_cached_property($fieldname); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1376 | + * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1377 | + * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1378 | + * that could lead to some unexpected results! |
|
| 1379 | + * |
|
| 1380 | + * @access public |
|
| 1381 | + * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1382 | + * value being returned. |
|
| 1383 | + * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1384 | + * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1385 | + * @param string $prepend You can include something to prepend on the timestamp |
|
| 1386 | + * @param string $append You can include something to append on the timestamp |
|
| 1387 | + * @throws EE_Error |
|
| 1388 | + * @return string timestamp |
|
| 1389 | + */ |
|
| 1390 | + public function display_in_my_timezone( |
|
| 1391 | + $field_name, |
|
| 1392 | + $callback = 'get_datetime', |
|
| 1393 | + $args = null, |
|
| 1394 | + $prepend = '', |
|
| 1395 | + $append = '' |
|
| 1396 | + ) { |
|
| 1397 | + $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1398 | + if ($timezone === $this->_timezone) { |
|
| 1399 | + return ''; |
|
| 1400 | + } |
|
| 1401 | + $original_timezone = $this->_timezone; |
|
| 1402 | + $this->set_timezone($timezone); |
|
| 1403 | + $fn = (array)$field_name; |
|
| 1404 | + $args = array_merge($fn, (array)$args); |
|
| 1405 | + if ( ! method_exists($this, $callback)) { |
|
| 1406 | + throw new EE_Error( |
|
| 1407 | + sprintf( |
|
| 1408 | + __( |
|
| 1409 | + 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1410 | + 'event_espresso' |
|
| 1411 | + ), |
|
| 1412 | + $callback |
|
| 1413 | + ) |
|
| 1414 | + ); |
|
| 1415 | + } |
|
| 1416 | + $args = (array)$args; |
|
| 1417 | + $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1418 | + $this->set_timezone($original_timezone); |
|
| 1419 | + return $return; |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * Deletes this model object. |
|
| 1426 | + * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1427 | + * override |
|
| 1428 | + * `EE_Base_Class::_delete` NOT this class. |
|
| 1429 | + * |
|
| 1430 | + * @return boolean | int |
|
| 1431 | + * @throws \EE_Error |
|
| 1432 | + */ |
|
| 1433 | + public function delete() |
|
| 1434 | + { |
|
| 1435 | + /** |
|
| 1436 | + * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1437 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1438 | + * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1439 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1440 | + * |
|
| 1441 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1442 | + */ |
|
| 1443 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1444 | + $result = $this->_delete(); |
|
| 1445 | + /** |
|
| 1446 | + * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1447 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1448 | + * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1449 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1450 | + * |
|
| 1451 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1452 | + * @param boolean $result |
|
| 1453 | + */ |
|
| 1454 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1455 | + return $result; |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * Calls the specific delete method for the instantiated class. |
|
| 1462 | + * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1463 | + * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1464 | + * `EE_Base_Class::delete` |
|
| 1465 | + * |
|
| 1466 | + * @return bool|int |
|
| 1467 | + * @throws \EE_Error |
|
| 1468 | + */ |
|
| 1469 | + protected function _delete() |
|
| 1470 | + { |
|
| 1471 | + return $this->delete_permanently(); |
|
| 1472 | + } |
|
| 1473 | + |
|
| 1474 | + |
|
| 1475 | + |
|
| 1476 | + /** |
|
| 1477 | + * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1478 | + * error) |
|
| 1479 | + * |
|
| 1480 | + * @return bool | int |
|
| 1481 | + * @throws \EE_Error |
|
| 1482 | + */ |
|
| 1483 | + public function delete_permanently() |
|
| 1484 | + { |
|
| 1485 | + /** |
|
| 1486 | + * Called just before HARD deleting a model object |
|
| 1487 | + * |
|
| 1488 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1489 | + */ |
|
| 1490 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1491 | + $model = $this->get_model(); |
|
| 1492 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1493 | + $this->refresh_cache_of_related_objects(); |
|
| 1494 | + /** |
|
| 1495 | + * Called just after HARD deleting a model object |
|
| 1496 | + * |
|
| 1497 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1498 | + * @param boolean $result |
|
| 1499 | + */ |
|
| 1500 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1501 | + return $result; |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1508 | + * related model objects |
|
| 1509 | + * |
|
| 1510 | + * @throws \EE_Error |
|
| 1511 | + */ |
|
| 1512 | + public function refresh_cache_of_related_objects() |
|
| 1513 | + { |
|
| 1514 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1515 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1516 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1517 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1518 | + //this relation only stores a single model object, not an array |
|
| 1519 | + //but let's make it consistent |
|
| 1520 | + $related_objects = array($related_objects); |
|
| 1521 | + } |
|
| 1522 | + foreach ($related_objects as $related_object) { |
|
| 1523 | + //only refresh their cache if they're in memory |
|
| 1524 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1525 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1526 | + } |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1536 | + * object just before saving. |
|
| 1537 | + * |
|
| 1538 | + * @access public |
|
| 1539 | + * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1540 | + * if provided during the save() method (often client code will change the fields' |
|
| 1541 | + * values before calling save) |
|
| 1542 | + * @throws \EE_Error |
|
| 1543 | + * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1544 | + * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1545 | + */ |
|
| 1546 | + public function save($set_cols_n_values = array()) |
|
| 1547 | + { |
|
| 1548 | + /** |
|
| 1549 | + * Filters the fields we're about to save on the model object |
|
| 1550 | + * |
|
| 1551 | + * @param array $set_cols_n_values |
|
| 1552 | + * @param EE_Base_Class $model_object |
|
| 1553 | + */ |
|
| 1554 | + $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1555 | + $this); |
|
| 1556 | + //set attributes as provided in $set_cols_n_values |
|
| 1557 | + foreach ($set_cols_n_values as $column => $value) { |
|
| 1558 | + $this->set($column, $value); |
|
| 1559 | + } |
|
| 1560 | + /** |
|
| 1561 | + * Saving a model object. |
|
| 1562 | + * Before we perform a save, this action is fired. |
|
| 1563 | + * |
|
| 1564 | + * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1565 | + */ |
|
| 1566 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1567 | + if ( ! $this->allow_persist()) { |
|
| 1568 | + return 0; |
|
| 1569 | + } |
|
| 1570 | + //now get current attribute values |
|
| 1571 | + $save_cols_n_values = $this->_fields; |
|
| 1572 | + //if the object already has an ID, update it. Otherwise, insert it |
|
| 1573 | + //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1574 | + $old_assumption_concerning_value_preparation = $this->get_model() |
|
| 1575 | + ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1576 | + $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
| 1577 | + //does this model have an autoincrement PK? |
|
| 1578 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1579 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1580 | + //ok check if it's set, if so: update; if not, insert |
|
| 1581 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1582 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1583 | + } else { |
|
| 1584 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1585 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1586 | + if ($results) { |
|
| 1587 | + //if successful, set the primary key |
|
| 1588 | + //but don't use the normal SET method, because it will check if |
|
| 1589 | + //an item with the same ID exists in the mapper & db, then |
|
| 1590 | + //will find it in the db (because we just added it) and THAT object |
|
| 1591 | + //will get added to the mapper before we can add this one! |
|
| 1592 | + //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1593 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1594 | + $this->_fields[$pk_field_name] = $results; |
|
| 1595 | + $this->_clear_cached_property($pk_field_name); |
|
| 1596 | + $this->get_model()->add_to_entity_map($this); |
|
| 1597 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1598 | + } |
|
| 1599 | + } |
|
| 1600 | + } else {//PK is NOT auto-increment |
|
| 1601 | + //so check if one like it already exists in the db |
|
| 1602 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1603 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1604 | + throw new EE_Error( |
|
| 1605 | + sprintf( |
|
| 1606 | + __('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', |
|
| 1607 | + 'event_espresso'), |
|
| 1608 | + get_class($this), |
|
| 1609 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 1610 | + get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
| 1611 | + '<br />' |
|
| 1612 | + ) |
|
| 1613 | + ); |
|
| 1614 | + } |
|
| 1615 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1616 | + } else { |
|
| 1617 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1618 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1619 | + } |
|
| 1620 | + } |
|
| 1621 | + } else {//there is NO primary key |
|
| 1622 | + $already_in_db = false; |
|
| 1623 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1624 | + $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1625 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1626 | + $already_in_db = true; |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + if ($already_in_db) { |
|
| 1630 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1631 | + $this->get_model()->get_combined_primary_key_fields()); |
|
| 1632 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1633 | + } else { |
|
| 1634 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1635 | + } |
|
| 1636 | + } |
|
| 1637 | + //restore the old assumption about values being prepared by the model object |
|
| 1638 | + $this->get_model() |
|
| 1639 | + ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1640 | + /** |
|
| 1641 | + * After saving the model object this action is called |
|
| 1642 | + * |
|
| 1643 | + * @param EE_Base_Class $model_object which was just saved |
|
| 1644 | + * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1645 | + * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1646 | + */ |
|
| 1647 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1648 | + return $results; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1655 | + * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1656 | + * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1657 | + * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1658 | + * 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 |
|
| 1659 | + * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1660 | + * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1661 | + * |
|
| 1662 | + * @return void |
|
| 1663 | + * @throws \EE_Error |
|
| 1664 | + */ |
|
| 1665 | + protected function _update_cached_related_model_objs_fks() |
|
| 1666 | + { |
|
| 1667 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1668 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1669 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1670 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1671 | + $this->get_model()->get_this_model_name() |
|
| 1672 | + ); |
|
| 1673 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1674 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1675 | + $related_model_obj_in_cache->save(); |
|
| 1676 | + } |
|
| 1677 | + } |
|
| 1678 | + } |
|
| 1679 | + } |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * Saves this model object and its NEW cached relations to the database. |
|
| 1686 | + * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1687 | + * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1688 | + * because otherwise, there's a potential for infinite looping of saving |
|
| 1689 | + * Saves the cached related model objects, and ensures the relation between them |
|
| 1690 | + * and this object and properly setup |
|
| 1691 | + * |
|
| 1692 | + * @return int ID of new model object on save; 0 on failure+ |
|
| 1693 | + * @throws \EE_Error |
|
| 1694 | + */ |
|
| 1695 | + public function save_new_cached_related_model_objs() |
|
| 1696 | + { |
|
| 1697 | + //make sure this has been saved |
|
| 1698 | + if ( ! $this->ID()) { |
|
| 1699 | + $id = $this->save(); |
|
| 1700 | + } else { |
|
| 1701 | + $id = $this->ID(); |
|
| 1702 | + } |
|
| 1703 | + //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1704 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1705 | + if ($this->_model_relations[$relationName]) { |
|
| 1706 | + //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1707 | + //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1708 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1709 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1710 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1711 | + /* @var $related_model_obj EE_Base_Class */ |
|
| 1712 | + $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1713 | + // if( ! $related_model_obj->ID()){ |
|
| 1714 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1715 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1716 | + // } |
|
| 1717 | + } else { |
|
| 1718 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1719 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1720 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1721 | + // if( ! $related_model_obj->ID()){ |
|
| 1722 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1723 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1724 | + // } |
|
| 1725 | + } |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + return $id; |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * for getting a model while instantiated. |
|
| 1736 | + * |
|
| 1737 | + * @return \EEM_Base | \EEM_CPT_Base |
|
| 1738 | + */ |
|
| 1739 | + public function get_model() |
|
| 1740 | + { |
|
| 1741 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1742 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + |
|
| 1746 | + |
|
| 1747 | + /** |
|
| 1748 | + * @param $props_n_values |
|
| 1749 | + * @param $classname |
|
| 1750 | + * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1751 | + * @throws \EE_Error |
|
| 1752 | + */ |
|
| 1753 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1754 | + { |
|
| 1755 | + //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1756 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1757 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1758 | + $id = $props_n_values[$primary_id_ref]; |
|
| 1759 | + return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1760 | + } |
|
| 1761 | + return false; |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1768 | + * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1769 | + * primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not |
|
| 1770 | + * we return false. |
|
| 1771 | + * |
|
| 1772 | + * @param array $props_n_values incoming array of properties and their values |
|
| 1773 | + * @param string $classname the classname of the child class |
|
| 1774 | + * @param null $timezone |
|
| 1775 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1776 | + * date_format and the second value is the time format |
|
| 1777 | + * @return mixed (EE_Base_Class|bool) |
|
| 1778 | + * @throws \EE_Error |
|
| 1779 | + */ |
|
| 1780 | + protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1781 | + { |
|
| 1782 | + $existing = null; |
|
| 1783 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1784 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1785 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1786 | + && ! empty($props_n_values[$primary_id_ref]) |
|
| 1787 | + ) { |
|
| 1788 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1789 | + $props_n_values[$primary_id_ref] |
|
| 1790 | + ); |
|
| 1791 | + } |
|
| 1792 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1793 | + //no primary key on this model, but there's still a matching item in the DB |
|
| 1794 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1795 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1796 | + ); |
|
| 1797 | + } |
|
| 1798 | + if ($existing) { |
|
| 1799 | + //set date formats if present before setting values |
|
| 1800 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1801 | + $existing->set_date_format($date_formats[0]); |
|
| 1802 | + $existing->set_time_format($date_formats[1]); |
|
| 1803 | + } else { |
|
| 1804 | + //set default formats for date and time |
|
| 1805 | + $existing->set_date_format(get_option('date_format')); |
|
| 1806 | + $existing->set_time_format(get_option('time_format')); |
|
| 1807 | + } |
|
| 1808 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1809 | + $existing->set($property, $field_value); |
|
| 1810 | + } |
|
| 1811 | + return $existing; |
|
| 1812 | + } else { |
|
| 1813 | + return false; |
|
| 1814 | + } |
|
| 1815 | + } |
|
| 1816 | + |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Gets the EEM_*_Model for this class |
|
| 1821 | + * |
|
| 1822 | + * @access public now, as this is more convenient |
|
| 1823 | + * @param $classname |
|
| 1824 | + * @param null $timezone |
|
| 1825 | + * @throws EE_Error |
|
| 1826 | + * @return EEM_Base |
|
| 1827 | + */ |
|
| 1828 | + protected static function _get_model($classname, $timezone = null) |
|
| 1829 | + { |
|
| 1830 | + //find model for this class |
|
| 1831 | + if ( ! $classname) { |
|
| 1832 | + throw new EE_Error( |
|
| 1833 | + sprintf( |
|
| 1834 | + __( |
|
| 1835 | + "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1836 | + "event_espresso" |
|
| 1837 | + ), |
|
| 1838 | + $classname |
|
| 1839 | + ) |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | + $modelName = self::_get_model_classname($classname); |
|
| 1843 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + |
|
| 1847 | + |
|
| 1848 | + /** |
|
| 1849 | + * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1850 | + * |
|
| 1851 | + * @param string $model_classname |
|
| 1852 | + * @param null $timezone |
|
| 1853 | + * @return EEM_Base |
|
| 1854 | + */ |
|
| 1855 | + protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1856 | + { |
|
| 1857 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1858 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1859 | + $model->set_timezone($timezone); |
|
| 1860 | + return $model; |
|
| 1861 | + } |
|
| 1862 | + |
|
| 1863 | + |
|
| 1864 | + |
|
| 1865 | + /** |
|
| 1866 | + * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 1867 | + * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 1868 | + * |
|
| 1869 | + * @param null $model_name |
|
| 1870 | + * @return string like EEM_Attendee |
|
| 1871 | + */ |
|
| 1872 | + private static function _get_model_classname($model_name = null) |
|
| 1873 | + { |
|
| 1874 | + if (strpos($model_name, "EE_") === 0) { |
|
| 1875 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1876 | + } else { |
|
| 1877 | + $model_classname = "EEM_" . $model_name; |
|
| 1878 | + } |
|
| 1879 | + return $model_classname; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * returns the name of the primary key attribute |
|
| 1886 | + * |
|
| 1887 | + * @param null $classname |
|
| 1888 | + * @throws EE_Error |
|
| 1889 | + * @return string |
|
| 1890 | + */ |
|
| 1891 | + protected static function _get_primary_key_name($classname = null) |
|
| 1892 | + { |
|
| 1893 | + if ( ! $classname) { |
|
| 1894 | + throw new EE_Error( |
|
| 1895 | + sprintf( |
|
| 1896 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1897 | + $classname |
|
| 1898 | + ) |
|
| 1899 | + ); |
|
| 1900 | + } |
|
| 1901 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + |
|
| 1905 | + |
|
| 1906 | + /** |
|
| 1907 | + * Gets the value of the primary key. |
|
| 1908 | + * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 1909 | + * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 1910 | + * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 1911 | + * |
|
| 1912 | + * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 1913 | + * @throws \EE_Error |
|
| 1914 | + */ |
|
| 1915 | + public function ID() |
|
| 1916 | + { |
|
| 1917 | + //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 1918 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1919 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1920 | + } else { |
|
| 1921 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1922 | + } |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + |
|
| 1926 | + |
|
| 1927 | + /** |
|
| 1928 | + * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 1929 | + * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 1930 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 1931 | + * |
|
| 1932 | + * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 1933 | + * @param string $relationName eg 'Events','Question',etc. |
|
| 1934 | + * an attendee to a group, you also want to specify which role they |
|
| 1935 | + * will have in that group. So you would use this parameter to |
|
| 1936 | + * specify array('role-column-name'=>'role-id') |
|
| 1937 | + * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 1938 | + * allow you to further constrict the relation to being added. |
|
| 1939 | + * However, keep in mind that the columns (keys) given must match a |
|
| 1940 | + * column on the JOIN table and currently only the HABTM models |
|
| 1941 | + * accept these additional conditions. Also remember that if an |
|
| 1942 | + * exact match isn't found for these extra cols/val pairs, then a |
|
| 1943 | + * NEW row is created in the join table. |
|
| 1944 | + * @param null $cache_id |
|
| 1945 | + * @throws EE_Error |
|
| 1946 | + * @return EE_Base_Class the object the relation was added to |
|
| 1947 | + */ |
|
| 1948 | + public function _add_relation_to( |
|
| 1949 | + $otherObjectModelObjectOrID, |
|
| 1950 | + $relationName, |
|
| 1951 | + $extra_join_model_fields_n_values = array(), |
|
| 1952 | + $cache_id = null |
|
| 1953 | + ) { |
|
| 1954 | + //if this thing exists in the DB, save the relation to the DB |
|
| 1955 | + if ($this->ID()) { |
|
| 1956 | + $otherObject = $this->get_model() |
|
| 1957 | + ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 1958 | + $extra_join_model_fields_n_values); |
|
| 1959 | + //clear cache so future get_many_related and get_first_related() return new results. |
|
| 1960 | + $this->clear_cache($relationName, $otherObject, true); |
|
| 1961 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1962 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1963 | + } |
|
| 1964 | + } else { |
|
| 1965 | + //this thing doesn't exist in the DB, so just cache it |
|
| 1966 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1967 | + throw new EE_Error(sprintf( |
|
| 1968 | + __('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', |
|
| 1969 | + 'event_espresso'), |
|
| 1970 | + $otherObjectModelObjectOrID, |
|
| 1971 | + get_class($this) |
|
| 1972 | + )); |
|
| 1973 | + } else { |
|
| 1974 | + $otherObject = $otherObjectModelObjectOrID; |
|
| 1975 | + } |
|
| 1976 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1977 | + } |
|
| 1978 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1979 | + //fix the reciprocal relation too |
|
| 1980 | + if ($otherObject->ID()) { |
|
| 1981 | + //its saved so assumed relations exist in the DB, so we can just |
|
| 1982 | + //clear the cache so future queries use the updated info in the DB |
|
| 1983 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1984 | + } else { |
|
| 1985 | + //it's not saved, so it caches relations like this |
|
| 1986 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1987 | + } |
|
| 1988 | + } |
|
| 1989 | + return $otherObject; |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 1996 | + * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 1997 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 1998 | + * from the cache |
|
| 1999 | + * |
|
| 2000 | + * @param mixed $otherObjectModelObjectOrID |
|
| 2001 | + * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 2002 | + * to the DB yet |
|
| 2003 | + * @param string $relationName |
|
| 2004 | + * @param array $where_query |
|
| 2005 | + * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2006 | + * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2007 | + * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2008 | + * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2009 | + * created in the join table. |
|
| 2010 | + * @return EE_Base_Class the relation was removed from |
|
| 2011 | + * @throws \EE_Error |
|
| 2012 | + */ |
|
| 2013 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2014 | + { |
|
| 2015 | + if ($this->ID()) { |
|
| 2016 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2017 | + $otherObject = $this->get_model() |
|
| 2018 | + ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2019 | + $where_query); |
|
| 2020 | + $this->clear_cache($relationName, $otherObject); |
|
| 2021 | + } else { |
|
| 2022 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2023 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2024 | + } |
|
| 2025 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 2026 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2027 | + } |
|
| 2028 | + return $otherObject; |
|
| 2029 | + } |
|
| 2030 | + |
|
| 2031 | + |
|
| 2032 | + |
|
| 2033 | + /** |
|
| 2034 | + * Removes ALL the related things for the $relationName. |
|
| 2035 | + * |
|
| 2036 | + * @param string $relationName |
|
| 2037 | + * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2038 | + * @return EE_Base_Class |
|
| 2039 | + * @throws \EE_Error |
|
| 2040 | + */ |
|
| 2041 | + public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2042 | + { |
|
| 2043 | + if ($this->ID()) { |
|
| 2044 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2045 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2046 | + $this->clear_cache($relationName, null, true); |
|
| 2047 | + } else { |
|
| 2048 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2049 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2050 | + } |
|
| 2051 | + if (is_array($otherObjects)) { |
|
| 2052 | + foreach ($otherObjects as $otherObject) { |
|
| 2053 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2054 | + } |
|
| 2055 | + } |
|
| 2056 | + return $otherObjects; |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + |
|
| 2060 | + |
|
| 2061 | + /** |
|
| 2062 | + * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2063 | + * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2064 | + * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2065 | + * because we want to get even deleted items etc. |
|
| 2066 | + * |
|
| 2067 | + * @param string $relationName key in the model's _model_relations array |
|
| 2068 | + * @param array $query_params like EEM_Base::get_all |
|
| 2069 | + * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2070 | + * @throws \EE_Error |
|
| 2071 | + * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2072 | + * you want IDs |
|
| 2073 | + */ |
|
| 2074 | + public function get_many_related($relationName, $query_params = array()) |
|
| 2075 | + { |
|
| 2076 | + if ($this->ID()) { |
|
| 2077 | + //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2078 | + //if there are query parameters, forget about caching the related model objects. |
|
| 2079 | + if ($query_params) { |
|
| 2080 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2081 | + } else { |
|
| 2082 | + //did we already cache the result of this query? |
|
| 2083 | + $cached_results = $this->get_all_from_cache($relationName); |
|
| 2084 | + if ( ! $cached_results) { |
|
| 2085 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2086 | + //if no query parameters were passed, then we got all the related model objects |
|
| 2087 | + //for that relation. We can cache them then. |
|
| 2088 | + foreach ($related_model_objects as $related_model_object) { |
|
| 2089 | + $this->cache($relationName, $related_model_object); |
|
| 2090 | + } |
|
| 2091 | + } else { |
|
| 2092 | + $related_model_objects = $cached_results; |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + } else { |
|
| 2096 | + //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2097 | + $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2098 | + } |
|
| 2099 | + return $related_model_objects; |
|
| 2100 | + } |
|
| 2101 | + |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2106 | + * unless otherwise specified in the $query_params |
|
| 2107 | + * |
|
| 2108 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2109 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2110 | + * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2111 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2112 | + * that by the setting $distinct to TRUE; |
|
| 2113 | + * @return int |
|
| 2114 | + */ |
|
| 2115 | + public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2116 | + { |
|
| 2117 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + |
|
| 2121 | + |
|
| 2122 | + /** |
|
| 2123 | + * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2124 | + * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2125 | + * |
|
| 2126 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2127 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2128 | + * @param string $field_to_sum name of field to count by. |
|
| 2129 | + * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2130 | + * change it) |
|
| 2131 | + * @return int |
|
| 2132 | + */ |
|
| 2133 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2134 | + { |
|
| 2135 | + return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + |
|
| 2139 | + |
|
| 2140 | + /** |
|
| 2141 | + * Gets the first (ie, one) related model object of the specified type. |
|
| 2142 | + * |
|
| 2143 | + * @param string $relationName key in the model's _model_relations array |
|
| 2144 | + * @param array $query_params like EEM_Base::get_all |
|
| 2145 | + * @return EE_Base_Class (not an array, a single object) |
|
| 2146 | + * @throws \EE_Error |
|
| 2147 | + */ |
|
| 2148 | + public function get_first_related($relationName, $query_params = array()) |
|
| 2149 | + { |
|
| 2150 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2151 | + //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2152 | + //also make sure we're not caching the result of get_first_related |
|
| 2153 | + //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2154 | + if ($query_params |
|
| 2155 | + || ! $this->get_model()->related_settings_for($relationName) |
|
| 2156 | + instanceof |
|
| 2157 | + EE_Belongs_To_Relation |
|
| 2158 | + ) { |
|
| 2159 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2160 | + } else { |
|
| 2161 | + //first, check if we've already cached the result of this query |
|
| 2162 | + $cached_result = $this->get_one_from_cache($relationName); |
|
| 2163 | + if ( ! $cached_result) { |
|
| 2164 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2165 | + $this->cache($relationName, $related_model_object); |
|
| 2166 | + } else { |
|
| 2167 | + $related_model_object = $cached_result; |
|
| 2168 | + } |
|
| 2169 | + } |
|
| 2170 | + } else { |
|
| 2171 | + $related_model_object = null; |
|
| 2172 | + //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2173 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2174 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2175 | + } |
|
| 2176 | + //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 |
|
| 2177 | + if ( ! $related_model_object) { |
|
| 2178 | + $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2179 | + } |
|
| 2180 | + } |
|
| 2181 | + return $related_model_object; |
|
| 2182 | + } |
|
| 2183 | + |
|
| 2184 | + |
|
| 2185 | + |
|
| 2186 | + /** |
|
| 2187 | + * Does a delete on all related objects of type $relationName and removes |
|
| 2188 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2189 | + * of blocking related model objects) does nothing. If the related model objects are |
|
| 2190 | + * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2191 | + * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2192 | + * |
|
| 2193 | + * @param string $relationName |
|
| 2194 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2195 | + * @return int how many deleted |
|
| 2196 | + * @throws \EE_Error |
|
| 2197 | + */ |
|
| 2198 | + public function delete_related($relationName, $query_params = array()) |
|
| 2199 | + { |
|
| 2200 | + if ($this->ID()) { |
|
| 2201 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2202 | + } else { |
|
| 2203 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2204 | + $this->clear_cache($relationName, null, true); |
|
| 2205 | + } |
|
| 2206 | + return $count; |
|
| 2207 | + } |
|
| 2208 | + |
|
| 2209 | + |
|
| 2210 | + |
|
| 2211 | + /** |
|
| 2212 | + * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2213 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2214 | + * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2215 | + * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2216 | + * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2217 | + * |
|
| 2218 | + * @param string $relationName |
|
| 2219 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2220 | + * @return int how many deleted (including those soft deleted) |
|
| 2221 | + * @throws \EE_Error |
|
| 2222 | + */ |
|
| 2223 | + public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2224 | + { |
|
| 2225 | + if ($this->ID()) { |
|
| 2226 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2227 | + } else { |
|
| 2228 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2229 | + } |
|
| 2230 | + $this->clear_cache($relationName, null, true); |
|
| 2231 | + return $count; |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + |
|
| 2235 | + |
|
| 2236 | + /** |
|
| 2237 | + * is_set |
|
| 2238 | + * Just a simple utility function children can use for checking if property exists |
|
| 2239 | + * |
|
| 2240 | + * @access public |
|
| 2241 | + * @param string $field_name property to check |
|
| 2242 | + * @return bool TRUE if existing,FALSE if not. |
|
| 2243 | + */ |
|
| 2244 | + public function is_set($field_name) |
|
| 2245 | + { |
|
| 2246 | + return isset($this->_fields[$field_name]); |
|
| 2247 | + } |
|
| 2248 | + |
|
| 2249 | + |
|
| 2250 | + |
|
| 2251 | + /** |
|
| 2252 | + * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2253 | + * EE_Error exception if they don't |
|
| 2254 | + * |
|
| 2255 | + * @param mixed (string|array) $properties properties to check |
|
| 2256 | + * @throws EE_Error |
|
| 2257 | + * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2258 | + */ |
|
| 2259 | + protected function _property_exists($properties) |
|
| 2260 | + { |
|
| 2261 | + foreach ((array)$properties as $property_name) { |
|
| 2262 | + //first make sure this property exists |
|
| 2263 | + if ( ! $this->_fields[$property_name]) { |
|
| 2264 | + throw new EE_Error( |
|
| 2265 | + sprintf( |
|
| 2266 | + __( |
|
| 2267 | + 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2268 | + 'event_espresso' |
|
| 2269 | + ), |
|
| 2270 | + $property_name |
|
| 2271 | + ) |
|
| 2272 | + ); |
|
| 2273 | + } |
|
| 2274 | + } |
|
| 2275 | + return true; |
|
| 2276 | + } |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * This simply returns an array of model fields for this object |
|
| 2282 | + * |
|
| 2283 | + * @return array |
|
| 2284 | + * @throws \EE_Error |
|
| 2285 | + */ |
|
| 2286 | + public function model_field_array() |
|
| 2287 | + { |
|
| 2288 | + $fields = $this->get_model()->field_settings(false); |
|
| 2289 | + $properties = array(); |
|
| 2290 | + //remove prepended underscore |
|
| 2291 | + foreach ($fields as $field_name => $settings) { |
|
| 2292 | + $properties[$field_name] = $this->get($field_name); |
|
| 2293 | + } |
|
| 2294 | + return $properties; |
|
| 2295 | + } |
|
| 2296 | + |
|
| 2297 | + |
|
| 2298 | + |
|
| 2299 | + /** |
|
| 2300 | + * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2301 | + * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2302 | + * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2303 | + * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2304 | + * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2305 | + * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2306 | + * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2307 | + * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2308 | + * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2309 | + * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2310 | + * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2311 | + * return $previousReturnValue.$returnString; |
|
| 2312 | + * } |
|
| 2313 | + * require('EE_Answer.class.php'); |
|
| 2314 | + * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2315 | + * echo $answer->my_callback('monkeys',100); |
|
| 2316 | + * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2317 | + * |
|
| 2318 | + * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2319 | + * @param array $args array of original arguments passed to the function |
|
| 2320 | + * @throws EE_Error |
|
| 2321 | + * @return mixed whatever the plugin which calls add_filter decides |
|
| 2322 | + */ |
|
| 2323 | + public function __call($methodName, $args) |
|
| 2324 | + { |
|
| 2325 | + $className = get_class($this); |
|
| 2326 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2327 | + if ( ! has_filter($tagName)) { |
|
| 2328 | + throw new EE_Error( |
|
| 2329 | + sprintf( |
|
| 2330 | + __( |
|
| 2331 | + "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;}", |
|
| 2332 | + "event_espresso" |
|
| 2333 | + ), |
|
| 2334 | + $methodName, |
|
| 2335 | + $className, |
|
| 2336 | + $tagName |
|
| 2337 | + ) |
|
| 2338 | + ); |
|
| 2339 | + } |
|
| 2340 | + return apply_filters($tagName, null, $this, $args); |
|
| 2341 | + } |
|
| 2342 | + |
|
| 2343 | + |
|
| 2344 | + |
|
| 2345 | + /** |
|
| 2346 | + * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2347 | + * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2348 | + * |
|
| 2349 | + * @param string $meta_key |
|
| 2350 | + * @param string $meta_value |
|
| 2351 | + * @param string $previous_value |
|
| 2352 | + * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2353 | + * @throws \EE_Error |
|
| 2354 | + * NOTE: if the values haven't changed, returns 0 |
|
| 2355 | + */ |
|
| 2356 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2357 | + { |
|
| 2358 | + $query_params = array( |
|
| 2359 | + array( |
|
| 2360 | + 'EXM_key' => $meta_key, |
|
| 2361 | + 'OBJ_ID' => $this->ID(), |
|
| 2362 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2363 | + ), |
|
| 2364 | + ); |
|
| 2365 | + if ($previous_value !== null) { |
|
| 2366 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2367 | + } |
|
| 2368 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2369 | + if ( ! $existing_rows_like_that) { |
|
| 2370 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2371 | + } else { |
|
| 2372 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2373 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2374 | + } |
|
| 2375 | + return count($existing_rows_like_that); |
|
| 2376 | + } |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2383 | + * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2384 | + * extra meta row was entered, false if not |
|
| 2385 | + * |
|
| 2386 | + * @param string $meta_key |
|
| 2387 | + * @param string $meta_value |
|
| 2388 | + * @param boolean $unique |
|
| 2389 | + * @return boolean |
|
| 2390 | + * @throws \EE_Error |
|
| 2391 | + */ |
|
| 2392 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2393 | + { |
|
| 2394 | + if ($unique) { |
|
| 2395 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2396 | + array( |
|
| 2397 | + array( |
|
| 2398 | + 'EXM_key' => $meta_key, |
|
| 2399 | + 'OBJ_ID' => $this->ID(), |
|
| 2400 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2401 | + ), |
|
| 2402 | + ) |
|
| 2403 | + ); |
|
| 2404 | + if ($existing_extra_meta) { |
|
| 2405 | + return false; |
|
| 2406 | + } |
|
| 2407 | + } |
|
| 2408 | + $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2409 | + array( |
|
| 2410 | + 'EXM_key' => $meta_key, |
|
| 2411 | + 'EXM_value' => $meta_value, |
|
| 2412 | + 'OBJ_ID' => $this->ID(), |
|
| 2413 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2414 | + ) |
|
| 2415 | + ); |
|
| 2416 | + $new_extra_meta->save(); |
|
| 2417 | + return true; |
|
| 2418 | + } |
|
| 2419 | + |
|
| 2420 | + |
|
| 2421 | + |
|
| 2422 | + /** |
|
| 2423 | + * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2424 | + * is specified, only deletes extra meta records with that value. |
|
| 2425 | + * |
|
| 2426 | + * @param string $meta_key |
|
| 2427 | + * @param string $meta_value |
|
| 2428 | + * @return int number of extra meta rows deleted |
|
| 2429 | + * @throws \EE_Error |
|
| 2430 | + */ |
|
| 2431 | + public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2432 | + { |
|
| 2433 | + $query_params = array( |
|
| 2434 | + array( |
|
| 2435 | + 'EXM_key' => $meta_key, |
|
| 2436 | + 'OBJ_ID' => $this->ID(), |
|
| 2437 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2438 | + ), |
|
| 2439 | + ); |
|
| 2440 | + if ($meta_value !== null) { |
|
| 2441 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2442 | + } |
|
| 2443 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2444 | + } |
|
| 2445 | + |
|
| 2446 | + |
|
| 2447 | + |
|
| 2448 | + /** |
|
| 2449 | + * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2450 | + * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2451 | + * You can specify $default is case you haven't found the extra meta |
|
| 2452 | + * |
|
| 2453 | + * @param string $meta_key |
|
| 2454 | + * @param boolean $single |
|
| 2455 | + * @param mixed $default if we don't find anything, what should we return? |
|
| 2456 | + * @return mixed single value if $single; array if ! $single |
|
| 2457 | + * @throws \EE_Error |
|
| 2458 | + */ |
|
| 2459 | + public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2460 | + { |
|
| 2461 | + if ($single) { |
|
| 2462 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2463 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2464 | + return $result->value(); |
|
| 2465 | + } else { |
|
| 2466 | + return $default; |
|
| 2467 | + } |
|
| 2468 | + } else { |
|
| 2469 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2470 | + if ($results) { |
|
| 2471 | + $values = array(); |
|
| 2472 | + foreach ($results as $result) { |
|
| 2473 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2474 | + $values[$result->ID()] = $result->value(); |
|
| 2475 | + } |
|
| 2476 | + } |
|
| 2477 | + return $values; |
|
| 2478 | + } else { |
|
| 2479 | + return $default; |
|
| 2480 | + } |
|
| 2481 | + } |
|
| 2482 | + } |
|
| 2483 | + |
|
| 2484 | + |
|
| 2485 | + |
|
| 2486 | + /** |
|
| 2487 | + * Returns a simple array of all the extra meta associated with this model object. |
|
| 2488 | + * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2489 | + * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2490 | + * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2491 | + * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2492 | + * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2493 | + * finally the extra meta's value as each sub-value. (eg |
|
| 2494 | + * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2495 | + * |
|
| 2496 | + * @param boolean $one_of_each_key |
|
| 2497 | + * @return array |
|
| 2498 | + * @throws \EE_Error |
|
| 2499 | + */ |
|
| 2500 | + public function all_extra_meta_array($one_of_each_key = true) |
|
| 2501 | + { |
|
| 2502 | + $return_array = array(); |
|
| 2503 | + if ($one_of_each_key) { |
|
| 2504 | + $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2505 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2506 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2507 | + $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2508 | + } |
|
| 2509 | + } |
|
| 2510 | + } else { |
|
| 2511 | + $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2512 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2513 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2514 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2515 | + $return_array[$extra_meta_obj->key()] = array(); |
|
| 2516 | + } |
|
| 2517 | + $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + } |
|
| 2521 | + return $return_array; |
|
| 2522 | + } |
|
| 2523 | + |
|
| 2524 | + |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2528 | + * |
|
| 2529 | + * @return string |
|
| 2530 | + * @throws \EE_Error |
|
| 2531 | + */ |
|
| 2532 | + public function name() |
|
| 2533 | + { |
|
| 2534 | + //find a field that's not a text field |
|
| 2535 | + $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2536 | + if ($field_we_can_use) { |
|
| 2537 | + return $this->get($field_we_can_use->get_name()); |
|
| 2538 | + } else { |
|
| 2539 | + $first_few_properties = $this->model_field_array(); |
|
| 2540 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2541 | + $name_parts = array(); |
|
| 2542 | + foreach ($first_few_properties as $name => $value) { |
|
| 2543 | + $name_parts[] = "$name:$value"; |
|
| 2544 | + } |
|
| 2545 | + return implode(",", $name_parts); |
|
| 2546 | + } |
|
| 2547 | + } |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + |
|
| 2551 | + /** |
|
| 2552 | + * in_entity_map |
|
| 2553 | + * Checks if this model object has been proven to already be in the entity map |
|
| 2554 | + * |
|
| 2555 | + * @return boolean |
|
| 2556 | + * @throws \EE_Error |
|
| 2557 | + */ |
|
| 2558 | + public function in_entity_map() |
|
| 2559 | + { |
|
| 2560 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2561 | + //well, if we looked, did we find it in the entity map? |
|
| 2562 | + return true; |
|
| 2563 | + } else { |
|
| 2564 | + return false; |
|
| 2565 | + } |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * refresh_from_db |
|
| 2572 | + * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2573 | + * |
|
| 2574 | + * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2575 | + * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2576 | + */ |
|
| 2577 | + public function refresh_from_db() |
|
| 2578 | + { |
|
| 2579 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2580 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2581 | + } else { |
|
| 2582 | + //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2583 | + //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2584 | + //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2585 | + //absolutely nothing in it for this ID |
|
| 2586 | + if (WP_DEBUG) { |
|
| 2587 | + throw new EE_Error( |
|
| 2588 | + sprintf( |
|
| 2589 | + __('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.', |
|
| 2590 | + 'event_espresso'), |
|
| 2591 | + $this->ID(), |
|
| 2592 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2593 | + get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2594 | + ) |
|
| 2595 | + ); |
|
| 2596 | + } |
|
| 2597 | + } |
|
| 2598 | + } |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + /** |
|
| 2603 | + * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2604 | + * (probably a bad assumption they have made, oh well) |
|
| 2605 | + * |
|
| 2606 | + * @return string |
|
| 2607 | + */ |
|
| 2608 | + public function __toString() |
|
| 2609 | + { |
|
| 2610 | + try { |
|
| 2611 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2612 | + } catch (Exception $e) { |
|
| 2613 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2614 | + return ''; |
|
| 2615 | + } |
|
| 2616 | + } |
|
| 2617 | + |
|
| 2618 | + |
|
| 2619 | + |
|
| 2620 | + /** |
|
| 2621 | + * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2622 | + * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2623 | + * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2624 | + * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2625 | + * Instead, those related model objects should be directly serialized and stored. |
|
| 2626 | + * Eg, the following won't work: |
|
| 2627 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2628 | + * $att = $reg->attendee(); |
|
| 2629 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2630 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2631 | + * //END REQUEST |
|
| 2632 | + * //START NEXT REQUEST |
|
| 2633 | + * $reg = get_option( 'my_option' ); |
|
| 2634 | + * $reg->attendee()->save(); |
|
| 2635 | + * And would need to be replace with: |
|
| 2636 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2637 | + * $att = $reg->attendee(); |
|
| 2638 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2639 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2640 | + * //END REQUEST |
|
| 2641 | + * //START NEXT REQUEST |
|
| 2642 | + * $att = get_option( 'my_option' ); |
|
| 2643 | + * $att->save(); |
|
| 2644 | + * |
|
| 2645 | + * @return array |
|
| 2646 | + * @throws \EE_Error |
|
| 2647 | + */ |
|
| 2648 | + public function __sleep() |
|
| 2649 | + { |
|
| 2650 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2651 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2652 | + $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2653 | + if ( |
|
| 2654 | + $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2655 | + && $this->get_one_from_cache($relation_name)->ID() |
|
| 2656 | + ) { |
|
| 2657 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2658 | + } |
|
| 2659 | + } |
|
| 2660 | + } |
|
| 2661 | + $this->_props_n_values_provided_in_constructor = array(); |
|
| 2662 | + return array_keys(get_object_vars($this)); |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + |
|
| 2667 | + /** |
|
| 2668 | + * restore _props_n_values_provided_in_constructor |
|
| 2669 | + * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2670 | + * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2671 | + * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2672 | + */ |
|
| 2673 | + public function __wakeup() |
|
| 2674 | + { |
|
| 2675 | + $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2676 | + } |
|
| 2677 | 2677 | |
| 2678 | 2678 | |
| 2679 | 2679 | |
@@ -17,122 +17,122 @@ |
||
| 17 | 17 | class GatewayDataFormatter implements GatewayDataFormatterInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 22 | - * |
|
| 23 | - * @param \EEI_Payment $payment |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
| 27 | - { |
|
| 28 | - return apply_filters( |
|
| 29 | - 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
| 30 | - $payment->get_first_event_name(), |
|
| 31 | - $this, |
|
| 32 | - $payment |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 40 | - * |
|
| 41 | - * @param \EEI_Payment $payment |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
| 45 | - { |
|
| 46 | - return apply_filters( |
|
| 47 | - 'FHEE__EE_Gateway___partial_payment_desc', |
|
| 48 | - sprintf( |
|
| 49 | - __("Payment of %s for %s", "event_espresso"), |
|
| 50 | - $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
| 51 | - $payment->get_first_event_name() |
|
| 52 | - ), |
|
| 53 | - $this, |
|
| 54 | - $payment |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Gets the name to use for a line item when sending line items to the gateway |
|
| 62 | - * |
|
| 63 | - * @param \EEI_Line_Item $line_item |
|
| 64 | - * @param \EEI_Payment $payment |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 68 | - { |
|
| 69 | - return apply_filters( |
|
| 70 | - 'FHEE__EE_gateway___line_item_name', |
|
| 71 | - sprintf( |
|
| 72 | - _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
| 73 | - $line_item->name(), |
|
| 74 | - $line_item->ticket_event_name() |
|
| 75 | - ), |
|
| 76 | - $this, |
|
| 77 | - $line_item, |
|
| 78 | - $payment |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Gets the description to use for a line item when sending line items to the gateway |
|
| 86 | - * |
|
| 87 | - * @param \EEI_Line_Item $line_item |
|
| 88 | - * @param \EEI_Payment $payment |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 92 | - { |
|
| 93 | - return apply_filters( |
|
| 94 | - 'FHEE__EE_Gateway___line_item_desc', |
|
| 95 | - $line_item->desc(), |
|
| 96 | - $this, |
|
| 97 | - $line_item, |
|
| 98 | - $payment |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Gets the order description that should generally be sent to gateways |
|
| 106 | - * |
|
| 107 | - * @param \EEI_Payment $payment |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function formatOrderDescription(\EEI_Payment $payment) |
|
| 111 | - { |
|
| 112 | - return apply_filters( |
|
| 113 | - 'FHEE__EE_Gateway___order_description', |
|
| 114 | - sprintf( |
|
| 115 | - __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
| 116 | - get_bloginfo('name'), |
|
| 117 | - $payment->get_first_event_name() |
|
| 118 | - ), |
|
| 119 | - $this, |
|
| 120 | - $payment |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Formats the amount so it can generally be sent to gateways |
|
| 128 | - * |
|
| 129 | - * @param float $amount |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function formatCurrency($amount) |
|
| 133 | - { |
|
| 134 | - return number_format($amount, 2, '.', ''); |
|
| 135 | - } |
|
| 20 | + /** |
|
| 21 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 22 | + * |
|
| 23 | + * @param \EEI_Payment $payment |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
| 27 | + { |
|
| 28 | + return apply_filters( |
|
| 29 | + 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
| 30 | + $payment->get_first_event_name(), |
|
| 31 | + $this, |
|
| 32 | + $payment |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 40 | + * |
|
| 41 | + * @param \EEI_Payment $payment |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
| 45 | + { |
|
| 46 | + return apply_filters( |
|
| 47 | + 'FHEE__EE_Gateway___partial_payment_desc', |
|
| 48 | + sprintf( |
|
| 49 | + __("Payment of %s for %s", "event_espresso"), |
|
| 50 | + $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
| 51 | + $payment->get_first_event_name() |
|
| 52 | + ), |
|
| 53 | + $this, |
|
| 54 | + $payment |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Gets the name to use for a line item when sending line items to the gateway |
|
| 62 | + * |
|
| 63 | + * @param \EEI_Line_Item $line_item |
|
| 64 | + * @param \EEI_Payment $payment |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 68 | + { |
|
| 69 | + return apply_filters( |
|
| 70 | + 'FHEE__EE_gateway___line_item_name', |
|
| 71 | + sprintf( |
|
| 72 | + _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
| 73 | + $line_item->name(), |
|
| 74 | + $line_item->ticket_event_name() |
|
| 75 | + ), |
|
| 76 | + $this, |
|
| 77 | + $line_item, |
|
| 78 | + $payment |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Gets the description to use for a line item when sending line items to the gateway |
|
| 86 | + * |
|
| 87 | + * @param \EEI_Line_Item $line_item |
|
| 88 | + * @param \EEI_Payment $payment |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
| 92 | + { |
|
| 93 | + return apply_filters( |
|
| 94 | + 'FHEE__EE_Gateway___line_item_desc', |
|
| 95 | + $line_item->desc(), |
|
| 96 | + $this, |
|
| 97 | + $line_item, |
|
| 98 | + $payment |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Gets the order description that should generally be sent to gateways |
|
| 106 | + * |
|
| 107 | + * @param \EEI_Payment $payment |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function formatOrderDescription(\EEI_Payment $payment) |
|
| 111 | + { |
|
| 112 | + return apply_filters( |
|
| 113 | + 'FHEE__EE_Gateway___order_description', |
|
| 114 | + sprintf( |
|
| 115 | + __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
| 116 | + get_bloginfo('name'), |
|
| 117 | + $payment->get_first_event_name() |
|
| 118 | + ), |
|
| 119 | + $this, |
|
| 120 | + $payment |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Formats the amount so it can generally be sent to gateways |
|
| 128 | + * |
|
| 129 | + * @param float $amount |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function formatCurrency($amount) |
|
| 133 | + { |
|
| 134 | + return number_format($amount, 2, '.', ''); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | // End of file GatewayDataFormatter.php |
| 138 | 138 | // Location: core\services\gateways/GatewayDataFormatter.php |
| 139 | 139 | \ No newline at end of file |
@@ -16,65 +16,65 @@ |
||
| 16 | 16 | interface GatewayDataFormatterInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 21 | - * |
|
| 22 | - * @param \EEI_Payment $payment |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function formatPartialPaymentLineItemName(\EEI_Payment $payment); |
|
| 19 | + /** |
|
| 20 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 21 | + * |
|
| 22 | + * @param \EEI_Payment $payment |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function formatPartialPaymentLineItemName(\EEI_Payment $payment); |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 31 | - * |
|
| 32 | - * @param \EEI_Payment $payment |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment); |
|
| 29 | + /** |
|
| 30 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 31 | + * |
|
| 32 | + * @param \EEI_Payment $payment |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment); |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Gets the name to use for a line item when sending line items to the gateway |
|
| 41 | - * |
|
| 42 | - * @param \EEI_Line_Item $line_item |
|
| 43 | - * @param \EEI_Payment $payment |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
| 39 | + /** |
|
| 40 | + * Gets the name to use for a line item when sending line items to the gateway |
|
| 41 | + * |
|
| 42 | + * @param \EEI_Line_Item $line_item |
|
| 43 | + * @param \EEI_Payment $payment |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Gets the description to use for a line item when sending line items to the gateway |
|
| 52 | - * |
|
| 53 | - * @param \EEI_Line_Item $line_item |
|
| 54 | - * @param \EEI_Payment $payment |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
| 50 | + /** |
|
| 51 | + * Gets the description to use for a line item when sending line items to the gateway |
|
| 52 | + * |
|
| 53 | + * @param \EEI_Line_Item $line_item |
|
| 54 | + * @param \EEI_Payment $payment |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gets the order description that should generally be sent to gateways |
|
| 63 | - * |
|
| 64 | - * @param \EEI_Payment $payment |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function formatOrderDescription(\EEI_Payment $payment); |
|
| 61 | + /** |
|
| 62 | + * Gets the order description that should generally be sent to gateways |
|
| 63 | + * |
|
| 64 | + * @param \EEI_Payment $payment |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function formatOrderDescription(\EEI_Payment $payment); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Formats the amount so it can generally be sent to gateways |
|
| 73 | - * |
|
| 74 | - * @param float $amount |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function formatCurrency($amount); |
|
| 71 | + /** |
|
| 72 | + * Formats the amount so it can generally be sent to gateways |
|
| 73 | + * |
|
| 74 | + * @param float $amount |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function formatCurrency($amount); |
|
| 78 | 78 | } |
| 79 | 79 | // End of file GatewayDataFormatterInterface.php |
| 80 | 80 | // Location: core\services\payment_methods\gateways/GatewayDataFormatterInterface.php |
| 81 | 81 | \ No newline at end of file |