public function update(array $params) { if (!empty($_REQUEST['id'])) { try { $person = new Person($_REQUEST['id']); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } else { $person = new Person(); } if (isset($person)) { if (isset($_POST['username'])) { try { $person->handleUpdateUserAccount($_POST); // We might have populated this person's information from LDAP // We need to do a new lookup in the system, to see if a person // with their email address already exists. // If they already exist, we should add the account info to that // person record. if (!$person->getId() && $person->getEmail()) { try { $existingPerson = new Person($person->getEmail()); $existingPerson->handleUpdateUserAccount($_POST); } catch (\Exception $e) { } } if (isset($existingPerson)) { $existingPerson->save(); } else { $person->save(); } header('Location: ' . BASE_URL . '/users'); exit; } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } return new \Application\Views\Users\UpdateView(['user' => $person]); } else { return new \Applications\Views\NotFoundView(); } }
public function testSave() { $person = new Person(); $person->setFirstname('First'); $person->setLastname('Last'); $person->setEmail('test@localhost'); $person->save(); $person = new Person('test@localhost'); $this->assertEquals('First', $person->getFirstname()); $this->assertEquals('Last', $person->getLastname()); $this->assertEquals('test@localhost', $person->getEmail()); }