Line 40... |
Line 40... |
40 |
protected $keyField; // name of the primary id field in table
|
40 |
protected $keyField; // name of the primary id field in table
|
41 |
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
|
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
|
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
|
43 |
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
|
44 |
protected $recordList; // if this is an array, will restrict records read to only these indicies
|
- |
|
45 |
protected $query; // the query used to get the records
|
45 |
|
46 |
|
46 |
public function __construct( $tableName, $keyField = 'id', $parentFieldName = 'parent_id', $rootNodeValue = 0, $recordList = null ) {
|
47 |
public function __construct( $tableName, $keyField = 'id', $parentFieldName = 'parent_id', $rootNodeValue = 0, $recordList = null ) {
|
47 |
// standard variable load
|
48 |
// standard variable load
|
48 |
$this->tableName = $tableName;
|
49 |
$this->tableName = $tableName;
|
49 |
$this->keyField = $keyField;
|
50 |
$this->keyField = $keyField;
|
Line 91... |
Line 92... |
91 |
additional columns will simply be added to the array pointed by it.
|
92 |
additional columns will simply be added to the array pointed by it.
|
92 |
An additional entry in the table will be created with $this->rootNodeValue as its index, to allow root level
|
93 |
An additional entry in the table will be created with $this->rootNodeValue as its index, to allow root level
|
93 |
items to have a parent.
|
94 |
items to have a parent.
|
94 |
*/
|
95 |
*/
|
95 |
private function loadData ( ) {
|
96 |
private function loadData ( ) {
|
96 |
$query = "select * from $this->tableName";
|
97 |
$this->query = "select * from $this->tableName";
|
97 |
if ( ! is_null( $this->recordList ) )
|
98 |
if ( ! is_null( $this->recordList ) )
|
98 |
$query .= " where $this->keyField not in (" . implode( ',',$this->recordList ) . ')';
|
99 |
$this->query .= " where $this->keyField not in (" . implode( ',',$this->recordList ) . ')';
|
99 |
$inputRows = queryDatabaseExtended( $query ); // get everything from the table
|
100 |
$inputRows = queryDatabaseExtended( $this->query ); // get everything from the table
|
100 |
$inputRows = $inputRows['data']; // we only care about the data
|
101 |
$inputRows = $inputRows['data']; // we only care about the data
|
101 |
$this->inputRecords = array(); // initialize inputRecords to empty
|
102 |
$this->inputRecords = array(); // initialize inputRecords to empty
|
102 |
// main loop, will read the query results in one row at a time
|
103 |
// main loop, will read the query results in one row at a time
|
103 |
foreach ( $inputRows as $thisRow ) {
|
104 |
foreach ( $inputRows as $thisRow ) {
|
104 |
foreach ($thisRow as $key => $values) { // copy each value
|
105 |
foreach ($thisRow as $key => $values) { // copy each value
|