1: <?php
2: 3: 4: 5:
6:
7:
8: class componentListHandler extends apphandler {
9:
10: private $selection_list = array();
11: private $parent_list = array();
12: protected $dbhandler;
13: protected $id = null;
14: protected $component_list_arr = array();
15: protected $component_treelist_arr = array();
16:
17: public function __construct ($id = null){
18: $this->id = $id;
19: }
20:
21: public function destructDbInstances(){
22: unset($this->dbhandler);
23: unset($this->data_source);
24: foreach ($this->component_treelist_arr as &$cobj){
25: if ( isset($cobj[0]) && is_object($cobj[0])) {
26: $cobj[0]->destructDbInstances();
27: }
28: }
29: }
30:
31: public function setDataSource(&$db){
32: $this->dbhandler = new taskComponentDbHandler($db);
33: $this->data_source = $db;
34: }
35:
36: public function initialize(){
37: $this->id = null;
38: $this->component_list_arr = array();
39: $this->component_treelist_arr = array();
40: $this->selection_list = array();
41: $this->parent_list = array();
42: }
43:
44: public function addComponentObject($id){
45: $this->setComponentListId($id);
46: array_push($this->component_list_arr,$this->getComponentObj($id));
47: }
48:
49: public function &getComponentObj($id){
50: $cat_obj = new taskComponentHandler();
51: $cat_obj->setDataSource($this->data_source);
52: $cat_obj->initializeById($id);
53: return $cat_obj;
54: }
55:
56: public function getComponentListId(){
57: if (!isset($this->id) || !is_numeric($this->id)) $this->id = 0;
58: return $this->id;
59: }
60:
61: public function setComponentListId($d){
62: $this->id = $d;
63: }
64:
65: public function getComponentTreeList(){
66: return $this->component_treelist_arr;
67: }
68:
69: public function buildTreeList($id = null,$childid = null,$project_id = null){
70: $this->component_treelist_arr = array();
71: $this->setComponentTreeList($id,$childid,$project_id);
72: $this->setComponentListId($id);
73: }
74:
75: public function setComponentTreeList($id = null,$childid = null,$project_id = null){
76: if ($id == null) $id = $this->getComponentListId();
77:
78: if ($childid == null) $this->initialize();
79: array_unshift($this->component_treelist_arr,$this->getComponentListByParentId($id,$project_id));
80:
81: if (($parentid = $this->dbhandler->getComponentPrev($id)) != false ){
82: $this->setComponentListSelection($parentid,$id);
83: $this->setComponentListParentId($parentid,$id);
84: $this->setComponentTreeList($parentid,$id);
85: }else{
86: $this->setComponentListSelection(0,$id);
87: $this->setComponentListParentId(0,$id);
88: if ($id > 0) array_unshift($this->component_treelist_arr,$this->getComponentListByParentId(0));
89: }
90: }
91:
92: public function &getComponentListByParentId($id,$project_id = false){
93: $component_list_arr = array();
94: if (!isset($id) || !is_numeric($id) ) $id = 0;
95: $cat_id_list_arr = $this->dbhandler->getComponentListByParent($id,$project_id);
96: if (!is_array($cat_id_list_arr)) return array();
97: foreach ($cat_id_list_arr as $child_id){
98: $cobj = $this->getComponentObj($child_id[0]);
99: array_push($component_list_arr,$this->getComponentObj($child_id[0]));
100:
101: }
102: return $component_list_arr;
103: }
104:
105: public function getCurrentComponentList(){
106: if (!is_array($this->component_list_arr)) return false;
107: $cat_list_arr = array();
108: $i = 0;
109: foreach ($this->component_list_arr as $catobj){
110: $cat_list_arr[$i][0] = $catobj->getComponentId();
111: $cat_list_arr[$i][1] = $catobj->getComponentName();
112: $cat_list_arr[$i][1] = $catobj->getComponentDesc();
113: $i++;
114: }
115: return $cat_list_arr;
116: }
117:
118: public function getCurrentComponentUiList(){
119: $retarr = array();
120: if (!is_array($this->component_list_arr)) return false;
121: $cat_list_arr = array();
122: foreach ($this->component_list_arr as $catobj){
123: $cat_list_arr[$catobj->getComponentId()] = $catobj->getComponentName();
124: }
125: return $cat_list_arr;
126: }
127:
128: public function setComponentListSelection($parentid,$id){
129: $this->selection_list[$parentid] = $id;
130: }
131:
132: public function getComponentListSelection($parentid){
133: if (isset($this->selection_list[$parentid]) ) return $this->selection_list[$parentid];
134: return null;
135: }
136:
137: public function setComponentListParentId($parentid,$id){
138: $this->parent_list[$id] = $parentid;
139: }
140:
141: public function getComponentListParentId($id){
142: if (isset($this->parent_list[$id]) ) return $this->parent_list[$id];
143: return null;
144: }
145:
146: public function getComponentListById($id){
147: return $this->dbhandler->getComponentTreeById($id);
148: }
149:
150: }
151: ?>
152: