/** * Checks if provided person is the same person who is logged in. * Contains somehow tricky logic, for identity, stored in a session * is not an instance of Person. * See documentation for \Application\Entity\Account class for details. * @param Person $person person to check if logged in * @return boolean true then and only then $person has the same ID as logged in person */ protected function isMyself(Person $person) { if ($this->identity() == null) { return false; } if ($myself = $this->identity()->getPerson()) { if ($myself == null) { return false; } return $person->getId() == $myself->getId(); } return false; }
public function destroy(Person $source, $idOfContact) { $contact = $this->retrieve($idOfContact); if ($source->getContacts()->contains($contact)) { $this->objectManager->remove($contact); /* * Note: Reflected contact might not be needed for other types of contacts. * TODO Implement DQL query for handling deletion of bidirectional contacts. */ foreach ($contact->getTarget()->getContacts() as $reflectedContact) { if ($reflectedContact->getTarget()->getId() == $source->getId()) { $this->objectManager->remove($reflectedContact); } } $this->objectManager->flush(); } }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }