/**
  *        This function is a singleton method used to instantiate the EEM_Event object
  *
  * @access public
  * @param string $timezone
  * @return EEM_Event
  */
 public static function instance($timezone = NULL)
 {
     // check if instance of EEM_Event already exists
     if (!self::$_instance instanceof EEM_Event) {
         // instantiate Espresso_model
         self::$_instance = new self($timezone);
     }
     //we might have a timezone set, let set_timezone decide what to do with it
     self::$_instance->set_timezone($timezone);
     // EEM_Event object
     return self::$_instance;
 }
 /**
  *    get_event
  *    attempts to retrieve an EE_Event object any way it can
  *
  * @access    public
  * @param    int $EVT_ID
  * @return    object
  */
 public static function get_event($EVT_ID = 0)
 {
     $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint($EVT_ID);
     // do we already have the Event  you are looking for?
     if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
         return EEH_Event_View::$_event;
     }
     EEH_Event_View::$_event = NULL;
     // international newspaper?
     global $post;
     // if this is being called from an EE_Event post, then we can just grab the attached EE_Event object
     if (isset($post->post_type) && $post->post_type == 'espresso_events' || $EVT_ID) {
         //			d( $post );
         // grab the event we're looking for
         if (isset($post->EE_Event) && ($EVT_ID == 0 || $EVT_ID == $post->ID)) {
             EEH_Event_View::$_event = $post->EE_Event;
             //				d( EEH_Event_View::$_event );
         }
         // now if we STILL do NOT have an EE_Event model object, BUT we have an Event ID...
         if (!EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
             // sigh... pull it from the db
             EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
             //				d( EEH_Event_View::$_event );
         }
     }
     return EEH_Event_View::$_event;
 }
 /**
  * like test_REG_final_price_matches_total_of_filtering_line_item_tree,
  * but makes sure the tickets have sub-prices, because that has shown to have some
  * bugs with calculations so far
  */
 function test_REG_final_price_matches_total_of_filtering_line_item_tree__with_sub_line_items()
 {
     $transaction = $this->new_typical_transaction(array('ticket_types' => 2, 'fixed_ticket_price_modifiers' => 2));
     //add another ticket purchase for one of the same events
     $event1 = EEM_Event::instance()->get_one(array(array('Registration.TXN_ID' => $transaction->ID())));
     $event_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'OBJ_type' => 'Event', 'OBJ_ID' => $event1->ID())));
     $discount = $this->new_model_obj_with_dependencies('Line_Item', array('LIN_type' => EEM_Line_Item::type_line_item, 'LIN_name' => 'event discount', 'LIN_total' => -8, 'LIN_unit_price' => -8, 'LIN_percent' => 0, 'LIN_quantity' => 1, 'LIN_parent' => $event_line_item->ID(), 'LIN_percent' => null, 'LIN_order' => count($event_line_item->children())));
     $transaction->total_line_item()->recalculate_pre_tax_total();
     //and add an unrelated purchase
     EEH_Line_Item::add_unrelated_item($transaction->total_line_item(), 'Transaction-Wide Discount', -5);
     $totals = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item());
     //		honestly the easiest way to confirm the total was right is to visualize the tree
     //		var_dump( $totals );
     //		EEH_Line_Item::visualize( $transaction->total_line_item() );
     //for each registration on the tranasction, verify the REG_final_price
     //indicated by EEH_Line_Item::calculate_reg_final_prices_per_line_item matches
     //what the line item filters would have returned
     EEH_Autoloader::register_line_item_filter_autoloaders();
     foreach ($transaction->registrations() as $registration) {
         $ticket_line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
         $reg_final_price_from_line_item_helper = $totals[$ticket_line_item->ID()];
         //now get the line item filter's final price
         $filters = new EE_Line_Item_Filter_Collection();
         $filters->add(new EE_Single_Registration_Line_Item_Filter($registration));
         $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, $transaction->total_line_item());
         $filtered_line_item_tree = $line_item_filter_processor->process();
         $reg_final_price_from_line_item_filter = $filtered_line_item_tree->total();
         $this->assertLessThan(0.2, abs($reg_final_price_from_line_item_filter - $reg_final_price_from_line_item_helper));
     }
 }
 /**
  * This allows setting the $_event property to a new event object if the incoming args for the
  * new dtt have an event id (or set to default if no evt_id)
  *
  * @since 4.3.0
  * @param int $EVT_ID EE_Event ID
  */
 private function _set_new_event($EVT_ID = 0)
 {
     $this->_event = empty($EVT_ID) ? EEM_Event::instance()->get_one_by_ID($EVT_ID) : $this->factory->event->create();
     //fail safe just in case (so we can be sure to have an event).
     if (empty($this->_event)) {
         $this->_event = $this->factory->event->create();
     }
 }
 /**
  *
  * @return \EE_Default_Where_Conditions
  */
 protected function _generate_restrictions()
 {
     //if there are no standard caps for this model, then for now all we know
     //if they need the default cap to access this
     if (!$this->model()->cap_slug()) {
         return array(self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions());
     }
     $event_model = EEM_Event::instance();
     return array(EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array($this->_path_to_event_model . 'status' => 'publish')), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(array('OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_path_to_event_model . 'status' => 'publish'))), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_path_to_event_model . 'status' => array('!=', 'private')))));
 }
 /**
  * checks that when we reset a model, that it does so properly and
  * also returns the NEW model
  */
 public function test_reset_model()
 {
     $model_a = EE_Registry::instance()->load_model('Event');
     $model_a2 = EE_Registry::instance()->load_model('Event');
     $model_a3 = EEM_Event::instance();
     $this->assertEquals($model_a, $model_a2);
     $this->assertEquals($model_a2, $model_a3);
     $model_b1 = EEM_Event::reset();
     $this->assertNotSame($model_a, $model_b1);
     $model_b2 = EE_Registry::instance()->reset_model('Event');
     $this->assertNotSame($model_a, $model_b2);
 }
Example #7
0
 /**
  * Like optimum_sales_now, but minus total sales so far.
  * See EE_Event::spaces_remaining_for_sale( true );
  *
  * @param array            $wpdb_row
  * @param \WP_REST_Request $request
  * @param Base             $controller
  * @return int
  * @throws \EE_Error
  */
 public static function spaces_remaining($wpdb_row, $request, $controller)
 {
     if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) {
         $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
     } else {
         $event_obj = null;
     }
     if ($event_obj instanceof \EE_Event) {
         return $event_obj->spaces_remaining_for_sale();
     } else {
         throw new \EE_Error(sprintf(__('Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'), $wpdb_row['Event_CPT.ID'], print_r($wpdb_row, true)));
     }
 }
    public function primary_questions($post_id, $post)
    {
        $this->_event = $this->_adminpage_obj->get_event_object();
        $event_id = $this->_event->ID();
        ?>
		<div class="inside">
			<p><strong>
					<?php 
        _e('Question Groups', 'event_espresso');
        ?>
				</strong><br />
				<?php 
        _e('Add a pre-populated', 'event_espresso');
        ?>
				<a href="admin.php?page=espresso_registration_form" target="_blank">
					<?php 
        _e('group of questions', 'event_espresso');
        ?>
				</a>
				<?php 
        _e('to your event. The personal information group is required for all events.', 'event_espresso');
        ?>
			</p>
			<?php 
        $QSGs = EEM_Event::instance()->get_all_question_groups();
        $EQGs = !empty($event_id) ? $this->_event->get_many_related('Question_Group', array(array('Event_Question_Group.EQG_primary' => 1))) : array();
        $EQGids = array_keys($EQGs);
        //printr( $QSGs, '$QSGs  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
        if (!empty($QSGs)) {
            $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
            foreach ($QSGs as $QSG) {
                $checked = in_array($QSG->ID(), $EQGids) || $QSG->get('QSG_system') == 1 ? ' checked="checked"' : '';
                $visibility = $QSG->get('QSG_system') == 1 ? ' style="visibility:hidden"' : '';
                $edit_link = $this->_adminpage_obj->add_query_args_and_nonce(array('action' => 'edit_question_group', 'QSG_ID' => $QSG->ID()), EE_FORMS_ADMIN_URL);
                $html .= '
					<p id="event-question-group-' . $QSG->ID() . '">
						<input value="' . $QSG->ID() . '" type="checkbox"' . $visibility . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> 
						<a href="' . $edit_link . '" title="Edit ' . $QSG->get('QSG_name') . ' Group" target="_blank">' . $QSG->get('QSG_name') . '</a>
					</p>';
            }
            $html .= count($QSGs) > 10 ? '</div>' : '';
            echo $html;
        } else {
            echo __('There seems to be a problem with your questions. Please contact support@eventespresso.com', 'event_espresso');
        }
        do_action('AHEE_event_editor_questions_notice');
        ?>
		</div>
		<?php 
    }
 /**
  * @return EE_Default_Where_Conditions
  * @throws EE_Error
  */
 protected function _generate_restrictions()
 {
     //if there are no standard caps for this model, then for now all we know
     //if they need the default cap to access this
     if (!$this->model()->cap_slug()) {
         return array(self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions());
     }
     $event_model = EEM_Event::instance();
     $restrictions = array(EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => array($this->_default_field_name => true, $this->_path_to_event_model . 'status' => 'publish'))), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_default_field_name => true, $this->_path_to_event_model . 'status' => 'publish'))), EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => array($this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, $this->_path_to_event_model . 'status' => array('!=', 'private'), $this->_default_field_name => true))), EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions(array($this->_default_field_name => false)));
     if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) {
         //if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones
         $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default')] = new EE_Default_Where_Conditions(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array('AND' => array(EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, $this->_default_field_name => true), $this->_default_field_name => false)));
     }
     return $restrictions;
 }
 /**
  * Test that when we set the minimum where conditions, we DO find cpt items
  * that are trashed, BUT DO NOT find CPT items of the wrong post_type (whcih might,
  * by some hackery, have an entry in the meta table)
  * @group 9179
  */
 public function test_get_minimum_where_conditions_during_query()
 {
     $this->assertEquals(0, EEM_Event::instance()->count(array('default_where_conditions' => 'none')));
     $e_normal = $this->new_model_obj_with_dependencies('Event', array('status' => EEM_CPT_Base::post_status_publish));
     $e_trashed = $this->new_model_obj_with_dependencies('Event', array('status' => EEM_CPT_Base::post_status_trashed));
     $monkey_post = $this->factory->post->create_and_get(array('post_type' => 'monkey'));
     //now verify we get what we wanted: the normal and trashed event, but not
     //the "monkey" post
     $events_found = EEM_Event::instance()->get_all(array('default_where_conditions' => 'minimum'));
     $this->assertArrayContains($e_normal, $events_found);
     $this->assertArrayContains($e_trashed, $events_found);
     $this->assertEquals(2, count($events_found));
     //incidentally, lets show the problem of using the 'default_where_conditions' => 'none'
     //it WOULD count the monkey post. Which is obviously NOT an event!
     $this->assertEquals(3, EEM_Event::instance()->count(array('default_where_conditions' => 'none')));
 }
 function test_generate_restrictions__basic_and_others_and_private()
 {
     //currently events have the 'ee_read_events', 'ee_read_others_events', and 'ee_read_others_private_events' caps
     //if that changes, this will need to be updated
     $generator = new EE_Restriction_Generator_Protected();
     $generator->_construct_finalize(EEM_Event::instance(), EEM_Base::caps_read);
     $restrictions = $generator->generate_restrictions();
     foreach ($restrictions as $default_where_conditions) {
         $default_where_conditions->_finalize_construct(EEM_Event::instance());
     }
     $this->assertArrayHasKey('ee_read_events', $restrictions);
     $this->assertInstanceOf('EE_Return_None_Where_Conditions', $restrictions['ee_read_events']);
     $this->assertArrayHasKey('ee_read_others_events', $restrictions);
     $this->assertInstanceOf('EE_Default_Where_Conditions', $restrictions['ee_read_others_events']);
     $this->assertEquals(array(EEM_Event::instance()->wp_user_field_name() => get_current_user_id()), $restrictions['ee_read_others_events']->get_default_where_conditions());
     $this->assertArrayHasKey('ee_read_private_events', $restrictions);
     $this->assertInstanceOf('EE_Default_Where_Conditions', $restrictions['ee_read_private_events']);
     $this->assertEquals(array('OR*no_' . EE_Restriction_Generator_Base::get_cap_name(EEM_Event::instance(), 'read_private') => array(EEM_Event::instance()->wp_user_field_name() => get_current_user_id(), 'status' => array('!=', 'private'))), $restrictions['ee_read_private_events']->get_default_where_conditions());
     $this->assertEquals(3, count($restrictions));
 }
 protected function _get_event_admin_id($event_id)
 {
     $event = EEM_Event::instance()->get_one_by_ID($event_id);
     return $event->wp_user();
 }
 public function send_invoice($download = FALSE)
 {
     $template_args = array();
     $EE = EE_Registry::instance();
     //allow the request to override the default theme defined in the invoice settings
     $theme_requested = isset($_REQUEST['theme']) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8 ? absint($_REQUEST['theme']) : null;
     $themes = array(1 => "simple.css", 2 => "bauhaus.css", 3 => "ejs.css", 4 => "horizon.css", 5 => "lola.css", 6 => "tranquility.css", 7 => "union.css");
     //Get the CSS file
     if (isset($themes[$theme_requested])) {
         $template_args['invoice_css'] = $themes[$theme_requested];
     } else {
         $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta('legacy_invoice_css', TRUE, 'simple.css');
     }
     if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
         $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
     } else {
         $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
     }
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $template_args['organization'] = $EE->CFG->organization->get_pretty('name');
     $template_args['street'] = 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');
     $template_args['city'] = $EE->CFG->organization->get_pretty('city');
     $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID($EE->CFG->organization->CNT_ISO);
     $template_args['zip'] = $EE->CFG->organization->get_pretty('zip');
     $template_args['email'] = $EE->CFG->organization->get_pretty('email');
     $template_args['registration_code'] = $this->registration->reg_code();
     $template_args['registration_date'] = $this->registration->date();
     $template_args['name'] = $primary_attendee->full_name();
     $template_args['attendee_address'] = $primary_attendee->address();
     $template_args['attendee_address2'] = $primary_attendee->address2();
     $template_args['attendee_city'] = $primary_attendee->city();
     $attendee_state = $primary_attendee->state_obj();
     if ($attendee_state) {
         $attendee_state_name = $attendee_state->name();
     } else {
         $attendee_state_name = '';
     }
     $template_args['attendee_state'] = $attendee_state_name;
     $template_args['attendee_zip'] = $primary_attendee->zip();
     $template_args['ship_name'] = $template_args['name'];
     $template_args['ship_address'] = $template_args['attendee_address'];
     $template_args['ship_city'] = $template_args['attendee_city'];
     $template_args['ship_state'] = $template_args['attendee_state'];
     $template_args['ship_zip'] = $template_args['attendee_zip'];
     $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', '');
     $template_args['transaction'] = $this->transaction;
     $template_args['amount_pd'] = $this->transaction->paid();
     $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid();
     $template_args['payments'] = $this->transaction->approved_payments();
     $template_args['net_total'] = '';
     $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url();
     $template_args['retry_payment_url'] = $this->registration->payment_overview_url();
     $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description($this->transaction->total_line_item());
     if ($template_args['amount_pd'] != $template_args['total_cost']) {
         //$template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']);
         $tax_items = $this->transaction->tax_items();
         if (!empty($tax_items)) {
             foreach ($tax_items as $tax) {
                 $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
             }
         }
         $difference = $template_args['amount_pd'] - $template_args['total_cost'];
         if ($difference < 0) {
             $text = __('Discount', 'event_espresso');
         } else {
             $text = __('Extra', 'event_espresso');
         }
         $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference);
     }
     $template_args['currency_symbol'] = $EE->CFG->currency->sign;
     $template_args['template_payment_instructions'] = wpautop(stripslashes_deep(html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE), ENT_QUOTES)));
     $template_args['shameless_plug'] = apply_filters('FHEE_Invoice__send_invoice__shameless_plug', true);
     if (isset($_GET['receipt'])) {
         //receipt-specific stuff
         $events_for_txn = EEM_Event::instance()->get_all(array(array('Registration.TXN_ID' => $this->transaction->ID())));
         $ticket_line_items_per_event = array();
         $registrations_per_line_item = array();
         $venues_for_events = array();
         foreach ($events_for_txn as $event_id => $event) {
             $line_items_for_this_event = EEM_Line_Item::instance()->get_all(array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())));
             $ticket_line_items_per_event[$event_id] = $line_items_for_this_event;
             foreach ($line_items_for_this_event as $line_item_id => $line_item) {
                 $ticket = $line_item->ticket();
                 $registrations_for_this_ticket = EEM_Registration::instance()->get_all(array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())));
                 $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket;
             }
             $venues_for_events = array_merge($venues_for_events, $event->venues());
         }
         $tax_total_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total)));
         $questions_to_skip = array(EEM_Attendee::system_question_fname, EEM_Attendee::system_question_lname, EEM_Attendee::system_question_email);
         $template_args['events_for_txn'] = $events_for_txn;
         $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event;
         $template_args['registrations_per_line_item'] = $registrations_per_line_item;
         $template_args['venues_for_events'] = $venues_for_events;
         $template_args['tax_total_line_item'] = $tax_total_line_item;
         $template_args['questions_to_skip'] = $questions_to_skip;
         //			d($template_args);
         $template_args['download_link'] = $this->registration->receipt_url('download');
     } else {
         //it's just an invoice we're accessing
         $template_args['download_link'] = $this->registration->invoice_url('download');
     }
     //Get the HTML as an object
     $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
     $template_header = EEH_Template::locate_template($templates_relative_path . 'invoice_header.template.php', $template_args, TRUE, TRUE);
     if (isset($_GET['receipt'])) {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', $template_args, TRUE, TRUE);
     } else {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', $template_args, TRUE, TRUE);
     }
     $template_footer = EEH_Template::locate_template($templates_relative_path . 'invoice_footer.template.php', $template_args, TRUE, TRUE);
     $copies = !empty($_REQUEST['copies']) ? $_REQUEST['copies'] : 1;
     $content = $this->espresso_replace_invoice_shortcodes($template_header);
     for ($x = 1; $x <= $copies; $x++) {
         $content .= $this->espresso_replace_invoice_shortcodes($template_body);
     }
     $content .= $this->espresso_replace_invoice_shortcodes($template_footer);
     //Check if debugging or mobile is set
     if (!empty($_REQUEST['html'])) {
         echo $content;
         exit(0);
     }
     $invoice_name = $template_args['organization'] . ' ' . __('Invoice #', 'event_espresso') . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name'];
     $invoice_name = str_replace(' ', '_', $invoice_name);
     //Create the PDF
     if (array_key_exists('html', $_GET)) {
         echo $content;
     } else {
         //only load dompdf if nobody else has yet...
         if (!defined('DOMPDF_DIR')) {
             define('DOMPDF_ENABLE_REMOTE', TRUE);
             define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
             define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
             require_once EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php';
         }
         $dompdf = new DOMPDF();
         $dompdf->load_html($content);
         $dompdf->render();
         $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download));
     }
     exit(0);
 }
 /**
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 public function display_line_item(EE_Line_Item $line_item, $options = array())
 {
     EE_Registry::instance()->load_helper('Template');
     EE_Registry::instance()->load_helper('HTML');
     $html = '';
     // set some default options and merge with incoming
     $default_options = array('show_desc' => true, 'odd' => false);
     $options = array_merge($default_options, (array) $options);
     switch ($line_item->type()) {
         case EEM_Line_Item::type_line_item:
             $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
             if ($line_item->OBJ_type() == 'Ticket') {
                 // item row
                 $html .= $this->_ticket_row($line_item, $options);
                 // got any kids?
                 foreach ($line_item->children() as $child_line_item) {
                     $this->display_line_item($child_line_item, $options);
                 }
             } else {
                 // item row
                 $html .= $this->_item_row($line_item, $options);
                 // got any kids?
                 foreach ($line_item->children() as $child_line_item) {
                     $this->display_line_item($child_line_item, $options);
                 }
             }
             break;
         case EEM_Line_Item::type_sub_line_item:
             $html .= $this->_sub_item_row($line_item, $options);
             break;
         case EEM_Line_Item::type_sub_total:
             static $sub_total = 0;
             $event_sub_total = 0;
             $text = __('Sub-Total', 'event_espresso');
             if ($line_item->OBJ_type() == 'Event') {
                 $options['event_id'] = $event_id = $line_item->OBJ_ID();
                 if (!isset($this->_events[$options['event_id']])) {
                     $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
                     if ($event instanceof EE_Event) {
                         if ($event->default_registration_status() == EEM_Registration::status_id_not_approved) {
                             return '';
                         }
                     }
                     $this->_events[$options['event_id']] = 0;
                     $html .= $this->_event_row($line_item);
                     $text = __('Event Sub-Total', 'event_espresso');
                 }
             }
             $child_line_items = $line_item->children();
             // loop thru children
             foreach ($child_line_items as $child_line_item) {
                 // recursively feed children back into this method
                 $html .= $this->display_line_item($child_line_item, $options);
             }
             $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
             $sub_total += $event_sub_total;
             if ($line_item->code() != 'pre-tax-subtotal' && count($child_line_items) > 1 || $line_item->code() == 'pre-tax-subtotal' && count($this->_events) > 1) {
                 $options['sub_total'] = $line_item->OBJ_type() == 'Event' ? $event_sub_total : $sub_total;
                 $html .= $this->_sub_total_row($line_item, $text, $options);
             }
             break;
         case EEM_Line_Item::type_tax:
             if ($this->_show_taxes) {
                 $this->_taxes_html .= $this->_tax_row($line_item, $options);
             }
             break;
         case EEM_Line_Item::type_tax_sub_total:
             if ($this->_show_taxes) {
                 $child_line_items = $line_item->children();
                 // loop thru children
                 foreach ($child_line_items as $child_line_item) {
                     // recursively feed children back into this method
                     $html .= $this->display_line_item($child_line_item, $options);
                 }
                 if (count($child_line_items) > 1) {
                     $this->_taxes_html .= $this->_total_tax_row($line_item, __('Tax Total', 'event_espresso'));
                 }
             }
             break;
         case EEM_Line_Item::type_total:
             // get all child line items
             $children = $line_item->children();
             // loop thru all non-tax child line items
             foreach ($children as $child_line_item) {
                 if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
                     // recursively feed children back into this method
                     $html .= $this->display_line_item($child_line_item, $options);
                 }
             }
             // now loop thru  tax child line items
             foreach ($children as $child_line_item) {
                 if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
                     // recursively feed children back into this method
                     $html .= $this->display_line_item($child_line_item, $options);
                 }
             }
             $html .= $this->_taxes_html;
             $html .= $this->_total_row($line_item, __('Total', 'event_espresso'));
             $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
             break;
     }
     return $html;
 }
 /**
  * 	process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
  *
  *
  *
  * 	[ESPRESSO_EVENT_ATTENDEES] - defaults to attendees for earliest active event, or earliest upcoming event.
  * 	[ESPRESSO_EVENT_ATTENDEES event_id=123] - attendees for specific event.
  * 	[ESPRESSO_EVENT_ATTENDEES datetime_id=245] - attendees for a specific datetime.
  * 	[ESPRESSO_EVENT_ATTENDEES ticket_id=123] - attendees for a specific ticket.
  * 	[ESPRESSO_EVENT_ATTENDEES status=all] - specific registration status (use status id) or all for all attendees
  *                                          regardless of status.  Note default is to only return approved attendees
  * 	[ESPRESSO_EVENT_ATTENDEES show_gravatar=true] - default is to not return gravatar.  Otherwise if this is set
  *                                                  then return gravatar for email address given.
  *
  *  Note: because of the relationship between event_id, ticket_id, and datetime_id. If more than one of those params
  *  is included then preference is given to the following:
  *  - event_id is used whenever its present and any others are ignored.
  *  - if no event_id then datetime is used whenever its present and any others are ignored.
  *  - otherwise ticket_id is used if present.
  *
  *  @access 	public
  *  @param 	    array 	$attributes
  *  @return 	string
  */
 public function process_shortcode($attributes = array())
 {
     //load helpers
     EE_Registry::instance()->load_helper('Event_View');
     EE_Registry::instance()->load_helper('Template');
     // merge in any attributes passed via fallback shortcode processor
     $attributes = array_merge((array) $attributes, (array) $this->_attributes);
     //set default attributes
     $default_shortcode_attributes = array('event_id' => null, 'datetime_id' => null, 'ticket_id' => null, 'status' => EEM_Registration::status_id_approved, 'show_gravatar' => false);
     // allow the defaults to be filtered
     $default_shortcode_attributes = apply_filters('EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', $default_shortcode_attributes);
     // grab attributes and merge with defaults, then extract
     $attributes = array_merge($default_shortcode_attributes, $attributes);
     $template_args = array('contacts' => array(), 'event' => null, 'datetime' => null, 'ticket' => null, 'show_gravatar' => $attributes['show_gravatar']);
     //start setting up the query for the contacts
     $query = array();
     $error = false;
     //what event?
     if (empty($attributes['event_id']) && empty($attributes['datetime_id']) && empty($attributes['ticket_id'])) {
         //seems like is_espresso_event_single() isn't working as expected. So using alternate method.
         if (is_single() && is_espresso_event()) {
             $event = EEH_Event_View::get_event();
             if ($event instanceof EE_Event) {
                 $template_args['event'] = $event;
                 $query[0]['Registration.EVT_ID'] = $event->ID();
             }
         } else {
             //try getting the earliest active event if none then get the
             $events = EEM_Event::instance()->get_active_events(array('limit' => 1, 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')));
             $events = empty($events) ? EEM_Event::instance()->get_upcoming_events(array('limit' => 1, 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'))) : $events;
             $event = reset($events);
             if ($event instanceof EE_Event) {
                 $query[0]['Registration.EVT_ID'] = $event->ID();
                 $template_args['event'] = $event;
             }
         }
     } elseif (!empty($attributes['event_id'])) {
         $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
         if ($event instanceof EE_Event) {
             $query[0]['Registration.EVT_ID'] = $attributes['event_id'];
             $template_args['event'] = $event;
         } else {
             $error = true;
         }
     }
     //datetime?
     if (!empty($attributes['datetime_id']) && empty($attributes['event_id'])) {
         $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
         if ($datetime instanceof EE_Datetime) {
             $query[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
             $query['default_where_conditions'] = 'this_model_only';
             $template_args['datetime'] = $datetime;
             $template_args['event'] = $datetime->event();
         } else {
             $error = true;
         }
     }
     //ticket?just
     if (!empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
         $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
         if ($ticket instanceof EE_Ticket) {
             $query[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
             $template_args['ticket'] = $ticket;
             $template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime ? $ticket->first_datetime()->event() : null;
         } else {
             $error = true;
         }
     }
     //status
     $reg_status_array = EEM_Registration::reg_status_array();
     if ($attributes['status'] != 'all' && isset($reg_status_array[$attributes['status']])) {
         $query[0]['Registration.STS_ID'] = $attributes['status'];
     }
     $query['group_by'] = array('ATT_ID');
     $query['order_by'] = apply_filters('FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC'));
     //if we have NO query where conditions, then there was an invalid parameter or the shortcode was used incorrectly
     //so when WP_DEBUG is set and true, we'll show a message, otherwise we'll just return an empty string.
     if (!isset($query[0]) || !is_array($query[0]) || $error) {
         if (WP_DEBUG) {
             return '<div class="important-notice ee-attention">' . __('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', 'event_espresso') . '</div>';
         } else {
             return '';
         }
     }
     //get contacts!
     $template_args['contacts'] = EEM_Attendee::instance()->get_all($query);
     //all set let's load up the template and return.
     return EEH_Template::locate_template('loop-espresso_event_attendees.php', $template_args, true, true);
 }
 /**
  * get total number of trashed events
  *
  * @access public
  * @return int
  */
 public function total_trashed_events()
 {
     $where = array('status' => 'trash');
     $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
     return $count;
 }
 /**
  * This just returns a count of all the registrations for this event
  * @access  public
  * @return int
  */
 public function get_count_of_all_registrations()
 {
     return EEM_Event::instance()->count_related($this, 'Registration');
 }
 /**
  * return the event object for a given event ID
  *
  * @since 4.3.0
  *
  * @param int $EVT_ID the event id for the event to attempt to retrieve
  *
  * @return null|EE_Event
  */
 public function get_object_by_id($EVT_ID)
 {
     return EEM_Event::instance()->get_one_by_ID($EVT_ID);
 }
 /**
  * Set up page for people list table
  *
  * @return string
  */
 protected function _people_list_table()
 {
     $this->_search_btn_label = __('People', 'event_espresso');
     $this->_admin_page_title .= $this->get_action_link_or_button('create_new', 'add-person', array(), 'add-new-h2');
     if (!empty($this->_req_data['EVT_ID'])) {
         $event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
         if ($event instanceof EE_Event) {
             $this->_template_args['before_list_table'] = '<h2>' . sprintf(__('Showing people assigned to the event: %s', 'event_espresso'), $event->name()) . '</h2>';
         }
     }
     $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(get_post_type_archive_link('espresso_people'), __("View People Archive Page", "event_espresso"), 'button');
     $this->display_admin_list_table_page_with_no_sidebar();
 }
 /**
  * 	_transactions_overview_list_table
  *
  * @access protected
  *	@return void
  */
 protected function _transactions_overview_list_table()
 {
     $this->_admin_page_title = __('Transactions', 'event_espresso');
     $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : NULL;
     $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(__('%sViewing Transactions for the Event: %s%s', 'event_espresso'), '<h3>', '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
     $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
     $this->display_admin_list_table_page_with_no_sidebar();
 }
 /**
  * @param $elements
  * @return array
  */
 public function dashboard_glance_items($elements)
 {
     $events = EEM_Event::instance()->count();
     $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php'));
     $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
     $items['events']['title'] = __('Click to view all Events', 'event_espresso');
     $registrations = EEM_Registration::instance()->count(array(array('STS_ID' => array('!=', EEM_Registration::status_id_incomplete))));
     $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php'));
     $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations));
     $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
     $items = apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
     foreach ($items as $type => $item_properties) {
         $elements[] = sprintf('<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']);
     }
     return $elements;
 }
 /**
  * Utility function used to get various items from the Person_Post model depending on the given params.
  * When no obj_id is provided, we use what is set as the $post id if present.
  *
  * @param int         $obj_id              What the obj_id is for comparing against.
  * @param string    $primary_obj_type What it is being retrieved.
  *
  * @return EE_Base_Class[]  (what is returned depends on what the primary_obj_type is)
  */
 protected static function _get_rel_objects($obj_id = 0, $primary_obj_type = 'Person')
 {
     $objects = array();
     if (empty($obj_id)) {
         global $post;
         $obj_id = $post instanceof WP_Post ? $post->ID : $obj_id;
     }
     //still empty? return empty array
     if (empty($obj_id)) {
         return array();
     }
     if ($primary_obj_type != 'Person') {
         $where = array('PER_ID' => $obj_id, 'OBJ_type' => $primary_obj_type);
         $query = array($where);
     } else {
         $where = array('OBJ_ID' => $obj_id);
         $query = array($where, 'order_by' => array('PER_OBJ_order' => 'ASC'));
     }
     $object_items = EEM_Person_Post::instance()->get_all($query);
     $term_name_cache = array();
     if (method_exists(EEM_Event::instance(), 'public_event_stati')) {
         $public_event_stati = EEM_Event::instance()->public_event_stati();
     } else {
         $public_event_stati = get_post_stati(array('public' => TRUE));
         foreach (EEM_Event::instance()->get_custom_post_statuses() as $custom_post_status) {
             $public_event_stati[] = strtolower(str_replace(' ', '_', $custom_post_status));
         }
     }
     foreach ($object_items as $object_item) {
         if (!isset($term_name_cache[$object_item->get('PT_ID')]) || !isset($objects[$term_name][$object_item->ID()])) {
             $term_name = EEM_Term_Taxonomy::instance()->get_one_by_ID($object_item->get('PT_ID'))->get_first_related('Term')->get('name');
             $related_object = $object_item->get_first_related($primary_obj_type, array(array('status' => array('IN', apply_filters('FHEE__EEH_People_View__get_rel_objects__public_event_stati', $public_event_stati)))));
             if ($related_object instanceof EE_Base_Class) {
                 $objects[$term_name][$object_item->ID()] = $related_object;
                 $term_name_cache[$object_item->get('PT_ID')] = $term_name;
             }
         }
     }
     return $objects;
 }
 /**
  * Contains tests for the update_dtts method and update_tkts method.
  * @since 4.6
  */
 public function test_update_dtts_and_update_tkts()
 {
     $this->_load_pricing_mock();
     $formats_to_test = $this->date_formats_to_test();
     $saved_dtts_for_tickets = $formats_for_compare = $saved_tkts = array();
     //test each date and time format combination for creating datetime objects
     foreach ($formats_to_test['date'] as $date_format) {
         foreach ($formats_to_test['time'] as $time_format) {
             $full_format = $date_format . ' ' . $time_format;
             $this->_pricingMock->set_date_format_strings(array('date' => $date_format, 'time' => $time_format));
             $data = $this->_get_save_data($full_format);
             $dtts = $this->_pricingMock->update_dtts($this->_event, $data);
             foreach ($dtts as $dtt) {
                 $this->assertInstanceof('EE_Datetime', $dtt);
                 //verify start and date
                 $this->assertEquals($dtt->start_date_and_time(), $this->_default_dates['DTT_start']->format($full_format), sprintf('Start Date Format Tested: %s', $full_format));
                 $this->assertEquals($dtt->end_date_and_time(), $this->_default_dates['DTT_end']->format($full_format), sprintf('End Date Format Tested: %s', $full_format));
                 $saved_dtts_for_tickets[$full_format] = $dtt;
                 $formats_for_compare[$dtt->ID()] = array($date_format, $time_format);
             }
         }
     }
     //test each date and time format combination for creating ticket objects
     foreach ($formats_to_test['date'] as $date_format) {
         foreach ($formats_to_test['time'] as $time_format) {
             $full_format = $date_format . ' ' . $time_format;
             $this->_pricingMock->set_date_format_strings(array('date' => $date_format, 'time' => $time_format));
             $data = $this->_get_save_data($full_format);
             $dtt_for_ticket['1'] = $saved_dtts_for_tickets[$full_format];
             $tkts = $this->_pricingMock->update_tkts($this->_event, $dtt_for_ticket, $data);
             foreach ($tkts as $tkt) {
                 $this->assertInstanceof('EE_Ticket', $tkt, sprintf('Format: %s', $full_format));
                 //verify start and date
                 $this->assertEquals($tkt->start_date(), $this->_default_dates['TKT_start']->format($full_format), sprintf('Start Ticket DateFormat Tested: %s', $full_format));
                 $this->assertEquals($tkt->end_date(), $this->_default_dates['TKT_end']->format($full_format), sprintf('End Ticket Date Format Tested: %s', $full_format));
                 $saved_tkts[$full_format] = $tkt;
             }
         }
     }
     //now let's verify these items were saved corectly in the db.
     /*$new_tkts = $new_dtts = array();
     		foreach ( $tkt as $format => $tkt ) {
     			$new_tkts[$format] = EEM_Ticket::instance()->refresh_entity_map_from_db( $tkt->ID() );
     		}
     
     		foreach ( $saved_dtts_for_tickets[$full_format] as $format => $dtt ) {
     			$new_dtts[$format] = EEM_Datetime::instance()->refresh_entity_map_from_db( $dtt->ID() );
     		}/**/
     $new_event = EEM_Event::instance()->refresh_entity_map_from_db($this->_event->ID());
     $new_event->set_timezone('America/Vancouver');
     $evt_dtts = $new_event->datetimes_ordered();
     //now let's do comparisons.
     foreach ($evt_dtts as $edtt) {
         $formats = $formats_for_compare[$edtt->ID()];
         $format = $formats[0] . ' ' . $formats[1];
         $this->assertEquals($edtt->start_date_and_time($formats[0], $formats[1]), $this->_default_dates['DTT_start']->format($format), sprintf('DB DTT/Default DTT Start Date Format Checked: %s', $format));
         $this->assertEquals($edtt->end_date_and_time($formats[0], $formats[1]), $this->_default_dates['DTT_end']->format($format), sprintf('DB DTT/Default DTT End Date Format Checked: %s', $format));
         $this->assertEquals($edtt->start_date_and_time($formats[0], $formats[1]), $saved_dtts_for_tickets[$format]->start_date_and_time(), sprintf('DB DTT/Orig DTT Start Date Format Checked: %s', $format));
         $this->assertEquals($edtt->end_date_and_time($formats[0], $formats[1]), $saved_dtts_for_tickets[$format]->end_date_and_time(), sprintf('DB DTT/Orig DTT End Date Format Checked: %s', $format));
         //get related ticket on this $edtt
         $evt_tkt = $edtt->get_first_related('Ticket');
         $this->assertEquals($evt_tkt->start_date($formats[0], $formats[1]), $this->_default_dates['TKT_start']->format($format), sprintf('DB TKT/Default TKT Start Date Format Checked: %s', $format));
         $this->assertEquals($evt_tkt->end_date($formats[0], $formats[1]), $this->_default_dates['TKT_end']->format($format), sprintf('DB TKT/Default TKT End Date Format Checked: %s', $format));
         $this->assertEquals($evt_tkt->start_date($formats[0], $formats[1]), $saved_tkts[$format]->start_date($formats[0], $formats[1]), sprintf('DB TKT/Orig TKT Start Date Format Checked: %s', $format));
         $this->assertEquals($evt_tkt->end_date($formats[0], $formats[1]), $saved_tkts[$format]->end_date($formats[0], $formats[1]), sprintf('DB TKT/Orig TKT End Date Format Checked: %s', $format));
     }
 }
 /**
  * checks that the BETWEEN operator works ok
  * @group 8187
  */
 function test_get_all__between()
 {
     EEM_Event::instance()->get_all(array(array('Datetime.DTT_EVT_start' => array('BETWEEN', array('2015-03-02 00:00:00', '2016-03-04 00:00:00')))));
     $this->assertTrue(true);
 }
 /**
  * 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);
 }
 /**
  *    finds and sets the EE_Event object for use throughout class
  *
  * @access 	public
  * @param 	mixed $event
  * @return 	bool
  */
 protected static function set_event($event = null)
 {
     if ($event === null) {
         global $post;
         $event = $post;
     }
     if ($event instanceof EE_Event) {
         self::$_event = $event;
     } else {
         if ($event instanceof WP_Post && isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
             self::$_event = $event->EE_Event;
         } else {
             if ($event instanceof WP_Post && $event->post_type == 'espresso_events') {
                 $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
                 self::$_event = $event->EE_Event;
             } else {
                 $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
                 $dev_msg = $user_msg . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', 'event_espresso');
                 EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * @param string $default_reg_status
  */
 public static function set_default_reg_status($default_reg_status)
 {
     self::$_default_reg_status = $default_reg_status;
     //if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default.
     if (self::$_instance instanceof EEM_Event) {
         self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field('EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), false, $default_reg_status, EEM_Registration::reg_status_array());
         self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta', 'EVT_default_registration_status', 'EEM_Event');
     }
 }
 /**
  * 		set_reg_event
  *		@access private
  *		@return boolean
  */
 private function _set_reg_event()
 {
     if (is_object($this->_reg_event)) {
         return TRUE;
     }
     $EVT_ID = !empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : FALSE;
     if (!$EVT_ID) {
         return FALSE;
     }
     $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
     return TRUE;
 }
 /**
  * Returns query args for use in model queries on the
  * EEM model related to scope.  Note this also should
  * consider any filters present
  *
  * @since 1.0.0
  *
  * @return array
  */
 public function get_query_args()
 {
     EE_Registry::instance()->load_helper('DTT_Helper');
     //$month_increment = apply_filters( 'FHEE__EE_Promotion_Event_Scope__get_query_args__month_increment', 1 );
     //check for any existing dtt queries
     $DTT_EVT_start = !empty($_REQUEST['EVT_start_date_filter']) ? $_REQUEST['EVT_start_date_filter'] : null;
     $DTT_EVT_end = !empty($_REQUEST['EVT_end_date_filter']) ? $_REQUEST['EVT_end_date_filter'] : null;
     $_where = array('status' => array('NOT IN', array(EEM_Event::cancelled, 'trash')));
     if (!empty($DTT_EVT_start)) {
         $_where['Datetime.DTT_EVT_start'] = array('>', EEM_datetime::instance()->convert_datetime_for_query('DTT_EVT_start', $DTT_EVT_start, 'Y-m-d g:i a'));
     }
     if (!empty($DTT_EVT_end)) {
         $_where['Datetime.DTT_EVT_end'] = array('<', EEM_Datetime::instance()->convert_datetime_for_query('DTT_EVT_end', $DTT_EVT_end, 'Y-m-d g:i a'));
     }
     //exclude expired events by default unless include_expiry is checked.
     if (!isset($_REQUEST['include_expired_events_filter'])) {
         $_where['Datetime.DTT_EVT_end**exclude_expired_events_query'] = array('>', time());
     }
     //category filters?
     if (!empty($_REQUEST['EVT_CAT_ID'])) {
         $_where['Term_Taxonomy.term_id'] = $_REQUEST['EVT_CAT_ID'];
     }
     //event title?
     if (!empty($_REQUEST['EVT_title_filter'])) {
         $_where['EVT_name'] = array('LIKE', '%' . $_REQUEST['EVT_title_filter'] . '%');
     }
     $orderby = !empty($_REQUEST['PRO_scope_sort']) ? $_REQUEST['PRO_scope_sort'] : 'DESC';
     $query_params = array('0' => $_where, 'order_by' => array('EVT_created' => $orderby), 'group_by' => 'EVT_ID');
     //apply caps
     if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events_for_promotions')) {
         $query_params = EEM_Event::instance()->alter_query_params_to_only_include_mine($query_params);
     }
     return $query_params;
 }
 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;
 }