/**
  *		_get_countries
  *		Gets and caches the list of active countries. If you know the list of active countries
  *		has changed during this request, first use EEM_Country::reset() to flush the cache
  * 		@access		public
  *		@return 		array
  */
 public function get_all_active_countries()
 {
     if (!self::$_active_countries) {
         self::$_active_countries = $this->get_all(array(array('CNT_active' => TRUE), 'order_by' => array('CNT_name' => 'ASC'), 'limit' => array(0, 99999)));
     }
     return self::$_active_countries;
 }
 public function test_save_and_clean_billing_info_for_payment_method()
 {
     $pm = EE_Payment_Method::new_instance(array('PMD_type' => 'Aim'));
     $pm->save();
     //reset the country model because it caches its list of countries which is used when
     //making most billing forms
     EEM_Country::reset();
     $form = $pm->type_obj()->billing_form();
     $form_name = $form->name();
     $form_values = array('first_name' => 'e', 'last_name' => 'e', 'email' => '*****@*****.**', 'address' => '123', 'address2' => '', 'city' => 'someville', 'state' => 12, 'country' => 'US', 'zip' => '1235', 'phone' => '9991231234', 'credit_card' => '4007000000027', 'exp_month' => '12', 'exp_year' => '2020', 'cvv' => '123');
     $form->receive_form_submission(array($form_name => $form_values));
     $this->assertTrue($form->is_valid(), 'error was: ' . $form->get_validation_error_string());
     $p = $this->new_model_obj_with_dependencies('Payment', array('PMD_ID' => $pm->ID()));
     $reg = $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $p->TXN_ID()));
     $att = $reg->attendee();
     $att->save_and_clean_billing_info_for_payment_method($form, $pm);
     //ok so now it should ahve been saved. Let's verify that
     $billing_info_form = $att->billing_info_for_payment_method($pm);
     $this->assertInstanceOf('EE_Billing_Attendee_Info_Form', $billing_info_form);
     //it should ahve been cleaned too, so lets tweak teh form values ot what they should be
     $form_values['credit_card'] = 'XXXXXXXXX0027';
     $form_values['cvv'] = 'XXX';
     $form_values['exp_month'] = '';
     $form_values['exp_year'] = 0;
     foreach ($form_values as $input_name => $value) {
         $input = $billing_info_form->get_input($input_name);
         $this->assertInstanceOf('EE_Form_Input_Base', $input);
         $this->assertEquals($value, $input->raw_value(), $input_name);
     }
 }
 /**
  *        _get_states
  *
  * @access        public
  * @param array $countries
  * @param bool  $flush_cache
  * @return        array
  */
 public function get_all_active_states($countries = array(), $flush_cache = FALSE)
 {
     if (!self::$_active_states || $flush_cache) {
         $countries = is_array($countries) && !empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
         self::$_active_states = $this->get_all(array(array('STA_active' => TRUE, 'CNT_ISO' => array('IN', array_keys($countries))), 'order_by' => array('STA_name' => 'ASC'), 'limit' => array(0, 99999), 'force_join' => array('Country')));
     }
     return self::$_active_states;
 }
 /**
  * Verifies we don't change these options into booleans
  * @group 8006
  */
 function test_double_valued_with_blank()
 {
     EEM_Country::instance()->update(array('CNT_active' => false), array());
     EEM_Country::instance()->update(array('CNT_active' => true), array('limit' => 1));
     $active_countries = EEM_Country::instance()->get_all(array(array('CNT_active' => true)));
     $this->assertEquals(1, count($active_countries));
     $active_country = reset($active_countries);
     $country_input = new EE_Country_Select_Input();
     $this->assertEquals(array('' => '', $active_country->ID() => $active_country->name()), $country_input->options());
     $this->assertInstanceOf('EE_Text_Normalization', $country_input->get_normalization_strategy());
 }
 /**
  *
  * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes. By default, all are allowed
  * @param array $input_settings
  */
 function __construct($only_specific_currency_codes = array(), $input_settings = array())
 {
     $query_params = array('order_by' => array('CNT_name' => 'asc'));
     if ($only_specific_currency_codes) {
         $query_params[0]['CNT_cur_code'] = array('IN', $only_specific_currency_codes);
     }
     $all_countries = EEM_Country::instance()->get_all($query_params);
     $country_options = array();
     foreach ($all_countries as $country) {
         /* @var $country EE_Country */
         $country_options[$country->currency_code()] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
     }
     parent::__construct($country_options, 'int', $input_settings);
 }
 /**
  * get_country_answer_options
  *
  * @param array $country_options
  * @return array
  */
 public function get_country_answer_options($country_options = NULL)
 {
     // if passed something that is NOT an array
     if (!is_array($country_options)) {
         // get possibly cached list of countries
         $countries = EEM_Country::instance()->get_all_active_countries();
         if (!empty($countries)) {
             $country_options[''] = '';
             foreach ($countries as $country) {
                 if ($country instanceof EE_Country) {
                     $country_options[$country->ID()] = $country->name();
                 }
             }
         } else {
             $country_options = array();
         }
     }
     return $country_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 '';
 }
 /**
  * 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_CNT_ISO($item)
 {
     $countries = EEM_Country::instance()->get_all_countries();
     //EEH_Debug_Tools::printr( $countries, '$countries  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
     $country = isset($countries[$item->country_ID()]) ? $countries[$item->country_ID()]->get('CNT_name') : $item->country_ID();
     return !is_numeric($country) ? $country : '';
 }
 /**
  * 		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);
 }
Ejemplo n.º 12
0
 /**
  * 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);
 }
 /**
  * test we dont insert conflicting data (especially term-taxonomies)
  */
 public function test_save_data_array_to_db__from_other_site__avoid_inserting_conflicting_data()
 {
     $term_taxonomy = $this->new_model_obj_with_dependencies('Term_Taxonomy', array('taxonomy' => 'category', 'description' => 'original term-taxonomy'));
     $this->assertEquals('original term-taxonomy', $term_taxonomy->get('description'));
     $term_taxonomy_from_other_db = $this->new_model_obj_with_dependencies('Term_Taxonomy', array('term_id' => $term_taxonomy->get('term_id'), 'taxonomy' => 'category', 'description' => 'in other db'), false);
     $country_usa = EEM_Country::instance()->get_one_by_ID('US');
     $this->assertEquals(false, $country_usa->get('CNT_is_EU'));
     //have the contry be slightly modified in the exporting site
     $country_usa_props = $country_usa->model_field_array();
     $country_usa_props['CNT_is_EU'] = true;
     $csv_data_rows = array('Term_Taxonomy' => array($term_taxonomy_from_other_db->model_field_array()), 'Country' => array($country_usa_props));
     $term_taxonomy_count = EEM_Term_Taxonomy::instance()->count();
     $country_count = EEM_Country::instance()->count();
     //ok give it a whirl (keep the term-taxonomy's "term_id" the same by having it map to itself, obviously super unlikely but helps testing)
     EE_Import::instance()->save_data_rows_to_db($csv_data_rows, true, array('Term' => array($term_taxonomy->get('term_id') => $term_taxonomy->get('term_id'))));
     $this->assertEmpty(EE_Import::instance()->get_total_update_errors());
     $this->assertEmpty(EE_Import::instance()->get_total_inserts());
     $this->assertEmpty(EE_Import::instance()->get_total_insert_errors());
     $this->assertEquals(2, EE_Import::instance()->get_total_updates());
     //there shouldn't be any new term taxonomies or countries
     $this->assertEquals($term_taxonomy_count, EEM_Term_Taxonomy::instance()->count());
     $this->assertEquals($country_count, EEM_Country::instance()->count());
     //however, they should be updated
     $updated_term_taxonomy = EEM_Term_Taxonomy::instance()->refresh_entity_map_from_db($term_taxonomy->ID());
     $this->assertEquals('in other db', $updated_term_taxonomy->get('description'));
     $updated_country = EEM_Country::instance()->refresh_entity_map_from_db($country_usa->ID());
     $this->assertEquals(true, $updated_country->get('CNT_is_EU'));
 }
