From aefcb7ef257df88780f589dbbbc65bee140f1da5 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 18 Jun 2014 14:17:18 -0400 Subject: [PATCH] update scheduler 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 | 15 ++++-- Toolkit/Schedule/EditController.php | 50 ++++++++++++++++++-- Toolkit/Schedule/EditSchedule.php | 36 ++++++++++++-- Toolkit/Schedule/js/editSchedule.js | 39 ++++++++++----- Toolkit/Schedule/templates/editSchedule.html | 9 +--- Toolkit/Template/Page/Toolbox.php | 4 ++ static/9.phtml | 4 -- 7 files changed, 119 insertions(+), 38 deletions(-) delete mode 100644 static/9.phtml diff --git a/Toolkit/Schedule/DepartureCalendar.php b/Toolkit/Schedule/DepartureCalendar.php index 61abfb7..57038e0 100644 --- a/Toolkit/Schedule/DepartureCalendar.php +++ b/Toolkit/Schedule/DepartureCalendar.php @@ -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; } diff --git a/Toolkit/Schedule/EditController.php b/Toolkit/Schedule/EditController.php index b9337ec..c884934 100644 --- a/Toolkit/Schedule/EditController.php +++ b/Toolkit/Schedule/EditController.php @@ -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 */ diff --git a/Toolkit/Schedule/EditSchedule.php b/Toolkit/Schedule/EditSchedule.php index 537a8f3..3a35135 100644 --- a/Toolkit/Schedule/EditSchedule.php +++ b/Toolkit/Schedule/EditSchedule.php @@ -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 = ''; $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); + } + } } diff --git a/Toolkit/Schedule/js/editSchedule.js b/Toolkit/Schedule/js/editSchedule.js index 2ff108e..f4c970d 100644 --- a/Toolkit/Schedule/js/editSchedule.js +++ b/Toolkit/Schedule/js/editSchedule.js @@ -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( '' ); } else if (data.dock == 2) { $('.bviTime.addTime[rel="'+data.departure_id+'"]').before( '' ); } @@ -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({ diff --git a/Toolkit/Schedule/templates/editSchedule.html b/Toolkit/Schedule/templates/editSchedule.html index ae17e6c..4d5394f 100644 --- a/Toolkit/Schedule/templates/editSchedule.html +++ b/Toolkit/Schedule/templates/editSchedule.html @@ -29,13 +29,6 @@ monthsHeight="monthsHeight" /> -
- -
{pageSelect:h} -
diff --git a/Toolkit/Template/Page/Toolbox.php b/Toolkit/Template/Page/Toolbox.php index b1e386a..0d1c4a5 100644 --- a/Toolkit/Template/Page/Toolbox.php +++ b/Toolkit/Template/Page/Toolbox.php @@ -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 index 24fc588..0000000 --- a/static/9.phtml +++ /dev/null @@ -1,4 +0,0 @@ -toHtml(); \ No newline at end of file -- 2.17.1