Next4Me
 All Classes Files Functions Variables
TplAsset.php
Go to the documentation of this file.
1 <?php
16 class Application_Model_TplAsset extends Zend_Db_Table_Abstract {
17  protected $_name="TplAsset";
18  protected $_primary="IdTplAsset";
19  //==== Start addEditTplAsset =========================================================================
30  function addEditTplAsset($entity) {
31  $resultId = 0;
32  $page="TplAsset.php";
33  $method="addEditTplAsset";
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['IdTplAsset'])){
43  $resultId = 3095;
44  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
45  $resultCode=sprintf($r['Message'], "IdTplAsset");
46  $message=sprintf($r['Message'], "IdTplAsset");
47  $type=3;
48  }else{$data['IdTplAsset']=(int)$entity['IdTplAsset'];}
49  if(!isset($entity['Name'])){
50  if($resultId==0 && $entity['IdTplAsset']=="0"){
51  $resultId = 3095;
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($data) || $data==null){
60  $resultId = 3095;
61  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
62  $resultCode=sprintf($r['Message'], "Name");
63  $message=sprintf($r['Message'], "Name");
64  $type=3;
65  }
66  if($resultId==0 && $data['IdTplAsset']!="0"){
67  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
68  ->from("TplAsset","*")
69  ->where("IdTplAsset=?",$data['IdTplAsset'])
70  );
71  if($rows==null){
72  $resultId = 3034;
73  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
74  $resultCode=$r['Message'];
75  $message=$r['Message'];
76  $type=3;
77  }
78  }
79  if($resultId==0){
80  if ($data['IdTplAsset']=="0"){
81  $k=$this->insert($data);
82  $k=$this->getAdapter()->lastInsertId();
83  $resultCode=$k;
84  }else{
85  $this->update($data,$this->getAdapter()->quoteInto('IdTplAsset=?',$data['IdTplAsset']));
86  $k=$data['IdTplAsset'];
87  $resultCode=$k;
88  }
89  }
90 
91 
92  }
93  catch(Exception $e){
94  $resultCode=$e->getMessage();
95  $resultId=101;
96  $type=3;
97  }
98  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
99  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
100  return $response;
101 
102 
103  }
104  //============ End addEditTplAsset ==============================================================
105 
106 
107  //==== Start deleteTplAsset =========================================================================
116  function deleteTplAsset($entity) {
117  // function implementation
118  $resultId = 0;
119  $page="TplAsset.php";
120  $method="deleteTplAsset";
121  $result=json_encode($entity);
122  $message="";
123  $type="1";
124  $this->ErrorCode = new Application_Model_ErrorCode;
125  $this->Log = new Application_Model_Log;
126 
127  try{
128  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
129  ->from("TplAsset","*")
130  ->where("IdTplAsset=?",$entity['IdTplAsset'])
131  );
132  if($rows==null){
133  $resultId = 3035;
134  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
135  $resultCode=$r['Message'];
136  $message=$r['Message'];
137  $type=3;
138  }else{
139  $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
140  ->from("TplAssetProperty","*")
141  ->where("IdTplAsset=?",$entity['IdTplAsset'])
142  );
143  if($chld==null){
144  $k=$this->delete($this->getAdapter()->quoteInto("IdTplAsset=?",$entity['IdTplAsset']));
145  $resultCode="Date sterse";
146  }else{
147  $resultId = 4006;
148  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
149  $resultCode=$r['Message'];
150  $message=$r['Message'];
151  $type=3;
152  }
153  }
154  }
155  catch(Exception $e){
156  $resultCode=$e->getMessage();
157  $resultId=101;
158  $type=3;
159  }
160  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
161  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
162  return $response;
163 
164 
165  }
166  //============ End deleteTplAsset ==============================================================
167 
168 
169  //==== Start getTplAsset =========================================================================
183  function getTplAsset($entity) {
184  // function implementation
185  $resultId = 0;
186  $page="TplAsset.php";
187  $method="getTplAsset";
188  $result=json_encode($entity);
189  $message="";
190  $type="1";
191  $this->ErrorCode = new Application_Model_ErrorCode;
192  $this->Log = new Application_Model_Log;
193  $this->Paging=new Application_Model_Paging;
194 
195  try{
196  $pg=$this->Paging->getPageDefault('TplAsset');
197 
198  $data=array();
199  if(!isset($entity['IdTplAsset']))
200  {
201  $resultId = 3147;
202  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
203  $resultCode=sprintf($r['Message'], "IdTplAsset");
204  $message=sprintf($r['Message'], "IdTplAsset");
205  $type=3;
206  }else{$data['IdTplAsset']=$entity['IdTplAsset'];}
207 
208  if(!isset($entity['IdUserAccount'])){
209  $resultId = 3147;
210  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
211  $resultCode=sprintf($r['Message'], "IdUserAccount");
212  $message=sprintf($r['Message'], "IdUserAccount");
213  $type=3;
214  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
215 
216  if(!isset($entity['UserAccountType'])){
217  $resultId = 3147;
218  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
219  $resultCode=sprintf($r['Message'], "UserAccountType");
220  $message=sprintf($r['Message'], "UserAccountType");
221  $type=3;
222  }else{$data['UserAccountType']=$entity['UserAccountType'];}
223 
224  if(!isset($entity['pageSize'])){
225  $_pageSize=$pg['pageSize'];
226  }else{
227  $_pageSize=$entity['pageSize'];
228  }
229 
230  if(!isset($entity['pageNo'])){
231  $_pageNo=$pg['pageNo'];
232  }else{$_pageNo=$entity['pageNo'];}
233 
234  if(!isset($entity['orderColumn'])){
235  $_orderColumn=$pg['orderColumn'];
236  }else{$_orderColumn=$entity['orderColumn'];}
237 
238  if(!isset($entity['orderType'])){
239  $_orderType=$pg['orderType'];
240  }else{
241  switch($entity['orderType'])
242  {
243  case 'ASC':
244  $_orderType="ASC";
245  break;
246  case 'DESC':
247  $_orderType="DESC";
248  break;
249  default:
250  $_orderType="DESC";
251  break;
252  }
253  }
254 
255  if(!isset($entity['orderColumn'])){
256  $_orderColumn=$pg['orderColumn'];
257  }else{
258  switch($entity['orderColumn'])
259  {
260  case 'IdTplAsset':
261  $_orderColumn="IdTplAsset";
262  break;
263  case 'Name':
264  $_orderColumn="Name";
265  break;
266  default:
267  $_orderColumn=$orderColumn;
268  break;
269  }
270 
271  }
272 
273  if($resultId==0){
274  $IdTplAsset=(int)$data['IdTplAsset'];
275 
276  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
277  ->from("TplAsset",array("total"=>"COUNT(IdTplAsset)"))
278  ->where("IdTplAsset=$IdTplAsset OR 0=$IdTplAsset")
279  );
280 
281  if($count->total==0){
282  $resultId = 3036;
283  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
284  $resultCode=$r['Message'];
285  $message=$r['Message'];
286  $type=3;
287  }else{
288 
289  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
290 
291  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
292  ->from("TplAsset","*")
293  ->where("IdTplAsset=$IdTplAsset OR 0=$IdTplAsset")
294  ->limit($_pageSize, $offset['start'])
295  ->order($_orderColumn." ".$_orderType)
296  );
297 
298  foreach($rows as $row){
299  $resultEntity[]=array("IdTplAsset"=>$row->IdTplAsset, "Name"=>$row->Name);
300  }
301 
302  $resultCode=array("pageNo"=>$_pageNo,
303  "pageSize"=>$_pageSize,
304  "pageCount"=>$offset['maxPage'],
305  "orderColumn"=>$_orderColumn,
306  "orderType"=>$_orderType,"entity"=>$resultEntity);
307 
308  }
309  }
310  }
311  catch(Exception $e){
312  $resultCode=$e->getMessage();
313  $resultId=101;
314  $type=3;
315  }
316  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
317  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
318  return $response;
319  }
320  //============ End getTplAsset ==============================================================
321 
322 }
323 
324 ?>