/**
  *		This function is a singleton method used to instantiate the EEM_Attendee object
  *
  *		@access public
  *		@return EEM_Attendee instance
  */
 public static function instance()
 {
     // check if instance of EEM_Attendee already exists
     if (self::$_instance === NULL) {
         // instantiate Espresso_model
         self::$_instance = new self();
     }
     // EEM_Attendee object
     return self::$_instance;
 }
 public function column_name($item)
 {
     $edit_query_args = array('action' => 'edit', 'post' => $item->ID());
     $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_VENUES_ADMIN_URL);
     $statuses = EEM_Venue::instance()->get_status_array();
     $actions = $this->_column_name_action_setup($item);
     $content = EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $item->ID()) ? '<strong><a class="row-title" href="' . $edit_link . '">' . stripslashes_deep($item->name()) . '</a></strong>' : $item->name();
     $content .= $item->status() == 'draft' ? ' - <span class="post-state">' . $statuses['draft'] . '</span>' : '';
     $content .= $this->row_actions($actions);
     return $content;
 }
 /**
  *    get_venue
  *    attempts to retrieve an EE_Venue object any way it can
  *
  * @access    public
  * @param int  $VNU_ID
  * @param bool $look_in_event
  * @param bool $privacy_check  Defaults to true.  When false, means even if the venue is private we return it
  *                             		     regardless of access.
  * @return EE_Venue | null
  */
 public static function get_venue($VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true)
 {
     $VNU_ID = absint($VNU_ID);
     // do we already have the Venue you are looking for?
     if (EEH_Venue_View::$_venue instanceof EE_Venue && EEH_Venue_View::$_venue->ID() == $VNU_ID) {
         return EEH_Venue_View::_get_venue($privacy_check);
     }
     // international newspaper?
     global $post;
     if ($post instanceof WP_Post) {
         switch ($post->post_type) {
             // if this is being called from an EE_Venue post,
             // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
             // then we can try to just grab the attached EE_Venue object
             case 'espresso_venues':
                 // the post already contains the related EE_Venue object AND one of the following is TRUE:
                 // the requested Venue ID matches the post ID OR...
                 // there was no specific Venue ID requested
                 if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || !$VNU_ID)) {
                     // use existing related EE_Venue object
                     EEH_Venue_View::$_venue = $post->EE_Venue;
                 } else {
                     if ($VNU_ID) {
                         // there WAS a specific Venue ID requested, but it's NOT the current post object
                         EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
                     } else {
                         // no specific Venue ID requested, so use post ID to generate EE_Venue object
                         EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
                     }
                 }
                 break;
             case 'espresso_events':
                 if ($look_in_event) {
                     // grab the events related venues
                     $venues = EEH_Venue_View::get_event_venues();
                     // make sure the result is an array
                     $venues = is_array($venues) ? $venues : array();
                     // do we have an ID for a specific venue?
                     if ($VNU_ID) {
                         // loop thru the related venues
                         foreach ($venues as $venue) {
                             if ($venue instanceof EE_Venue) {
                                 // until we find the venue we're looking for
                                 if ($venue->ID() == $VNU_ID) {
                                     EEH_Venue_View::$_venue = $venue;
                                     break;
                                 }
                             }
                             // if the venue being asked for is not related to the global event post,
                             // still return the venue being asked for
                         }
                         // no venue ID ?
                         // then the global post is an events post and this function was called with no argument
                     } else {
                         // just grab the first related event venue
                         EEH_Venue_View::$_venue = reset($venues);
                     }
                 }
                 break;
         }
     }
     // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
     if (!EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
         // sigh... pull it from the db
         EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
     }
     return EEH_Venue_View::_get_venue($privacy_check);
 }
 private function _delete_or_trash_venue($VNU_ID = FALSE)
 {
     // grab event id
     if (!($VNU_ID = absint($VNU_ID))) {
         $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
         EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
         return FALSE;
     }
     $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
     //first need to remove all term relationships
     $venue->_remove_relations('Term_Taxonomy');
     $success = $venue->delete_permanently();
     // did it all go as planned ?
     if ($success) {
         $msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
         EE_Error::add_success($msg);
     } else {
         $msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
         EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
         return FALSE;
     }
     do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
     return TRUE;
 }
 function test_get_cap_name()
 {
     $this->assertEquals('ee_edit_events', EE_Restriction_Generator_Base::get_cap_name(EEM_Event::instance(), 'edit'));
     $this->assertEquals('ee_read_private_venues', EE_Restriction_Generator_Base::get_cap_name(EEM_Venue::instance(), 'read_private'));
 }
 /**
  *    posts_orderby_sql
  *
  *    possible parameters:
  *    ID
  *    start_date
  *    end_date
  *    event_name
  *    category_slug
  *    ticket_start
  *    ticket_end
  *    venue_title
  *    city
  *    state
  *
  *    **IMPORTANT**
  *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
  *    or else some of the table references below will result in MySQL errors
  *
  * @access    public
  * @param array|bool $orderby_params
  * @param string     $sort
  * @return    string
  */
 public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC')
 {
     global $wpdb;
     $SQL = '';
     $counter = 0;
     //make sure 'orderby' is set in query params
     if (!isset(self::$_query_params['orderby'])) {
         self::$_query_params['orderby'] = array();
     }
     // loop thru $orderby_params (type cast as array)
     foreach ((array) $orderby_params as $orderby) {
         // check if we have already added this param
         if (isset(self::$_query_params['orderby'][$orderby])) {
             // if so then remove from the $orderby_params so that the count() method below is accurate
             unset($orderby_params[$orderby]);
             // then bump ahead to the next param
             continue;
         }
         // this will ad a comma depending on whether this is the first or last param
         $glue = $counter == 0 || $counter == count($orderby_params) ? ' ' : ', ';
         // ok what's we dealing with?
         switch ($orderby) {
             case 'id':
             case 'ID':
                 $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
                 break;
             case 'end_date':
                 $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
                 break;
             case 'event_name':
                 $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
                 break;
             case 'category_slug':
                 $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
                 break;
             case 'ticket_start':
                 $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
                 break;
             case 'ticket_end':
                 $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
                 break;
             case 'venue_title':
                 $SQL .= $glue . 'venue_title ' . $sort;
                 break;
             case 'city':
                 $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
                 break;
             case 'state':
                 $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
                 break;
             case 'start_date':
             default:
                 $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
                 break;
         }
         // add to array of orderby params that have been added
         self::$_query_params['orderby'][$orderby] = TRUE;
         $counter++;
     }
     return $SQL;
 }
 /**
  * 	posts_orderby_sql
  *
  * 	possible parameters:
  * 	ID
  * 	start_date
  * 	end_date
  * 	event_name
  * 	category_slug
  * 	ticket_start
  * 	ticket_end
  * 	venue_title
  * 	city
  * 	state
  *
  * 	**IMPORTANT**
  * 	make sure to also send the $orderby_params array to the posts_join_for_orderby() method
  * 	or else some of the table references below will result in MySQL errors
  *
  *  @access 	public
  *  @param	boolean	$orderby_params
  *  @return 	string
  */
 public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC')
 {
     global $wpdb;
     $SQL = '';
     $cntr = 1;
     $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
     foreach ($orderby_params as $orderby) {
         $glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', ';
         switch ($orderby) {
             case 'id':
             case 'ID':
                 $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
                 break;
             case 'start_date':
                 $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
                 break;
             case 'end_date':
                 $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
                 break;
             case 'event_name':
                 $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
                 break;
             case 'category_slug':
                 $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
                 break;
             case 'ticket_start':
                 $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
                 break;
             case 'ticket_end':
                 $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
                 break;
             case 'venue_title':
                 $SQL .= $glue . 'venue_title ' . $sort;
                 break;
             case 'city':
                 $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
                 break;
             case 'state':
                 $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
                 break;
         }
         $cntr++;
     }
     //echo '<h4>$SQL : ' . $SQL . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
     return $SQL;
 }
 /**
  * return the venue object for a given venue ID
  *
  * @since 4.3.0
  *
  * @param int $VNU_ID the venue id for the venue to attempt to retrieve
  *
  * @return mixed null|EE_Venue
  */
 public function get_object_by_id($VNU_ID)
 {
     return EEM_Venue::instance()->get_one_by_ID($VNU_ID);
 }
    /**
     * Gets the HTML for the calendar filters area
     * @param array $ee_calendar_js_options mess of options which will eb passed onto js
     * which we might want in here. (But using the config object directly might be nice,
     * because it's well-defined... however, unfortunately settings in it might be overridden
     * by shortcode attributes, which you can access in this array, if you know their key)
     * @return string
     */
    private function _get_filter_html($ee_calendar_js_options = array())
    {
        $output_filter = '';
        if (!$ee_calendar_js_options['widget']) {
            // Query for Select box filters
            $ee_terms = EEM_Term::instance()->get_all(array('order_by' => array('name' => 'ASC'), array('Term_Taxonomy.taxonomy' => 'espresso_event_categories')));
            $venues = EEM_Venue::instance()->get_all(array('order_by' => array('VNU_name' => 'ASC')));
            if (!empty($venues) || !empty($ee_terms)) {
                ob_start();
                //Category legend
                if ($this->config()->display->enable_category_legend) {
                    echo '
			<div id="espresso-category-legend">
				<p class="smaller-text lt-grey-txt">' . __('Click to select a category:', 'event_espresso') . '</p>
				<ul id="ee-category-legend-ul">';
                    foreach ($ee_terms as $ee_term) {
                        if ($ee_term instanceof EE_Term) {
                            /*@var $ee_term EE_Term */
                            $catcode = $ee_term->ID();
                            $bg = $ee_term->get_extra_meta('background_color', TRUE, $this->config()->display->event_background);
                            $fontcolor = $ee_term->get_extra_meta('text_color', TRUE, $this->config()->display->event_text_color);
                            $use_bg = $ee_term->get_extra_meta('use_color_picker', TRUE);
                            $caturl = esc_url(add_query_arg('event_category_id', $ee_term->slug()));
                            if ($use_bg) {
                                echo '
							<li id="ee-category-legend-li-' . $catcode . '" class="has-sub" style="background: ' . $bg . ';">
								<span class="ee-category"><a href="' . $caturl . '" style="color: ' . $fontcolor . ';">' . $ee_term->name() . '</a></span>
							</li>';
                            } else {
                                echo '
							<li id="ee-category-li-' . $catcode . '" class="has-sub" style="background: #f3f3f3;" >
								<span class="ee-category"><a href="' . $caturl . '">' . $ee_term->name() . '</a></span>
							</li>';
                            }
                        }
                    }
                    echo '</ul>
				</div>
				<div class="clear"></div>
				';
                }
                //Filter dropdowns
                if ($this->config()->display->enable_calendar_filters) {
                    ?>
				<!-- select box filters -->
				<div class="ee-filter-form">
				<form name="filter-calendar-form" id="filter-calendar-form" method="post" action="">
				<?php 
                    if (!empty($ee_terms)) {
                        ?>
					<label for="ee-category-submit"></label>
					<select id="ee-category-submit" class="submit-this ee-category-select" name="event_category_id">
					<option id="option" class="ee_select" value=""><?php 
                        echo __('Select a Category', 'event_espresso');
                        ?>
</option>
					<option class="ee_filter_show_all" value=""><?php 
                        echo __('Show All', 'event_espresso');
                        ?>
</option>
					<?php 
                        foreach ($ee_terms as $term) {
                            if ($term instanceof EE_Term) {
                                $selected = in_array($ee_calendar_js_options['event_category_id'], array($term->slug(), $term->ID())) ? 'selected="selected"' : '';
                                echo '<option ' . $selected . ' value="' . $term->slug() . '">' . $term->name() . '</option>';
                            }
                        }
                        ?>
					</select>
				<?php 
                    }
                    ?>

				<?php 
                    if (!empty($venues)) {
                        ?>
					<label for="ee-venue-submit"></label>
					<select id="ee-venue-submit" class="submit-this ee-venue-select" name="event_venue_id">
					<option class="ee_select" value=""><?php 
                        echo __('Select a Venue', 'event_espresso');
                        ?>
</option>
					<option class="ee_filter_show_all" value=""><?php 
                        echo __('Show All', 'event_espresso');
                        ?>
</option>
					<?php 
                        foreach ($venues as $venue) {
                            if ($venue instanceof EE_Venue && $venue->status() == 'publish') {
                                $selected = in_array($ee_calendar_js_options['event_venue_id'], array($venue->identifier(), $venue->ID())) ? ' selected="selected"' : '';
                                echo '<option' . $selected . ' value="' . $venue->identifier() . '">' . stripslashes($venue->name()) . '</option>';
                            }
                        }
                        ?>
					</select>
				<?php 
                    }
                    ?>
				</form>
				</div>
				<?php 
                }
                $output_filter = ob_get_contents();
                ob_end_clean();
            }
        }
        return $output_filter;
    }