Next4Me
 All Classes Files Functions Variables
ChannelType.php
Go to the documentation of this file.
1 <?php
19 class Application_Model_ChannelType extends Zend_Db_Table_Abstract {
20  //put your code here
21  protected $_name="ChannelType";
22  protected $_primary="IdChannelType";
23 
24  //==== Start addEditChannelType =========================================================================
36  function addEditChannelType($entity) {
37  // function implementation
38  $resultId = 0;
39  $page="ChannelType.php";
40  $method="addEditChannelType";
41  $result=json_encode($entity);
42  $message="";
43  $type="1";
44  $this->ErrorCode = new Application_Model_ErrorCode;
45  $this->Log = new Application_Model_Log;
46 
47  try{
48  $data=array();
49  if(!isset($entity['IdChannelType'])){
50  $resultId = 3182;
51  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
52  $resultCode=sprintf($r['Message'], "IdChannelType");
53  $message=sprintf($r['Message'], "IdChannelType");
54  $type=3;
55  }else{$data['IdChannelType']=$entity['IdChannelType'];}
56 
57  if(!isset($entity['NameChannelType'])){
58  if($resultId==0 && (int)$entity['IdChannelType']==0){
59  $resultId = 3182;
60  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
61  $resultCode=sprintf($r['Message'], "NameChannelType");
62  $message=sprintf($r['Message'], "NameChannelType");
63  $type=3;
64  }
65  }else{$data['NameChannelType']=$entity['NameChannelType'];}
66 
67 
68  if(!isset($data)|| $data==null)
69  {
70  $resultId = 3182;
71  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
72  $resultCode=sprintf($r['Message'], "IdChannelType,NameChannelType");
73  $message=sprintf($r['Message'], "IdChannelType,NameChannelType");
74  $type=3;
75  }
76 
77  if($resultId==0){
78  $IdChannelType=(int)$data['IdChannelType'];
79 
80  if($IdChannelType!="0"){
81  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
82  ->from("ChannelType","*")
83  ->where("IdChannelType=?",$IdChannelType)
84  );
85  if($rows==null){
86  $resultId = 3183;
87  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
88  $resultCode=$r['Message'];
89  $message=$r['Message'];
90  $type=3;
91  }
92  }
93  }
94  if($resultId==0){
95  if ($IdChannelType=="0"){
96  $k=$this->insert($data);
97  $k=$this->getAdapter()->lastInsertId();
98  $resultCode=$k;
99  }else{
100  $this->update($data,$this->getAdapter()->quoteInto('IdChannelType=?',$IdChannelType));
101  $k=$data['IdChannelType'];
102  $resultCode=$k;
103 
104  }
105  }
106  }
107  catch(Exception $e){
108  $resultCode=$e->getMessage();
109  $resultId=101;
110  $type=3;
111  }
112  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
113  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
114  return $response;
115  }
116  //============ End addEditChannelType ==============================================================
117 
118 
119  //==== Start deleteChannelType =========================================================================
130  function deleteChannelType($entity) {
131  // function implementation
132  $resultId = 0;
133  $page="ChannelType.php";
134  $method="deleteChannelType";
135  $result=json_encode($entity);
136  $message="";
137  $type="1";
138  $this->ErrorCode = new Application_Model_ErrorCode;
139  $this->Log = new Application_Model_Log;
140 
141  try{
142  $data=array();
143  if(!isset($entity['IdChannelType'])){
144  $resultId = 3185;
145  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
146  $resultCode=sprintf($r['Message'], "IdChannelType");
147  $message=sprintf($r['Message'], "IdChannelType");
148  $type=3;
149  }else{$data['IdChannelType']=$entity['IdChannelType'];}
150 
151  if(!isset($data)|| $data==null)
152  {
153  $resultId = 3185;
154  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
155  $resultCode=sprintf($r['Message'], "Value,Type,IdContact");
156  $message=sprintf($r['Message'], "Value,Type,IdContact");
157  $type=3;
158  }
159  if($resultId==0){
160  $IdChannelType=(int)$data['IdChannelType'];
161 
162  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
163  ->from("ChannelType","*")
164  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
165  );
166  if($rows==null){
167  $resultId = 3184;
168  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
169  $resultCode=$r['Message'];
170  $message=$r['Message'];
171  $type=3;
172  }
173  }
174  if($resultId==0){
175  $IdChannelType=(int)$data['IdChannelType'];
176 
177  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
178  ->from("Channel","*")
179  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
180  );
181  if($rows!=null){
182  $resultId = 4014;
183  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
184  $resultCode=$r['Message'];
185  $message=$r['Message'];
186  $type=3;
187  }
188  }
189  if($resultId==0){
190  $k=$this->delete(array("IdChannelType=$IdChannelType OR 0=$IdChannelType"));
191  $resultCode="Date sterse";
192  }
193 
194  }
195  catch(Exception $e){
196  $resultCode=$e->getMessage();
197  $resultId=101;
198  $type=3;
199  }
200  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
201  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
202  return $response;
203  }
204  //============ End deleteChannelType ==============================================================
205 
206 
207  //==== Start getChannelType =========================================================================
223  function getChannelType($entity) {
224  // function implementation
225  $resultId = 0;
226  $page="ChannelType.php";
227  $method="getChannelType";
228  $result=json_encode($entity);
229  $message="";
230  $type="1";
231  $this->ErrorCode = new Application_Model_ErrorCode;
232  $this->Log = new Application_Model_Log;
233  $this->Paging = new Application_Model_Paging;
234 
235  try{
236  $pg=$this->Paging->getPageDefault('ChannelType');
237 
238  $data=array();
239  if(!isset($entity['IdChannelType']))
240  {
241  $resultId = 3187;
242  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
243  $resultCode=sprintf($r['Message'], "IdChannelType");
244  $message=sprintf($r['Message'], "IdChannelType");
245  $type=3;
246  }else{$data['IdChannelType']=$entity['IdChannelType'];}
247 
248  if(!isset($entity['pageSize'])){
249  $_pageSize=$pg['pageSize'];
250  }else{
251  $_pageSize=$entity['pageSize'];
252  }
253 
254  if(!isset($entity['pageNo'])){
255  $_pageNo=$pg['pageNo'];
256  }else{$_pageNo=$entity['pageNo'];}
257 
258  if(!isset($entity['orderColumn'])){
259  $_orderColumn=$pg['orderColumn'];
260  }else{$_orderColumn=$entity['orderColumn'];}
261 
262  if(!isset($entity['orderType'])){
263  $_orderType=$pg['orderType'];
264  }else{
265  switch($entity['orderType'])
266  {
267  case 'ASC':
268  $_orderType="ASC";
269  break;
270  case 'DESC':
271  $_orderType="DESC";
272  break;
273  default:
274  $_orderType="DESC";
275  break;
276  }
277  }
278 
279  if(!isset($entity['orderColumn'])){
280  $_orderColumn=$pg['orderColumn'];
281  }else{
282  switch($entity['orderColumn'])
283  {
284  case 'IdChannelType':
285  $_orderColumn="IdChannelType";
286  break;
287  case 'NameChannelType':
288  $_orderColumn="NameChannelType";
289  break;
290  default:
291  $_orderColumn=$orderColumn;
292  break;
293  }
294 
295  }
296  if($resultId==0){
297  $IdChannelType=(int)$data['IdChannelType'];
298 
299 
300  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
301  ->from("ChannelType",array("total"=>"COUNT(IdChannelType)"))
302  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
303  );
304 
305  if($count->total==0){
306  $resultId = 3186;
307  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
308  $resultCode=$r['Message'];
309  $message=$r['Message'];
310  $type=3;
311  }else{
312  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
313 
314  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
315  ->from("ChannelType","*")
316  ->where("IdChannelType=$IdChannelType OR 0=$IdChannelType")
317  ->limit($_pageSize, $offset['start'])
318  ->order($_orderColumn." ".$_orderType)
319  );
320  foreach($rows as $row){
321  $resultEntity[]=array("IdChannelType"=>$row->IdChannelType,
322  "NameChannelType"=>$row->NameChannelType);
323  }
324  $resultCode=array("pageNo"=>$_pageNo,
325  "pageSize"=>$_pageSize,
326  "pageCount"=>$offset['maxPage'],
327  "orderColumn"=>$_orderColumn,
328  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
329  }
330  }
331  }
332  catch(Exception $e){
333  $resultCode=$e->getMessage();
334  $resultId=101;
335  $type=3;
336  }
337  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
338  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
339  return $response;
340  }
341  //============ End getChannelType ==============================================================
342 }