Next4Me
 All Data Structures Files Functions Variables
application/models/CmplxAssets.php
00001 <?php
00002 
00021 class CmplxAssetAndProperties  {
00022     //put your code here
00023     
00024         //==== Start GetAssetAndProperties =========================================================================
00036         function GetAssetAndProperties($entity) {
00037             
00038             $this->Assets = new Assets();
00039             $this->AssetProperties = new AssetProperties();
00040             $Assets=$this->Assets->GetAssets($entity);
00041             foreach($Assets as $a)
00042             {
00043                 $entity=array("IdAsset"=>$a['IdAsset']);
00044                 $AssetProperties=$this->AssetProperties->GetAssetProperties($entity);
00045                 
00046                 $resultCode[]=array_push($a,$AssetProperties);
00047             }
00048             
00049             return $resultCode;
00050             
00051         }
00052         //============ End GetAssetAndProperties ==============================================================
00053 
00054         //==== Start AddEditAssetAndProperties =========================================================================
00075         function AddEditAssetAndProperties($entity,$IdUser) {
00076             //require_once 'Zend/Db.php';
00077             $this->Assets = new Assets();
00078             $this->AssetProperties = new AssetProperties();
00079             if($IdUser==0){
00080                 $idu=$entity['IdUser'];
00081             }else{
00082                 $idu=$IdUser;
00083             }
00084             $assetData=array("IdAsset"=>$entity['IdAsset'],
00085                             "IdTplAssetType"=>$entity['IdTplAssetType'],
00086                             "Name"=>$entity['IdTplAssetType'],
00087                             "IdUser"=>$idu);
00088             //zona de adaugare inregistrare noua
00089                 if($entity['IdAsset']=="0"){
00090                     $r=$this->Assets->AddEditAssets($assetData);
00091                     if ($r['resultId']=="0"){
00092                         $lastId= $r['resultCode'];
00093                         foreach($entity['AssetProperties'] as $property)
00094                         {
00095                             $property['IdAsset']=$lastId;
00096                             $p=$this->AssetProperties->AddEditAssetProperties($property);
00097                             if($p['resultId']!="0"){
00098                                 return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00099                                 break;
00100                             }
00101                         }
00102                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00103                     }else{
00104                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00105                     }
00106                     
00107                 }else{
00108                     //zona de edit inregistrare
00109                     $r=$this->Assets->AddEditAssets($assetData);
00110                     if ($r['resultId']=="0"){
00111                         $lastId= $r['resultCode'];
00112                         foreach($entity['AssetProperties'] as $property)
00113                         {
00114                             //echo $property['IdAssetProperty']."<br>";
00115                             if((int)$property['IdAssetProperty']>=0){
00116                                 $property['IdAsset']=$lastId;
00117                             $p=$this->AssetProperties->AddEditAssetProperties($property);
00118                             if($p['resultId']!="0"){
00119                                 return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00120                                 break;
00121                             }
00122                             }else{
00123                                 $entity['IdAssetProperty']=(int)$property['IdAssetProperty']*(-1);
00124                                $p=$this->AssetProperties->DeleteAssetProperties($entity);
00125                                 if($p['resultId']!="0"){
00126                                     return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00127                                     break;
00128                                 }
00129                             }
00130                         }
00131                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00132                     }else{
00133                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00134                     }
00135                 }
00136                 
00137             
00138         }
00139         //============ End AddEditAssetAndProperties ==============================================================
00140 
00141         //==== DeleteAssetAndProperties =========================================================================
00149         function DeleteAssetAndProperties($entity) {
00150             //require_once 'Zend/Db.php';
00151             
00152             $this->Assets = new Assets();
00153             $this->AssetProperties = new AssetProperties();
00154             $this->AssetProperties->DeleteAssetProperties($entity);
00155             $this->Assets->DeleteAssets($entity);
00156                 
00157             return array("resultId"=>"0", "resultCode"=>"Date Sterse");
00158         }
00159         //============ End DeleteAssetAndProperties ==============================================================
00160 }
00161 ?>