Next4Me
 All Classes Files Functions Variables
ContextFactor.php
Go to the documentation of this file.
1 <?php
18 class Application_Model_ContextFactor extends Zend_Db_Table_Abstract {
19  //put your code here
20  protected $_name="ContextFactor";
21  protected $_primary="IdContextFactor";
22  protected $_referenceMap=array(
23  'ContextFactor'=>array(
24  'columns'=>array('IdContextCondition'),
25  'refTableClass'=>'ContextCondition',
26  'refColumns'=>array('IdContextCondition')
27  )
28  );
29 
30  //==== Start addEditContextFactor =========================================================================
51  function addEditContextFactor($entity) {
52  // function implementation
53  $resultId = 0;
54  $page="ContextFactor.php";
55  $method="addEditContextFactor";
56  $result=json_encode($entity);
57  $message="";
58  $type="1";
59  $this->ErrorCode = new Application_Model_ErrorCode;
60  $this->Log = new Application_Model_Log;
61 
62  try{
63  $data=array();
64  if(!isset($entity['IdContextFactor'])){
65  $resultId = 3089;
66  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
67  $resultCode=sprintf($r['Message'], "IdContextFactor");
68  $message=sprintf($r['Message'], "IdContextFactor");
69  $type=3;
70  }else{$data['IdContextFactor']=$entity['IdContextFactor'];}
71 
72  if(!isset($entity['IdContextCondition'])){
73  if($resultId==0 && $entity['IdContextFactor']=="0"){
74  $resultId = 3089;
75  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
76  $resultCode=sprintf($r['Message'], "IdContextCondition");
77  $message=sprintf($r['Message'], "IdContextCondition");
78  $type=3;
79  }
80  }else{$data['IdContextCondition']=$entity['IdContextCondition'];}
81 
82  if(!isset($entity['IdTplContextFactor'])){
83  if($resultId==0 && $entity['IdContextFactor']=="0"){
84  $resultId = 3089;
85  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
86  $resultCode=sprintf($r['Message'], "IdTplContextFactor");
87  $message=sprintf($r['Message'], "IdTplContextFactor");
88  $type=3;
89  }
90  }else{$data['IdTplContextFactor']=$entity['IdTplContextFactor'];}
91 
92  if(!isset($entity['Description'])){
93  if($resultId==0 && $entity['IdContextFactor']=="0"){
94  $resultId = 3089;
95  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
96  $resultCode=sprintf($r['Message'], "Description");
97  $message=sprintf($r['Message'], "Description");
98  $type=3;
99  }
100  }else{$data['Description']=$entity['Description'];}
101 
102  if(!isset($entity['Type'])){
103  if($resultId==0 && $entity['IdContextFactor']=="0"){
104  $resultId = 3089;
105  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
106  $resultCode=sprintf($r['Message'], "Type");
107  $message=sprintf($r['Message'], "Type");
108  $type=3;
109  }
110  }else{$data['Type']=$entity['Type'];}
111 
112  if(!isset($entity['Function'])){
113  if($resultId==0 && $entity['IdContextFactor']=="0"){
114  $resultId = 3089;
115  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
116  $resultCode=sprintf($r['Message'], "Function");
117  $message=sprintf($r['Message'], "Function");
118  $type=3;
119  }
120  }else{$data['Function']=$entity['Function'];}
121 
122  if(!isset($entity['Value'])){
123  if($resultId==0 && $entity['IdContextFactor']=="0"){
124  $resultId = 3089;
125  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
126  $resultCode=sprintf($r['Message'], "Value");
127  $message=sprintf($r['Message'], "Value");
128  $type=3;
129  }
130  }else{$data['Value']=$entity['Value'];}
131 
132  if(!isset($entity['IdUserAccount'])){
133  $resultId = 3089;
134  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
135  $resultCode=sprintf($r['Message'], "IdUserAccount");
136  $message=sprintf($r['Message'], "IdUserAccount");
137  $type=3;
138  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
139 
140  if(!isset($entity['UserAccountType'])){
141  $resultId = 3089;
142  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
143  $resultCode=sprintf($r['Message'], "UserAccountType");
144  $message=sprintf($r['Message'], "UserAccountType");
145  $type=3;
146  }else{$data['UserAccountType']=$entity['UserAccountType'];}
147 
148  if(!isset($data) && $data==null){
149  $resultId = 3089;
150  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
151  $resultCode=sprintf($r['Message'], "IdContextCondition,IdTplContextFactor,Description,Type,Function,Value");
152  $message=sprintf($r['Message'], "IdContextCondition,IdTplContextFactor,Description,Type,Function,Value");
153  $type=3;
154  }
155  if($resultId==0){
156  if($data['UserAccountType']=="0"){
157  $IdUserAccount=0;
158  }else{
159  $IdUserAccount=(int)$data['IdUserAccount'];
160  }
161  $IdContextFactor=(int)$data['IdContextFactor'];
162  $IdContextCondition=(int)$data['IdContextCondition'];
163  unset($data['UserAccountType']);
164  if ($IdContextFactor!="0"){
165  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
166  ->from("ContextFactor","*")
167  ->where("IdContextFactor=$IdContextFactor")
168  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
169  );
170  if($rows!=null){
171  $IdContextCondition=$rows->IdContextCondition;
172  if($data['IdContextCondition']){
173  if($IdContextCondition!=$data['IdContextCondition']){
174  $resultId = 5003;
175  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
176  $resultCode=$r['Message'];
177  $message=$r['Message'];
178  $type=3;
179  }
180  }
181  }else{
182  $resultId = 3013;
183  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
184  $resultCode=$r['Message'];
185  $message=$r['Message'];
186  $type=3;
187  }
188  }
189  }
190  if($resultId==0){
191  if ($IdContextFactor=="0"){
192  $k=$this->insert($data);
193  $k=$this->getAdapter()->lastInsertId();
194  $resultCode=$k;
195  }else{
196  unset($data['IdUserAccount']);
197  $this->update($data,$this->getAdapter()->quoteInto('IdContextFactor=?',$IdContextFactor));
198  $k=$entity['IdContextFactor'];
199  $resultCode=$k;
200  }
201  }
202  }
203  catch(Exception $e){
204  $resultCode=$e->getMessage();
205  $resultId=101;
206  $type=3;
207  }
208  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
209  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
210  return $response;
211  }
212  //============ End addEditContextFactor ==============================================================
213 
214 
215  //==== Start deleteContextFactor =========================================================================
228  function deleteContextFactor($entity) {
229  // function implementation
230  $resultId = 0;
231  $page="ContextFactor.php";
232  $method="deleteContextFactor";
233  $result=json_encode($entity);
234  $message="";
235  $type="1";
236  $this->ErrorCode = new Application_Model_ErrorCode;
237  $this->Log = new Application_Model_Log;
238 
239  try{
240  $data=array();
241  if(!isset($entity['IdContextFactor'])){
242  $resultId = 3160;
243  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
244  $resultCode=sprintf($r['Message'], "IdContextFactor");
245  $message=sprintf($r['Message'], "IdContextFactor");
246  $type=3;
247  }else{$data['IdContextFactor']=$entity['IdContextFactor'];}
248 
249  if(!isset($entity['IdContextCondition'])){
250  if($resultId==0 && $entity['IdContextFactor']=="0"){
251  $resultId = 3160;
252  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
253  $resultCode=sprintf($r['Message'], "IdContextCondition");
254  $message=sprintf($r['Message'], "IdContextCondition");
255  $type=3;
256  }
257  }else{$data['IdContextCondition']=$entity['IdContextCondition'];}
258 
259  if(!isset($entity['IdUserAccount'])){
260  $resultId = 3160;
261  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
262  $resultCode=sprintf($r['Message'], "IdUserAccount");
263  $message=sprintf($r['Message'], "IdUserAccount");
264  $type=3;
265  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
266 
267  if(!isset($entity['UserAccountType'])){
268  $resultId = 3160;
269  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
270  $resultCode=sprintf($r['Message'], "UserAccountType");
271  $message=sprintf($r['Message'], "UserAccountType");
272  $type=3;
273  }else{$data['UserAccountType']=$entity['UserAccountType'];}
274 
275  if(!isset($data) && $data==null){
276  $resultId = 3160;
277  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
278  $resultCode=sprintf($r['Message'], "IdContextCondition,IdContextFactor,UserAccountType,IdUserAccount");
279  $message=sprintf($r['Message'], "IdContextCondition,IdContextFactor,UserAccountType,IdUserAccount");
280  $type=3;
281  }
282 
283  if($resultId==0){
284  $IdContextCondition=(int)$data['IdContextCondition'];
285  $IdContextFactor=(int)$data['IdContextFactor'];
286  $IdUserAccount=(int)$data['IdUserAccount'];
287 
288  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
289  ->from("ContextFactor","*")
290  ->where("IdContextCondition=$IdContextCondition OR 0=$IdContextCondition")
291  ->where("IdContextFactor=$IdContextFactor OR 0=$IdContextFactor")
292  ->where("IdUserAccount=$IdUserAccount")
293  );
294  if($rows==null){
295  $resultId = 3014;
296  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
297  $resultCode=$r['Message'];
298  $message=$r['Message'];
299  $type=3;
300  }else{
301  $k=$this->delete(array("IdContextCondition=$IdContextCondition OR 0=$IdContextCondition",
302  "IdContextFactor=$IdContextFactor OR 0=$IdContextFactor",
303  "IdUserAccount=$IdUserAccount"));
304  $resultCode="Date sterse";
305  }
306  }
307  }
308  catch(Exception $e){
309  $resultCode=$e->getMessage();
310  $resultId=101;
311  $type=3;
312  }
313  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
314  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
315  return $response;
316  }
317  //============ End deleteContextFactor ==============================================================
318 
319 
320  //==== Start getContextFactor =========================================================================
337  function getContextFactor($entity) {
338  // function implementation
339  $resultId = 0;
340  $page="ContextFactor.php";
341  $method="getContextFactor";
342  $result=json_encode($entity);
343  $message="";
344  $type="1";
345  $this->ErrorCode = new Application_Model_ErrorCode;
346  $this->Log = new Application_Model_Log;
347  $this->Paging = new Application_Model_Paging;
348 
349  try{
350  $pg=$this->Paging->getPageDefault('ContextFactor');
351 
352  $data=array();
353  if(!isset($entity['IdContextFactor']))
354  {
355  $resultId = 3133;
356  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
357  $resultCode=sprintf($r['Message'], "IdContextFactor");
358  $message=sprintf($r['Message'], "IdContextFactor");
359  $type=3;
360  }else{$data['IdContextFactor']=$entity['IdContextFactor'];}
361 
362  if(!isset($entity['IdContextCondition']))
363  {
364  $resultId = 3133;
365  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
366  $resultCode=sprintf($r['Message'], "IdContextCondition");
367  $message=sprintf($r['Message'], "IdContextCondition");
368  $type=3;
369  }else{$data['IdContextCondition']=$entity['IdContextCondition'];}
370 
371  if(!isset($entity['Type'])){
372 
373  }else{
374  $entity['Type']=$data['Type'];
375  }
376 
377  if(!isset($entity['Function'])){
378 
379  }else{
380  $entity['Function']=$data['Function'];
381  }
382 
383  if(!isset($entity['Value'])){
384 
385  }else{
386  $entity['Value']=$data['Value'];
387  }
388 
389  if(!isset($entity['IdUserAccount'])){
390  $resultId = 3133;
391  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
392  $resultCode=sprintf($r['Message'], "IdUserAccount");
393  $message=sprintf($r['Message'], "IdUserAccount");
394  $type=3;
395  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
396 
397  if(!isset($entity['UserAccountType'])){
398  $resultId = 3133;
399  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
400  $resultCode=sprintf($r['Message'], "UserAccountType");
401  $message=sprintf($r['Message'], "UserAccountType");
402  $type=3;
403  }else{$data['UserAccountType']=$entity['UserAccountType'];}
404 
405  if(!isset($entity['pageSize'])){
406  $_pageSize=$pg['pageSize'];
407  }else{
408  $_pageSize=$entity['pageSize'];
409  }
410 
411  if(!isset($entity['pageNo'])){
412  $_pageNo=$pg['pageNo'];
413  }else{$_pageNo=$entity['pageNo'];}
414 
415  if(!isset($entity['orderColumn'])){
416  $_orderColumn=$pg['orderColumn'];
417  }else{$_orderColumn=$entity['orderColumn'];}
418 
419  if(!isset($entity['orderType'])){
420  $_orderType=$pg['orderType'];
421  }else{
422  switch($entity['orderType'])
423  {
424  case 'ASC':
425  $_orderType="ASC";
426  break;
427  case 'DESC':
428  $_orderType="DESC";
429  break;
430  default:
431  $_orderType="DESC";
432  break;
433  }
434  }
435 
436  if(!isset($entity['orderColumn'])){
437  $_orderColumn=$pg['orderColumn'];
438  }else{
439  switch($entity['orderColumn'])
440  {
441  case 'IdContextFactor':
442  $_orderColumn="IdContextFactor";
443  break;
444  case 'IdContextCondition':
445  $_orderColumn="IdContextCondition";
446  break;
447  case 'IdTplContextFactor':
448  $_orderColumn="IdTplContextFactor";
449  break;
450  case 'Description':
451  $_orderColumn="Description";
452  break;
453  case 'Type':
454  $_orderColumn="Type";
455  break;
456  case 'Function':
457  $_orderColumn="Function";
458  break;
459  case 'Value':
460  $_orderColumn="Value";
461  break;
462  case 'IdUserAccount':
463  $_orderColumn="IdUserAccount";
464  break;
465  default:
466  $_orderColumn=$orderColumn;
467  break;
468  }
469 
470  }
471  if($resultId==0){
472  if($data['UserAccountType']=="0"){
473  $IdUserAccount=0;
474  }else{
475  $IdUserAccount=(int)$data['IdUserAccount'];
476  }
477  $IdContextFactor=(int)$data['IdContextFactor'];
478  $IdContextCondition=(int)$data['IdContextCondition'];
479 
480 
481  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
482  ->from("ContextFactor",array("total"=>"COUNT(IdContextFactor)"))
483  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
484  ->where("IdContextFactor=$IdContextFactor OR 0=$IdContextFactor")
485  ->where("IdContextCondition=$IdContextCondition OR 0=$IdContextCondition")
486  );
487 
488  if($count->total==0){
489  $resultId = 3015;
490  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
491  $resultCode=$r['Message'];
492  $message=$r['Message'];
493  $type=3;
494 
495  }else{
496  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
497 
498  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
499  ->from("ContextFactor","*")
500  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
501  ->where("IdContextFactor=$IdContextFactor OR 0=$IdContextFactor")
502  ->where("IdContextCondition=$IdContextCondition OR 0=$IdContextCondition")
503  ->limit($_pageSize, $offset['start'])
504  ->order($_orderColumn." ".$_orderType)
505  );
506 
507  foreach($rows as $row){
508 
509  $resultEntity[]=array("IdContextFactor"=>$row->IdContextFactor,
510  "IdContextCondition"=>$row->IdContextCondition,
511  "IdTplContextFactor"=>$row->IdTplContextFactor,
512  "Description"=>$row->Description,
513  "Type"=>$row->Type,
514  "Function"=>$row->Function,
515  "Value"=>$row->Value);
516  }
517  $resultCode=array("pageNo"=>$_pageNo,
518  "pageSize"=>$_pageSize,
519  "pageCount"=>$offset['maxPage'],
520  "orderColumn"=>$_orderColumn,
521  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
522  }
523  }
524  }
525  catch(Exception $e){
526  $resultCode=$e->getMessage();
527  $resultId=101;
528  $type=3;
529  }
530  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
531  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
532  return $response;
533  }
534  //============ End getContextFactor ==============================================================
535 
536 }