/** * Sets an attribute value for this person. * Data Type of $mixValue is dependent on the Data Type for the attribute being set. * @param Attribute $objAttribute * @param mixed $mixValue * @return AttributeValue */ public function SetAttribute(Attribute $objAttribute, $mixValue) { $objValue = AttributeValue::LoadByAttributeIdPersonId($objAttribute->Id, $this->intId); if (!$objValue) { $objValue = new AttributeValue(); $objValue->Attribute = $objAttribute; $objValue->Person = $this; } switch ($objAttribute->AttributeDataTypeId) { case AttributeDataType::Text: $objValue->TextValue = $mixValue; break; case AttributeDataType::Checkbox: $objValue->BooleanValue = $mixValue; break; case AttributeDataType::Date: $objValue->DateValue = $mixValue; break; case AttributeDataType::ImmutableSingleDropdown: case AttributeDataType::MutableSingleDropdown: $objValue->SingleAttributeOption = $mixValue; break; case AttributeDataType::ImmutableMultipleDropdown: case AttributeDataType::MutableMultipleDropdown: $objValue->Save(); $objValue->UnassociateAllAttributeOptionsAsMultiple(); foreach ($mixValue as $objOption) { $objValue->AssociateAttributeOptionAsMultiple($objOption); } break; default: throw new Exception('Unhandled Attribute Data Type'); } $objValue->Save(); return $objValue; }
protected function btnUnsubscribe_Click() { $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->txtEmail->Text); $objEmailArray = Email::LoadArrayByAddress($this->txtEmail->Text); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson != null) { $strUnsubscribedList = ''; $success = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($this->objList->IsPersonAssociated($objPerson)) { $this->objList->UnassociatePerson($objPerson); // If church newletter is the one being unsubscribed, document reason. if ($this->lstTerminationReason->SelectedValue == -1) { $objAttributeOption = new AttributeOption(); $objAttributeOption->AttributeId = $this->objAttributeValue->AttributeId; $objAttributeOption->Name = trim($this->txtOther->Text); $objAttributeOption->Save(); $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } else { $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } if (!$bFound) { $this->lblMessage->Text = '(Person Entry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList) . '/' . $objPerson->Id); } } } if ($objCommunicationListEntry) { $strUnsubscribedList = ''; $success = false; $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($objCommunicationListEntry != null) { if ($this->objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { $this->objList->UnassociateCommunicationListEntry($objCommunicationListEntry); $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } } if (!$bFound) { $this->lblMessage->Text = '(CommunicationsEntry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList)); } } $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $bChecked = true; break; } } if (!$bChecked) { $this->lblMessage->Text = 'You must select a list to subscribe to.'; $this->lblMessage->Visible = true; } else { $this->lblMessage->Text = 'Failed to unsubscribe from the list. The email may not exist.'; $this->lblMessage->Visible = true; } }
protected function SaveAttribute() { if ($this->txtAttributePreviousChurch != null && $this->txtAttributeOccupation->Text != "") { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Previous Church")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->TextValue = $this->txtAttributePreviousChurch->Text; $objAttributeValue->DatetimeValue = QDateTime::Now(); $objAttributeValue->Save(); } if ($this->txtAttributeOccupation != null && $this->txtAttributeOccupation->Text != "") { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Occupation")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->TextValue = $this->txtAttributeOccupation->Text; $objAttributeValue->DatetimeValue = QDateTime::Now(); $objAttributeValue->Save(); } if ($this->lstAttributeMethodJoin != null && $this->lstAttributeMethodJoin->SelectedName != '- Select One -') { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Method of Joining ALCF")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->TextValue = $this->lstAttributeMethodJoin->SelectedName; $objAttributeValue->DatetimeValue = QDateTime::Now(); $objAttributeValue->SingleAttributeOptionId = $this->lstAttributeMethodJoin->SelectedValue; $objAttributeValue->SingleAttributeOption->Name = $this->lstAttributeMethodJoin->SelectedName; $objAttributeValue->Save(); } if ($this->lstAttributeEthnicity != null && $this->lstAttributeEthnicity->SelectedName != '- Select One -') { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Ethnicity")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->TextValue = $this->lstAttributeEthnicity->SelectedName; $objAttributeValue->DatetimeValue = QDateTime::Now(); $objAttributeValue->SingleAttributeOptionId = $this->lstAttributeEthnicity->SelectedValue; $objAttributeValue->SingleAttributeOption->Name = $this->lstAttributeEthnicity->SelectedName; $objAttributeValue->Save(); } if ($this->dtxAttributeDateAcceptedChrist != null && $this->dtxAttributeDateAcceptedChrist->DateTime != null) { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Date Accepted Christ")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->DatetimeValue = $this->dtxAttributeDateAcceptedChrist->DateTime; $objAttributeValue->DateValue = $this->dtxAttributeDateAcceptedChrist->DateTime; $objAttributeValue->Save(); } if ($this->chkAcceptedChristAtALCF->Checked) { $objAttributeValue = new AttributeValue(); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Accepted Christ At ALCF")); $objAttributeValue->AttributeId = $objAttribute->Id; $objAttributeValue->PersonId = $this->mctPerson->Person->Id; $objAttributeValue->BooleanValue = true; $objAttributeValue->Save(); } }