Next4Me
 All Classes Files Functions Variables
Context.php
Go to the documentation of this file.
1 <?php
19 class Application_Model_Context extends Zend_Db_Table_Abstract {
20  //put your code here
21  protected $_name="Context";
22  protected $_primary="IdContext";
23  protected $_dependentTable=array('ContextCondition');
24 
25  //==== Start addEditContext =========================================================================
41  function addEditContext($entity) {
42  // function implementation
43  $resultId = 0;
44  $page="Context.php";
45  $method="addEditContext";
46  $result=json_encode($entity);
47  $message="";
48  $type="1";
49  $this->ErrorCode = new Application_Model_ErrorCode;
50  $this->Log = new Application_Model_Log;
51 
52  try{
53  $data=array();
54  if(!isset($entity['IdContext'])){
55  $resultId = 3087;
56  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
57  $resultCode=sprintf($r['Message'], "IdContext");
58  $message=sprintf($r['Message'], "IdContext");
59  $type=3;
60  }else{$data['IdContext']=$entity['IdContext'];}
61 
62  if(!isset($entity['IdTplContext'])){
63  if($resultId==0 && $entity['IdContext']=="0"){
64  $resultId = 3087;
65  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
66  $resultCode=sprintf($r['Message'], "IdTplContext");
67  $message=sprintf($r['Message'], "IdTplContext");
68  $type=3;
69  }
70  }else{$data['IdTplContext']=$entity['IdTplContext'];}
71 
72  if(!isset($entity['Name'])){
73  if($resultId==0 && $entity['IdContext']=="0"){
74  $resultId = 3087;
75  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
76  $resultCode=sprintf($r['Message'], "Name");
77  $message=sprintf($r['Message'], "Name");
78  $type=3;
79  }
80  }else{$data['Name']=$entity['Name'];}
81 
82  if(!isset($entity['Description'])){
83  if($resultId==0 && $entity['IdContext']=="0"){
84  $resultId = 3087;
85  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
86  $resultCode=sprintf($r['Message'], "Description");
87  $message=sprintf($r['Message'], "Description");
88  $type=3;
89  }
90  }else{$data['Description']=$entity['Description'];}
91 
92  if(!isset($entity['IdUserAccount'])){
93  if($resultId==0 && $entity['IdContext']=="0"){
94  $resultId = 3087;
95  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
96  $resultCode=sprintf($r['Message'], "IdUserAccount");
97  $message=sprintf($r['Message'], "IdUserAccount");
98  $type=3;
99  }
100  }else{ $data['IdUserAccount']=$entity['IdUserAccount'];}
101  if(!isset($entity['UserAccountType'])){
102  if($resultId==0){
103  $resultId = 3087;
104  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
105  $resultCode=sprintf($r['Message'], "UserAccountType");
106  $message=sprintf($r['Message'], "UserAccountType");
107  $type=3;
108  }
109  }else{ $data['UserAccountType']=$entity['UserAccountType'];}
110 
111 
112  if(!isset($data) && $data==null){
113  $resultId = 3087;
114  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
115  $resultCode=sprintf($r['Message'], "IdTplContext,Name,Description");
116  $message=sprintf($r['Message'], "IdTplContext,Name,Description");
117  $type=3;
118  }
119  if(!isset($data) && $data==null){
120  $resultId = 3087;
121  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
122  $resultCode=sprintf($r['Message'], "IdContext,IdUserAccount,UserAccountType");
123  $message=sprintf($r['Message'], "IdContext,IdUserAccount,UserAccountType");
124  $type=3;
125  }
126  $IdContext=(int)$data['IdContext'];
127  if($data['UserAccountType']=="0"){
128  $IdUserAccount=0;
129  }else{
130  $IdUserAccount=$data['IdUserAccount'];
131  }
132  unset($data['UserAccountType']);
133 
134  if($resultId==0 && $IdContext!="0"){
135  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
136  ->from("Context","*")
137  ->where("IdContext=?",$IdContext)
138  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
139  );
140  if($rows==null){
141  $resultId = 3007;
142  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
143  $resultCode=$r['Message'];
144  $message=$r['Message'];
145  $type=3;
146  }
147  }
148  if($resultId==0){
149  if ($entity['IdContext']=="0"){
150  $k=$this->insert($data);
151  $k=$this->getAdapter()->lastInsertId();
152  $resultCode=$k;
153  }else{
154  unset($data['IdUserAccount']);
155  $this->update($data,$this->getAdapter()->quoteInto('IdContext=?',$IdContext));
156  $k=$entity['IdContext'];
157  $resultCode=$k;
158  }
159  }
160 
161  }
162  catch(Exception $e){
163  $resultCode=$e->getMessage();
164  $resultId=101;
165  $type=3;
166  }
167  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
168  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
169  return $response;
170  }
171  //============ End addEditContext ==============================================================
172 
173 
174  //==== Start deleteContext =========================================================================
186  function deleteContext($entity) {
187  // function implementation
188  $resultId = 0;
189  $page="Context.php";
190  $method="deleteContext";
191  $result=json_encode($entity);
192  $message="";
193  $type="1";
194  $this->ErrorCode = new Application_Model_ErrorCode;
195  $this->Log = new Application_Model_Log;
196 
197  try{
198  $data=array();
199  if(!isset($entity['IdContext'])){
200  $resultId = 3158;
201  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
202  $resultCode=sprintf($r['Message'], "IdContext");
203  $message=sprintf($r['Message'], "IdContext");
204  $type=3;
205  }else{$data['IdContext']=$entity['IdContext'];}
206 
207  if(!isset($entity['IdUserAccount'])){
208  $resultId = 3158;
209  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
210  $resultCode=sprintf($r['Message'], "IdUserAccount");
211  $message=sprintf($r['Message'], "IdUserAccount");
212  $type=3;
213  }else{ $data['IdUserAccount']=$entity['IdUserAccount'];}
214 
215  if(!isset($entity['UserAccountType'])){
216  $resultId = 3158;
217  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
218  $resultCode=sprintf($r['Message'], "UserAccountType");
219  $message=sprintf($r['Message'], "UserAccountType");
220  $type=3;
221  }else{ $data['UserAccountType']=$entity['UserAccountType'];}
222  if($resultId==0){
223  $IdContext=(int)$data['IdContext'];
224  $IdUserAccount=(int)$data['IdUserAccount'];
225 
226 
227  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
228  ->from("Context","*")
229  ->where("IdContext=$IdContext OR 0=$IdContext")
230  ->where("IdUserAccount=$IdUserAccount")
231  );
232  if(count($rows)==0){
233  $resultId = 3008;
234  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
235  $resultCode=$r['Message'];
236  $message=$r['Message'];
237  $type=3;
238  }else{
239  foreach ($rows as $row){
240  if($resultId==0){
241  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
242  ->from("ContextCondition","*")
243  ->where("IdContext=?",$entity['IdContext'])
244  );
245  if($chld!=null){
246  $resultId = 4002;
247  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
248  $resultCode=$r['Message'];
249  $message=$r['Message'];
250  $type=3;
251  }
252  }
253  }
254  }
255  if($resultId==0){
256  $k=$this->delete(array("IdUserAccount=$IdUserAccount",
257  "IdContext=$IdContext OR 0=$IdContext"));
258  $resultCode="Date sterse";
259  }
260  }
261  }
262  catch(Exception $e){
263  $resultCode=$e->getMessage();
264  $resultId=101;
265  $type=3;
266  }
267  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
268  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
269  return $response;
270  }
271  //============ End deleteContext ==============================================================
272 
273 
274  //==== Start getContext =========================================================================
286  function getContext($entity) {
287  // function implementation
288  $resultId = 0;
289  $page="Context.php";
290  $method="getContext";
291  $result=json_encode($entity);
292  $message="";
293  $type="1";
294  $this->ErrorCode = new Application_Model_ErrorCode;
295  $this->Log = new Application_Model_Log;
296  $this->Paging = new Application_Model_Paging;
297 
298  try{
299  $pg=$this->Paging->getPageDefault('Context');
300 
301  $data=array();
302  if(!isset($entity['IdContext']))
303  {
304  $resultId = 3131;
305  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
306  $resultCode=sprintf($r['Message'], "IdContext");
307  $message=sprintf($r['Message'], "IdContext");
308  $type=3;
309  }else{$data['IdContext']=$entity['IdContext'];}
310 
311  if(!isset($entity['IdUserAccount'])){
312  $resultId = 3131;
313  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
314  $resultCode=sprintf($r['Message'], "IdUserAccount");
315  $message=sprintf($r['Message'], "IdUserAccount");
316  $type=3;
317  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
318 
319  if(!isset($entity['UserAccountType'])){
320  $resultId = 3131;
321  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
322  $resultCode=sprintf($r['Message'], "UserAccountType");
323  $message=sprintf($r['Message'], "UserAccountType");
324  $type=3;
325  }else{$data['UserAccountType']=$entity['UserAccountType'];}
326 
327  if(!isset($entity['IdStatus'])){
328  $resultId = 3131;
329  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
330  $resultCode=sprintf($r['Message'], "IdStatus");
331  $message=sprintf($r['Message'], "IdStatus");
332  $type=3;
333  }else{$data['IdStatus']=$entity['IdStatus'];}
334 
335  if(!isset($entity['pageSize'])){
336  $_pageSize=$pg['pageSize'];
337  }else{
338  $_pageSize=$entity['pageSize'];
339  }
340 
341  if(!isset($entity['pageNo'])){
342  $_pageNo=$pg['pageNo'];
343  }else{$_pageNo=$entity['pageNo'];}
344 
345  if(!isset($entity['orderColumn'])){
346  $_orderColumn=$pg['orderColumn'];
347  }else{$_orderColumn=$entity['orderColumn'];}
348 
349  if(!isset($entity['orderType'])){
350  $_orderType=$pg['orderType'];
351  }else{
352  switch($entity['orderType'])
353  {
354  case 'ASC':
355  $_orderType="ASC";
356  break;
357  case 'DESC':
358  $_orderType="DESC";
359  break;
360  default:
361  $_orderType="DESC";
362  break;
363  }
364  }
365 
366  if(!isset($entity['orderColumn'])){
367  $_orderColumn=$pg['orderColumn'];
368  }else{
369  switch($entity['orderColumn'])
370  {
371  case 'IdContext':
372  $_orderColumn="IdContext";
373  break;
374  case 'IdTplContext':
375  $_orderColumn="IdTplContext";
376  break;
377  case 'Name':
378  $_orderColumn="Name";
379  break;
380  case 'Description':
381  $_orderColumn="Description";
382  break;
383  case 'IdUserAccount':
384  $_orderColumn="IdUserAccount";
385  break;
386  default:
387  $_orderColumn=$orderColumn;
388  break;
389  }
390 
391  }
392  if($resultId==0){
393  if($data['UserAccountType']=="0"){
394  $IdUserAccount=0;
395  }else{
396  $IdUserAccount=(int)$data['IdUserAccount'];
397  }
398  $IdContext=(int)$data['IdContext'];
399  $IdStatus = (int)$data['IdStatus'];
400 
401  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
402  ->from("Context",array("total"=>"COUNT(IdContext)"))
403  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
404  ->where("IdContext=$IdContext OR 0=$IdContext")
405  ->where("IdStatus<=$IdStatus OR 0=$IdStatus")
406  );
407 
408  if($count->total==0){
409 
410  $resultId = 3009;
411  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
412  $resultCode=$r['Message'];
413  $message=$r['Message'];
414  $type=3;
415  }else{
416  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
417 
418  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
419  ->from("Context","*")
420  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
421  ->where("IdContext=$IdContext OR 0=$IdContext")
422  ->where("IdStatus<$IdStatus OR 0=$IdStatus")
423  ->limit($_pageSize, $offset['start'])
424  ->order($_orderColumn." ".$_orderType)
425  );
426  foreach($rows as $row){
427 
428  $resultEntity[]=array("IdContext"=>$row->IdContext,
429  "IdTplContext"=>$row->IdTplContext,
430  "Name"=>$row->Name,
431  "Description"=>$row->Description,
432  "IdUserAccount"=>$row->IdUserAccount,
433  "IdStatus"=>$row->IdStatus
434  );
435  }
436 
437  $resultCode=array("pageNo"=>$_pageNo,
438  "pageSize"=>$_pageSize,
439  "pageCount"=>$offset['maxPage'],
440  "orderColumn"=>$_orderColumn,
441  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
442  }
443  }
444  }
445  catch(Exception $e){
446  $resultCode=$e->getMessage();
447  $resultId=101;
448  $type=3;
449  }
450  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
451  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
452  return $response;
453  }
454  //============ End getContext ==============================================================
455 
456 }