/**
  * 		column_default
  */
 function column_DTT_EVT_start(EE_Registration $item)
 {
     $datetime_strings = array();
     $remove_defaults = array('default_where_conditions' => 'none');
     $ticket = $item->ticket();
     $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array();
     $query_args = array('action' => 'event_registrations', 'event_id' => $item->event_ID());
     foreach ($datetimes as $datetime) {
         $query_args['DTT_ID'] = $datetime->ID();
         $checkin_url = EE_Admin_Page::add_query_args_and_nonce($query_args, REG_ADMIN_URL);
         $datetime_strings[] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $item->ID()) ? '<a href="' . $checkin_url . '" title="' . esc_attr__('View Checkins for this Event', 'event_espresso') . '">' . $datetime->get_i18n_datetime('DTT_EVT_start') . '</a>' : $datetime->get_i18n_datetime('DTT_EVT_start');
     }
     return implode("<br />", $datetime_strings);
 }
 /**
  * @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;
     }
 }
 /**
  * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what models get affected.
  * @param  EE_Registration $REG registration to be deleted permenantly
  * @return boolean              true = successful deletion, false = fail.
  */
 protected function _delete_registration(EE_Registration $REG)
 {
     //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
     $TXN = $REG->get_first_related('Transaction');
     $REGS = $TXN->get_many_related('Registration');
     $all_trashed = TRUE;
     foreach ($REGS as $registration) {
         if (!$registration->get('REG_deleted')) {
             $all_trashed = FALSE;
         }
     }
     if (!$all_trashed) {
         EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
     foreach ($REGS as $registration) {
         //delete related answers
         $registration->delete_related_permanently('Answer');
         //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
         $attendee = $registration->get_first_related('Attendee');
         if ($attendee instanceof EE_Attendee) {
             $registration->_remove_relation_to($attendee, 'Attendee');
         }
         //now remove relationships to tickets on this registration.
         $registration->_remove_relations('Ticket');
         //now delete permanently the checkins related to this registration.
         $registration->delete_related_permanently('Checkin');
         if ($registration->ID() === $REG->ID()) {
             continue;
         }
         //we don't want to delete permanently the existing registration just yet.
         //remove relation to transaction for these registrations if NOT the existing registrations
         $registration->_remove_relations('Transaction');
         //now delete this registration permanently
         $registration->delete_permanently();
     }
     //now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
     //delete the line items related to the transaction for this registration.
     $TXN->delete_related_permanently('Line_Item');
     //we need to remove all the relationships on the transaction
     $TXN->delete_related_permanently('Payment');
     $TXN->delete_related_permanently('Extra_Meta');
     //now we can delete this REG permanently (and the transaction of course)
     $REG->delete_related_permanently('Transaction');
     return $REG->delete_permanently();
 }
 /**
  * _save_question_answers
  *
  * @param 	EE_Registration 	$registration
  * @param bool $show_errors
  * @return void
  */
 private function _save_registration_answers($registration, $show_errors = TRUE)
 {
     // now save the answers
     foreach ($registration->answers() as $cache_key => $answer) {
         // verify object
         if ($answer instanceof EE_Answer) {
             $answer->set_registration($registration->ID());
             $answer->save();
             if (!$registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
                 if ($show_errors) {
                     EE_Error::add_error(__('The newly saved Answer object could not be cached on the registration.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
                 }
             }
         } else {
             if ($show_errors) {
                 EE_Error::add_error(__('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             }
         }
     }
 }
 /**
  * Gets the EE_Answer object for the question for this registration (if it exists)
  * @param EE_Registration $registration
  * @param int $question_id
  * @return EE_Answer
  */
 public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL)
 {
     $answer_obj = $this->get_one(array(array('QST_ID' => $question_id, 'REG_ID' => $registration->ID())));
     return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
 }
 /**
  * update registration REG_paid field after successful payment and link registration with payment
  *
  * @param EE_Registration $registration
  * @param EE_Payment $payment
  * @param float $payment_amount
  * @return float
  * @throws \EE_Error
  */
 protected function _apply_registration_payment(EE_Registration $registration, EE_Payment $payment, $payment_amount = 0.0)
 {
     // find any existing reg payment records for this registration and payment
     $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())));
     // if existing registration payment exists
     if ($existing_reg_payment instanceof EE_Registration_Payment) {
         // then update that record
         $existing_reg_payment->set_amount($payment_amount);
         $existing_reg_payment->save();
     } else {
         // or add new relation between registration and payment and set amount
         $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
         // make it stick
         $registration->save();
     }
 }
 private function _get_ticket_list_from_registration(EE_Registration $registration, $att = NULL)
 {
     return isset($this->_extra_data['data']->registrations) ? array($this->_extra_data['data']->registrations[$registration->ID()]['tkt_obj']) : array();
 }
 function column_ATT_name(EE_Registration $item)
 {
     $attendee = $item->attendee();
     if (!$attendee instanceof EE_Attendee) {
         return __('No contact record for this registration.', 'event_espresso');
     }
     // edit attendee link
     $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
     $name_link = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact', 'event_espresso') . '">' . $item->attendee()->full_name() . '</a>' : $item->attendee()->full_name();
     $name_link .= $item->count() == 1 ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	' : '';
     //add group details
     $name_link .= '&nbsp;' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
     //add regcode
     $link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
     $name_link .= '<br>';
     $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can('ee_read_registration', 'view_registration', $item->ID()) ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' . $item->reg_code() . '</a>' : $item->reg_code();
     //status
     $name_link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') . '</span>';
     $actions = array();
     $DTT_ID = !empty($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : NULL;
     $DTT_ID = empty($DTT_ID) && !empty($this->_req_data['event_id']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['event_id'])->primary_datetime()->ID() : $DTT_ID;
     if (!empty($DTT_ID) && EE_Registry::instance()->CAP->current_user_can('ee_read_checkins', 'espresso_registrations_registration_checkins')) {
         $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID));
         $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__('View all the check-ins/checkouts for this registrant', 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>';
     }
     return !empty($DTT_ID) ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)) : $name_link;
 }
 /**
  * column_ATT_fname
  *
  * @access public
  * @param \EE_Registration $item
  * @return string
  */
 function column_ATT_fname(EE_Registration $item)
 {
     $attendee = $item->attendee();
     $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
     $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
     $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID()) ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' . $attendee_name . '</a>' : $attendee_name;
     $link .= $item->count() == 1 ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
     $t = $item->get_first_related('Transaction');
     $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
     //trash/restore/delete actions
     $actions = array();
     if ($this->_view != 'trash' && $payment_count === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', 'espresso_registrations_trash_registrations', $item->ID())) {
         $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_registrations', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
         $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
     } elseif ($this->_view == 'trash') {
         // restore registration link
         if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', 'espresso_registrations_restore_registrations', $item->ID())) {
             $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_registrations', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
             $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>';
         }
         if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', 'espresso_registrations_ee_delete_registrations', $item->ID())) {
             $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_registrations', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
             $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' . esc_attr__('Delete Registration Permanently', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>';
         }
     }
     return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
 }
 /**
  * sets reg status based either on passed param or on transaction status and event pre-approval setting
  *
  * @param \EE_Registration $registration
  * @param array 	$additional_details
  * @return bool
  */
 public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array())
 {
     // set initial REG_Status
     $this->set_old_reg_status($registration->ID(), $registration->status_ID());
     // if the registration status gets updated, then save the registration
     if ($this->toggle_registration_status_for_default_approved_events($registration, false) || $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details)) {
         $registration->save();
     }
     // set new  REG_Status
     $this->set_new_reg_status($registration->ID(), $registration->status_ID());
     return $this->reg_status_updated($registration->ID()) && $this->new_reg_status($registration->ID()) == EEM_Registration::status_id_approved ? true : false;
 }
    /**
     * 		column_actions
     */
    function column_actions(EE_Registration $item)
    {
        //Build row actions
        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_attendee', 'post' => $item->attendee_ID()), REG_ADMIN_URL);
        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
        //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
        //Build row actions
        $view_lnk = '
		<li>
			<a href="' . $view_lnk_url . '" title="' . __('View Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-clipboard"></div>
			</a>
		</li>';
        $edit_lnk = '
		<li>
			<a href="' . $edit_lnk_url . '" title="' . __('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
			</a>
		</li>';
        $resend_reg_lnk = '
		<li>
			<a href="' . $resend_reg_lnk_url . '" title="' . __('Resend Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-email-alt"></div>
			</a>
		</li>';
        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), TXN_ADMIN_URL);
        $view_txn_lnk = '
		<li>
			<a href="' . $view_txn_lnk_url . '"  title="' . __('View Transaction', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-cart"></div>
			</a>
		</li>';
        $actions = '
	<ul class="reg-overview-actions-ul">' . $view_lnk . $edit_lnk . $resend_reg_lnk . $view_txn_lnk . '
	</ul>';
        return $actions;
    }
 private function _get_events_from_registration(EE_Registration $registration)
 {
     return isset($this->_extra_data['data']->registrations) ? array($this->_extra_data['data']->registrations[$registration->ID()]['evt_obj']) : array();
 }
 /**
  * REG_code
  * @param  EE_Registration $item EE_Registration object
  * @return string                Registration code
  */
 function column__REG_code(EE_Registration $item)
 {
     $link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
     return EE_Registry::instance()->instance()->CAP->current_user_can('ee_read_registration', 'view_registration', $item->ID()) ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' . $item->get('REG_code') . '</a>' : $item->get('REG_code');
 }
 /**
  * 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;
 }