Next4Me
 All Classes Files Functions Variables
ControlSessionHistory.php
Go to the documentation of this file.
1 <?php
11 class Application_Model_ControlSessionHistory extends Zend_Db_Table_Abstract{
12 
13  protected $_name="ControlSessionHistory";
14  protected $_primary="IdControlSessionHistory";
15  //==== Start addControlSessionHistory =========================================================================
32  function addControlSessionHistory($entity){
33  // function implementation
34  $resultId = 0;
35  $page="ControlSessionHistory.php";
36  $method="addControlSessionHistory";
37  $result=json_encode($entity);
38  $message="";
39  $type="1";
40  $this->ErrorCode = new Application_Model_ErrorCode;
41  $this->Log = new Application_Model_Log;
42 
43  try{
44  $data=array();
45  if(!isset($entity['IdControlSession'])){
46  $resultId = 3104;
47  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
48  $resultCode=sprintf($r['Message'], "IdControlSession");
49  $message=sprintf($r['Message'], "IdControlSession");
50  $type=3;
51  }else{$data['IdControlSession']=(int)$entity['IdControlSession'];}
52 
53  if(!isset($entity['LastActionTime'])){
54  $resultId = 3104;
55  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
56  $resultCode=sprintf($r['Message'], "LastActionTime");
57  $message=sprintf($r['Message'], "LastActionTime");
58  $type=3;
59  }else{$data['LastActionTime']=$entity['LastActionTime'];}
60 
61  if(!isset($entity['Token'])){
62  $resultId = 3104;
63  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
64  $resultCode=sprintf($r['Message'], "Token");
65  $message=sprintf($r['Message'], "Token");
66  $type=3;
67  }else{$data['Token']=$entity['Token'];}
68 
69  if(!isset($entity['IdUserAccount'])){
70  $resultId = 3104;
71  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
72  $resultCode=sprintf($r['Message'], "IdUserAccount");
73  $message=sprintf($r['Message'], "IdUserAccount");
74  $type=3;
75  }else{$data['IdUserAccount']=(int)$entity['IdUserAccount'];}
76 
77  if(!isset($entity['Lat'])){
78  $resultId = 3104;
79  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
80  $resultCode=sprintf($r['Message'], "Lat");
81  $message=sprintf($r['Message'], "Lat");
82  $type=3;
83  }else{$data['Lat']=$entity['Lat'];}
84 
85  if(!isset($entity['Long'])){
86  $resultId = 3104;
87  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
88  $resultCode=sprintf($r['Message'], "Long");
89  $message=sprintf($r['Message'], "Long");
90  $type=3;
91  }else{$data['Long']=$entity['Long'];}
92 
93  if(!isset($entity['Device'])){
94  $resultId = 3104;
95  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
96  $resultCode=sprintf($r['Message'], "Device");
97  $message=sprintf($r['Message'], "Device");
98  $type=3;
99  }else{$data['Device']=$entity['Device'];}
100 
101  if(!isset($entity['Activity'])){
102  $resultId = 3104;
103  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
104  $resultCode=sprintf($r['Message'], "Activity");
105  $message=sprintf($r['Message'], "Activity");
106  $type=3;
107  }else{$data['Activity']=$entity['Activity'];}
108 
109  if(!isset($entity['Speed'])){
110  $resultId = 3104;
111  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
112  $resultCode=sprintf($r['Message'], "Speed");
113  $message=sprintf($r['Message'], "Speed");
114  $type=3;
115  }else{$data['Speed']=$entity['Speed'];}
116  //echo "<pre>"; print_r($data); echo "</pre>";
117  if($resultId == 0){
118  $k=$this->insert($data);
119  $k=$this->getAdapter()->lastInsertId();
120  $resultCode=$k;
121  }
122  }
123  catch(Exception $e){
124  $resultCode=$e->getMessage();
125  $resultId=101;
126  $type=3;
127  }
128  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
129  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
130  return $response;
131  }
132 
133  //==== End addControlSessionHistory =========================================================================
134 
135  //==== Start getControlSessionHistory =========================================================================
143  function getControlSessionHistory($entity){
144  // function implementation
145  $resultId = 0;
146  $page="ControlSessionHistory.php";
147  $method="getControlSessionHistory";
148  $result=json_encode($entity);
149  $message="";
150  $type="1";
151  $this->ErrorCode = new Application_Model_ErrorCode;
152  $this->Log = new Application_Model_Log;
153 
154  try{
155  $data=array();
156  if(!isset($entity['IdUserAccount'])){
157  $resultId = 3104;
158  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
159  $resultCode=sprintf($r['Message'], "IdUserAccount");
160  $message=sprintf($r['Message'], "IdUserAccount");
161  $type=3;
162  }else{$IdUserAccount=(int)$entity['IdUserAccount'];}
163 
164  if($resultId == 0){
165  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
166  ->from("ControlSessionHistory","*")
167  ->where("IdUserAccount=$IdUserAccount")
168  ->limit(1, 0)
169  ->order("IdControlSessionHistory DESC")
170  );
171  foreach($rows as $row){
172  $resultEntity[]=array("IdControlSessionHistory" => $row->IdControlSessionHistory,
173  "IdControlSession" => $row->IdControlSession,
174  "LastActionTime" => $row->LastActionTime,
175  "Token" => $row->Token,
176  "IdUserAccount" => $row->IdUserAccount,
177  "Lat" => $row->Lat,
178  "Long" => $row->Long,
179  "Device" => $row->Device,
180  "Activity" => $row->Activity,
181  "Speed" => $row->Speed );
182  }
183 
184  $resultCode = $resultEntity;
185  }
186  }
187  catch(Exception $e){
188  $resultCode=$e->getMessage();
189  $resultId=101;
190  $type=3;
191  }
192  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
193  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
194  return $response;
195  }
196 
197  //==== End getControlSessionHistory =========================================================================
198 
199 }