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