Next4Me
 All Classes Files Functions Variables
application/models/CmplxAsset.php
Go to the documentation of this file.
00001 <?php
00002 
00021 class CmplxAssetAndProperty  {
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             echo "<pre>"; print_r($Assets); echo "</pre>"; //exit;
00042             foreach($Assets['resultCode'] as $a)
00043             {
00044                 $entity=array("IdAsset"=>$a['IdAsset']);
00045                 $AssetProperties=$this->AssetProperties->GetAssetProperties($entity);
00046                 echo "<br>---------";                print_r($entity);
00047                 echo "<pre>"; print_r($AssetProperties); echo "</pre>";
00048                 if($AssetProperties['resultId']=="0"){
00049                 $resultCode[]=array_push($a,$AssetProperties['resultCode']);
00050                 }
00051             }
00052             echo "<pre>"; print_r($resultCode); echo "</pre>";
00053             return $resultCode;
00054             
00055         }
00056         //============ End GetAssetAndProperties ==============================================================
00057 
00058         //==== Start AddEditAssetAndProperties =========================================================================
00079         function AddEditAssetAndProperties($entity,$IdUser) {
00080             //require_once 'Zend/Db.php';
00081             $this->Assets = new Assets();
00082             $this->AssetProperties = new AssetProperties();
00083             if($IdUser==0){
00084                 $idu=$entity['IdUser'];
00085             }else{
00086                 $idu=$IdUser;
00087             }
00088             $assetData=array("IdAsset"=>$entity['IdAsset'],
00089                             "IdTplAssetType"=>$entity['IdTplAssetType'],
00090                             "Name"=>$entity['IdTplAssetType'],
00091                             "IdUser"=>$idu);
00092             //zona de adaugare inregistrare noua
00093                 if($entity['IdAsset']=="0"){
00094                     $r=$this->Assets->AddEditAssets($assetData);
00095                     if ($r['resultId']=="0"){
00096                         $lastId= $r['resultCode'];
00097                         foreach($entity['AssetProperties'] as $property)
00098                         {
00099                             $property['IdAsset']=$lastId;
00100                             $p=$this->AssetProperties->AddEditAssetProperties($property);
00101                             if($p['resultId']!="0"){
00102                                 return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00103                                 break;
00104                             }
00105                         }
00106                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00107                     }else{
00108                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00109                     }
00110                     
00111                 }else{
00112                     //zona de edit inregistrare
00113                     $r=$this->Assets->AddEditAssets($assetData);
00114                     if ($r['resultId']=="0"){
00115                         $lastId= $r['resultCode'];
00116                         foreach($entity['AssetProperties'] as $property)
00117                         {
00118                             //echo $property['IdAssetProperty']."<br>";
00119                             if((int)$property['IdAssetProperty']>=0){
00120                                 $property['IdAsset']=$lastId;
00121                             $p=$this->AssetProperties->AddEditAssetProperties($property);
00122                             if($p['resultId']!="0"){
00123                                 return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00124                                 break;
00125                             }
00126                             }else{
00127                                 $entity['IdAssetProperty']=(int)$property['IdAssetProperty']*(-1);
00128                                $p=$this->AssetProperties->DeleteAssetProperties($entity);
00129                                 if($p['resultId']!="0"){
00130                                     return array("resultId"=>$p['resultId'], "resultCode"=>$p['resultCode']);
00131                                     break;
00132                                 }
00133                             }
00134                         }
00135                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00136                     }else{
00137                         return array("resultId"=>$r['resultId'], "resultCode"=>$r['resultCode']);
00138                     }
00139                 }
00140                 
00141             
00142         }
00143         //============ End AddEditAssetAndProperties ==============================================================
00144 
00145         //==== DeleteAssetAndProperties =========================================================================
00153         function DeleteAssetAndProperties($entity) {
00154             //require_once 'Zend/Db.php';
00155             
00156             $this->Assets = new Assets();
00157             $this->AssetProperties = new AssetProperties();
00158             $this->AssetProperties->DeleteAssetProperties($entity);
00159             $this->Assets->DeleteAssets($entity);
00160                 
00161             return array("resultId"=>"0", "resultCode"=>"Date Sterse");
00162         }
00163         //============ End DeleteAssetAndProperties ==============================================================
00164 }
00165 ?>