update scheduler feature/cruise
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Jun 2014 18:17:18 +0000 (14:17 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Jun 2014 18:17:18 +0000 (14:17 -0400)
can now add page to schedule
removed static page for 9
now using the toolbox page class to add the schedule to the page output.

Toolkit/Schedule/DepartureCalendar.php
Toolkit/Schedule/EditController.php
Toolkit/Schedule/EditSchedule.php
Toolkit/Schedule/js/editSchedule.js
Toolkit/Schedule/templates/editSchedule.html
Toolkit/Template/Page/Toolbox.php
static/9.phtml [deleted file]

index 61abfb7..57038e0 100644 (file)
@@ -107,15 +107,20 @@ class Toolkit_Schedule_DepartureCalendar
         }
     }
 
-    public function hasSchedule()
+    public function hasSchedule($pageId)
     {
         try {
             $this->dbh = Toolkit_Database::getInstance();
             $sql = "
             SELECT *
               FROM schedules
-             WHERE active = true";
-            $scheduleData = $this->dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
+             WHERE page = :page";
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':page', $pageId, PDO::PARAM_INT);
+            $stmt->execute();
+
+            $scheduleData = $stmt->fetch(PDO::FETCH_ASSOC);
+
             if (!$scheduleData) {
                 return false;
             } else {
@@ -133,7 +138,7 @@ class Toolkit_Schedule_DepartureCalendar
      *
      * @return type
      */
-    public function toHtml()
+    public function toHtml($pageId)
     {
         // load ZendConfig
         $this->config = new Zend_Config_Ini(
@@ -149,7 +154,7 @@ 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();
+        $scheduleData = $this->hasSchedule($pageId);
         if (!$scheduleData) {
             return false;
         }
index b9337ec..c884934 100644 (file)
@@ -31,7 +31,7 @@ class Toolkit_Schedule_EditController
 
     /**
      * addScheduleAction
-     * 
+     *
      * adds a empty schedule and echos id
      * this is used in ajax call so exit do not return just echo and exit
      */
@@ -45,7 +45,7 @@ class Toolkit_Schedule_EditController
 
     /**
      * getCalendarYearAction
-     * 
+     *
      * this is used in a ajax call so don't return just echo it and exit
      * gets the set year calendars as html for output
      */
@@ -158,10 +158,10 @@ class Toolkit_Schedule_EditController
         $html = $schedule->toHtml($this->registry);
         return $html;
     }
-    
+
     /**
      * removeDepartureSetAction
-     * 
+     *
      * removes the departures record and then removes all times and dates
      */
     public function removeDepartureSetAction()
@@ -655,9 +655,49 @@ class Toolkit_Schedule_EditController
         exit;
     }
 
+    public function updatePageAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $page = filter_input(
+            INPUT_GET,
+            'page',
+            FILTER_VALIDATE_INT
+        );
+        if (!$scheduleId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE schedules
+               SET page = :page
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':page',
+                $page,
+                PDO::PARAM_INT
+            );
+            $update->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
     /**
      * updateScheduleYearAction
-     * 
+     *
      * this is ajax call so don't return just echo and exit
      * update the year field for the schedule record
      */
index 537a8f3..3a35135 100644 (file)
@@ -7,6 +7,8 @@ class Toolkit_Schedule_EditSchedule
     protected $timesBvi = array();
     protected $dates    = array();
 
+    const LEVELS_DEEP = 5;
+
     /**
      * For the Ajax call to add a departure set create the html and exit
      */
@@ -415,17 +417,18 @@ class Toolkit_Schedule_EditSchedule
         return $select;
     }
 
-    private function _parentSelect($catid = null)
+    private function _parentSelect($registry, $catid = null)
     {
         // select catid portion
         $qs  = "
           SELECT id,navigation_name,parent
             FROM toolbox.pages
+           WHERE id != ".HOME_ID."
         ORDER BY parent,pos";
         $dbh    = $registry->dbh;
         $data   = $dbh->query($qs)->fetchAll(PDO::FETCH_ASSOC);
         $data1  = $this->_sort_by_parent($data);
-        $select = '<select name="page"><option value=""></option>';
+        $select = '<select name="page" id="schedulePageId"><option value=""></option>';
         $parts  = $this->_convertParent($data1, $data1[0]);
         if (is_array($parts)) {
             foreach($parts as $key => $value) {
@@ -495,7 +498,14 @@ class Toolkit_Schedule_EditSchedule
         if ($scheduleId) {
             $page->departures = $this->getDepartures($registry, $scheduleId);
         }
-        $page->pageSelect   = $this->_parentSelect();
+        $page->pageSelect
+            = $this->_parentSelect(
+                $registry,
+                $this->getSchedulePageId(
+                    $registry,
+                    $scheduleId
+                )
+            );
         $page->colors       = $this->colors;
         $page->timesChx     = $this->timesChx;
         $page->timesBvi     = $this->timesBvi;
@@ -512,9 +522,25 @@ class Toolkit_Schedule_EditSchedule
         for ($i = $startingYear; $i <= $endingYear; ++$i) {
             $years[$i] = $i;
         }
-        $elements['schedule_year']->setOptions($years);
-        $elements['schedule_year']->setValue($scheduleData['schedule_year']);
+        //$elements['schedule_year']->setOptions($years);
+        //$elements['schedule_year']->setValue($scheduleData['schedule_year']);
         $html .= $tpl->bufferedOutputObject($page, $elements);
         return $html;
     }
+
+    public function getSchedulePageId($registry, $scheduleId)
+    {
+        try {
+            $sql = "
+            SELECT page
+              FROM boats.schedules
+             WHERE id = :id";
+            $stmt = $registry->dbh->prepare($sql);
+            $stmt->bindParam(':id', $scheduleId, PDO::PARAM_INT);
+            $stmt->execute();
+            return $stmt->fetchColumn();
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
 }
index 2ff108e..f4c970d 100644 (file)
@@ -121,7 +121,7 @@ var EditSchedule =
         $('.commentSave').live('click', function(){
             var departureId = $(this).attr('rel');
             var comments = $('#comments' + departureId).val();
-                
+
             $.ajax({
                 cache: false,
                 url: glm_baseUrl + "schedules/Edit/updateComment/",
@@ -141,7 +141,7 @@ var EditSchedule =
         $('.nameSave').live('click', function(){
             var scheduleId = $(this).attr('rel');
             var name = $('#scheduleNameText').val();
-                
+
             $.ajax({
                 cache: false,
                 url: glm_baseUrl + "schedules/Edit/updateName/",
@@ -154,6 +154,23 @@ var EditSchedule =
                 }
             });
         });
+        // setup pageSave click for all future events
+        $('.pageSave').live('click', function(){
+            var scheduleId = $(this).attr('rel');
+            var page = $('#schedulePageId').val();
+
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updatePage/",
+                data: "id=" + scheduleId
+                    + "&page="  + encodeURIComponent(page),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                }
+            });
+        });
         // for all glm_departures (from flexy phpToJson) setup departures
         for (i in glm_departures) {
             EditSchedule.setupDepartureById(glm_departures[i]);
@@ -230,9 +247,9 @@ var EditSchedule =
                 "Edit Time": function() {
                     var bValid = true;
                     allFields.removeClass( "ui-state-error" );
-                    
+
                     bValid = bValid && checkLength( depart_time, "Time", 4);
-                    
+
                     if (depart_time.val()) {
                         bValid = bValid && checkRegexp( depart_time, /([0-9]{1,2}:[0-9]{2} [APMapm]{2})$/i, "time in HH:MM AM or PM" );
                     }
@@ -269,14 +286,14 @@ var EditSchedule =
                                         $('.chxTime.addTime[rel="'+data.departure_id+'"]').before(
                                             '<label class="timeLabel">' +
                                             '<span rel="'+data.id+'" class="form-element">'+ data.time + '</span>' +
-                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' + 
+                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' +
                                             '</label>'
                                         );
                                     } else if (data.dock == 2) {
                                         $('.bviTime.addTime[rel="'+data.departure_id+'"]').before(
                                             '<label class="timeLabel">' +
                                             '<span rel="'+data.id+'" class="form-element">'+ data.time + '</span>' +
-                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' + 
+                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' +
                                             '</label>'
                                         );
                                     }
@@ -288,7 +305,7 @@ var EditSchedule =
                                 }
                             });
                         }
-                        
+
                         $( this ).dialog( "close" );
                     }
                 },
