protected function btnSubmit_Click($strFormId, $strControlId, $strParameter) { $this->objSignupEntry->Save(); $this->CreateChildObject(); if (!QApplication::$PublicLogin) { // Create a communcations entry object or use an existing communcations_entry // if user is not logged in $txtEmail = $this->GetControl($this->strEmailCtrlId); $objCommunicationsEntry = CommunicationListEntry::LoadByEmail($txtEmail->Text); if (!$objCommunicationsEntry) { $objCommunicationsEntry = new CommunicationListEntry(); $objCommunicationsEntry->FirstName = $this->objFormQuestionControlArray[0]->Text; $objCommunicationsEntry->LastName = $this->objFormQuestionControlArray[1]->Text; if ($txtEmail) { $objCommunicationsEntry->Email = $txtEmail->Text; } $objCommunicationsEntry->Save(); } $this->objSignupEntry->CommunicationsEntryId = $objCommunicationsEntry->Id; } foreach ($this->objSignupForm->GetFormQuestionArray() as $objFormQuestion) { // Only update if this is NOT "InternalFlag" if ($objFormQuestion->InternalFlag) { continue; } $strControlId = 'fq' . $objFormQuestion->Id; $objFormAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($this->objSignupEntry->Id, $objFormQuestion->Id); if (!$objFormAnswer) { $objFormAnswer = new FormAnswer(); $objFormAnswer->SignupEntry = $this->objSignupEntry; $objFormAnswer->FormQuestion = $objFormQuestion; } switch ($objFormQuestion->FormQuestionTypeId) { case FormQuestionType::SpouseName: $lstSpouse = $this->GetControl($strControlId . 'id'); $txtSpouse = $this->GetControl($strControlId . 'nm'); if ($lstSpouse && $lstSpouse->SelectedValue) { $objFormAnswer->TextValue = Person::Load($lstSpouse->SelectedValue)->Name; } else { $objFormAnswer->TextValue = trim($txtSpouse->Text); } break; case FormQuestionType::Address: $rblAddress = $this->GetControl($strControlId . 'switch'); $txtAddress1 = $this->GetControl($strControlId . 'address1'); $txtAddress2 = $this->GetControl($strControlId . 'address2'); $txtCity = $this->GetControl($strControlId . 'city'); $lstState = $this->GetControl($strControlId . 'state'); $txtZipCode = $this->GetControl($strControlId . 'zipcode'); if ($rblAddress && $rblAddress->SelectedValue) { $objFormAnswer->AddressId = $rblAddress->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Address->AddressFullLine; } else { $objFormAnswer->AddressId = null; $objAddress = new Address(); $objAddress->Address1 = trim($txtAddress1->Text); $objAddress->Address2 = trim($txtAddress2->Text); $objAddress->City = trim($txtCity->Text); $objAddress->State = $lstState->SelectedValue; $objAddress->ZipCode = trim($txtZipCode->Text); $objFormAnswer->TextValue = $objAddress->AddressFullLine; } break; case FormQuestionType::Age: $txtAge = $this->GetControl($strControlId . 'age'); if (strlen(trim($txtAge->Text))) { $objFormAnswer->IntegerValue = $txtAge->Text; } else { $objFormAnswer->IntegerValue = null; } break; case FormQuestionType::DateofBirth: $dtxDateOfBirth = $this->GetControl($strControlId . 'dob'); if ($dtxDateOfBirth->DateTime) { $objFormAnswer->DateValue = $dtxDateOfBirth->DateTime; // Update the Person Information if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->DateOfBirth = $objFormAnswer->DateValue; $this->objSignupEntry->Person->DobGuessedFlag = false; $this->objSignupEntry->Person->DobYearApproximateFlag = false; $this->objSignupEntry->Person->Save(); } } else { $objFormAnswer->DateValue = null; } break; case FormQuestionType::Gender: $lstGender = $this->GetControl($strControlId . 'gender'); if ($lstGender->SelectedValue === true) { $objFormAnswer->TextValue = 'Male'; $objFormAnswer->BooleanValue = true; if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->Gender = 'M'; $this->objSignupEntry->Person->Save(); } } else { if ($lstGender->SelectedValue === false) { $objFormAnswer->TextValue = 'Female'; $objFormAnswer->BooleanValue = false; if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->Gender = 'F'; $this->objSignupEntry->Person->Save(); } } else { $objFormAnswer->TextValue = null; $objFormAnswer->BooleanValue = null; } } break; case FormQuestionType::Phone: $lstPhone = $this->GetControl($strControlId . 'id'); $txtPhone = $this->GetControl($strControlId . 'phone'); if ($lstPhone && $lstPhone->SelectedValue) { $objFormAnswer->PhoneId = $lstPhone->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Phone->Number; } else { if ($strNumber = trim($txtPhone->Text)) { $objFormAnswer->PhoneId = null; $objFormAnswer->TextValue = $strNumber; } else { $objFormAnswer->PhoneId = null; $objFormAnswer->TextValue = null; } } break; case FormQuestionType::Email: $lstEmail = $this->GetControl($strControlId . 'id'); $txtEmail = $this->GetControl($strControlId . 'email'); if ($lstEmail && $lstEmail->SelectedValue) { $objFormAnswer->EmailId = $lstEmail->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Email->Address; } else { if ($strNumber = trim($txtEmail->Text)) { $objFormAnswer->EmailId = null; $objFormAnswer->TextValue = $strNumber; } else { $objFormAnswer->EmailId = null; $objFormAnswer->TextValue = null; } } break; case FormQuestionType::ShortText: case FormQuestionType::LongText: $txtAnswer = $this->GetControl($strControlId); if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->TextValue = $strText; } else { $objFormAnswer->TextValue = null; } break; case FormQuestionType::Number: $txtAnswer = $this->GetControl($strControlId); if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->IntegerValue = $strText; } else { $objFormAnswer->IntegerValue = null; } break; case FormQuestionType::YesNo: $chkAnswer = $this->GetControl($strControlId); $objFormAnswer->BooleanValue = $chkAnswer->Checked; break; case FormQuestionType::SingleSelect: $lstAnswer = $this->GetControl($strControlId); $txtAnswer = $this->GetControl($strControlId . 'other'); // No item selected ("-select one-" still selected) if (is_null($lstAnswer->SelectedValue)) { $objFormAnswer->TextValue = null; // "Other" option } else { if ($lstAnswer->SelectedValue === false) { if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->TextValue = $strText; } else { $objFormAnswer->TextValue = null; } // Regular List Selection } else { $objFormAnswer->TextValue = trim($lstAnswer->SelectedValue); } } break; case FormQuestionType::MultipleSelect: //GJS - changing to multiple check boxes $chkAnswer = $this->GetControl($strControlId); $objItemsArray = $chkAnswer->GetAllItems(); if (count($objItemsArray)) { $strSelectedArray = array(); foreach ($objItemsArray as $objItem) { if ($objItem->Selected) { $strSelectedArray[] = $objItem->Name; } } $objFormAnswer->TextValue = implode("\r\n", $strSelectedArray); } else { $objFormAnswer->TextValue = null; } break; case FormQuestionType::Instructions: // Don't need to do anything here! break; default: throw new Exception('Invalid FormQuestionTypeId: ' . $objFormQuestion->FormQuestionTypeId); } $objFormAnswer->Save(); } if ($this->objSignupForm->CountFormProducts()) { QApplication::Redirect($this->objSignupEntry->PaymentUrl); } else { $this->objSignupEntry->Complete(); QApplication::Redirect($this->objSignupEntry->ConfirmationUrl); } }
protected function CreateAndRedirect(Person $objPerson) { $objSignupEntry = new SignupEntry(); $objSignupEntry->SignupForm = $this->objSignupForm; $objSignupEntry->Person = $objPerson; $objSignupEntry->SignupByPerson = $objPerson; $objSignupEntry->SignupEntryStatusTypeId = SignupEntryStatusType::Incomplete; $objSignupEntry->DateCreated = QDateTime::Now(); $objSignupEntry->Save(); if ($this->objSignupForm->SignupFormTypeId == SignupFormType::Course) { $objClassRegistration = new ClassRegistration(); $objClassRegistration->SignupEntry = $objSignupEntry; $objClassRegistration->ClassMeeting = $this->objSignupForm->ClassMeeting; $objClassRegistration->Person = $objSignupEntry->Person; $objClassRegistration->Save(); } QApplication::Redirect(sprintf('/events/result.php/%s/%s', $this->objSignupForm->Id, $objSignupEntry->Id)); }
public static function GenerateFormInMinistry(Ministry $objMinistry) { $objSignupForm = new SignupForm(); $objSignupForm->SignupFormTypeId = SignupFormType::Event; $objSignupForm->Ministry = $objMinistry; $objSignupForm->Name = self::GenerateTitle(3, 8); if (rand(0, 2)) { $strToken = strtolower($objSignupForm->Name); $strToken = str_replace(' ', '_', $strToken); if (!SignupForm::LoadByToken($strToken)) { $objSignupForm->Token = $strToken; } } $objSignupForm->ActiveFlag = rand(0, 10); $objSignupForm->Description = self::GenerateContent(rand(1, 3), 8, 20); $objSignupForm->InformationUrl = 'http://www.yahoo.com/'; $objSignupForm->EmailNotification = rand(0, 1) ? 'mike@michaelho.com, mike.ho@alcf.net' : null; $objSignupForm->AllowOtherFlag = rand(0, 1); $objSignupForm->AllowMultipleFlag = rand(0, 1); switch (rand(0, 5)) { case 1: $objSignupForm->SignupLimit = 50; break; case 2: $objSignupForm->SignupMaleLimit = 50; $objSignupForm->SignupFemaleLimit = 50; break; } $objSignupForm->DateCreated = self::GenerateDateTime(self::$SystemStartDate, QDateTime::Now()); $objSignupForm->Save(); $objEventSignupForm = new EventSignupForm(); $objEventSignupForm->SignupForm = $objSignupForm; $objEventSignupForm->DateStart = new QDateTime('2011-06-27 17:00'); $objEventSignupForm->DateEnd = new QDateTime('2011-06-30 12:00'); $objEventSignupForm->Location = 'Camp Hammer, Boulder Creek, CA'; $objEventSignupForm->Save(); // Add form products information // 1: Required Product $intOrderNumber = 1; if (rand(0, 1)) { $objFormProduct = new FormProduct(); $objFormProduct->SignupForm = $objSignupForm; $objFormProduct->FormProductTypeId = FormProductType::Required; $objFormProduct->FormPaymentTypeId = self::GenerateFromArray(array_keys(FormPaymentType::$NameArray)); $objFormProduct->Name = 'Main Registration Fee'; switch ($objFormProduct->FormPaymentTypeId) { case FormPaymentType::DepositRequired: $objFormProduct->Cost = rand(1, 10) * 10; $objFormProduct->Deposit = $objFormProduct->Cost / 2; break; case FormPaymentType::PayInFull: $objFormProduct->Cost = rand(1, 10) * 10; break; case FormPaymentType::Donation: $objFormProduct->FormPaymentTypeId = FormPaymentType::PayInFull; $objFormProduct->Cost = rand(1, 10) * 10; break; } $objFormProduct->OrderNumber = $intOrderNumber; $intOrderNumber++; $objFormProduct->ViewFlag = true; $objFormProduct->MinimumQuantity = 1; $objFormProduct->MaximumQuantity = 1; $objFormProduct->Save(); } // 2: Required w/ Choice Product if (rand(0, 1)) { $arrProduct = array('100' => 'Standard Accommodation', '150' => 'Deluxe Accommodation'); foreach ($arrProduct as $fltAmount => $strName) { $objFormProduct = new FormProduct(); $objFormProduct->SignupForm = $objSignupForm; $objFormProduct->FormProductTypeId = FormProductType::RequiredWithChoice; $objFormProduct->FormPaymentTypeId = FormPaymentType::PayInFull; $objFormProduct->Name = $strName; $objFormProduct->Description = self::GenerateContent(1, 3, 10); $objFormProduct->Cost = $fltAmount; $objFormProduct->OrderNumber = $intOrderNumber; $objFormProduct->MinimumQuantity = 1; $objFormProduct->MaximumQuantity = 1; $intOrderNumber++; $objFormProduct->ViewFlag = true; $objFormProduct->Save(); } } // 3: Optional Product(s) $intProductCount = rand(0, 3); for ($i = 0; $i < $intProductCount; $i++) { $objFormProduct = new FormProduct(); $objFormProduct->SignupForm = $objSignupForm; $objFormProduct->FormProductTypeId = FormProductType::Optional; $objFormProduct->FormPaymentTypeId = FormPaymentType::PayInFull; $objFormProduct->Name = self::GenerateTitle(2, 5); $objFormProduct->Description = self::GenerateContent(1, 3, 10); $objFormProduct->MinimumQuantity = 1; $objFormProduct->MaximumQuantity = rand(1, 3); $objFormProduct->Cost = rand(1, 10) * 5; $objFormProduct->OrderNumber = $intOrderNumber; $intOrderNumber++; $objFormProduct->ViewFlag = true; $objFormProduct->Save(); } // 4: Otpional Donation if (rand(0, 1)) { $objFormProduct = new FormProduct(); $objFormProduct->SignupForm = $objSignupForm; $objFormProduct->FormProductTypeId = FormProductType::Optional; $objFormProduct->FormPaymentTypeId = FormPaymentType::Donation; $objFormProduct->Name = 'Donation'; $objFormProduct->Description = self::GenerateContent(1, 3, 10); $objFormProduct->MinimumQuantity = 1; $objFormProduct->MaximumQuantity = 1; $objFormProduct->OrderNumber = $intOrderNumber; $intOrderNumber++; $objFormProduct->ViewFlag = true; $objFormProduct->Save(); } // Add Form Questions $intOrderNumber = 1; foreach (FormQuestionType::$NameArray as $intFormQuestionTypeId => $strName) { if (rand(0, 1)) { $objFormQuestion = null; } else { $objFormQuestion = new FormQuestion(); $objFormQuestion->SignupForm = $objSignupForm; $objFormQuestion->OrderNumber = $intOrderNumber; $objFormQuestion->FormQuestionTypeId = $intFormQuestionTypeId; $objFormQuestion->RequiredFlag = rand(0, 1); $objFormQuestion->ViewFlag = rand(0, 1); switch ($intFormQuestionTypeId) { case FormQuestionType::SpouseName: $objFormQuestion->ShortDescription = 'Spouse\'s Name'; $objFormQuestion->Question = 'What is your spouse\'s name?'; break; case FormQuestionType::Address: $objFormQuestion->ShortDescription = 'Home Address'; $objFormQuestion->Question = 'What is your address?'; break; case FormQuestionType::Age: $objFormQuestion->ShortDescription = 'Age'; $objFormQuestion->Question = 'How old are you?'; break; case FormQuestionType::DateofBirth: $objFormQuestion->ShortDescription = 'Date of Birth'; $objFormQuestion->Question = 'When were you born'; break; case FormQuestionType::Gender: $objFormQuestion->ShortDescription = 'Gender'; $objFormQuestion->Question = 'What is your gender?'; break; case FormQuestionType::Phone: $objFormQuestion->ShortDescription = 'Phone'; $objFormQuestion->Question = 'What is your phone number?'; break; case FormQuestionType::Email: $objFormQuestion->ShortDescription = 'Email'; $objFormQuestion->Question = 'What is your email address?'; break; case FormQuestionType::ShortText: $objFormQuestion->ShortDescription = 'Foo Bar'; $objFormQuestion->Question = 'What is your foo bar?'; break; case FormQuestionType::LongText: $objFormQuestion->ShortDescription = 'Foo Bar Long'; $objFormQuestion->Question = 'What is your foo bar long?'; break; case FormQuestionType::Number: $objFormQuestion->ShortDescription = 'Number of Baz'; $objFormQuestion->Question = 'How many baz?'; break; case FormQuestionType::YesNo: $objFormQuestion->ShortDescription = 'Blue Color'; $objFormQuestion->Question = 'Is it blue?'; break; case FormQuestionType::SingleSelect: $objFormQuestion->ShortDescription = 'One Item'; $objFormQuestion->Question = 'Which is it?'; $objFormQuestion->Options = "Option One\nOption Two\nOption Three"; break; case FormQuestionType::MultipleSelect: $objFormQuestion->ShortDescription = 'Multiple Item'; $objFormQuestion->Question = 'What are they?'; $objFormQuestion->Options = "Option One\nOption Two\nOption Three"; break; default: throw new QCallerException(sprintf('Invalid intFormQuestionTypeId: %s', $intFormQuestionTypeId)); } $objFormQuestion->Save(); $intPersonCount = rand(self::SignupsPerFormMinimum, self::SignupsPerFormMaximum); for ($i = 0; $i < $intPersonCount; $i++) { $objPerson = null; while (!$objPerson) { $objPerson = Person::Load(rand(1, self::$MaximumPersonId)); if ($objPerson && !$objSignupForm->AllowMultipleFlag && $objSignupForm->IsPersonRegistered($objPerson)) { $objPerson = null; } } $objSignup = new SignupEntry(); $objSignup->SignupForm = $objSignupForm; $objSignup->Person = $objPerson; $objSignup->SignupByPerson = $objPerson; $objSignup->DateCreated = self::GenerateDateTime($objSignupForm->DateCreated, QDateTime::Now()); $objSignup->SignupEntryStatusTypeId = SignupEntryStatusType::Incomplete; $objSignup->InternalNotes = !rand(0, 2) ? self::GenerateContent(1, 5, 10) : null; $objSignup->Save(); // Rqeuired Products foreach ($objSignupForm->GetFormProductArrayByType(FormProductType::Required) as $objFormProduct) { $objSignup->AddProduct($objFormProduct); } // Required with Choice $objArray = $objSignupForm->GetFormProductArrayByType(FormProductType::RequiredWithChoice); if (count($objArray)) { $objSignup->AddProduct(self::GenerateFromArray($objArray)); } // Optionals (including donations) foreach ($objSignupForm->GetFormProductArrayByType(FormProductType::Optional) as $objFormProduct) { if (rand(0, 1)) { if ($objFormProduct->FormPaymentTypeId == FormPaymentType::Donation) { $objSignup->AddProduct($objFormProduct, rand($objFormProduct->MinimumQuantity, $objFormProduct->MaximumQuantity), rand(1, 10) * 10); } else { $objSignup->AddProduct($objFormProduct, rand($objFormProduct->MinimumQuantity, $objFormProduct->MaximumQuantity)); } } } // Payments if (rand(0, 14)) { $objSignup->SignupEntryStatusTypeId = SignupEntryStatusType::Complete; $objSignup->DateSubmitted = new QDateTime($objSignup->DateCreated); $objSignup->DateSubmitted->Minute += 1; $objSignup->Save(); $fltAmount = rand(0, 1) ? $objSignup->AmountTotal : $objSignup->CalculateMinimumDeposit(); $objSignup->AddPayment(SignupPaymentType::CreditCard, $fltAmount, 'DATAGEN1234', new QDateTime($objSignup->DateSubmitted)); } // Create the form answers for each question foreach ($objSignupForm->GetFormQuestionArray(QQ::OrderBy(QQN::FormQuestion()->OrderNumber)) as $objFormQuestion) { if ($objFormQuestion->RequiredFlag || rand(0, 1)) { $objFormAnswer = new FormAnswer(); $objFormAnswer->SignupEntry = $objSignup; $objFormAnswer->FormQuestion = $objFormQuestion; switch ($objFormQuestion->FormQuestionTypeId) { case FormQuestionType::SpouseName: $objFormAnswer->TextValue = 'Spouse Name'; break; case FormQuestionType::Address: $objFormAnswer->TextValue = $objPerson->PrimaryAddressText . ', ' . $objPerson->PrimaryCityText; $objArray = $objPerson->GetHouseholdParticipationArray(); if (count($objArray)) { $objAddress = $objArray[0]->Household->GetCurrentAddress(); if ($objAddress) { $objFormAnswer->AddressId = $objAddress->Id; } else { $objFormAnswer = null; } } else { $objArray = $objPerson->GetAddressArray(); if (count($objArray)) { $objFormAnswer->AddressId = $objArray[0]->Id; } else { $objFormAnswer = null; } } break; case FormQuestionType::Age: $objFormAnswer->IntegerValue = $objPerson->Age; break; case FormQuestionType::DateofBirth: if ($objPerson->DateOfBirth) { $objFormAnswer->DateValue = $objPerson->DateOfBirth; } break; case FormQuestionType::Gender: switch ($objPerson->Gender) { case 'M': $objFormAnswer->BooleanValue = true; $objFormAnswer->TextValue = 'Male'; break; case 'F': $objFormAnswer->BooleanValue = false; $objFormAnswer->TextValue = 'Female'; break; default: $objFormAnswer = null; break; } break; case FormQuestionType::Phone: if (count($objArray = $objPerson->GetPhoneArray())) { $objFormAnswer->TextValue = $objArray[0]->Number; $objFormAnswer->PhoneId = $objArray[0]->Id; } break; case FormQuestionType::Email: if (count($objArray = $objPerson->GetEmailArray())) { $objFormAnswer->TextValue = $objArray[0]->Address; $objFormAnswer->EmailId = $objArray[0]->Id; } break; case FormQuestionType::ShortText: $objFormAnswer->TextValue = 'Foo Bar'; break; case FormQuestionType::LongText: $objFormAnswer->TextValue = 'The quick brown fox jumps over the lazy dog.'; break; case FormQuestionType::Number: $objFormAnswer->IntegerValue = 28; break; case FormQuestionType::YesNo: $objFormAnswer->BooleanValue = rand(0, 1); break; case FormQuestionType::SingleSelect: $objFormAnswer->TextValue = "Option Two"; break; case FormQuestionType::MultipleSelect: $objFormAnswer->TextValue = "Option One\nOption Three"; break; } if ($objFormAnswer) { $objFormAnswer->Save(); } } } } } } }