DBnested.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: DBnested.php,v 1.8 2003/02/26 18:45:50 cain Exp $
  20. require_once 'Tree/Dynamic/DBnested.php';
  21. /**
  22. *
  23. *
  24. * @access public
  25. * @author
  26. * @package Tree
  27. */
  28. class Tree_Memory_DBnested extends Tree_Dynamic_DBnested
  29. {
  30. /**
  31. * retreive all the data from the db and prepare the data so the structure can
  32. * be built in the parent class
  33. *
  34. * @version 2002/04/20
  35. * @access public
  36. * @author Wolfram Kriesing <wolfram@kriesing.de>
  37. * @param array the result of a query which retreives (all) the tree data from a DB
  38. * @return array the result
  39. */
  40. function setup($res=null)
  41. {
  42. if ($res==null) {
  43. //
  44. $whereAddOn = '';
  45. if ($this->options['whereAddOn']) {
  46. $whereAddOn = 'WHERE '.$this->getOption('whereAddOn');
  47. }
  48. //
  49. $orderBy = 'left';
  50. if ($order=$this->getOption('order')) {
  51. $orderBy = $order;
  52. }
  53. // build the query this way, that the root, which has no parent (parentId=0) is first
  54. $query = sprintf( 'SELECT * FROM %s %s ORDER BY %s',
  55. $this->table,
  56. $whereAddOn,
  57. $this->_getColName($orderBy) // sort by the left-column, so we have the data sorted as it is supposed to be :-)
  58. );
  59. if (DB::isError( $res = $this->dbh->getAll($query))) {
  60. return $this->_throwError($res->getMessage(),__LINE__);
  61. }
  62. }
  63. return $this->_prepareResults( $res );
  64. }
  65. }
  66. ?>