Next4Me
 All Classes Files Functions Variables
Address.php
Go to the documentation of this file.
1 <?php
25 class Application_Model_Address extends Zend_Db_Table_Abstract {
26  //put your code here
27  protected $_name="Address";
28  protected $_primary="IdAddress";
29 
30  //==== Start addEditAddress =========================================================================
54  public function addEditAddress($entity) {
55  // function implementation
56  $resultId = 0;
57  $page="Address.php";
58  $method="addEditAddress";
59  $result=json_encode($entity);
60  $message="";
61  $type="1";
62  $this->ErrorCode = new Application_Model_ErrorCode;
63  $this->Log = new Application_Model_Log;
64 
65  try{
66  $data=array();
67  if(!isset($entity['IdAddress'])){
68  $resultId = 3105;
69  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
70  $resultCode=sprintf($r['Message'], "IdAddress");
71  $message=sprintf($r['Message'], "IdAddress");
72  $type=3;
73  }else{$data['IdAddress']=$entity['IdAddress'];}
74 
75  if(!isset($entity['IdUserAccount'])){
76  $resultId = 3105;
77  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
78  $resultCode=sprintf($r['Message'], "IdUserAccount");
79  $message=sprintf($r['Message'], "IdUserAccount");
80  $type=3;
81  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
82 
83  if(!isset($entity['UserAccountType'])){
84  $resultId = 3105;
85  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
86  $resultCode=sprintf($r['Message'], "UserAccountType");
87  $message=sprintf($r['Message'], "UserAccountType");
88  $type=3;
89  }else{$data['UserAccountType']=$entity['UserAccountType'];}
90 
91  if(!isset($entity['Type'])){
92  if($resultId==0 && (int)$entity['IdAddress']==0){
93  $resultId = 3105;
94  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
95  $resultCode=sprintf($r['Message'], "Type");
96  $message=sprintf($r['Message'], "Type");
97  $type=3;
98  }
99  }else{$data['Type']=$entity['Type'];}
100 
101  if(!isset($entity['IdRegion'])){
102  if($resultId==0 && (int)$entity['IdAddress']==0){
103  $resultId = 3105;
104  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
105  $resultCode=sprintf($r['Message'], "IdRegion");
106  $message=sprintf($r['Message'], "IdRegion");
107  $type=3;
108  }
109  }else{$data['IdRegion']=$entity['IdRegion'];}
110 
111  if(!isset($entity['Street'])){
112  if($resultId==0 && (int)$entity['IdAddress']==0){
113  $resultId = 3105;
114  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
115  $resultCode=sprintf($r['Message'], "Street");
116  $message=sprintf($r['Message'], "Street");
117  $type=3;
118  }
119  }else{$data['Street']=$entity['Street'];}
120 
121  if(!isset($entity['Number'])){
122  if($resultId==0 && (int)$entity['IdAddress']==0){
123  $resultId = 3105;
124  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
125  $resultCode=sprintf($r['Message'], "Number");
126  $message=sprintf($r['Message'], "Number");
127  $type=3;
128  }
129  }else{$data['Number']=$entity['Number'];}
130 
131  if(!isset($entity['Building'])){
132  if($resultId==0 && (int)$entity['IdAddress']==0){
133  $resultId = 3105;
134  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
135  $resultCode=sprintf($r['Message'], "Building");
136  $message=sprintf($r['Message'], "Building");
137  $type=3;
138  }
139  }else{$data['Building']=$entity['Building'];}
140 
141  if(!isset($entity['Floor'])){
142  if($resultId==0 && (int)$entity['IdAddress']==0){
143  $resultId = 3105;
144  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
145  $resultCode=sprintf($r['Message'], "Floor");
146  $message=sprintf($r['Message'], "Floor");
147  $type=3;
148  }
149  }else{$data['Floor']=$entity['Floor'];}
150 
151  if(!isset($entity['Appartment'])){
152  if($resultId==0 && (int)$entity['IdAddress']==0){
153  $resultId = 3105;
154  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
155  $resultCode=sprintf($r['Message'], "Appartment");
156  $message=sprintf($r['Message'], "Appartment");
157  $type=3;
158  }
159  }else{$data['Appartment']=$entity['Appartment'];}
160 
161  if(!isset($entity['Lat'])){
162  if($resultId==0 && (int)$entity['IdAddress']==0){
163  $resultId = 3105;
164  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
165  $resultCode=sprintf($r['Message'], "Lat");
166  $message=sprintf($r['Message'], "Lat");
167  $type=3;
168  }
169  }else{$data['Lat']=$entity['Lat'];}
170 
171  if(!isset($entity['Long'])){
172  if($resultId==0 && (int)$entity['IdAddress']==0){
173  $resultId = 3105;
174  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
175  $resultCode=sprintf($r['Message'], "Long");
176  $message=sprintf($r['Message'], "Long");
177  $type=3;
178  }
179  }else{$data['Long']=$entity['Long'];}
180 
181  if(!isset($entity['IdContact'])){
182  if($resultId==0 && (int)$entity['IdAddress']==0){
183  $resultId = 3105;
184  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
185  $resultCode=sprintf($r['Message'], "IdContact");
186  $message=sprintf($r['Message'], "IdContact");
187  $type=3;
188  }
189  }else{$data['IdContact']=$entity['IdContact'];}
190 
191  if(!isset($data)|| $data==null)
192  {
193  $resultId = 3105;
194  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
195  $resultCode=sprintf($r['Message'], "Type,IdRegion,Street,Number,Building,Floor,Appartment,Lat,Long,IdContact");
196  $message=sprintf($r['Message'], "Type,IdRegion,Street,Number,Building,Floor,Appartment,Lat,Long,IdContact");
197  $type=3;
198  }
199 
200  if($data['UserAccountType']=="0"){
201  $IdUserAccount=0;
202  }else{
203  $IdUserAccount=$data['IdUserAccount'];
204  }
205  if($resultId==0){
206  $IdAddress=(int)$data['IdAddress'];
207  if($IdAddress!="0"){
208  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
209  ->from("Address","*")
210  ->where("IdAddress=?",$IdAddress)
211  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
212  );
213  if($rows!=null){
214  $IdContact=$rows->IdContact;
215  if(isset($data['IdContact'])){
216  if($IdContact!=$data['IdContact']){
217  $resultId = 5020;
218  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
219  $resultCode=$r['Message'];
220  $message=$r['Message'];
221  $type=3;
222  }
223  }
224  }else{
225  $resultId = 3106;
226  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
227  $resultCode=$r['Message'];
228  $message=$r['Message'];
229  $type=3;
230  }}
231  }
232  if($resultId==0){
233  unset($data['UserAccountType']);
234  if ($IdAddress=="0"){
235  $k=$this->insert($data);
236  $k=$this->getAdapter()->lastInsertId();
237  $resultCode=$k;
238  }else{
239  unset($data['IdUserAccount']);
240  $this->update($data,$this->getAdapter()->quoteInto('IdAddress=?',$IdAddress));
241  $k=$IdAddress;
242  $resultCode=$k;
243 
244  }
245  }
246  }
247  catch(Exception $e){
248  $resultCode=$e->getMessage();
249  $resultId=101;
250  $type=3;
251  }
252  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
253  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
254  return $response;
255  }
256  //============ End addEditAddress ==============================================================
257 
258 
259  //==== Start deleteAddress =========================================================================
271  function deleteAddress($entity) {
272  // function implementation
273  $resultId = 0;
274  $page="Address.php";
275  $method="deleteAddress";
276  $result=json_encode($entity);
277  $message="";
278  $type="1";
279  $this->ErrorCode = new Application_Model_ErrorCode;
280  $this->Log = new Application_Model_Log;
281 
282  try{
283  if(!isset($entity['IdAddress'])){
284  $resultId = 3125;
285  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
286  $resultCode=sprintf($r['Message'], "IdAddress");
287  $message=sprintf($r['Message'], "IdAddress");
288  $type=3;
289  }else{$data['IdAddress']=$entity['IdAddress'];}
290 
291  if(!isset($entity['IdContact'])){
292  $resultId = 3125;
293  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
294  $resultCode=sprintf($r['Message'], "IdContact");
295  $message=sprintf($r['Message'], "IdContact");
296  $type=3;
297  }else{$data['IdContact']=$entity['IdContact'];}
298 
299  if(!isset($entity['IdUserAccount'])){
300  $resultId = 3125;
301  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
302  $resultCode=sprintf($r['Message'], "IdUserAccount");
303  $message=sprintf($r['Message'], "IdUserAccount");
304  $type=3;
305  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
306 
307  if(!isset($entity['UserAccountType'])){
308  $resultId = 3125;
309  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
310  $resultCode=sprintf($r['Message'], "UserAccountType");
311  $message=sprintf($r['Message'], "UserAccountType");
312  $type=3;
313  }else{$data['UserAccountType']=$entity['UserAccountType'];}
314 
315  if($resultId==0){
316 
317  $IdUserAccount=(int)$data['IdUserAccount'];
318 
319 
320  $IdAddress=(int)$data['IdAddress'];
321  $IdContact=(int)$data['IdContact'];
322 
323  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
324  ->from("Address","*")
325  ->where("IdAddress=$IdAddress OR 0=$IdAddress")
326  ->where("IdUserAccount=$IdUserAccount")
327  ->where("IdContact=$IdContact OR 0=$IdContact")
328  );
329  if($rows==null){
330  $resultId = 3107;
331  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
332  $resultCode=$r['Message'];
333  $message=$r['Message'];
334  $type=3;
335  }else{
336  $k=$this->delete(array("IdAddress=$IdAddress OR 0=$IdAddress",
337  "IdUserAccount=$IdUserAccount OR 0=$IdUserAccount",
338  "IdContact=$IdContact OR 0=$IdContact"));
339  $resultCode="Date sterse";
340  }
341  }
342  }
343  catch(Exception $e){
344  $resultCode=$e->getMessage();
345  $resultId=101;
346  $type=3;
347  }
348  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
349  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
350  return $response;
351  }
352  //============ End deleteAddress ==============================================================
353 
354 
355  //==== Start getAddress =========================================================================
375  function getAddress($entity) {
376  // function implementation
377  $resultId = 0;
378  $page="Address.php";
379  $method="getAddress";
380  $result=json_encode($entity);
381  $message="";
382  $type="1";
383  $this->Paging=new Application_Model_Paging;
384  $this->ErrorCode = new Application_Model_ErrorCode;
385  $this->Log = new Application_Model_Log;
386 
387  try{
388  $pg=$this->Paging->getPageDefault('Address');
389 
390  if(!isset($entity['IdAddress'])){
391  $resultId = 3126;
392  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
393  $resultCode=sprintf($r['Message'], "IdAddress");
394  $message=sprintf($r['Message'], "IdAddress");
395  $type=3;
396  }else{$data['IdAddress']=$entity['IdAddress'];}
397 
398  if(!isset($entity['IdContact'])){
399  $resultId = 3126;
400  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
401  $resultCode=sprintf($r['Message'], "IdContact");
402  $message=sprintf($r['Message'], "IdContact");
403  $type=3;
404  }else{$data['IdContact']=$entity['IdContact'];}
405 
406  if(!isset($entity['IdUserAccount'])){
407  $resultId = 3126;
408  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
409  $resultCode=sprintf($r['Message'], "IdUserAccount");
410  $message=sprintf($r['Message'], "IdUserAccount");
411  $type=3;
412  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
413 
414  if(!isset($entity['UserAccountType'])){
415  $resultId = 3126;
416  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
417  $resultCode=sprintf($r['Message'], "UserAccountType");
418  $message=sprintf($r['Message'], "UserAccountType");
419  $type=3;
420  }else{$data['UserAccountType']=$entity['UserAccountType'];}
421 
422  if(!isset($entity['pageSize'])){
423  $_pageSize=$pg['pageSize'];
424  }else{
425  $_pageSize=$entity['pageSize'];
426  }
427 
428  if(!isset($entity['pageNo'])){
429  $_pageNo=$pg['pageNo'];
430  }else{$_pageNo=$entity['pageNo'];}
431 
432  if(!isset($entity['orderColumn'])){
433  $_orderColumn=$pg['orderColumn'];
434  }else{$_orderColumn=$entity['orderColumn'];}
435 
436  if(!isset($entity['orderType'])){
437  $_orderType=$pg['orderType'];
438  }else{
439  switch($entity['orderType'])
440  {
441  case 'ASC':
442  $_orderType="ASC";
443  break;
444  case 'DESC':
445  $_orderType="DESC";
446  break;
447  default:
448  $_orderType="DESC";
449  break;
450  }
451  }
452 
453  if(!isset($entity['orderColumn'])){
454  $_orderColumn=$pg['orderColumn'];
455  }else{
456  switch($entity['orderColumn'])
457  {
458  case 'IdAddress':
459  $_orderColumn="IdAddress";
460  break;
461  case 'Type':
462  $_orderColumn="Type";
463  break;
464  case 'IdRegion':
465  $_orderColumn="IdRegion";
466  break;
467  case 'Street':
468  $_orderColumn="Street";
469  break;
470  case 'Number':
471  $_orderColumn="Number";
472  break;
473  case 'Building':
474  $_orderColumn="Building";
475  break;
476  case 'Floor':
477  $_orderColumn="Floor";
478  break;
479  case 'Appartment':
480  $_orderColumn="Appartment";
481  break;
482  case 'Lat':
483  $_orderColumn="Lat";
484  break;
485  case 'Long':
486  $_orderColumn="Long";
487  break;
488  case 'IdContact':
489  $_orderColumn="IdContact";
490  break;
491  case 'IdUserAccount':
492  $_orderColumn="IdUserAccount";
493  break;
494  default:
495  $_orderColumn=$orderColumn;
496  break;
497  }
498 
499  }
500 
501  if($resultId==0){
502  if($data['UserAccountType']=="0"){
503  $IdUserAccount=0;
504  }else{
505  $IdUserAccount=$data['IdUserAccount'];
506  }
507 
508 
509  $IdAddress=(int)$data['IdAddress'];
510  $IdContact=(int)$data['IdContact'];
511 
512 
513  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
514  ->from("Address", array("total"=>"COUNT(IdAddress)"))
515  ->where("IdAddress=$IdAddress OR 0=$IdAddress")
516  ->where("IdContact=$IdContact OR 0=$IdContact")
517  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount"));
518  if($count->total!=0){
519  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
520 
521 
522  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
523  ->from("Address", "*")
524  ->where("IdAddress=$IdAddress OR 0=$IdAddress")
525  ->where("IdContact=$IdContact OR 0=$IdContact")
526  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
527  ->limit($_pageSize, $offset['start'])
528  ->order($_orderColumn." ".$_orderType)
529  );
530 
531 
532  foreach($rows as $row){
533 
534  $resultEntity[]=array("IdAddress"=>$row->IdAddress,
535  "Type"=>$row->Type,
536  "IdRegion"=>$row->IdRegion,
537  "Street"=>$row->Street,
538  "Number"=>$row->Number,
539  "Building"=>$row->Building,
540  "Floor"=>$row->Floor,
541  "Appartment"=>$row->Appartment,
542  "Lat"=>$row->Lat,
543  "Long"=>$row->Long,
544  "IdContact"=>$row->IdContact);
545  }
546 
547  $resultCode=array("pageNo"=>$_pageNo,
548  "pageSize"=>$_pageSize,
549  "pageCount"=>$offset['maxPage'],
550  "orderColumn"=>$_orderColumn,
551  "orderType"=>$_orderType,"entity"=>$resultEntity) ;//$count->total;
552  }else{
553  $resultId = 3108;
554  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
555  $resultCode=$r['Message'];
556  $message=$r['Message'];
557  $type=3;
558  }
559  }
560  }
561  catch(Exception $e){
562  $resultCode=$e->getMessage();
563  $resultId=101;
564  $type=3;
565  }
566  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
567  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
568  return $response;
569  }
570  //============ End getAddress ==============================================================
571 
572 }