public function test_get_state_name_by_ID() { $this->assertFalse(EEM_State::instance()->exists_by_ID(99999)); $s = $this->new_model_obj_with_dependencies('State'); $this->assertEquals('', EEM_State::instance()->get_state_name_by_ID(99999)); $this->assertEquals($s->name(), EEM_State::instance()->get_state_name_by_ID($s->ID())); }
/** * get_state_answer_options * * @param array $state_options * @return array */ public function get_state_answer_options($state_options = NULL) { // if passed something that is NOT an array if (!is_array($state_options)) { // get possibly cached list of states $states = EEM_State::instance()->get_all_active_states(); if (!empty($states)) { //set the default $state_options[''][''] = ''; foreach ($states as $state) { if ($state instanceof EE_State) { $state_options[$state->country()->name()][$state->ID()] = $state->name(); } } } else { $state_options = array(); } } return $state_options; }
public function get_csv_data($offset, $limit) { $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results(array('limit' => array($offset, $limit), 'force_join' => array('State', 'Country'))); $csv_data = array(); foreach ($attendee_rows as $attendee_row) { $csv_row = array(); foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { if ($field_name == 'STA_ID') { $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; } elseif ($field_name == 'CNT_ISO') { $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); $csv_row[__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; } else { $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; } } $csv_data[] = $csv_row; } return $csv_data; }
/** * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods will have to take care of handling. * * @access protected * @param string $shortcode the shortcode to be parsed. * @return string parsed shortcode */ protected function _parser($shortcode) { if (!$this->_data instanceof EE_Answer || !isset($this->_extra_data['data']) || !$this->_extra_data['data'] instanceof EE_Messages_Addressee) { return ''; } switch ($shortcode) { case '[QUESTION]': $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); if (!$question instanceof EE_Question) { return ''; //get out because we can't figure out what the question is. } return $question->get_pretty('QST_display_text', 'no_wpautop'); break; case '[ANSWER]': //need to get the question to determine the type of question (some questions require translation of the answer). $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); if (!$question instanceof EE_Question) { return ''; //get out cause we can't figure out what the question type is! } //what we show for the answer depends on the question type! switch ($question->get('QST_type')) { case 'STATE': $state = EEM_State::instance()->get_one_by_ID($this->_data->get('ANS_value')); $answer = $state instanceof EE_State ? $state->name() : ''; break; case 'COUNTRY': $country = EEM_Country::instance()->get_one_by_ID($this->_data->get('ANS_value')); $answer = $country instanceof EE_Country ? $country->name() : ''; break; default: $answer = $this->_data->get_pretty('ANS_value', 'no_wpautop'); break; } return $answer; break; } return ''; }
/** * update_country_settings * * @access public * @return boolean */ public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) { $CNT_ISO = !empty($CNT_ISO) ? $CNT_ISO : FALSE; if (!$CNT_ISO) { EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] : FALSE; if (!$STA_abbrev && !empty($STA_ID)) { if ($state = EEM_State::instance()->get_one_by_ID($STA_ID)) { if ($state instanceof EE_State) { $STA_abbrev = $state->abbrev(); } } } if (!$STA_abbrev) { EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev); }
/** * create_attendee_from_request_data * uses info from alternate GET or POST data (such as AJAX) to create a new attendee * @return \EE_Attendee */ protected function _create_attendee_from_request_data() { // get State ID $STA_ID = !empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; if (!empty($STA_ID)) { // can we get state object from name ? EE_Registry::instance()->load_model('State'); $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); $STA_ID = is_array($state) && !empty($state) ? reset($state) : $STA_ID; } // get Country ISO $CNT_ISO = !empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; if (!empty($CNT_ISO)) { // can we get country object from name ? EE_Registry::instance()->load_model('Country'); $country = EEM_Country::instance()->get_col(array(array('CNT_name' => $CNT_ISO), 'limit' => 1), 'CNT_ISO'); $CNT_ISO = is_array($country) && !empty($country) ? reset($country) : $CNT_ISO; } // grab attendee data $attendee_data = array('ATT_fname' => !empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', 'ATT_lname' => !empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', 'ATT_email' => !empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', 'ATT_address' => !empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', 'ATT_address2' => !empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', 'ATT_city' => !empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', 'STA_ID' => $STA_ID, 'CNT_ISO' => $CNT_ISO, 'ATT_zip' => !empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', 'ATT_phone' => !empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : ''); // validate the email address since it is the most important piece of info if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] != $_REQUEST['email']) { EE_Error::add_error(__('An invalid email address was submitted.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } // does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address if (!empty($attendee_data['ATT_fname']) && !empty($attendee_data['ATT_lname']) && !empty($attendee_data['ATT_email'])) { $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(array('ATT_fname' => $attendee_data['ATT_fname'], 'ATT_lname' => $attendee_data['ATT_lname'], 'ATT_email' => $attendee_data['ATT_email'])); if ($existing_attendee instanceof EE_Attendee) { return $existing_attendee; } } // no existing attendee? kk let's create a new one // kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist $attendee_data['ATT_fname'] = !empty($attendee_data['ATT_fname']) ? $attendee_data['ATT_fname'] : $attendee_data['ATT_email']; $attendee_data['ATT_lname'] = !empty($attendee_data['ATT_lname']) ? $attendee_data['ATT_lname'] : $attendee_data['ATT_email']; return EE_Attendee::new_instance($attendee_data); }
function column_STA_ID($item) { $states = EEM_State::instance()->get_all_states(); $state = isset($states[$item->state_ID()]) ? $states[$item->state_ID()]->get('STA_name') : $item->state_ID(); return !is_numeric($state) ? $state : ''; }
/** * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price name, * and the questions associated with the registrations * @param int $event_id */ function report_registrations_for_event($event_id = NULL) { $reg_fields_to_include = array('TXN_ID', 'ATT_ID', 'REG_ID', 'REG_date', 'REG_code', 'REG_count', 'REG_final_price'); $att_fields_to_include = array('ATT_fname', 'ATT_lname', 'ATT_email', 'ATT_address', 'ATT_address2', 'ATT_city', 'STA_ID', 'CNT_ISO', 'ATT_zip', 'ATT_phone'); $registrations_csv_ready_array = array(); $reg_model = EE_Registry::instance()->load_model('Registration'); $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(array('OR' => array('Transaction.STS_ID' => array('NOT IN', array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code)), 'STS_ID' => EEM_Registration::status_id_approved), 'Ticket.TKT_deleted' => array('IN', array(true, false))), 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), 'force_join' => array('Transaction', 'Ticket', 'Attendee'), 'caps' => EEM_Base::caps_read_admin), $event_id); if ($event_id) { $query_params[0]['EVT_ID'] = $event_id; } else { $query_params['force_join'][] = 'Event'; } $registration_rows = $reg_model->get_all_wpdb_results($query_params); //get all questions which relate to someone in this group $registration_ids = array(); foreach ($registration_rows as $reg_row) { $registration_ids[] = intval($reg_row['Registration.REG_ID']); } // EEM_Question::instance()->show_next_x_db_queries(); $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(array(array('Answer.REG_ID' => array('IN', $registration_ids)))); foreach ($registration_rows as $reg_row) { if (is_array($reg_row)) { $reg_csv_array = array(); if (!$event_id) { //get the event's name and Id $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), $this->_prepare_value_from_db_for_display(EEM_Event::instance(), 'EVT_name', $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); } $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; /*@var $reg_row EE_Registration */ foreach ($reg_fields_to_include as $field_name) { $field = $reg_model->field_settings_for($field_name); if ($field_name == 'REG_final_price') { $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_final_price'], 'localized_float'); } elseif ($field_name == 'REG_count') { $value = sprintf(__('%s of %s', 'event_espresso'), $this->_prepare_value_from_db_for_display($reg_model, 'REG_count', $reg_row['Registration.REG_count']), $this->_prepare_value_from_db_for_display($reg_model, 'REG_group_size', $reg_row['Registration.REG_group_size'])); } elseif ($field_name == 'REG_date') { $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_date'], 'no_html'); } else { $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row[$field->get_qualified_column()]); } $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; if ($field_name == 'REG_final_price') { //add a column named Currency after the final price $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; } } //get pretty status $stati = EEM_Status::instance()->localized_status(array($reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso')), FALSE, 'sentence'); $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; //get pretty trnasaction status $reg_csv_array[__("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_total', $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00'; $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_paid', $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00'; $payment_methods = array(); $gateway_txn_ids_etc = array(); $payment_times = array(); if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { $payments_info = EEM_Payment::instance()->get_all_wpdb_results(array(array('TXN_ID' => $reg_row['TransactionTable.TXN_ID'], 'STS_ID' => EEM_Payment::status_id_approved), 'force_join' => array('Payment_Method')), ARRAY_A, 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'); foreach ($payments_info as $payment_method_and_gateway_txn_id) { $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) ? $payment_method_and_gateway_txn_id['payment_time'] : ''; } } $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); //get whether or not the user has checked in $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); //get ticket of registration and its price $ticket_model = EE_Registry::instance()->load_model('Ticket'); if ($reg_row['Ticket.TKT_ID']) { $ticket_name = $this->_prepare_value_from_db_for_display($ticket_model, 'TKT_name', $reg_row['Ticket.TKT_name']); $datetimes_strings = array(); foreach (EEM_Datetime::instance()->get_all_wpdb_results(array(array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), 'order_by' => array('DTT_EVT_start' => 'ASC'), 'default_where_conditions' => 'none')) as $datetime) { $datetimes_strings[] = $this->_prepare_value_from_db_for_display(EEM_Datetime::instance(), 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); } } else { $ticket_name = __('Unknown', 'event_espresso'); $datetimes_strings = array(__('Unknown', 'event_espresso')); } $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); //get datetime(s) of registration //add attendee columns foreach ($att_fields_to_include as $att_field_name) { $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); if ($reg_row['Attendee_CPT.ID']) { if ($att_field_name == 'STA_ID') { $value = EEM_State::instance()->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), 'STA_name'); } elseif ($att_field_name == 'CNT_ISO') { $value = EEM_Country::instance()->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), 'CNT_name'); } else { $value = $this->_prepare_value_from_db_for_display(EEM_Attendee::instance(), $att_field_name, $reg_row[$field_obj->get_qualified_column()]); } } else { $value = ''; } $reg_csv_array[$this->_get_column_name_for_field($field_obj)] = $value; } //make sure each registration has the same questions in the same order foreach ($questions_for_these_regs_rows as $question_row) { if (!isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { $reg_csv_array[$question_row['Question.QST_admin_label']] = null; } } //now fill out the questions THEY answered foreach (EEM_Answer::instance()->get_all_wpdb_results(array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question'))) as $answer_row) { /* @var $answer EE_Answer */ if ($answer_row['Question.QST_ID']) { $question_label = $this->_prepare_value_from_db_for_display(EEM_Question::instance(), 'QST_admin_label', $answer_row['Question.QST_admin_label']); } else { $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); } if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID($answer_row['Answer.ANS_value']); } else { $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display(EEM_Answer::instance(), 'ANS_value', $answer_row['Answer.ANS_value']); } } $registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row); } } //if we couldn't export anything, we want to at least show the column headers if (empty($registrations_csv_ready_array)) { $reg_csv_array = array(); $model_and_fields_to_include = array('Registration' => $reg_fields_to_include, 'Attendee' => $att_fields_to_include); foreach ($model_and_fields_to_include as $model_name => $field_list) { $model = EE_Registry::instance()->load_model($model_name); foreach ($field_list as $field_name) { $field = $model->field_settings_for($field_name); $reg_csv_array[$this->_get_column_name_for_field($field)] = null; //$registration->get($field->get_name()); } } $registrations_csv_ready_array[] = $reg_csv_array; } if ($event_id) { $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); if (!$event_slug) { $event_slug = __('unknown', 'event_espresso'); } } else { $event_slug = __('all', 'event_espresso'); } $filename = sprintf("registrations-for-%s", $event_slug); $handle = $this->EE_CSV->begin_sending_csv($filename); $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); $this->EE_CSV->end_sending_csv($handle); }
/** * posts_orderby_sql * * possible parameters: * ID * start_date * end_date * event_name * category_slug * ticket_start * ticket_end * venue_title * city * state * * **IMPORTANT** * make sure to also send the $orderby_params array to the posts_join_for_orderby() method * or else some of the table references below will result in MySQL errors * * @access public * @param array|bool $orderby_params * @param string $sort * @return string */ public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { global $wpdb; $SQL = ''; $counter = 0; //make sure 'orderby' is set in query params if (!isset(self::$_query_params['orderby'])) { self::$_query_params['orderby'] = array(); } // loop thru $orderby_params (type cast as array) foreach ((array) $orderby_params as $orderby) { // check if we have already added this param if (isset(self::$_query_params['orderby'][$orderby])) { // if so then remove from the $orderby_params so that the count() method below is accurate unset($orderby_params[$orderby]); // then bump ahead to the next param continue; } // this will ad a comma depending on whether this is the first or last param $glue = $counter == 0 || $counter == count($orderby_params) ? ' ' : ', '; // ok what's we dealing with? switch ($orderby) { case 'id': case 'ID': $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; break; case 'end_date': $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; break; case 'event_name': $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; break; case 'category_slug': $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; break; case 'ticket_start': $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; break; case 'ticket_end': $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; break; case 'venue_title': $SQL .= $glue . 'venue_title ' . $sort; break; case 'city': $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; break; case 'state': $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; break; case 'start_date': default: $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort; break; } // add to array of orderby params that have been added self::$_query_params['orderby'][$orderby] = TRUE; $counter++; } return $SQL; }
<?php if (empty($billing_info)) { ?> <div class="clearfix"> <?php _e('There is no billing info for this transaction.', 'event_espresso'); ?> <br/> </div> <?php } else { foreach ($billing_info as $item => $props) { $value = $props['sanitize'] == 'ccard' ? substr($props['value'], 0, 4) . 'XXXX XXXX ' . substr($props['value'], -4) : $props['value']; $value = $props['sanitize'] == 'ccv' ? 'XXX' : $props['value']; if ($props['db-col'] == 'state') { $state_obj = EEM_State::instance()->get_one_by_ID($props['value']); $value = $state_obj instanceof EE_State ? $state_obj->name() : $props['value']; } else { if ($props['db-col'] == 'country') { $country_obj = EEM_Country::instance()->get_one_by_ID($props['value']); $value = $country_obj instanceof EE_Country ? $country_obj->name() : $props['value']; } } ?> <div class="clearfix"> <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php echo $props['label']; ?> </span><?php echo $value;
/** * posts_orderby_sql * * possible parameters: * ID * start_date * end_date * event_name * category_slug * ticket_start * ticket_end * venue_title * city * state * * **IMPORTANT** * make sure to also send the $orderby_params array to the posts_join_for_orderby() method * or else some of the table references below will result in MySQL errors * * @access public * @param boolean $orderby_params * @return string */ public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { global $wpdb; $SQL = ''; $cntr = 1; $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); foreach ($orderby_params as $orderby) { $glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', '; switch ($orderby) { case 'id': case 'ID': $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; break; case 'start_date': $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort; break; case 'end_date': $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; break; case 'event_name': $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; break; case 'category_slug': $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; break; case 'ticket_start': $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; break; case 'ticket_end': $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; break; case 'venue_title': $SQL .= $glue . 'venue_title ' . $sort; break; case 'city': $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; break; case 'state': $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; break; } $cntr++; } //echo '<h4>$SQL : ' . $SQL . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; return $SQL; }
/** * @Export data for ALL attendees * @access public * @return void */ function export_attendees() { $states_that_have_an_attendee = EEM_State::instance()->get_all(array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))); $countries_that_have_an_attendee = EEM_Country::instance()->get_all(array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL')))); // $states_to_export_query_params $models_to_export = array('Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), 'Attendee' => array()); $model_data = $this->_get_export_data_for_models($models_to_export); $filename = $this->generate_filename('all-attendees'); if (!$this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { EE_Error::add_error(__('An error occurred and the Attendee data could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } }
/** * Gets the list of states for the form input * * @param array|null $states_list * @param EE_Question $question * @param EE_Registration $registration * @return array 2d keys are state IDs, values are their names */ public function use_cached_states_for_form_input($states_list, $question, $registration, $answer) { $state_options = array('' => array('' => '')); $states = $this->checkout->action == 'process_reg_step' ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_active_states(); if (!empty($states)) { foreach ($states as $state) { if ($state instanceof EE_State) { $state_options[$state->country()->name()][$state->ID()] = $state->name(); } } } if ($question instanceof EE_Question && $registration instanceof EE_Registration) { $answer = EEM_Answer::instance()->get_one(array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))); } else { $answer = EE_Answer::new_instance(); } $state_options = apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', $state_options, $this, $registration, $question, $answer); return $state_options; }
/** * generate_state_dropdown * @param array $QST * @param bool $get_all * @return array */ public static function generate_state_dropdown($QST, $get_all = FALSE) { $states = $get_all ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_states_of_active_countries(); if ($states && count($states) != count($QST->options())) { $QST->set('QST_type', 'DROPDOWN'); // if multiple countries, we'll create option groups within the dropdown foreach ($states as $state) { if ($state instanceof EE_State) { $QSO = EE_Question_Option::new_instance(array('QSO_value' => $state->ID(), 'QSO_desc' => $state->name(), 'QST_ID' => $QST->get('QST_ID'), 'QSO_deleted' => FALSE)); // set option group $QSO->set_opt_group($state->country()->name()); // add option to question $QST->add_temp_option($QSO); } } } return $QST; }
/** * inject_new_reg_state_into_options * * @access public * @param \EE_State[] $state_options * @param \EE_SPCO_Reg_Step_Attendee_Information $reg_step * @param \EE_Registration $registration * @param \EE_Question $question * @param $answer * @return bool */ public static function inject_new_reg_state_into_options($state_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer) { if ($answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_state) { $STA_ID = $answer->value(); if (!empty($STA_ID)) { $state = EEM_State::instance()->get_one_by_ID($STA_ID); if ($state instanceof EE_State) { $country = $state->country(); if ($country instanceof EE_Country) { if (!isset($state_options[$country->name()])) { $state_options[$country->name()] = array(); } if (!isset($state_options[$country->name()][$STA_ID])) { $state_options[$country->name()][$STA_ID] = $state->name(); } } } } } return $state_options; }
/** * @param EE_Registration $registration * @param EE_Question $question * @param mixed EE_Answer|NULL $answer * @return EE_Form_Input_Base */ public function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) { // d( $registration ); // d( $question ); // d( $answer ); // array of params to pass to parent constructor. // possible values: // html_id; // html_class; // html_style; // name; // html_name; // html_label_id; // html_label_class; // html_label_style; // html_label_text; // html_label; // html_help_text; // html_help_class = 'description'; // html_help_style; // raw_value; $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); $input_constructor_args = array('html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, 'required' => $question->required() ? TRUE : FALSE, 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, 'html_label_class' => 'ee-reg-qstn', 'html_label_text' => $question->display_text(), 'required_validation_error_message' => $question->required_text()); // has this question been answered ? if ($answer instanceof EE_Answer) { if ($answer->ID()) { $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; $input_constructor_args['html_id'] .= '-' . $answer->ID(); $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); } $input_constructor_args['default'] = $answer->value(); } //add "-lbl" to the end of the label id $input_constructor_args['html_label_id'] .= '-lbl'; switch ($question->type()) { // Text case EEM_Question::QST_type_text: if ($identifier == 'email') { return new EE_Email_Input($input_constructor_args); } else { return new EE_Text_Input($input_constructor_args); } break; // Textarea // Textarea case EEM_Question::QST_type_textarea: return new EE_Text_Area_Input($input_constructor_args); break; // Radio Buttons // Radio Buttons case EEM_Question::QST_type_radio: return new EE_Radio_Button_Input($question->options(), $input_constructor_args); break; // Dropdown // Dropdown case EEM_Question::QST_type_dropdown: return new EE_Select_Input($question->options(), $input_constructor_args); break; // State Dropdown // State Dropdown case EEM_Question::QST_type_state: $state_options = array('' => array('' => '')); $states = $this->checkout->action == 'process_reg_step' ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_active_states(); if (!empty($states)) { foreach ($states as $state) { if ($state instanceof EE_State) { $state_options[$state->country()->name()][$state->ID()] = $state->name(); } } } $state_options = apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', $state_options, $this, $registration, $question, $answer); return new EE_State_Select_Input($state_options, $input_constructor_args); break; // Country Dropdown // Country Dropdown case EEM_Question::QST_type_country: $country_options = array('' => ''); // get possibly cached list of countries $countries = $this->checkout->action == 'process_reg_step' ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries(); if (!empty($countries)) { foreach ($countries as $country) { if ($country instanceof EE_Country) { $country_options[$country->ID()] = $country->name(); } } } $country_options = apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', $country_options, $this, $registration, $question, $answer); return new EE_Country_Select_Input($country_options, $input_constructor_args); break; // Checkboxes // Checkboxes case EEM_Question::QST_type_checkbox: return new EE_Checkbox_Multi_Input($question->options(), $input_constructor_args); break; // Date // Date case EEM_Question::QST_type_date: return new EE_Datepicker_Input($input_constructor_args); break; case EEM_Question::QST_type_html_textarea: $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); $input = new EE_Text_Area_Input($input_constructor_args); $input->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); return $input; // fallback // fallback default: $default_input = apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', null, $question->type(), $question, $input_constructor_args); if (!$default_input) { $default_input = new EE_Text_Input($input_constructor_args); } return $default_input; } }
/** * generates HTML for the Edit Registration side meta box * @access public * @return void */ public function _reg_billing_info_side_meta_box() { $billing_info = $this->_session['billing_info']; //echo printr( $billing_info, '$billing_info' ); if (is_array($billing_info)) { $this->_template_args['free_event'] = FALSE; $this->_template_args['fname']['value'] = !empty($billing_info['_reg-page-billing-fname']['value']) ? $billing_info['_reg-page-billing-fname']['value'] : ''; $this->_template_args['fname']['label'] = !empty($billing_info['_reg-page-billing-fname']['label']) ? $billing_info['_reg-page-billing-fname']['label'] : __('First Name', 'event_espresso'); $this->_template_args['lname']['value'] = !empty($billing_info['_reg-page-billing-lname']['value']) ? $billing_info['_reg-page-billing-lname']['value'] : ''; $this->_template_args['lname']['label'] = !empty($billing_info['_reg-page-billing-lname']['label']) ? $billing_info['_reg-page-billing-lname']['label'] : __('Last Name', 'event_espresso'); $this->_template_args['email']['value'] = !empty($billing_info['_reg-page-billing-email']['value']) ? $billing_info['_reg-page-billing-email']['value'] : ''; $this->_template_args['email']['label'] = __('Email', 'event_espresso'); $this->_template_args['address']['value'] = !empty($billing_info['_reg-page-billing-address']['value']) ? $billing_info['_reg-page-billing-address']['value'] : ''; $this->_template_args['address']['label'] = !empty($billing_info['_reg-page-billing-address']['label']) ? $billing_info['_reg-page-billing-address']['label'] : __('Address', 'event_espresso'); $this->_template_args['city']['value'] = !empty($billing_info['_reg-page-billing-city']['value']) ? $billing_info['_reg-page-billing-city']['value'] : ''; $this->_template_args['city']['label'] = !empty($billing_info['_reg-page-billing-city']['label']) ? $billing_info['_reg-page-billing-city']['label'] : __('City', 'event_espresso'); $this->_template_args['state']['value'] = !empty($billing_info['_reg-page-billing-state']['value']) ? $billing_info['_reg-page-billing-state']['value'] : ''; $this->_template_args['state']['label'] = !empty($billing_info['_reg-page-billing-state']['label']) ? $billing_info['_reg-page-billing-state']['label'] : __('State', 'event_espresso'); if ($state_obj = EEM_State::instance()->get_one_by_ID($this->_template_args['state']['value'])) { $this->_template_args['state']['value'] = $state_obj instanceof EE_State ? $state_obj->name() : $billing_info['_reg-page-billing-state']['value']; } $this->_template_args['country']['value'] = !empty($billing_info['_reg-page-billing-country']['value']) ? $billing_info['_reg-page-billing-country']['value'] : ''; $this->_template_args['country']['label'] = !empty($billing_info['_reg-page-billing-country']['label']) ? $billing_info['_reg-page-billing-country']['label'] : __('Country', 'event_espresso'); if ($country_obj = EEM_Country::instance()->get_one_by_ID($this->_template_args['country']['value'])) { $this->_template_args['country']['value'] = $country_obj instanceof EE_Country ? $country_obj->name() : $billing_info['_reg-page-billing-country']['value']; } $this->_template_args['zip']['value'] = !empty($billing_info['_reg-page-billing-zip']['value']) ? $billing_info['_reg-page-billing-zip']['value'] : ''; $this->_template_args['zip']['label'] = !empty($billing_info['_reg-page-billing-zip']['label']) ? $billing_info['_reg-page-billing-zip']['label'] : __('Zip Code', 'event_espresso'); if (isset($billing_info['_reg-page-billing-card-nmbr'])) { $this->_template_args['credit_card_info'] = TRUE; $ccard = $billing_info['_reg-page-billing-card-nmbr']['value']; $this->_template_args['card_nmbr']['value'] = substr($ccard, 0, 4) . ' XXXX XXXX ' . substr($ccard, -4); $this->_template_args['card_nmbr']['label'] = __('Credit Card', 'event_espresso'); $this->_template_args['card_exp_date']['value'] = $billing_info['_reg-page-billing-card-exp-date-mnth']['value'] . ' / ' . $billing_info['_reg-page-billing-card-exp-date-year']['value']; $this->_template_args['card_exp_date']['label'] = __('mm / yy', 'event_espresso'); $this->_template_args['card_ccv_code']['value'] = $billing_info['_reg-page-billing-card-ccv-code']['value']; $this->_template_args['card_ccv_code']['label'] = $billing_info['_reg-page-billing-card-ccv-code']['label']; } else { $this->_template_args['credit_card_info'] = FALSE; } } else { $this->_template_args['free_event'] = $billing_info; } $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_box_billing_info.template.php'; echo EEH_Template::display_template($template_path, $this->_template_args, TRUE); }
/** * _update_country_settings * * @access protected * @return void */ protected function _update_country_settings() { // EEH_Debug_Tools::printr( $this->_req_data, '$this->_req_data <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); // grab the country ISO code $CNT_ISO = isset($this->_req_data['country']) ? strtoupper(sanitize_text_field($this->_req_data['country'])) : FALSE; if (!$CNT_ISO) { EE_Error::add_error(__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); return; } $cols_n_values = array(); $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) : FALSE; $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) : NULL; $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) : NULL; $cols_n_values['CNT_cur_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) : 'USD'; $cols_n_values['CNT_cur_single'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) : 'dollar'; $cols_n_values['CNT_cur_plural'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) : 'dollars'; $cols_n_values['CNT_cur_sign'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) : '$'; $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) : TRUE; $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) : 2; $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) : '.'; $cols_n_values['CNT_cur_thsnds'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) : ','; $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) : NULL; $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) : FALSE; $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) : FALSE; // allow filtering of country data $cols_n_values = apply_filters('FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', $cols_n_values); //EEH_Debug_Tools::printr( $cols_n_values, '$cols_n_values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); // where values $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); // run the update $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); // global $wpdb; // echo '<h4>' . $wpdb->last_query . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // echo '<h4>$success : ' . $success . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== FALSE) { // allow filtering of states data $states = apply_filters('FHEE__General_Settings_Admin_Page___update_country_settings__states', $this->_req_data['states']); // EEH_Debug_Tools::printr( $states, '$states <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); // loop thru state data ( looks like : states[75][STA_name] ) foreach ($states as $STA_ID => $state) { $cols_n_values = array('CNT_ISO' => $CNT_ISO, 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), 'STA_name' => sanitize_text_field($state['STA_name']), 'STA_active' => (bool) absint($state['STA_active'])); // where values $where_cols_n_values = array(array('STA_ID' => $STA_ID)); // run the update $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); if ($success !== FALSE) { do_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', $CNT_ISO, $STA_ID, $cols_n_values); } } } // check if country being edited matches org option country, and if so, then update EE_Config with new settings if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO) { EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); EE_Registry::instance()->CFG->update_espresso_config(); } $this->_redirect_after_action($success, 'Countries', 'updated', array('action' => 'country_settings', 'country' => $CNT_ISO)); }
/** * Adjust the billing form data. * Need Country and State abbreviations, not full names. * * @param billing_form * @return array */ protected function _get_billing_values_from_form($billing_form) { $billing_values = parent::_get_billing_values_from_form($billing_form); $billing_values['country'] = $billing_form->get_input_value('country'); $state = EEM_State::instance()->get_col(array(array('STA_name' => $billing_values['state']), 'limit' => 1), 'STA_abbrev'); $billing_values['state'] = $state[0]; return $billing_values; }