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