Esempio n. 1
0
 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();
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
File: form.php Progetto: alcf/chms
 protected function Form_Create()
 {
     $this->objSignupForm = SignupForm::Load(QApplication::PathInfo(0));
     if (!$this->objSignupForm) {
         QApplication::Redirect('/events/');
     }
     $this->mctSignupForm = SignupFormMetaControl::Create($this, $this->objSignupForm->Id);
     if (!$this->objSignupForm->IsLoginCanView(QApplication::$Login)) {
         QApplication::Redirect('/events/');
     }
     $this->strPageTitle .= $this->objSignupForm->Name;
     $this->dtgQuestions = new FormQuestionDataGrid($this);
     $this->dtgQuestions->AddColumn(new QDataGridColumn('Reorder', '<?= $_FORM->RenderReorderQuestion($_ITEM); ?>', 'HtmlEntities=false', 'Width=60px'));
     $this->dtgQuestions->MetaAddTypeColumn('FormQuestionTypeId', 'FormQuestionType', 'Name=Question Type', 'Width=140px');
     $this->dtgQuestions->MetaAddColumn('ShortDescription', 'Html=<?= $_FORM->RenderShortDescription($_ITEM); ?>', 'Width=170px', 'HtmlEntities=false');
     $this->dtgQuestions->MetaAddColumn('Question', 'Width=400px');
     $this->dtgQuestions->MetaAddColumn('RequiredFlag', 'Width=60px', 'Name=Required?', 'Html=<?= ($_ITEM->RequiredFlag ? "Yes" : null) ?>');
     $this->dtgQuestions->MetaAddColumn('InternalFlag', 'Width=60px', 'Name=Internal Only', 'Html=<?= ($_ITEM->InternalFlag ? "Yes" : null) ?>');
     $this->dtgQuestions->SetDataBinder('dtgQuestions_Bind');
     $this->dtgProductsArray = array();
     foreach (FormProductType::$NameArray as $intFormProductTypeId => $strName) {
         if (FormProduct::CountBySignupFormIdFormProductTypeId($this->objSignupForm->Id, $intFormProductTypeId)) {
             $dtgProducts = new FormProductDataGrid($this);
             $dtgProducts->Name = $intFormProductTypeId;
             $dtgProducts->SetDataBinder('dtgProducts_Bind');
             $dtgProducts->AddColumn(new QDataGridColumn('Reorder', '<?= $_FORM->RenderReorderProduct($_ITEM, $_CONTROL); ?>', 'HtmlEntities=false', 'Width=60px'));
             $dtgProducts->MetaAddColumn('Name', 'Html=<?= $_FORM->RenderName($_ITEM); ?>', 'Width=250px', 'HtmlEntities=false');
             $dtgProducts->MetaAddColumn('DateStart', 'Name=Date Available', 'Html=<?= $_ITEM->DateStartHtml; ?>', 'HtmlEntities=false', 'Width=100px');
             $dtgProducts->MetaAddColumn('DateEnd', 'Name=Date Unavail.', 'Html=<?= $_ITEM->DateEndHtml; ?>', 'HtmlEntities=false', 'Width=100px');
             $dtgProducts->MetaAddColumn('MinimumQuantity', 'Name=Min. Qty.', 'Width=70px');
             $dtgProducts->MetaAddColumn('MaximumQuantity', 'Name=Max. Qty.', 'Width=70px');
             $dtgProducts->MetaAddTypeColumn('FormPaymentTypeId', 'FormPaymentType', 'Name=Pay Type', 'Width=70px');
             $dtgProducts->MetaAddColumn('Cost', 'Html=<?= $_FORM->RenderAmount($_ITEM->Cost, false); ?>', 'Width=70px');
             $dtgProducts->MetaAddColumn('Deposit', 'Html=<?= $_FORM->RenderAmount($_ITEM->Deposit, false); ?>', 'Width=70px');
             $this->dtgProductsArray[] = $dtgProducts;
         }
     }
     if ($this->objSignupForm->Ministry->IsLoginCanAdminMinistry(QApplication::$Login)) {
         $this->lstCreateNew = new QListBox($this);
         $this->lstCreateNew->AddItem('- Create New Question or Product -', null);
         foreach (FormQuestionType::$NameArray as $intId => $strName) {
             $this->lstCreateNew->AddItem($strName, $intId, false, 'Question Types');
         }
         foreach (FormProductType::$NameArray as $intId => $strName) {
             $this->lstCreateNew->AddItem($strName, $intId * -1, false, 'Product Types');
         }
         $this->lstCreateNew->AddAction(new QChangeEvent(), new QAjaxAction('lstCreateNew_Change'));
     }
     // Setup "About Event" label controls
     $this->SetupLabels();
     switch ($this->objSignupForm->SignupFormTypeId) {
         case SignupFormType::Event:
             $this->SetupLabelsForEvent();
             break;
         case SignupFormType::Course:
             $this->SetupLabelsForCourse();
             break;
     }
     // Add email automatically if "Allow No Login" is selected
     // and if email is not already there.
     $bHasEmail = false;
     $objQuestionArray = FormQuestion::LoadArrayBySignupFormId($this->objSignupForm->Id);
     foreach ($objQuestionArray as $objQuestionItem) {
         if ($objQuestionItem->FormQuestionTypeId == 7) {
             $bHasEmail = true;
             break;
         }
     }
     if ($this->objSignupForm->LoginNotRequiredFlag && !$bHasEmail) {
         $objQuestion = new FormQuestion();
         $objQuestion->SignupForm = $this->objSignupForm;
         $objQuestion->FormQuestionTypeId = 7;
         // email
         $objQuestion->OrderNumber = 100000;
         $objQuestion->ShortDescription = 'Email Address';
         $objQuestion->Question = 'Email Address';
         $objQuestion->RequiredFlag = true;
         $objQuestion->ViewFlag = true;
         $objQuestion->Save();
     }
     $this->pxyMoveDownQuestion = new QControlProxy($this);
     $this->pxyMoveDownQuestion->AddAction(new QClickEvent(), new QAjaxAction('pxyMoveDownQuestion_Click'));
     $this->pxyMoveDownQuestion->AddAction(new QClickEvent(), new QTerminateAction());
     $this->pxyMoveUpQuestion = new QControlProxy($this);
     $this->pxyMoveUpQuestion->AddAction(new QClickEvent(), new QAjaxAction('pxyMoveUpQuestion_Click'));
     $this->pxyMoveUpQuestion->AddAction(new QClickEvent(), new QTerminateAction());
     $this->pxyMoveDownProduct = new QControlProxy($this);
     $this->pxyMoveDownProduct->AddAction(new QClickEvent(), new QAjaxAction('pxyMoveDownProduct_Click'));
     $this->pxyMoveDownProduct->AddAction(new QClickEvent(), new QTerminateAction());
     $this->pxyMoveUpProduct = new QControlProxy($this);
     $this->pxyMoveUpProduct->AddAction(new QClickEvent(), new QAjaxAction('pxyMoveUpProduct_Click'));
     $this->pxyMoveUpProduct->AddAction(new QClickEvent(), new QTerminateAction());
 }