Subversion Repositories php_library

Rev

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

Rev 47 Rev 48
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
-
 
3
/*
-
 
4
 * 20190510 - RWR
-
 
5
 * Modified to allow us to pass in a list of acceptable keys
-
 
6
 * This allows us to restrict access to menu items
-
 
7
 */
-
 
8
 
-
 
9
 
3
if ( isset($TESTING) ) {
10
if ( isset($TESTING) ) {
4
   mysql_connect("localhost", "test", "test") or die(mysql_error());
11
   mysql_connect("localhost", "test", "test") or die(mysql_error());
5
   mysql_select_db("camp") or die(mysql_error());
12
   mysql_select_db("camp") or die(mysql_error());
6
   ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/home/rodolico/Desktop/wip/common-cgi' );
13
   ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/home/rodolico/Desktop/wip/common-cgi' );
7
}
14
}
Line 32... Line 39...
32
   protected $tableName; // table name that data will be read from
39
   protected $tableName; // table name that data will be read from
33
   protected $keyField;  // name of the primary id field in table
40
   protected $keyField;  // name of the primary id field in table
34
   protected $parentFieldName; // name of the field used to point to the parent of the current row
41
   protected $parentFieldName; // name of the field used to point to the parent of the current row
35
   protected $rootNodevalue; // the value (default 0) of the indicator that a row has no parent. THIS MUST NOT EXIST in the id column of the table
42
   protected $rootNodevalue; // the value (default 0) of the indicator that a row has no parent. THIS MUST NOT EXIST in the id column of the table
36
   protected $inputRecords; // storage for the records read in.
43
   protected $inputRecords; // storage for the records read in.
-
 
44
   protected $recordList; // if this is an array, will restrict records read to only these indicies
37
   
45
   
38
   public function __construct( $tableName, $keyField = 'id', $parentFieldName = 'parent_id', $rootNodeValue = 0 ) {
46
   public function __construct( $tableName, $keyField = 'id', $parentFieldName = 'parent_id', $rootNodeValue = 0, $recordList = null ) {
39
      // standard variable load
47
      // standard variable load
40
      $this->tableName = $tableName;
48
      $this->tableName = $tableName;
41
      $this->keyField = $keyField;
49
      $this->keyField = $keyField;
42
      $this->parentFieldName = $parentFieldName;
50
      $this->parentFieldName = $parentFieldName;
43
      $this->rootNodevalue = $rootNodeValue;
51
      $this->rootNodevalue = $rootNodeValue;
-
 
52
      $this->recordList = $recordList;
44
      // load the data from the database into memory
53
      // load the data from the database into memory
45
      // upon completion, will have data in a single hash of hashes (not hiearchy)
54
      // upon completion, will have data in a single hash of hashes (not hiearchy)
46
      // will also create an emtpy entry for "element 0"
55
      // will also create an emtpy entry for "element 0"
47
      $this->loadData();
56
      $this->loadData();
48
      // find the children of each node
57
      // find the children of each node
Line 82... Line 91...
82
      additional columns will simply be added to the array pointed by it.
91
      additional columns will simply be added to the array pointed by it.
83
      An additional entry in the table will be created with $this->rootNodeValue as its index, to allow root level
92
      An additional entry in the table will be created with $this->rootNodeValue as its index, to allow root level
84
      items to have a parent.
93
      items to have a parent.
85
   */
94
   */
86
   private function loadData ( ) {
95
   private function loadData ( ) {
-
 
96
      $query = "select * from $this->tableName";
-
 
97
      if ( ! isnull( $this->recordList ) )
-
 
98
         $query .= " where $this->keyField not in (" . implode( ',',$this->recordList ) . ')';
87
      $inputRows = queryDatabaseExtended( "select * from $this->tableName" ); // get everything from the table
99
      $inputRows = queryDatabaseExtended( $query ); // get everything from the table
88
      $inputRows = $inputRows['data']; // we only care about the data
100
      $inputRows = $inputRows['data']; // we only care about the data
89
      $this->inputRecords = array(); // initialize inputRecords to empty
101
      $this->inputRecords = array(); // initialize inputRecords to empty
90
      // main loop, will read the query results in one row at a time
102
      // main loop, will read the query results in one row at a time
91
      foreach ( $inputRows as $thisRow ) {
103
      foreach ( $inputRows as $thisRow ) {
92
         foreach ($thisRow as $key => $values) { // copy each value
104
         foreach ($thisRow as $key => $values) { // copy each value
Line 159... Line 171...
159
   // string which is placed around <menublock>, ie this goes around a menu/submenu. <level> can be used to determine
171
   // string which is placed around <menublock>, ie this goes around a menu/submenu. <level> can be used to determine
160
   // which level (zero based) we are in the menu (level = 0 is top menu)
172
   // which level (zero based) we are in the menu (level = 0 is top menu)
161
   protected  $menuBlockString = '<ul class="menu"><menublock></ul>';
173
   protected  $menuBlockString = '<ul class="menu"><menublock></ul>';
162
   
174
   
163
   // simply pass fields on to DBHierarchicalHash so it can load and parse the table
175
   // simply pass fields on to DBHierarchicalHash so it can load and parse the table
164
   public function __construct ($tableName = 'menu', $idFieldName = 'id', $parentFieldName = 'parent_id' ) {
176
   public function __construct ($tableName = 'menu', $idFieldName = 'id', $parentFieldName = 'parent_id', $recordList = null ) {
165
      parent::__construct($tableName, $idFieldName, $parentFieldName );
177
      parent::__construct($tableName, $idFieldName, $parentFieldName, $recordList );
166
   }
178
   }
167
   
179
   
168
   // simple setter/getter for the caption column name in table
180
   // simple setter/getter for the caption column name in table
169
   public function captionColumnName ( $newValue = '' ) {
181
   public function captionColumnName ( $newValue = '' ) {
170
      if ($newValue) {
182
      if ($newValue) {
Line 237... Line 249...
237
//print $menu->DBMenu2String();
249
//print $menu->DBMenu2String();
238
//print "Menu Structure:\n"; print_r($menu);
250
//print "Menu Structure:\n"; print_r($menu);
239
 
251
 
240
/* end of block for testing */
252
/* end of block for testing */
241
 
253
 
242
?>
-
 
243
 
254
?>
-
 
255