public function isValidMother(PersonaInterface $persona, PersonaInterface $mother)
 {
     $errors = [];
     if ($mother->getGender() !== self::GENDER_FEMALE) {
         $errors[] = 'Mother must be a female';
     }
     if ($mother->hasDateOfBirth() && $persona->hasDateOfBirth() && (int) $mother->getDateOfBirth('Y') >= (int) $persona->getDateOfBirth('Y')) {
         $errors[] = 'Child must be younger than the parent';
     }
     return $this->getResult($errors);
 }
예제 #2
0
 public function setMother(PersonaInterface $mother = null)
 {
     if ($mother instanceof PersonaInterface) {
         if ($this->parentsValidator->isValidMother($this, $mother)) {
             $this->mother = $mother;
             if (!$this->mother->getChildren()->contains($this)) {
                 $this->mother->addChild($this);
             }
         } else {
             $this->throwValidationErrors($this->parentsValidator);
         }
     }
 }
 public function isValidSpouse(PersonaInterface $persona, PersonaInterface $spouse)
 {
     $errors = [];
     if ($persona === $spouse) {
         $errors[] = "Persona can't be spouse for self";
     }
     if ($persona->getGender() === self::GENDER_UNDEFINED || $spouse->getGender() === self::GENDER_UNDEFINED) {
         $errors[] = 'Both spouses must have the gender. ';
     }
     if ($persona->getGender() === $spouse->getGender()) {
         $errors[] = 'Spouses must be of different genders. ';
     }
     if ($persona->hasDateOfBirth() && $spouse->hasDateOfDeath()) {
         if ($persona->getDateOfBirth() >= $spouse->getDateOfDeath()) {
             $errors[] = "Persona can't born after spouse death. ";
         }
     }
     if ($persona->hasDateOfDeath() && $spouse->hasDateOfBirth()) {
         if ($persona->getDateOfDeath() <= $spouse->getDateOfBirth()) {
             $errors[] = "Persona can't dead before spouse will born. ";
         }
     }
     return $this->getResult($errors);
 }
 /**
  * TODO: use special object PersonaRow (ext.
  * RowGateway?) instead of $rowData,
  * that can be using as prototype for ResultSet in TableGateway.
  *
  *
  * (non-PHPdoc)
  * @see \Phamily\Framework\Repository\PersonaIdentityMapInterface::add($persona, $rowData)
  *
  */
 public function add(PersonaInterface $persona, $rowData, $options = 0)
 {
     $this->items[$persona->getId()] = ['object' => $persona, 'data' => $rowData, 'options' => $options];
 }
 /**
  *
  * (non-PHPdoc)
  * @see \Phamily\Framework\Repository\PersonaRepositoryInterface::delete()
  *
  */
 public function delete(PersonaInterface $persona)
 {
     /*
      * inlink with spouse
      */
     $spouseTableGateway = $this->createTableGateway('spouse_relationship');
     $spouseTableGateway->delete(['husband_id' => $persona->getId()]);
     $spouseTableGateway->delete(['wife_id' => $persona->getId()]);
     /*
      * unlink parent for existing childs
      */
     $table = $this->createTableGateway($this->tableName);
     $table->update(['father_id' => null], ['father_id' => $persona->getId()]);
     $table->update(['mother_id' => null], ['mother_id' => $persona->getId()]);
     /*
      * delete persona row
      */
     $row = $this->getRowGatewayInstance();
     $row->populate($this->extractData($persona), true);
     $row->delete();
 }