1: <?php
2: 3: 4: 5:
6:
7:
8: class projectEquipmentHandler extends equipmentHandler {
9:
10: private $dbhandler;
11: protected $start_date;
12: protected $end_date;
13:
14: public function __construct ($id,$name,$model,$manufacturer,$build_date,$desc,$start_date,$end_date){
15: parent::__construct($id,$name,$model,$manufacturer,$build_date,$desc);
16: $this->start_date = $start_date;
17: $this->end_date = $end_date;
18: }
19:
20: public function destructDbInstances(){
21: parent::destructDbInstances();
22: unset($this->dbhandler);
23: }
24:
25: public function setDataSource(&$db){
26: $this->dbhandler = new equipmentDbHandler($db);
27: parent::setDataSource($db);
28: }
29:
30: public function &getDataSource(){
31: return $this->dbhandler;
32: }
33:
34: public function initialize(){
35: $this->start_date = null;
36: $this->end_date = null;
37: parent::initialize();
38: }
39:
40: public function initializeById($eqid,$prid){
41: if (is_object($this->dbhandler) && is_numeric($eqid) && is_numeric($prid) ){
42: $this->start_date = $this->dbhandler->getStartDate($eqid,$prid);
43: $this->end_date = $this->dbhandler->getEndDate($eqid,$prid);
44: parent::initializeById($eqid);
45: }
46: }
47:
48: public function initializeEquipmentData($id){
49: parent::initializeById($id);
50: }
51:
52: public function syncStorage(){
53: if (!$this->getEquipmentId())
54: $this->syncStorageUpdate();
55: else
56: $this->syncStorageInsert();
57: }
58:
59: public function syncStorageUpdate($trans = true){
60:
61: try {
62: if ($trans == true ) $this->dbhandler->db->transactionStart();
63:
64: $this->setEquipmentDates();
65: }catch (Exception $e){
66: $this->dbhandler->db->transactionRollback();
67: return false;
68: }
69: if ($trans == true ) $this->dbhandler->db->transactionEnd();
70: return true;
71: }
72:
73:
74: public function syncStorageInsert($trans = true){
75:
76: try {
77: if ($trans == true ) $this->dbhandler->db->transactionStart();
78: if (parent::insertEquipmentData() == false) throw new Exception('Insert failed');
79: $this->setEquipmentDates();
80: }catch (Exception $e){
81: $this->dbhandler->db->transactionRollback();
82: return false;
83: }
84: if ($trans == true ) $this->dbhandler->db->transactionEnd();
85: return true;
86: }
87:
88: public function syncStorageRemove(){
89: if (is_numeric($this->getEquipmentId()) == false) throw new Exception($this->translator->translate('equipm_not_selected','u'));
90:
91: try {
92: $this->dbhandler->db->transactionStart();
93: $this->dbhandler->deleteEquipmentData($this->getEquipmentId());
94: }catch (Exception $e){
95: $this->dbhandler->db->transactionRollback();
96: return false;
97: }
98: $this->initialize();
99: $this->dbhandler->db->transactionEnd();
100: return true;
101: }
102:
103: protected function setEquipmentDates(){
104:
105: if ($this->datehandler->verifyDateValue($this->getEquipmentStartDate()))
106: $this->dbhandler->setEquipmentStartDate(
107: $this->getEquipmentId(),
108: $this->getProjectId(),
109: $this->getEquipmentStartDate());
110:
111: if ($this->datehandler->verifyDateValue($this->getEquipmentEndDate()))
112: $this->dbhandler->setEquipmentEndDate(
113: $this->getEquipmentId(),
114: $this->getProjectId(),
115: $this->getEquipmentEndDate());
116: }
117:
118:
119: public function setEquipmentStartDate($d){
120: $this->start_date = $d;
121: }
122:
123: public function setEquipmentEndDate($d){
124: $this->end_date = $d;
125: }
126:
127: public function getEquipmentStartDate(){
128: return $this->start_date;
129: }
130:
131: public function getEquipmentEndDate(){
132: return $this->end_date;
133: }
134:
135: }
136: ?>
137: