Пример #1
0
 public function testSaveAndLoad()
 {
     $email = new Email();
     $email->setPerson_id($this->testPerson_id);
     $email->setEmail('something@localhost');
     $email->save();
     $id = $email->getId();
     $this->assertNotEmpty($id);
     $email = new Email($id);
     $this->assertEquals('something@localhost', $email->getEmail());
 }
Пример #2
0
 public function update()
 {
     $errorURL = isset($_REQUEST['return_url']) ? $_REQUEST['return_url'] : BASE_URL . '/people';
     if (isset($_REQUEST['person_id']) && $_REQUEST['person_id']) {
         try {
             $person = new Person($_REQUEST['person_id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
             header("Location: {$errorURL}");
             exit;
         }
     } else {
         $person = new Person();
     }
     if (isset($_POST['firstname'])) {
         try {
             $newRecord = $person->getId() ? false : true;
             $person->handleUpdate($_POST);
             $person->save();
             if ($newRecord) {
                 if (!empty($_POST['email'])) {
                     $email = new Email();
                     $email->setPerson($person);
                     $email->setEmail($_POST['email']);
                     $email->save();
                 }
                 if (!empty($_POST['phone'])) {
                     $phone = new Phone();
                     $phone->setPerson($person);
                     $phone->setNumber($_POST['phone']);
                     $phone->save();
                 }
             }
             if (isset($_REQUEST['return_url'])) {
                 $return_url = new Url($_REQUEST['return_url']);
                 $return_url->person_id = $person->getId();
             } elseif (isset($_REQUEST['callback'])) {
                 $return_url = new Url(BASE_URL . '/callback');
                 $return_url->callback = $_REQUEST['callback'];
                 $return_url->data = "{$person->getId()}";
             } else {
                 $return_url = $person->getURL();
             }
             header("Location: {$return_url}");
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $this->template->title = 'Update a person';
     $this->template->blocks[] = new Block('people/updatePersonForm.inc', array('person' => $person));
 }
Пример #3
0
 * on the web server.
 * If you are planning on using local authentication, you must
 * provide a password here.  The password will be encrypted when
 * the new person's account is saved
 *
 * If you are doing Employee or CAS authentication you do
 * not need to save a password into the database.
 *
 * @copyright 2011-2014 City of Bloomington, Indiana
 * @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
 * @author Cliff Ingham <*****@*****.**>
 */
use Application\Models\Person;
use Application\Models\Email;
include '../configuration.inc';
$person = new Person();
// Fill these out as needed
$person->setFirstname('Admin');
$person->setLastname('Person');
$person->setUsername('administrator');
$person->setAuthenticationMethod('local');
#$person->setPassword('');
// You most likely want Administrator
$person->setRole('Administrator');
$person->save();
// Don't forget to create an email address
$email = new Email();
$email->setPerson($person);
$email->setEmail('admin@localhost');
$email->save();
Пример #4
0
 /**
  * @param ExternalIdentity $identity An object implementing ExternalIdentity
  */
 public function populateFromExternalIdentity(ExternalIdentity $identity)
 {
     if (!$this->getFirstname() && $identity->getFirstname()) {
         $this->setFirstname($identity->getFirstname());
     }
     if (!$this->getLastname() && $identity->getLastname()) {
         $this->setLastname($identity->getLastname());
     }
     // We're going to be adding email and phone records for this person.
     // We have to save the person record before we can do the foreign keys.
     if (!$this->getId()) {
         $this->save();
     }
     $list = $this->getEmails();
     if (!count($list) && $identity->getEmail()) {
         $email = new Email();
         $email->setPerson($this);
         $email->setEmail($identity->getEmail());
         $email->save();
     }
     $list = $this->getPhones();
     if (!count($list) && $identity->getPhone()) {
         $phone = new Phone();
         $phone->setPerson($this);
         $phone->setNumber($identity->getPhone());
         $phone->save();
     }
     $list = $this->getAddresses();
     if (!count($list) && $identity->getAddress()) {
         $address = new Address();
         $address->setPerson($this);
         $address->setAddress($identity->getAddress());
         $address->setCity($identity->getCity());
         $address->setState($identity->getState());
         $address->setZip($identity->setZip());
         $address->save();
     }
 }