Beispiel #1
0
 protected static function GenerateAddressesAndPhonesForPerson(Person $objPerson)
 {
     $intAddressCount = rand(0, 5);
     for ($i = 0; $i < $intAddressCount; $i++) {
         $objAddress = new Address();
         $objAddress->AddressTypeId = QDataGen::GenerateFromArray(array_keys(AddressType::$NameArray));
         $objAddress->Person = $objPerson;
         $objAddress->Address1 = QDataGen::GenerateStreetAddress();
         if (rand(0, 1)) {
             $objAddress->Address2 = QDataGen::GenerateAddressLine2();
         }
         $objAddress->City = QDataGen::GenerateCity();
         $objAddress->State = QDataGen::GenerateUsState();
         $objAddress->ZipCode = rand(10000, 99999);
         $objAddress->Country = 'US';
         $objAddress->InvalidFlag = false;
         $objAddress->VerificationCheckedFlag = true;
         switch ($objAddress->AddressTypeId) {
             case AddressType::Temporary:
                 $objAddress->CurrentFlag = true;
                 $dttNextYear = QDateTime::Now();
                 $dttNextYear->Year++;
                 $objAddress->DateUntilWhen = QDataGen::GenerateDateTime(QDateTime::Now(), $dttNextYear);
                 break;
             default:
                 $objAddress->CurrentFlag = rand(0, 1);
                 break;
         }
         $objAddress->Save();
     }
     $intPhoneCount = rand(0, 5);
     $objPhoneArray = array();
     for ($i = 0; $i < $intPhoneCount; $i++) {
         $objPhone = new Phone();
         $objPhone->PhoneTypeId = QDataGen::GenerateFromArray(array_keys(PhoneType::$NameArray));
         while ($objPhone->PhoneTypeId == PhoneType::Home) {
             $objPhone->PhoneTypeId = QDataGen::GenerateFromArray(array_keys(PhoneType::$NameArray));
         }
         $objPhone->Number = QDataGen::GeneratePhone();
         $objPhone->Person = $objPerson;
         $objPhone->Save();
         $objPhoneArray[] = $objPhone;
     }
     if ($intPhoneCount && !rand(0, 2)) {
         QDataGen::GenerateFromArray($objPhoneArray)->SetAsPrimary();
     }
     $intEmailCount = rand(0, 5);
     $objEmailArray = array();
     for ($i = 0; $i < $intEmailCount; $i++) {
         $objEmail = new Email();
         $objEmail->Address = QDataGen::GenerateEmail($objPerson->FirstName, $objPerson->LastName);
         $objEmail->Person = $objPerson;
         $objEmail->Save();
         $objEmailArray[] = $objEmail;
     }
     if ($intEmailCount && !rand(0, 2)) {
         QDataGen::GenerateFromArray($objEmailArray)->SetAsPrimary();
     }
     $intMaxId = OtherContactMethod::CountAll();
     for ($intOtherContactMethodId = 1; $intOtherContactMethodId <= $intMaxId; $intOtherContactMethodId++) {
         if (!rand(0, 2)) {
             $objContactInfo = new OtherContactInfo();
             $objContactInfo->Person = $objPerson;
             $objContactInfo->OtherContactMethodId = $intOtherContactMethodId;
             $objContactInfo->Value = QDataGen::GenerateUsername($objPerson->FirstName, $objPerson->LastName);
             $objContactInfo->Save();
         }
     }
 }
