/**
  * 		generates HTML for the Edit Registration side meta box
  *		@access public
  *		@return void
  */
 public function _reg_registrant_side_meta_box()
 {
     /*@var $attendee EE_Attendee */
     $att_check = $this->_registration->attendee();
     $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
     //now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show cereate button or not)
     if (!$this->_registration->is_primary_registrant()) {
         $primary_registration = $this->_registration->get_primary_registration();
         $primary_attendee = $primary_registration->attendee();
         if (!$primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
             //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
             $primary_registration = NULL;
         }
     } else {
         $primary_registration = NULL;
     }
     $this->_template_args['ATT_ID'] = $attendee->ID();
     $this->_template_args['fname'] = $attendee->fname();
     //$this->_registration->ATT_fname;
     $this->_template_args['lname'] = $attendee->lname();
     //$this->_registration->ATT_lname;
     $this->_template_args['email'] = $attendee->email();
     //$this->_registration->ATT_email;
     $this->_template_args['phone'] = $attendee->phone();
     $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
     //edit link
     $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_attendee', 'post' => $attendee->ID()), REG_ADMIN_URL);
     $this->_template_args['att_edit_label'] = __('View/Edit Contact');
     //create link
     $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration ? EE_Admin_Page::add_query_args_and_nonce(array('action' => 'duplicate_attendee', '_REG_ID' => $this->_registration->ID()), REG_ADMIN_URL) : '';
     $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
     $this->_template_args['att_check'] = $att_check;
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 protected function _get_data_for_context($context, EE_Registration $registration, $id)
 {
     //newsletter message type data handler is 'Contacts' and it expects an array of EE_Attendee objects.
     $contact = $registration->attendee();
     if ($contact instanceof EE_Attendee) {
         return array($contact);
     }
     return array();
 }
 /**
  * 	get_transaction_details
  *
  *  @access 	public
  *  @return 	string
  */
 public function get_transaction_details()
 {
     //prepare variables for displaying
     $template_args = array();
     $template_args['transaction'] = $this->_current_txn;
     $template_args['reg_url_link'] = $this->_reg_url_link;
     $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(TRUE);
     // link to SPCO payment_options
     $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
     $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
     // verify template arguments
     EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
     EEH_Template_Validator::verify_isnt_null($template_args['show_try_pay_again_link'], '$show_try_pay_again_link');
     EEH_Template_Validator::verify_isnt_null($template_args['SPCO_payment_options_url'], '$SPCO_payment_options_url');
     return EEH_Template::locate_template(THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', $template_args, TRUE, TRUE);
 }
 /**
  * _save_registration_attendee
  *
  * @param 	EE_Registration 	$registration
  * @return void
  */
 protected function _refresh_registration_attendee($registration)
 {
     $attendee = $registration->attendee();
     // verify object
     if ($attendee instanceof EE_Attendee && $attendee->ID()) {
         // make sure the cached attendee is added to the model entity mapper
         $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
         // maybe cache primary_attendee_obj ?
         if ($registration->is_primary_registrant()) {
             $this->primary_attendee_obj = $attendee;
         }
     }
 }
 /**
  * Gets the string answer to the question for this registration's attendee
  * @param EE_Registration $registration
  * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string then it should be its QST_system value.
  *	Passing in the QST_system value is more efficient
  * @param boolean $pretty_answer
  * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for 
  * a question corresponding to an attendee field, returns null)
  */
 public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE)
 {
     $field_name = NULL;
     $value = NULL;
     //backward compat: we still want to find the question's ID
     if (is_numeric($question_system_id)) {
         //find this question's QST_system value
         $question_id = $question_system_id;
         $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system');
     } else {
         $question_id = intval(EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'));
     }
     //only bother checking if the registration has an attendee
     if ($registration->attendee() instanceof EE_Attendee) {
         $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
         if ($field_name) {
             if ($pretty_answer) {
                 if ($field_name == 'STA_ID') {
                     $state = $registration->attendee()->state_obj();
                     $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
                 } else {
                     if ($field_name == 'CNT_ISO') {
                         $country = $registration->attendee()->country_obj();
                         $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
                     } else {
                         $value = $registration->attendee()->get_pretty($field_name);
                     }
                 }
                 //if field name is blank, leave the value as null too
             } else {
                 $value = $registration->attendee()->get($field_name);
             }
         }
         //if no field was found, leave value blank
     }
     return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
 }
 function column_ATT_email(EE_Registration $item)
 {
     $attendee = $item->attendee();
     return $attendee instanceof EE_Attendee ? $attendee->email() : '';
     return $item->get_first_related('Attendee')->email();
 }
    /**
     * column_actions
     *
     * @access public
     * @param \EE_Registration $item
     * @return string
     */
    function column_actions(EE_Registration $item)
    {
        $attendee = $item->attendee();
        $ticket = $item->ticket();
        $this->_set_related_details($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, true);
        //Build row actions
        $view_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID()) ? '
			<li>
			<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-clipboard"></div>
			</a>
			</li>' : '';
        $edit_lnk = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') && $attendee instanceof EE_Attendee ? '
			<li>
			<a href="' . $edit_lnk_url . '" title="' . esc_attr__('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 = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration', $item->ID()) ? '
			<li>
			<a href="' . $resend_reg_lnk_url . '" title="' . esc_attr__('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' => $this->_transaction_details['id']), TXN_ADMIN_URL);
        $view_txn_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? '
			<li>
			<a class="ee-status-color-' . $this->_transaction_details['status'] . '" href="' . $view_txn_lnk_url . '"  title="' . $this->_transaction_details['title_attr'] . '" class="tiny-text">
				<div class="dashicons dashicons-cart"></div>
			</a>
			</li>' : '';
        return $this->_action_string($view_lnk . $edit_lnk . $resend_reg_lnk . $view_txn_lnk, $item, 'ul', 'reg-overview-actions-ul');
    }
 /**
  * 		column_ATT_fname
  */
 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 = '<a href="' . $edit_lnk_url . '" title="' . __('View Registration Details', 'event_espresso') . '">' . $attendee_name . '</a>';
     $link .= $item->count() == 1 ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
     $payment_count = $item->get_first_related('Transaction')->count_related('Payment');
     //trash/restore/delete actions
     $actions = array();
     if ($this->_view != 'trash' && $payment_count === 0) {
         $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="' . __('Trash Registration', 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
     } elseif ($this->_view == 'trash') {
         // restore registration link
         $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_registrations', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
         $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_registrations', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
         $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . __('Restore Registration', 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>';
         $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' . __('Delete Registration Permanently', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>';
     }
     return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
 }
 /**
  * Gets the string answer to the question for this registration's attendee
  * @param EE_Registration $registration
  * @param int $question_id
  * @param boolean $pretty_answer
  * @return string
  */
 public function get_attendee_property_answer_value(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE)
 {
     $field_name = NULL;
     $value = NULL;
     //only bother checking if the registration has an attendee
     if ($registration->attendee() instanceof EE_Attendee && isset($this->_question_id_to_att_field_map[$question_id])) {
         $field_name = $this->_question_id_to_att_field_map[$question_id];
         if ($pretty_answer) {
             if ($field_name == 'STA_ID') {
                 $state = $registration->attendee()->state_obj();
                 $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
             } else {
                 if ($field_name == 'CNT_ISO') {
                     $country = $registration->attendee()->country_obj();
                     $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
                 } else {
                     $value = $registration->attendee()->get_pretty($field_name);
                 }
             }
         } else {
             $value = $registration->attendee()->get($field_name);
         }
     }
     return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id);
 }
    /**
     * column_actions
     *
     * @access public
     * @param \EE_Registration $item
     * @return string
     * @throws \EE_Error
     */
    public function column_actions(EE_Registration $item)
    {
        $attendee = $item->attendee();
        $this->_set_related_details($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, true);
        //Build row actions
        $view_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID()) ? '
			<li>
			<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-clipboard"></div>
			</a>
			</li>' : '';
        $edit_lnk = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') && $attendee instanceof EE_Attendee ? '
			<li>
			<a href="' . $edit_lnk_url . '" title="' . esc_attr__('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 = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration', $item->ID()) ? '
			<li>
			<a href="' . $resend_reg_lnk_url . '" title="' . esc_attr__('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' => $this->_transaction_details['id']), TXN_ADMIN_URL);
        $view_txn_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? '
			<li>
			<a class="ee-status-color-' . $this->_transaction_details['status'] . ' tiny-text" href="' . $view_txn_lnk_url . '"  title="' . $this->_transaction_details['title_attr'] . '">
				<div class="dashicons dashicons-cart"></div>
			</a>
			</li>' : '';
        //invoice link
        $dl_invoice_lnk = '';
        $dl_invoice_lnk_url = $item->invoice_url();
        //only show invoice link if message type is active.
        if ($attendee instanceof EE_Attendee && $item->is_primary_registrant() && EEH_MSG_Template::is_mt_active('invoice')) {
            $dl_invoice_lnk = '
		<li>
			<a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text">
				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
			</a>
		</li>';
        }
        $filtered_messages_link = '';
        //message list table link (filtered by REG_ID
        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
            $filtered_messages_link = '<li>' . EEH_MSG_Template::get_message_action_link('see_notifications_for', null, array('_REG_ID' => $item->ID())) . '</li>';
        }
        return $this->_action_string($view_lnk . $edit_lnk . $resend_reg_lnk . $view_txn_lnk . $dl_invoice_lnk . $filtered_messages_link, $item, 'ul', 'reg-overview-actions-ul');
    }