Subversion Repositories phpLibraryV2

Rev

Rev 10 | Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 29
Line 26... Line 26...
26
class DBMenu extends DBHierarchicalHash {
26
class DBMenu extends DBHierarchicalHash {
27
   
27
   
28
   protected  $captionName = 'caption'; // column name for display string in database
28
   protected  $captionName = 'caption'; // column name for display string in database
29
   protected  $urlName = 'url';         // column name for URL field in database
29
   protected  $urlName = 'url';         // column name for URL field in database
30
   // string which is searched/replaced for a menu item that has a URL (<url> and <caption> are replaced)
30
   // string which is searched/replaced for a menu item that has a URL (<url> and <caption> are replaced)
31
   protected  $menuItemString = '<li class="menu_item_<level>"><a href="<url>"><caption></a></li>';
31
   protected  $menuItemString = "<li class='menu_item_<level>'><a href='<url>'><caption></a></li>\n";
32
   // string which is searched/replaced for a menu item that has no URL (<caption> is replaced)
32
   // string which is searched/replaced for a menu item that has no URL (<caption> is replaced)
33
   protected  $menuHeaderString = '<li class="menu_header_<level>"><caption></li>';
33
   protected  $menuHeaderString = "<li class='menu_header_<level>'><caption></li>\n";
34
   // string which is placed around <menublock>, ie this goes around a menu/submenu. <level> can be used to determine
34
   // string which is placed around <menublock>, ie this goes around a menu/submenu. <level> can be used to determine
35
   // which level (zero based) we are in the menu (level = 0 is top menu)
35
   // which level (zero based) we are in the menu (level = 0 is top menu)
36
   protected  $menuBlockString = '<ul class="menu"><menublock></ul>';
36
   protected  $menuBlockString = "<ul class='menu'><menublock></ul>\n";
37
   
37
   
38
   // simply pass fields on to DBHierarchicalHash so it can load and parse the table
38
   // simply pass fields on to DBHierarchicalHash so it can load and parse the table
39
   public function __construct ($tableName = 'menus', $idFieldName = 'id', $parentFieldName = 'parent_id' ) {
39
   public function __construct ( $dbConnect, $tableName = 'menus', $idFieldName = 'id', $parentFieldName = 'parent_id' ) {
40
      parent::__construct($tableName, $idFieldName, $parentFieldName );
40
      parent::__construct($dbConnect, $tableName, $idFieldName, $parentFieldName );
41
   }
41
   }
42
   
42
   
43
   // simple setter/getter for the caption column name in table
43
   // simple setter/getter for the caption column name in table
44
   public function captionColumnName ( $newValue = '' ) {
44
   public function captionColumnName ( $newValue = '' ) {
45
      if ($newValue) {
45
      if ($newValue) {
Line 79... Line 79...
79
      }
79
      }
80
      return $this->menuBlockString;
80
      return $this->menuBlockString;
81
   }
81
   }
82
   
82
   
83
   // just an entry point to displayMenu, with root of inputRecords and level 0
83
   // just an entry point to displayMenu, with root of inputRecords and level 0
84
   function DBMenu2String ( $rootDir = '' ) {
84
   function DBMenu2String ( $rootDir = '', $toAdd = null ) {
-
 
85
      foreach ( $toAdd as $additional ) {
-
 
86
         $this->inputRecords[] = $additional;
-
 
87
      }
-
 
88
      //print "<pre>\n" . print_r( $this, true) . "</pre>"; die;
85
      return $this->htmlMenu( $this->inputRecords, 0, $rootDir );
89
      return $this->htmlMenu( $this->inputRecords, 0, $rootDir, $toAdd );
86
   }
90
   }
87
   
91
   
88
   // function takes a menu level and creates an HTML Menu items from it. If a node has children, will
92
   // function takes a menu level and creates an HTML Menu items from it. If a node has children, will
89
   // recursively call itself for each child node.
93
   // recursively call itself for each child node.
90
   private function htmlMenu ($menu, $level=0, $rootDir = '' ) {
94
   private function htmlMenu ($menu, $level=0, $rootDir = '' ) {
Line 97... Line 101...
97
         }
101
         }
98
         if ( isset($value['children'])) { // if it has children, process them
102
         if ( isset($value['children'])) { // if it has children, process them
99
            $result .=  $this->htmlMenu($value['children'], $level+1, $rootDir);
103
            $result .=  $this->htmlMenu($value['children'], $level+1, $rootDir);
100
         }
104
         }
101
      }
105
      }
-
 
106
      /*
-
 
107
      // if they want anything added, do it here.
-
 
108
      foreach ( $toAdd as $key => $value ) {
-
 
109
         $result .= insertValuesIntoQuery( $this->menuItemString, array( 'url' => $value, 'caption' =>$key ) );
-
 
110
      }
-
 
111
      */
102
      // place the block code around the menu, and return the result
112
      // place the block code around the menu, and return the result
103
      return insertValuesIntoQuery( $this->menuBlockString, array( 'menublock' => $result, 'level' => $level ) );
113
      return insertValuesIntoQuery( $this->menuBlockString, array( 'menublock' => $result, 'level' => $level ) );
104
   }
114
   }
105
   
115
   
106
} // class DBMenu
116
} // class DBMenu