From 54a289602eb7903529ce24ec9507d8c2a4074d96 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 28 Oct 2014 11:49:05 -0400 Subject: [PATCH] Update for the output class Can now output more than one calender schedule for the page. --- Toolkit/Schedule/DepartureCalendar.php | 89 +++++++++++++------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/Toolkit/Schedule/DepartureCalendar.php b/Toolkit/Schedule/DepartureCalendar.php index 9749da6..271ba22 100644 --- a/Toolkit/Schedule/DepartureCalendar.php +++ b/Toolkit/Schedule/DepartureCalendar.php @@ -114,12 +114,13 @@ class Toolkit_Schedule_DepartureCalendar $sql = " SELECT * FROM schedules - WHERE page = :page"; + WHERE page = :page + ORDER BY schedule_year"; $stmt = $this->dbh->prepare($sql); $stmt->bindParam(':page', $pageId, PDO::PARAM_INT); $stmt->execute(); - $scheduleData = $stmt->fetch(PDO::FETCH_ASSOC); + $scheduleData = $stmt->fetchAll(PDO::FETCH_ASSOC); if (!$scheduleData) { return false; @@ -140,6 +141,7 @@ class Toolkit_Schedule_DepartureCalendar */ public function toHtml($pageId) { + $calendars = ''; // load ZendConfig $this->config = new Zend_Config_Ini( BASE . 'Toolkit/Schedule/application.ini', @@ -154,53 +156,54 @@ class Toolkit_Schedule_DepartureCalendar $cals = new Toolkit_Schedule_Calendar(); // get the active schedule if no active schedule is found then return // nothing - $scheduleData = $this->hasSchedule($pageId); - if (!$scheduleData) { + $scheduleDataArray = $this->hasSchedule($pageId); + if (!$scheduleDataArray) { return false; } - $scheduleId = (string)$scheduleData['id']; - $scheduleName = $scheduleData['name']; - $year = $scheduleData['schedule_year']; - - $colors - = ($scheduleId) - ? $cals->getDepartureColors($scheduleId) - : null; $style = ''; - if ($colors) { - foreach ($colors as $departId => $color) { - $style .= ".depart{$departId} {background-color:{$color};}\n"; + foreach ($scheduleDataArray as $scheduleData) { + $scheduleId = (string)$scheduleData['id']; + $scheduleName = $scheduleData['name']; + $year = $scheduleData['schedule_year']; + + $colors + = ($scheduleId) + ? $cals->getDepartureColors($scheduleId) + : null; + + if ($colors) { + foreach ($colors as $departId => $color) { + $style .= ".depart{$departId} {background-color:{$color};}\n"; + } } - } - $selected = $cals->getDepartureDates($scheduleId); -// echo '
'.print_r($selected, true).'
'; -// exit; - $year - = ($year) - ? $year - : date('Y'); - $page = new stdClass(); - $startingMonth = $this->config->months->start; - $endingMonth = $this->config->months->end; - for ($i = $startingMonth; $i <= $endingMonth; ++$i) { - if (in_array($i, $cals->months)) { - $page->calendarsHtml .= $cals->buildCalendar($i, $year, $selected); + $selected = $cals->getDepartureDates($scheduleId); + $year + = ($year) + ? $year + : date('Y'); + $page = new stdClass(); + $startingMonth = $this->config->months->start; + $endingMonth = $this->config->months->end; + for ($i = $startingMonth; $i <= $endingMonth; ++$i) { + if (in_array($i, $cals->months)) { + $page->calendarsHtml .= $cals->buildCalendar($i, $year, $selected); + } } + $tpl = new HTML_Template_Flexy($this->flexyOptions); + $page->style = $style; + $page->appBase = GLM_APP_BASE_URL; + $page->baseUrl = BASE_URL; + $page->scheduleId = $scheduleId; + $page->scheduleName = $scheduleName; + $page->departByDate = $this->getDeparturesForDate(); + $ScheduleEdit = new Toolkit_Schedule_EditSchedule(); + $page->departures = $ScheduleEdit->getDeparturesForSchedules( + $this, + $scheduleId + ); + $tpl->compile('departuresScheduleCalendar.html'); + $calendars .= $tpl->bufferedOutputObject($page); } - $tpl = new HTML_Template_Flexy($this->flexyOptions); - $page->style = $style; - $page->appBase = GLM_APP_BASE_URL; - $page->baseUrl = BASE_URL; - $page->scheduleId = $scheduleId; - $page->scheduleName = $scheduleName; - $page->departByDate = $this->getDeparturesForDate(); - $ScheduleEdit = new Toolkit_Schedule_EditSchedule(); - $page->departures = $ScheduleEdit->getDeparturesForSchedules( - $this, - $scheduleId - ); - $tpl->compile('departuresScheduleCalendar.html'); - $calendars = $tpl->bufferedOutputObject($page); return $calendars; } } -- 2.17.1