work on schedule
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 12 Jun 2014 14:28:02 +0000 (10:28 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 12 Jun 2014 14:28:02 +0000 (10:28 -0400)
start adding in a page option for the schedule
to output based on page

Toolkit/Schedule/Database/application.sql
Toolkit/Schedule/Database/tables/schedule_pages.sql [new file with mode: 0644]
Toolkit/Schedule/EditSchedule.php
Toolkit/Schedule/templates/editSchedule.html

index 6c83eae..99bcb5a 100644 (file)
@@ -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 (file)
index 0000000..fbacb64
--- /dev/null
@@ -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
index 24a8e08..b03c831 100644 (file)
@@ -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 = '<select name="page"><option value=""></option>';
+        $parts  = $this->_convertParent($data1, $data1[0]);
+        if (is_array($parts)) {
+            foreach($parts as $key => $value) {
+                if (isset($backcount) && $value['count'] <= $backcount) {
+                    unset($backcount);
+                }
+                if ($key == $id && $sel_name = "parent") {
+                    $backcount = $value['count'];
+                }
+
+                if (   (!isset($backcount)
+                        && ($value['count'] < (self::LEVELS_DEEP - 1))
+                    || $sel_name == "catid[]")
+                ) {
+                    $bkg     = $value["color"];
+                    $indent  = (int)$value["count"] * 10;
+                    $cc      = (int)$value["count"] * 2;
+                    $paddman = ($cc > 0) ? str_repeat("&nbsp;", $cc) : '';
+                    $select .= '<option value="' . $key . '"';
+                    if ($catid == $key) {
+                        $select .= ' selected';
+                    }
+                    $select .= ' style="background-color:' . $bkg . ';"';
+                    $select .= '>'.$paddman . $value["category"] . '</option>';
+                }
+            }
+        }
+        $select .= "</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;
index d7e1bf8..ae17e6c 100644 (file)
@@ -1,6 +1,6 @@
 <style>
     #loading {position: absolute; top: 50%; left: 50%;}
-    .row {clear:both;width: 850px;height:100px;border-top: 1px solid black;}
+    .row {clear:both;width: 650px;height:100px;border-top: 1px solid black;}
     .colorDiv {width:100px;float:left;}
     .departB {width:200px;float:left;}
     .departC {width:200px;float:left;}
@@ -33,7 +33,6 @@
     <label>
         Year for Schedule
     <select id="schedule_year" name="schedule_year">
-
     </select>
     </label>
 </div>
       <span class="ui-button-text">Save</span>
     </button>
 </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">
+      <span class="ui-button-text">Save</span>
+    </button>
+</div>
 <button id="addDepartureSet" rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
   <span class="ui-button-text">Add a new Departure Set</span>
 </button>