Update for the output class
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Oct 2014 15:49:05 +0000 (11:49 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Oct 2014 15:49:05 +0000 (11:49 -0400)
Can now output more than one calender schedule for
the page.

Toolkit/Schedule/DepartureCalendar.php

index 9749da6..271ba22 100644 (file)
@@ -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 '<pre>'.print_r($selected, true).'</pre>';
-//        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;
     }
 }