From: Anthony Talarico Date: Thu, 8 Feb 2018 14:00:43 +0000 (-0500) Subject: adjusting the date ranges for the events being pulled from the ajax events widget X-Git-Tag: v1.6.77^2~14 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3d9548ee7480edd172c11c2d93d024ef9bbd02eb;p=WP-Plugins%2Fglm-member-db-events.git adjusting the date ranges for the events being pulled from the ajax events widget ajax events widget needed to have different date ranges --- diff --git a/models/admin/ajax/eventsCalMonthAJAX.php b/models/admin/ajax/eventsCalMonthAJAX.php index d9359b7..a1d35c7 100644 --- a/models/admin/ajax/eventsCalMonthAJAX.php +++ b/models/admin/ajax/eventsCalMonthAJAX.php @@ -117,6 +117,7 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes $this->postAddTimes = false; return $events; } + function clean($string) { $string= strtolower(str_replace(" ", '-',$string)); return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. @@ -142,29 +143,37 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes $image_url = false; $datesArray = array(); - // this section is for a sidebar events widget, typically on a front page + // this section is for a sidebar events widget, typically on a front page if( isset( $_REQUEST['date_string'] ) || isset($_REQUEST['all_events'] ) ){ + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + $memberInfo = new GlmDataMembers($this->wpdb, $this->config); + $locationName = false; + + $category = ( isset($_REQUEST['cat']) ) ? "WHERE category = ". $_REQUEST['cat'] : "WHERE TRUE "; + $image_url = GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/small/'; if( isset( $_REQUEST['date_string'] ) ){ - - + + $date = date_parse($_REQUEST['date_string']); $month = $date['month']; $year = $date['year']; - + $from = date('Y-m-01', strtotime($year.'-'.$month."-01")); $to = date('Y-m-t', strtotime($year.'-'.$month."-01")); - - $this->dateRangeTimes = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE) AND end_time >= CURDATE() ORDER BY start_time LIMIT 3"; - + + $this->dateRangeTimes = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE) AND end_time >= CURDATE() ORDER BY start_time"; + $events = $this->getModelTimesData(); + } else if( isset( $_REQUEST['all_events'] ) ){ - - $this->dateRangeTimes = "end_time >= CURDATE() ORDER BY start_time LIMIT 3"; + + $this->dateRangeTimes = "start_time >= CURDATE() AND end_time <= CURDATE() + INTERVAL 3 DAY ORDER BY start_time"; $events = $this->getModelTimesData(); + // $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE end_time >= CURDATE() GROUP BY event ORDER BY start_time LIMIT 3;"; // $events = $wpdb->get_results($sql, 'ARRAY_A'); - + // foreach($events_times as $times){ // $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $times->event.";"; // $event[] = $wpdb->get_results($sql, 'ARRAY_A'); @@ -174,54 +183,76 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes // $events[] = $e; // } // } - + } // $this->dateRangeTimes = "AND end_time >= CURDATE() ORDER BY start_time LIMIT 3"; // $events = $this->getModelTimesData(); - + foreach($events as $event){ - $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $event['event']; - +// $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $event['event']; + $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $event['event'] . " AND id IN(select event FROM " + . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."event_categories $category);"; +// $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id IN(select event FROM " +// . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."event_categories $category);"; + $event_recur = $wpdb->get_results($sql); - - if($event_recur[0]->image !== ''){ - $image = $image_url . $event_recur[0]->image; - } else { - $image = "none"; + + $sql = "SELECT name FROM ". GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations WHERE event = " .$event['event'] . ";"; + $location = $wpdb->get_results($sql); + + // use member location is is set otherwise use the event location + if($event_recur[0]->use_member_location){ + + $memberID = $event_recur[0]->ref_dest; + $locationName = $memberInfo->getIdName("id = $memberID")[$memberID]['name']; + + } else if( $location[0]->name){ + $locationName = $location[0]->name; } + + // get event image path + if($event_recur){ + if($event_recur[0]->image !== ''){ + $image = $image_url . $event_recur[0]->image; + } else { + $image = "none"; + } - $time_of_day = date('g:i A', strtotime($event['start_time']['datetime'])); - $start_date = date('M d', strtotime($event['start_time']['datetime'])); - $start_timestamp = strtotime($start_date); - $end_timestamp = strtotime($end_date); + $time_of_day = date('g:i A', strtotime($event['start_time']['datetime'])); + $start_date = date('M d', strtotime($event['start_time']['datetime'])); + $start_timestamp = strtotime($start_date); + $end_timestamp = strtotime($end_date); - if($start_timestamp < $end_timestamp){ - $start_date = $start_date . " - " . $end_date; - } + if($start_timestamp < $end_timestamp){ + $start_date = $start_date . " - " . $end_date; + } - if(count($event['start_time']['datetime']) > 1){ - $end_date = date('M d', strtotime(end($event['end_time']['datetime'])->end_time)); - } else { - $end_date = ''; + if(count($event['start_time']['datetime']) > 1){ + $end_date = date('M d', strtotime(end($event['end_time']['datetime'])->end_time)); + } else { + $end_date = ''; + } + + $event_data[] = array( + "start_date" => $start_date, + "end_date" => $end_date, + "name" => $event_recur[0]->name, + "content" => $event_recur[0]->intro, + 'location' => $locationName, + 'image' => $image, + 'id' => $event->id, + 'time' => $time_of_day, + 'timestamp' => $start_timestamp, + 'slug' => $event->name_slug, + 'url' => GLM_MEMBERS_EVENTS_SITE_BASE_URL . 'event-detail/' . $event_recur[0]->name_slug . "/" + ); + + $datesArray[$event['start_time']['timestamp']][] = $event_data; } - - $event_data[] = array( - "start_date" => $start_date, - "end_date" => $end_date, - "name" => $event_recur[0]->name, - "content" => $event_recur[0]->intro, - 'image' => $image, - 'id' => $event->id, - 'time' => $time_of_day, - 'timestamp' => $start_timestamp, - 'slug' => $event->name_slug, - 'url' => GLM_MEMBERS_EVENTS_SITE_BASE_URL . 'event-detail/' . $event_recur[0]->name_slug . "/" - ); - - $datesArray[$event['start_time']['timestamp']][] = $event_data; + } - - // end section for front page events widget data + + // end section for front page events widget data } else if( isset($_REQUEST['month']) ){ if( isset( $_REQUEST['custom_page'] ) ){