@@ -300,7 +317,7 @@ var EditSchedule =
                 allFields.val( "" ).removeClass( "ui-state-error" );
             }
         });
-        
+
     },
     // setup the departures by id
     setupDepartureById: function(id){
@@ -319,13 +336,13 @@ var EditSchedule =
                 }
             });
         });
-        
+
         $('#departureCal' + id).click(function(){
             var ajaxUrl = glm_baseUrl + "schedules/Edit/getCalendarYear/";
             var departureId = $(this).attr('rel');
             var timeDate = new Date();
-            ajaxUrl += "?id=" + glm_scheduleId 
-                + "&departId=" + id 
+            ajaxUrl += "?id=" + glm_scheduleId
+                + "&departId=" + id
                 + "&year=" + glm_scheduleYear
                 + "&_=" + timeDate.getTime();
             $('#departure' + departureId).load(ajaxUrl).dialog({
index ae17e6c..4d5394f 100644 (file)
   monthsHeight="monthsHeight"
 />
 <div id="breadcrumbs"><a href="{backUrl:h}">Schedules</a> > {name:h} </div>
-<div>
-    <label>
-        Year for Schedule
-    <select id="schedule_year" name="schedule_year">
-    </select>
-    </label>
-</div>
 <div id="scheduleName" class="edit-field">
     <input id="scheduleNameText" name="scheduleName" value="{name:h}" >
     <button rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only nameSave">
@@ -44,7 +37,7 @@
 </div>
 <div id="schedulePage" class="edit-field">
     {pageSelect:h}
-    <button rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only nameSave">
+    <button rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only pageSave">
       <span class="ui-button-text">Save</span>
     </button>
 </div>
index b1e386a..0d1c4a5 100644 (file)
@@ -154,6 +154,9 @@ class Toolkit_Template_Page_Toolbox implements Toolkit_Template_Page_IBody
                $breadCrumbs         = $breadCrumbsBuilder->toHtml($this->id);
                $secondaryParagraphs = $this->getSecondaryParagraphs($this->id);
                $primaryParagraph    = $this->getPrimaryParagraph($this->id);
+        $schedules           = new Toolkit_Schedule_DepartureCalendar();
+        $scheduleDisplay     = $schedules->toHtml($this->id);
+
         $coupons = null;
                if (defined('COUPONS') && COUPONS) {
                        $coupons = $this->_getPageCoupons($this->id);
@@ -169,6 +172,7 @@ class Toolkit_Template_Page_Toolbox implements Toolkit_Template_Page_IBody
                $primaryParagraph .
                $secondaryParagraphs .
                $staticPageContent .
+               $scheduleDisplay .
                $coupons .
                $photoGalleryContent;
        }
diff --git a/static/9.phtml b/static/9.phtml
deleted file mode 100644 (file)
index 24fc588..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
-// need to get the config for app loaded
-$schedules = new Toolkit_Schedule_DepartureCalendar();
-echo $schedules->toHtml();
\ No newline at end of file