/** * Main DataGen Runner * @return void */ public static function Run() { // Run "Fake Data" SQL Script $strFakeDataSql = file_get_contents(__DOCROOT__ . '/../database/fake_data.sql'); foreach (explode("\n", $strFakeDataSql) as $strSql) { $strSql = trim($strSql); if (strlen($strSql) && substr($strSql, 0, 1) != '#') { Person::GetDatabase()->NonQuery($strSql); } } self::$SystemStartDate = new QDateTime('1990-01-01'); self::$LifeStartDate = new QDateTime('1930-01-01'); self::$OldestChildBirthDate = QDateTime::Now(false); self::$OldestChildBirthDate->Year -= 18; // Get Cached Data self::$CommentCategoryArray = CommentCategory::LoadAll(); // Erase Directories exec('rm -r -f ' . __DOCROOT__ . '/../file_assets/head_shots'); exec('rm -r -f ' . __DOCROOT__ . '/../file_assets/contribution_images'); // Generate Stuff ChmsDataGen::GenerateMinistries(); ChmsDataGen::GenerateUsers(); ChmsDataGen::GenerateHouseholds(); ChmsDataGen::GenerateStewardship(); self::$MaxPersonId = Person::CountAll(); ChmsDataGen::GenerateCommunicationLists(); ChmsDataGen::GenerateGroups(); }
/** * 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(); }
protected function dtgCustom_Bind() { //Set up our normal query $sql = 'SELECT p.first_name as "FirstName", p.last_name as "LastName", count(a.id) as "AddressCount" FROM person as p LEFT JOIN address as a on a.person_id = p.id GROUP BY p.id'; //apply any filters the user has set foreach ($this->dtgCustom->FilterInfo as $filter) { if ($filter['column'] == 'AddressCount') { $sql .= ' HAVING count(a.id) = ' . $filter['value']; } } //and run the query, using it as the datasource for the grid $objDatabase = Person::GetDatabase(); $objDbResult = $objDatabase->Query($sql); $array = array(); while ($mixRow = $objDbResult->FetchArray()) { $array[] = $mixRow; } $this->dtgCustom->DataSource = $array; }
/** * Unassociates all NameItems * @return void */ public function UnassociateAllNameItems() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllNameItemArray on this unsaved Person.'); } // Get the Database Object for this Class $objDatabase = Person::GetDatabase(); // Journaling (if applicable) if ($objDatabase->JournalingDatabase) { $objResult = $objDatabase->Query('SELECT `name_item_id` AS associated_id FROM `person_nameitem_assn` WHERE `person_id` = ' . $objDatabase->SqlVariable($this->intId)); while ($objRow = $objResult->GetNextRow()) { $this->JournalNameItemAssociation($objRow->GetColumn('associated_id'), 'DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `person_nameitem_assn` WHERE `person_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
public function testTransactionWithCacheDeleteRollBack2() { Person::GetDatabase()->Caching = true; // establish a cache object we can work with $objCacheProvider = QApplication::$objCacheProvider; QApplication::$objCacheProvider = new QCacheProviderLocalMemoryTest(array()); // cache is empty now // create an object in the database $objPerson1z = new Person(); $objPerson1z->FirstName = "test"; $objPerson1z->LastName = "test"; $objPerson1z->Save(); Person::Load($objPerson1z->Id); // the person object is placed in a cache $this->assertEqual(count(QApplication::$objCacheProvider->arrLocalCache), 1, "Object is placed in a cache."); try { Person::GetDatabase()->TransactionBegin(); // cache is substituted $objPerson1 = Person::Load($objPerson1z->Id); // person object is placed in the temporary cache $objPerson1->Delete(); // person object is removed from the temporary cache throw new Exception("DATABASE ERROR!"); // imitate the database error in the next Save call Person::GetDatabase()->TransactionCommit(); } catch (Exception $ex) { Person::GetDatabase()->TransactionRollBack(); // actual cache leaved unchanged } $this->assertEqual(count(QApplication::$objCacheProvider->arrLocalCache), 1, "Object is NOT removed from a cache after delete because of the transaction roll back."); // restore the actual cache object QApplication::$objCacheProvider = $objCacheProvider; // clean up $objPerson1 = Person::Load($objPerson1z->Id); // person object is placed in the temporary cache $objPerson1->Delete(); }
$objPerson->DisplayRealNameFlag = $objRow['display_real_name_flag']; $objPerson->DisplayEmailFlag = $objRow['display_email_flag']; $objPerson->OptInFlag = $objRow['opt_in_flag']; $objPerson->DonatedFlag = $objRow['donated_flag']; $objPerson->Location = $objRow['location']; $objPerson->Url = $objRow['url']; $objPerson->RegistrationDate = new QDateTime($objRow['registration_date']); if ($objRow['country_id']) { $objCountryResult = $objDb->query('SELECT * FROM country WHERE id=' . $objRow['country_id']); $objCountryRow = $objCountryResult->fetch_array(); $objPerson->Country = Country::LoadByCode($objCountryRow['code']); } $objPerson->RefreshDisplayName(); $objPerson->Save(); if ($objPerson->Id != $objRow['id']) { Person::GetDatabase()->NonQuery('UPDATE person SET id=' . $objRow['id'] . ' WHERE id=' . $objPerson->Id); } } $intNewTopicLinkIdArray[3591] = 7; $intNewTopicLinkIdArray[3578] = 7; $intNewTopicLinkIdArray[3547] = 7; $intNewTopicLinkIdArray[3455] = 7; $intNewTopicLinkIdArray[3242] = 7; $intNewTopicLinkIdArray[3244] = 7; $objResult = $objDb->query('SELECT * FROM topic ORDER BY id'); while (QDataGen::DisplayWhileTask('Migrating Topics', $objResult->num_rows)) { $objRow = $objResult->fetch_array(); $objTopic = new Topic(); if (array_key_exists(intval($objRow['id']), $intNewTopicLinkIdArray)) { $objTopic->TopicLinkId = $intNewTopicLinkIdArray[intval($objRow['id'])]; } else {
/** * Truncate person table * @return void */ public static function Truncate() { // Get the Database Object for this Class $objDatabase = Person::GetDatabase(); // Perform the Query $objDatabase->NonQuery(' TRUNCATE `person`'); }
/** * Unassociates all TopicsAsRead * @return void */ public function UnassociateAllTopicsAsRead() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllTopicAsReadArray on this unsaved Person.'); } // Get the Database Object for this Class $objDatabase = Person::GetDatabase(); // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `read_topic_person_assn` WHERE `person_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
/** * Given data points supplied this will attempt to reconcile this PublicLogin record to an actual person... or if not possible, * it will create a new person record. * * There are several stesp to this process. * First, do a Search of All People for the given Email * - if 1 and only 1 person was found: * + Check the personal details of that persons record * - If matched against First/Last or Nickname/Last, setup the match * - If matched against DOB and/or Gender and/or Mobile, setup the match and update the name * - If not matched, create as new * - if no people were found * + in all the DB, do a search to find matches against First/Last or Nickname/Last AND any address * - if exactly one is found, setup the match * - if non were found, create as new * - if multiple were found, find the first one that also match DOB and/or Gender and/or Mobile (or if none just find the first one) and setup the match * - if multiple people were found * + WITHIN the set of found people, do a search to find matches against First/Last or Nickname/Last AND any address * - if exactly one is found, setup the match * - if non were found, create as new * - if multiple were found, find the first one that also match DOB and/or Gender and/or Mobile (or if none just find the first one) and setup the match * * It will then check and see if the Person found (if any) already has a login object... if so, it will return that found Person record and do nothing further. * * Otherwise, it will then update all data accordingly (including creating a new Person record, if needed) and return the Person that was created. * * @param string $strPassword * @param string $strQuestion * @param string $strAnswer * @param string $strHomePhone * @param string $strMobilePhone * @param Address $objHomeAddress * @param Address $objMailingAddress optional * @param QDateTime $dttDateOfBirth optional * @param string $strGenderFlag optional * @return Person the person that was matched */ public function Reconcile($strPassword, $strQuestion, $strAnswer, $strHomePhone, $strMobilePhone, Address $objHomeAddress, Address $objMailingAddress = null, QDateTime $dttDateOfBirth = null, $strGenderFlag = null) { // Try and Find a Person based on Email $objPersonArray = array(); foreach (Email::LoadArrayByAddress($this->strEmailAddress) as $objEmail) { $objPersonArray[] = $objEmail->Person; } // Let's try and find a single Person object to reconcile for // 1 and only 1 person was found with the email if (count($objPersonArray) == 1) { if ($objPersonArray[0]->IsNameMatch($this->FirstName, $this->LastName)) { $objPerson = $objPersonArray[0]; } else { if ($objPersonArray[0]->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone) > 0) { $objPerson = $objPersonArray[0]; } else { $objPerson = null; } } // MORE than one person was found with the email } else { if (count($objPersonArray)) { // Go through each of them and find a name-match and address-match $objMatchedPersonArray = array(); foreach ($objPersonArray as $objPerson) { if ($objPerson->IsNameAndAddressMatch($this->FirstName, $this->LastName, $objHomeAddress, $objMailingAddress)) { $objMatchedPersonArray[] = $objPerson; } } if (count($objMatchedPersonArray) == 1) { $objPerson = $objMatchedPersonArray[0]; } else { if (!count($objMatchedPersonArray)) { $objPerson = null; } else { $objPerson = $objMatchedPersonArray[0]; $intCurrentScore = 0; foreach ($objMatchedPersonArray as $objMatchedPerson) { $intScore = $objMatchedPerson->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone); if ($intScore > $intCurrentScore) { $intCurrentScore = $intScore; $objPerson = $objMatchedPerson; } } } } // NO ONE was found with the email } else { // First pull the ones with Name Matched $objPersonArray = Person::LoadArrayByNameMatch($this->FirstName, $this->LastName); // Go through each of those and find address-match records $objMatchedPersonArray = array(); foreach ($objPersonArray as $objPerson) { if ($objPerson->IsNameAndAddressMatch($this->FirstName, $this->LastName, $objHomeAddress, $objMailingAddress)) { $objMatchedPersonArray[] = $objPerson; } } if (count($objMatchedPersonArray) == 1) { $objPerson = $objMatchedPersonArray[0]; } else { if (!count($objMatchedPersonArray)) { $objPerson = null; } else { $objPerson = $objMatchedPersonArray[0]; $intCurrentScore = 0; foreach ($objMatchedPersonArray as $objMatchedPerson) { $intScore = $objMatchedPerson->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone); if ($intScore > $intCurrentScore) { $intCurrentScore = $intScore; $objPerson = $objMatchedPerson; } } } } } } // If we have a person, make sure it's not already linked if ($objPerson) { if ($objPerson->PublicLogin) { return $objPerson; } } // We now have either a unlinked Person record or no person record // Let's make all the DB updates we need to Person::GetDatabase()->TransactionBegin(); // Do we have a single Person object? // If not, let's create it if (!$objPerson) { $blnMaleFlag = null; if ($strGenderFlag = trim(strtoupper($strGenderFlag))) { $blnMaleFlag = $strGenderFlag == 'M'; } $intPhoneTypeId = $strMobilePhone ? PhoneType::Mobile : null; $objPerson = Person::CreatePerson($this->FirstName, null, $this->LastName, $blnMaleFlag, $this->EmailAddress, $strMobilePhone, $intPhoneTypeId); $objPerson->DateOfBirth = $dttDateOfBirth; if ($objPerson->DateOfBirth) { $objPerson->DobGuessedFlag = false; $objPerson->DobYearApproximateFlag = false; } $objPerson->PublicCreationFlag = true; $objPerson->Save(); } ////////////////////////////////// // Let's update the information ////////////////////////////////// // Email Address $objPerson->ChangePrimaryEmailTo($this->EmailAddress, false); // Gender and DOB if ($strGenderFlag = trim(strtoupper($strGenderFlag))) { $objPerson->Gender = $strGenderFlag; } if ($dttDateOfBirth) { $objPerson->DateOfBirth = $dttDateOfBirth; $objPerson->DobGuessedFlag = false; $objPerson->DobYearApproximateFlag = false; } // Mobile Phone if ($strMobilePhone) { $blnFound = false; foreach ($objPerson->GetAllAssociatedPhoneArray() as $objPhone) { if ($objPhone->Number == $strMobilePhone) { $objPhone->PhoneTypeId = PhoneType::Mobile; $objPhone->Save(); $blnFound = true; } } if (!$blnFound) { $objPhone = new Phone(); $objPhone->Number = $strMobilePhone; $objPhone->PhoneTypeId = PhoneType::Mobile; $objPhone->Save(); $objPerson->PrimaryPhone = $objPhone; } } // Mailing Address if ($objMailingAddress) { $blnFound = false; foreach ($objPerson->GetAllAssociatedAddressArray() as $objAddress) { if ($objAddress->IsEqualTo($objMailingAddress)) { $blnFound = true; $objAddress->CurrentFlag = true; $objAddress->AddressTypeId = AddressType::Other; $objAddress->Save(); $objPerson->MailingAddress = $objAddress; $objPerson->StewardshipAddress = $objAddress; } } if (!$blnFound) { $objMailingAddress->Person = $objPerson; $objMailingAddress->CurrentFlag = true; $objMailingAddress->AddressTypeId = AddressType::Other; $objMailingAddress->Save(); $objPerson->MailingAddress = $objMailingAddress; $objPerson->StewardshipAddress = $objMailingAddress; } } // Home Address and Phone $objHouseholdParticipationArray = $objPerson->GetHouseholdParticipationArray(); if (count($objHouseholdParticipationArray) == 1) { $objHousehold = $objHouseholdParticipationArray[0]->Household; $objAddress = $objHousehold->GetCurrentAddress(); if ($objAddress && $objAddress->IsEqualTo($objHomeAddress)) { $objHomeAddress = $objAddress; } else { $objHomeAddress->AddressTypeId = AddressType::Home; $objHomeAddress->Household = $objHousehold; $objHomeAddress->CurrentFlag = true; $objHomeAddress->Save(); if ($objAddress) { $objAddress->CurrentFlag = false; $objAddress->Save(); } } if ($strHomePhone) { $blnFound = false; foreach ($objHomeAddress->GetPhoneArray() as $objPhone) { if ($objPhone->Number == $strHomePhone) { $blnFound = true; $objPhone->SetAsPrimary(null, $objHomeAddress); } } if (!$blnFound) { $objPhone = new Phone(); $objPhone->PhoneTypeId = PhoneType::Home; $objPhone->Number = $strHomePhone; $objPhone->Address = $objHomeAddress; $objPhone->Save(); $objPhone->SetAsPrimary(null, $objHomeAddress); } } } else { if (count($objHouseholdParticipationArray) == 0) { $objHousehold = Household::CreateHousehold($objPerson); $objHomeAddress->AddressTypeId = AddressType::Home; $objHomeAddress->Household = $objHousehold; $objHomeAddress->CurrentFlag = true; $objHomeAddress->Save(); $objHousehold->SetAsCurrentAddress($objHomeAddress); if ($strHomePhone) { $objPhone = new Phone(); $objPhone->PhoneTypeId = PhoneType::Home; $objPhone->Number = $strHomePhone; $objPhone->Address = $objHomeAddress; $objPhone->Save(); $objPhone->SetAsPrimary(null, $objHomeAddress); } } } // Wire to PublicLogin $this->PublicLogin->Person = $objPerson; $this->PublicLogin->SetPassword($strPassword); $this->PublicLogin->LostPasswordQuestion = trim($strQuestion); $this->PublicLogin->LostPasswordAnswer = trim(strtolower($strAnswer)); $this->PublicLogin->DateLastLogin = QDateTime::Now(); $this->PublicLogin->Save(); // Save the person and delete the provision $objPerson->RefreshPrimaryContactInfo(); $objPerson->RefreshAge(false); $objPerson->RefreshNameItemAssociations(true); $this->Delete(); // Commit to DB Person::GetDatabase()->TransactionCommit(); // Return the now-linked person! return $objPerson; }