Next4Me
 All Classes Files Functions Variables
CmplxUserAccountAndDetail.php
Go to the documentation of this file.
1 <?php
17 {
18  //==== Start addEditUserAccountAndDetail =========================================================================
68  function addEditUserAccountAndDetail($entity){
69  $this->UserAccount = new Application_Model_UserAccount();
70  $this->Contact = new Application_Model_Contact();
71  $this->Email = new Application_Model_Email();
72  $this->Phone = new Application_Model_Phone();
73  $this->Address = new Application_Model_Address();
74  $commit=1;
75  $userAccountResult=$this->UserAccount->addEditUserAccount($entity);
76  if($userAccountResult['resultId']=="0"){
77  $lastId=$userAccountResult['resultId'];
78  if(isset($entity['Contact'])){
79  foreach($entity['Contact'] as $contact)
80  {
81  if($commit==1){
82  $contact['UserAccountType']=$entity['UserAccountType'];
83  $contact['IdUserAccount']=$entity['IdUserAccount'];
84  // echo "<pre>"; print_r($entity['AssetProperty']); echo "</pre>";
85  if((int)$contact['IdContact']<0){
86  $del['IdContact']=(int)$contact['IdContact']*(-1);
87  $del['IdUserAccount']=$entity['IdUserAccount'];
88  $del['UserAccountType']=$entity['UserAccountType'];
89  $contactDelete=$this->Contact->deleteContact($del);
90  if($contactDelete['resultId']!="0"){
91  //break;
92  $response=$contactDelete['resultCode'];
93  $commit=0;
94  }
95  }else{
96  $contact['IdContact']=$lastId;
97  $contactAddEdit=$this->Contact->addEditContact($contact);
98  if($contactAddEdit['resultId']!="0"){
99  //break;
100  $response=$contactAddEdit['resultCode'];
101  $commit=0;
102  }else{
103  $lastIdContact=$contactAddEdit['resultCode'];
104  if(isset($contact['Address'])){
105  foreach($contact['Address'] as $address){
106  if($commit==1){
107  $address['UserAccountType']=$entity['UserAccountType'];
108  $address['IdUserAccount']=$entity['IdUserAccount'];
109  // echo "<pre>"; print_r($entity['AssetProperty']); echo "</pre>";
110  if((int)$address['IdContact']<0){
111  $del['IdAddress']=(int)$address['IdAddress']*(-1);
112  $del['IdUserAccount']=$entity['IdUserAccount'];
113  $del['UserAccountType']=$entity['UserAccountType'];
114  $del['IdContact']="0";
115  $addressDelete=$this->Address->deleteAddress($del);
116  if($addressDelete['resultId']!="0"){
117  //break;
118  $response=$addressDelete['resultCode'];
119  $commit=0;
120  }
121  }else{
122  $address['IdContact']=$lastIdContact;
123  $addressAddEdit=$this->Address->addEditAddress($address);
124  if($addressAddEdit['resultId']!="0"){
125  //break;
126  $response=$addressAddEdit['resultCode'];
127  $commit=0;
128  }
129  }
130  }
131  }
132  }
133  if(isset($contact['Phone'])){
134  foreach($contact['Phone'] as $phone){
135  if($commit==1){
136  $phone['UserAccountType']=$entity['UserAccountType'];
137  $phone['IdUserAccount']=$entity['IdUserAccount'];
138  // echo "<pre>"; print_r($entity['AssetProperty']); echo "</pre>";
139  if((int)$phone['IdPhone']<0){
140  $del['IdPhone']=(int)$phone['IdPhone']*(-1);
141  $del['IdUserAccount']=$entity['IdUserAccount'];
142  $del['UserAccountType']=$entity['UserAccountType'];
143  $del['IdContact']="0";
144  $phoneDelete=$this->Phone->deletePhone($del);
145  if($phoneDelete['resultId']!="0"){
146  //break;
147  $response=$phoneDelete['resultCode'];
148  $commit=0;
149  }
150  }else{
151  $phone['IdContact']=$lastIdContact;
152  $phoneAddEdit=$this->Phone->addEditPhone($phone);
153  if($phoneAddEdit['resultId']!="0"){
154  //break;
155  $response=$phoneAddEdit['resultCode'];
156  $commit=0;
157  }
158  }
159  }
160  }
161  }
162  if(isset($contact['Email'])){
163  foreach($contact['Email'] as $email){
164  if($commit==1){
165  $email['UserAccountType']=$entity['UserAccountType'];
166  $email['IdUserAccount']=$entity['IdUserAccount'];
167  // echo "<pre>"; print_r($entity['AssetProperty']); echo "</pre>";
168  if((int)$email['IdEmail']<0){
169  $del['IdEmail']=(int)$email['IdEmail']*(-1);
170  $del['IdUserAccount']=$entity['IdUserAccount'];
171  $del['UserAccountType']=$entity['UserAccountType'];
172  $del['IdContact']="0";
173  $emailDelete=$this->Email->deleteEmail($del);
174  if($emailDelete['resultId']!="0"){
175  //break;
176  $response=$emailDelete['resultCode'];
177  $commit=0;
178  }
179  }else{
180  $email['IdContact']=$lastIdContact;
181  $emailAddEdit=$this->Email->addEditEmail($email);
182  if($emailAddEdit['resultId']!="0"){
183  //break;
184  $response=$emailAddEdit['resultCode'];
185  $commit=0;
186  }
187  }
188  }
189  }
190  }
191  }
192  }
193  }
194  }
195  }
196  if($commit==1){
197  $response=$userAccountResult;
198  }
199  }else{
200  $response=$userAccountResult;
201  $commit=0;
202  }
203 
204  return array("commit"=>$commit,"entity"=>$response);
205 
206  }
207  //==== End addEditUserAccountAndDetail =======================================================================
208 
209 
210  function deleteUserAccountAndDetail($entity){
211  $this->UserAccount = new Application_Model_UserAccount();
212  $this->Contact = new Application_Model_Contact();
213  $this->Email = new Application_Model_Email();
214  $this->Phone = new Application_Model_Phone();
215  $this->Address = new Application_Model_Address();
216  $commit=1;
217 
218  }
219  //==== Start getUserAccountAndDetail =======================================================================
231  function getUserAccountAndDetail($entity){
232  $this->UserAccount = new Application_Model_UserAccount();
233  $this->Contact = new Application_Model_Contact();
234  $this->Email = new Application_Model_Email();
235  $this->Phone = new Application_Model_Phone();
236  $this->Address = new Application_Model_Address();
237  $commit=1;
238  $userAccountRowset = $this->UserAccount->getUserAccount($entity);//array('bug_status = ?', 'NEW'));
239  //ho "<pre>".print_r($entity)."</pre>";
240  if($userAccountRowset['resultId']=="0"){
241  foreach($userAccountRowset['resultCode']['entity'] as $row)
242  {
243  //echo "<pre>".print_r($row)."</pre>";
244  $data=array("IdContact"=>"0", "IdUserAccount"=>$row['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
245  $_Contact="";
246  $contactRowset=$this->Contact->getContact($data);
247  if($contactRowset['resultId']=="0"){
248  foreach($contactRowset['resultCode']['entity'] as $contact)
249  {
250  $data=array("IdAddress"=>"0", "IdContact"=>$contact['IdContact'], "IdUserAccount"=>$row['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
251  $addressRowset=$this->Address->getAddress($data);
252  $_Address="";
253  if($addressRowset['resultId']=="0"){
254  foreach($addressRowset['resultCode']['entity'] as $address)
255  {
256  $_Address[]=array("IdAddress"=>$address['IdAddress'],
257  "Type"=>$address['Type'],
258  "IdRegion"=>$address['IdRegion'],
259  "Street"=>$address['Street'],
260  "Number"=>$address['Number'],
261  "Building"=>$address['Building'],
262  "Floor"=>$address['Floor'],
263  "Appartment"=>$address['Appartment'],
264  "Lat"=>$address['Lat'],
265  "Long"=>$address['Long'],
266  "IdContact"=>$address['IdContact']);
267  }
268  }else{
269  $_Address="";
270  }
271  $data=array("IdEmail"=>"0", "IdContact"=>$contact['IdContact'], "IdUserAccount"=>$row['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
272  $emailRowset=$this->Email->getEmail($data);
273  $_Email="";
274  if($emailRowset['resultId']=="0"){
275  foreach($emailRowset['resultCode']['entity'] as $email)
276  {
277  $_Email[]=array("IdEmail"=>$email['IdEmail'],
278  "Value"=>$email['Value'],
279  "Type"=>$email['Type'],
280  "IdContact"=>$email['IdContact']);
281 
282  }
283  }else{
284  $_Email="";
285  }
286  $data=array("IdPhone"=>"0", "IdContact"=>$contact['IdContact'], "IdUserAccount"=>$row['IdUserAccount'],"UserAccountType"=>$entity['UserAccountType']);
287  $phoneRowset=$this->Phone->getPhone($data);
288  $_Phone="";
289  if($phoneRowset['resultId']=="0"){
290  foreach($phoneRowset['resultCode']['entity'] as $phone)
291  {
292  $_Phone[]=array("IdPhone"=>$phone['IdPhone'],
293  "Value"=>$phone['Value'],
294  "Type"=>$phone['Type'],
295  "IdContact"=>$phone['IdContact']);
296 
297  }
298  }else{
299  $_Phone="";
300  }
301 
302  $_Contact[]=array("IdContact"=>$contact['IdContact'],
303  "Name"=>$contact['Name'],
304  "Surname"=>$contact['Surname'],
305  "Company"=>$contact['Company'],
306  "Birthday"=>$contact['Birthday'],
307  "Gender"=>$contact['Gender'],"Address"=>$_Address, "Phone"=>$_Phone, "Email"=>$_Email);
308  }
309  }else{
310  $_Contact="";
311  }
312  $_CmplxUserAccount[]=array("IdUserAccount"=>$row['IdUserAccount'],
313  "UserName"=>$row['UserName'],
314  "Password"=>$row['Password'],
315  "RecoveryAnswer"=>$row['RecoveryAnswer'],
316  "RecoveryQuestion"=>$row['RecoveryQuestion'],
317  "Email"=>$row['Email'],
318  "Active"=>$row['Active'],
319  "LastLogInIp"=>$row['LastLogInIp'],
320  "LastLogInDate"=>$row['LastLogInDate'],
321  "Fail"=>$row['Fail'],
322  "IdContactMyself"=>$row['IdContactMyself'],
323  "UserAccountType"=>$row['UserAccountType'],
324  "Contact"=>$_Contact);
325  }
326 
327  $result=array("resultId"=>$userAccountRowset['resultId'], "resultCode"=>array("pageNo"=>$userAccountRowset['resultCode']['pageNo'],
328  "pageSize"=>$userAccountRowset['resultCode']['pageSize'],
329  "pageCount"=>$userAccountRowset['resultCode']['pageCount'],
330  "orderColumn"=>$userAccountRowset['resultCode']['orderColumn'],
331  "orderType"=>$userAccountRowset['resultCode']['orderType'],"entity"=>$_CmplxUserAccount));
332  }else{
333  $result=array("resultId"=>$userAccountRowset['resultId'], "resultCode"=>$userAccountRowset['resultCode']);
334  }
335  return array("commit"=>"1","entity"=>$result);
336 
337  }
338  //==== End getUserAccountAndDetail =======================================================================
339 }