Beispiel #2
0
Datei: new.php Projekt: alcf/chms
 protected function SaveSpouse()
 {
     // Fixup Middle
     $this->txtSpouseMiddleName->Text = trim($this->txtSpouseMiddleName->Text);
     if (strlen($this->txtSpouseMiddleName->Text) == 1) {
         $this->txtSpouseMiddleName->Text = strtoupper($this->txtSpouseMiddleName->Text);
     } else {
         if (strlen($this->txtSpouseMiddleName->Text) == 2 && $this->txtSpouseMiddleName->Text[1] == '.') {
             $this->txtSpouseMiddleName->Text = strtoupper($this->txtSpouseMiddleName->Text[0]);
         }
     }
     // Update Gender and Types and Save
     $this->mctSpouse->Person->Gender = $this->lstSpouseGender->SelectedValue;
     $this->mctSpouse->Person->MembershipStatusTypeId = MembershipStatusType::NonMember;
     $this->mctSpouse->Person->MaritalStatusTypeId = MaritalStatusType::NotSpecified;
     $this->mctSpouse->Person->DeceasedFlag = false;
     $this->mctSpouse->SavePerson();
     $this->mctSpouse->Person->RefreshNameItemAssociations();
     // Is there a home address?
     if ($objHousehold = Household::LoadByHeadPersonId($this->mctPerson->Person->Id)) {
         $objHousehold->AssociatePerson($this->mctSpouse->Person);
     }
     // Email
     if (trim($this->txtSpouseEmail->Text)) {
         $objEmail = new Email();
         $objEmail->Person = $this->mctSpouse->Person;
         $objEmail->Address = trim($this->txtSpouseEmail->Text);
         $objEmail->Save();
         $this->mctSpouse->Person->PrimaryEmail = $objEmail;
     }
     // Phones
     if (trim($this->txtSpouseCellPhone->Text)) {
         $objPhone = new Phone();
         $objPhone->PhoneTypeId = PhoneType::Mobile;
         $objPhone->Person = $this->mctSpouse->Person;
         $objPhone->Number = trim($this->txtSpouseCellPhone->Text);
         $objPhone->MobileProviderId = $this->lstSpouseMobileProvider->SelectedValue;
         $objPhone->Save();
         $this->mctSpouse->Person->PrimaryPhone = $objPhone;
     }
     if (trim($this->txtSpouseHomePhone->Text)) {
         if ($this->txtSpouseHomePhone->Text != $this->txtPersonHomePhone->Text) {
             $objPhone = new Phone();
             $objPhone->PhoneTypeId = PhoneType::Home;
             $objPhone->Number = trim($this->txtSpouseHomePhone->Text);
             if ($objHousehold) {
                 $objPhone->Address = $this->mctAddress->Address;
             } else {
                 $objPhone->Person = $this->mctSpouse->Person;
             }
             $objPhone->Save();
         } else {
             $objPhone = $this->objHomePhone;
         }
         if (!$this->mctSpouse->Person->PrimaryPhone) {
             $this->mctSpouse->Person->PrimaryPhone = $objPhone;
         }
         if ($this->mctAddress->Address->Id && !$this->mctAddress->Address->PrimaryPhone) {
             $this->mctAddress->Address->PrimaryPhone = $objPhone;
             $this->mctAddress->Address->Save();
         }
     }
     if (trim($this->txtSpouseWorkPhone->Text)) {
         $objPhone = new Phone();
         $objPhone->PhoneTypeId = PhoneType::Work;
         $objPhone->Person = $this->mctSpouse->Person;
         $objPhone->Number = trim($this->txtSpouseWorkPhone->Text);
         $objPhone->Save();
         if (!$this->mctSpouse->Person->PrimaryPhone) {
             $this->mctSpouse->Person->PrimaryPhone = $objPhone;
         }
     }
 }
