/**
  * 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 _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;
 }
 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 '';
 }