Next4Me
 All Classes Files Functions Variables
TplContextCondition.php
Go to the documentation of this file.
1 <?php
14 class Application_Model_TplContextCondition extends Zend_Db_Table_Abstract {
15  protected $_name="TplContextCondition";
16  protected $_primary="IdTplContextCondition";
17  //==== Start addEditTplContextCondition =========================================================================
32  function addEditTplContextCondition($entity) {
33  // function implementation
34  $resultId = 0;
35  $page="TplContextCondition.php";
36  $method="addEditTplContextCondition";
37  $result=json_encode($entity);
38  $message="";
39  $type="1";
40  $this->ErrorCode = new Application_Model_ErrorCode;
41  $this->Log = new Application_Model_Log;
42 
43  try{
44  $data=array();
45  if(!isset($entity['IdTplContextCondition'])){
46  $resultId = 3099;
47  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
48  $resultCode=sprintf($r['Message'], "IdTplContextCondition");
49  $message=sprintf($r['Message'], "IdTplContextCondition");
50  $type=3;
51  }else{$data['IdTplContextCondition']=(int)$entity['IdTplContextCondition'];}
52 
53  if(!isset($entity['IdTplContext'])){
54  if($resultId==0 && $data['IdTplContextCondition']=="0"){
55  $resultId = 3099;
56  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
57  $resultCode=sprintf($r['Message'], "IdTplContext");
58  $message=sprintf($r['Message'], "IdTplContext");
59  $type=3;
60  }
61  }else{$data['IdTplContext']=$entity['IdTplContext'];}
62 
63  if(!isset($entity['Name'])){
64  if($resultId==0 && $data['IdTplContextCondition']=="0"){
65  $resultId = 3099;
66  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
67  $resultCode=sprintf($r['Message'], "Name");
68  $message=sprintf($r['Message'], "Name");
69  $type=3;
70  }
71  }else{$data['Name']=$entity['Name'];}
72 
73  if(!isset($entity['Description'])){
74  if($resultId==0 && $data['IdTplContextCondition']=="0"){
75  $resultId = 3099;
76  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
77  $resultCode=sprintf($r['Message'], "Description");
78  $message=sprintf($r['Message'], "Description");
79  $type=3;
80  }
81  }else{$data['Description']=$entity['Description'];}
82 
83  if(!isset($entity['IdContext'])){
84  if($resultId==0 && $data['IdTplContextCondition']=="0"){
85  $resultId = 3099;
86  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
87  $resultCode=sprintf($r['Message'], "IdContext");
88  $message=sprintf($r['Message'], "IdContext");
89  $type=3;
90  }
91  }else{$data['IdContext']=$entity['IdContext'];}
92 
93  if(!isset($data) || $data==null){
94  $resultId = 3099;
95  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
96  $resultCode=sprintf($r['Message'], "Name,Description,IdContext");
97  $message=sprintf($r['Message'], "Name,Description,IdContext");
98  $type=3;
99  }
100 
101  if($resultId==0 && $data['IdTplContextCondition']!="0"){
102  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
103  ->from("TplContextCondition","*")
104  ->where("IdTplContextCondition=?",$data['IdTplContextCondition'])
105  );
106  if($rows!=null){
107  $IdTplContext=$rows->IdTplContext;
108  if(isset($data['IdTplContext']) && $IdTplContext!=$data['IdTplContext']){
109  $resultId = 5011;
110  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
111  $resultCode=$r['Message'];
112  $message=$r['Message'];
113  $type=3;
114  }
115  }else{
116  $resultId = 3046;
117  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
118  $resultCode=$r['Message'];
119  $message=$r['Message'];
120  $type=3;
121  }
122  }
123 
124  if($resultId==0){
125  if ($data['IdTplContextCondition']=="0"){
126  $k=$this->insert($data);
127  $k=$this->getAdapter()->lastInsertId();
128  $resultCode=$k;
129  }else{
130  $this->update($data,$this->getAdapter()->quoteInto('IdTplContextCondition=?',$data['IdTplContextCondition']));
131  $k=$data['IdTplContextCondition'];
132  $resultCode=$k;
133  }
134  }
135  }
136  catch(Exception $e){
137  $resultCode=$e->getMessage();
138  $resultId=101;
139  $type=3;
140  }
141  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
142  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
143  return $response;
144  }
145  //============ End addEditTplContextCondition ==============================================================
146 
147 
148  //==== Start deleteTplContextCondition =========================================================================
157  function deleteTplContextCondition($entity) {
158  // function implementation
159  $resultId = 0;
160  $page="TplContextCondition.php";
161  $method="deleteTplContextCondition";
162  $result=json_encode($entity);
163  $message="";
164  $type="1";
165  $this->ErrorCode = new Application_Model_ErrorCode;
166  $this->Log = new Application_Model_Log;
167 
168 
169  try{
170 
171  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
172  ->from("TplContextCondition","*")
173  ->where("IdTplContextCondition=?",$entity['IdTplContextCondition'])
174  );
175  if($rows==null){
176  $resultId = 3047;
177  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
178  $resultCode=$r['Message'];
179  $message=$r['Message'];
180  $type=3;
181  }else{
182  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
183  ->from("TplContextFactor","*")
184  ->where("IdTplContextCondition=?",$entity['IdTplContextCondition'])
185  );
186  if($chld==null){
187  $k=$this->delete($this->getAdapter()->quoteInto("IdTplContextCondition=?",$entity['IdTplContextCondition']));
188  $resultCode="Date sterse";
189  }else{
190  $resultId = 4009;
191  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
192  $resultCode=$r['Message'];
193  $message=$r['Message'];
194  $type=3;
195  }
196  }
197  }
198  catch(Exception $e){
199  $resultCode=$e->getMessage();
200  $resultId=101;
201  $type=3;
202  }
203  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
204  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
205  return $response;
206  }
207  //============ End deleteTplContextCondition ==============================================================
208 
209 
210  //==== Start getTplContextCondition =========================================================================
224  function getTplContextCondition($entity) {
225  // function implementation
226  $resultId = 0;
227  $page="TplContextCondition.php";
228  $method="getTplContextCondition";
229  $result=json_encode($entity);
230  $message="";
231  $type="1";
232  $this->ErrorCode = new Application_Model_ErrorCode;
233  $this->Log = new Application_Model_Log;
234  $this->Paging=new Application_Model_Paging;
235 
236  try{
237  $pg=$this->Paging->getPageDefault('TplContextCondition');
238 
239  $data=array();
240  if(!isset($entity['IdTplContextCondition']))
241  {
242  $resultId = 3151;
243  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
244  $resultCode=sprintf($r['Message'], "IdTplContextCondition");
245  $message=sprintf($r['Message'], "IdTplContextCondition");
246  $type=3;
247  }else{$data['IdTplContextCondition']=$entity['IdTplContextCondition'];}
248 
249  if(!isset($entity['IdTplContext']))
250  {
251  $resultId = 3151;
252  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
253  $resultCode=sprintf($r['Message'], "IdTplContext");
254  $message=sprintf($r['Message'], "IdTplContext");
255  $type=3;
256  }else{$data['IdTplContext']=$entity['IdTplContext'];}
257 
258  if(!isset($entity['IdUserAccount'])){
259  $resultId = 3151;
260  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
261  $resultCode=sprintf($r['Message'], "IdUserAccount");
262  $message=sprintf($r['Message'], "IdUserAccount");
263  $type=3;
264  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
265 
266  if(!isset($entity['UserAccountType'])){
267  $resultId = 3151;
268  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
269  $resultCode=sprintf($r['Message'], "UserAccountType");
270  $message=sprintf($r['Message'], "UserAccountType");
271  $type=3;
272  }else{$data['UserAccountType']=$entity['UserAccountType'];}
273 
274  if(!isset($entity['pageSize'])){
275  $_pageSize=$pg['pageSize'];
276  }else{
277  $_pageSize=$entity['pageSize'];
278  }
279 
280  if(!isset($entity['pageNo'])){
281  $_pageNo=$pg['pageNo'];
282  }else{$_pageNo=$entity['pageNo'];}
283 
284  if(!isset($entity['orderColumn'])){
285  $_orderColumn=$pg['orderColumn'];
286  }else{$_orderColumn=$entity['orderColumn'];}
287 
288  if(!isset($entity['orderType'])){
289  $_orderType=$pg['orderType'];
290  }else{
291  switch($entity['orderType'])
292  {
293  case 'ASC':
294  $_orderType="ASC";
295  break;
296  case 'DESC':
297  $_orderType="DESC";
298  break;
299  default:
300  $_orderType="DESC";
301  break;
302  }
303  }
304 
305  if(!isset($entity['orderColumn'])){
306  $_orderColumn=$pg['orderColumn'];
307  }else{
308  switch($entity['orderColumn'])
309  {
310  case 'IdTplContextCondition':
311  $_orderColumn="IdTplContextCondition";
312  break;
313  case 'IdTplContext':
314  $_orderColumn="IdTplContext";
315  break;
316  case 'Name':
317  $_orderColumn="Name";
318  break;
319  case 'Description':
320  $_orderColumn="Description";
321  break;
322  case 'IdContext':
323  $_orderColumn="IdContext";
324  break;
325  default:
326  $_orderColumn=$orderColumn;
327  break;
328  }
329 
330  }
331  if($resultId==0){
332  $IdTplContext=(int)$data['IdTplContext'];
333  $IdTplContextCondition=(int)$data['IdTplContextCondition'];
334 
335  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
336  ->from("TplContextCondition",array("total"=>"COUNT(IdTplContextCondition)"))
337  ->where("IdTplContext=$IdTplContext OR 0=$IdTplContext")
338  ->where("IdTplContextCondition=$IdTplContextCondition OR 0=$IdTplContextCondition")
339  );
340 
341  if($count->total==0){
342  $resultId = 3048;
343  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
344  $resultCode=$r['Message'];
345  $message=$r['Message'];
346  $type=3;
347  }else{
348 
349  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
350 
351  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
352  ->from("TplContextCondition","*")
353  ->where("IdTplContext=$IdTplContext OR 0=$IdTplContext")
354  ->where("IdTplContextCondition=$IdTplContextCondition OR 0=$IdTplContextCondition")
355  ->limit($_pageSize, $offset['start'])
356  ->order($_orderColumn." ".$_orderType)
357  );
358  foreach($rows as $row){
359  $resultEntity[]=array("IdTplContextCondition" => $row->IdTplContextCondition,
360  "IdTplContext" => $row->IdTplContext,
361  "Name" => $row->Name,
362  "Description" => $row->Description,
363  "IdContext" => $row->IdContext, );
364  }
365 
366  $resultCode=array("pageNo"=>$_pageNo,
367  "pageSize"=>$_pageSize,
368  "pageCount"=>$offset['maxPage'],
369  "orderColumn"=>$_orderColumn,
370  "orderType"=>$_orderType,"entity"=>$resultEntity);
371  }
372  }
373  }
374  catch(Exception $e){
375  $resultCode=$e->getMessage();
376  $resultId=101;
377  $type=3;
378  }
379  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
380  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
381  return $response;
382  }
383  //============ End getTplContextCondition ==============================================================
384 
385 }
386 
387 ?>