Next4Me
 All Classes Files Functions Variables
CmplxContextAndDetail.php
Go to the documentation of this file.
1 <?php
24 class Application_Model_CmplxContextAndDetail extends Zend_Db_Table
25 {
26  //==== Start getContextAndDetail =======================================================================
34  function getContextAndDetail($entity){
35  $this->Context = new Application_Model_Context();
36  $this->ContextCondition = new Application_Model_ContextCondition();
37  $this->ContextFactor = new Application_Model_ContextFactor();
38 
39  $contextsRowset=$this->Context->getContext($entity);
40 
41  if($contextsRowset['resultId']=="0"){
42  foreach($contextsRowset['resultCode']['entity'] as $contextRow)
43  {
44  $data=array("IdContext"=>$contextRow['IdContext'], "IdContextCondition"=>"0", "IdUserAccount"=>$entity['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
45  $contextCondition=array();
46  $contextConditionsRowset=$this->ContextCondition->getContextCondition($data);
47  if($contextConditionsRowset['resultId']=="0"){
48  foreach($contextConditionsRowset['resultCode']['entity'] as $contextConditionRow)
49  {
50  $contextFactor=array();
51  $data=array("IdContextFactor"=>"0", "IdContextCondition"=>$contextConditionRow['IdContextCondition'], "IdUserAccount"=>$entity['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
52  $contextFactorsRowset=$this->ContextFactor->getContextFactor($data);
53  if($contextFactorsRowset['resultId']=="0"){
54  //echo "<pre>"; print_r($contextFactorsRowset['resultCode']); echo "</pre>";
55  foreach($contextFactorsRowset['resultCode']['entity'] as $contextFactorRow){
56  $contextFactor[]=array("IdContextFactor"=>$contextFactorRow['IdContextFactor'],
57  "IdContextCondition"=>$contextFactorRow['IdContextCondition'],
58  "IdTplContextFactor"=>$contextFactorRow['IdTplContextFactor'],
59  "Description"=>$contextFactorRow['Description'],
60  "Type"=>$contextFactorRow['Type'],
61  "Function"=>$contextFactorRow['Function'],
62  "Value"=>$contextFactorRow['Value']);
63  }
64  }
65  $contextCondition[]=array("IdContextCondition"=>$contextConditionRow['IdContextCondition'],
66  "IdContext"=>$contextConditionRow['IdContext'],
67  "IdTplContextCondition"=>$contextConditionRow['IdTplContextCondition'],
68  "Name"=>$contextConditionRow['Name'],
69  "Description"=>$contextConditionRow['Description'],
70  "ContextFactors"=>$contextFactor);
71  }
72  }
73  $_CmplxContext[]=array("IdContext"=>$contextRow['IdContext'],
74  "IdTplContext"=>$contextRow['IdTplContext'],
75  "Name"=>$contextRow['Name'],
76  "Description"=>$contextRow['Description'],
77  "IdUserAccount"=>$contextRow['IdUserAccount'], "ContextCondition"=>$contextCondition);
78  }
79  $result=array("resultId"=>$contextsRowset['resultId'], "resultCode"=>$_CmplxContext);
80  }else{
81  $result=array("resultId"=>$contextsRowset['resultId'], "resultCode"=>$contextsRowset['resultCode']);
82  }
83  return array("commit"=>"1","entity"=>$result);
84  }
85  //==== End getContextAndDetail =======================================================================
86 
87  //==== Start addEditContextAndDetail =========================================================================
112  function addEditContextAndDetail($entity){
113 
114  $this->Context = new Application_Model_Context();
115  $this->ContextCondition = new Application_Model_ContextCondition();
116  $this->ContextFactor = new Application_Model_ContextFactor();
117  //echo "<pre>"; print_r($entity); echo "</pre>";
118  $commit=1;
119  $contextResult=$this->Context->addEditContext($entity);
120  if($contextResult['resultId']=="0"){
121  $lastId=$contextResult['resultCode'];
122  $response=$contextResult['resultCode'];
123  //echo "<pre>"; print_r($contextResult); echo "</pre>";
124 
125  if(isset($entity['ContextCondition'])){
126  //echo "<pre>"; print_r($entity['ContextCondition']); echo "</pre>";
127  foreach($entity['ContextCondition'] as $condition)
128  {
129  if($commit==1){
130  $condition['UserAccountType']=$entity['UserAccountType'];
131  $condition['IdUserAccount']=$entity['IdUserAccount'];
132  //echo "<pre>"; print_r($condition); echo "</pre>";
133  if((int)$condition['IdContextCondition']<0){
134  $del['IdContextCondition']=(int)$condition['IdContextCondition']*(-1);
135  $del['IdUserAccount']=$entity['IdUserAccount'];
136  $del['UserAccountType']=$entity['UserAccountType'];
137  $del['IdContext']="0";
138  $factorDelete=$contextFactor->deleteContextFactor($del);
139  $conditionDelete=$contextCondition->deleteContextCondition($del);
140  if($conditionDelete['resultId']!="0"){
141  $response=$conditionDelete['resultCode'];
142  $commit=0;
143  }
144  }else{
145  //echo "Sunt pe addEdit";
146 
147  $condition['IdContext']=$lastId;
148  $conditionAddEdit=$this->ContextCondition->addEditContextCondition($condition);
149  //echo "<pre>"; print_r($conditionAddEdit); echo "</pre>";
150  if($conditionAddEdit['resultId']!="0"){
151  $response=$conditionAddEdit['resultCode'];
152  $commit=0;
153  }else{
154  $lastIdCondition=$conditionAddEdit['resultCode'];
155  if(isset($condition['ContextFactor'])){
156  foreach($condition['ContextFactor'] as $factor)
157  {
158  if($commit==1){
159  $factor['UserAccountType']=$entity['UserAccountType'];
160  $factor['IdUserAccount']=$entity['IdUserAccount'];
161  if((int)$factor['IdContextFactor']<0){
162  $delFactor['IdContextFactor']=(int)$factor['IdContextFactor']*(-1);
163  $delFactor['IdUserAccount']=$entity['IdUserAccount'];
164  $delFactor['UserAccountType']=$entity['UserAccountType'];
165  $delFactor['IdContextCondition']="0";
166  $factorDelete=$contextFactor->deleteContextFactor($delFactor);
167  if($factorDelete['resultId']!="0"){
168  $response=$factorDelete['resultCode'];
169  $commit=0;
170  }
171  }else{
172  $factor['IdContextCondition']=$lastIdCondition;
173  $factorAddEdit=$this->ContextFactor->addEditContextFactor($factor);
174  //echo "<pre>"; print_r($factorAddEdit); echo "</pre>";
175  if($factorAddEdit['resultId']!="0"){
176  $response=$factorAddEdit['resultCode'];
177  $commit=0;
178  }
179  }
180  }
181  }
182  }
183  }
184 
185  }
186  }
187  }
188  }
189  if($commit==1){
190  $response=$contextResult;
191  }
192  }else{
193  $response=$contextResult;
194  $commit=0;
195  }
196  return array("commit"=>$commit,"entity"=>$response);
197  }
198  //==== End addEditContextAndDetail =========================================================================
199 
200  //==== Start deleteContextAndDetail =========================================================================
208  function deleteContextAndDetail($entity){
209  $this->Context = new Application_Model_Context();
210  $this->ContextCondition = new Application_Model_ContextCondition();
211  $this->ContextFactor = new Application_Model_ContextFactor();
212  $contextsRowset=$this->Context->getContext($entity);
213 
214  if($contextsRowset['resultId']=="0"){
215  foreach($contextsRowset['resultCode']['entity'] as $contextRow)
216  {
217  $data1=array("IdContext"=>$contextRow['IdContext'], "IdContextCondition"=>"0", "IdUserAccount"=>$entity['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
218  $contextCondition=array();
219  $contextConditionsRowset=$this->ContextCondition->getContextCondition($data1);
220  if($contextConditionsRowset['resultId']=="0"){
221  foreach($contextConditionsRowset['resultCode']['entity'] as $contextConditionRow)
222  {
223  $contextFactor=array();
224  $data=array("IdContextFactor"=>"0", "IdContextCondition"=>$contextConditionRow['IdContextCondition'], "IdUserAccount"=>$entity['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
225  $delFactorsRowset=$this->ContextFactor->deleteContextFactor($data);
226  }
227  }
228  $delConditionsRowset=$this->ContextCondition->deleteContextCondition($data1);
229  }
230  $delContextsRowset=$this->Context->deleteContext($entity);
231  $result=array("resultId"=>$delContextsRowset['resultId'], "resultCode"=>$delContextsRowset['resultCode']);
232  }else{
233  $result=array("resultId"=>$contextsRowset['resultId'], "resultCode"=>$contextsRowset['resultCode']);
234  }
235  return array("commit"=>"1","entity"=>$result);
236  }
237  //==== End deleteContextAndDetail =========================================================================
238 }