Next4Me
 All Classes Files Functions Variables
TplActionType.php
Go to the documentation of this file.
1 <?php
15 class Application_Model_TplActionType extends Zend_Db_Table_Abstract {
16  protected $_name="TplActionType";
17  protected $_primary="IdTplActionType";
18 
19  //==== Start addEditTplActionType =========================================================================
34  function addEditTplActionType($entity) {
35  // function implementation
36  $resultId = 0;
37  $page="TplActionType.php";
38  $method="addEditTplActionType";
39  $result=json_encode($entity);
40  $message="";
41  $type="1";
42  $this->ErrorCode = new Application_Model_ErrorCode;
43  $this->Log = new Application_Model_Log;
44 
45  try{
46  $data=array();
47 
48  if(!isset($entity['IdTplActionType'])){
49  $resultId = 3090;
50  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
51  $resultCode=sprintf($r['Message'], "IdTplActionType");
52  $message=sprintf($r['Message'], "IdTplActionType");
53  $type=3;
54  }else{
55  $data['IdTplActionType']=(int)$entity['IdTplActionType'];
56  }
57 
58  if(!isset($entity['IdTplContext'])){
59  if($resultId==0 && $entity['IdTplActionType']=="0"){
60  $resultId = 3090;
61  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
62  $resultCode=sprintf($r['Message'], "IdTplContext");
63  $message=sprintf($r['Message'], "IdTplContext");
64  $type=3;
65  }
66  }else{$data['IdTplContext']=$entity['IdTplContext'];}
67 
68  if(!isset($entity['Name'])){
69  if($resultId==0 && $entity['IdTplActionType']=="0"){
70  $resultId = 3090;
71  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
72  $resultCode=sprintf($r['Message'], "Name");
73  $message=sprintf($r['Message'], "Name");
74  $type=3;
75  }
76  }else{$data['Name']=$entity['Name'];}
77 
78  if(!isset($entity['Icon'])){
79  if($resultId==0 && $entity['IdTplActionType']=="0"){
80  $resultId = 3090;
81  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
82  $resultCode=sprintf($r['Message'], "Icon");
83  $message=sprintf($r['Message'], "Icon");
84  $type=3;
85  }
86  }else{$data['Icon']=$entity['Icon'];}
87 
88  if(!isset($entity['DurataImplicita'])){
89  if($resultId==0 && $entity['IdTplActionType']=="0"){
90  $resultId = 3090;
91  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
92  $resultCode=sprintf($r['Message'], "DurataImplicita");
93  $message=sprintf($r['Message'], "DurataImplicita");
94  $type=3;
95  }
96  }else{$data['DurataImplicita']=$entity['DurataImplicita'];}
97 
98  if(!isset($data) || $data==null){
99  $resultId = 3090;
100  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
101  $resultCode=sprintf($r['Message'], "IdTplContext,Name,Icon,DurataImplicita");
102  $message=sprintf($r['Message'], "IdTplContext,Name,Icon,DurataImplicita");
103  $type=3;
104  }
105 
106  if($resultId==0 && $data['IdTplActionType']!="0"){
107  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
108  ->from("TplActionType","*")
109  ->where("IdTplActionType=?",$data['IdTplActionType'])
110  );
111  if($rows==null){
112  $resultId = 3052;
113  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
114  $resultCode=$r['Message'];
115  $message=$r['Message'];
116  $type=3;
117  }
118  }
119 
120  if($resultId==0){
121  $IdTplActionType=(int)$data['IdTplActionType'];
122  if ($IdTplActionType==0){
123  $k=$this->insert($data);
124  $k=$this->getAdapter()->lastInsertId();
125  $resultCode=$k;
126  }else{
127  $this->update($data,$this->getAdapter()->quoteInto('IdTplActionType=?',$IdTplActionType));
128  $k=$data['IdTplActionType'];
129  $resultCode=$k;
130  }
131  }
132 
133  }
134  catch(Exception $e){
135  $resultCode=$e->getMessage();
136  $resultId=101;
137  $type=3;
138  }
139  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
140  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
141  return $response;
142 
143  }
144  //============ End addEditTplActionType ==============================================================
145 
146 
147  //==== Start deleteTplActionType =========================================================================
157  function deleteTplActionType($entity) {
158  // function implementation
159  $resultId = 0;
160  $page="TplActionType.php";
161  $method="deleteTplActionType";
162  $result=json_encode($entity);
163  $message="";
164  $type="1";
165  $this->ErrorCode = new Application_Model_ErrorCode;
166  $this->Log = new Application_Model_Log;
167 
168  try{
169  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
170  ->from("TplActionType","*")
171  ->where("IdTplActionType=?",$entity['IdTplActionType'])
172  );
173  if($rows==null){
174  $resultId = 3053;
175  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
176  $resultCode=$r['Message'];
177  $message=$r['Message'];
178  $type=3;
179  }else{
180  $i=0;
181  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
182  ->from("TplActionTypeResult","*")
183  ->where("IdTplActionType=?",$entity['IdTplActionType'])
184  );
185  if($chld!=null){
186  $i++;
187  }
188  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
189  ->from("TplActionTypeProperty","*")
190  ->where("IdTplActionType=?",$entity['IdTplActionType'])
191  );
192  if($chld!=null){
193  $i++;
194  }
195  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
196  ->from("TplActionTypeAlert","*")
197  ->where("IdTplActionType=?",$entity['IdTplActionType'])
198  );
199  if($chld!=null){
200  $i++;
201  }
202  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
203  ->from("TplActionTypeNextAction","*")
204  ->where("IdTplActionType=?",$entity['IdTplActionType'])
205  );
206  if($chld!=null){
207  $i++;
208  }
209  if($i==0){
210  $k=$this->delete($this->getAdapter()->quoteInto("IdTplActionType=?",$entity['IdTplActionType']));
211  $resultCode="Date sterse";
212  }else{
213  $resultId = 4010;
214  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
215  $resultCode=$r['Message'];
216  $message=$r['Message'];
217  $type=3;
218  }
219  }
220  }
221  catch(Exception $e){
222  $resultCode=$e->getMessage();
223  $resultId=101;
224  $type=3;
225  }
226  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
227  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
228  return $response;
229  }
230  //============ End deleteTplActionType ==============================================================
231 
232 
233  //==== Start getTplActionType =========================================================================
248  function getTplActionType($entity) {
249  // function implementation
250  $resultId = 0;
251  $page="TplActionType.php";
252  $method="getTplActionType";
253  $result=json_encode($entity);
254  $message="";
255  $type="1";
256  $this->ErrorCode = new Application_Model_ErrorCode;
257  $this->Log = new Application_Model_Log;
258  $this->Paging = new Application_Model_Paging;
259 
260  try{
261  $pg=$this->Paging->getPageDefault('TplActionType');
262 
263  $data=array();
264  if(!isset($entity['IdTplActionType']))
265  {
266  $resultId = 3142;
267  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
268  $resultCode=sprintf($r['Message'], "IdTplActionType");
269  $message=sprintf($r['Message'], "IdTplActionType");
270  $type=3;
271  }else{$data['IdTplActionType']=$entity['IdTplActionType'];}
272 
273  if(!isset($entity['IdUserAccount'])){
274  $resultId = 3142;
275  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
276  $resultCode=sprintf($r['Message'], "IdUserAccount");
277  $message=sprintf($r['Message'], "IdUserAccount");
278  $type=3;
279  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
280 
281  if(!isset($entity['UserAccountType'])){
282  $resultId = 3142;
283  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
284  $resultCode=sprintf($r['Message'], "UserAccountType");
285  $message=sprintf($r['Message'], "UserAccountType");
286  $type=3;
287  }else{$data['UserAccountType']=$entity['UserAccountType'];}
288 
289  if(!isset($entity['pageSize'])){
290  $_pageSize=$pg['pageSize'];
291  }else{
292  $_pageSize=$entity['pageSize'];
293  }
294 
295  if(!isset($entity['pageNo'])){
296  $_pageNo=$pg['pageNo'];
297  }else{$_pageNo=$entity['pageNo'];}
298 
299  if(!isset($entity['orderColumn'])){
300  $_orderColumn=$pg['orderColumn'];
301  }else{$_orderColumn=$entity['orderColumn'];}
302 
303  if(!isset($entity['orderType'])){
304  $_orderType=$pg['orderType'];
305  }else{
306  switch($entity['orderType'])
307  {
308  case 'ASC':
309  $_orderType="ASC";
310  break;
311  case 'DESC':
312  $_orderType="DESC";
313  break;
314  default:
315  $_orderType="DESC";
316  break;
317  }
318  }
319 
320  if(!isset($entity['orderColumn'])){
321  $_orderColumn=$pg['orderColumn'];
322  }else{
323  switch($entity['orderColumn'])
324  {
325  case 'IdTplActionType':
326  $_orderColumn="IdTplActionType";
327  break;
328  case 'IdTplContext':
329  $_orderColumn="IdTplContext";
330  break;
331  case 'Name':
332  $_orderColumn="Name";
333  break;
334  case 'Icon':
335  $_orderColumn="Icon";
336  break;
337  case 'DurataImplicita':
338  $_orderColumn="DurataImplicita";
339  break;
340  default:
341  $_orderColumn=$orderColumn;
342  break;
343  }
344 
345  }
346 
347  if($resultId==0){
348  $IdTplActionType=(int)$data['IdTplActionType'];
349 
350  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
351  ->from("TplActionType",array("total"=>"COUNT(IdTplActionType)"))
352  ->where("IdTplActionType=$IdTplActionType OR 0=$IdTplActionType")
353 
354  );
355 
356  if($count->total==0){
357 
358  $resultId = 3054;
359  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
360  $resultCode=$r['Message'];
361  $message=$r['Message'];
362  $type=3;
363 
364  }else{
365 
366  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
367 
368  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
369  ->from("TplActionType","*")
370  ->where("IdTplActionType=$IdTplActionType OR 0=$IdTplActionType")
371  ->limit($_pageSize, $offset['start'])
372  ->order($_orderColumn." ".$_orderType)
373  );
374 
375  foreach($rows as $row){
376  $resultEntity[]=array("IdTplActionType"=>$row->IdTplActionType,
377  "IdTplContext" =>$row->IdTplContext,
378  "Name" =>$row->Name,
379  "Icon" => $row->Icon,
380  "DurataImplicita" => $row->DurataImplicita);
381  }
382 
383  $resultCode=array("pageNo"=>$_pageNo,
384  "pageSize"=>$_pageSize,
385  "pageCount"=>$offset['maxPage'],
386  "orderColumn"=>$_orderColumn,
387  "orderType"=>$_orderType,"entity"=>$resultEntity);
388  }
389  }
390  }
391  catch(Exception $e){
392  $resultCode=$e->getMessage();
393  $resultId=101;
394  $type=3;
395  }
396  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
397  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
398  return $response;
399  }
400  //============ End getTplActionType ==============================================================
401 
402 }
403 
404 ?>