From 72ca48a4f407a8dc831e1fbed4515850c0ed4b36 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 8 Jun 2016 10:53:13 -0400 Subject: [PATCH] Fixed bad dates in events list when no times entries --- classes/data/dataEvents.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index a75e307..f21289f 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -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; -- 2.17.1