| 16 |
// | Authors: | |
// | Authors: | |
| 17 |
// +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| 18 |
// |
// |
|
// Id: DBnested.php,v 1.6 2003/01/04 11:56:28 mj Exp |
|
| 19 |
// $Id$ |
// $Id$ |
| 20 |
|
|
| 21 |
require_once('Tree/Dynamic/DBnested.php'); |
require_once 'Tree/Dynamic/DBnested.php'; |
| 22 |
|
|
| 23 |
/** |
/** |
| 24 |
* |
* |
| 37 |
* @version 2002/04/20 |
* @version 2002/04/20 |
| 38 |
* @access public |
* @access public |
| 39 |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
| 40 |
|
* @param array the result of a query which retreives (all) the tree data from a DB |
| 41 |
* @return array the result |
* @return array the result |
| 42 |
*/ |
*/ |
| 43 |
function setup() |
function setup($res=null) |
| 44 |
{ |
{ |
| 45 |
// |
if ($res==null) { |
| 46 |
$whereAddOn = ''; |
// |
| 47 |
if( $this->options['whereAddOn'] ) |
$whereAddOn = ''; |
| 48 |
{ |
if ($this->options['whereAddOn']) { |
| 49 |
$whereAddOn = 'WHERE '.$this->getOption('whereAddOn'); |
$whereAddOn = 'WHERE '.$this->getOption('whereAddOn'); |
| 50 |
} |
} |
| 51 |
|
|
| 52 |
// |
// |
| 53 |
$orderBy = 'left'; |
$orderBy = 'left'; |
| 54 |
if( $order=$this->getOption('order') ) |
if ($order=$this->getOption('order')) { |
| 55 |
{ |
$orderBy = $order; |
| 56 |
$orderBy = $order; |
} |
| 57 |
} |
|
| 58 |
|
// build the query this way, that the root, which has no parent (parentId=0) is first |
| 59 |
// build the query this way, that the root, which has no parent (parentId=0) is first |
$query = sprintf( 'SELECT * FROM %s %s ORDER BY %s', |
| 60 |
$query = sprintf( 'SELECT * FROM %s %s ORDER BY %s', |
$this->table, |
| 61 |
$this->table, |
$whereAddOn, |
| 62 |
$whereAddOn, |
$this->_getColName($orderBy) // sort by the left-column, so we have the data sorted as it is supposed to be :-) |
| 63 |
$this->_getColName($orderBy) // sort by the left-column, so we have the data sorted as it is supposed to be :-) |
); |
| 64 |
); |
if (DB::isError( $res = $this->dbh->getAll($query))) { |
| 65 |
if( DB::isError( $res = $this->dbh->getAll( $query ) ) ) |
return $this->_throwError($res->getMessage(),__LINE__); |
| 66 |
{ |
} |
|
return $this->_throwError($res->getMessage(),__LINE__); |
|
| 67 |
} |
} |
| 68 |
|
|
| 69 |
return $this->_prepareResults( $res ); |
return $this->_prepareResults( $res ); |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
} |
} |
| 73 |
|
|
| 74 |
|
?> |