Next4Me
 All Data Structures Files Functions Variables
application/models/Assets.php
Go to the documentation of this file.
00001 <?php 
00018 class Assets  extends Zend_Db_Table_Abstract {
00019     //put your code here
00020     protected $_name="Assets"; 
00021     protected $_primary="IdAsset";  
00022     
00023 
00024         //==== Start AddEditAssets =========================================================================
00036         function AddEditAssets($entity) {
00037                         // function implementation
00038             $resultId = 0;
00039             $page="Assets.php";
00040             $method="AddEditAssets";
00041             $result=json_encode($entity);
00042             $message="";
00043             $type="1";
00044             $this->ErrorCode = new ErrorCode;
00045             $this->Log = new Log;
00046             try{
00047                 
00048                 if ($entity['IdAsset']=="0"){
00049                     $k=$this->insert($entity);
00050                     $k=$this->getAdapter()->lastInsertId();
00051                     $resultCode=$k;                        
00052                 }else{
00053                     $row = $this->fetchRow($this->select()->setIntegrityCheck(false)
00054                             ->from("Assets","*")
00055                             ->where("IdAsset=?",$entity['IdAsset'])
00056                     );      
00057                     if($row==null){
00058                         $resultId = 3001;
00059                         $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00060                         $resultCode=$r['Message'];
00061                         $message=$r['Message'];
00062                         $type=3;
00063                     }else{
00064                     $this->update(array(
00065                         "IdTplAssetType" => $entity['IdTplAssetType'],
00066                         "Name" => $entity['Name'],
00067                     ),$this->getAdapter()->quoteInto('IdAsset=?',$entity['IdAsset']));
00068                      $k=$entity['IdAsset'];                     
00069                      $resultCode=$k;    
00070                      $message=$k;
00071                     }
00072                 }
00073                 }
00074                 catch(Exception $e){
00075                     $resultCode=$e->getMessage();
00076                     $resultId=101;       
00077                     $type=3;
00078                 }
00079                 $this->Log->save($page,$method,json_encode($entity),$resultId.'=>'.$resultCode,$type);
00080                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00081         return $response;    
00082         }
00083         //============ End AddEditAssets ==============================================================
00084 
00085 
00086         //==== Start DeleteAssets =========================================================================
00096         function DeleteAssets($entity) {
00097                         // function implementation
00098             $resultId = 0;
00099             $page="Assets.php";
00100             $method="DeleteAssets";
00101             $result=json_encode($entity);
00102             $message="";
00103             $type="1";
00104             $this->ErrorCode = new ErrorCode;
00105             $this->Log = new Log;
00106 
00107             try{
00108                 $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00109                             ->from("Assets","*")
00110                             ->where("IdAsset=?",$entity['IdAsset'])
00111                     );
00112                 if($rows==null){
00113                     $resultId = 3002;
00114                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00115                     $resultCode=$r['Message'];
00116                     $message=$r['Message'];
00117                     $type=3;
00118                 }else{
00119                     $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
00120                             ->from("AssetProperties","*")
00121                             ->where("IdAsset=?",$entity['IdAsset'])
00122                     );
00123                     if($chld==null){
00124                         $k=$this->delete($this->getAdapter()->quoteInto("IdAsset=?",$entity['IdAsset']));
00125                         $resultCode="Date sterse";    
00126                         
00127                     }else{
00128                         $resultId = 4001;
00129                         $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00130                         $resultCode=$r['Message'];
00131                         $message=$r['Message'];
00132                         $type=3;
00133                     }
00134                 }
00135             }
00136             catch(Exception $e){
00137                 $resultCode=$e->getMessage();
00138                     $resultId=101;       
00139                     $type=3;
00140                 }
00141                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00142                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00143           return $response;
00144         }
00145         //============ End DeleteAssets ==============================================================
00146 
00147 
00148         //==== Start GetAssets =========================================================================
00158         function GetAssets($entity) {
00159                         // function implementation
00160             $resultId = 0;
00161             $page="Assets.php";
00162             $method="GetAssets";
00163             $result=json_encode($entity);
00164             $message="";
00165             $type="1";
00166             $this->ErrorCode = new ErrorCode;
00167             $this->Log = new Log;
00168 
00169             try{
00170                 
00171                 $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00172                             ->from("Assets","*")
00173                             ->where("IdAsset=?",$entity['IdAsset'])
00174                             ->orWhere("0=?", $entity['IdAsset'])
00175                     );
00176                  
00177             if(count($rows)==0){
00178                     $resultId = 3003;
00179                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00180                     $resultCode=$r['Message'];
00181                     $message=$r['Message'];
00182                     $type=3;
00183             }else{
00184                 
00185                     foreach($rows as $row){
00186 
00187                         $resultCode[]=array("IdAsset"=>$row->IdAsset,
00188                             "IdTplAssetType" => $row->IdTplAssetType,
00189                             "Name" => $row->Name,
00190                             "IdUser" => $row->IdUser,);
00191                     }
00192                     
00193             }
00194             }
00195             catch(Exception $e){
00196                 $resultCode=$e->getMessage();
00197                 $resultId=101;       
00198                 $type=3;
00199             }
00200                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00201                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00202          return $response;  
00203         
00204         }
00205         //============ End GetAssets ==============================================================
00206 
00207 }
00208 
00209 ?>