Fixed bad dates in events list when no times entries
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 8 Jun 2016 14:53:13 +0000 (10:53 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 8 Jun 2016 14:53:13 +0000 (10:53 -0400)
classes/data/dataEvents.php

index a75e307..f21289f 100644 (file)
@@ -774,15 +774,32 @@ class GlmDataEvents extends GlmDataAbstract
     public function getFirstAndLastTimes($id = false)
     {
 
+        $firstDate = '';
+        $lastDate = '';
+
         // Load the data class for Event Times
         require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataTimes.php');
         $Times = new GlmDataEventsTimes($this->wpdb, $this->config);
 
-        // Select the first and last entries by matching min and max start times
+        // Select the first entry by matching min start time
         $first = $Times->getEntry(0, 'id', "T.event = $id ORDER BY T.start_time");
-        $last = $Times->getEntry(0, 'id', "T.event = $id ORDER BY T.start_time DESC");
 
-        $r = array('first' => date('m/d/Y', $first['start_time']['timestamp']), 'last' => date('m/d/Y', $last['start_time']['timestamp']));
+        // If there's a first times entry
+        if ($first) {
+
+            // Convert to text date
+            $firstDate = date('m/d/Y', $first['start_time']['timestamp']);
+
+            // Find last date
+            $last = $Times->getEntry(0, 'id', "T.event = $id ORDER BY T.start_time DESC");
+
+            // If last date is not the same as first
+            if ($last != $first) {
+                $lastDate = date('m/d/Y', $last['start_time']['timestamp']);
+            }
+        }
+
+        $r = array('first' => $firstDate, 'last' => $lastDate);
 
         return $r;