1: <?php
2: 3: 4: 5:
6:
7:
8: class taskComponentHandler extends baseModel {
9:
10: protected $dbhandler;
11: protected $default_version;
12: protected $task_component_versions_arr = array();
13: protected $project_name;
14:
15: public function __construct ($oid = null){
16: $this->initColumnDefinitions("task_component",null);
17: $this->initColumnDefinitions("task_component","view");
18: $this->instance = $this;
19: $this->createObjInstance(array("viewhandler","taskComponentViewHandler",$this->instance));
20: $this->createObjInstance(array("sideviewhandler","appSideViewHandler",$this->instance));
21:
22: $this->viewhandler->setHeaderIdent("project_area",null);
23: parent::__construct();
24: }
25:
26: public function &getDataObject($ident){
27: switch($ident){
28: default:
29: return $this->instance;
30: break;
31: }
32: }
33:
34: public function destructDbInstances(){
35: unset($this->dbhandler);
36: }
37:
38: public function setDataSource(&$db){
39: $column_types = $this->getColumnTypesAll();
40: $this->dbhandler = new taskComponentDbHandler($db,$column_types,$this->column_method_pointers);
41: }
42:
43: public function &getDbHandler(){
44: return $this->dbhandler;
45: }
46:
47: public function initialize(){
48: $project_id = $this->getTaskComponentProjectId();
49: $this->initColumnTypes();
50: $this->task_component_versions_arr = array();
51: $this->setTaskComponentProjectId($project_id);
52: }
53:
54: public function initializeById($id){
55: $this->setColumnMethodTypes($id);
56: $this->project_name = $this->dbhandler->getTaskComponentProjectName($this->getTaskComponentProjectId());
57: $this->task_component_versions_arr = $this->dbhandler->getTaskComponentVersions($this->getTaskComponentId());
58: $this->viewhandler->setHeaderIdent("project_area","{$this->getTaskComponentName()}");
59: }
60:
61: public function syncStorage($project_id = null){
62: if ($this->getTaskComponentId())
63: $this->syncStorageUpdate($project_id);
64: else
65: $this->syncStorageInsert($project_id);
66:
67: $this->viewhandler->setHeaderIdent("project_area","{$this->getTaskComponentName()}");
68: }
69:
70: public function syncStorageUpdate($project_id){
71: if (!($this->getTaskComponentName())) throw new Exception("component_name_undefined");
72:
73: try {
74: $this->dbhandler->db->transactionStart();
75: $this->dbhandler->updateData($this->getTaskComponentId(),$this->column_types);
76: }catch (Exception $e){
77: $this->dbhandler->db->transactionRollback();
78: throw new Exception ($e->getMessage());
79: }
80: $this->dbhandler->db->transactionEnd();
81: }
82:
83: public function syncStorageInsert($project_id){
84: if (!($this->getTaskComponentName())) throw new Exception("component_name_undefined");
85: if (!intval($project_id)) throw new Exception("project_not_selected");
86: if ($this->dbhandler->getTaskComponentIdByName($project_id,$this->getTaskComponentName())) throw new Exception("component_exists");
87: try {
88: $this->dbhandler->db->transactionStart();
89: $this->setTaskComponentProjectId($project_id);
90: $this->setTaskComponentId($this->dbhandler->insertData($this->column_types));
91: $this->addComponentVersion('default');
92: }catch (Exception $e){
93: $this->setTaskComponentProjectId(null);
94: $this->dbhandler->db->transactionRollback();
95: throw new Exception ($e->getMessage());
96: }
97: $this->dbhandler->db->transactionEnd();
98: }
99:
100: public function syncStorageRemove(){
101:
102: $childlist = array();
103: $productlist = array();
104: if (!($this->getTaskComponentId())) throw new Exception('del_fail_component_not_selected');
105: if (!($this->getTaskComponentProjectId())) throw new Exception("project_not_selected");
106: $childlist = $this->dbhandler->getComponentListByParent($this->getTaskComponentId()) ;
107: if ( isset($childlist[0][0]) && is_numeric($childlist[0][0])) throw new Exception('del_fail_component_in_use');
108: $productlist = $this->dbhandler->getTaskComponentProductList($this->getTaskComponentId()) ;
109: if ( isset($productlist[0][0]) && is_numeric($productlist[0][0])) throw new Exception('del_fail_component_in_use');
110: try {
111: $this->dbhandler->db->transactionStart();
112: $this->dbhandler->deleteComponentData($this->getTaskComponentId());
113:
114: }catch (Exception $e){
115: $this->dbhandler->db->transactionRollback();
116: return false;
117: }
118: $this->initialize();
119: $this->dbhandler->db->transactionEnd();
120: }
121:
122: public function setDefaultComponent($project_id){
123: try {
124: $this->initialize();
125: $this->setTaskComponentName('default');
126: $this->setTaskComponentProjectId($project_id);
127: $this->syncStorageInsert($project_id);
128: $this->dbhandler->updateTaskComponentVersionDefault($project_id,$this->getTaskComponentId(),$this->getDefaultComponentVersionId());
129: $this->dbhandler->updateTaskComponentVersionEnabledStatus($this->getDefaultComponentVersionId(),true);
130: }catch(Exception $e){
131: throw new Exception($e->getMessage());
132: }
133: }
134:
135: public function updateTaskComponentVersionDefault($project_id,$component_id,$component_version_id){
136: if ($project_id)
137: $this->dbhandler->updateTaskComponentVersionDefault($project_id,$component_id,$component_version_id);
138: }
139:
140: private function setDefaultComponentVersionId($id){
141: $this->default_version = $id;
142: }
143:
144: private function getDefaultComponentVersionId(){
145: return $this->default_version;
146: }
147:
148: public function transferComponentTasks($com_source_id,$com_source_version_id,$com_target_id,$com_target_version_id){
149: global $STATUS_LIST;
150: $this->dbhandler->transferOpenTasks($com_source_id,$com_source_version_id,$com_target_id,$com_target_version_id,$STATUS_LIST['PROJECT_TASK']['COMPLETE'][0]);
151: }
152:
153: public function addComponentVersion($version,$default = 0){
154: if (empty($version))
155: throw new Exception('component_name_empty');
156:
157: if ($this->dbhandler->checkComponentVersionExistence($version,$this->getTaskComponentId()))
158: throw new Exception('component_version_exists');
159:
160: $this->dbhandler->addTaskComponentVersion($version,$this->getTaskComponentId());
161: $this->task_component_versions_arr = $this->dbhandler->getTaskComponentVersions($this->getTaskComponentId());
162:
163: $this->dbhandler->updateTaskComponentVersionDefault($this->getTaskComponentProjectId(),$this->getTaskComponentId(),$this->task_component_versions_arr[0][2]);
164: $this->setDefaultComponentVersionId($this->task_component_versions_arr[0][2]);
165: }
166:
167: public function deleteComponentVersion($version_id){
168: $this->dbhandler->deleteTaskComponentVersion($version_id);
169: $this->task_component_versions_arr = $this->dbhandler->getTaskComponentVersions($this->getTaskComponentId());
170: }
171:
172: public function updateTaskComponentVersionEnabledStatus($version_id,$enabled){
173: $this->dbhandler->updateTaskComponentVersionEnabledStatus($version_id,$enabled);
174: }
175:
176: public function getComponentVersions(){
177: return $this->task_component_versions_arr;
178: }
179:
180: public function setProjectData($id){
181: $this->setTaskComponentProjectId(intval($id));
182: $this->project_name = $this->dbhandler->getTaskComponentProjectName($id);
183: }
184:
185: public function getComponentListByProject($key){
186: return $this->dbhandler->getTaskComponentListByProject($key);
187: }
188:
189: public function getComponentProjectName(){
190: return $this->project_name;
191: }
192:
193: public function getComponentIdByNameVer($name,$version){
194: return $this->dbhandler->getComponentIdByNameVer($name,$version);
195: }
196:
197: public function getComponentNameVerById($version_id){
198: return $this->dbhandler->getComponentNameVerById($version_id);
199: }
200:
201: }
202: ?>
203: