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