Next4Me
 All Classes Files Functions Variables
Channel.php
Go to the documentation of this file.
1 <?php
20 class Application_Model_Channel extends Zend_Db_Table_Abstract {
21  //put your code here
22  protected $_name="Channel";
23  protected $_primary="IdChannel";
24 
25  //==== Start addEditChannel =========================================================================
41  function addEditChannel($entity) {
42  // function implementation
43  $resultId = 0;
44  $page="Channel.php";
45  $method="addEditChannel";
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['IdChannel'])){
55  $resultId = 3188;
56  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
57  $resultCode=sprintf($r['Message'], "IdChannel");
58  $message=sprintf($r['Message'], "IdChannel");
59  $type=3;
60  }else{$data['IdChannel']=$entity['IdChannel'];}
61 
62  if(!isset($entity['IdChannelType'])){
63  if($resultId==0 && (int)$entity['IdChannel']==0){
64  $resultId = 3188;
65  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
66  $resultCode=sprintf($r['Message'], "IdChannelType");
67  $message=sprintf($r['Message'], "IdChannelType");
68  $type=3;
69  }
70  }else{$data['IdChannelType']=$entity['IdChannelType'];}
71 
72  if(!isset($entity['ChannelName'])){
73  if($resultId==0 && (int)$entity['IdChannel']==0){
74  $resultId = 3188;
75  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
76  $resultCode=sprintf($r['Message'], "ChannelName");
77  $message=sprintf($r['Message'], "ChannelName");
78  $type=3;
79  }
80  }else{$data['ChannelName']=$entity['ChannelName'];}
81 
82  if(!isset($entity['Target'])){
83  if($resultId==0 && (int)$entity['IdChannel']==0){
84  $resultId = 3188;
85  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
86  $resultCode=sprintf($r['Message'], "Target");
87  $message=sprintf($r['Message'], "Target");
88  $type=3;
89  }
90  }else{$data['Target']=$entity['Target'];}
91 
92  if(!isset($entity['Activ'])){
93  if($resultId==0 && (int)$entity['IdChannel']==0){
94  $resultId = 3188;
95  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
96  $resultCode=sprintf($r['Message'], "Activ");
97  $message=sprintf($r['Message'], "Activ");
98  $type=3;
99  }
100  }else{$data['Activ']=$entity['Activ'];}
101 
102  if(!isset($entity['IdUserAccount'])){
103  $resultId = 3188;
104  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
105  $resultCode=sprintf($r['Message'], "IdUserAccount");
106  $message=sprintf($r['Message'], "IdUserAccount");
107  $type=3;
108  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
109 
110  if(!isset($entity['UserAccountType'])){
111  $resultId = 3188;
112  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
113  $resultCode=sprintf($r['Message'], "UserAccountType");
114  $message=sprintf($r['Message'], "UserAccountType");
115  $type=3;
116  }else{$data['UserAccountType']=$entity['UserAccountType'];}
117 
118  if(!isset($data)|| $data==null)
119  {
120  $resultId = 3188;
121  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
122  $resultCode=sprintf($r['Message'], "IdChannel,IdChannelType,ChannelName,Target,Activ");
123  $message=sprintf($r['Message'], "IdChannel,IdChannelType,ChannelName,Target,Activ");
124  $type=3;
125  }
126 
127  if($resultId==0){
128  if($data['UserAccountType']=="0"){
129  $IdUserAccount=0;
130  }else{
131  $IdUserAccount=(int)$data['IdUserAccount'];
132  }
133  $IdChannel=(int)$data['IdChannel'];
134  unset($data['UserAccountType']);
135 
136  if($IdChannel!="0"){
137  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
138  ->from("Channel","*")
139  ->where("IdChannel=?",$IdChannel)
140  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
141  );
142  if($rows!=null){
143  $IdChannelType=$rows->IdChannelType;
144  if(isset($data['IdChannelType'])){
145  if($IdChannelType!=$data['IdChannelType']){
146  $resultId = 5024;
147  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
148  $resultCode=$r['Message'];
149  $message=$r['Message'];
150  $type=3;
151  }
152  }
153  }else{
154  $resultId = 3189;
155  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
156  $resultCode=$r['Message'];
157  $message=$r['Message'];
158  $type=3;
159  }
160  }
161  }
162  if($resultId==0){
163  if ($IdChannel=="0"){
164  $k=$this->insert($data);
165  $k=$this->getAdapter()->lastInsertId();
166  $resultCode=$k;
167  }else{
168  unset($data['IdUserAccount']);
169  $this->update($data,$this->getAdapter()->quoteInto('IdChannel=?',$IdChannel));
170  $k=$entity['IdChannelType'];
171  $resultCode=$k;
172 
173  }
174  }
175  }
176  catch(Exception $e){
177  $resultCode=$e->getMessage();
178  $resultId=101;
179  $type=3;
180  }
181  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
182  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
183  return $response;
184  }
185  //============ End addEditChannel ==============================================================
186 
187 
188  //==== Start deleteChannel =========================================================================
198  function deleteChannel($entity) {
199  // function implementation
200  $resultId = 0;
201  $page="Channel.php";
202  $method="deleteChannel";
203  $result=json_encode($entity);
204  $message="";
205  $type="1";
206  $this->ErrorCode = new Application_Model_ErrorCode;
207  $this->Log = new Application_Model_Log;
208 
209  try{
210  $data=array();
211  if(!isset($entity['IdChannel'])){
212  $resultId = 3191;
213  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
214  $resultCode=sprintf($r['Message'], "IdChannel");
215  $message=sprintf($r['Message'], "IdChannel");
216  $type=3;
217  }else{$data['IdChannel']=$entity['IdChannel'];}
218 
219  if(!isset($entity['IdChannelType'])){
220  if($resultId==0 && (int)$entity['IdChannel']==0){
221  $resultId = 3191;
222  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
223  $resultCode=sprintf($r['Message'], "IdChannelType");
224  $message=sprintf($r['Message'], "IdChannelType");
225  $type=3;
226  }
227  }else{$data['IdChannelType']=$entity['IdChannelType'];}
228 
229  if(!isset($entity['IdUserAccount'])){
230  $resultId = 3191;
231  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
232  $resultCode=sprintf($r['Message'], "IdUserAccount");
233  $message=sprintf($r['Message'], "IdUserAccount");
234  $type=3;
235  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
236 
237  if(!isset($entity['UserAccountType'])){
238  $resultId = 3191;
239  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
240  $resultCode=sprintf($r['Message'], "UserAccountType");
241  $message=sprintf($r['Message'], "UserAccountType");
242  $type=3;
243  }else{$data['UserAccountType']=$entity['UserAccountType'];}
244 
245  if(!isset($data)|| $data==null)
246  {
247  $resultId = 3191;
248  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
249  $resultCode=sprintf($r['Message'], "IdChannel,IdChannelType");
250  $message=sprintf($r['Message'], "IdChannel,IdChannelType");
251  $type=3;
252  }
253  if($resultId==0){
254 
255  $IdUserAccount=(int)$data['IdUserAccount'];
256  $IdChannel=(int)$data['IdChannel'];
257  $IdChannelType=(int)$data['IdChannelType'];
258 
259  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
260  ->from("Channel","*")
261  ->where("IdChannel=$IdChannel OR 0=$IdChannel")
262  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
263  ->where("IdUserAccount=$IdUserAccount")
264  );
265  if($rows==null){
266  $resultId = 3190;
267  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
268  $resultCode=$r['Message'];
269  $message=$r['Message'];
270  $type=3;
271  }else{
272  $k=$this->delete(array("IdChannel=$IdChannel OR 0=$IdChannel",
273  "IdChannelType=$IdChannelType OR 0=$IdChannelType",
274  "IdUserAccount=$IdUserAccount"));
275  $resultCode="Date sterse";
276  }
277  }
278  }
279  catch(Exception $e){
280  $resultCode=$e->getMessage();
281  $resultId=101;
282  $type=3;
283  }
284  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
285  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
286  return $response;
287  }
288  //============ End deleteChannel ==============================================================
289 
290 
291  //==== Start getChannel =========================================================================
311  function getChannel($entity) {
312  // function implementation
313  $resultId = 0;
314  $page="Channel.php";
315  $method="getChannel";
316  $result=json_encode($entity);
317  $message="";
318  $type="1";
319  $this->ErrorCode = new Application_Model_ErrorCode;
320  $this->Log = new Application_Model_Log;
321  $this->Paging = new Application_Model_Paging;
322 
323  try{
324  $pg=$this->Paging->getPageDefault('Channel');
325 
326  $data=array();
327  if(!isset($entity['IdChannel']))
328  {
329  $resultId = 3192;
330  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
331  $resultCode=sprintf($r['Message'], "IdChannel");
332  $message=sprintf($r['Message'], "IdChannel");
333  $type=3;
334  }else{$data['IdChannel']=$entity['IdChannel'];}
335 
336  if(!isset($entity['IdChannelType']))
337  {
338  $resultId = 3192;
339  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
340  $resultCode=sprintf($r['Message'], "IdChannelType");
341  $message=sprintf($r['Message'], "IdChannelType");
342  $type=3;
343  }else{$data['IdChannelType']=$entity['IdChannelType'];}
344 
345  if(!isset($entity['IdUserAccount'])){
346  $resultId = 3192;
347  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
348  $resultCode=sprintf($r['Message'], "IdUserAccount");
349  $message=sprintf($r['Message'], "IdUserAccount");
350  $type=3;
351  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
352 
353  if(!isset($entity['UserAccountType'])){
354  $resultId = 3192;
355  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
356  $resultCode=sprintf($r['Message'], "UserAccountType");
357  $message=sprintf($r['Message'], "UserAccountType");
358  $type=3;
359  }else{$data['UserAccountType']=$entity['UserAccountType'];}
360 
361  if(!isset($entity['pageSize'])){
362  $_pageSize=$pg['pageSize'];
363  }else{
364  $_pageSize=$entity['pageSize'];
365  }
366 
367  if(!isset($entity['pageNo'])){
368  $_pageNo=$pg['pageNo'];
369  }else{$_pageNo=$entity['pageNo'];}
370 
371  if(!isset($entity['orderColumn'])){
372  $_orderColumn=$pg['orderColumn'];
373  }else{$_orderColumn=$entity['orderColumn'];}
374 
375  if(!isset($entity['orderType'])){
376  $_orderType=$pg['orderType'];
377  }else{
378  switch($entity['orderType'])
379  {
380  case 'ASC':
381  $_orderType="ASC";
382  break;
383  case 'DESC':
384  $_orderType="DESC";
385  break;
386  default:
387  $_orderType="DESC";
388  break;
389  }
390  }
391 
392  if(!isset($entity['orderColumn'])){
393  $_orderColumn=$pg['orderColumn'];
394  }else{
395  switch($entity['orderColumn'])
396  {
397  case 'IdChannel':
398  $_orderColumn="IdChannel";
399  break;
400  case 'IdChannelType':
401  $_orderColumn="IdChannelType";
402  break;
403  case 'ChannelName':
404  $_orderColumn="ChannelName";
405  break;
406  case 'Target':
407  $_orderColumn="Target";
408  break;
409  case 'Activ':
410  $_orderColumn="Activ";
411  break;
412  case 'IdUserAccount':
413  $_orderColumn="IdUserAccount";
414  break;
415  default:
416  $_orderColumn=$orderColumn;
417  break;
418  }
419 
420  }
421  if($resultId==0){
422  if($data['UserAccountType']=="0"){
423  $IdUserAccount=0;
424  }else{
425  $IdUserAccount=(int)$data['IdUserAccount'];
426  }
427  $IdChannel=(int)$data['IdChannel'];
428  $IdChannelType=(int)$data['IdChannelType'];
429 
430 
431  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
432  ->from("Channel",array("total"=>"COUNT(IdChannel)"))
433  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
434  ->where("IdChannel=$IdChannel OR 0=$IdChannel")
435  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
436  );
437 
438  if($count->total==0){
439  $resultId = 3193;
440  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
441  $resultCode=$r['Message'];
442  $message=$r['Message'];
443  $type=3;
444  }else{
445  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
446 
447  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
448  ->from("Channel","*")
449  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
450  ->where("IdChannel=$IdChannel OR 0=$IdChannel")
451  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
452  ->limit($_pageSize, $offset['start'])
453  ->order($_orderColumn." ".$_orderType)
454  );
455  foreach($rows as $row){
456  $resultEntity[]=array("IdChannel"=>$row->IdChannel,
457  "IdChannelType"=>$row->IdChannelType,
458  "ChannelName"=>$row->ChannelName,
459  "Target"=>$row->Target,
460  "Activ"=>$row->Activ,
461  "IdUserAccount"=>$row->IdUserAccount);
462  }
463  $resultCode=array("pageNo"=>$_pageNo,
464  "pageSize"=>$_pageSize,
465  "pageCount"=>$offset['maxPage'],
466  "orderColumn"=>$_orderColumn,
467  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
468  }
469  }
470  }
471  catch(Exception $e){
472  $resultCode=$e->getMessage();
473  $resultId=101;
474  $type=3;
475  }
476  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
477  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
478  return $response;
479  }
480  //============ End getChannel ==============================================================
481 
482  //============ Start getChannelCount ==============================================================
483  /*
484  \brief Returneaza (in campul "response") Numarul de Channel-uri ale unui UserAccount
485  In caz de eroare (resId!=0), campul "response" contine descrierea erorii (tip string).
486  \param[in] Integer $IdUserAccount legatura cu tabela UserAccount, acest parametru il baga automat indexcontroller functie de token
487  \exception <3194> Campuri obligatorii nu au fost trimise
488  \return array(resultCode, resultId)
489  \nfmapi Channel
490 
491  */
492  function getChannelCount($entity) {
493  // function implementation
494  $resultId = 0;
495  $page="Channel.php";
496  $method="getChannelCount";
497  $result=json_encode($entity);
498  $message="";
499  $type="1";
500  $this->ErrorCode = new Application_Model_ErrorCode;
501  $this->Log = new Application_Model_Log;
502  $this->Paging = new Application_Model_Paging;
503 
504  try{
505 
506  if(!isset($entity['IdUserAccount'])){
507  $resultId = 3196;
508  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
509  $resultCode=sprintf($r['Message'], "IdUserAccount");
510  $message=sprintf($r['Message'], "IdUserAccount");
511  $type=3;
512  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
513  if($resultId==0){
514  $IdUserAccount=(int)$data['IdUserAccount'];
515 
516  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
517  ->from("Channel",array("total"=>"COUNT(IdChannel)"))
518  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
519  );
520 
521  $resultCode=array("NoOfChannel"=>$count->total);
522  }
523  }
524  catch(Exception $e){
525  $resultCode=$e->getMessage();
526  $resultId=101;
527  $type=3;
528  }
529  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
530  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
531  return $response;
532 
533  }
534 
535  //============ End getChannelCount ==============================================================
536 }