Next4Me
 All Classes Files Functions Variables
AssetProperty.php
Go to the documentation of this file.
1 <?php
22 class Application_Model_AssetProperty extends Zend_Db_Table_Abstract{
23  protected $_name="AssetProperty";
24  protected $_primary="IdAssetProperty";
25  protected $_referenceMap=array(
26  'Asset'=>array(
27  'columns'=>array('IdAsset'),
28  'refTableClass'=>'Asset',
29  'refColumns'=>array('IdAsset')
30  )
31  );
32 
33 //==== Start AddEditAssetProperty =========================================================================
53  function addEditAssetProperty($entity) {
54  // function implementation
55  $resultId = 0;
56  $page="AssetsProperty.php";
57  $method="addEditAssetsProperty";
58  $result=json_encode($entity);
59  $message="";
60  $type="1";
61  $this->ErrorCode = new Application_Model_ErrorCode;
62  $this->Log = new Application_Model_Log;
63 
64  try{
65  $data=array();
66  if(!isset($entity['IdAssetProperty']))
67  {
68  $resultId = 3086;
69  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
70  $resultCode=sprintf($r['Message'], "IdAssetProperty");
71  $message=sprintf($r['Message'], "IdAssetProperty");
72  $type=3;
73  }else{$data['IdAssetProperty']=$entity['IdAssetProperty'];}
74 
75  if(!isset($entity['IdAsset'])){
76  if($resultId==0 && $entity['IdAssetProperty']=="0"){
77  $resultId = 3086;
78  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
79  $resultCode=sprintf($r['Message'], "IdAsset");
80  $message=sprintf($r['Message'], "IdAsset");
81  $type=3;
82  }
83  }else{$data['IdAsset']=$entity['IdAsset'];}
84 
85  if(!isset($entity['Name'])){
86  if($resultId==0 && $entity['IdAssetProperty']=="0"){
87  $resultId = 3086;
88  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
89  $resultCode=sprintf($r['Message'], "Name");
90  $message=sprintf($r['Message'], "Name");
91  $type=3;
92  }
93  }else{$data['Name']=$entity['Name'];}
94 
95  if(!isset($entity['PropertyValue'])){
96  if($resultId==0 && $entity['IdAssetProperty']=="0"){
97  $resultId = 3086;
98  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
99  $resultCode=sprintf($r['Message'], "PropertyValue");
100  $message=sprintf($r['Message'], "PropertyValue");
101  $type=3;
102  }
103  }else{$data['PropertyValue']=$entity['PropertyValue'];}
104 
105  if(!isset($entity['PropertyString'])){
106  if($resultId==0 && $entity['IdAssetProperty']=="0"){
107  $resultId = 3086;
108  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
109  $resultCode=sprintf($r['Message'], "PropertyString");
110  $message=sprintf($r['Message'], "PropertyString");
111  $type=3;
112  }
113  }else{$data['PropertyString']=$entity['PropertyString'];}
114 
115  if(!isset($entity['PropertyDate'])){
116  if($resultId==0 && $entity['IdAssetProperty']=="0"){
117  $resultId = 3086;
118  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
119  $resultCode=sprintf($r['Message'], "PropertyDate");
120  $message=sprintf($r['Message'], "PropertyDate");
121  $type=3;
122  }
123  }else{$data['PropertyDate']=$entity['PropertyDate'];}
124 
125  if(!isset($entity['PropertyType'])){
126  if($resultId==0 && $entity['IdAssetProperty']=="0"){
127  $resultId = 3086;
128  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
129  $resultCode=sprintf($r['Message'], "PropertyType");
130  $message=sprintf($r['Message'], "PropertyType");
131  $type=3;
132  }
133  }else{$data['PropertyType']=$entity['PropertyType'];}
134 
135  if(!isset($entity['IdUserAccount'])){
136  $resultId = 3086;
137  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
138  $resultCode=sprintf($r['Message'], "IdUserAccount");
139  $message=sprintf($r['Message'], "IdUserAccount");
140  $type=3;
141  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
142 
143  if(!isset($entity['UserAccountType'])){
144  $resultId = 3086;
145  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
146  $resultCode=sprintf($r['Message'], "UserAccountType");
147  $message=sprintf($r['Message'], "UserAccountType");
148  $type=3;
149  }else{$data['UserAccountType']=$entity['UserAccountType'];}
150 
151  if(!isset($data) && $data==null){
152  $resultId = 3086;
153  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
154  $resultCode=sprintf($r['Message'], "IdAsset,Name,PropertyValue,PropertyString,PropertyDate,PropertyType");
155  $message=sprintf($r['Message'], "IdAsset,Name,PropertyValue,PropertyString,PropertyDate,PropertyType");
156  $type=3;
157  }
158 
159  if($resultId==0){
160  $IdAssetProperty=(int)$data['IdAssetProperty'];
161 
162  if($IdAssetProperty!="0"){
163  if($data['UserAccountType']=="0"){
164  $IdUserAccount=0;
165  }else{
166  $IdUserAccount=$data['IdUserAccount'];
167  }
168  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
169  ->from("AssetProperty","*")
170  ->where("IdAssetProperty=?",$IdAssetProperty)
171  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
172  );
173  if($rows!=null){
174  if(isset($data['IdAsset'])){
175  $IdAsset=$rows->IdAsset;
176  if($IdAsset!=$data['IdAsset']){
177  $resultId = 5001;
178  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
179  $resultCode=$r['Message'];
180  $message=$r['Message'];
181  $type=3;
182  }
183  }
184  }else{
185  $resultId = 3004;
186  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
187  $resultCode=$r['Message'];
188  $message=$r['Message'];
189  $type=3;
190  }
191 
192  }
193  }
194  if($resultId==0){
195  unset($data['UserAccountType']);
196  if ($IdAssetProperty=="0"){
197  $k=$this->insert($data);
198  $k=$this->getAdapter()->lastInsertId();
199  $resultCode=$k;
200  }else{
201  unset($data['IdUserAccount']);
202  $this->update($data,$this->getAdapter()->quoteInto('IdAssetProperty=?',$IdAssetProperty));
203  $k=$entity['IdAssetProperty'];
204  $resultCode=$k;
205  $message=$k;
206  }
207 
208  }
209 
210  }
211  catch(Exception $e){
212  $resultCode=$e->getMessage();
213  $resultId=101;
214  $type=3;
215  }
216  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
217  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
218  return $response;
219  }
220  //============ End AddEditAssetProperty ==============================================================
221 
222 
223  //==== Start deleteAssetProperty =========================================================================
236  function deleteAssetProperty($entity) {
237  // function implementation
238  $resultId = 0;
239  $page="AssetProperty.php";
240  $method="deleteAssetProperty";
241  $result=json_encode($entity);
242  $message="";
243  $type="1";
244  $this->ErrorCode = new Application_Model_ErrorCode;
245  $this->Log = new Application_Model_Log;
246 
247  try{
248  $data=array();
249  if(!isset($entity['IdAsset']))
250  {
251  $resultId = 3211;
252  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
253  $resultCode=sprintf($r['Message'], "IdAsset");
254  $message=sprintf($r['Message'], "IdAsset");
255  $type=3;
256  }else{$data['IdAsset']=$entity['IdAsset'];}
257 
258  if(!isset($entity['IdAssetProperty']))
259  {
260  $resultId = 3211;
261  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
262  $resultCode=sprintf($r['Message'], "IdAssetProperty");
263  $message=sprintf($r['Message'], "IdAssetProperty");
264  $type=3;
265  }else{$data['IdAssetProperty']=$entity['IdAssetProperty'];}
266 
267  if(!isset($entity['IdUserAccount'])){
268  $resultId = 3211;
269  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
270  $resultCode=sprintf($r['Message'], "IdUserAccount");
271  $message=sprintf($r['Message'], "IdUserAccount");
272  $type=3;
273  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
274 
275  if(!isset($entity['UserAccountType'])){
276  $resultId = 3211;
277  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
278  $resultCode=sprintf($r['Message'], "UserAccountType");
279  $message=sprintf($r['Message'], "UserAccountType");
280  $type=3;
281  }else{$data['UserAccountType']=$entity['UserAccountType'];}
282 
283 
284  $IdUserAccount=(int)$data['IdUserAccount'];
285 
286  if($resultId==0){
287  $IdAsset=(int)$data['IdAsset'];
288  $IdAssetProperty=(int)$data['IdAssetProperty'];
289  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
290  ->from("AssetProperty","*")
291  ->where("IdAsset=$IdAsset OR 0=$IdAsset")
292  ->where("IdAssetProperty=$IdAssetProperty OR 0=$IdAssetProperty")
293  ->where("IdUserAccount=$IdUserAccount")
294  );
295  if($rows==null){
296  $resultId = 3005;
297  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
298  $resultCode=$r['Message'];
299  $message=$r['Message'];
300  $type=3;
301  }else{
302 
303  $k=$this->delete(array("IdAsset=$IdAsset OR 0=$IdAsset",
304  "IdAssetProperty=$IdAssetProperty OR 0=$IdAssetProperty",
305  "IdUserAccount=$IdUserAccount OR 0=$IdUserAccount"));
306  $resultCode="Date sterse";
307  }
308  }
309  }
310  catch(Exception $e){
311  $resultCode=$e->getMessage();
312  $resultId=101;
313  $type=3;
314  }
315  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
316  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
317  return $response;
318  }
319  //============ End deleteAssetProperty ==============================================================
320 
321 
322  //==== Start getAssetProperty =========================================================================
341  function getAssetProperty($entity) {
342  // function implementation
343  $resultId = 0;
344  $page="AssetProperty.php";
345  $method="getAssetProperty";
346  $result=json_encode($entity);
347  $message="";
348  $type="1";
349  $this->ErrorCode = new Application_Model_ErrorCode;
350  $this->Log = new Application_Model_Log;
351  $this->Paging = new Application_Model_Paging;
352 
353  try{
354  $pg=$this->Paging->getPageDefault('AssetProperty');
355 
356  $data=array();
357  if(!isset($entity['IdAssetProperty']))
358  {
359  $resultId = 3129;
360  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
361  $resultCode=sprintf($r['Message'], "IdAssetProperty");
362  $message=sprintf($r['Message'], "IdAssetProperty");
363  $type=3;
364  }else{$data['IdAssetProperty']=$entity['IdAssetProperty'];}
365  if(!isset($entity['IdAsset']))
366  {
367  $resultId = 3129;
368  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
369  $resultCode=sprintf($r['Message'], "IdAsset");
370  $message=sprintf($r['Message'], "IdAsset");
371  $type=3;
372  }else{$data['IdAsset']=$entity['IdAsset'];}
373  if(!isset($entity['IdUserAccount'])){
374  $resultId = 3129;
375  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
376  $resultCode=sprintf($r['Message'], "IdUserAccount");
377  $message=sprintf($r['Message'], "IdUserAccount");
378  $type=3;
379  }else{$data['IdUserAccount']=$entity['IdUserAccount'];}
380 
381  if(!isset($entity['UserAccountType'])){
382  $resultId = 3129;
383  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
384  $resultCode=sprintf($r['Message'], "UserAccountType");
385  $message=sprintf($r['Message'], "UserAccountType");
386  $type=3;
387  }else{$data['UserAccountType']=$entity['UserAccountType'];}
388 
389  if(!isset($entity['pageSize'])){
390  $_pageSize=$pg['pageSize'];
391  }else{
392  $_pageSize=$entity['pageSize'];
393  }
394 
395  if(!isset($entity['pageNo'])){
396  $_pageNo=$pg['pageNo'];
397  }else{$_pageNo=$entity['pageNo'];}
398 
399  if(!isset($entity['orderColumn'])){
400  $_orderColumn=$pg['orderColumn'];
401  }else{$_orderColumn=$entity['orderColumn'];}
402 
403  if(!isset($entity['orderType'])){
404  $_orderType=$pg['orderType'];
405  }else{
406  switch($entity['orderType'])
407  {
408  case 'ASC':
409  $_orderType="ASC";
410  break;
411  case 'DESC':
412  $_orderType="DESC";
413  break;
414  default:
415  $_orderType="DESC";
416  break;
417  }
418  }
419 
420  if(!isset($entity['orderColumn'])){
421  $_orderColumn=$pg['orderColumn'];
422  }else{
423  switch($entity['orderColumn'])
424  {
425  case 'IdAssetProperty':
426  $_orderColumn="IdAssetProperty";
427  break;
428  case 'IdAsset':
429  $_orderColumn="IdAsset";
430  break;
431  case 'Name':
432  $_orderColumn="Name";
433  break;
434  case 'PropertyValue':
435  $_orderColumn="PropertyValue";
436  break;
437  case 'PropertyString':
438  $_orderColumn="PropertyString";
439  break;
440  case 'PropertyDate':
441  $_orderColumn="PropertyDate";
442  break;
443  case 'PropertyType':
444  $_orderColumn="PropertyType";
445  break;
446  case 'IdUserAccount':
447  $_orderColumn="IdUserAccount";
448  break;
449  default:
450  $_orderColumn=$orderColumn;
451  break;
452  }
453 
454  }
455 
456  if($resultId==0){
457  if($data['UserAccountType']=="0"){
458  $IdUserAccount=0;
459  }else{
460  $IdUserAccount=(int)$data['IdUserAccount'];
461  }
462  $IdAssetProperty=(int)$data['IdAssetProperty'];
463  $IdAsset=(int)$data['IdAsset'];
464 
465  $count = $this->fetchRow($this->select()->setIntegrityCheck(false)
466  ->from("AssetProperty",array("total"=>"COUNT(IdAssetProperty)"))
467  ->where("IdAssetProperty=$IdAssetProperty OR 0=$IdAssetProperty")
468  ->where("IdAsset=$IdAsset OR 0=$IdAsset")
469  ->where("IdUserAccount=$IdUserAccount OR 0=$IdUserAccount")
470  );
471  if($count->total==0){
472 
473  $resultId = 3006;
474  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
475  $resultCode=$r['Message'];
476  $message=$r['Message'];
477  $type=3;
478  }else{
479 
480  $offset=$this->Paging->getOffset($count->total, $_pageSize, $_pageNo);
481 
482  $rows= $this->fetchAll($this->select()->setIntegrityCheck(false)
483  ->from("AssetProperty","*")
484  ->where("IdAssetProperty=$IdAssetProperty OR 0=$IdAssetProperty")
485  ->Where("IdAsset=$IdAsset OR 0=$IdAsset")
486  ->limit($_pageSize, $offset['start'])
487  ->order($_orderColumn." ".$_orderType)
488  );
489 
490  foreach($rows as $row){
491 
492  $resultEntity[]=array("IdAssetProperty"=>$row->IdAssetProperty,
493  "IdAsset" => $row->IdAsset,
494  "Name" => $row->Name,
495  "PropertyValue" => $row->PropertyValue,
496  "PropertyString" => $row->PropertyString,
497  "PropertyDate" => $row->PropertyDate,
498  "PropertyType" => $row->PropertyType,
499  );
500 
501  }
502  $resultCode=array("pageNo"=>$_pageNo,
503  "pageSize"=>$_pageSize,
504  "pageCount"=>$offset['maxPage'],
505  "orderColumn"=>$_orderColumn,
506  "orderType"=>$_orderType,"entity"=>$resultEntity) ;
507  }
508  }
509  }
510  catch(Exception $e){
511  $resultCode=$e->getMessage();
512  $resultId=101;
513  $type=3;
514  }
515  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
516  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
517  return $response;
518  }
519  //============ End getAssetProperty ==============================================================
520 
521 }