/** * Associates a Person into this Household, and an optional role can be specified. If no role is specified, * then the role is calculated. * * If this person is Head of another household, this will throw an exception * If a record already exists, no new record will be created. If a Role is specified, it will use it. Otherwise, * it will update the role using RefreshRole() calculation. * * @param Person $objPerson * @param string $strRole * @return void */ public function AssociatePerson(Person $objPerson, $strRole = null) { if ($objPerson->HouseholdAsHead && $objPerson->HouseholdAsHead->Id != $this->Id) { throw new QCallerException('Cannot associate a person who is already head of another household'); } // Create if doesn't exist $objHouseholdParticipation = HouseholdParticipation::LoadByPersonIdHouseholdId($objPerson->Id, $this->Id); if (!$objHouseholdParticipation) { $objHouseholdParticipation = new HouseholdParticipation(); $objHouseholdParticipation->Person = $objPerson; $objHouseholdParticipation->Household = $this; } if ($strRole) { $objHouseholdParticipation->RoleOverride = $strRole; } else { $objHouseholdParticipation->RefreshRole(false); } $objHouseholdParticipation->Save(); $this->RefreshMembers(); $objPerson->RefreshPrimaryContactInfo(); }