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