From 0a5060f47f976d4c6a5e3b9d7b4d7930e8127668 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 20 Jun 2014 11:10:56 -0400 Subject: [PATCH] update schedule app assigning pages to schedule and output schedule without having a static page created for it. --- Toolkit/Schedule/DepartureCalendar.php | 15 ++++-- Toolkit/Schedule/EditController.php | 50 ++++++++++++++++++-- Toolkit/Schedule/EditSchedule.php | 36 ++++++++++++-- Toolkit/Schedule/js/editSchedule.js | 17 +++++++ Toolkit/Schedule/templates/editSchedule.html | 9 +--- Toolkit/Template/Page/Toolbox.php | 4 ++ 6 files changed, 108 insertions(+), 23 deletions(-) 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..6d73926 100644 --- a/Toolkit/Schedule/js/editSchedule.js +++ b/Toolkit/Schedule/js/editSchedule.js @@ -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]); 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; } -- 2.17.1