From adf3315b10ead6e40aae7190c9bccd8f5a843527 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 31 Jan 2017 13:03:31 -0500 Subject: [PATCH] adding end date to the events with different end dates than the start date --- models/admin/ajax/eventsCalMonthAJAX.php | 24 ++++++++++++++++-------- views/front/events/sidebarEvents.html | 3 +-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/models/admin/ajax/eventsCalMonthAJAX.php b/models/admin/ajax/eventsCalMonthAJAX.php index f627656..6b852d0 100644 --- a/models/admin/ajax/eventsCalMonthAJAX.php +++ b/models/admin/ajax/eventsCalMonthAJAX.php @@ -141,7 +141,7 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE status = 10 AND id IN (SELECT event FROM "; - $sql .= GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE YEAR(start_time) = $year AND MONTH(start_time) = $month AND active = 1 ORDER BY start_time) LIMIT 3; "; + $sql .= GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE YEAR(start_time) = $year AND MONTH(start_time) = $month AND active = 1 AND end_time >= CURDATE() ORDER BY start_time) LIMIT 3; "; $events = $wpdb->get_results($sql); @@ -149,7 +149,8 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes // $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE status = 10 AND id IN (SELECT event FROM "; // $sql .= GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times ORDER BY start_time) LIMIT 3"; - $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times GROUP BY event ORDER BY start_time LIMIT 3;"; + $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE end_time >= CURDATE() GROUP BY event ORDER BY start_time LIMIT 3;"; +// $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times ORDER BY start_time LIMIT 3;"; $events_times = $wpdb->get_results($sql); foreach($events_times as $times){ @@ -164,7 +165,7 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes } } foreach($events as $event){ - $sql = "SELECT start_time, end_time FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE event = " . $event->id; + $sql = "SELECT start_time, end_time, event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE event = " . $event->id; if($event->image !== ''){ $image = $image_url . $event->image; @@ -173,15 +174,23 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes } $date = $wpdb->get_results($sql); - $dates[] = $date[0]; + + if(count($date) > 1){ + $end_date = date('M d', strtotime($date[1]->end_time)); + } else { + $end_date = ''; + } + $start_date = date('M d', strtotime($date[0]->start_time)); - $end_date = date('M d', strtotime($date[0]->end_time)); $start_timestamp = strtotime($start_date); $end_timestamp = strtotime($end_date); - + + if($start_timestamp < $end_timestamp){ + $start_date = $start_date . " - " . $end_date; + } $sidebar_events[$event->id] = array( - "start_date" => $start_date, + "start_date" => $start_date, "end_date" => $end_date, "name" => $event->name, "content" => $event->descr, @@ -263,7 +272,6 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes 'message' => $info, 'sidebar_events' => $sidebar_events, 'array_dates' => $arrayDates, - 'event' => $events ); header('Content-type:application/json;charset=utf-8', true); diff --git a/views/front/events/sidebarEvents.html b/views/front/events/sidebarEvents.html index ebeebf3..da0c026 100644 --- a/views/front/events/sidebarEvents.html +++ b/views/front/events/sidebarEvents.html @@ -2,7 +2,7 @@

Upcoming Events

- +