00001 <?PHP
00017 include_once(OPENBIZ_BIN.'data/BizDataObj.php');
00018
00027 class BizDataTree extends BizDataObj
00028 {
00029 protected $m_RootNodes;
00034 protected $m_Depth;
00035
00040 protected $m_globalSearchRule;
00041
00047 public function fetchTree($rootSearchRule, $depth, $globalSearchRule="")
00048 {
00049 $this->m_Depth = $depth;
00050 $this->m_globalSearchRule = $globalSearchRule;
00051
00052
00053 $searchRule = "(" . $rootSearchRule . ")";
00054 if ($globalSearchRule!="")
00055 $searchRule .= " AND (" . $globalSearchRule . ")";
00056 $recordList = $this->directFetch($searchRule);
00057 if (!$recordList)
00058 {
00059 $this->m_RootNodes = array();
00060 return;
00061 }
00062 foreach ($recordList as $rec)
00063 {
00064 $this->m_RootNodes[] = new NodeRecord($rec);
00065 }
00066 if ($this->m_Depth <= 1)
00067 return $this->m_RootNodes;
00068 if(is_array($this->m_RootNodes)){
00069 foreach ($this->m_RootNodes as $node)
00070 {
00071 $this->_getChildrenNodes($node, 1);
00072 }
00073 }
00074 return $this->m_RootNodes;
00075 }
00076
00084 public function fetchNodePath($nodeSearchRule, &$pathArray)
00085 {
00086 $recordList = $this->directFetch($nodeSearchRule);
00087 if(count($recordList)>=1)
00088 {
00089
00090 if($recordList[0]['PId']!='0')
00091 {
00092 $searchRule = "[Id]='".$recordList[0]['PId']."'";
00093 $this->fetchNodePath($searchRule, $pathArray);
00094 }
00095 $nodes = new NodeRecord($recordList[0]);
00096 array_push($pathArray,$nodes);
00097 return $pathArray;
00098 }
00099 }
00100
00106 private function _getChildrenNodes(&$node, $depth)
00107 {
00108 $pid = $node->m_Id;
00109
00110 $searchRule = "[PId]='$pid'";
00111 if ($this->m_globalSearchRule!="")
00112 $searchRule .= " AND " . $this->m_globalSearchRule;
00113 $recordList = $this->directFetch($searchRule);
00114
00115 foreach ($recordList as $rec)
00116 {
00117 $node->m_ChildNodes[] = new NodeRecord($rec);
00118 }
00119
00120
00121 if ($node->m_ChildNodes == null)
00122 return;
00123
00124 $depth++;
00125
00126 if ($depth >= $this->m_Depth)
00127 return;
00128 else
00129 {
00130 foreach ($node->m_ChildNodes as $node_c)
00131 {
00132 $this->_getChildrenNodes($node_c, $depth);
00133 }
00134 }
00135 }
00136 }
00137
00149 class NodeRecord
00150 {
00151 public $m_Id = "";
00152 public $m_PId = "";
00153 public $m_ChildNodes = null;
00154 public $m_Record;
00155
00162 function __construct($rec)
00163 {
00164 $this->m_Id = $rec['Id'];
00165 $this->m_PId = $rec['PId'];
00166 $this->m_Record = $rec;
00167 }
00168 }
00169
00170
00171 ?>