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