1: <?php
2: 3: 4: 5:
6:
7:
8: class taskCommentHandler {
9:
10:
11: protected $id;
12: protected ;
13: protected $created;
14: protected $user_id;
15: protected $user_name;
16: protected $task_id;
17:
18: private $dbhandler;
19:
20: public function __construct ($id = null,$created = null,$comment = null,$user_id = null,$task_id = null,$user_name = null){
21: $this->initialize();
22: $this->id = $id;
23: $this->comment = $comment;
24: $this->created = $created;
25: $this->user_id = $user_id;
26: $this->task_id = $task_id;
27: $this->user_name = $user_name;
28: }
29:
30: public function destructDbInstances(){
31: unset($this->dbhandler);
32: }
33:
34: public function setDataSource(&$db){
35: $this->dbhandler = new projectTaskDbHandler($db,$null = null,$null = null);
36: }
37:
38: public function &getDataSource(){
39: return $this->dbhandler;
40: }
41:
42:
43: public function initialize(){
44: $this->id = null;
45: $this->comment = null;
46: $this->created = null;
47: $this->user_id = null;
48: $this->user_name = null;
49: $this->task_id = null;
50:
51: }
52:
53: public function initializeById($id){
54: if (is_object($this->dbhandler) && is_numeric($id)){
55: $this->id = $id;
56: $this->comment = $this->dbhandler->getTaskCommentText();
57: $this->created = $this->dbhandler->getTaskCommentCreated();
58: $this->user_id = $this->dbhandler->getTaskCommentUserId();
59: $this->user_name = $this->dbhandler->getTaskCommentUserName($this->user_id);
60: $this->task_id = $this->dbhandler->getTaskCommentTaskId();
61: }
62: }
63:
64: public function syncStorage(){
65: if (!$this->getEquipmentId())
66: $this->syncStorageUpdate();
67: else
68: $this->syncStorageInsert();
69: }
70:
71: public function syncStorageUpdate($trans = true){
72:
73: try {
74: if ($trans == true) $this->dbhandler->db->transactionStart();
75: $this->dbhandler->updateTaskCommentData(
76: $this->id,
77: $this->getTaskCommentText(),
78: $this->getTaskCommentCreated(),
79: $this->getTaskCommentUserId(),
80: $this->getTaskCommentTaskId());
81: }catch (Exception $e){
82: if ($trans == true) $this->dbhandler->db->transactionRollback();
83: return false;
84: }
85: if ($trans == true) $this->dbhandler->db->transactionEnd();
86: return true;
87: }
88:
89: public function syncStorageInsert($trans = true){
90:
91: try {
92: if ($trans == true) $this->dbhandler->db->transactionStart();
93: $this->id = $this->dbhandler->insertTaskCommentData(
94: $this->getTaskCommentText(),
95: $this->getTaskCommentCreated(),
96: $this->getTaskCommentUserId(),
97: $this->getTaskCommentTaskId());
98: }catch (Exception $e){
99: if ($trans == true) $this->dbhandler->db->transactionRollback();
100: return false;
101: }
102: if ($trans == true) $this->dbhandler->db->transactionEnd();
103: return true;
104: }
105:
106: public function syncStorageRemove($trans = true){
107:
108: try {
109: if ($trans == true) $this->dbhandler->db->transactionStart();
110: $this->dbhandler->deleteTaskCommentData($this->getTaskCommentId());
111: }catch (Exception $e){
112: $this->dbhandler->db->transactionRollback();
113: return false;
114: }
115: $this->initialize();
116: if ($trans == true) $this->dbhandler->db->transactionEnd();
117: }
118:
119: public function (){
120: return $this->id;
121: }
122:
123: public function (){
124: return $this->comment;
125: }
126:
127: public function (){
128: return $this->created;
129: }
130:
131: public function (){
132: return $this->user_id;
133: }
134:
135: public function (){
136: return $this->user_name;
137: }
138:
139:
140: public function (){
141: return $this->task_id;
142: }
143:
144: public function ($d){
145: $this->id = $d;
146: }
147:
148: public function ($d){
149: $this->comment = $d;
150: }
151:
152: public function ($d){
153: $this->created = $d;
154: }
155:
156: public function ($d){
157: $this->user_id = $d;
158: }
159:
160: public function ($d){
161: $this->task_id = $d;
162: }
163:
164:
165: }
166: ?>
167: