public function testSaveAndLoad()
 {
     $person = new Person($this->testPersonId);
     $this->assertEquals($this->testPersonId, $person->getId());
     $address = new Address();
     $address->setAddress('test');
     $address->setPerson($person);
     $address->save();
     $id = $address->getId();
     $this->assertNotEmpty($id);
     $address = new Address($id);
     $this->assertEquals('test', $address->getAddress());
     $this->assertEquals(1, $address->getPerson_id());
 }
Exemple #2
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();
     }
 }