Beispiel #3
0
 /**
  * Given a home (and optional mailing) address validator (which is unlinked from any db entry), go ahead and make updates
  * to this person record accordingly.
  * 
  * If this person is part of multiple households, it will throw an error.
  * 
  * If this person is part of one household, it will update the information for the household.
  * 
  * If this person is not part of any houseold, it will create one for him/her.
  * 
  * @param AddressValidator $objHomeAddressValidator
  * @param AddressValidator $objMailingAddressValidator optional
  * @param string $strHomePhone optional
  */
 public function UpdateAddressInformation(AddressValidator $objHomeAddressValidator, AddressValidator $objMailingAddressValidator = null, $strHomePhone = null)
 {
     $objHouseholdArray = array();
     foreach ($this->GetHouseholdParticipationArray() as $objHouseholdParticipation) {
         $objHouseholdArray[] = $objHouseholdParticipation->Household;
     }
     // Figure Out Household Information
     if (count($objHouseholdArray) > 1) {
         throw new QCallerException('Cannot call UpdateAddressInformation on a person who is part of multiple households: ' . $this->intId);
     }
     if (count($objHouseholdArray)) {
         $objHousehold = $objHouseholdArray[0];
     } else {
         $objHousehold = Household::CreateHousehold($this);
     }
     // Home Address
     $objHomeAddress = $objHousehold->GetCurrentAddress();
     $objAddress = $objHomeAddressValidator->CreateAddressRecord();
     // Are we using the existing Household CurrentAddress record?
     if ($objHomeAddress && $objHomeAddress->IsEqualTo($objAddress)) {
         // Yes -- so all we're handling is the phones
         $objHomePhoneArray = $objHomeAddress->GetPhoneArray();
         // Are we setting a home phone?
         if ($strHomePhone) {
             // Try and find the phone within the array
             foreach ($objHomePhoneArray as $objPhone) {
                 $blnFound = false;
                 if ($objPhone->Number == $strHomePhone) {
                     $objPhone->SetAsPrimary(null, $objHomeAddress);
                     $blnFound = true;
                 }
             }
             // If we didn't find an existing home phone, we will update the current primary (if applicable)
             // Or create a new one as primary
             if (!$blnFound) {
                 if (count($objHomePhoneArray)) {
                     $objHomePhoneArray[0]->Number = $strHomePhone;
                     $objHomePhoneArray[0]->Save();
                 } else {
                     $objPhone = new Phone();
                     $objPhone->Number = $strHomePhone;
                     $objPhone->Address = $objHomeAddress;
                     $objPhone->PhoneTypeId = PhoneType::Home;
                     $objPhone->Save();
                     $objPhone->SetAsPrimary(null, $objHomeAddress);
                 }
             }
             // Nope - we are deleting the home phone
         } else {
             foreach ($objHomePhoneArray as $objPhone) {
                 $objPhone->Delete();
             }
         }
         // Not an existing Household CurrentAddress record that matches -- so we are creating a new one
     } else {
         $objAddress->Household = $objHousehold;
         $objAddress->CurrentFlag = true;
         $objAddress->AddressTypeId = AddressType::Home;
         $objAddress->Save();
         $objHousehold->SetAsCurrentAddress($objAddress);
         // Add the phone if applicable
         if ($strHomePhone) {
             $objPhone = new Phone();
             $objPhone->Number = $strHomePhone;
             $objPhone->Address = $objAddress;
             $objPhone->PhoneTypeId = PhoneType::Home;
             $objPhone->Save();
             $objPhone->SetAsPrimary(null, $objAddress);
         }
     }
     // Mailing Address?
     if ($objMailingAddressValidator) {
         $objAddress = $objMailingAddressValidator->CreateAddressRecord();
         $blnFound = false;
         foreach ($this->GetAllAssociatedAddressArray($objHousehold) as $objExistingAddress) {
             if ($objExistingAddress->IsEqualTo($objAddress)) {
                 $this->MailingAddress = $objExistingAddress;
                 $this->RefreshPrimaryContactInfo();
                 $blnFound = true;
             }
         }
         if (!$blnFound) {
             $objAddress->AddressTypeId = AddressType::Other;
             $objAddress->Person = $this;
             $objAddress->CurrentFlag = true;
             $objAddress->Save();
             $this->MailingAddress = $objAddress;
             $this->RefreshPrimaryContactInfo();
         }
     } else {
         if ($this->MailingAddress) {
             $this->MailingAddress = null;
             $this->RefreshPrimaryContactInfo();
         }
     }
 }
 /**
  * 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;
 }