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