Next4Me
 All Classes Files Functions Variables
MicroflowAction.php
Go to the documentation of this file.
1 <?php
18 class Application_Model_MicroflowAction extends Zend_Db_Table_Abstract {
19  //put your code here
20  protected $_name="MicroflowAction";
21  protected $_primary="IdMicroflowAction";
22  protected $_referenceMap=array(
23  'MicroflowAction'=>array(
24  'columns'=>array('IdMicroflow'),
25  'refTableClass'=>'Microflow',
26  'refColumns'=>array('IdMicroflow'),
27  'onDelete' => self::CASCADE,
28  'onUpdate' => self::RESTRICT
29  )
30  );
31  protected $_dependentTable=array('MicroflowActionAlert',
32  'MicroflowActionProperty',
33  'MicroflowActionResult',
34  'MicroflowNextAction');
35 
36  //==== Start addEditMicroflowAction =========================================================================
57  function addEditMicroflowAction($entity) {
58  // function implementation
59  $resultId = 0;
60  $page="MicroflowAction.php";
61  $method="addEditMicroflowAction";
62  $result=json_encode($entity);
63  $message="";
64  $type="1";
65  $this->ErrorCode = new Application_Model_ErrorCode;
66  $this->Log = new Application_Model_Log;
67 
68  try{
69  $data=array();
70  if(!isset($entity['IdMicroflowAction'])){
71  $resultId = 3079;
72  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
73  $resultCode=sprintf($r['Message'], "IdMicroflowAction");
74  $message=sprintf($r['Message'], "IdMicroflowAction");
75  $type=3;
76  }else{$data['IdMicroflowAction']=$entity['IdMicroflowAction'];}
77 
78  if(!isset($entity['IdMicroflow'])){
79  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
80  $resultId = 3079;
81  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
82  $resultCode=sprintf($r['Message'], "IdMicroflow");
83  $message=sprintf($r['Message'], "IdMicroflow");
84  $type=3;
85  }
86  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
87 
88  if(!isset($entity['Name'])){
89  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
90  $resultId = 3079;
91  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
92  $resultCode=sprintf($r['Message'], "Name");
93  $message=sprintf($r['Message'], "Name");
94  $type=3;
95  }
96  }else{$data['Name']=$entity['Name'];}
97 
98  if(!isset($entity['Description'])){
99  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
100  $resultId = 3079;
101  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
102  $resultCode=sprintf($r['Message'], "Description");
103  $message=sprintf($r['Message'], "Description");
104  $type=3;
105  }
106  }else{$data['Description']=$entity['Description'];}
107 
108  if(!isset($entity['TimeActivation'])){
109  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
110  $resultId = 3079;
111  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
112  $resultCode=sprintf($r['Message'], "TimeActivation");
113  $message=sprintf($r['Message'], "TimeActivation");
114  $type=3;
115  }
116  }else{$data['TimeActivation']=$entity['TimeActivation'];}
117 
118  if(!isset($entity['TimeClosed'])){
119  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
120  $resultId = 3079;
121  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
122  $resultCode=sprintf($r['Message'], "TimeClosed");
123  $message=sprintf($r['Message'], "TimeClosed");
124  $type=3;
125  }
126  }else{$data['TimeClosed']=$entity['TimeClosed'];}
127  if(!isset($entity['IdContext'])){
128  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
129  $resultId = 3079;
130  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
131  $resultCode=sprintf($r['Message'], "IdContext");
132  $message=sprintf($r['Message'], "IdContext");
133  $type=3;
134  }
135  }else{$data['IdContext']=$entity['IdContext'];}
136 
137  if(!isset($entity['IdTplMicroflowAction'])){
138  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
139  $resultId = 3079;
140  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
141  $resultCode=sprintf($r['Message'], "IdTplMicroflowAction");
142  $message=sprintf($r['Message'], "IdTplMicroflowAction");
143  $type=3;
144  }
145  }else{$data['IdTplMicroflowAction']=$entity['IdTplMicroflowAction'];}
146 
147  if(!isset($entity['Status'])){
148  if($resultId==0 && (int)$entity['IdMicroflowAction']==0){
149  $resultId = 3079;
150  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
151  $resultCode=sprintf($r['Message'], "Status");
152  $message=sprintf($r['Message'], "Status");
153  $type=3;
154  }
155  }else{$data['Status']=$entity['Status'];}
156 
157  if(!isset($entity['IdUserAccount'])){
158  $resultId = 3079;
159  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
160  $resultCode=sprintf($r['Message'], "IdUserAccount");
161  $message=sprintf($r['Message'], "IdUserAccount");
162  $type=3;
163  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
164 
165  if(!isset($entity['UserAccountType'])){
166  $resultId = 3079;
167  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
168  $resultCode=sprintf($r['Message'], "UserAccountType");
169  $message=sprintf($r['Message'], "UserAccountType");
170  $type=3;
171  }else{$data['UserAccountType']=$entity['UserAccountType'];}
172 
173  if(!isset($data)|| $data==null){
174  $resultId = 3079;
175  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
176  $resultCode=sprintf($r['Message'], "IdMicroflow,Name,Description,TimeActivation,TimeClosed,IdContext,IdTplMicroflowAction");
177  $message=sprintf($r['Message'], "IdMicroflow,Name,Description,TimeActivation,TimeClosed,IdContext,IdTplMicroflowAction");
178  $type=3;
179  }
180 
181  if($resultId==0){
182  if($data['UserAccountType']=="0"){
183  $IdUserAccount=0;
184  }else{
185  $IdUserAccount=(int)$data['IdUserAccount'];
186  }
187  $IdMicroflowAction=(int)$data['IdMicroflowAction'];
188  $IdMicroflow=(int)$data['IdMicroflow'];
189  unset($data['UserAccountType']);
190 
191  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
192  ->from("MicroflowAction","*")
193  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
194  ->where("IdMicroflowAction=$IdMicroflowAction")
195  );
196  if($rows!=null){
197  $IdMicroflow=$rows->IdMicroflow;
198  if(isset($data['IdMicroflow'])){
199  if($IdMicroflow!=$data['IdMicroflow']){
200  $resultId = 5004;
201  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
202  $resultCode=$r['Message'];
203  $message=$r['Message'];
204  $type=3;
205  }
206  }
207  }else{
208  if($IdMicroflowAction!="0"){
209  $resultId = 3019;
210  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
211  $resultCode=$r['Message'];
212  $message=$r['Message'];
213  $type=3;
214  }
215  }
216  }
217  if($resultId==0){
218  if ($IdMicroflowAction=="0"){
219  $k=$this->insert($data);
220  $k=$this->getAdapter()->lastInsertId();
221  $resultCode=$k;
222  }else{
223  unset($data['IdUserAccount']);
224  $this->update($data,$this->getAdapter()->quoteInto('IdMicroflowAction=?',$IdMicroflowAction));
225  $k=$entity['IdMicroflowAction'];
226  $resultCode=$k;
227  }
228  }
229  }
230  catch(Exception $e){
231  $resultCode=$e->getMessage();
232  $resultId=101;
233  $type=3;
234  }
235  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
236  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
237  return $response;
238  }
239  //============ End addEditMicroflowAction ==============================================================
240 
241 
242  //==== Start deleteMicroflowAction =========================================================================
253  function deleteMicroflowAction($entity) {
254  // function implementation
255  $resultId = 0;
256  $page="MicroflowAction.php";
257  $method="deleteMicroflowAction";
258  $result=json_encode($entity);
259  $message="";
260  $type="1";
261  $this->ErrorCode = new Application_Model_ErrorCode;
262  $this->Log = new Application_Model_Log;
263 
264  try{
265  $data=array();
266  if(!isset($entity['IdMicroflowAction'])){
267  $resultId = 3163;
268  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
269  $resultCode=sprintf($r['Message'], "IdMicroflowAction");
270  $message=sprintf($r['Message'], "IdMicroflowAction");
271  $type=3;
272  }else{$data['IdMicroflowAction']=$entity['IdMicroflowAction'];}
273 
274  if(!isset($entity['IdMicroflow'])){
275  $resultId = 3163;
276  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
277  $resultCode=sprintf($r['Message'], "IdMicroflow");
278  $message=sprintf($r['Message'], "IdMicroflow");
279  $type=3;
280  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
281 
282  if(!isset($entity['IdUserAccount'])){
283  $resultId = 3163;
284  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
285  $resultCode=sprintf($r['Message'], "IdUserAccount");
286  $message=sprintf($r['Message'], "IdUserAccount");
287  $type=3;
288  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
289 
290  if(!isset($entity['UserAccountType'])){
291  $resultId = 3163;
292  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
293  $resultCode=sprintf($r['Message'], "UserAccountType");
294  $message=sprintf($r['Message'], "UserAccountType");
295  $type=3;
296  }else{$data['UserAccountType']=$entity['UserAccountType'];}
297 
298  if(!isset($data)|| $data==null){
299  $resultId = 3163;
300  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
301  $resultCode=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
302  $message=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
303  $type=3;
304  }
305  if($resultId==0){
306  $i=0;
307  $IdUserAccount=(int)$data['IdUserAccount'];
308  $IdMicroflow=(int)$data['IdMicroflow'];
309  $IdMicroflowAction=(int)$data['IdMicroflowAction'];
310 
311  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
312  ->from("MicroflowAction","*")
313  ->where("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow")
314  ->where("IdMicroflowAction=$IdMicroflowAction OR 0=$IdMicroflowAction")
315  ->where("IdUserAccount=$IdUserAccount")
316  );
317  if(count($rows)==0){
318  $resultId = 3020;
319  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
320  $resultCode=$r['Message'];
321  $message=$r['Message'];
322  $type=3;
323  }else{
324  foreach ($rows as $row){
325 
326  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
327  ->from("MicroflowActionResult","*")
328  ->where("IdMicroflowAction=?",$row->IdMicroflowAction)
329  );
330  if($chld!=null){
331  $i++;
332  }
333  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
334  ->from("MicroflowActionProperty","*")
335  ->where("IdMicroflowAction=?",$row->IdMicroflowAction)
336  );
337  if($chld!=null){
338  $i++;
339  }
340  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
341  ->from("MicroflowActionAlert","*")
342  ->where("IdMicroflowAction=?",$row->IdMicroflowAction)
343  );
344  if($chld!=null){
345  $i++;
346  }
347  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
348  ->from("MicroflowNextAction","*")
349  ->where("IdNextActionMf=?",$row->IdMicroflowAction)
350  );
351  if($chld!=null){
352  $i++;
353  }
354  }
355  }
356  }
357  if($resultId==0){
358  if($i==0){
359  $k=$this->delete(array("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow",
360  "IdMicroflowAction=$IdMicroflowAction OR 0=$IdMicroflowAction"));
361  $resultCode="Date sterse";
362  }else{
363  $resultId = 4005;
364  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
365  $resultCode=$r['Message'];
366  $message=$r['Message'];
367  $type=3;
368  }
369  }
370  }
371  catch(Exception $e){
372  $resultCode=$e->getMessage();
373  $resultId=101;
374  $type=3;
375  }
376  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
377  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
378  return $response;
379  }
380  //============ End deleteMicroflowAction ==============================================================
381 
382 
383  //==== Start getMicroflowAction =========================================================================
404  function getMicroflowAction($entity) {
405  // function implementation
406  $resultId = 0;
407  $page="MicroflowAction.php";
408  $method="getMicroflowAction";
409  $result=json_encode($entity);
410  $message="";
411  $type="1";
412  $this->ErrorCode = new Application_Model_ErrorCode;
413  $this->Log = new Application_Model_Log;
414  $this->Paging = new Application_Model_Paging;
415 
416  try{
417  $pg=$this->Paging->getPageDefault('MicroflowAction');
418 
419  $data=array();
420  if(!isset($entity['IdMicroflowAction']))
421  {
422  $resultId = 3136;
423  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
424  $resultCode=sprintf($r['Message'], "IdMicroflowAction");
425  $message=sprintf($r['Message'], "IdMicroflowAction");
426  $type=3;
427  }else{$data['IdMicroflowAction']=$entity['IdMicroflowAction'];}
428 
429  if(!isset($entity['IdMicroflow']))
430  {
431  $resultId = 3136;
432  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
433  $resultCode=sprintf($r['Message'], "IdMicroflow");
434  $message=sprintf($r['Message'], "IdMicroflow");
435  $type=3;
436  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
437 
438  if(!isset($entity['IdUserAccount'])){
439  $resultId = 3136;
440  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
441  $resultCode=sprintf($r['Message'], "IdUserAccount");
442  $message=sprintf($r['Message'], "IdUserAccount");
443  $type=3;
444  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
445 
446  if(!isset($entity['UserAccountType'])){
447  $resultId = 3136;
448  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
449  $resultCode=sprintf($r['Message'], "UserAccountType");
450  $message=sprintf($r['Message'], "UserAccountType");
451  $type=3;
452  }else{$data['UserAccountType']=$entity['UserAccountType'];}
453 
454  if(!isset($entity['pageSize'])){
455  $_pageSize=$pg['pageSize'];
456  }else{
457  $_pageSize=$entity['pageSize'];
458  }
459 
460  if(!isset($entity['pageNo'])){
461  $_pageNo=$pg['pageNo'];
462  }else{$_pageNo=$entity['pageNo'];}
463 
464  if(!isset($entity['orderColumn'])){
465  $_orderColumn=$pg['orderColumn'];
466  }else{$_orderColumn=$entity['orderColumn'];}
467 
468  if(!isset($entity['orderType'])){
469  $_orderType=$pg['orderType'];
470  }else{
471  switch($entity['orderType'])
472  {
473  case 'ASC':
474  $_orderType="ASC";
475  break;
476  case 'DESC':
477  $_orderType="DESC";
478  break;
479  default:
480  $_orderType="DESC";
481  break;
482  }
483  }
484 
485  if(!isset($entity['orderColumn'])){
486  $_orderColumn=$pg['orderColumn'];
487  }else{
488  switch($entity['orderColumn'])
489  {
490  case 'IdMicroflowAction':
491  $_orderColumn="IdMicroflowAction";
492  break;
493  case 'IdMicroflow':
494  $_orderColumn="IdMicroflow";
495  break;
496  case 'Name':
497  $_orderColumn="Name";
498  break;
499  case 'Description':
500  $_orderColumn="Description";
501  break;
502  case 'TimeActivation':
503  $_orderColumn="TimeActivation";
504  break;
505  case 'TimeClosed':
506  $_orderColumn="TimeClosed";
507  break;
508  case 'IdContext':
509  $_orderColumn="IdContext";
510  break;
511  case 'IdTplMicroflowAction':
512  $_orderColumn="IdTplMicroflowAction";
513  break;
514  case 'Status':
515  $_orderColumn="Status";
516  break;
517  case 'IdUserAccount':
518  $_orderColumn="IdUserAccount";
519  break;
520  default:
521  $_orderColumn=$orderColumn;
522  break;
523  }
524 
525  }
526  if($resultId==0){
527  if($data['UserAccountType']=="0"){
528  $IdUserAccount=0;
529  }else{
530  $IdUserAccount=(int)$data['IdUserAccount'];
531  }
532  $IdMicroflow=(int)$data['IdMicroflow'];
533  $IdMicroflowAction=(int)$data['IdMicroflowAction'];
534 
535  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
536  ->from("MicroflowAction",array("total"=>"COUNT(IdMicroflowAction)"))
537  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
538  ->where("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow")
539  ->where("IdMicroflowAction=$IdMicroflowAction OR 0=$IdMicroflowAction")
540  );
541 
542  if($count->total==0){
543  $resultId = 3021;
544  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
545  $resultCode=$r['Message'];
546  $message=$r['Message'];
547  $type=3;
548  }else{
549  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
550 
551  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
552  ->from("MicroflowAction","*")
553  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
554  ->where("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow")
555  ->where("IdMicroflowAction=$IdMicroflowAction OR 0=$IdMicroflowAction")
556  ->limit($_pageSize, $offset['start'])
557  ->order($_orderColumn." ".$_orderType)
558  );
559 
560  foreach($rows as $row){
561  $resultEntity[]=array("IdMicroflowAction"=>$row->IdMicroflowAction,
562  "IdMicroflow"=>$row->IdMicroflow,
563  "Name"=>$row->Name,
564  "Description"=>$row->Description,
565  "TimeActivation"=>$row->TimeActivation,
566  "TimeClosed"=>$row->TimeClosed,
567  "IdContext"=>$row->IdContext,
568  "IdTplMicroflowAction"=>$row->IdTplMicroflowAction,
569  "Status"=>$row->Status);
570  }
571 
572  $resultCode=array("pageNo"=>$_pageNo,
573  "pageSize"=>$_pageSize,
574  "pageCount"=>$offset['maxPage'],
575  "orderColumn"=>$_orderColumn,
576  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
577  }
578  }
579  }
580  catch(Exception $e){
581  $resultCode=$e->getMessage();
582  $resultId=101;
583  $type=3;
584  }
585  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
586  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
587  return $response;
588  }
589  //============ End getMicroflowAction ==============================================================
590 
591 }
592 
593 ?>