Next4Me
 All Classes Files Functions Variables
Microflow.php
Go to the documentation of this file.
1 <?php
18 class Application_Model_Microflow extends Zend_Db_Table_Abstract {
19  //put your code here
20  protected $_name="Microflow";
21  protected $_primary="IdMicroflow";
22  protected $_dependentTable=array('MicroflowAction');
23 
24  //==== Start addEditMicroflow =========================================================================
39  function addEditMicroflow($entity) {
40  // function implementation
41  $resultId = 0;
42  $page="Microflow.php";
43  $method="addEditMicroflow";
44  $result=json_encode($entity);
45  $message="";
46  $type="1";
47  $this->ErrorCode = new Application_Model_ErrorCode;
48  $this->Log = new Application_Model_Log;
49 
50  try{
51  $data=array();
52  if(!isset($entity['IdMicroflow'])){
53  $resultId = 3080;
54  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
55  $resultCode=sprintf($r['Message'], "IdMicroflow");
56  $message=sprintf($r['Message'], "IdMicroflow");
57  $type=3;
58  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
59 
60  if(!isset($entity['IdAssetProperty'])){
61  if($resultId==0 && (int)$entity['IdMicroflow']==0){
62  $resultId = 3080;
63  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
64  $resultCode=sprintf($r['Message'], "IdAssetProperty");
65  $message=sprintf($r['Message'], "IdAssetProperty");
66  $type=3;
67  }
68  }else{$data['IdAssetProperty']=$entity['IdAssetProperty'];}
69 
70  if(!isset($entity['IdTplMicroflow'])){
71  if($resultId==0 && (int)$entity['IdMicroflow']==0){
72  $resultId = 3080;
73  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
74  $resultCode=sprintf($r['Message'], "IdTplMicroflow");
75  $message=sprintf($r['Message'], "IdTplMicroflow");
76  $type=3;
77  }
78  }else{$data['IdTplMicroflow']=$entity['IdTplMicroflow'];}
79 
80  if(!isset($entity['Name'])){
81  if($resultId==0 && (int)$entity['IdMicroflow']==0){
82  $resultId = 3080;
83  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
84  $resultCode=sprintf($r['Message'], "Name");
85  $message=sprintf($r['Message'], "Name");
86  $type=3;
87  }
88  }else{$data['Name']=$entity['Name'];}
89 
90  if(!isset($entity['IdUserAccount'])){
91  $resultId = 3080;
92  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
93  $resultCode=sprintf($r['Message'], "IdUserAccount");
94  $message=sprintf($r['Message'], "IdUserAccount");
95  $type=3;
96  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
97 
98  if(!isset($entity['UserAccountType'])){
99  $resultId = 3080;
100  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
101  $resultCode=sprintf($r['Message'], "UserAccountType");
102  $message=sprintf($r['Message'], "UserAccountType");
103  $type=3;
104  }else{$data['UserAccountType']=$entity['UserAccountType'];}
105 
106  if(!isset($data)|| $data==null){
107  $resultId = 3080;
108  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
109  $resultCode=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
110  $message=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
111  $type=3;
112  }
113 
114  if($resultId==0){
115  if($data['UserAccountType']=="0"){
116  $IdUserAccount=0;
117  }else{
118  $IdUserAccount=(int)$data['IdUserAccount'];
119  }
120  $IdMicroflow=(int)$data['IdMicroflow'];
121  unset($data['UserAccountType']);
122 
123  if ($IdMicroflow=="0"){
124  $k=$this->insert($data);
125  $k=$this->getAdapter()->lastInsertId();
126  $resultCode=$k;
127  }else{
128  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
129  ->from("Microflow","*")
130  ->where("IdMicroflow=?",$IdMicroflow)
131  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
132  );
133  if($rows!=null){
134  unset($data['IdUserAccount']);
135  $this->update($data,$this->getAdapter()->quoteInto('IdMicroflow=?',$IdMicroflow));
136  $k=$IdMicroflow;
137  $resultCode=$k;
138  }else{
139  $resultId = 3016;
140  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
141  $resultCode=$r['Message'];
142  $message=$r['Message'];
143  $type=3;
144  }
145  }
146  }
147  }
148  catch(Exception $e){
149  $resultCode=$e->getMessage();
150  $resultId=101;
151  $type=3;
152  }
153  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
154  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
155  return $response;
156  }
157  //============ End addEditMicroflow ==============================================================
158 
159 
160  //==== Start deleteMicroflow =========================================================================
171  function deleteMicroflow($entity) {
172  // function implementation
173  $resultId = 0;
174  $page="Microflow.php";
175  $method="deleteMicroflow";
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 
184  $data=array();
185  if(!isset($entity['IdMicroflow'])){
186  $resultId = 3162;
187  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
188  $resultCode=sprintf($r['Message'], "IdMicroflow");
189  $message=sprintf($r['Message'], "IdMicroflow");
190  $type=3;
191  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
192 
193  if(!isset($entity['IdUserAccount'])){
194  $resultId = 3162;
195  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
196  $resultCode=sprintf($r['Message'], "IdUserAccount");
197  $message=sprintf($r['Message'], "IdUserAccount");
198  $type=3;
199  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
200 
201  if(!isset($entity['UserAccountType'])){
202  $resultId = 3162;
203  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
204  $resultCode=sprintf($r['Message'], "UserAccountType");
205  $message=sprintf($r['Message'], "UserAccountType");
206  $type=3;
207  }else{$data['UserAccountType']=$entity['UserAccountType'];}
208 
209  if(!isset($data)|| $data==null){
210  $resultId = 3162;
211  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
212  $resultCode=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
213  $message=sprintf($r['Message'], "IdAssetProperty,IdTplMicroflow,Name");
214  $type=3;
215  }
216  if($resultId==0){
217  $IdUserAccount=(int)$data['IdUserAccount'];
218  $IdMicroflow=(int)$data['IdMicroflow'];
219 
220  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
221  ->from("Microflow","*")
222  ->where("IdMicroflow=?",$IdMicroflow)
223  ->where("IdUserAccount=$IdUserAccount")
224  );
225  if($rows==null){
226  $resultId = 3017;
227  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
228  $resultCode=$r['Message'];
229  $message=$r['Message'];
230  $type=3;
231  }else{
232  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
233  ->from("MicroflowAction","*")
234  ->where("IdMicroflow=?",$IdMicroflow)
235  );
236  if($chld==null){
237  $k=$this->delete($this->getAdapter()->quoteInto("IdMicroflow=?",$IdMicroflow));
238  $resultCode="Date sterse";
239  }else{
240  $resultId = 4004;
241  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
242  $resultCode=$r['Message'];
243  $message=$r['Message'];
244  $type=3;
245  }
246  }
247  }
248  }
249  catch(Exception $e){
250  $resultCode=$e->getMessage();
251  $resultId=101;
252  $type=3;
253  }
254  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
255  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
256  return $response;
257  }
258  //============ End deleteMicroflow ==============================================================
259 
260 
261  //==== Start getMicroflow =========================================================================
279  function getMicroflow($entity) {
280  // function implementation
281  $resultId = 0;
282  $page="Microflow.php";
283  $method="getMicroflow";
284  $result=json_encode($entity);
285  $message="";
286  $type="1";
287  $this->ErrorCode = new Application_Model_ErrorCode;
288  $this->Log = new Application_Model_Log;
289  $this->Paging = new Application_Model_Paging;
290 
291  try{
292  $pg=$this->Paging->getPageDefault('Microflow');
293 
294  $data=array();
295  if(!isset($entity['IdMicroflow']))
296  {
297  $resultId = 3135;
298  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
299  $resultCode=sprintf($r['Message'], "IdMicroflow");
300  $message=sprintf($r['Message'], "IdMicroflow");
301  $type=3;
302  }else{$data['IdMicroflow']=$entity['IdMicroflow'];}
303 
304  if(!isset($entity['IdAssetProperty']))
305  {
306  $resultId = 3135;
307  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
308  $resultCode=sprintf($r['Message'], "IdAssetProperty");
309  $message=sprintf($r['Message'], "IdAssetProperty");
310  $type=3;
311  }else{$data['IdAssetProperty']=$entity['IdAssetProperty'];}
312 
313  if(!isset($entity['IdUserAccount'])){
314  $resultId = 3135;
315  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
316  $resultCode=sprintf($r['Message'], "IdUserAccount");
317  $message=sprintf($r['Message'], "IdUserAccount");
318  $type=3;
319  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
320 
321  if(!isset($entity['UserAccountType'])){
322  $resultId = 3135;
323  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
324  $resultCode=sprintf($r['Message'], "UserAccountType");
325  $message=sprintf($r['Message'], "UserAccountType");
326  $type=3;
327  }else{$data['UserAccountType']=$entity['UserAccountType'];}
328 
329  if(!isset($entity['pageSize'])){
330  $_pageSize=$pg['pageSize'];
331  }else{
332  $_pageSize=$entity['pageSize'];
333  }
334 
335  if(!isset($entity['pageNo'])){
336  $_pageNo=$pg['pageNo'];
337  }else{$_pageNo=$entity['pageNo'];}
338 
339  if(!isset($entity['orderColumn'])){
340  $_orderColumn=$pg['orderColumn'];
341  }else{$_orderColumn=$entity['orderColumn'];}
342 
343  if(!isset($entity['orderType'])){
344  $_orderType=$pg['orderType'];
345  }else{
346  switch($entity['orderType'])
347  {
348  case 'ASC':
349  $_orderType="ASC";
350  break;
351  case 'DESC':
352  $_orderType="DESC";
353  break;
354  default:
355  $_orderType="DESC";
356  break;
357  }
358  }
359 
360  if(!isset($entity['orderColumn'])){
361  $_orderColumn=$pg['orderColumn'];
362  }else{
363  switch($entity['orderColumn'])
364  {
365  case 'IdMicroflow':
366  $_orderColumn="IdMicroflow";
367  break;
368  case 'IdAssetProperty':
369  $_orderColumn="IdAssetProperty";
370  break;
371  case 'IdTplMicroflow':
372  $_orderColumn="IdTplMicroflow";
373  break;
374  case 'Name':
375  $_orderColumn="Name";
376  break;
377  case 'IdUserAccount':
378  $_orderColumn="IdUserAccount";
379  break;
380  default:
381  $_orderColumn=$orderColumn;
382  break;
383  }
384 
385  }
386  if($resultId==0){
387  if($data['UserAccountType']=="0"){
388  $IdUserAccount=0;
389  }else{
390  $IdUserAccount=(int)$data['IdUserAccount'];
391  }
392  $IdMicroflow=(int)$data['IdMicroflow'];
393  $IdAssetProperty=(int)$data['IdAssetProperty'];
394 
395  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
396  ->from("Microflow",array("total"=>"COUNT(IdMicroflow)"))
397  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
398  ->where("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow")
399  ->where("IdAssetProperty=$IdAssetProperty OR 0=$IdAssetProperty")
400  );
401 
402  if($count->total==0){
403  $resultId = 3018;
404  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
405  $resultCode=$r['Message'];
406  $message=$r['Message'];
407  $type=3;
408 
409  }else{
410  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
411 
412  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
413  ->from("Microflow","*")
414  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
415  ->where("IdMicroflow=$IdMicroflow OR 0=$IdMicroflow")
416  ->limit($_pageSize, $offset['start'])
417  ->order($_orderColumn." ".$_orderType)
418  );
419  foreach($rows as $row){
420  $resultEntity[]=array("IdMicroflow"=>$row->IdMicroflow,
421  "IdAssetProperty"=>$row->IdAssetProperty,
422  "IdTplMicroflow"=>$row->IdTplMicroflow,
423  "Name"=>$row->Name);
424  }
425 
426  $resultCode=array("pageNo"=>$_pageNo,
427  "pageSize"=>$_pageSize,
428  "pageCount"=>$offset['maxPage'],
429  "orderColumn"=>$_orderColumn,
430  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
431  }
432  }
433  }
434  catch(Exception $e){
435  $resultCode=$e->getMessage();
436  $resultId=101;
437  $type=3;
438  }
439  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
440  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
441  return $response;
442  }
443  //============ End getMicroflow ==============================================================
444 
445 
446  //============ Start getMicroflowCount ==============================================================
447  /*
448  \brief Returneaza (in campul "response") Numarul de Microflow-uri ale unui UserAccount
449  In caz de eroare (resId!=0), campul "response" contine descrierea erorii (tip string).
450  \param[in] $IdUserAccount [Integer] legatura cu tabela UserAccount, acest parametru il baga automat indexcontroller functie de token
451  \exception <3194> Campuri obligatorii nu au fost trimise
452  \return array(resultCode, resultId)
453  \nfmapi Microflow
454 
455  */
456  function getMicroflowCount($entity) {
457  // function implementation
458  $resultId = 0;
459  $page="Microflow.php";
460  $method="getMicroflowCount";
461  $result=json_encode($entity);
462  $message="";
463  $type="1";
464  $this->ErrorCode = new Application_Model_ErrorCode;
465  $this->Log = new Application_Model_Log;
466  $this->Paging = new Application_Model_Paging;
467 
468  try{
469 
470  if(!isset($entity['IdUserAccount'])){
471  $resultId = 3194;
472  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
473  $resultCode=sprintf($r['Message'], "IdUserAccount");
474  $message=sprintf($r['Message'], "IdUserAccount");
475  $type=3;
476  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
477 
478  if($resultId==0){
479  $IdUserAccount=(int)$data['IdUserAccount'];
480 
481  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
482  ->from("Microflow",array("total"=>"COUNT(IdMicroflow)"))
483  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
484  );
485 
486  $resultCode=array("NoOfMicroflow"=>$count->total);
487  }
488  }
489  catch(Exception $e){
490  $resultCode=$e->getMessage();
491  $resultId=101;
492  $type=3;
493  }
494  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
495  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
496  return $response;
497 
498  }
499 
500  //============ End getMicroflowCount ==============================================================
501 
502 }
503 
504 ?>