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();
 }
 protected function _get_data_for_context($context, EE_Registration $registration, $id)
 {
     //receipt message type data handler is 'Gateways' and it expects a transaction object.
     $transaction = $registration->transaction();
     if ($transaction instanceof EE_Transaction) {
         return array($transaction);
     }
     return array();
 }
 protected function _get_data_for_context($context, EE_Registration $registration, $id)
 {
     //use the registration to get the transaction.
     $transaction = $registration->transaction();
     //bail early if no transaction
     if (!$transaction instanceof EE_Transaction) {
         throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
     }
     $payment = !empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
     return array($transaction, $payment);
 }
 /**
  * 		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);
 }
 public function test_events()
 {
     $a = EE_Attendee::new_instance();
     $a->save();
     $this->assertNotEquals($a->ID(), 0);
     $e1 = EE_Event::new_instance(array('EVT_name' => '1'));
     $e1->save();
     $this->assertNotEquals($e1->ID(), 0);
     $e2 = EE_Event::new_instance(array('EVT_name' => '2'));
     $e2->save();
     $this->assertNotEquals($e2->ID(), 0);
     $e3 = EE_Event::new_instance(array('EVT_name' => '3'));
     $e3->save();
     $this->assertNotEquals($e3->ID(), 0);
     $r1 = EE_Registration::new_instance(array('EVT_ID' => $e1->ID(), 'ATT_ID' => $a->ID()));
     $r1->save();
     $this->assertNotEquals($r1->ID(), 0);
     $r2 = EE_Registration::new_instance(array('EVT_ID' => $e2->ID(), 'ATT_ID' => $a->ID()));
     $r2->save();
     $this->assertNotEquals($r2->ID(), 0);
     $events = $a->events();
     $this->assertArrayContains($e1, $events);
     $this->assertArrayContains($e2, $events);
     $this->assertArrayDoesNotContain($e3, $events);
 }
 function espresso_replace_invoice_shortcodes($content)
 {
     $EE = EE_Registry::instance();
     //Create the logo
     if (!empty($this->invoice_settings['invoice_logo_url'])) {
         $invoice_logo_url = $this->invoice_settings['invoice_logo_url'];
     } else {
         $invoice_logo_url = $EE->CFG->organization->logo_url;
     }
     if (!empty($invoice_logo_url)) {
         $image_size = getimagesize($invoice_logo_url);
         $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
     } else {
         $invoice_logo_image = '';
     }
     $SearchValues = array("[organization]", "[registration_code]", "[transaction_id]", "[name]", "[base_url]", "[download_link]", "[invoice_logo_image]", "[street]", "[city]", "[state]", "[zip]", "[email]", "[vat]", "[registration_date]", "[instructions]");
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     if ($org_state) {
         $org_state_name = $org_state->name();
     } else {
         $org_state_name = '';
     }
     $ReplaceValues = array(stripslashes($EE->CFG->organization->name), $this->registration->reg_code(), $this->transaction->ID(), $primary_attendee->full_name(), is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice') ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' : EE_GATEWAYS_URL . 'Invoice/lib/templates/', $this->registration->invoice_url(), $invoice_logo_image, empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->address_1 : $EE->CFG->organization->address_1 . '<br>' . $EE->CFG->organization->address_2, $EE->CFG->organization->city, $org_state_name, $EE->CFG->organization->zip, $EE->CFG->organization->email, $EE->CFG->organization->vat, date_i18n(get_option('date_format'), strtotime($this->registration->date())), $this->invoice_settings['pdf_instructions']);
     return str_replace($SearchValues, $ReplaceValues, $content);
 }
 /**
  * 	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);
 }
 function espresso_replace_invoice_shortcodes($content)
 {
     $EE = EE_Registry::instance();
     //Create the logo
     $invoice_logo_url = $this->invoice_payment_method->get_extra_meta('pdf_logo_image', TRUE, $EE->CFG->organization->logo_url);
     if (!empty($invoice_logo_url)) {
         $image_size = getimagesize($invoice_logo_url);
         $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
     } else {
         $invoice_logo_image = '';
     }
     $SearchValues = array("[organization]", "[registration_code]", "[transaction_id]", "[name]", "[base_url]", "[download_link]", "[invoice_logo_image]", "[street]", "[city]", "[state]", "[zip]", "[email]", "[vat]", "[registration_date]", "[instructions]");
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     if ($org_state) {
         $org_state_name = $org_state->name();
     } else {
         $org_state_name = '';
     }
     $ReplaceValues = array($EE->CFG->organization->get_pretty('name'), $this->registration->reg_code(), $this->transaction->ID(), $primary_attendee->full_name(), is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice') ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' : EE_GATEWAYS_URL . 'Invoice/lib/templates/', $this->registration->invoice_url(), $invoice_logo_image, empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty('address_1') : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'), $EE->CFG->organization->get_pretty('city'), $org_state_name, $EE->CFG->organization->get_pretty('zip'), $EE->CFG->organization->get_pretty('email'), $EE->CFG->organization->vat, $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), $this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE));
     return str_replace($SearchValues, $ReplaceValues, $content);
 }
 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();
 }
 /**
  * 		column_TXN_total
  */
 function column_TXN_total(EE_Registration $item)
 {
     $txn = $item->transaction();
     $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
     if ($item->get('REG_count') == 1) {
         $line_total_obj = $txn->total_line_item();
         $txn_total = $line_total_obj instanceof EE_Line_Item ? $line_total_obj->get_pretty('LIN_total') : __('View Transaction', 'event_espresso');
         return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? '<a href="' . $view_txn_url . '" title="' . esc_attr__('View Transaction', 'event_espresso') . '"><span class="reg-pad-rght">' . $txn_total . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
     } else {
         return '<span class="reg-pad-rght"></span>';
     }
 }
 /**
  * used by factory to create registration object.
  *
  * @since 4.3.0
  *
  * @param array $args Incoming field values to set on the new object
  *
  * @return EE_Registration|false
  */
 public function create_object($args)
 {
     static $att_nmbr = 0;
     //timezone?
     if (isset($args['timezone'])) {
         $timezone = $args['timezone'];
         unset($args['timezone']);
     } else {
         $timezone = null;
     }
     //date_formats?
     if (isset($args['formats']) && is_array($args['formats'])) {
         $formats = $args['formats'];
         unset($args['formats']);
     } else {
         $formats = array();
     }
     $registration = EE_Registration::new_instance($args, $timezone, $formats);
     //some things have to be set after the registration has been instantiated.
     $registration->set('REG_session', uniqid());
     $registrationID = $registration->save();
     $registration = $this->_maybe_chained($registration, $args);
     //only run finalize if $chained because it requires EE_Transaction
     if ($this->_chained) {
         $p = EE_Registration_Processor::instance();
         $att_nmbr++;
         $registration->set_reg_url_link($p->generate_reg_url_link($att_nmbr, md5('ticket' . $registrationID . time())));
         $registration->set_reg_code($p->generate_reg_code($registration));
         $registration->save();
     }
     return $registrationID ? $registration : false;
 }
 /**
  *    create_new_attendee
  *
  * @param EE_Registration $registration
  * @param array           $attendee_data
  * @return \EE_Attendee
  */
 private function _create_new_attendee(EE_Registration $registration, $attendee_data = array())
 {
     // create new attendee object
     $new_attendee = EE_Attendee::new_instance($attendee_data);
     // set author to event creator
     $new_attendee->set('ATT_author', $registration->event()->wp_user());
     $new_attendee->save();
     return $new_attendee;
 }
 /**
  * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send trigger
  *
  * @since   4.3.0
  *
  * @param 	string 	$registration_message_trigger_url
  * @param 	EE_Registration $registration
  * @param string 	$messenger
  * @param string 	$message_type
  * @return 	string
  */
 public static function registration_message_trigger_url($registration_message_trigger_url, EE_Registration $registration, $messenger = 'html', $message_type = 'invoice')
 {
     EE_Registry::instance()->load_helper('MSG_Template');
     // whitelist $messenger
     switch ($messenger) {
         case 'pdf':
             $sending_messenger = 'pdf';
             $generating_messenger = 'html';
             break;
         case 'html':
         default:
             $sending_messenger = 'html';
             $generating_messenger = 'html';
             break;
     }
     // whitelist $message_type
     switch ($message_type) {
         case 'receipt':
             $message_type = 'receipt';
             break;
         case 'invoice':
         default:
             $message_type = 'invoice';
             break;
     }
     // verify that both the messenger AND the message type are active
     if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
         //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
         $template_query_params = array('MTP_is_active' => TRUE, 'MTP_messenger' => $generating_messenger, 'MTP_message_type' => $message_type, 'Event.EVT_ID' => $registration->event_ID());
         //get the message template group.
         $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
         //if we don't have an EE_Message_Template_Group then return
         if (!$msg_template_group instanceof EE_Message_Template_Group) {
             // remove EVT_ID from query params so that global templates get picked up
             unset($template_query_params['Event.EVT_ID']);
             //get global template as the fallback
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
         }
         //if we don't have an EE_Message_Template_Group then return
         if (!$msg_template_group instanceof EE_Message_Template_Group) {
             return '';
         }
         // generate the URL
         $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger($sending_messenger, $generating_messenger, 'purchaser', $message_type, $registration, $msg_template_group->ID(), $registration->transaction_ID());
     }
     return $registration_message_trigger_url;
 }
 /**
  * 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);
 }
 /**
  * sorts registrations by REG_count
  *
  * @access public
  * @param EE_Registration $reg_A
  * @param EE_Registration $reg_B
  * @return array()
  */
 public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
 {
     // this shouldn't ever happen within the same TXN, but oh well
     if ($reg_A->count() == $reg_B->count()) {
         return 0;
     }
     return $reg_A->count() > $reg_B->count() ? 1 : -1;
 }
 protected function _setup_data()
 {
     //need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
     EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
     $cart = EE_Cart::reset();
     //add tickets to cart
     foreach ($this->tickets as $ticket) {
         $cart->add_ticket_to_cart($ticket['ticket']);
     }
     //setup txn property
     $this->txn = EE_Transaction::new_instance(array('TXN_timestamp' => time(), 'TXN_total' => 0, 'TXN_paid' => 0, 'STS_ID' => EEM_Transaction::incomplete_status_code, 'TXN_session_data' => NULL, 'TXN_hash_salt' => NULL, 'TXN_ID' => 999999));
     //setup reg_objects
     //note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
     $this->reg_objs = array();
     $regid = 9999990;
     foreach ($this->_attendees as $key => $attendee) {
         //note we need to setup reg_objects for each event this attendee belongs to
         $regatt = $attendee['att_obj']->ID();
         $regtxn = $this->txn->ID();
         $regcnt = 1;
         foreach ($attendee['line_ref'] as $evtid) {
             foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) {
                 $reg_array = array('EVT_ID' => $evtid, 'ATT_ID' => $regatt, 'TXN_ID' => $regtxn, 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_pending_payment, 'REG_date' => time(), 'REG_final_price' => $ticket->get('TKT_price'), 'REG_session' => 'dummy_session_id', 'REG_code' => $regid . '-dummy-generated-code', 'REG_url_link' => $regcnt . '-daafpapasdlfakasdfpqasdfasdf', 'REG_count' => $regcnt, 'REG_group_size' => $this->_events[$evtid]['total_attendees'], 'REG_att_is_going' => TRUE, 'REG_ID' => $regid);
                 $REG_OBJ = EE_Registration::new_instance($reg_array);
                 $this->_attendees[$key]['reg_objs'][$regid] = $REG_OBJ;
                 $this->_events[$evtid]['reg_objs'][] = $REG_OBJ;
                 $this->reg_objs[] = $REG_OBJ;
                 $this->tickets[$ticket->ID()]['reg_objs'][$regid] = $REG_OBJ;
                 $regcnt++;
                 $regid++;
             }
         }
     }
     //setup line items!
     EE_Registry::instance()->load_helper('Line_Item');
     $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
     //add tickets
     foreach ($this->tickets as $tktid => $item) {
         $qty = $item['count'];
         $ticket = $item['ticket'];
         EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
     }
     $shipping_line_item = EE_Line_Item::new_instance(array('LIN_name' => __('Shipping Surcharge', 'event_espresso'), 'LIN_desc' => __('Sent via Millenium Falcon', 'event_espresso'), 'LIN_unit_price' => 20, 'LIN_quantity' => 1, 'LIN_is_taxable' => TRUE, 'LIN_total' => 20, 'LIN_type' => EEM_Line_Item::type_line_item));
     EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
     $this->additional_line_items = array($shipping_line_item);
     //now let's add taxes
     EEH_Line_Item::apply_taxes($line_item_total);
     //now we should be able to get the items we need from this object
     $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
     $line_items = array();
     foreach ($event_line_items as $line_id => $line_item) {
         if (!$line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
             continue;
         }
         $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
         foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
             if (!$ticket_line_item instanceof EE_Line_Item) {
                 continue;
             }
             $this->tickets[$ticket_line_item->OBJ_ID()]['line_item'] = $ticket_line_item;
             $this->tickets[$ticket_line_item->OBJ_ID()]['sub_line_items'] = $ticket_line_item->children();
             $line_items[$ticket_line_item->ID()]['children'] = $ticket_line_item->children();
             $line_items[$ticket_line_item->ID()]['EE_Ticket'] = $this->tickets[$ticket_line_item->OBJ_ID()]['ticket'];
         }
     }
     $this->line_items_with_children = $line_items;
     $this->tax_line_items = $line_item_total->tax_descendants();
     //add proper total to transaction object.
     $grand_total = $line_item_total->recalculate_total_including_taxes();
     $this->grand_total_line_item = $line_item_total;
     $this->txn->set_total($grand_total);
     //add additional details for each registration
     foreach ($this->reg_objs as $reg) {
         $this->_registrations[$reg->ID()]['tkt_obj'] = $this->tickets[$reg->get('TKT_ID')]['ticket'];
         $this->_registrations[$reg->ID()]['evt_obj'] = $this->_events[$reg->get('EVT_ID')]['event'];
         $this->_registrations[$reg->ID()]['reg_obj'] = $reg;
         $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs'];
         $this->_registrations[$reg->ID()]['att_obj'] = $this->_attendees[$reg->get('ATT_ID')]['att_obj'];
         $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs'];
     }
     //events and attendees
     $this->events = $this->_events;
     $this->attendees = $this->_attendees;
     $this->registrations = $this->_registrations;
     $attendees_to_shift = $this->_attendees;
     //setup primary attendee property
     $this->primary_attendee_data = array('fname' => $this->_attendees[999999991]['att_obj']->fname(), 'lname' => $this->_attendees[999999991]['att_obj']->lname(), 'email' => $this->_attendees[999999991]['att_obj']->email(), 'att_obj' => $this->_attendees[999999991]['att_obj'], 'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']));
     //reg_info property
     //note this isn't referenced by any shortcode parsers so we'll ignore for now.
     $this->reg_info = array();
     //let's set a reg_obj for messengers expecting one.
     $this->reg_obj = array_pop($this->_attendees[999999991]['reg_objs']);
     //the below are just dummy items.
     $this->user_id = 1;
     $this->ip_address = '192.0.2.1';
     $this->user_agent = '';
     $this->init_access = time();
     $this->last_access = time();
 }
 /**
  * This generates a url trigger for the msg_url_trigger route using the given arguments
  *
  * @param string          $sending_messenger    The sending messenger slug.
  * @param string          $generating_messenger The generating messenger slug.
  * @param string          $context              The context for the template.
  * @param string          $message_type         The message type slug
  * @param EE_Registration $registration
  * @param integer          $message_template_group id              The EE_Message_Template_Group ID for the template.
  * @param integer          $data_id              The id to the EE_Base_Class for getting the data used by the trigger.
  *
  * @return string          The generated url.
  */
 public static function generate_url_trigger($sending_messenger, $generating_messenger, $context, $message_type, EE_Registration $registration, $message_template_group, $data_id)
 {
     $query_args = array('ee' => 'msg_url_trigger', 'snd_msgr' => $sending_messenger, 'gen_msgr' => $generating_messenger, 'message_type' => $message_type, 'context' => $context, 'token' => $registration->reg_url_link(), 'GRP_ID' => $message_template_group, 'id' => $data_id);
     $url = add_query_arg($query_args, get_site_url());
     //made it here so now we can just get the url and filter it.  Filtered globally and by message type.
     $url = apply_filters('FHEE__EEH_MSG_Template__generate_url_trigger', $url, $sending_messenger, $generating_messenger, $context, $message_type, $registration, $message_template_group, $data_id);
     return $url;
 }
 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();
 }
 /**
  * set_transaction_payment_method_based_on_registration_statuses
  *
  * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
  * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
  * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
  * 		the first "default" Payment Method
  * 		the first active Payment Method
  * 	whichever is found first.
  *
  * @param  EE_Registration $edited_registration
  * @return void
  */
 public function set_transaction_payment_method_based_on_registration_statuses(EE_Registration $edited_registration)
 {
     if ($edited_registration instanceof EE_Registration) {
         $transaction = $edited_registration->transaction();
         if ($transaction instanceof EE_Transaction) {
             $all_not_approved = true;
             foreach ($transaction->registrations() as $registration) {
                 if ($registration instanceof EE_Registration) {
                     // if any REG != "Not Approved" then toggle to false
                     $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
                 }
             }
             // if ALL Registrations are "Not Approved"
             if ($all_not_approved) {
                 $transaction->set_payment_method_ID(null);
                 $transaction->save();
             } else {
                 $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart);
                 if (!empty($available_payment_methods)) {
                     $PMD_ID = 0;
                     foreach ($available_payment_methods as $available_payment_method) {
                         if ($available_payment_method instanceof EE_Payment_Method && $available_payment_method->open_by_default()) {
                             $PMD_ID = $available_payment_method->ID();
                             break;
                         }
                     }
                     if (!$PMD_ID) {
                         $first_payment_method = reset($available_payment_methods);
                         if ($first_payment_method instanceof EE_Payment_Method) {
                             $PMD_ID = $first_payment_method->ID();
                         } else {
                             EE_Error::add_error(__('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
                         }
                     }
                     $transaction->set_payment_method_ID($PMD_ID);
                     $transaction->save();
                 } else {
                     EE_Error::add_error(__('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
                 }
             }
         }
     }
 }
 /**
  *   toggle_registration_status_if_no_monies_owing
  * determine whether to toggle free tickets to "Approved" based on payment status (kinda sorta) of other tickets for
  * the same event. So if more than one ticket for the same event is in the cart, and one or more tickets are NOT
  * free, then free tickets will NOT be automatically toggled to "Approved"
  *
  * @access public
  * @param bool $toggle_registration_status
  * @param \EE_Registration $registration
  * @return bool
  */
 public static function toggle_registration_status_if_no_monies_owing($toggle_registration_status = false, EE_Registration $registration)
 {
     $reg_tickets = array();
     if ($registration instanceof EE_Registration && $registration->transaction() instanceof EE_Transaction) {
         // now we need to get an accurate count of registration tickets
         foreach ($registration->transaction()->registrations() as $reg) {
             if ($reg instanceof EE_Registration) {
                 if ($reg->event() instanceof EE_Event && $reg->ticket() instanceof EE_Ticket) {
                     $reg_tickets[$reg->event()->ID()][$reg->ticket()->ID()] = $reg->ticket()->is_free();
                 }
             }
         }
     }
     if ($registration->ticket() instanceof EE_Ticket && $registration->ticket()->is_free()) {
         $toggle_registration_status = true;
         if ($registration->event() instanceof EE_Event && isset($reg_tickets[$registration->event()->ID()])) {
             foreach ($reg_tickets[$registration->event()->ID()] as $free_ticket) {
                 $toggle_registration_status = $free_ticket ? $toggle_registration_status : false;
             }
         }
     }
     return $toggle_registration_status;
 }
 /**
  * Gets the query params used to retrieve a specific line item for the given registration
  * @param EE_Registration $registration
  * @param array $original_query_params any extra query params you'd like to be merged with
  * @return array like EEM_Base::get_all()'s $query_params
  */
 public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
 {
     return array_replace_recursive($original_query_params, array(array('OBJ_ID' => $registration->ticket_ID(), 'OBJ_type' => 'Ticket', 'TXN_ID' => $registration->transaction_ID())));
 }
    /**
     * 		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;
    }
 /**
  * update registration REG_paid field after refund and link registration with payment
  *
  * @param EE_Registration $registration
  * @param EE_Payment      $payment
  * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
  * @return float
  * @throws \EE_Error
  */
 public function process_registration_refund(EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.0)
 {
     //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
     if ($registration->paid() > 0) {
         // ensure $available_refund_amount is NOT negative
         $available_refund_amount = (double) abs($available_refund_amount);
         // don't allow refund amount to exceed the available payment amount, OR the amount paid
         $refund_amount = min($available_refund_amount, (double) $registration->paid());
         // update $available_payment_amount
         $available_refund_amount -= $refund_amount;
         //calculate and set new REG_paid
         $registration->set_paid($registration->paid() - $refund_amount);
         // convert payment amount back to a negative value for storage in the db
         $refund_amount = (double) abs($refund_amount) * -1;
         // now save it
         $this->_apply_registration_payment($registration, $payment, $refund_amount);
     }
     return $available_refund_amount;
 }
 /**
  * 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;
 }
 /**
  * _refresh_registration_answers
  *
  * @param 	EE_Registration 	$registration
  * @return void
  */
 protected function _refresh_registration_answers($registration)
 {
     // now update the answers
     foreach ($registration->answers() as $cache_key => $answer) {
         // verify object
         if ($answer instanceof EE_Answer) {
             if ($answer->ID()) {
                 // make sure the cached answer is added to the model entity mapper
                 $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
             }
         } else {
             EE_Error::add_error(__('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         }
     }
 }
    /**
     * 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');
    }
 /**
  * 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();
 }
 protected function _setup_data()
 {
     //need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
     EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
     $cart = EE_Cart::instance();
     //add tickets to cart
     foreach ($this->tickets as $ticket) {
         $cart->add_ticket_to_cart($ticket['ticket']);
     }
     $grand_total = $cart->get_cart_grand_total() * count($this->_attendees);
     //EEH_Template::format_currency($cart->get_grand_total(), true);
     //setup billing property
     //todo:  I'm only using this format for the array because its how the gateways currently setup this data.  I HATE IT and it needs fixed but I have no idea how many places in the code this data structure currently touches.  Once its fixed we'll have to fix it here and in the shortcode parsing where this particular property is accessed.  (See https://events.codebasehq.com/projects/event-espresso/tickets/2271) for related ticket.
     $this->billing = array('first name' => 'Luke', 'last name' => 'Skywalker', 'email address' => '*****@*****.**', 'address' => '804 Bantha Dr.', 'city' => 'Mos Eisley', 'state' => 'Section 7', 'country' => 'Tatooine', 'zip' => 'f0r3e', 'ccv code' => 'xxx', 'credit card #' => '999999xxxxxxxx', 'expiry date' => '12 / 3000', 'total_due' => $grand_total);
     //setup txn property
     $this->txn = EE_Transaction::new_instance(array('TXN_timestamp' => current_time('mysql'), 'TXN_total' => $grand_total, 'TXN_paid' => $grand_total, 'STS_ID' => EEM_Transaction::incomplete_status_code, 'TXN_session_data' => NULL, 'TXN_hash_salt' => NULL, 'TXN_ID' => 999999));
     //setup reg_objects
     //note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
     $this->reg_objs = array();
     $regid = 9999990;
     foreach ($this->_attendees as $key => $attendee) {
         //note we need to setup reg_objects for each event this attendee belongs to
         $regatt = $attendee['att_obj']->ID();
         $regtxn = $this->txn->ID();
         $regcnt = 1;
         foreach ($attendee['line_ref'] as $evtid) {
             foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) {
                 $reg_array = array('EVT_ID' => $evtid, 'ATT_ID' => $regatt, 'TXN_ID' => $regtxn, 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_pending_payment, 'REG_date' => current_time('mysql'), 'REG_final_price' => $ticket->get('TKT_price'), 'REG_session' => 'dummy_session_id', 'REG_code' => $regid . '-dummy_generated_reg_code', 'REG_url_link' => '#', 'REG_count' => $regcnt, 'REG_group_size' => $this->_events[$evtid]['total_attendees'], 'REG_att_is_going' => TRUE, 'REG_ID' => $regid);
                 $REG_OBJ = EE_Registration::new_instance($reg_array);
                 $this->_attendees[$key]['reg_obj'][$regid] = $REG_OBJ;
                 $this->_events[$evtid]['reg_objs'][] = $REG_OBJ;
                 $this->reg_objs[] = $REG_OBJ;
                 $regcnt++;
                 $regid++;
             }
         }
     }
     //add additional details for each registration
     foreach ($this->reg_objs as $reg) {
         $this->_registrations[$reg->ID()]['tkt_obj'] = $this->tickets[$reg->get('TKT_ID')]['ticket'];
         $this->_registrations[$reg->ID()]['evt_obj'] = $this->_events[$reg->get('EVT_ID')]['event'];
         $this->_registrations[$reg->ID()]['reg_obj'] = $reg;
         $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs'];
         $this->_registrations[$reg->ID()]['att_obj'] = $this->_attendees[$reg->get('ATT_ID')]['att_obj'];
         $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs'];
     }
     //events and attendees
     $this->events = $this->_events;
     $this->attendees = $this->_attendees;
     $this->registrations = $this->_registrations;
     //setup primary attendee property
     $this->primary_attendee_data = array('fname' => $this->_attendees[999999991]['att_obj']->fname(), 'lname' => $this->_attendees[999999991]['att_obj']->lname(), 'email' => $this->_attendees[999999991]['att_obj']->email(), 'att_obj' => $this->_attendees[999999991]['att_obj'], 'reg_obj' => $this->_attendees[999999991]['reg_obj']);
     //reg_info property
     //note this isn't referenced by any shortcode parsers so we'll ignore for now.
     $this->reg_info = array();
     //the below are just dummy items.
     $this->user_id = 1;
     $this->ip_address = '192.0.2.1';
     $this->user_agent = '';
     $this->init_access = current_time('mysql');
     $this->last_access = current_time('mysql');
 }
 /**
  *		get_question_groups
  *
  * 		@access		public
  * 		@param		int $EVT_ID
  * 		@param		EE_Registration 	$registration
  *		@return 		array
  */
 public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
 {
     if (!isset($EVT_ID) || !absint($EVT_ID)) {
         EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return FALSE;
     }
     $where_params = array('Event_Question_Group.EVT_ID' => $EVT_ID, 'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? TRUE : FALSE, 'QSG_deleted' => FALSE);
     return EE_Registry::instance()->load_model('Question_Group')->get_all(array($where_params, 'order_by' => array('QSG_order' => 'ASC')));
 }
 /**
  * simulate six sales for an event's ticket, which will also increase sold qty for D1 & D2
  *
  * @param \EE_Ticket $ticket
  * @param int $qty
  * @throws \EE_Error
  */
 protected function _sell_tickets(EE_Ticket $ticket, $qty = 1)
 {
     if ($ticket instanceof EE_Ticket) {
         $transaction = EE_Transaction::new_instance(array('STS_ID' => EEM_Transaction::complete_status_code, 'TXN_timestamp' => time() - DAY_IN_SECONDS, 'TXN_total' => 0, 'TXN_paid' => 0));
         $transaction->save();
         for ($x = 1; $x <= $qty; $x++) {
             $registration = EE_Registration::new_instance(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_date' => time() - DAY_IN_SECONDS, 'REG_code' => $transaction->ID() . "-" . $ticket->ID() . "-{$x}-test", 'TXN_ID' => $transaction->ID(), 'EVT_ID' => $ticket->get_event_ID(), 'TKT_ID' => $ticket->ID()));
             $registration->save();
         }
     }
 }