/**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $userLabel = 'Tenant';
     if (isset($options['userLabel']) && is_string($options['userLabel'])) {
         $userLabel = $options['userLabel'];
     }
     /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingCase\Model\ReferencingCase $case */
     $case = $this->progressiveStore->getPrototypeByClass('Barbondev\\IRISSDK\\IndividualApplication\\ReferencingCase\\Model\\ReferencingCase');
     $builder->add('signaturePreference', 'hidden', array('data' => SignaturePreferenceOptions::SCANNED_DECLARATION))->add('productId', 'choice', array('label' => 'Product', 'choices' => $this->getProductChoices(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a product')))))->add('update', 'submit', array('attr' => array('value' => '1')))->add('title', 'choice', array('choices' => Titles::getTitles(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a title', 'groups' => array('fullValidation'))))))->add('firstName', 'text', array('label' => $userLabel . ' First Name', 'constraints' => array(new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please enter a first name')), new Assert\Regex(array('pattern' => '/^[-a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('middleName', 'text', array('label' => $userLabel . ' Middle Name', 'required' => false, 'constraints' => array(new Assert\Regex(array('pattern' => '/^[ -a-zA-Z0-9\\w]*$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('lastName', 'text', array('label' => $userLabel . ' Last Name', 'constraints' => array(new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please enter a last name')), new Assert\Regex(array('pattern' => '/^[ -a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('email', 'repeated', array('type' => 'email', 'options' => array('required' => true, 'constraints' => array(new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please enter an email address')), new Assert\Email(array('groups' => array('fullValidation'), 'message' => 'Please enter a valid email address')))), 'first_options' => array('label' => $userLabel . ' Email'), 'second_options' => array('label' => 'Confirm Email')))->add('rentShare', new MoneyWithoutStringTransformerType(), array('label' => 'Share of Rent', 'currency' => 'GBP', 'constraints' => array(new Assert\GreaterThanOrEqual(array('value' => 0, 'groups' => array('fullValidation'), 'message' => 'Please enter a positive numeric value for share of rent')), new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please enter a share of rent')), new Assert\Regex(array('pattern' => '/^([0-9]+\\.[0-9]{0,2}|[0-9]+)$/', 'message' => 'Amount must either have 2 decimal places or a whole number, e.g. "15000.00" or "15000"')), new Assert\LessThanOrEqual(array('value' => $case->getTotalRent(), 'groups' => array('fullValidation'), 'message' => 'This amount must be less than the total rent')))))->add('completionMethod', 'choice', array('choices' => Lookup::getInstance()->getCategoryAsChoices(LookupCategoryOptions::COMPLETION_METHODS), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please select a completion method')))));
     $self = $this;
     /**
      * Form modifier callback - adds policyLength field if rent guarantee product and adds helper notes depending on
      * the product.
      *
      * @param FormInterface $form
      * @param \Barbondev\IRISSDK\IndividualApplication\Product\Model\Product $product
      * @return void
      */
     $policyLengthFormModifier = function (FormInterface $form, Product $product = null) {
         if (null !== $product) {
             // Check if this is a rent guarantee product
             if ($product->getHasRentGuarantee()) {
                 // Check for international products by product code
                 $form->add('policyLength', 'choice', array('choices' => array(6 => '6 Months', 12 => '12 Months'), 'expanded' => true, 'constraints' => array(new Assert\NotBlank(array('message' => 'Please enter a policy length for rent guarantee')), new Assert\Choice(array('choices' => array(6, 12))))));
             } else {
                 // Not a rent guarantee product
             }
         } elseif (null !== $product && !$product->getHasRentGuarantee()) {
             if ($form->has('policyLength')) {
                 $form->remove('policyLength');
             }
         }
     };
     if (!$this->progressiveStore instanceof AgentGuarantorProgressiveStore) {
         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($self, $policyLengthFormModifier) {
             /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\ReferencingApplication $application */
             $application = $event->getData();
             if ($application->getProductId()) {
                 // Get the current product and if has rent guarantee, add a policy length field
                 $product = $self->getProductById($application->getProductId());
                 $policyLengthFormModifier($event->getForm(), $product);
             }
         });
         $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use($self, $policyLengthFormModifier) {
             /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\ReferencingApplication $application */
             $application = $event->getData();
             // Get the current product and if has rent guarantee, add a policy length field
             $product = $self->getProductById($application->getProductId());
             $policyLengthFormModifier($event->getForm(), $product);
         });
         $builder->get('productId')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($self, $policyLengthFormModifier) {
             $productId = $event->getForm()->getData();
             // Get the current product and if has rent guarantee, add a policy length field
             $product = $self->getProductById($productId);
             $policyLengthFormModifier($event->getForm()->getParent(), $product);
         });
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('title', 'choice', array('choices' => Titles::getTitles(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a title')))))->add('firstName', 'text', array('constraints' => array(new Assert\NotBlank(array('message' => 'Please enter first name')), new Assert\Regex(array('pattern' => '/^[-a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('middleName', 'text', array('required' => false, 'constraints' => array(new Assert\Regex(array('pattern' => '/^[ -a-zA-Z0-9\\w]*$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('lastName', 'text', array('constraints' => array(new Assert\NotBlank(array('groups' => array('fullValidation'), 'message' => 'Please enter a last name')), new Assert\Regex(array('pattern' => '/^[ -a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('otherName', 'text', array('required' => false, 'constraints' => array(new Assert\Regex(array('pattern' => '/^[a-zA-Z0-9\\w]*$/', 'message' => 'Please enter alphanumeric characters and spaces only')))))->add('birthDate', 'birthday', array('constraints' => array(new DateRange(array('min' => '-121 YEARS', 'max' => '-18 YEARS', 'maxMessage' => 'Applicant must be older than 18 years of age')))))->add('residentialStatus', 'choice', array('label' => 'Current Residential Status', 'choices' => self::getResidentialStatusChoices(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a current residential status')))))->add('employmentStatus', 'choice', array('label' => 'Current Employment Status', 'choices' => self::getEmploymentStatusChoices(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a current employment status')))))->add('grossIncome', new MoneyWithoutStringTransformerType(), array('label' => 'Total Gross Annual Income', 'currency' => 'GBP', 'constraints' => array(new Assert\GreaterThanOrEqual(array('value' => 0, 'message' => 'Please enter a positive numeric value for share of rent')), new Assert\NotBlank(array('message' => 'Please enter a total gross annual income')), new Assert\Regex(array('pattern' => '/^([0-9]+\\.[0-9]{0,2}|[0-9]+)$/', 'message' => 'Amount must either have 2 decimal places or a whole number, e.g. "15000.00" or "15000"')))))->add('bankAccount', new BankAccountType())->add('phone', 'text', array('label' => 'Telephone Number', 'required' => false, 'constraints' => array(new Assert\Length(array('groups' => 'phone', 'min' => 9, 'minMessage' => 'Please provide at least 9 numeric characters')), new Assert\NotBlank(array('groups' => 'phone', 'message' => 'Please provide a telephone number')), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('mobile', 'text', array('label' => 'Mobile Number', 'required' => false, 'constraints' => array(new Assert\Length(array('groups' => 'mobile', 'min' => 11, 'minMessage' => 'Please provide at least 11 numeric characters')), new Assert\NotBlank(array('groups' => 'mobile', 'message' => 'Please provide a mobile number')), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('email', 'email', array('label' => 'Email Address', 'required' => false, 'constraints' => array(new Assert\Email(array('message' => 'Please provide a valid email address')))))->add('hasCCJ', new BooleanExpandedType(), array('label' => 'Any CCJs or adverse credit history?', 'required' => false));
     $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
         $form = $event->getForm();
         /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\ReferencingApplication $application */
         $application = $event->getData();
         if ($application instanceof ReferencingApplication) {
             // Try to get the product from the application
             $product = $application->getProduct();
             if ($product instanceof Product) {
                 // Modify choices to exclude "Unknown" option on some occasions
                 $residentialStatusChoices = TenantDetailsType::getResidentialStatusChoices();
                 $employmentStatusChoices = TenantDetailsType::getEmploymentStatusChoices();
                 if (!in_array($product->getProductCode(), array('INSG', 'INRG'))) {
                     // Remove the unknown choices
                     unset($residentialStatusChoices[5]);
                 }
                 if (!in_array($product->getProductCode(), array('INSG'))) {
                     // Remove the unknown choices
                     unset($employmentStatusChoices[8]);
                 }
                 $form->add('residentialStatus', 'choice', array('label' => 'Current Residential Status', 'choices' => $residentialStatusChoices, 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a current residential status')))))->add('employmentStatus', 'choice', array('label' => 'Current Employment Status', 'choices' => $employmentStatusChoices, 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a current employment status')))));
                 // Prune unnecessary forms
                 // Only display this field if not Insight and not a guarantor
                 if (in_array($product->getProductCode(), array('INSG'))) {
                     //$form->remove('residentialStatus'); // todo: this causes errors in IRIS validation
                 }
                 // Prune unnecessary forms
                 // Only display this field if not Insight
                 if (in_array($product->getProductCode(), array('INSG'))) {
                     //$form->remove('hasEmploymentChanged'); // todo: this causes errors in IRIS validation
                 }
                 // Prune unnecessary forms
                 // Only display if not credit reference only product
                 if (in_array($product->getProductCode(), array('INSG'))) {
                     $form->remove('grossIncome');
                 }
             }
         }
     })->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         $data = $event->getData();
         $form = $event->getForm();
         if (isset($data['employmentStatus'])) {
             // Remove not blank constraint gross income if student or unemployed
             switch ($data['employmentStatus']) {
                 case 3:
                     // Student
                 // Student
                 case 7:
                     // Unemployed
                     $form->add('grossIncome', new MoneyWithoutStringTransformerType(), array('label' => 'Total Gross Annual Income', 'currency' => 'GBP', 'constraints' => array(new Assert\GreaterThanOrEqual(array('value' => 0, 'message' => 'Please enter a positive numeric value for share of rent')), new Assert\Regex(array('pattern' => '/^([0-9]+\\.[0-9]{0,2}|[0-9]+)$/', 'message' => 'Amount must either have 2 decimal places or a whole number, e.g. "15000.00" or "15000"')))));
                     break;
             }
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // Get the current application
     $currentApplication = \Zend_Registry::get('iris_container')->get('iris.referencing.application.current_form_flow_records')->getApplication();
     $builder->add('title', 'choice', array('choices' => Titles::getTitles(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank(array('message' => 'Please select a title')))))->add('firstName', 'text', array('constraints' => array(new Assert\NotBlank(array('message' => 'Please enter first name')), new Assert\Regex(array('pattern' => '/^[-a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric and spaces only')))))->add('lastName', 'text', array('constraints' => array(new Assert\NotBlank(array('message' => 'Please enter last name')), new Assert\Regex(array('pattern' => '/^[ -a-zA-Z0-9\\w]+$/', 'message' => 'Please enter alphanumeric and spaces only')))))->add('address', new AddressType())->add('dayPhone', 'text', array('label' => 'Telephone (day)', 'constraints' => array(new Assert\Length(array('max' => self::PHONE_NUMBER_MAX_LENGTH)), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('eveningPhone', 'text', array('label' => 'Telephone (evening)', 'constraints' => array(new Assert\Length(array('max' => self::PHONE_NUMBER_MAX_LENGTH)), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('fax', 'text', array('constraints' => array(new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Fax number is invalid')))))->add('email', 'email', array('constraints' => array(new Assert\Email(), new Assert\NotEqualTo(array('value' => $currentApplication->getEmail() ?: 'noemail', 'message' => 'Email must not be the same as tenant contact details')))));
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         $form = $event->getForm();
         $data = $event->getData();
         // If day phone or eve phone don't exist
         if (!$data['dayPhone'] && !$data['eveningPhone']) {
             $form->add('dayPhone', 'text', array('constraints' => array(new Assert\NotBlank(array('message' => LandlordType::PHONE_NOT_BLANK_MESSAGE)), new Assert\Length(array('max' => LandlordType::PHONE_NUMBER_MAX_LENGTH))), 'label' => 'Telephone (day)'))->add('eveningPhone', 'text', array('constraints' => array(new Assert\NotBlank(array('message' => LandlordType::PHONE_NOT_BLANK_MESSAGE)), new Assert\Length(array('max' => LandlordType::PHONE_NUMBER_MAX_LENGTH))), 'label' => 'Telephone (evening)'));
         } elseif (!$data['dayPhone']) {
             $form->add('eveningPhone', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => LandlordType::PHONE_NUMBER_MAX_LENGTH))), 'label' => 'Telephone (evening)'));
         } elseif (!$data['eveningPhone']) {
             $form->add('dayPhone', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => LandlordType::PHONE_NUMBER_MAX_LENGTH))), 'label' => 'Telephone (day)'));
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('title', 'choice', array('choices' => Titles::getTitles(), 'empty_value' => '- Please Select -', 'constraints' => array(new Assert\NotBlank())))->add('firstName', 'text', array('constraints' => array(new Assert\Length(array('min' => 1)), new Assert\NotBlank())))->add('middleName', 'text', array('required' => false))->add('lastName', 'text', array('constraints' => array(new Assert\Length(array('min' => 1)), new Assert\NotBlank())))->add('otherName', 'text', array('required' => false))->add('birthDate', 'birthday')->add('employmentStatus', 'choice', array('label' => 'Current Employment Status', 'choices' => Lookup::getInstance()->getCategoryAsChoices(LookupCategoryOptions::EMPLOYMENT_STATUS), 'empty_value' => '- Please Select -'))->add('grossIncome', new MoneyWithoutStringTransformerType(), array('label' => 'Total Gross Annual Income', 'currency' => 'GBP', 'constraints' => array(new Assert\GreaterThanOrEqual(array('value' => 0)), new Assert\NotNull(array('message' => 'Please confirm the gross annual income')), new Assert\Regex(array('pattern' => '/^([0-9]+\\.[0-9]{0,2}|[0-9]+)$/', 'message' => 'Amount must either have 2 decimal places or a whole number, e.g. "15000.00" or "15000"')))))->add('bankAccount', new BankAccountType(), array())->add('phone', 'text', array('label' => 'Telephone Number', 'required' => false, 'constraints' => array(new Assert\Length(array('groups' => 'phone', 'min' => 9)), new Assert\NotBlank(array('groups' => 'phone')), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('mobile', 'text', array('label' => 'Mobile Number', 'required' => false, 'constraints' => array(new Assert\Length(array('groups' => 'mobile', 'min' => 11)), new Assert\NotBlank(array('groups' => 'mobile')), new Assert\Regex(array('pattern' => '/^[0-9+\\(\\)#\\.\\s\\/ext-]{1,20}+$/', 'message' => 'Phone number is invalid')))))->add('email', 'email', array('label' => 'Email Address', 'required' => false, 'constraints' => array(new Assert\Email(), new Assert\NotBlank())))->add('hasCCJ', 'checkbox', array('label' => 'Any CCJs or adverse credit history?', 'required' => false));
 }