adding end date to the events with different end dates than the start date
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 31 Jan 2017 18:03:31 +0000 (13:03 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 31 Jan 2017 18:03:31 +0000 (13:03 -0500)
models/admin/ajax/eventsCalMonthAJAX.php
views/front/events/sidebarEvents.html

index f627656..6b852d0 100644 (file)
@@ -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);
index ebeebf3..da0c026 100644 (file)
@@ -2,7 +2,7 @@
     <h1>Upcoming Events </h1>
     <div id="sidebar-date-select" class="sidebar-datepicker"></div>
     <div class="sidebar-events"></div>
-
+    
 
 <script>
     jQuery(document).ready(function($) {
@@ -20,7 +20,6 @@
                     $('.sidebar-event').fadeIn("slow");
                 },
                 success: function(data){
-
                       if(data.array_dates !== null){
                         var num = 0;
                         $.each(data.array_dates, function(index, value){