Skip to content

Commit

Permalink
Moved saluation utlity to ORM (ChurchCRM#2115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnan0703 authored and DawoudIO committed Mar 15, 2017
1 parent df6c391 commit 9c8cda3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/ChurchCRM/model/ChurchCRM/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,48 @@ private function createTimeLineNote($new)

$note->save();
}

/**
* Figure out how to address a family for correspondence.
*
* Put the name if there is only one individual in the family.
* Put two first names and the last name when there are exactly two people in the family
* (e.g. "Nathaniel and Jeanette Brooks").
* Put two whole names where there are exactly two people with different names
* (e.g. "Doug Philbrook and Karen Andrews")
* When there are more than two people in the family I don't have any way to know
* which people are children, so I would have to just use the family name (e.g. "Grossman Family").
*
* @return string
*/
public function getSaluation()
{
$childRoleId = SystemConfig::getValue("sDirRoleChild");
$people = $this->getPeople();
$notChildren = null;
foreach ($people as $person) {
if ($person->getFmrId() != $childRoleId) {
$notChildren[] = $person;
}
}

$notChildrenCount = count($notChildren);
if ($notChildrenCount === 1) {
return $notChildren[0]->getFullName();
}

if ($notChildrenCount === 2) {
if ($notChildren[0]->getLastName() == $notChildren[1]->getLastName()) {
return $notChildren[0]->getFirstName() .' & '. $notChildren[1]->getFirstName() .' '. $notChildren[0]->getLastName();
}
return $notChildren[0]->getFullName() .' & '. $notChildren[1]->getFullName();
}

return $this->getName() . ' Family';
}

private function getPhoto()
{

$photo = new Photo("Family", $this->getId());
return $photo;
}
Expand Down

0 comments on commit 9c8cda3

Please sign in to comment.