public function testAssociateAndUnassociatePerson() { $this->objMultiplePersonHousehold1->AssociatePerson($this->objIndividual); $this->AssertEquals($this->objMultiplePersonHousehold1->CountHouseholdParticipations(), 4, 'AssociatePerson Count incorrect'); $this->AssertEquals($this->objIndividual->GetHouseholdStatus(), Person::HouseholdStatusMemberOfOne, 'AssociatePerson HouseholdStatusMemberOfOne incorrect'); $this->AssertNotNull(HouseholdParticipation::LoadByPersonIdHouseholdId($this->objIndividual->Id, $this->objMultiplePersonHousehold1->Id), 'AssociatePerson failed'); $objOldHead = $this->objMultiplePersonHousehold1->HeadPerson; $this->objMultiplePersonHousehold1->SetAsHeadPerson($this->objIndividual); $this->AssertEquals($this->objIndividual->GetHouseholdStatus(), Person::HouseholdStatusHeadOfFamily, 'AssociatePerson HouseholdStatusHeadOfFamily incorrect'); $this->objMultiplePersonHousehold1->SetAsHeadPerson($objOldHead); $this->objIndividual = Person::Load($this->objIndividual->Id); $this->AssertEquals($this->objIndividual->GetHouseholdStatus(), Person::HouseholdStatusMemberOfOne, 'AssociatePerson HouseholdStatusMemberOfOne incorrect'); $this->objMultiplePersonHousehold1->UnassociatePerson($this->objIndividual); $this->AssertEquals($this->objIndividual->GetHouseholdStatus(), Person::HouseholdStatusNone, 'UnassociatePerson HouseholdStatusNone failed'); }
protected function Form_Create() { $this->objHousehold = Household::Load(QApplication::PathInfo(1)); if ($this->objHousehold) { if (!HouseholdParticipation::LoadByPersonIdHouseholdId($this->objPerson->Id, $this->objHousehold->Id)) { QApplication::Redirect('/individuals/'); } } else { $objHouseholdParticipationArray = HouseholdParticipation::LoadArrayByPersonId($this->objPerson->Id); if ($objHouseholdParticipationArray) { $this->objHousehold = $objHouseholdParticipationArray[0]->Household; } } $this->strPageTitle .= $this->objPerson->Name; // Unset based on Permissions if (!QApplication::$Login->IsPermissionAllowed(PermissionType::AccessStewardship)) { unset($this->strSubNavItemArray['stewardship']); } if (!QApplication::$Login->IsPermissionAllowed(PermissionType::MergeIndividuals)) { unset($this->strSubNavItemArray['merge']); } // Alter Inactive/Active based on whether or not the person has a login if ($this->objPerson->PublicLogin) { $this->strSubNavItemArray['online'][2] = null; } $this->lblHeading = new QLabel($this); $this->lblSubheading = new QLabel($this); $this->lblSubheading->CssClass = 'subhead'; $this->lblSubheading->HtmlEntities = false; $this->lstHouseholdSwitcher = new QListBox($this); $this->lstHouseholdSwitcher->SetCustomStyle('float', 'right'); $this->lstHouseholdSwitcher->SetCustomStyle('margin-top', '8px;'); $this->lstHouseholdSwitcher->Visible = false; $this->lstHouseholdSwitcher->AddAction(new QChangeEvent(), new QAjaxAction('lstHouseholdSwitcher_Change')); $this->pnlHouseholdSelector = new HouseholdSelectorPanel($this); $this->pnlSubnavBar = new ViewIndividualSubNavPanel($this); $this->pnlMainContent = new QPanel($this); $this->pnlMainContent->AutoRenderChildren = true; $this->pnlMainContent->CssClass = 'subnavContent'; $this->SetUrlHashProcessor('Form_ProcessHash'); $this->lblHeading_Refresh(); $this->lstHouseholdSwitcher_Refresh(); }
protected function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->objPersonToAdd = $this->pnlPerson->Person; if (HouseholdParticipation::LoadByPersonIdHouseholdId($this->objPersonToAdd->Id, $this->objHousehold->Id)) { $this->dlgMessage->RemoveAllButtons(); $this->dlgMessage->MessageHtml = sprintf('<strong>%s</strong> is already part of this household.', QApplication::HtmlEntities($this->objPersonToAdd->Name)); $this->dlgMessage->ShowDialogBox(); return; } $this->dlgMessage->RemoveAllButtons(); switch ($this->objPersonToAdd->GetHouseholdStatus()) { case Person::HouseholdStatusNone: $this->AddToHousehold(); return; case Person::HouseholdStatusHeadOfOne: $this->MergeHouseholds(); return; case Person::HouseholdStatusHeadOfFamily: $this->dlgMessage->MessageHtml = sprintf('<strong>%s</strong> is Head of another household and thus cannot be added to this one.', QApplication::HtmlEntities($this->objPersonToAdd->Name)); break; case Person::HouseholdStatusMemberOfOne: $objParticipationArray = $this->objPersonToAdd->GetHouseholdParticipationArray(); $objHousehold = $objParticipationArray[0]->Household; $this->dlgMessage->MessageHtml = sprintf('<strong>%s</strong> is currently part of the <strong>%s</strong>.<br/><br/>Is %s <strong>moving</strong> to this household, or is %s <strong>adding</strong> this as an <em>additional</em> household?', QApplication::HtmlEntities($this->objPersonToAdd->Name), QApplication::HtmlEntities($objHousehold->Name), $this->objPersonToAdd->PronounSubject, $this->objPersonToAdd->PronounSubject); $this->dlgMessage->AddButton('Moving', MessageDialog::ButtonPrimary, 'MoveHouseholds'); $this->dlgMessage->AddButton('Adding', MessageDialog::ButtonPrimary, 'AddToHousehold'); $this->dlgMessage->AddButton('Cancel', MessageDialog::ButtonSecondary, 'HideDialogBox', $this->dlgMessage); break; case Person::HouseholdStatusMemberOfMultiple: $this->dlgMessage->MessageHtml = sprintf('<strong>%s</strong> is currently part of <strong>multiple households</strong>.<br/><br/>Are you sure you want to add %s to this household?', QApplication::HtmlEntities($this->objPersonToAdd->Name), $this->objPersonToAdd->PronounIndirectObject); $this->dlgMessage->AddButton('Yes', MessageDialog::ButtonPrimary, 'AddToHousehold'); $this->dlgMessage->AddButton('No', MessageDialog::ButtonSecondary, 'HideDialogBox', $this->dlgMessage); break; case Person::HouseholdStatusError: default: $this->dlgMessage->MessageHtml = sprintf('An unknown data error occurred while trying to add <strong>%s</strong> to this "%s" household. Please contact a ChMS Administrator to report the issue.', QApplication::HtmlEntities($this->objPersonToAdd->Name), QApplication::HtmlEntities($this->objHousehold->Name)); break; } $this->dlgMessage->ShowDialogBox(); }
/** * Attempts to remove the person from the household. This will throw an exception if: * - This person is not currently part of the household * - This person is the only person in the household * - This person is the head of the household * @param Person $objPerson * @param boolean $blnClearAssociatedPhoneAndAddress * @return void */ public function UnassociatePerson(Person $objPerson, $blnClearAssociatedPhoneAndAddress = true) { $objParticipation = HouseholdParticipation::LoadByPersonIdHouseholdId($objPerson->Id, $this->Id); if (!$objParticipation) { throw new QCallerException('Person does not exist in the household'); } if ($this->CountHouseholdParticipations() == 1) { throw new QCallerException('Person is the only member of this household and thus cannot be removed'); } if ($this->HeadPersonId == $objPerson->Id) { throw new QCallerException('Person is the Head of this household and thus cannot be removed'); } self::GetDatabase()->TransactionBegin(); try { foreach ($this->GetAddressArray() as $objAddress) { $objAddress->CopyForPerson($objPerson, AddressType::Home, false); } $objParticipation->Delete(); $this->RefreshMembers(); } catch (Exception $objExc) { self::GetDatabase()->TransactionRollBack(); throw $objExc; } self::GetDatabase()->TransactionCommit(); // Update linked phone and address stuff if ($blnClearAssociatedPhoneAndAddress) { $intAddressIdArray = array(); $intPhoneIdArray = array(); foreach ($this->GetAddressArray() as $objAddress) { $intAddressIdArray[$objAddress->Id] = true; foreach ($objAddress->GetPhoneArray() as $objPhone) { $intPhoneIdArray[$objPhone->Id] = true; } } if (array_key_exists($objPerson->MailingAddressId, $intAddressIdArray)) { $objPerson->MailingAddress = null; } if (array_key_exists($objPerson->StewardshipAddressId, $intAddressIdArray)) { $objPerson->StewardshipAddress = null; } if (array_key_exists($objPerson->PrimaryPhoneId, $intPhoneIdArray)) { $objPerson->PrimaryPhone = null; } } $objPerson->RefreshPrimaryContactInfo(); }
/** * Merges two records together. * @param Person $objPersonMergeWith * @param boolean $blnUseThisDetails boolean on whether to use this person's Person object details, or if false, use the PersonMergeWith's */ public function MergeWith(Person $objPersonMergeWith, $blnUseThisDetails) { QLog::Log(sprintf('Merging %s (ID %s) with %s (ID %s) - %s', $this->Name, $this->Id, $objPersonMergeWith->Name, $objPersonMergeWith->Id, $blnUseThisDetails ? 'left' : 'right')); Person::GetDatabase()->TransactionBegin(); // Household Participation Records if ($this->HouseholdAsHead && $objPersonMergeWith->HouseholdAsHead) { $this->HouseholdAsHead->MergeHousehold($objPersonMergeWith->HouseholdAsHead, $this); } else { if ($this->HouseholdAsHead) { // Go through each MergeWith HouseholdParticipation -- Throw if it's another household, Delete if it's this Household-as-Head foreach ($objPersonMergeWith->GetHouseholdParticipationArray() as $objHouseholdParticipation) { if ($objHouseholdParticipation->HouseholdId != $this->HouseholdAsHead->Id) { throw new QCallerException('Cannot merge this head of household with a person record that exists in other households'); } else { $objHouseholdParticipation->Delete(); } } } else { if ($objHousehold = $objPersonMergeWith->HouseholdAsHead) { // Go through each of this's HouseholdParticipation -- Throw if it's another household, Delete if it's MergeWith's Household-as-Head foreach ($this->GetHouseholdParticipationArray() as $objHouseholdParticipation) { if ($objHouseholdParticipation->HouseholdId != $objPersonMergeWith->HouseholdAsHead->Id) { throw new QCallerException('Cannot merge MergeWith head of household with this person record which exists in other households'); } else { $objHouseholdParticipation->Delete(); } } $objHousehold->HeadPerson = $this; $objHousehold->Save(); $objParticipation = HouseholdParticipation::LoadByPersonIdHouseholdId($objPersonMergeWith->Id, $objHousehold->Id); $objParticipation->PersonId = $this->Id; $objParticipation->Save(); } else { // Otherwise: members of multiple households! but head of none foreach ($objPersonMergeWith->GetHouseholdParticipationArray() as $objHouseholdParticipation) { if (HouseholdParticipation::LoadByPersonIdHouseholdId($this->Id, $objHouseholdParticipation->HouseholdId)) { $objHouseholdParticipation->Delete(); } else { $objHouseholdParticipation->PersonId = $this->Id; $objHouseholdParticipation->Save(); } } } } } if (!$blnUseThisDetails) { $this->FirstName = $objPersonMergeWith->FirstName; $this->MiddleName = $objPersonMergeWith->MiddleName; $this->LastName = $objPersonMergeWith->LastName; $this->MailingLabel = $objPersonMergeWith->MailingLabel; $this->PriorLastNames = $objPersonMergeWith->PriorLastNames; $this->Nickname = $objPersonMergeWith->Nickname; $this->Title = $objPersonMergeWith->Title; $this->Suffix = $objPersonMergeWith->Suffix; $this->Gender = $objPersonMergeWith->Gender; $this->DateOfBirth = $objPersonMergeWith->DateOfBirth; $this->DobYearApproximateFlag = $objPersonMergeWith->DobYearApproximateFlag; $this->DobGuessedFlag = $objPersonMergeWith->DobGuessedFlag; $this->Age = $objPersonMergeWith->Age; $this->DeceasedFlag = $objPersonMergeWith->DeceasedFlag; $this->DateDeceased = $objPersonMergeWith->DateDeceased; } // Attributes foreach ($objPersonMergeWith->GetAttributeValueArray() as $objAttributeValue) { // Check for double-defined attributes if ($objDoubleDefinedAttribute = AttributeValue::LoadByAttributeIdPersonId($objAttributeValue->AttributeId, $this->Id)) { if ($blnUseThisDetails) { $objAttributeValue->Delete(); } else { $objDoubleDefinedAttribute->Delete(); $objAttributeValue->PersonId = $this->Id; $objAttributeValue->Save(); } // Nothing double-defined -- just move it over! } else { $objAttributeValue->PersonId = $this->Id; $objAttributeValue->Save(); } } // Comments foreach ($objPersonMergeWith->GetCommentArray() as $objComment) { $objComment->PersonId = $this->Id; $objComment->Save(); } // Memberships foreach ($objPersonMergeWith->GetMembershipArray() as $objMembership) { $objMembership->PersonId = $this->Id; $objMembership->Save(); } // Communication Lists foreach ($objPersonMergeWith->GetCommunicationListArray() as $objCommList) { $objPersonMergeWith->UnassociateCommunicationList($objCommList); if (!$this->IsCommunicationListAssociated($objCommList)) { $this->AssociateCommunicationList($objCommList); } } // Head Shots foreach ($objPersonMergeWith->GetHeadShotArray() as $objHeadShot) { $objHeadShot->PersonId = $this->Id; $objHeadShot->Save(); } // Group Participation foreach ($objPersonMergeWith->GetGroupParticipationArray() as $objGroupParticipation) { $objGroupParticipation->PersonId = $this->Id; $objGroupParticipation->Save(); } // NameItemAssn $objPersonMergeWith->UnassociateAllNameItems(); // Marrriage Records foreach ($objPersonMergeWith->GetMarriageArray() as $objMarriage) { $this->CreateMarriageWith($objMarriage->MarriedToPerson, $objMarriage->DateStart, $objMarriage->DateEnd, $objMarriage->MarriageStatusTypeId); $objMarriage->DeleteThisAndLinked(); } foreach ($objPersonMergeWith->GetMarriageAsMarriedToArray() as $objMarriage) { $this->CreateMarriageWith($objMarriage->Person, $objMarriage->DateStart, $objMarriage->DateEnd, $objMarriage->MarriageStatusTypeId); $objMarriage->DeleteThisAndLinked(); } // Family Relationships foreach ($objPersonMergeWith->GetRelationshipArray() as $objRelationship) { if (!Relationship::LoadByPersonIdRelatedToPersonId($this->Id, $objRelationship->RelatedToPersonId)) { $this->AddRelationship($objRelationship->RelatedToPerson, $objRelationship->RelationshipTypeId); } $objRelationship->DeleteThisAndLinked(); } foreach ($objPersonMergeWith->GetRelationshipAsRelatedToArray() as $objRelationship) { if (!Relationship::LoadByPersonIdRelatedToPersonId($this->Id, $objRelationship->PersonId)) { $this->AddRelationship($objRelationship->Person, $objRelationship->RelationshipTypeId); } $objRelationship->DeleteThisAndLinked(); } // Phones foreach ($objPersonMergeWith->GetPhoneArray() as $objContact) { $objContact->PersonId = $this->Id; $objContact->Save(); } // Addresses foreach ($objPersonMergeWith->GetAddressArray() as $objContact) { $objContact->PersonId = $this->Id; $objContact->Save(); } // Email foreach ($objPersonMergeWith->GetEmailArray() as $objContact) { $objContact->PersonId = $this->Id; $objContact->Save(); } // Other Contact Info foreach ($objPersonMergeWith->GetOtherContactInfoArray() as $objContact) { $objContact->PersonId = $this->Id; $objContact->Save(); } // Checking Account Lookups foreach ($objPersonMergeWith->GetCheckingAccountLookupArray() as $objCheckingAccount) { $objPersonMergeWith->UnassociateCheckingAccountLookup($objCheckingAccount); if (!$this->IsCheckingAccountLookupAssociated($objCheckingAccount)) { $this->AssociateCheckingAccountLookup($objCheckingAccount); } } // Stewardship Contributions foreach ($objPersonMergeWith->GetStewardshipContributionArray() as $objStewardship) { $objStewardship->PersonId = $this->Id; $objStewardship->Save(); } // Stewardship Pledges foreach ($objPersonMergeWith->GetStewardshipPledgeArray() as $objPledge) { // Check for double-defined pledge if ($objDoubleDefinedPledge = StewardshipPledge::LoadByPersonIdStewardshipFundId($this->Id, $objPledge->StewardshipFundId)) { if ($blnUseThisDetails) { $objPledge->Delete(); } else { $objDoubleDefinedPledge->Delete(); $objPledge->PersonId = $this->Id; $objPledge->Save(); } // Nope, just move it over like normal } else { $objPledge->PersonId = $this->Id; $objPledge->Save(); } } // Online Donations foreach ($objPersonMergeWith->GetOnlineDonationArray() as $objOnlineDonation) { $objOnlineDonation->PersonId = $this->Id; $objOnlineDonation->Save(); } // Public Login if ($objPublicLogin = $objPersonMergeWith->PublicLogin) { $objPublicLogin->PersonId = $this->Id; $objPublicLogin->Save(); } // Events and Classes foreach ($objPersonMergeWith->GetSignupEntryArray() as $objSignupEntry) { $objSignupEntry->PersonId = $this->Id; $objSignupEntry->Save(); } foreach ($objPersonMergeWith->GetSignupEntryAsSignupByArray() as $objSignupEntry) { $objSignupEntry->SignupByPersonId = $this->Id; $objSignupEntry->Save(); } foreach ($objPersonMergeWith->GetClassRegistrationArray() as $objClassRegistration) { $objClassRegistration->PersonId = $this->Id; $objClassRegistration->Save(); } // Stewardship Post Line Items foreach ($objPersonMergeWith->GetStewardshipPostLineItemArray() as $objStewardship) { $objStewardship->PersonId = $this->Id; $objStewardship->Save(); } // Email Message Route foreach ($objPersonMergeWith->GetEmailMessageRouteArray() as $objEmailMessageRoute) { $objEmailMessageRoute->PersonId = $this->Id; $objEmailMessageRoute->Save(); } // Search Query foreach ($objPersonMergeWith->GetSearchQueryArray() as $objSearchQuery) { $objSearchQuery->PersonId = $this->Id; $objSearchQuery->Save(); } // Final Refresh/Cleanup $this->RefreshAge(false); $this->RefreshMaritalStatusTypeId(false); $this->RefreshMembershipStatusTypeId(false); $this->RefreshPrimaryContactInfo(false); $this->Save(); $this->RefreshNameItemAssociations(); $objPersonMergeWith->Delete(); Person::GetDatabase()->TransactionCommit(); }
QApplication::Authenticate(null, array(PermissionType::AccessStewardship)); // Setup Zend Framework load set_include_path(get_include_path() . ':' . __INCLUDES__); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Pdf'); // Expected PathInfo to be PersonId/HouseholdId/Year // Note that HouseholdId is OPTIONAL -- if HouseholdId, then it is a combined statement for the entire household // Otherwise, if no HouseholdId (e.g. "0"), then it is just a individual statement $objPerson = Person::Load(QApplication::PathInfo(0)); $objObject = $objPerson; if (QApplication::PathInfo(1)) { $objHousehold = Household::Load(QApplication::PathInfo(1)); if (!$objHousehold) { QApplication::Redirect('/main/'); } if (!HouseholdParticipation::LoadByPersonIdHouseholdId($objPerson->Id, $objHousehold->Id)) { QApplication::Redirect('/main/'); } $objObject = $objHousehold; } if (!(QApplication::PathInfo(2) >= 1950 && QApplication::PathInfo(2) <= 2500)) { QApplication::Redirect('/main/'); } // Create the PDF Object $objPdf = new Zend_Pdf(); StewardshipContribution::GenerateReceiptInPdf($objPdf, $objObject, QApplication::PathInfo(2), true); // Get PDF document as a string $strData = $objPdf->render(); // Disable strict no-cache for IE due to IE issues with downloading no-cache items if (QApplication::IsBrowser(QBrowserType::InternetExplorer)) { header("Pragma:");
/** * This will set this phone object as the "primary" phone number for (if associated to an address) the address * or (if associated to a person) the person. * * Alternatively, if the phone is associated with the address (e.g. a home phone), you can explicitly * pass in a Person in that house to set as "primary" for that person. * * This will automatically UNSET as primary any current-primary phone (if applicable) * @return void */ public function SetAsPrimary(Person $objPerson = null, Address $objAddress = null) { if ($objPerson) { if ($this->PersonId != $objPerson->Id && (!$this->Address || !$this->Address->Household || !HouseholdParticipation::LoadByPersonIdHouseholdId($objPerson->Id, $this->Address->HouseholdId))) { throw new QCallerException('Cannot set as primary phone for person not in the household for this address'); } $objPerson->PrimaryPhone = $this; $objPerson->Save(); $objPerson->RefreshPrimaryContactInfo(); } else { if ($objAddress) { if ($objAddress->Id != $this->intAddressId) { throw new QCallerException('Cannot set as primary phone for home address that does not own this phone object'); } $objAddress->PrimaryPhone = $this; $objAddress->Save(); } else { if ($this->Address) { $this->Address->PrimaryPhone = $this; $this->Address->Save(); } else { $this->Person->PrimaryPhone = $this; $this->Person->Save(); $this->Person->RefreshPrimaryContactInfo(); } } } }