/**
  *    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;
 }
 /**
  * This grabs an EE_Messages_Addressee object for the Preview data handler.
  *
  * @return EE_Messages_Addressee
  */
 protected function _get_addressee($context = 'primary_attendee')
 {
     $data = new EE_Messages_Preview_incoming_data(array('event_ids' => array($this->_event->ID())));
     /**
      * @see EE_message_type::_init_data()
      */
     $addressee_data = array('billing' => $data->billing, 'taxes' => $data->taxes, 'tax_line_items' => $data->tax_line_items, 'additional_line_items' => $data->additional_line_items, 'grand_total_line_item' => $data->grand_total_line_item, 'txn' => $data->txn, 'payments' => $data->payments, 'payment' => isset($data->payment) ? $data->payment : NULL, 'reg_objs' => $data->reg_objs, 'registrations' => $data->registrations, 'datetimes' => $data->datetimes, 'tickets' => $data->tickets, 'line_items_with_children' => $data->line_items_with_children, 'questions' => $data->questions, 'answers' => $data->answers, 'txn_status' => $data->txn_status, 'total_ticket_count' => $data->total_ticket_count);
     if (is_array($data->primary_attendee_data)) {
         $addressee_data = array_merge($addressee_data, $data->primary_attendee_data);
         $addressee_data['primary_att_obj'] = $data->primary_attendee_data['att_obj'];
         $addressee_data['primary_reg_obj'] = $data->primary_attendee_data['reg_obj'];
     }
     /**
      * @see EE_message_type::_process_data()
      */
     switch ($context) {
         case 'primary_attendee':
         case 'purchaser':
             $aee = $addressee_data;
             $aee['events'] = $data->events;
             $aee['attendees'] = $data->attendees;
             return new EE_Messages_Addressee($aee);
             break;
         case 'attendee':
             //for the purpose of testing we're just going to do ONE attendee
             $attendee = reset($data->attendees);
             foreach ($attendee as $item => $value) {
                 $aee[$item] = $value;
                 if ($item == 'line_ref') {
                     foreach ($value as $event_id) {
                         $aee['events'][$event_id] = $data->events[$event_id];
                     }
                 }
             }
             $aee['reg_obj'] = array_shift($attendee['reg_objs']);
             $aee['attendees'] = $data->attendees;
             return new EE_Messages_Addressee($aee);
             break;
         case 'admin':
             //for the purpose of testing we're only setting up for the event we have active for testing.
             $aee['user_id'] = $this->_event->get('EVT_wp_user');
             $aee['events'] = $data->events;
             $aee['attendees'] = $data->attendees;
             return new EE_Messages_Addressee($aee);
     }
 }
 protected function _column_name_action_setup(EE_Event $item)
 {
     $export_query_args = array('action' => 'export_events', 'EVT_ID' => $item->ID());
     $export_event_link = EE_Admin_Page::add_query_args_and_nonce($export_query_args, EVENTS_ADMIN_URL);
     $actions = parent::_column_name_action_setup($item);
     //		$actions['export'] = '<a href="' . $export_event_link . '" title="' . __('Export Event', 'event_espresso') . '">' . __('Export', 'event_espresso') . '</a>';
     return $actions;
 }
 /**
  * 	display_ticket_selector_submit
  *
  *	@access public
  * 	@access 		public
  * 	@return		string
  */
 public static function display_view_details_btn()
 {
     if (!self::$_event->get_permalink()) {
         $msg = __('The URL for the Event Details page could not be retrieved.', 'event_espresso');
         EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
     }
     $view_details_btn = '<form id="" method="POST" action="' . self::$_event->get_permalink() . '">';
     $btn_text = apply_filters('FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', __('View Details', 'event_espresso'));
     $view_details_btn .= '<input id="ticket-selector-submit-' . self::$_event->ID() . '-btn" class="ticket-selector-submit-btn" type="submit" value="' . $btn_text . '" /><div class="clear"><br/></div>';
     $view_details_btn .= '</form>';
     return $view_details_btn;
 }
 public function test_get_all__caps__delete__with_assign_event_category()
 {
     //log the user in
     global $current_user;
     $current_user = $this->user;
     $current_user->add_cap('ee_edit_events');
     $current_user->add_cap('ee_assign_event_category');
     //now check they can only see the term relationship for their own event
     $term_rs = EEM_Term_Relationship::instance()->get_all(array(array('object_id' => array('IN', array($this->my_event->ID(), $this->others_event->ID()))), 'order_by' => array('object_id' => 'ASC'), 'caps' => EEM_Base::caps_delete));
     $this->assertEEModelObjectsEquals($this->term_r_for_my_event, reset($term_rs));
     $this->assertEquals(1, count($term_rs));
 }
 public function setUp()
 {
     parent::setUp();
     //let's make sure we start off with NO tickets in the DB
     EEM_Ticket::instance()->delete_permanently(EEM_Ticket::instance()->alter_query_params_so_deleted_and_undeleted_items_included(), false);
     $this->assertEquals(0, EEM_Ticket::instance()->count(EEM_Ticket::instance()->alter_query_params_so_deleted_and_undeleted_items_included()));
     $this->user = $this->factory->user->create_and_get();
     $this->e_mine = $this->new_model_obj_with_dependencies('Event', array('EVT_wp_user' => $this->user->ID, 'status' => 'publish'));
     $this->e_others = $this->new_model_obj_with_dependencies('Event', array('EVT_wp_user' => 99999, 'status' => 'publish'));
     $this->e_private = $this->new_model_obj_with_dependencies('Event', array('EVT_wp_user' => 99999, 'status' => 'private'));
     $this->t_mine = $this->new_model_obj_with_dependencies('Ticket', array('TKT_is_default' => false, 'TKT_wp_user' => $this->user->ID));
     $this->t_others = $this->new_model_obj_with_dependencies('Ticket', array('TKT_is_default' => false, 'TKT_wp_user' => 9999));
     $this->t_private = $this->new_model_obj_with_dependencies('Ticket', array('TKT_is_default' => false, 'TKT_wp_user' => 9999));
     $this->t_mine_default = $this->new_model_obj_with_dependencies('Ticket', array('TKT_is_default' => true, 'TKT_wp_user' => $this->user->ID));
     $this->t_others_default = $this->new_model_obj_with_dependencies('Ticket', array('TKT_is_default' => true, 'TKT_wp_user' => 9999));
     $dtt_to_mine = $this->new_model_obj_with_dependencies('Datetime', array('EVT_ID' => $this->e_mine->ID()));
     $dtt_to_mine->_add_relation_to($this->t_mine, 'Ticket');
     $dtt_to_others = $this->new_model_obj_with_dependencies('Datetime', array('EVT_ID' => $this->e_others->ID()));
     $dtt_to_others->_add_relation_to($this->t_others, 'Ticket');
     $dtt_to_private = $this->new_model_obj_with_dependencies('Datetime', array('EVT_ID' => $this->e_private->ID()));
     $dtt_to_private->_add_relation_to($this->t_private, 'Ticket');
 }
 /**
  * 		process_reg_step
  *
  * 		@access 		public
  * 		@return 		string
  */
 public function process_reg_step()
 {
     EE_System::do_not_cache();
     $this->_set_reg_event();
     EE_Registry::instance()->REQ->set_espresso_page(TRUE);
     //what step are we on?
     $cart = EE_Registry::instance()->SSN->cart();
     $step = !$cart instanceof EE_Cart ? 'ticket' : 'questions';
     //if doing ajax then we need to verify the nonce
     if (defined('DOING_AJAX')) {
         $nonce = isset($this->_req_data[$this->_req_nonce]) ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
         $this->_verify_nonce($nonce, $this->_req_nonce);
     }
     switch ($step) {
         case 'ticket':
             //process ticket selection
             $success = EED_Ticket_Selector::instance()->process_ticket_selections();
             if ($success) {
                 EE_Error::add_success(__('Tickets Selected. Now complete the registration.'), 'event_espresso');
             } else {
                 $query_args['step_error'] = $this->_req_data['step_error'] = TRUE;
             }
             if (defined('DOING_AJAX')) {
                 $this->new_registration();
                 //display next step
             } else {
                 $query_args['action'] = 'new_registration';
                 $query_args['processing_registration'] = 1;
                 $query_args['event_id'] = $this->_reg_event->ID();
                 $this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
             }
             break;
         case 'questions':
             if (!isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
             }
             //process registration
             $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
             if ($cart instanceof EE_Cart) {
                 $grand_total = $cart->get_cart_grand_total();
                 if ($grand_total instanceof EE_Line_Item) {
                     $grand_total->save_this_and_descendants_to_txn();
                 }
             }
             if (!$transaction instanceof EE_Transaction) {
                 $query_args = array('action' => 'new_registration', 'processing_registration' => 2, 'event_id' => $this->_reg_event->ID());
                 if (defined('DOING_AJAX')) {
                     //display registration form again because there are errors (maybe validation?)
                     $this->new_registration();
                     return;
                 } else {
                     $this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
                     return;
                 }
             }
             /** @type EE_Transaction_Payments $transaction_payments */
             $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
             // maybe update status, and make sure to save transaction if not done already
             if (!$transaction_payments->update_transaction_status_based_on_total_paid($transaction)) {
                 $transaction->save();
             }
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
             $this->_req_data = array();
             $query_args = array('action' => 'redirect_to_txn', 'TXN_ID' => $transaction->ID(), 'EVT_ID' => $this->_reg_event->ID(), 'event_name' => urlencode($this->_reg_event->name()), 'redirect_from' => 'new_registration');
             $this->_redirect_after_action(false, '', '', $query_args, true);
             break;
     }
     //what are you looking here for?  Should be nothing to do at this point.
 }
 private function _get_registrations_from_event(EE_Event $event)
 {
     return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID()]['reg_objs'] : array();
 }
 private function _get_datetimes_from_event(EE_Event $event, $reg = NULL)
 {
     $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID()]['dtt_objs'] : array();
     if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
         $adj_dtts = array();
         //return only dtts for the given attendee
         foreach ($evt_dtts as $dtt) {
             if (isset($this->_extra_data['data']->registrations[$reg->ID()]['dtt_objs'][$dtt->ID()])) {
                 $adj_dtts[] = $dtt;
             }
         }
         $evt_dtts = $adj_dtts;
     }
     return $evt_dtts;
 }
 /**
  * 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));
     }
 }
 /**
  * @param EE_Event $item
  *
  * @return string
  */
 public function column_actions(EE_Event $item)
 {
     //todo: remove when attendees is active
     if (!defined('REG_ADMIN_URL')) {
         define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
     }
     $actionlinks = array();
     $view_link = get_permalink($item->ID());
     $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
     $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>';
     if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) {
         $edit_query_args = array('action' => 'edit', 'post' => $item->ID());
         $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
         $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>';
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID())) {
         $attendees_query_args = array('action' => 'default', 'event_id' => $item->ID());
         $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
         $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>';
     }
     $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, $item);
     return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div');
 }
 private function _get_datetimes_from_event(EE_Event $event, $att = NULL)
 {
     return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID()]['dtt_objs'] : array();
 }
 protected function _parser($shortcode)
 {
     EE_Registry::instance()->load_helper('Formatter');
     $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
     //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
     if (empty($this->_event)) {
         $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : NULL;
         $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
         $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : NULL;
     }
     //If there is no event objecdt by now then get out.
     if (!$this->_event instanceof EE_Event) {
         return '';
     }
     switch ($shortcode) {
         case '[EVENT_ID]':
             return $this->_event->ID();
             break;
         case '[EVENT_IDENTIFIER]':
             return isset($this->_data['line_ref']) ? $this->_data['line_ref'] : '';
             break;
         case '[EVENT]':
         case '[EVENT_NAME]':
             return $this->_event->get('EVT_name');
             break;
         case '[EVENT_PHONE]':
             return $this->_event->get('EVT_phone');
             break;
         case '[EVENT_DESCRIPTION]':
             return $this->_event->get('EVT_desc');
             break;
         case '[EVENT_EXCERPT]':
             return $this->_event->get('EVT_short_desc');
             break;
         case '[EVENT_LINK]':
             return $this->_get_event_link($this->_event);
             break;
         case '[EVENT_URL]':
             return $this->_get_event_link($this->_event, FALSE);
             break;
         case '[VIRTUAL_URL]':
             $venue = $this->_event->get_first_related('Venue');
             if (empty($venue)) {
                 return '';
             }
             return $venue->get('VNU_virtual_url');
         case '[VIRTUAL_PHONE]':
             $venue = $this->_event->get_first_related('Venue');
             if (empty($venue)) {
                 return '';
             }
             return $venue->get('VNU_virtual_phone');
             break;
         case '[EVENT_IMAGE]':
             $image = $this->_event->feature_image_url(array(600, 300));
             // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
             return !empty($image) ? '<img src="' . $image . '" alt="' . sprintf(esc_attr__('%s Feature Image', 'event_espresso'), $this->_event->get('EVT_name')) . '" />' : '';
             break;
         case '[EVENT_FACEBOOK_URL]':
             $facebook_url = $this->_event->get_post_meta('event_facebook', true);
             return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') : $facebook_url;
             break;
         case '[EVENT_TWITTER_URL]':
             $twitter_url = $this->_event->get_post_meta('event_twitter', true);
             return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') : $twitter_url;
             break;
         case '[EVENT_AUTHOR_EMAIL]':
             $author_id = $this->_event->get('EVT_wp_user');
             $user_data = get_userdata((int) $author_id);
             return $user_data->user_email;
             break;
     }
     return '';
 }
 /**
  * @param \EE_Transaction $transaction
  * @param \EE_Ticket $ticket
  * @param \EE_Event $event
  * @param float $REG_final_price
  * @return \EE_Registration
  * @throws \EE_Error
  */
 public function get_registration_mock(EE_Transaction $transaction, EE_Ticket $ticket, EE_Event $event, $REG_final_price = 10.0)
 {
     return $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'EVT_ID' => $event->ID(), 'REG_final_price' => $REG_final_price, 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT));
 }
 /**
  * Gets what the event ticket's code SHOULD be
  * @param EE_Event $event
  * @return string
  */
 public static function get_event_code($event)
 {
     return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0');
 }
 /**
  * Handles attaching people to event relationships
  *
  * @param EE_Event $evtobj
  * @param array $data   incoming data
  *
  * @return bool
  */
 public function people_to_event_updates($evtobj, $data)
 {
     $saved_people = array();
     if (!isset($data['people_to_cpt'])) {
         //no people in system yet or doing from a context where the people ui isn't present.
         return true;
     }
     //loop through data and set things up for save.
     foreach ($data['people_to_cpt'] as $type_id => $people_values) {
         $existing_people = EE_Registry::instance()->load_model('Person_Post')->get_all_people_ids_for_post_and_type($evtobj->ID(), $type_id);
         $order_count = count($people_values) + 1;
         foreach ($people_values as $person_value) {
             if (!isset($person_value['PER_ID'])) {
                 continue;
             }
             $person_order = isset($person_value['PER_order']) && $person_value['PER_order'] !== '' ? $person_value['PER_order'] : $order_count;
             if (in_array($person_value['PER_ID'], $existing_people)) {
                 $existing_person = EEM_Person_Post::instance()->get_one(array(array('PER_ID' => $person_value['PER_ID'], 'PT_ID' => $type_id, 'OBJ_ID' => $evtobj->ID())));
                 $existing_person->set('PER_OBJ_order', $person_order);
                 $existing_person->save();
                 $saved_people[$type_id][] = (int) $person_value['PER_ID'];
                 continue;
             }
             $values_to_save = array('PER_ID' => $person_value['PER_ID'], 'OBJ_ID' => $evtobj->ID(), 'OBJ_type' => str_replace('EE_', '', get_class($evtobj)), 'PT_ID' => $type_id, 'PER_OBJ_order' => $person_order);
             $new_rel = EE_Person_Post::new_instance($values_to_save);
             $new_rel->save();
             $saved_people[$type_id][] = (int) $person_value['PER_ID'];
             $order_count++;
         }
         //now let's grab the changes between the tow and we'll know that's what got removed.
         $rel_to_remove = empty($saved_people[$type_id]) ? $existing_people : array_diff($existing_people, $saved_people[$type_id]);
         foreach ($rel_to_remove as $rel_per_id) {
             $remove_where = array('OBJ_ID' => $evtobj->ID(), 'PT_ID' => $type_id, 'PER_ID' => $rel_per_id);
             EE_Registry::instance()->load_model('Person_Post')->delete(array($remove_where));
         }
     }
     //its entirely possible that all the people_event relationships for a particular type were removed.  So we need to account for that
     $types_for_evt = EE_Registry::instance()->load_model('Person_Post')->get_all(array(array('OBJ_ID' => $evtobj->ID())));
     foreach ($types_for_evt as $type_for_evt) {
         if (!isset($saved_people[$type_for_evt->get('PT_ID')])) {
             $type_for_evt->delete_permanently();
         }
     }
     return true;
 }
 /**
  * This is a common looped to test saves of ticket and datetime data.
  *
  * @param string $context_for_error_messages Used this to add context to any failed tests so
  *                                           			     you can easily verify what triggered it.
  * @param array  $data_to_replace                    An array of replacements for the default data.
  *                                                   		    Use null to indicate you want the key unset.
  * @param array $data_to_unset		    An array that indicates the keys you want unset.
  * @param array $expected_date_data              An aray of expected data to replace what's being
  *                                               		    expected.
  * @since 4.6
  */
 protected function _testing_updates($context_for_error_messages, $data_to_replace = array())
 {
     $formats_to_test = $this->date_formats_to_test();
     $saved_dtts_for_tickets = $formats_for_compare = $saved_tkts = array();
     /**
      * Note: Keep in mind, decaf does NOT provide the ability to choose the format that the dates are
      * displayed in for the event editor.  So when we test comparing formats, it is important to set the
      * format on the objects before retrieval.  Also important is that only the 'Y-m-d h:i a' format is used
      * on the decaf editor form.  So we make sure the all the dates going in for the data are in the same format.
      */
     foreach ($formats_to_test['date'] as $date_format) {
         foreach ($formats_to_test['time'] as $time_format) {
             $full_format = $date_format . ' ' . $time_format;
             $decaf_date_format = 'Y-m-d h:i a';
             $data = $this->_get_save_data($decaf_date_format);
             //is there any data to unset/replace?
             if (!empty($data_to_replace)) {
                 //any data to unset?
                 foreach ($data_to_replace as $top_level => $second_level) {
                     if (is_array($second_level)) {
                         foreach ($second_level as $third_level => $fourth_level) {
                             if (is_array($fourth_level)) {
                                 foreach ($fourth_level as $fifth_level => $sixth_level) {
                                     if (is_null($sixth_level)) {
                                         unset($data_to_replace[$top_level][$third_level][$fifth_level]);
                                         unset($data[$top_level][$third_level][$fifth_level]);
                                     }
                                 }
                             } else {
                                 if (is_null($fourth_level)) {
                                     unset($data_to_replace[$top_level][$third_level]);
                                     unset($data[$top_level][$third_level]);
                                 }
                             }
                         }
                     } else {
                         if (is_null($second_level)) {
                             unset($data_to_replace[$top_level]);
                             unset($data[$top_level]);
                         }
                     }
                 }
                 //moige
                 $data = array_merge($data, $data_to_replace);
             }
             $saved_data = $this->_admin_page->default_tickets_update($this->_event, $data);
             $dtt = $saved_data[0];
             $tkts = $saved_data[1];
             //verify datetime.
             $this->assertInstanceof('EE_Datetime', $dtt);
             //verify start and date
             $this->assertEquals($dtt->start_date_and_time($date_format, $time_format), $this->_default_dates['DTT_start']->format($full_format), $context_for_error_messages . sprintf('Start Date Format Tested: %s', $full_format));
             $this->assertEquals($dtt->end_date_and_time($date_format, $time_format), $this->_default_dates['DTT_end']->format($full_format), $context_for_error_messages . 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);
             //verify tkts
             foreach ($tkts as $tkt) {
                 $this->assertInstanceof('EE_Ticket', $tkt, $context_for_error_messages . sprintf('Format: %s', $full_format));
                 //verify start and date
                 //Note: currently this test sometimes fails depending on the timing of when it happens and how fast
                 // the server is. Whenever I've seen this fail its been off by 1 minute and that's because when the
                 // default dates for testing were created, they likely happened at the second turnover.
                 $this->assertDateWithinOneMinute($tkt->start_date($date_format, $time_format), $this->_default_dates['TKT_start']->format($full_format), $full_format, $context_for_error_messages . sprintf('Start Ticket DateFormat Tested: %s', $full_format));
                 $this->assertDateWithinOneMinute($tkt->end_date($date_format, $time_format), $this->_default_dates['TKT_end']->format($full_format), $full_format, $context_for_error_messages . 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), $context_for_error_messages . 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), $context_for_error_messages . 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($formats[0], $formats[1]), $context_for_error_messages . 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($formats[0], $formats[1]), $context_for_error_messages . 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->assertDateWithinOneMinute($evt_tkt->start_date($formats[0], $formats[1]), $this->_default_dates['TKT_start']->format($format), $format, $context_for_error_messages . sprintf('DB TKT/Default TKT Start Date Format Checked: %s', $format));
         $this->assertDateWithinOneMinute($evt_tkt->end_date($formats[0], $formats[1]), $this->_default_dates['TKT_end']->format($format), $format, $context_for_error_messages . sprintf('DB TKT/Default TKT End Date Format Checked: %s', $format));
         $this->assertDateWithinOneMinute($evt_tkt->start_date($formats[0], $formats[1]), $saved_tkts[$format]->start_date($formats[0], $formats[1]), $format, $context_for_error_messages . sprintf('DB TKT/Orig TKT Start Date Format Checked: %s', $format));
         $this->assertDateWithinOneMinute($evt_tkt->end_date($formats[0], $formats[1]), $saved_tkts[$format]->end_date($formats[0], $formats[1]), $format, $context_for_error_messages . sprintf('DB TKT/Orig TKT End Date Format Checked: %s', $format));
     }
 }
 /**
  * 
  * @return array which can be used for converting to json
  */
 function to_array_for_json()
 {
     $title = $this->_datetime->name() != '' ? $this->_event->name() . ': ' . $this->_datetime->name() : $this->_event->name();
     return array('allDay' => false, 'className' => $this->classname(), 'color' => $this->color(), 'end' => $this->_datetime->end_date('c'), 'event_days' => $this->_datetime->length('days', true), 'event_time' => $this->event_time(), 'event_time_no_tags' => $this->event_time_no_tags(), 'event_img_thumb' => $this->event_img_thumb(), 'eventType' => $this->eventType(), 'description' => apply_filters('FHEE__EE_Datetime_In_Calendar__to_array_for_json__description', $this->description(), $this), 'id' => $this->_event->ID(), 'show_tooltips' => $this->show_tooltips(), 'start' => $this->_datetime->start_date('c'), 'target_date' => $this->_datetime->start_date('Y-m-d'), 'textColor' => $this->textColor(), 'tooltip' => $this->tooltip(), 'tooltip_my' => $this->tooltip_my(), 'tooltip_at' => $this->tooltip_at(), 'tooltip_style' => $this->tooltip_style(), 'title' => apply_filters('FHEE__EE_Datetime_In_Calendar__to_array_for_json__title', $title, $this), 'url' => $this->_event->get_permalink());
 }
 protected function _parser($shortcode)
 {
     EE_Registry::instance()->load_helper('Formatter');
     $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
     //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
     if (empty($this->_event)) {
         $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : NULL;
         $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
         $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : NULL;
     }
     //If there is no event objecdt by now then get out.
     if (!$this->_event instanceof EE_Event) {
         return '';
     }
     switch ($shortcode) {
         case '[EVENT_ID]':
             return $this->_event->ID();
             break;
         case '[EVENT_IDENTIFIER]':
             return isset($this->_data['line_ref']) ? $this->_data['line_ref'] : '';
             break;
         case '[EVENT]':
         case '[EVENT_NAME]':
             return $this->_event->get('EVT_name');
             break;
         case '[EVENT_PHONE]':
             return $this->_event->get('EVT_phone');
             break;
         case '[EVENT_DESCRIPTION]':
             return $this->_event->get('EVT_desc');
             break;
         case '[EVENT_EXCERPT]':
             return $this->_event->get('EVT_short_desc');
             break;
         case '[EVENT_LINK]':
             return $this->_get_event_link($this->_event);
             break;
         case '[EVENT_URL]':
             return $this->_get_event_link($this->_event, FALSE);
             break;
         case '[VIRTUAL_URL]':
             $venue = $this->_event->get_first_related('Venue');
             if (empty($venue)) {
                 return '';
             }
             return $venue->get('VNU_virtual_url');
         case '[VIRTUAL_PHONE]':
             $venue = $this->_event->get_first_related('Venue');
             if (empty($venue)) {
                 return '';
             }
             return $venue->get('VNU_virtual_phone');
             break;
         case '[EVENT_IMAGE]':
             $image = $this->_event->feature_image_url(array(600, 300));
             // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
             return !empty($image) ? '<img src="' . $image . '" alt="' . sprintf(esc_attr__('%s Feature Image', 'event_espresso'), $this->_event->get('EVT_name')) . '" />' : '';
             break;
         case '[EVENT_FACEBOOK_URL]':
             $facebook_url = $this->_event->get_post_meta('event_facebook', true);
             return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') : $facebook_url;
             break;
         case '[EVENT_TWITTER_URL]':
             $twitter_url = $this->_event->get_post_meta('event_twitter', true);
             return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') : $twitter_url;
             break;
         case '[EVENT_AUTHOR_EMAIL]':
             $author_id = $this->_event->get('EVT_wp_user');
             $user_data = get_userdata((int) $author_id);
             return $user_data->user_email;
             break;
         case '[EVENT_TOTAL_SPOTS_TAKEN]':
             return EEM_Registration::instance()->count(array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)), 'REG_ID', true);
             break;
         case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
             EE_Registry::instance()->load_helper('URL');
             return EEH_URL::add_query_args_and_nonce(array('event_id' => $this->_event->ID(), 'page' => 'espresso_registrations', 'action' => 'default'), admin_url('admin.php'), true);
             break;
     }
     if (strpos($shortcode, '[EVENT_META_*') !== false) {
         $shortcode = str_replace('[EVENT_META_*', '', $shortcode);
         $shortcode = trim(str_replace(']', '', $shortcode));
         //pull the meta value from the event post
         $event_meta = $this->_event->get_post_meta($shortcode, true);
         return !empty($event_meta) ? $this->_event->get_post_meta($shortcode, true) : '';
     }
     if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
         $attrs = $this->_get_shortcode_attrs($shortcode);
         $method = empty($attrs['method']) ? 'current' : $attrs['method'];
         $method = $method === 'current';
         $available = $this->_event->total_available_spaces($method);
         return $available === INF ? '&infin;' : $available;
     }
     return '';
 }
 /**
  * Just a method for setting up the actions for the name column
  *
  * @param EE_Event $item
  *
  * @return array array of actions
  */
 protected function _column_name_action_setup(EE_Event $item)
 {
     //todo: remove when attendees is active
     if (!defined('REG_ADMIN_URL')) {
         define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
     }
     $actions = array();
     if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) {
         $edit_query_args = array('action' => 'edit', 'post' => $item->ID());
         $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
         $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>';
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID())) {
         $attendees_query_args = array('action' => 'default', 'event_id' => $item->ID());
         $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
         $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>';
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', $item->ID())) {
         $trash_event_query_args = array('action' => 'trash_event', 'EVT_ID' => $item->ID());
         $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, EVENTS_ADMIN_URL);
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', $item->ID())) {
         $restore_event_query_args = array('action' => 'restore_event', 'EVT_ID' => $item->ID());
         $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, EVENTS_ADMIN_URL);
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', $item->ID())) {
         $delete_event_query_args = array('action' => 'delete_event', 'EVT_ID' => $item->ID());
         $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, EVENTS_ADMIN_URL);
     }
     $view_link = get_permalink($item->ID());
     $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>';
     switch ($item->get('status')) {
         case 'trash':
             if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', $item->ID())) {
                 $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>';
             }
             if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', $item->ID())) {
                 $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>';
             }
             break;
         default:
             if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', $item->ID())) {
                 $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
             }
     }
     return $actions;
 }