Next4Me
 All Classes Files Functions Variables
Language.php
Go to the documentation of this file.
1 <?php
2 
26 class Application_Model_Language extends Zend_Db_Table_Abstract {
27  //put your code here
28  protected $_name="Language";
29  protected $_primary="IdLanguage";
30 
31  //==== Start addEditLanguage =========================================================================
45  function addEditChannel($entity) {
46  // function implementation
47  $resultId = 0;
48  $page="Language.php";
49  $method="addEditLanguage";
50  $result=json_encode($entity);
51  $message="";
52  $type="1";
53  $this->ErrorCode = new Application_Model_ErrorCode;
54  $this->Log = new Application_Model_Log;
55 
56  try{
57  $data=array();
58  if(!isset($entity['IdLanguage'])){
59  $resultId = 3188;
60  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
61  $resultCode=sprintf($r['Message'], "IdLanguage");
62  $message=sprintf($r['Message'], "IdLanguage");
63  $type=3;
64  }else{$data['IdLanguage']=$entity['IdLanguage'];}
65 
66  if(!isset($entity['Name'])){
67  if($resultId==0 && (int)$entity['IdLanguage']==0){
68  $resultId = 3188;
69  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
70  $resultCode=sprintf($r['Message'], "Name");
71  $message=sprintf($r['Message'], "Name");
72  $type=3;
73  }
74  }else{$data['Name']=$entity['Name'];}
75 
76  if(!isset($entity['Code'])){
77  if($resultId==0 && (int)$entity['IdLanguage']==0){
78  $resultId = 3188;
79  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
80  $resultCode=sprintf($r['Message'], "Code");
81  $message=sprintf($r['Message'], "Code");
82  $type=3;
83  }
84  }else{$data['Code']=$entity['Code'];}
85 
86  if(!isset($entity['Activ'])){
87  if($resultId==0 && (int)$entity['IdChannel']==0){
88  $resultId = 3188;
89  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
90  $resultCode=sprintf($r['Message'], "Activ");
91  $message=sprintf($r['Message'], "Activ");
92  $type=3;
93  }
94  }else{$data['Activ']=$entity['Activ'];}
95 
96  if(!isset($entity['IdUserAccount'])){
97  $resultId = 3188;
98  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
99  $resultCode=sprintf($r['Message'], "IdUserAccount");
100  $message=sprintf($r['Message'], "IdUserAccount");
101  $type=3;
102  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
103 
104  if(!isset($entity['UserAccountType'])){
105  $resultId = 3188;
106  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
107  $resultCode=sprintf($r['Message'], "UserAccountType");
108  $message=sprintf($r['Message'], "UserAccountType");
109  $type=3;
110  }else{$data['UserAccountType']=$entity['UserAccountType'];}
111 
112  if(!isset($data)|| $data==null)
113  {
114  $resultId = 3188;
115  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
116  $resultCode=sprintf($r['Message'], "IdLanguage,Name,Code,Activ");
117  $message=sprintf($r['Message'], "IdLanguage,Name,Code,Activ");
118  $type=3;
119  }
120 
121  if($resultId==0){
122  if($data['UserAccountType']=="0"){
123  $IdUserAccount=0;
124  }else{
125  $IdUserAccount=(int)$data['IdUserAccount'];
126  }
127  $IdChannel=(int)$data['IdChannel'];
128  unset($data['UserAccountType']);
129  unset($data['IdUserAccount']);
130  if($IdChannel=="0"){
131  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
132  ->from("Language","*")
133  ->where("IdLanguage=?",$IdLanguage)
134  );
135  if($rows==null){
136  $resultId = 3189;
137  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
138  $resultCode=$r['Message'];
139  $message=$r['Message'];
140  $type=3;
141  }
142  }
143  }
144  if($resultId==0){
145  if ($IdLanguage=="0"){
146  $k=$this->insert($data);
147  $k=$this->getAdapter()->lastInsertId();
148  $resultCode=$k;
149  }else{
150 
151  $this->update($data,$this->getAdapter()->quoteInto('IdLanguage=?',$IdLanguage));
152  $k=$entity['IdLanguage'];
153  $resultCode=$k;
154 
155  }
156  }
157  }
158  catch(Exception $e){
159  $resultCode=$e->getMessage();
160  $resultId=101;
161  $type=3;
162  }
163  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
164  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
165  return $response;
166  }
167  //============ End addEditLanguage ==============================================================
168 
169 
170  //==== Start deleteLanguage =========================================================================
179  function deleteLanguage($entity) {
180  // function implementation
181  $resultId = 0;
182  $page="Language.php";
183  $method="deleteLanguage";
184  $result=json_encode($entity);
185  $message="";
186  $type="1";
187  $this->ErrorCode = new Application_Model_ErrorCode;
188  $this->Log = new Application_Model_Log;
189 
190  try{
191  $data=array();
192  if(!isset($entity['IdLanguage'])){
193  $resultId = 3191;
194  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
195  $resultCode=sprintf($r['Message'], "IdLanguage");
196  $message=sprintf($r['Message'], "IdLanguage");
197  $type=3;
198  }else{$data['IdLanguage']=$entity['IdLanguage'];}
199 
200  if(!isset($entity['IdUserAccount'])){
201  $resultId = 3191;
202  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
203  $resultCode=sprintf($r['Message'], "IdUserAccount");
204  $message=sprintf($r['Message'], "IdUserAccount");
205  $type=3;
206  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
207 
208  if(!isset($entity['UserAccountType'])){
209  $resultId = 3191;
210  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
211  $resultCode=sprintf($r['Message'], "UserAccountType");
212  $message=sprintf($r['Message'], "UserAccountType");
213  $type=3;
214  }else{$data['UserAccountType']=$entity['UserAccountType'];}
215 
216  if(!isset($data)|| $data==null)
217  {
218  $resultId = 3191;
219  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
220  $resultCode=sprintf($r['Message'], "IdChannel,IdChannelType");
221  $message=sprintf($r['Message'], "IdChannel,IdChannelType");
222  $type=3;
223  }
224  if($resultId==0){
225 
226  $IdUserAccount=(int)$data['IdUserAccount'];
227  $IdLanguage=(int)$data['IdLanguage'];
228 
229  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
230  ->from("Language","*")
231  ->where("IdLanguage=$IdLanguage")
232  );
233  if($rows==null){
234  $resultId = 3190;
235  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
236  $resultCode=$r['Message'];
237  $message=$r['Message'];
238  $type=3;
239  }else{
240  $k=$this->delete(array("IdLanguage=$IdLanguage"));
241  $resultCode="Date sterse";
242  }
243  }
244  }
245  catch(Exception $e){
246  $resultCode=$e->getMessage();
247  $resultId=101;
248  $type=3;
249  }
250  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
251  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
252  return $response;
253  }
254  //============ End deleteLanguage ==============================================================
255 
256 
257  //==== Start getLanguage =========================================================================
275  function getLanguage($entity) {
276  // function implementation
277  $resultId = 0;
278  $page="Language.php";
279  $method="getLanguage";
280  $result=json_encode($entity);
281  $message="";
282  $type="1";
283  $this->ErrorCode = new Application_Model_ErrorCode;
284  $this->Log = new Application_Model_Log;
285  $this->Paging = new Application_Model_Paging;
286 
287  try{
288  $pg=$this->Paging->getPageDefault('Language');
289 
290  $data=array();
291  if(!isset($entity['IdLanguage']))
292  {
293  $resultId = 3192;
294  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
295  $resultCode=sprintf($r['Message'], "IdLanguage");
296  $message=sprintf($r['Message'], "IdLanguage");
297  $type=3;
298  }else{$data['IdLanguage']=$entity['IdLanguage'];}
299 
300  if(!isset($entity['IdUserAccount'])){
301  $resultId = 3192;
302  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
303  $resultCode=sprintf($r['Message'], "IdUserAccount");
304  $message=sprintf($r['Message'], "IdUserAccount");
305  $type=3;
306  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
307 
308  if(!isset($entity['UserAccountType'])){
309  $resultId = 3192;
310  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
311  $resultCode=sprintf($r['Message'], "UserAccountType");
312  $message=sprintf($r['Message'], "UserAccountType");
313  $type=3;
314  }else{$data['UserAccountType']=$entity['UserAccountType'];}
315 
316  if(!isset($entity['pageSize'])){
317  $_pageSize=$pg['pageSize'];
318  }else{
319  $_pageSize=$entity['pageSize'];
320  }
321 
322  if(!isset($entity['pageNo'])){
323  $_pageNo=$pg['pageNo'];
324  }else{$_pageNo=$entity['pageNo'];}
325 
326  if(!isset($entity['orderColumn'])){
327  $_orderColumn=$pg['orderColumn'];
328  }else{$_orderColumn=$entity['orderColumn'];}
329 
330  if(!isset($entity['orderType'])){
331  $_orderType=$pg['orderType'];
332  }else{
333  switch($entity['orderType'])
334  {
335  case 'ASC':
336  $_orderType="ASC";
337  break;
338  case 'DESC':
339  $_orderType="DESC";
340  break;
341  default:
342  $_orderType="DESC";
343  break;
344  }
345  }
346 
347  if(!isset($entity['orderColumn'])){
348  $_orderColumn=$pg['orderColumn'];
349  }else{
350  switch($entity['orderColumn'])
351  {
352  case 'IdLanguage':
353  $_orderColumn="IdLanguage";
354  break;
355  case 'Name':
356  $_orderColumn="Name";
357  break;
358  case 'Code':
359  $_orderColumn="Code";
360  break;
361  case 'Activ':
362  $_orderColumn="Activ";
363  break;
364  default:
365  $_orderColumn=$orderColumn;
366  break;
367  }
368 
369  }
370  if($resultId==0){
371  if($data['UserAccountType']=="0"){
372  $IdUserAccount=0;
373  }else{
374  $IdUserAccount=(int)$data['IdUserAccount'];
375  }
376  $IdLanguage=(int)$data['IdLanguage'];
377 
378  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
379  ->from("Language",array("total"=>"COUNT(IdLanguage)"))
380  ->where("IdLanguage=$IdLanguage OR 0=$IdLanguage")
381  );
382 
383  if($count->total==0){
384  $resultId = 3193;
385  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
386  $resultCode=$r['Message'];
387  $message=$r['Message'];
388  $type=3;
389  }else{
390  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
391 
392  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
393  ->from("Language","*")
394  ->where("IdLanguage=$IdLanguage OR 0=$IdLanguage")
395  ->limit($_pageSize, $offset['start'])
396  ->order($_orderColumn." ".$_orderType)
397  );
398  foreach($rows as $row){
399  $resultEntity[]=array("IdLanguage"=>$row->IdLanguage,
400  "Name"=>$row->Name,
401  "Code"=>$row->Code,
402  "Activ"=>$row->Activ);
403  }
404  $resultCode=array("pageNo"=>$_pageNo,
405  "pageSize"=>$_pageSize,
406  "pageCount"=>$offset['maxPage'],
407  "orderColumn"=>$_orderColumn,
408  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
409  }
410  }
411  }
412  catch(Exception $e){
413  $resultCode=$e->getMessage();
414  $resultId=101;
415  $type=3;
416  }
417  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
418  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
419  return $response;
420  }
421  //============ End getLanguage ==============================================================
422 
423 }
424 
425 ?>