@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | /** @var string $default_hidden_inputs */ |
| 5 | 5 | ?> |
| 6 | 6 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 7 | - <?php echo apply_filters( 'FHEE__registration_page_attendee_information__attendee_information_pg', sprintf( __('In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', 'event_espresso'), '<br />', '<span class="asterisk">*</span>' )); ?> |
|
| 7 | + <?php echo apply_filters('FHEE__registration_page_attendee_information__attendee_information_pg', sprintf(__('In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', 'event_espresso'), '<br />', '<span class="asterisk">*</span>')); ?> |
|
| 8 | 8 | </p> |
| 9 | 9 | |
| 10 | 10 | <?php |
@@ -12,34 +12,34 @@ discard block |
||
| 12 | 12 | $prev_event = 0; |
| 13 | 13 | $prev_ticket = 0; |
| 14 | 14 | |
| 15 | -if ( count( $registrations ) > 0 ) { |
|
| 16 | - foreach ( $registrations as $registration ) { |
|
| 17 | - if ( $registration instanceof EE_Registration ) { |
|
| 15 | +if (count($registrations) > 0) { |
|
| 16 | + foreach ($registrations as $registration) { |
|
| 17 | + if ($registration instanceof EE_Registration) { |
|
| 18 | 18 | $att_nmbr++; |
| 19 | 19 | ?> |
| 20 | 20 | |
| 21 | - <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link();?>" class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID();?>"> |
|
| 21 | + <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
|
| 22 | 22 | |
| 23 | - <?php if ( $registration->event()->ID() !== $prev_event ) { ?> |
|
| 23 | + <?php if ($registration->event()->ID() !== $prev_event) { ?> |
|
| 24 | 24 | <h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr"> |
| 25 | 25 | <?php echo $registration->event()->name(); ?> |
| 26 | 26 | </h4> |
| 27 | 27 | <?php } ?> |
| 28 | - <?php if ( $registration->ticket()->ID() !== $prev_ticket ) { ?> |
|
| 29 | - <?php if ( ! $revisit ) { ?> |
|
| 28 | + <?php if ($registration->ticket()->ID() !== $prev_ticket) { ?> |
|
| 29 | + <?php if ( ! $revisit) { ?> |
|
| 30 | 30 | <div class="spco-ticket-info-dv small-text"> |
| 31 | - <h5><?php _e('Details', 'event_espresso');?></h5> |
|
| 31 | + <h5><?php _e('Details', 'event_espresso'); ?></h5> |
|
| 32 | 32 | <table> |
| 33 | 33 | <thead> |
| 34 | 34 | <tr> |
| 35 | - <th scope="col" width=""><?php _e('Name and Description', 'event_espresso');?></th> |
|
| 36 | - <th scope="col" width="7.5%" class="jst-rght"><?php _e('Qty', 'event_espresso');?></th> |
|
| 37 | - <th scope="col" width="17.5%" class="jst-rght"><?php _e('Price', 'event_espresso');?></th> |
|
| 38 | - <th scope="col" width="17.5%" class="jst-rght"><?php _e('Total', 'event_espresso');?></th> |
|
| 35 | + <th scope="col" width=""><?php _e('Name and Description', 'event_espresso'); ?></th> |
|
| 36 | + <th scope="col" width="7.5%" class="jst-rght"><?php _e('Qty', 'event_espresso'); ?></th> |
|
| 37 | + <th scope="col" width="17.5%" class="jst-rght"><?php _e('Price', 'event_espresso'); ?></th> |
|
| 38 | + <th scope="col" width="17.5%" class="jst-rght"><?php _e('Total', 'event_espresso'); ?></th> |
|
| 39 | 39 | </tr> |
| 40 | 40 | </thead> |
| 41 | 41 | <tbody> |
| 42 | - <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?> |
|
| 42 | + <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?> |
|
| 43 | 43 | </tbody> |
| 44 | 44 | </table> |
| 45 | 45 | </div> |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | <?php |
| 50 | 50 | // ATTENDEE QUESTIONS |
| 51 | - $reg_form = EE_Template_Layout::get_subform_name( $registration->reg_url_link() ); |
|
| 51 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
| 52 | 52 | echo ${$reg_form}; |
| 53 | 53 | ?> |
| 54 | 54 | |
@@ -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 |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | ? $form_input |
| 1060 | 1060 | : $form_input . '-' . $registration->reg_url_link(); |
| 1061 | 1061 | $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
| 1062 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1062 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1063 | 1063 | ? true |
| 1064 | 1064 | : false; |
| 1065 | 1065 | //rename form_inputs if they are EE_Attendee properties |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | // then attempt to copy them from the primary attendee |
| 1180 | 1180 | if ( |
| 1181 | 1181 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
| 1182 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1182 | + && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1183 | 1183 | ) { |
| 1184 | 1184 | return $this->checkout->primary_attendee_obj; |
| 1185 | 1185 | } |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | } |
| 1298 | 1298 | foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
| 1299 | 1299 | if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
| 1300 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1300 | + || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1301 | 1301 | ) { |
| 1302 | 1302 | $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
| 1303 | 1303 | $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,26 +1043,26 @@ 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 | // $answer_cache_id is the key used to find the EE_Answer we want |
| 1058 | 1057 | $answer_cache_id = $this->checkout->reg_url_link |
| 1059 | 1058 | ? $form_input |
| 1060 | - : $form_input . '-' . $registration->reg_url_link(); |
|
| 1061 | - $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
|
| 1062 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
| 1059 | + : $form_input.'-'.$registration->reg_url_link(); |
|
| 1060 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
| 1061 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
| 1063 | 1062 | ? true |
| 1064 | 1063 | : false; |
| 1065 | 1064 | //rename form_inputs if they are EE_Attendee properties |
| 1066 | - switch( (string)$form_input ) { |
|
| 1065 | + switch ((string) $form_input) { |
|
| 1067 | 1066 | |
| 1068 | 1067 | case 'state' : |
| 1069 | 1068 | case 'STA_ID' : |
@@ -1078,32 +1077,32 @@ discard block |
||
| 1078 | 1077 | break; |
| 1079 | 1078 | |
| 1080 | 1079 | default : |
| 1081 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1080 | + $ATT_input = 'ATT_'.$form_input; |
|
| 1082 | 1081 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
| 1083 | - $attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false; |
|
| 1084 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1082 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1083 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
| 1085 | 1084 | } |
| 1086 | 1085 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
| 1087 | 1086 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
| 1088 | 1087 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
| 1089 | 1088 | // if this form input has a corresponding attendee property |
| 1090 | - if ( $attendee_property ) { |
|
| 1091 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
| 1092 | - if ( $answer_is_obj ) { |
|
| 1089 | + if ($attendee_property) { |
|
| 1090 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
| 1091 | + if ($answer_is_obj) { |
|
| 1093 | 1092 | // and delete the corresponding answer since we won't be storing this data in that object |
| 1094 | - $registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' ); |
|
| 1095 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
| 1093 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
| 1094 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
| 1096 | 1095 | } |
| 1097 | 1096 | return true; |
| 1098 | - } elseif ( $answer_is_obj ) { |
|
| 1097 | + } elseif ($answer_is_obj) { |
|
| 1099 | 1098 | // save this data to the answer object |
| 1100 | - $this->_registration_answers[ $answer_cache_id ]->set_value( $input_value ); |
|
| 1101 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
| 1099 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
| 1100 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
| 1102 | 1101 | return $result !== false ? true : false; |
| 1103 | 1102 | } else { |
| 1104 | - foreach ( $this->_registration_answers as $answer ) { |
|
| 1105 | - if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) { |
|
| 1106 | - $answer->set_value( $input_value ); |
|
| 1103 | + foreach ($this->_registration_answers as $answer) { |
|
| 1104 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1105 | + $answer->set_value($input_value); |
|
| 1107 | 1106 | $result = $answer->save(); |
| 1108 | 1107 | return $result !== false ? true : false; |
| 1109 | 1108 | } |
@@ -1125,15 +1124,15 @@ discard block |
||
| 1125 | 1124 | $form_input = '', |
| 1126 | 1125 | $input_value = '' |
| 1127 | 1126 | ) { |
| 1128 | - if ( empty( $input_value ) ) { |
|
| 1127 | + if (empty($input_value)) { |
|
| 1129 | 1128 | // if the form input isn't marked as being required, then just return |
| 1130 | - if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) { |
|
| 1129 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1131 | 1130 | return true; |
| 1132 | 1131 | } |
| 1133 | - switch ( $form_input ) { |
|
| 1132 | + switch ($form_input) { |
|
| 1134 | 1133 | case 'fname' : |
| 1135 | 1134 | EE_Error::add_error( |
| 1136 | - __( 'First Name is a required value.', 'event_espresso' ), |
|
| 1135 | + __('First Name is a required value.', 'event_espresso'), |
|
| 1137 | 1136 | __FILE__, |
| 1138 | 1137 | __FUNCTION__, |
| 1139 | 1138 | __LINE__ |
@@ -1142,7 +1141,7 @@ discard block |
||
| 1142 | 1141 | break; |
| 1143 | 1142 | case 'lname' : |
| 1144 | 1143 | EE_Error::add_error( |
| 1145 | - __( 'Last Name is a required value.', 'event_espresso' ), |
|
| 1144 | + __('Last Name is a required value.', 'event_espresso'), |
|
| 1146 | 1145 | __FILE__, |
| 1147 | 1146 | __FUNCTION__, |
| 1148 | 1147 | __LINE__ |
@@ -1151,7 +1150,7 @@ discard block |
||
| 1151 | 1150 | break; |
| 1152 | 1151 | case 'email' : |
| 1153 | 1152 | EE_Error::add_error( |
| 1154 | - __( 'Please enter a valid email address.', 'event_espresso' ), |
|
| 1153 | + __('Please enter a valid email address.', 'event_espresso'), |
|
| 1155 | 1154 | __FILE__, |
| 1156 | 1155 | __FUNCTION__, |
| 1157 | 1156 | __LINE__ |
@@ -1173,30 +1172,30 @@ discard block |
||
| 1173 | 1172 | * @return boolean|EE_Attendee |
| 1174 | 1173 | * @throws \EE_Error |
| 1175 | 1174 | */ |
| 1176 | - private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
| 1175 | + private function _find_existing_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
| 1177 | 1176 | $existing_attendee = null; |
| 1178 | 1177 | // if none of the critical properties are set in the incoming attendee data... |
| 1179 | 1178 | // then attempt to copy them from the primary attendee |
| 1180 | 1179 | if ( |
| 1181 | 1180 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
| 1182 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
| 1181 | + && ! isset($attendee_data['ATT_fname'], $attendee_data['ATT_email']) |
|
| 1183 | 1182 | ) { |
| 1184 | 1183 | return $this->checkout->primary_attendee_obj; |
| 1185 | 1184 | } |
| 1186 | 1185 | // does this attendee already exist in the db ? |
| 1187 | 1186 | // we're searching using a combination of first name, last name, AND email address |
| 1188 | - $ATT_fname = isset( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_fname'] ) |
|
| 1187 | + $ATT_fname = isset($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_fname']) |
|
| 1189 | 1188 | ? $attendee_data['ATT_fname'] |
| 1190 | 1189 | : ''; |
| 1191 | - $ATT_lname = isset( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_lname'] ) |
|
| 1190 | + $ATT_lname = isset($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_lname']) |
|
| 1192 | 1191 | ? $attendee_data['ATT_lname'] |
| 1193 | 1192 | : ''; |
| 1194 | - $ATT_email = isset( $attendee_data['ATT_email'] ) && ! empty( $attendee_data['ATT_email'] ) |
|
| 1193 | + $ATT_email = isset($attendee_data['ATT_email']) && ! empty($attendee_data['ATT_email']) |
|
| 1195 | 1194 | ? $attendee_data['ATT_email'] |
| 1196 | 1195 | : ''; |
| 1197 | 1196 | // but only if those have values |
| 1198 | - if ( $ATT_fname && $ATT_lname && $ATT_email ) { |
|
| 1199 | - $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( array( |
|
| 1197 | + if ($ATT_fname && $ATT_lname && $ATT_email) { |
|
| 1198 | + $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(array( |
|
| 1200 | 1199 | 'ATT_fname' => $ATT_fname, |
| 1201 | 1200 | 'ATT_lname' => $ATT_lname, |
| 1202 | 1201 | 'ATT_email' => $ATT_email |
@@ -1220,13 +1219,13 @@ discard block |
||
| 1220 | 1219 | * @return \EE_Attendee |
| 1221 | 1220 | * @throws \EE_Error |
| 1222 | 1221 | */ |
| 1223 | - private function _update_existing_attendee_data( EE_Attendee $existing_attendee, $attendee_data = array() ) { |
|
| 1222 | + private function _update_existing_attendee_data(EE_Attendee $existing_attendee, $attendee_data = array()) { |
|
| 1224 | 1223 | // first remove fname, lname, and email from attendee data |
| 1225 | - $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
| 1224 | + $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1226 | 1225 | // now loop thru what's left and add to attendee CPT |
| 1227 | - foreach ( $attendee_data as $property_name => $property_value ) { |
|
| 1228 | - if ( ! in_array( $property_name, $dont_set ) && EEM_Attendee::instance()->has_field( $property_name )) { |
|
| 1229 | - $existing_attendee->set( $property_name, $property_value ); |
|
| 1226 | + foreach ($attendee_data as $property_name => $property_value) { |
|
| 1227 | + if ( ! in_array($property_name, $dont_set) && EEM_Attendee::instance()->has_field($property_name)) { |
|
| 1228 | + $existing_attendee->set($property_name, $property_value); |
|
| 1230 | 1229 | } |
| 1231 | 1230 | } |
| 1232 | 1231 | // better save that now |
@@ -1244,11 +1243,11 @@ discard block |
||
| 1244 | 1243 | * @return void |
| 1245 | 1244 | * @throws \EE_Error |
| 1246 | 1245 | */ |
| 1247 | - private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) { |
|
| 1246 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) { |
|
| 1248 | 1247 | // add relation to attendee |
| 1249 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
| 1250 | - $registration->set_attendee_id( $attendee->ID() ); |
|
| 1251 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
| 1248 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1249 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1250 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1252 | 1251 | } |
| 1253 | 1252 | |
| 1254 | 1253 | |
@@ -1260,10 +1259,10 @@ discard block |
||
| 1260 | 1259 | * @return void |
| 1261 | 1260 | * @throws \EE_Error |
| 1262 | 1261 | */ |
| 1263 | - private function _associate_registration_with_transaction( EE_Registration $registration ) { |
|
| 1262 | + private function _associate_registration_with_transaction(EE_Registration $registration) { |
|
| 1264 | 1263 | // add relation to attendee |
| 1265 | - $this->checkout->transaction->_add_relation_to( $registration, 'Registration' ); |
|
| 1266 | - $this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration ); |
|
| 1264 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1265 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1267 | 1266 | } |
| 1268 | 1267 | |
| 1269 | 1268 | |
@@ -1276,14 +1275,14 @@ discard block |
||
| 1276 | 1275 | * @return array |
| 1277 | 1276 | * @throws \EE_Error |
| 1278 | 1277 | */ |
| 1279 | - private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) { |
|
| 1278 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) { |
|
| 1280 | 1279 | // bare minimum critical details include first name, last name, email address |
| 1281 | - $critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
| 1280 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1282 | 1281 | // add address info to critical details? |
| 1283 | - if ( apply_filters( |
|
| 1282 | + if (apply_filters( |
|
| 1284 | 1283 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
| 1285 | 1284 | false |
| 1286 | - ) ) { |
|
| 1285 | + )) { |
|
| 1287 | 1286 | $address_details = array( |
| 1288 | 1287 | 'ATT_address', |
| 1289 | 1288 | 'ATT_address2', |
@@ -1293,13 +1292,13 @@ discard block |
||
| 1293 | 1292 | 'ATT_zip', |
| 1294 | 1293 | 'ATT_phone' |
| 1295 | 1294 | ); |
| 1296 | - $critical_attendee_details = array_merge( $critical_attendee_details, $address_details ); |
|
| 1295 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1297 | 1296 | } |
| 1298 | - foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
|
| 1299 | - if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1300 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
| 1297 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1298 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
| 1299 | + || empty($attendee_data[$critical_attendee_detail]) |
|
| 1301 | 1300 | ) { |
| 1302 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
| 1301 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
| 1303 | 1302 | $critical_attendee_detail |
| 1304 | 1303 | ); |
| 1305 | 1304 | } |
@@ -1317,11 +1316,11 @@ discard block |
||
| 1317 | 1316 | * @return \EE_Attendee |
| 1318 | 1317 | * @throws \EE_Error |
| 1319 | 1318 | */ |
| 1320 | - private function _create_new_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
| 1319 | + private function _create_new_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
| 1321 | 1320 | // create new attendee object |
| 1322 | - $new_attendee = EE_Attendee::new_instance( $attendee_data ); |
|
| 1321 | + $new_attendee = EE_Attendee::new_instance($attendee_data); |
|
| 1323 | 1322 | // set author to event creator |
| 1324 | - $new_attendee->set( 'ATT_author', $registration->event()->wp_user() ); |
|
| 1323 | + $new_attendee->set('ATT_author', $registration->event()->wp_user()); |
|
| 1325 | 1324 | $new_attendee->save(); |
| 1326 | 1325 | return $new_attendee; |
| 1327 | 1326 | } |
@@ -1338,7 +1337,7 @@ discard block |
||
| 1338 | 1337 | */ |
| 1339 | 1338 | public function update_reg_step() { |
| 1340 | 1339 | // save everything |
| 1341 | - if ( $this->process_reg_step() ) { |
|
| 1340 | + if ($this->process_reg_step()) { |
|
| 1342 | 1341 | $this->checkout->redirect = true; |
| 1343 | 1342 | $this->checkout->redirect_url = add_query_arg( |
| 1344 | 1343 | array( |
@@ -1347,7 +1346,7 @@ discard block |
||
| 1347 | 1346 | ), |
| 1348 | 1347 | $this->checkout->thank_you_page_url |
| 1349 | 1348 | ); |
| 1350 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
| 1349 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1351 | 1350 | return true; |
| 1352 | 1351 | } |
| 1353 | 1352 | return false; |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | * @param string $table_column |
| 16 | 16 | * @param string $nicename |
| 17 | 17 | * @param bool $nullable |
| 18 | - * @param null $default_value |
|
| 18 | + * @param string|null $default_value |
|
| 19 | 19 | */ |
| 20 | 20 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 21 | 21 | { |
@@ -11,28 +11,28 @@ |
||
| 11 | 11 | abstract class EE_DB_Only_Field_Base extends EE_Model_Field_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param string $table_column |
|
| 16 | - * @param string $nicename |
|
| 17 | - * @param bool $nullable |
|
| 18 | - * @param null $default_value |
|
| 19 | - */ |
|
| 20 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 21 | - { |
|
| 22 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 23 | - $this->setSchemaReadOnly(true); |
|
| 24 | - } |
|
| 14 | + /** |
|
| 15 | + * @param string $table_column |
|
| 16 | + * @param string $nicename |
|
| 17 | + * @param bool $nullable |
|
| 18 | + * @param null $default_value |
|
| 19 | + */ |
|
| 20 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 21 | + { |
|
| 22 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 23 | + $this->setSchemaReadOnly(true); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * All these children classes are for the db-only (meaning, we should select them |
|
| 29 | - * on get_all queries, update, delete, and will still want to set their default value |
|
| 30 | - * on inserts, but the model object won't have reference to these fields) |
|
| 31 | - * |
|
| 32 | - * @return boolean |
|
| 33 | - */ |
|
| 34 | - function is_db_only_field() |
|
| 35 | - { |
|
| 36 | - return true; |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * All these children classes are for the db-only (meaning, we should select them |
|
| 29 | + * on get_all queries, update, delete, and will still want to set their default value |
|
| 30 | + * on inserts, but the model object won't have reference to these fields) |
|
| 31 | + * |
|
| 32 | + * @return boolean |
|
| 33 | + */ |
|
| 34 | + function is_db_only_field() |
|
| 35 | + { |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @param string $table_column |
| 13 | 13 | * @param string $nicename |
| 14 | 14 | * @param bool $nullable |
| 15 | - * @param null $default_value |
|
| 15 | + * @param integer|null $default_value |
|
| 16 | 16 | */ |
| 17 | 17 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 18 | 18 | { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
| 28 | 28 | * Returns a float |
| 29 | 29 | * |
| 30 | - * @param type $value_inputted_for_field_on_model_object |
|
| 30 | + * @param string $value_inputted_for_field_on_model_object |
|
| 31 | 31 | * @return float |
| 32 | 32 | */ |
| 33 | 33 | function prepare_for_set($value_inputted_for_field_on_model_object) |
@@ -8,64 +8,64 @@ |
||
| 8 | 8 | class EE_Float_Field extends EE_Model_Field_Base |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @param string $table_column |
|
| 13 | - * @param string $nicename |
|
| 14 | - * @param bool $nullable |
|
| 15 | - * @param null $default_value |
|
| 16 | - */ |
|
| 17 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | - { |
|
| 19 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | - $this->setSchemaType('number'); |
|
| 21 | - } |
|
| 11 | + /** |
|
| 12 | + * @param string $table_column |
|
| 13 | + * @param string $nicename |
|
| 14 | + * @param bool $nullable |
|
| 15 | + * @param null $default_value |
|
| 16 | + */ |
|
| 17 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | + { |
|
| 19 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | + $this->setSchemaType('number'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
| 26 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
| 27 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 28 | - * Returns a float |
|
| 29 | - * |
|
| 30 | - * @param type $value_inputted_for_field_on_model_object |
|
| 31 | - * @return float |
|
| 32 | - */ |
|
| 33 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 34 | - { |
|
| 24 | + /** |
|
| 25 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
| 26 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
| 27 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 28 | + * Returns a float |
|
| 29 | + * |
|
| 30 | + * @param type $value_inputted_for_field_on_model_object |
|
| 31 | + * @return float |
|
| 32 | + */ |
|
| 33 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 34 | + { |
|
| 35 | 35 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
| 36 | - //remove whitespaces and thousands separators |
|
| 37 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
| 38 | - $value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds), |
|
| 39 | - "", $value_inputted_for_field_on_model_object); |
|
| 36 | + //remove whitespaces and thousands separators |
|
| 37 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
| 38 | + $value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds), |
|
| 39 | + "", $value_inputted_for_field_on_model_object); |
|
| 40 | 40 | //echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
| 41 | 41 | //normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
| 42 | - $value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".", |
|
| 43 | - $value_inputted_for_field_on_model_object); |
|
| 42 | + $value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".", |
|
| 43 | + $value_inputted_for_field_on_model_object); |
|
| 44 | 44 | //echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
| 45 | 45 | //double-check there's absolutely nothing left on this string besides numbers |
| 46 | - $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", |
|
| 47 | - $value_inputted_for_field_on_model_object); |
|
| 48 | - } |
|
| 46 | + $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", |
|
| 47 | + $value_inputted_for_field_on_model_object); |
|
| 48 | + } |
|
| 49 | 49 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
| 50 | - return floatval($value_inputted_for_field_on_model_object); |
|
| 51 | - } |
|
| 50 | + return floatval($value_inputted_for_field_on_model_object); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
| 55 | - * |
|
| 56 | - * @param float $value_on_field_to_be_outputted |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 60 | - { |
|
| 61 | - $EE = EE_Registry::instance(); |
|
| 62 | - return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk, |
|
| 63 | - $EE->CFG->currency->thsnds); |
|
| 64 | - } |
|
| 53 | + /** |
|
| 54 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
| 55 | + * |
|
| 56 | + * @param float $value_on_field_to_be_outputted |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 60 | + { |
|
| 61 | + $EE = EE_Registry::instance(); |
|
| 62 | + return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk, |
|
| 63 | + $EE->CFG->currency->thsnds); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 67 | - { |
|
| 66 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 67 | + { |
|
| 68 | 68 | // echo "prepare for set from db of ";d($value_found_in_db_for_model_object); |
| 69 | - return floatval($value_found_in_db_for_model_object); |
|
| 70 | - } |
|
| 69 | + return floatval($value_found_in_db_for_model_object); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @param string $table_column name fo column for field |
| 9 | 9 | * @param string $nicename should eb internationalized with __('blah','event_espresso') |
| 10 | 10 | * @param boolean $nullable |
| 11 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
| 11 | + * @param integer|null $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
| 12 | 12 | * dbe a string |
| 13 | 13 | * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
| 14 | 14 | * "EEM_" |
@@ -4,37 +4,37 @@ |
||
| 4 | 4 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
| 5 | 5 | { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @param string $table_column name fo column for field |
|
| 9 | - * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
| 10 | - * @param boolean $nullable |
|
| 11 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
| 12 | - * dbe a string |
|
| 13 | - * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
| 14 | - * "EEM_" |
|
| 15 | - */ |
|
| 16 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
| 17 | - { |
|
| 18 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
| 19 | - $this->setSchemaType('integer'); |
|
| 20 | - } |
|
| 7 | + /** |
|
| 8 | + * @param string $table_column name fo column for field |
|
| 9 | + * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
| 10 | + * @param boolean $nullable |
|
| 11 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
| 12 | + * dbe a string |
|
| 13 | + * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
| 14 | + * "EEM_" |
|
| 15 | + */ |
|
| 16 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
| 17 | + { |
|
| 18 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
| 19 | + $this->setSchemaType('integer'); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
| 25 | - * @return int |
|
| 26 | - */ |
|
| 27 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 28 | - { |
|
| 29 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 30 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 31 | - } |
|
| 32 | - return absint($value_inputted_for_field_on_model_object); |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
| 25 | + * @return int |
|
| 26 | + */ |
|
| 27 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 28 | + { |
|
| 29 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 30 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 31 | + } |
|
| 32 | + return absint($value_inputted_for_field_on_model_object); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 36 | - { |
|
| 37 | - return intval($value_found_in_db_for_model_object); |
|
| 38 | - } |
|
| 35 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 36 | + { |
|
| 37 | + return intval($value_found_in_db_for_model_object); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | * @param string $table_column |
| 20 | 20 | * @param string $nicename |
| 21 | 21 | * @param bool $nullable |
| 22 | - * @param null $default_value |
|
| 22 | + * @param string $default_value |
|
| 23 | 23 | */ |
| 24 | 24 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 25 | 25 | { |
@@ -15,57 +15,57 @@ |
||
| 15 | 15 | class EE_Full_HTML_Field extends EE_Text_Field_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param string $table_column |
|
| 20 | - * @param string $nicename |
|
| 21 | - * @param bool $nullable |
|
| 22 | - * @param null $default_value |
|
| 23 | - */ |
|
| 24 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 25 | - { |
|
| 26 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | - $this->setSchemaType('object'); |
|
| 28 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $table_column |
|
| 20 | + * @param string $nicename |
|
| 21 | + * @param bool $nullable |
|
| 22 | + * @param null $default_value |
|
| 23 | + */ |
|
| 24 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 25 | + { |
|
| 26 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | + $this->setSchemaType('object'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 33 | - * |
|
| 34 | - * @param type $value_on_field_to_be_outputted |
|
| 35 | - * @param type $schema |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 39 | - { |
|
| 40 | - if ($schema == 'form_input') { |
|
| 41 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 42 | - } elseif ($schema == 'no_wpautop') { |
|
| 43 | - return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 44 | - } else { |
|
| 45 | - return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + /** |
|
| 32 | + * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 33 | + * |
|
| 34 | + * @param type $value_on_field_to_be_outputted |
|
| 35 | + * @param type $schema |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 39 | + { |
|
| 40 | + if ($schema == 'form_input') { |
|
| 41 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 42 | + } elseif ($schema == 'no_wpautop') { |
|
| 43 | + return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 44 | + } else { |
|
| 45 | + return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | - public function getSchemaProperties() |
|
| 52 | - { |
|
| 53 | - return array( |
|
| 54 | - 'raw' => array( |
|
| 55 | - 'description' => sprintf( |
|
| 56 | - __('%s - the value in the database.', 'event_espresso'), |
|
| 57 | - $this->get_nicename() |
|
| 58 | - ), |
|
| 59 | - 'type' => 'string' |
|
| 60 | - ), |
|
| 61 | - 'rendered' => array( |
|
| 62 | - 'description' => sprintf( |
|
| 63 | - __('%s - transformed for display.', 'event_espresso'), |
|
| 64 | - $this->get_nicename() |
|
| 65 | - ), |
|
| 66 | - 'type' => 'string', |
|
| 67 | - 'readonly' => true |
|
| 68 | - ) |
|
| 69 | - ); |
|
| 70 | - } |
|
| 51 | + public function getSchemaProperties() |
|
| 52 | + { |
|
| 53 | + return array( |
|
| 54 | + 'raw' => array( |
|
| 55 | + 'description' => sprintf( |
|
| 56 | + __('%s - the value in the database.', 'event_espresso'), |
|
| 57 | + $this->get_nicename() |
|
| 58 | + ), |
|
| 59 | + 'type' => 'string' |
|
| 60 | + ), |
|
| 61 | + 'rendered' => array( |
|
| 62 | + 'description' => sprintf( |
|
| 63 | + __('%s - transformed for display.', 'event_espresso'), |
|
| 64 | + $this->get_nicename() |
|
| 65 | + ), |
|
| 66 | + 'type' => 'string', |
|
| 67 | + 'readonly' => true |
|
| 68 | + ) |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * @param string $table_column |
| 12 | 12 | * @param string $nicename |
| 13 | 13 | * @param bool $nullable |
| 14 | - * @param null $default_value |
|
| 14 | + * @param integer|null $default_value |
|
| 15 | 15 | */ |
| 16 | 16 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 17 | 17 | { |
@@ -7,26 +7,26 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class EE_Integer_Field extends EE_Model_Field_Base |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param string $table_column |
|
| 12 | - * @param string $nicename |
|
| 13 | - * @param bool $nullable |
|
| 14 | - * @param null $default_value |
|
| 15 | - */ |
|
| 16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | - { |
|
| 18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | - $this->setSchemaType('integer'); |
|
| 20 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $table_column |
|
| 12 | + * @param string $nicename |
|
| 13 | + * @param bool $nullable |
|
| 14 | + * @param null $default_value |
|
| 15 | + */ |
|
| 16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | + { |
|
| 18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | + $this->setSchemaType('integer'); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 24 | - { |
|
| 25 | - return intval($value_inputted_for_field_on_model_object); |
|
| 26 | - } |
|
| 23 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 24 | + { |
|
| 25 | + return intval($value_inputted_for_field_on_model_object); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
| 29 | - { |
|
| 30 | - return intval($value_inputted_for_field_on_model_object); |
|
| 31 | - } |
|
| 28 | + function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
| 29 | + { |
|
| 30 | + return intval($value_inputted_for_field_on_model_object); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -582,7 +582,7 @@ |
||
| 582 | 582 | /** |
| 583 | 583 | * Validates that the incoming format is an allowable string to use for the _schema_format property |
| 584 | 584 | * @throws InvalidArgumentException |
| 585 | - * @param $format |
|
| 585 | + * @param string $format |
|
| 586 | 586 | */ |
| 587 | 587 | private function validateSchemaFormat($format) |
| 588 | 588 | { |
@@ -21,602 +21,601 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class EE_Model_Field_Base implements HasSchemaInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * The alias for the table the column belongs to. |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $_table_alias; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The actual db column name for the table |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $_table_column; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * The authoritative name for the table column (used by client code to reference the field). |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $_name; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * A description for the field. |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $_nicename; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Whether the field is nullable or not |
|
| 53 | - * @var bool |
|
| 54 | - */ |
|
| 55 | - protected $_nullable; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * What the default value for the field should be. |
|
| 60 | - * @var mixed |
|
| 61 | - */ |
|
| 62 | - protected $_default_value; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Other configuration for the field |
|
| 67 | - * @var mixed |
|
| 68 | - */ |
|
| 69 | - protected $_other_config; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * The name of the model this field is instantiated for. |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - protected $_model_name; |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This should be a json-schema valid data type for the field. |
|
| 81 | - * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - private $_schema_type = 'string'; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * If the schema has a defined format then it should be defined via this property. |
|
| 89 | - * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 92 | - private $_schema_format = ''; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Indicates that the value of the field is managed exclusively by the server/model and not something |
|
| 97 | - * settable by client code. |
|
| 98 | - * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4 |
|
| 99 | - * @var bool |
|
| 100 | - */ |
|
| 101 | - private $_schema_readonly = false; |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param string $table_column |
|
| 106 | - * @param string $nicename |
|
| 107 | - * @param bool $nullable |
|
| 108 | - * @param null $default_value |
|
| 109 | - */ |
|
| 110 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 111 | - { |
|
| 112 | - $this->_table_column = $table_column; |
|
| 113 | - $this->_nicename = $nicename; |
|
| 114 | - $this->_nullable = $nullable; |
|
| 115 | - $this->_default_value = $default_value; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param $table_alias |
|
| 121 | - * @param $name |
|
| 122 | - * @param $model_name |
|
| 123 | - */ |
|
| 124 | - public function _construct_finalize($table_alias, $name, $model_name) |
|
| 125 | - { |
|
| 126 | - $this->_table_alias = $table_alias; |
|
| 127 | - $this->_name = $name; |
|
| 128 | - $this->_model_name = $model_name; |
|
| 129 | - /** |
|
| 130 | - * allow for changing the defaults |
|
| 131 | - */ |
|
| 132 | - $this->_nicename = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename', |
|
| 133 | - $this->_nicename, $this); |
|
| 134 | - $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value', |
|
| 135 | - $this->_default_value, $this); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function get_table_alias() |
|
| 139 | - { |
|
| 140 | - return $this->_table_alias; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function get_table_column() |
|
| 144 | - { |
|
| 145 | - return $this->_table_column; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime' |
|
| 150 | - * |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_model_name() |
|
| 154 | - { |
|
| 155 | - return $this->_model_name; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function get_name() |
|
| 163 | - { |
|
| 164 | - if ($this->_name) { |
|
| 165 | - return $this->_name; |
|
| 166 | - } else { |
|
| 167 | - throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", |
|
| 168 | - "event_espresso"), get_class($this))); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function get_nicename() |
|
| 173 | - { |
|
| 174 | - return $this->_nicename; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function is_nullable() |
|
| 178 | - { |
|
| 179 | - return $this->_nullable; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * returns whether this field is an auto-increment field or not. If it is, then |
|
| 184 | - * on insertion it can be null. However, on updates it must be present. |
|
| 185 | - * |
|
| 186 | - * @return boolean |
|
| 187 | - */ |
|
| 188 | - public function is_auto_increment() |
|
| 189 | - { |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * The default value in the model object's value domain. See lengthy comment about |
|
| 195 | - * value domains at the top of EEM_Base |
|
| 196 | - * |
|
| 197 | - * @return mixed |
|
| 198 | - */ |
|
| 199 | - public function get_default_value() |
|
| 200 | - { |
|
| 201 | - return $this->_default_value; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the table alias joined to the table column, however this isn't the right |
|
| 206 | - * table alias if the aliased table is being joined to. In that case, you can use |
|
| 207 | - * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias |
|
| 208 | - * in the current query |
|
| 209 | - * |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function get_qualified_column() |
|
| 213 | - { |
|
| 214 | - return $this->get_table_alias() . "." . $this->get_table_column(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * When get() is called on a model object (eg EE_Event), before returning its value, |
|
| 219 | - * call this function on it, allowing us to customize the returned value based on |
|
| 220 | - * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default, |
|
| 221 | - * we simply return it. |
|
| 222 | - * |
|
| 223 | - * @param mixed $value_of_field_on_model_object |
|
| 224 | - * @return mixed |
|
| 225 | - */ |
|
| 226 | - public function prepare_for_get($value_of_field_on_model_object) |
|
| 227 | - { |
|
| 228 | - return $value_of_field_on_model_object; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * When inserting or updating a field on a model object, run this function on each |
|
| 233 | - * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc. |
|
| 234 | - * By default, we do nothing. |
|
| 235 | - * |
|
| 236 | - * @param mixed $value_of_field_on_model_object |
|
| 237 | - * @return mixed |
|
| 238 | - */ |
|
| 239 | - public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 240 | - { |
|
| 241 | - return $value_of_field_on_model_object; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
| 246 | - * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
| 247 | - * By default, we do nothing. |
|
| 248 | - * |
|
| 249 | - * @param mixed $value_inputted_for_field_on_model_object |
|
| 250 | - * @return mixed |
|
| 251 | - */ |
|
| 252 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 253 | - { |
|
| 254 | - return $value_inputted_for_field_on_model_object; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * When instantiating a model object from DB results, this function is called before setting each field. |
|
| 260 | - * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that |
|
| 261 | - * is the one child classes will most often define. |
|
| 262 | - * |
|
| 263 | - * @param mixed $value_found_in_db_for_model_object |
|
| 264 | - * @return mixed |
|
| 265 | - */ |
|
| 266 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 267 | - { |
|
| 268 | - return $this->prepare_for_set($value_found_in_db_for_model_object); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a |
|
| 273 | - * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12, |
|
| 274 | - * 2013, at 3:23pm" instead of |
|
| 275 | - * "8765678632", or any other modifications to how the value should be displayed, but not modified itself. |
|
| 276 | - * |
|
| 277 | - * @param mixed $value_on_field_to_be_outputted |
|
| 278 | - * @return mixed |
|
| 279 | - */ |
|
| 280 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
| 281 | - { |
|
| 282 | - return $value_on_field_to_be_outputted; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns whatever is set as the nicename for the object. |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function getSchemaDescription() |
|
| 291 | - { |
|
| 292 | - return $this->get_nicename(); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Returns whatever is set as the $_schema_type property for the object. |
|
| 298 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 299 | - * @return string|array |
|
| 300 | - */ |
|
| 301 | - public function getSchemaType() |
|
| 302 | - { |
|
| 303 | - if ($this->is_nullable()) { |
|
| 304 | - $this->_schema_type = (array) $this->_schema_type; |
|
| 305 | - if (! in_array('null', $this->_schema_type)) { |
|
| 306 | - $this->_schema_type[] = 'null'; |
|
| 307 | - }; |
|
| 308 | - } |
|
| 309 | - return $this->_schema_type; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Sets the _schema_type property. Child classes should call this in their constructors to override the default state |
|
| 315 | - * for this property. |
|
| 316 | - * @param string|array $type |
|
| 317 | - * @throws InvalidArgumentException |
|
| 318 | - */ |
|
| 319 | - protected function setSchemaType($type) |
|
| 320 | - { |
|
| 321 | - $this->validateSchemaType($type); |
|
| 322 | - $this->_schema_type = $type; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 328 | - * this method and return the properties for the schema. |
|
| 329 | - * |
|
| 330 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 331 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 332 | - * |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - public function getSchemaProperties() |
|
| 336 | - { |
|
| 337 | - return array(); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * If a child class has enum values, they should override this method and provide a simple array |
|
| 343 | - * of the enum values. |
|
| 344 | - |
|
| 345 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 346 | - * are set on the instantiated object that could be filtered after construct. |
|
| 347 | - * |
|
| 348 | - * @return array |
|
| 349 | - */ |
|
| 350 | - public function getSchemaEnum() |
|
| 351 | - { |
|
| 352 | - return array(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * This returns the value of the $_schema_format property on the object. |
|
| 358 | - * @return string |
|
| 359 | - */ |
|
| 360 | - public function getSchemaFormat() |
|
| 361 | - { |
|
| 362 | - return $this->_schema_format; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Sets the schema format property. |
|
| 368 | - * @throws InvalidArgumentException |
|
| 369 | - * @param string $format |
|
| 370 | - */ |
|
| 371 | - protected function setSchemaFormat($format) |
|
| 372 | - { |
|
| 373 | - $this->validateSchemaFormat($format); |
|
| 374 | - $this->_schema_format = $format; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * This returns the value of the $_schema_readonly property on the object. |
|
| 380 | - * @return bool |
|
| 381 | - */ |
|
| 382 | - public function getSchemaReadonly() |
|
| 383 | - { |
|
| 384 | - return $this->_schema_readonly; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * This sets the value for the $_schema_readonly property. |
|
| 390 | - * @param bool $readonly (only explicit boolean values are accepted) |
|
| 391 | - */ |
|
| 392 | - protected function setSchemaReadOnly($readonly) |
|
| 393 | - { |
|
| 394 | - if (! is_bool($readonly)) { |
|
| 395 | - throw new InvalidArgumentException( |
|
| 396 | - sprintf( |
|
| 397 | - esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'), |
|
| 398 | - print_r($readonly, true) |
|
| 399 | - ) |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->_schema_readonly = $readonly; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Return `%d`, `%s` or `%f` to indicate the data type for the field. |
|
| 411 | - * @uses _get_wpdb_data_type() |
|
| 412 | - * |
|
| 413 | - * @return string |
|
| 414 | - */ |
|
| 415 | - public function get_wpdb_data_type() |
|
| 416 | - { |
|
| 417 | - return $this->_get_wpdb_data_type(); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries. |
|
| 423 | - * @param string $type Included if a specific type is requested. |
|
| 424 | - * @uses get_schema_type() |
|
| 425 | - * @return string |
|
| 426 | - */ |
|
| 427 | - protected function _get_wpdb_data_type($type='') |
|
| 428 | - { |
|
| 429 | - $type = empty($type) ? $this->getSchemaType() : $type; |
|
| 430 | - |
|
| 431 | - //if type is an array, then different parsing is required. |
|
| 432 | - if (is_array($type)) { |
|
| 433 | - return $this->_get_wpdb_data_type_for_type_array($type); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - $wpdb_type = '%s'; |
|
| 437 | - switch ($type) { |
|
| 438 | - case 'number': |
|
| 439 | - $wpdb_type = '%f'; |
|
| 440 | - break; |
|
| 441 | - case 'integer': |
|
| 442 | - case 'boolean': |
|
| 443 | - $wpdb_type = '%d'; |
|
| 444 | - break; |
|
| 445 | - case 'object': |
|
| 446 | - $properties = $this->getSchemaProperties(); |
|
| 447 | - if (isset($properties['raw'], $properties['raw']['type'])) { |
|
| 448 | - $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']); |
|
| 449 | - } |
|
| 450 | - break; //leave at default |
|
| 451 | - } |
|
| 452 | - return $wpdb_type; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - protected function _get_wpdb_data_type_for_type_array($type) |
|
| 458 | - { |
|
| 459 | - $type = (array) $type; |
|
| 460 | - //first let's flip because then we can do a faster key check |
|
| 461 | - $type = array_flip($type); |
|
| 462 | - |
|
| 463 | - //check for things that mean '%s' |
|
| 464 | - if (isset($type['string'],$type['object'],$type['array'])) { |
|
| 465 | - return '%s'; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - //if makes it past the above condition and there's float in the array |
|
| 469 | - //then the type is %f |
|
| 470 | - if (isset($type['number'])) { |
|
| 471 | - return '%f'; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - //if it makes it above the above conditions and there is an integer in the array |
|
| 475 | - //then the type is %d |
|
| 476 | - if (isset($type['integer'])) { |
|
| 477 | - return '%d'; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - //anything else is a string |
|
| 481 | - return '%s'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * This returns elements used to represent this field in the json schema. |
|
| 487 | - * |
|
| 488 | - * @link http://json-schema.org/ |
|
| 489 | - * @return array |
|
| 490 | - */ |
|
| 491 | - public function getSchema() |
|
| 492 | - { |
|
| 493 | - $schema = array( |
|
| 494 | - 'description' => $this->getSchemaDescription(), |
|
| 495 | - 'type' => $this->getSchemaType(), |
|
| 496 | - 'readonly' => $this->getSchemaReadonly(), |
|
| 497 | - ); |
|
| 498 | - |
|
| 499 | - //optional properties of the schema |
|
| 500 | - $enum = $this->getSchemaEnum(); |
|
| 501 | - $properties = $this->getSchemaProperties(); |
|
| 502 | - $format = $this->getSchemaFormat(); |
|
| 503 | - if ($enum) { |
|
| 504 | - $schema['enum'] = $enum; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - if ($properties) { |
|
| 508 | - $schema['properties'] = $properties; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - if ($format) { |
|
| 512 | - $schema['format'] = $format; |
|
| 513 | - } |
|
| 514 | - return $schema; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part |
|
| 519 | - * of the model objects (ie, client code shouldn't care to ever see their value... if client code does |
|
| 520 | - * want to see their value, then they shouldn't be db-only fields!) |
|
| 521 | - * Eg, when doing events as custom post types, querying the post_type is essential, but |
|
| 522 | - * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event'). |
|
| 523 | - * By default, all fields aren't db-only. |
|
| 524 | - * |
|
| 525 | - * @return boolean |
|
| 526 | - */ |
|
| 527 | - public function is_db_only_field() |
|
| 528 | - { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Validates the incoming string|array to ensure its an allowable type. |
|
| 535 | - * @throws InvalidArgumentException |
|
| 536 | - * @param string|array $type |
|
| 537 | - */ |
|
| 538 | - private function validateSchemaType($type) |
|
| 539 | - { |
|
| 540 | - if (! (is_string($type) || is_array($type))) { |
|
| 541 | - throw new InvalidArgumentException( |
|
| 542 | - sprintf( |
|
| 543 | - esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'), |
|
| 544 | - print_r($type, true) |
|
| 545 | - ) |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - //validate allowable types. |
|
| 550 | - //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 551 | - $allowable_types = array_flip( |
|
| 552 | - array( |
|
| 553 | - 'string', |
|
| 554 | - 'number', |
|
| 555 | - 'null', |
|
| 556 | - 'object', |
|
| 557 | - 'array', |
|
| 558 | - 'boolean', |
|
| 559 | - 'integer' |
|
| 560 | - ) |
|
| 561 | - ); |
|
| 562 | - |
|
| 563 | - if (is_array($type)) { |
|
| 564 | - foreach ($type as $item_in_type) { |
|
| 565 | - $this->validateSchemaType($item_in_type); |
|
| 566 | - } |
|
| 567 | - return; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (! isset($allowable_types[$type])) { |
|
| 571 | - throw new InvalidArgumentException( |
|
| 572 | - sprintf( |
|
| 573 | - esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'), |
|
| 574 | - $type, |
|
| 575 | - implode(',', array_flip($allowable_types)) |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Validates that the incoming format is an allowable string to use for the _schema_format property |
|
| 584 | - * @throws InvalidArgumentException |
|
| 585 | - * @param $format |
|
| 586 | - */ |
|
| 587 | - private function validateSchemaFormat($format) |
|
| 588 | - { |
|
| 589 | - if (! is_string($format)) { |
|
| 590 | - throw new InvalidArgumentException( |
|
| 591 | - sprintf( |
|
| 592 | - esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'), |
|
| 593 | - print_r($format, true) |
|
| 594 | - ) |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - //validate allowable format values |
|
| 599 | - //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 600 | - $allowable_formats = array_flip( |
|
| 601 | - array( |
|
| 602 | - 'date-time', |
|
| 603 | - 'email', |
|
| 604 | - 'hostname', |
|
| 605 | - 'ipv4', |
|
| 606 | - 'ipv6', |
|
| 607 | - 'uri', |
|
| 608 | - 'uriref' |
|
| 609 | - ) |
|
| 610 | - ); |
|
| 611 | - |
|
| 612 | - if (! isset($allowable_formats[$format])) { |
|
| 613 | - throw new InvalidArgumentException( |
|
| 614 | - sprintf( |
|
| 615 | - esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'), |
|
| 616 | - $format, |
|
| 617 | - implode(',', array_flip($allowable_formats)) |
|
| 618 | - ) |
|
| 619 | - ); |
|
| 620 | - } |
|
| 621 | - } |
|
| 24 | + /** |
|
| 25 | + * The alias for the table the column belongs to. |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $_table_alias; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The actual db column name for the table |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $_table_column; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * The authoritative name for the table column (used by client code to reference the field). |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $_name; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * A description for the field. |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $_nicename; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Whether the field is nullable or not |
|
| 53 | + * @var bool |
|
| 54 | + */ |
|
| 55 | + protected $_nullable; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * What the default value for the field should be. |
|
| 60 | + * @var mixed |
|
| 61 | + */ |
|
| 62 | + protected $_default_value; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Other configuration for the field |
|
| 67 | + * @var mixed |
|
| 68 | + */ |
|
| 69 | + protected $_other_config; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * The name of the model this field is instantiated for. |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + protected $_model_name; |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This should be a json-schema valid data type for the field. |
|
| 81 | + * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + private $_schema_type = 'string'; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * If the schema has a defined format then it should be defined via this property. |
|
| 89 | + * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | + private $_schema_format = ''; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Indicates that the value of the field is managed exclusively by the server/model and not something |
|
| 97 | + * settable by client code. |
|
| 98 | + * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4 |
|
| 99 | + * @var bool |
|
| 100 | + */ |
|
| 101 | + private $_schema_readonly = false; |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param string $table_column |
|
| 106 | + * @param string $nicename |
|
| 107 | + * @param bool $nullable |
|
| 108 | + * @param null $default_value |
|
| 109 | + */ |
|
| 110 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 111 | + { |
|
| 112 | + $this->_table_column = $table_column; |
|
| 113 | + $this->_nicename = $nicename; |
|
| 114 | + $this->_nullable = $nullable; |
|
| 115 | + $this->_default_value = $default_value; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param $table_alias |
|
| 121 | + * @param $name |
|
| 122 | + * @param $model_name |
|
| 123 | + */ |
|
| 124 | + public function _construct_finalize($table_alias, $name, $model_name) |
|
| 125 | + { |
|
| 126 | + $this->_table_alias = $table_alias; |
|
| 127 | + $this->_name = $name; |
|
| 128 | + $this->_model_name = $model_name; |
|
| 129 | + /** |
|
| 130 | + * allow for changing the defaults |
|
| 131 | + */ |
|
| 132 | + $this->_nicename = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename', |
|
| 133 | + $this->_nicename, $this); |
|
| 134 | + $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value', |
|
| 135 | + $this->_default_value, $this); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function get_table_alias() |
|
| 139 | + { |
|
| 140 | + return $this->_table_alias; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function get_table_column() |
|
| 144 | + { |
|
| 145 | + return $this->_table_column; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime' |
|
| 150 | + * |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_model_name() |
|
| 154 | + { |
|
| 155 | + return $this->_model_name; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function get_name() |
|
| 163 | + { |
|
| 164 | + if ($this->_name) { |
|
| 165 | + return $this->_name; |
|
| 166 | + } else { |
|
| 167 | + throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", |
|
| 168 | + "event_espresso"), get_class($this))); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function get_nicename() |
|
| 173 | + { |
|
| 174 | + return $this->_nicename; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function is_nullable() |
|
| 178 | + { |
|
| 179 | + return $this->_nullable; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * returns whether this field is an auto-increment field or not. If it is, then |
|
| 184 | + * on insertion it can be null. However, on updates it must be present. |
|
| 185 | + * |
|
| 186 | + * @return boolean |
|
| 187 | + */ |
|
| 188 | + public function is_auto_increment() |
|
| 189 | + { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * The default value in the model object's value domain. See lengthy comment about |
|
| 195 | + * value domains at the top of EEM_Base |
|
| 196 | + * |
|
| 197 | + * @return mixed |
|
| 198 | + */ |
|
| 199 | + public function get_default_value() |
|
| 200 | + { |
|
| 201 | + return $this->_default_value; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the table alias joined to the table column, however this isn't the right |
|
| 206 | + * table alias if the aliased table is being joined to. In that case, you can use |
|
| 207 | + * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias |
|
| 208 | + * in the current query |
|
| 209 | + * |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public function get_qualified_column() |
|
| 213 | + { |
|
| 214 | + return $this->get_table_alias() . "." . $this->get_table_column(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * When get() is called on a model object (eg EE_Event), before returning its value, |
|
| 219 | + * call this function on it, allowing us to customize the returned value based on |
|
| 220 | + * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default, |
|
| 221 | + * we simply return it. |
|
| 222 | + * |
|
| 223 | + * @param mixed $value_of_field_on_model_object |
|
| 224 | + * @return mixed |
|
| 225 | + */ |
|
| 226 | + public function prepare_for_get($value_of_field_on_model_object) |
|
| 227 | + { |
|
| 228 | + return $value_of_field_on_model_object; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * When inserting or updating a field on a model object, run this function on each |
|
| 233 | + * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc. |
|
| 234 | + * By default, we do nothing. |
|
| 235 | + * |
|
| 236 | + * @param mixed $value_of_field_on_model_object |
|
| 237 | + * @return mixed |
|
| 238 | + */ |
|
| 239 | + public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 240 | + { |
|
| 241 | + return $value_of_field_on_model_object; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
| 246 | + * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
| 247 | + * By default, we do nothing. |
|
| 248 | + * |
|
| 249 | + * @param mixed $value_inputted_for_field_on_model_object |
|
| 250 | + * @return mixed |
|
| 251 | + */ |
|
| 252 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 253 | + { |
|
| 254 | + return $value_inputted_for_field_on_model_object; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * When instantiating a model object from DB results, this function is called before setting each field. |
|
| 260 | + * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that |
|
| 261 | + * is the one child classes will most often define. |
|
| 262 | + * |
|
| 263 | + * @param mixed $value_found_in_db_for_model_object |
|
| 264 | + * @return mixed |
|
| 265 | + */ |
|
| 266 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 267 | + { |
|
| 268 | + return $this->prepare_for_set($value_found_in_db_for_model_object); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a |
|
| 273 | + * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12, |
|
| 274 | + * 2013, at 3:23pm" instead of |
|
| 275 | + * "8765678632", or any other modifications to how the value should be displayed, but not modified itself. |
|
| 276 | + * |
|
| 277 | + * @param mixed $value_on_field_to_be_outputted |
|
| 278 | + * @return mixed |
|
| 279 | + */ |
|
| 280 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
| 281 | + { |
|
| 282 | + return $value_on_field_to_be_outputted; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns whatever is set as the nicename for the object. |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function getSchemaDescription() |
|
| 291 | + { |
|
| 292 | + return $this->get_nicename(); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Returns whatever is set as the $_schema_type property for the object. |
|
| 298 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 299 | + * @return string|array |
|
| 300 | + */ |
|
| 301 | + public function getSchemaType() |
|
| 302 | + { |
|
| 303 | + if ($this->is_nullable()) { |
|
| 304 | + $this->_schema_type = (array) $this->_schema_type; |
|
| 305 | + if (! in_array('null', $this->_schema_type)) { |
|
| 306 | + $this->_schema_type[] = 'null'; |
|
| 307 | + }; |
|
| 308 | + } |
|
| 309 | + return $this->_schema_type; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Sets the _schema_type property. Child classes should call this in their constructors to override the default state |
|
| 315 | + * for this property. |
|
| 316 | + * @param string|array $type |
|
| 317 | + * @throws InvalidArgumentException |
|
| 318 | + */ |
|
| 319 | + protected function setSchemaType($type) |
|
| 320 | + { |
|
| 321 | + $this->validateSchemaType($type); |
|
| 322 | + $this->_schema_type = $type; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 328 | + * this method and return the properties for the schema. |
|
| 329 | + * |
|
| 330 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 331 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 332 | + * |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + public function getSchemaProperties() |
|
| 336 | + { |
|
| 337 | + return array(); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * If a child class has enum values, they should override this method and provide a simple array |
|
| 343 | + * of the enum values. |
|
| 344 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 345 | + * are set on the instantiated object that could be filtered after construct. |
|
| 346 | + * |
|
| 347 | + * @return array |
|
| 348 | + */ |
|
| 349 | + public function getSchemaEnum() |
|
| 350 | + { |
|
| 351 | + return array(); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * This returns the value of the $_schema_format property on the object. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function getSchemaFormat() |
|
| 360 | + { |
|
| 361 | + return $this->_schema_format; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Sets the schema format property. |
|
| 367 | + * @throws InvalidArgumentException |
|
| 368 | + * @param string $format |
|
| 369 | + */ |
|
| 370 | + protected function setSchemaFormat($format) |
|
| 371 | + { |
|
| 372 | + $this->validateSchemaFormat($format); |
|
| 373 | + $this->_schema_format = $format; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * This returns the value of the $_schema_readonly property on the object. |
|
| 379 | + * @return bool |
|
| 380 | + */ |
|
| 381 | + public function getSchemaReadonly() |
|
| 382 | + { |
|
| 383 | + return $this->_schema_readonly; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * This sets the value for the $_schema_readonly property. |
|
| 389 | + * @param bool $readonly (only explicit boolean values are accepted) |
|
| 390 | + */ |
|
| 391 | + protected function setSchemaReadOnly($readonly) |
|
| 392 | + { |
|
| 393 | + if (! is_bool($readonly)) { |
|
| 394 | + throw new InvalidArgumentException( |
|
| 395 | + sprintf( |
|
| 396 | + esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'), |
|
| 397 | + print_r($readonly, true) |
|
| 398 | + ) |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + $this->_schema_readonly = $readonly; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Return `%d`, `%s` or `%f` to indicate the data type for the field. |
|
| 410 | + * @uses _get_wpdb_data_type() |
|
| 411 | + * |
|
| 412 | + * @return string |
|
| 413 | + */ |
|
| 414 | + public function get_wpdb_data_type() |
|
| 415 | + { |
|
| 416 | + return $this->_get_wpdb_data_type(); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries. |
|
| 422 | + * @param string $type Included if a specific type is requested. |
|
| 423 | + * @uses get_schema_type() |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + protected function _get_wpdb_data_type($type='') |
|
| 427 | + { |
|
| 428 | + $type = empty($type) ? $this->getSchemaType() : $type; |
|
| 429 | + |
|
| 430 | + //if type is an array, then different parsing is required. |
|
| 431 | + if (is_array($type)) { |
|
| 432 | + return $this->_get_wpdb_data_type_for_type_array($type); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + $wpdb_type = '%s'; |
|
| 436 | + switch ($type) { |
|
| 437 | + case 'number': |
|
| 438 | + $wpdb_type = '%f'; |
|
| 439 | + break; |
|
| 440 | + case 'integer': |
|
| 441 | + case 'boolean': |
|
| 442 | + $wpdb_type = '%d'; |
|
| 443 | + break; |
|
| 444 | + case 'object': |
|
| 445 | + $properties = $this->getSchemaProperties(); |
|
| 446 | + if (isset($properties['raw'], $properties['raw']['type'])) { |
|
| 447 | + $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']); |
|
| 448 | + } |
|
| 449 | + break; //leave at default |
|
| 450 | + } |
|
| 451 | + return $wpdb_type; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + protected function _get_wpdb_data_type_for_type_array($type) |
|
| 457 | + { |
|
| 458 | + $type = (array) $type; |
|
| 459 | + //first let's flip because then we can do a faster key check |
|
| 460 | + $type = array_flip($type); |
|
| 461 | + |
|
| 462 | + //check for things that mean '%s' |
|
| 463 | + if (isset($type['string'],$type['object'],$type['array'])) { |
|
| 464 | + return '%s'; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + //if makes it past the above condition and there's float in the array |
|
| 468 | + //then the type is %f |
|
| 469 | + if (isset($type['number'])) { |
|
| 470 | + return '%f'; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + //if it makes it above the above conditions and there is an integer in the array |
|
| 474 | + //then the type is %d |
|
| 475 | + if (isset($type['integer'])) { |
|
| 476 | + return '%d'; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + //anything else is a string |
|
| 480 | + return '%s'; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * This returns elements used to represent this field in the json schema. |
|
| 486 | + * |
|
| 487 | + * @link http://json-schema.org/ |
|
| 488 | + * @return array |
|
| 489 | + */ |
|
| 490 | + public function getSchema() |
|
| 491 | + { |
|
| 492 | + $schema = array( |
|
| 493 | + 'description' => $this->getSchemaDescription(), |
|
| 494 | + 'type' => $this->getSchemaType(), |
|
| 495 | + 'readonly' => $this->getSchemaReadonly(), |
|
| 496 | + ); |
|
| 497 | + |
|
| 498 | + //optional properties of the schema |
|
| 499 | + $enum = $this->getSchemaEnum(); |
|
| 500 | + $properties = $this->getSchemaProperties(); |
|
| 501 | + $format = $this->getSchemaFormat(); |
|
| 502 | + if ($enum) { |
|
| 503 | + $schema['enum'] = $enum; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + if ($properties) { |
|
| 507 | + $schema['properties'] = $properties; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if ($format) { |
|
| 511 | + $schema['format'] = $format; |
|
| 512 | + } |
|
| 513 | + return $schema; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part |
|
| 518 | + * of the model objects (ie, client code shouldn't care to ever see their value... if client code does |
|
| 519 | + * want to see their value, then they shouldn't be db-only fields!) |
|
| 520 | + * Eg, when doing events as custom post types, querying the post_type is essential, but |
|
| 521 | + * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event'). |
|
| 522 | + * By default, all fields aren't db-only. |
|
| 523 | + * |
|
| 524 | + * @return boolean |
|
| 525 | + */ |
|
| 526 | + public function is_db_only_field() |
|
| 527 | + { |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Validates the incoming string|array to ensure its an allowable type. |
|
| 534 | + * @throws InvalidArgumentException |
|
| 535 | + * @param string|array $type |
|
| 536 | + */ |
|
| 537 | + private function validateSchemaType($type) |
|
| 538 | + { |
|
| 539 | + if (! (is_string($type) || is_array($type))) { |
|
| 540 | + throw new InvalidArgumentException( |
|
| 541 | + sprintf( |
|
| 542 | + esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'), |
|
| 543 | + print_r($type, true) |
|
| 544 | + ) |
|
| 545 | + ); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + //validate allowable types. |
|
| 549 | + //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 550 | + $allowable_types = array_flip( |
|
| 551 | + array( |
|
| 552 | + 'string', |
|
| 553 | + 'number', |
|
| 554 | + 'null', |
|
| 555 | + 'object', |
|
| 556 | + 'array', |
|
| 557 | + 'boolean', |
|
| 558 | + 'integer' |
|
| 559 | + ) |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + if (is_array($type)) { |
|
| 563 | + foreach ($type as $item_in_type) { |
|
| 564 | + $this->validateSchemaType($item_in_type); |
|
| 565 | + } |
|
| 566 | + return; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if (! isset($allowable_types[$type])) { |
|
| 570 | + throw new InvalidArgumentException( |
|
| 571 | + sprintf( |
|
| 572 | + esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'), |
|
| 573 | + $type, |
|
| 574 | + implode(',', array_flip($allowable_types)) |
|
| 575 | + ) |
|
| 576 | + ); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Validates that the incoming format is an allowable string to use for the _schema_format property |
|
| 583 | + * @throws InvalidArgumentException |
|
| 584 | + * @param $format |
|
| 585 | + */ |
|
| 586 | + private function validateSchemaFormat($format) |
|
| 587 | + { |
|
| 588 | + if (! is_string($format)) { |
|
| 589 | + throw new InvalidArgumentException( |
|
| 590 | + sprintf( |
|
| 591 | + esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'), |
|
| 592 | + print_r($format, true) |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + //validate allowable format values |
|
| 598 | + //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 599 | + $allowable_formats = array_flip( |
|
| 600 | + array( |
|
| 601 | + 'date-time', |
|
| 602 | + 'email', |
|
| 603 | + 'hostname', |
|
| 604 | + 'ipv4', |
|
| 605 | + 'ipv6', |
|
| 606 | + 'uri', |
|
| 607 | + 'uriref' |
|
| 608 | + ) |
|
| 609 | + ); |
|
| 610 | + |
|
| 611 | + if (! isset($allowable_formats[$format])) { |
|
| 612 | + throw new InvalidArgumentException( |
|
| 613 | + sprintf( |
|
| 614 | + esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'), |
|
| 615 | + $format, |
|
| 616 | + implode(',', array_flip($allowable_formats)) |
|
| 617 | + ) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + } |
|
| 622 | 621 | } |
| 623 | 622 | \ No newline at end of file |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public function get_qualified_column() |
| 213 | 213 | { |
| 214 | - return $this->get_table_alias() . "." . $this->get_table_column(); |
|
| 214 | + return $this->get_table_alias().".".$this->get_table_column(); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | { |
| 303 | 303 | if ($this->is_nullable()) { |
| 304 | 304 | $this->_schema_type = (array) $this->_schema_type; |
| 305 | - if (! in_array('null', $this->_schema_type)) { |
|
| 305 | + if ( ! in_array('null', $this->_schema_type)) { |
|
| 306 | 306 | $this->_schema_type[] = 'null'; |
| 307 | 307 | }; |
| 308 | 308 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | */ |
| 392 | 392 | protected function setSchemaReadOnly($readonly) |
| 393 | 393 | { |
| 394 | - if (! is_bool($readonly)) { |
|
| 394 | + if ( ! is_bool($readonly)) { |
|
| 395 | 395 | throw new InvalidArgumentException( |
| 396 | 396 | sprintf( |
| 397 | 397 | esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'), |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @uses get_schema_type() |
| 425 | 425 | * @return string |
| 426 | 426 | */ |
| 427 | - protected function _get_wpdb_data_type($type='') |
|
| 427 | + protected function _get_wpdb_data_type($type = '') |
|
| 428 | 428 | { |
| 429 | 429 | $type = empty($type) ? $this->getSchemaType() : $type; |
| 430 | 430 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | $type = array_flip($type); |
| 462 | 462 | |
| 463 | 463 | //check for things that mean '%s' |
| 464 | - if (isset($type['string'],$type['object'],$type['array'])) { |
|
| 464 | + if (isset($type['string'], $type['object'], $type['array'])) { |
|
| 465 | 465 | return '%s'; |
| 466 | 466 | } |
| 467 | 467 | |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | */ |
| 538 | 538 | private function validateSchemaType($type) |
| 539 | 539 | { |
| 540 | - if (! (is_string($type) || is_array($type))) { |
|
| 540 | + if ( ! (is_string($type) || is_array($type))) { |
|
| 541 | 541 | throw new InvalidArgumentException( |
| 542 | 542 | sprintf( |
| 543 | 543 | esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'), |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | return; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if (! isset($allowable_types[$type])) { |
|
| 570 | + if ( ! isset($allowable_types[$type])) { |
|
| 571 | 571 | throw new InvalidArgumentException( |
| 572 | 572 | sprintf( |
| 573 | 573 | esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'), |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | */ |
| 587 | 587 | private function validateSchemaFormat($format) |
| 588 | 588 | { |
| 589 | - if (! is_string($format)) { |
|
| 589 | + if ( ! is_string($format)) { |
|
| 590 | 590 | throw new InvalidArgumentException( |
| 591 | 591 | sprintf( |
| 592 | 592 | esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'), |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | ) |
| 610 | 610 | ); |
| 611 | 611 | |
| 612 | - if (! isset($allowable_formats[$format])) { |
|
| 612 | + if ( ! isset($allowable_formats[$format])) { |
|
| 613 | 613 | throw new InvalidArgumentException( |
| 614 | 614 | sprintf( |
| 615 | 615 | esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'), |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * @param string $table_column |
| 13 | 13 | * @param string $nicename |
| 14 | 14 | * @param bool $nullable |
| 15 | - * @param null $default_value |
|
| 15 | + * @param integer $default_value |
|
| 16 | 16 | */ |
| 17 | 17 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 18 | 18 | { |
@@ -8,91 +8,91 @@ |
||
| 8 | 8 | class EE_Money_Field extends EE_Float_Field |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @param string $table_column |
|
| 13 | - * @param string $nicename |
|
| 14 | - * @param bool $nullable |
|
| 15 | - * @param null $default_value |
|
| 16 | - */ |
|
| 17 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | - { |
|
| 19 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | - $this->setSchemaType('object'); |
|
| 21 | - } |
|
| 11 | + /** |
|
| 12 | + * @param string $table_column |
|
| 13 | + * @param string $nicename |
|
| 14 | + * @param bool $nullable |
|
| 15 | + * @param null $default_value |
|
| 16 | + */ |
|
| 17 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | + { |
|
| 19 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | + $this->setSchemaType('object'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Schemas: |
|
| 26 | - * 'localized_float': "3,023.00" |
|
| 27 | - * 'no_currency_code': "$3,023.00" |
|
| 28 | - * null: "$3,023.00<span>USD</span>" |
|
| 29 | - * |
|
| 30 | - * @param string $value_on_field_to_be_outputted |
|
| 31 | - * @param string $schema |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 35 | - { |
|
| 36 | - $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 24 | + /** |
|
| 25 | + * Schemas: |
|
| 26 | + * 'localized_float': "3,023.00" |
|
| 27 | + * 'no_currency_code': "$3,023.00" |
|
| 28 | + * null: "$3,023.00<span>USD</span>" |
|
| 29 | + * |
|
| 30 | + * @param string $value_on_field_to_be_outputted |
|
| 31 | + * @param string $schema |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 35 | + { |
|
| 36 | + $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 37 | 37 | |
| 38 | - if ($schema == 'localized_float') { |
|
| 39 | - return $pretty_float; |
|
| 40 | - } |
|
| 41 | - if ($schema == 'no_currency_code') { |
|
| 38 | + if ($schema == 'localized_float') { |
|
| 39 | + return $pretty_float; |
|
| 40 | + } |
|
| 41 | + if ($schema == 'no_currency_code') { |
|
| 42 | 42 | // echo "schema no currency!"; |
| 43 | - $display_code = false; |
|
| 44 | - } else { |
|
| 45 | - $display_code = true; |
|
| 46 | - } |
|
| 47 | - //we don't use the $pretty_float because format_currency will take care of it. |
|
| 48 | - return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
| 49 | - } |
|
| 43 | + $display_code = false; |
|
| 44 | + } else { |
|
| 45 | + $display_code = true; |
|
| 46 | + } |
|
| 47 | + //we don't use the $pretty_float because format_currency will take care of it. |
|
| 48 | + return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
| 53 | - * Rounds the float to the correct number of decimal places for this country's currency. |
|
| 54 | - * Also, interprets periods and commas according to the country's currency settings. |
|
| 55 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 56 | - * |
|
| 57 | - * @param string $value_inputted_for_field_on_model_object |
|
| 58 | - * @return float |
|
| 59 | - */ |
|
| 60 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 61 | - { |
|
| 62 | - //remove any currencies etc. |
|
| 51 | + /** |
|
| 52 | + * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
| 53 | + * Rounds the float to the correct number of decimal places for this country's currency. |
|
| 54 | + * Also, interprets periods and commas according to the country's currency settings. |
|
| 55 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 56 | + * |
|
| 57 | + * @param string $value_inputted_for_field_on_model_object |
|
| 58 | + * @return float |
|
| 59 | + */ |
|
| 60 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 61 | + { |
|
| 62 | + //remove any currencies etc. |
|
| 63 | 63 | // if(is_string($value_inputted_for_field_on_model_object)){ |
| 64 | 64 | // $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object); |
| 65 | 65 | // } |
| 66 | - //now it's a float-style string or number |
|
| 67 | - $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 68 | - //round to the correctly number of decimal places for this currency |
|
| 69 | - $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc); |
|
| 70 | - return $rounded_value; |
|
| 71 | - } |
|
| 66 | + //now it's a float-style string or number |
|
| 67 | + $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 68 | + //round to the correctly number of decimal places for this currency |
|
| 69 | + $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc); |
|
| 70 | + return $rounded_value; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - function prepare_for_get($value_of_field_on_model_object) |
|
| 74 | - { |
|
| 75 | - $c = EE_Registry::instance()->CFG->currency; |
|
| 76 | - return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc); |
|
| 77 | - } |
|
| 73 | + function prepare_for_get($value_of_field_on_model_object) |
|
| 74 | + { |
|
| 75 | + $c = EE_Registry::instance()->CFG->currency; |
|
| 76 | + return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function getSchemaProperties() |
|
| 80 | - { |
|
| 81 | - return array( |
|
| 82 | - 'raw' => array( |
|
| 83 | - 'description' => sprintf( |
|
| 84 | - __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
| 85 | - $this->get_nicename() |
|
| 86 | - ), |
|
| 87 | - 'type' => 'number' |
|
| 88 | - ), |
|
| 89 | - 'pretty' => array( |
|
| 90 | - 'description' => sprintf( |
|
| 91 | - __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
| 92 | - $this->get_nicename() |
|
| 93 | - ), |
|
| 94 | - 'type' => 'string' |
|
| 95 | - ) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 79 | + public function getSchemaProperties() |
|
| 80 | + { |
|
| 81 | + return array( |
|
| 82 | + 'raw' => array( |
|
| 83 | + 'description' => sprintf( |
|
| 84 | + __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
| 85 | + $this->get_nicename() |
|
| 86 | + ), |
|
| 87 | + 'type' => 'number' |
|
| 88 | + ), |
|
| 89 | + 'pretty' => array( |
|
| 90 | + 'description' => sprintf( |
|
| 91 | + __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
| 92 | + $this->get_nicename() |
|
| 93 | + ), |
|
| 94 | + 'type' => 'string' |
|
| 95 | + ) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | \ No newline at end of file |