From 34e391f80e9512cd3069b64f659305b615f251d9 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 12 Jun 2014 10:28:02 -0400 Subject: [PATCH] work on schedule start adding in a page option for the schedule to output based on page --- Toolkit/Schedule/Database/application.sql | 1 + .../Database/tables/schedule_pages.sql | 6 + Toolkit/Schedule/EditSchedule.php | 162 ++++++++++++++---- Toolkit/Schedule/templates/editSchedule.html | 9 +- 4 files changed, 143 insertions(+), 35 deletions(-) create mode 100644 Toolkit/Schedule/Database/tables/schedule_pages.sql diff --git a/Toolkit/Schedule/Database/application.sql b/Toolkit/Schedule/Database/application.sql index 6c83eae..99bcb5a 100644 --- a/Toolkit/Schedule/Database/application.sql +++ b/Toolkit/Schedule/Database/application.sql @@ -6,3 +6,4 @@ GRANT ALL ON SCHEMA boats TO nobody; \i ./tables/departures.sql \i ./tables/departure_dates.sql \i ./tables/departure_times.sql +\i ./tables/schedule_pages.sql diff --git a/Toolkit/Schedule/Database/tables/schedule_pages.sql b/Toolkit/Schedule/Database/tables/schedule_pages.sql new file mode 100644 index 0000000..fbacb64 --- /dev/null +++ b/Toolkit/Schedule/Database/tables/schedule_pages.sql @@ -0,0 +1,6 @@ +CREATE TABLE boats.schedule_pages ( +schedule INTEGER NOT NULL, +page INTEGER NOT NULL +); + +GRANT ALL ON boats.schedules TO nobody; \ No newline at end of file diff --git a/Toolkit/Schedule/EditSchedule.php b/Toolkit/Schedule/EditSchedule.php index 24a8e08..b03c831 100644 --- a/Toolkit/Schedule/EditSchedule.php +++ b/Toolkit/Schedule/EditSchedule.php @@ -6,7 +6,7 @@ class Toolkit_Schedule_EditSchedule protected $timesChx = array(); protected $timesBvi = array(); protected $dates = array(); - + /** * For the Ajax call to add a departure set create the html and exit */ @@ -42,15 +42,15 @@ class Toolkit_Schedule_EditSchedule 'html' => $tpl->bufferedOutputObject($page) ); } - + /** * addSchedule - * + * * Creates a new empty schedule record * return the new id - * + * * @param type $registry - * @return type + * @return type */ public function addSchedule($registry) { @@ -69,10 +69,10 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + /** * add times to the timesBvi array - * + * * @param type $times array of times */ protected function addTimesBvi($times) @@ -83,10 +83,10 @@ class Toolkit_Schedule_EditSchedule } } } - + /** * add times to the timesChx array - * + * * @param type $times array of times */ protected function addTimesChx($times) @@ -97,7 +97,7 @@ class Toolkit_Schedule_EditSchedule } } } - + /** * get the departure times for dock 1 for a departureId * @@ -126,7 +126,7 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + /** * get the departure dates for a departureId * @@ -154,7 +154,7 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + /** * get the departure times for dock 2 for a departureId * @@ -183,10 +183,10 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + /** * get all departures for a schedule - * + * * @param type $registry Registry Obj * @param type $scheduleId schedule id * @return type array of data @@ -235,15 +235,15 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + public function getDeparturesForSchedules($registry, $scheduleId) { return $this->getDepartures($registry, $scheduleId); } - + /** * Get the schedule name from and scheduleId - * + * * @param PDO $dbh PDO obj * @param type $scheduleId id for schedule record * @return type string name of schedule @@ -263,15 +263,15 @@ class Toolkit_Schedule_EditSchedule Toolkit_Common::handleError($e); } } - + /** * removeDeparturesById - * + * * Removes the departures record by id - * + * * @param PDO $dbh PDO object * @param type $departureId id to delete - * @return type + * @return type */ public function removeDeparturesById(PDO $dbh, $departureId) { @@ -296,15 +296,15 @@ class Toolkit_Schedule_EditSchedule return false; } } - + /** * removeDepartureDatesById - * + * * Removes all the departure dates record by id - * + * * @param PDO $dbh PDO object * @param type $departureId id to delete - * @return type + * @return type */ public function removeDepartureDatesById(PDO $dbh, $departureId) { @@ -329,15 +329,15 @@ class Toolkit_Schedule_EditSchedule return false; } } - + /** * removeDepartureTimesById - * + * * Removes all the departure times record by id - * + * * @param PDO $dbh PDO object * @param type $departureId id to delete - * @return type + * @return type */ public function removeDepartureTimesById(PDO $dbh, $departureId) { @@ -362,17 +362,112 @@ class Toolkit_Schedule_EditSchedule return false; } } - + + + /** + * sort_by_parent + * + * @param mixed $data + * @access public + * @return void + */ + private function _sort_by_parent($data) + { + if (!is_array($data)) { + return false; + } + foreach($data as $key=>$value) { + $data_new[$value["parent"]][$value["id"]] = $value; + } + return $data_new; + } + + /** + * convertParent + * + * @param mixed $threads + * @param mixed $thread + * @access public + * @return void + */ + private function _convertParent($threads, $thread) + { + static $select,$count; + if (!$count) { + $count = 0; + } + $bgcolor[] = '#ccc'; + $bgcolor[] = '#ddd'; + if (is_array($thread)) { + foreach($thread as $parent=>$value) { + $color = $bgcolor[$count]; + $select[$value["id"]]["color"] = $color; + $select[$value["id"]]["category"] = $value["navigation_name"]; + $select[$value["id"]]["count"] = $count; + + if (isset($threads[$parent])) { + $count++; + $this->_convertParent($threads, $threads[$parent]); + } + } + } + $count--; + return $select; + } + + private function _parentSelect($catid = null) + { + // select catid portion + $qs = " + SELECT id,navigation_name,parent + FROM toolbox.pages + ORDER BY parent,pos"; + + $data = $this->dbh->query($qs)->fetchAll(PDO::FETCH_ASSOC); + $data1 = $this->_sort_by_parent($data); + $select = '"; + return $select; + } + + /** * Return the html for the edit form - * + * * @param type $registry Registry obj * @return type string HTML */ public function toHtml($registry) { $GLOBALS['styleSheets'][] - = GLM_APP_BASE_URL . + = GLM_APP_BASE_URL . 'libjs/jqueryui/1.8.13/development-bundle/themes/cupertino/jquery.ui.all.css'; $GLOBALS['bottomScripts'][] = GLM_APP_BASE_URL . @@ -382,7 +477,7 @@ class Toolkit_Schedule_EditSchedule = BASE_URL . 'css/colorPicker.css'; $GLOBALS['bottomScripts'][] = BASE_URL . 'libjs/jquery.colorPicker.js'; - + // javascript for the edit schedule page $GLOBALS['bottomScripts'][] = BASE_URL . 'Toolkit/Schedule/js/editSchedule.js'; @@ -400,6 +495,7 @@ class Toolkit_Schedule_EditSchedule if ($scheduleId) { $page->departures = $this->getDepartures($registry, $scheduleId); } + $page->pageSelect = $this->_parentSelect($image->getPage()); $page->colors = $this->colors; $page->timesChx = $this->timesChx; $page->timesBvi = $this->timesBvi; diff --git a/Toolkit/Schedule/templates/editSchedule.html b/Toolkit/Schedule/templates/editSchedule.html index d7e1bf8..ae17e6c 100644 --- a/Toolkit/Schedule/templates/editSchedule.html +++ b/Toolkit/Schedule/templates/editSchedule.html @@ -1,6 +1,6 @@