Ejemplo n.º 14
0
 /**
  *			@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 countries for the form input
  *
  * @param array|null $countries_list
  * @param EE_Question $question
  * @param EE_Registration $registration
  * @return array 2d keys are country IDs, values are their names
  */
 public function use_cached_countries_for_form_input($countries_list, $question, $registration, $answer)
 {
     $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();
             }
         }
     }
     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();
     }
     $country_options = apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', $country_options, $this, $registration, $question, $answer);
     return $country_options;
 }
 /**
  *    generate_country_dropdown
  * @param      $QST
  * @param bool $get_all
  * @internal param array $question
  * @return array
  */
 public static function generate_country_dropdown($QST, $get_all = FALSE)
 {
     $countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries();
     if ($countries && count($countries) != count($QST->options())) {
         $QST->set('QST_type', 'DROPDOWN');
         // now add countries
         foreach ($countries as $country) {
             if ($country instanceof EE_Country) {
                 $QSO = EE_Question_Option::new_instance(array('QSO_value' => $country->ID(), 'QSO_desc' => $country->name(), 'QST_ID' => $QST->get('QST_ID'), 'QSO_deleted' => FALSE));
                 $QST->add_temp_option($QSO);
             }
         }
     }
     return $QST;
 }
 /**
  * @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;
     }
 }
			<?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;
        ?>
		</div>
		
		<?php 
 /**
  * 		_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));
 }
 /**
  *    inject_new_reg_country_into_options
  *
  * @access public
  * @param \EE_Country[] $country_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_country_into_options($country_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_country) {
         $CNT_ISO = $answer->value();
         if (!empty($CNT_ISO)) {
             $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
             if ($country instanceof EE_Country) {
                 if (!isset($country_options[$CNT_ISO])) {
                     $country_options[$CNT_ISO] = $country->name();
                 }
             }
         }
     }
     return $country_options;
 }