diff --git a/src/ChurchCRM/model/ChurchCRM/Family.php b/src/ChurchCRM/model/ChurchCRM/Family.php index 38ca262291..782f5bb4f7 100644 --- a/src/ChurchCRM/model/ChurchCRM/Family.php +++ b/src/ChurchCRM/model/ChurchCRM/Family.php @@ -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; }