/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = FormAnswer::QueryCount($objCondition, $objClauses); } // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from FormAnswer, given the clauses above $this->DataSource = FormAnswer::QueryArray($objCondition, $objClauses); }
/** * Deletes all associated FormAnswers * @return void */ public function DeleteAllFormAnswers() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateFormAnswer on this unsaved SignupEntry.'); } // Get the Database Object for this Class $objDatabase = SignupEntry::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (FormAnswer::LoadArrayBySignupEntryId($this->intId) as $objFormAnswer) { $objFormAnswer->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `form_answer` WHERE `signup_entry_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, FormAnswer::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }
/** * If the form has an "address" field, it will return the address data as an address record * NOT linked with the database. This is primarily used for pre-filling credit card data/forms. * * This will return NULL if no address can be retrieved. * @return Address */ public function RetrieveAnyValidAddressObject() { foreach ($this->SignupForm->GetFormQuestionArray() as $objFormQuestion) { if ($objFormQuestion->FormQuestionTypeId == FormQuestionType::Address) { if ($objFormAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($this->intId, $objFormQuestion->Id)) { $objAddress = Address::DeduceAddressFromFullLine($objFormAnswer->TextValue); if ($objAddress) { return $objAddress; } } } } return null; }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this FormAnswerMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing FormAnswer object creation - defaults to CreateOrEdit * @return FormAnswerMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objFormAnswer = FormAnswer::Load($intId); // FormAnswer was found -- return it! if ($objFormAnswer) { return new FormAnswerMetaControl($objParentObject, $objFormAnswer); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a FormAnswer object with PK arguments: ' . $intId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new FormAnswerMetaControl($objParentObject, new FormAnswer()); }
protected function pxyEditFormQuestion_Click($strFormId, $strControlId, $strParameter) { $objFormQuestion = FormQuestion::Load($strParameter); if ($objFormQuestion->SignupFormId != $this->objSignupForm->Id) { return; } /** * @var SignupEntry */ $objSignupEntry = $this->mctSignupEntry->SignupEntry; /** * @var Person */ $objPerson = $this->mctSignupEntry->SignupEntry->Person; $this->dlgEdit->ShowDialogBox(); $this->dlgEdit->Template = dirname(__FILE__) . '/dlgEditResult_FormAnswer.tpl.php'; $this->intEditTag = self::EditTagAnswer; $this->objAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($objSignupEntry->Id, $objFormQuestion->Id); if (!$this->objAnswer) { $this->objAnswer = new FormAnswer(); $this->objAnswer->SignupEntryId = $objSignupEntry->Id; $this->objAnswer->FormQuestionId = $objFormQuestion->Id; $this->btnDelete->Visible = false; } else { $this->btnDelete->Visible = true; } // Reset $this->ResetDialogControls(); // Setup the appropriate control switch ($objFormQuestion->FormQuestionTypeId) { case FormQuestionType::YesNo: $this->chkBoolean->Name = 'Response'; $this->chkBoolean->Checked = $this->objAnswer->BooleanValue; $this->chkBoolean->Text = $objFormQuestion->ShortDescription; break; case FormQuestionType::SpouseName: $this->txtTextbox->Name = 'Spouse\'s Name'; $this->txtTextbox->Text = $this->objAnswer->TextValue; $this->txtTextbox->Focus(); break; case FormQuestionType::Address: $objAddresses = array(); foreach ($objPerson->GetHouseholdParticipationArray() as $objHouseholdParticipation) { foreach ($objHouseholdParticipation->Household->GetAddressArray() as $objAddress) { if ($objAddress->CurrentFlag) { $objAddresses[$objAddress->Id] = $objAddress; } } } foreach (Address::LoadArrayByPersonId($objPerson->Id) as $objAddress) { if ($objAddress->CurrentFlag) { $objAddresses[$objAddress->Id] = $objAddress; } } $this->lstListbox->RemoveAllItems(); foreach ($objAddresses as $objAddress) { $this->lstListbox->AddItem(sprintf('%s (%s)', $objAddress->Label, $objAddress->AddressShortLine), $objAddress->Id, $objAddress->Id == $this->objAnswer->AddressId); } $this->lstListbox->Name = $objFormQuestion->ShortDescription; $this->lblInstructions->Text = sprintf('If you need to specify an address that is not listed, you will need to <a href="%s">Update this person\'s Contact Info</a>.', $objPerson->ContactInfoLinkUrl); break; case FormQuestionType::Gender: $this->lstListbox->RemoveAllItems(); $this->lstListbox->AddItem('Male', true, $objPerson->Gender == 'M'); $this->lstListbox->AddItem('Female', false, $objPerson->Gender == 'F'); $this->lstListbox->Name = 'Gender'; $this->lblInstructions->Text = 'Please note that updating the Gender value here will also update this person\'s record in NOAH.'; break; case FormQuestionType::Phone: $objPhones = array(); foreach ($objPerson->GetHouseholdParticipationArray() as $objHouseholdParticipation) { foreach ($objHouseholdParticipation->Household->GetAddressArray() as $objAddress) { foreach ($objAddress->GetPhoneArray() as $objPhone) { $objPhones[] = $objPhone; } } } foreach ($objPerson->GetPhoneArray() as $objPhone) { $objPhones[] = $objPhone; } $this->lstListbox->RemoveAllItems(); foreach ($objPhones as $objPhone) { $this->lstListbox->AddItem(sprintf('%s (%s)', $objPhone->Number, $objPhone->Label), $objPhone->Id, $objPhone->Id == $this->objAnswer->PhoneId); } $this->lstListbox->Name = $objFormQuestion->ShortDescription; $this->lblInstructions->Text = sprintf('If you need to specify a phone number that is not listed, you will need to <a href="%s">Update this person\'s Contact Info</a>.', $objPerson->ContactInfoLinkUrl); break; case FormQuestionType::Email: $this->lstListbox->RemoveAllItems(); foreach ($objPerson->GetEmailArray() as $objEmail) { $this->lstListbox->AddItem($objEmail->Label, $objEmail->Id, $objEmail->Id == $this->objAnswer->EmailId); } $this->lstListbox->Name = $objFormQuestion->ShortDescription; $this->lblInstructions->Text = sprintf('If you need to specify an email address that is not listed, you will need to <a href="%s">Update this person\'s Contact Info</a>.', $objPerson->ContactInfoLinkUrl); break; case FormQuestionType::ShortText: $this->txtTextbox->Text = $this->objAnswer->TextValue; $this->txtTextbox->Name = $objFormQuestion->ShortDescription; break; case FormQuestionType::LongText: $this->txtTextArea->Text = $this->objAnswer->TextValue; $this->txtTextArea->Name = $objFormQuestion->ShortDescription; break; case FormQuestionType::SingleSelect: $this->lstListbox->RemoveAllItems(); $this->lstListbox->Name = $objFormQuestion->ShortDescription; foreach (explode("\n", $objFormQuestion->Options) as $strOption) { $strOption = trim($strOption); $this->lstListbox->AddItem($strOption, $strOption, trim($this->objAnswer->TextValue) == $strOption); } if ($objFormQuestion->AllowOtherFlag) { $this->txtTextbox->Name = 'Other...'; if (!$this->lstListbox->SelectedValue && strlen(trim($this->objAnswer->TextValue))) { $blnOtherSelected = true; $this->txtTextbox->Text = trim($this->objAnswer->TextValue); } else { $blnOtherSelected = false; } $this->txtTextbox->Enabled = $blnOtherSelected; $this->lstListbox->AddItem('- Other... -', false, $blnOtherSelected); $this->lstListbox->AddAction(new QChangeEvent(), new QAjaxAction('lstListbox_Change')); $this->lstListbox_Change(); } break; case FormQuestionType::MultipleSelect: //GJS - changing to multiple check boxes $this->chkAnswer->Name = $objFormQuestion->ShortDescription; $this->chkAnswer->RemoveAllItems(); // Get the answers $strAnswerArray = $this->objAnswer->GetSelectedMultipleChoiceArray(); foreach (explode("\n", trim($objFormQuestion->Options)) as $strItem) { if (strlen($strItem = trim($strItem))) { $this->chkAnswer->AddItem($strItem, $strItem, array_key_exists($strItem, $strAnswerArray)); $strAnswerArray[$strItem] = null; unset($strAnswerArray[$strItem]); } } foreach ($strAnswerArray as $strAnswer) { $this->chkAnswer->AddItem($strAnswer, $strAnswer, true); } // Are we allowing "others"? if ($objFormQuestion->AllowOtherFlag) { $this->txtTextbox->Name = 'Other...'; $this->txtTextbox->Text = null; $this->txtTextbox->RemoveAllActions(QEnterKeyEvent::EventName); $this->txtTextbox->AddAction(new QEnterKeyEvent(), new QAjaxAction('txtTextbox_EnterKey')); $this->txtTextbox->AddAction(new QEnterKeyEvent(), new QTerminateAction()); $this->txtTextbox->Instructions = 'Type in a value and hit <strong>return</strong> to add it to the list'; } break; case FormQuestionType::Number: $this->txtInteger->Text = $this->objAnswer->IntegerValue; $this->txtInteger->Name = $objFormQuestion->ShortDescription; break; case FormQuestionType::Age: $this->txtTextbox->Name = $objFormQuestion->ShortDescription; $this->txtTextbox->Text = $objPerson->Age; $this->txtTextbox->Enabled = false; $this->lblInstructions->Text = sprintf('If you need modify the person\'s age, you will need to <a href="%s">update this person\'s NOAH information</a>.', $objPerson->LinkUrl); break; case FormQuestionType::DateofBirth: $this->txtTextbox->Name = $objFormQuestion->ShortDescription; $this->txtTextbox->Text = $objPerson->DateOfBirth ? $objPerson->DateOfBirth->ToString('MMM D YYYY') : null; $this->txtTextbox->Enabled = false; $this->lblInstructions->Text = sprintf('If you need modify the person\'s date of birth, you will need to <a href="%s">update this person\'s NOAH information</a>.', $objPerson->LinkUrl); break; } }
print ","; print $objFormProduct->Name; } } print ",Total,Paid,Balance,Payment Type"; } print ",Date Submitted\r\n"; $objCursor = SignupEntry::QueryCursor(QQ::Equal(QQN::SignupEntry()->SignupFormId, $objSignupForm->Id), QQ::OrderBy(QQN::SignupEntry()->DateSubmitted)); while ($objSignupEntry = SignupEntry::InstantiateCursor($objCursor)) { if ($objSignupEntry->SignupEntryStatusTypeId == SignupEntryStatusType::Complete) { print EscapeCsv($objSignupEntry->Person->FirstName); print ","; print EscapeCsv($objSignupEntry->Person->LastName); print ","; foreach ($objFormQuestionArray as $objFormQuestion) { $objAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($objSignupEntry->Id, $objFormQuestion->Id); if ($objAnswer) { switch ($objFormQuestion->FormQuestionTypeId) { case FormQuestionType::YesNo: if ($objAnswer->BooleanValue) { print 'Yes'; } break; case FormQuestionType::SpouseName: case FormQuestionType::Phone: case FormQuestionType::Email: case FormQuestionType::Gender: case FormQuestionType::ShortText: case FormQuestionType::LongText: case FormQuestionType::SingleSelect: case FormQuestionType::MultipleSelect:
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); } }
public function RenderAnswer(SignupEntry $objSignupEntry, $intFormQuestionId, $intFormQuestionTypeId) { $objAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($objSignupEntry->Id, $intFormQuestionId); if (!$objAnswer) { return; } switch ($intFormQuestionTypeId) { case FormQuestionType::YesNo: if ($objAnswer->BooleanValue) { return 'Yes'; } break; case FormQuestionType::SpouseName: case FormQuestionType::Address: case FormQuestionType::Gender: case FormQuestionType::Phone: case FormQuestionType::Email: case FormQuestionType::ShortText: case FormQuestionType::LongText: case FormQuestionType::SingleSelect: case FormQuestionType::MultipleSelect: return QString::Truncate(QApplication::HtmlEntities($objAnswer->TextValue), 50); case FormQuestionType::Number: case FormQuestionType::Age: return $objAnswer->IntegerValue; case FormQuestionType::DateofBirth: if ($objAnswer->DateValue) { return $objAnswer->DateValue->ToString('MMM D YYYY'); } break; } }