Next4Me
 All Classes Files Functions Variables
CmplxAssetAndProperty.php
Go to the documentation of this file.
1 <?php
24 class Application_Model_CmplxAssetAndProperty extends Zend_Db_Table
25 {
26  //==== Start addEditAssetAndProperty =========================================================================
45  function addEditAssetAndProperty($entity){
46  //$this->db = $this->getActionController()->getInvokeArg("bootstrap")->getResource("db");
47  //$this->db= new Application_Model_DbTable_Transactions();
48  $this->Asset = new Application_Model_Asset();
49  $this->AssetProperty = new Application_Model_AssetProperty();
50 
51  //echo "<pre>"; print_r($entity); echo "</pre>";
52  $commit=1;
53  $assetResult=$this->Asset->addEditAsset($entity);
54  //echo "<pre>"; print_r($assetResult); echo "</pre>";
55  if($assetResult['resultId']=="0"){
56  $lastId=$assetResult['resultCode'];
57  $response=$assetResult['resultCode'];
58  if(isset($entity['AssetProperty'])){
59  foreach($entity['AssetProperty'] as $property)
60  {
61  if($commit==1){
62  $property['UserAccountType']=$entity['UserAccountType'];
63  $property['IdUserAccount']=$entity['IdUserAccount'];
64  // echo "<pre>"; print_r($entity['AssetProperty']); echo "</pre>";
65  if((int)$property['IdAssetProperty']<0){
66  $del['IdAssetProperty']=(int)$property['IdAssetProperty']*(-1);
67  $del['IdUserAccount']=$entity['IdUserAccount'];
68  $del['UserAccountType']=$entity['UserAccountType'];
69  $del['IdAsset']="0";
70  $propertyDelete=$this->AssetProperty->deleteAssetProperty($del);
71  if($propertyDelete['resultId']!="0"){
72  //break;
73  $response=$propertyDelete['resultCode'];
74  $commit=0;
75  }
76  }else{
77  $property['IdAsset']=$lastId;
78  $propertyAddEdit=$this->AssetProperty->addEditAssetProperty($property);
79  if($propertyAddEdit['resultId']!="0"){
80  //break;
81  $response=$propertyAddEdit['resultCode'];
82  $commit=0;
83  }
84  }
85  }
86  }
87  }
88  if($commit==1){
89  $response=$assetResult;
90  }
91  }else{
92  $response=$assetResult;
93  $commit=0;
94  }
95 
96  return array("commit"=>$commit,"entity"=>$response);
97 
98  }
99  //==== End addEditAssetAndProperty =========================================================================
100 
101  //==== Start deleteAssetAndProperty =========================================================================
109  function deleteAssetAndProperty($entity){
110 
111  $this->Asset = new Application_Model_Asset();
112  $this->AssetProperty = new Application_Model_AssetProperty();
113 
114  $commit=1;
115  $entity['IdAssetProperty']="0";
116  $propertyResult=$this->AssetProperty->deleteAssetProperty($entity);
117  if($propertyResult['resultId']!="0"){
118  $commit=0;
119  $response=$propertyResult['resultCode'];
120  }
121  if($commit==1){
122  $assetResult=$this->Asset->deleteAsset($entity);
123  if($assetResult['resultId']!="0"){
124  $commit=0;
125  $response=$assetResult;
126  }else{
127  $response=$assetResult;
128  }
129  }
130 
131  return array("commit"=>$commit,"entity"=>$response);
132  }
133  //==== End deleteAssetAndProperty =========================================================================
134 
135  //==== Start getAssetAndProperty =======================================================================
143  function getAssetAndProperty($entity){
144  $this->Asset = new Application_Model_Asset();
145  $this->AssetProperty = new Application_Model_AssetProperty();
146 
147 
148  //if()
149  $assetsRowset = $this->Asset->getAsset($entity);//array('bug_status = ?', 'NEW'));
150  //echo "<pre>"; print_r($assetsRowset); echo "</pre>";
151  if($assetsRowset['resultId']=="0"){
152  foreach($assetsRowset['resultCode']['entity'] as $row)
153  {
154  //echo "<pre>"; print_r($row); echo "</pre>";
155  //echo "<pre>"; print_r($assetsRowset); echo "</pre>";
156  $data=array("IdAsset"=>$row['IdAsset'], "IdAssetProperty"=>"0", "IdUserAccount"=>$entity['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
157  $rowAssetProperty=$this->AssetProperty->getAssetProperty($data);
158  $assetProperty=array();
159  if($rowAssetProperty['resultId']=="0"){
160  foreach($rowAssetProperty['resultCode']['entity'] as $assetPropertyRow)
161  {
162  $assetProperty[]=array("IdAssetProperty"=>$assetPropertyRow['IdAssetProperty'],
163  "IdAsset"=>$assetPropertyRow['IdAsset'],
164  "Name"=>$assetPropertyRow['Name'],
165  "PropertyValue"=>$assetPropertyRow['PropertyValue'],
166  "PropertyString"=>$assetPropertyRow['PropertyString'],
167  "PropertyDate"=>$assetPropertyRow['PropertyDate'],
168  "PropertyType"=>$assetPropertyRow['PropertyType']);
169  }
170  }
171  $_CmplxAsset[]=array("IdAsset"=>$row['IdAsset'],
172  "IdTplAsset"=>$row['IdTplAsset'],
173  "Name"=>$row['Name'],
174  "IdUserAccount"=>$row['IdUserAccount'],
175  "AssetProperty"=>$assetProperty);
176 
177  }
178  $result=array("resultId"=>$assetsRowset['resultId'], "resultCode"=>$_CmplxAsset);
179  }else{
180  $result=array("resultId"=>$assetsRowset['resultId'], "resultCode"=>$assetsRowset['resultCode']);
181  }
182  return array("commit"=>"1","entity"=>$result);
183  }
184  //==== End getAssetAndProperty =======================================================================
185 }