Beispiel #1
0
 public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes()
 {
     $element = new NumberElement();
     $element->setAttributes(array('inclusive' => true, 'min' => 5, 'max' => 10, 'step' => 1));
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $this->assertInternalType('array', $inputSpec['validators']);
     $expectedClasses = array('Zend\\I18n\\Validator\\Float', 'Zend\\Validator\\GreaterThan', 'Zend\\Validator\\LessThan', 'Zend\\Validator\\Step');
     foreach ($inputSpec['validators'] as $validator) {
         $class = get_class($validator);
         $this->assertTrue(in_array($class, $expectedClasses), $class);
         switch ($class) {
             case 'Zend\\Validator\\GreaterThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals(5, $validator->getMin());
                 break;
             case 'Zend\\Validator\\LessThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals(10, $validator->getMax());
                 break;
             case 'Zend\\Validator\\Step':
                 $this->assertEquals(1, $validator->getStep());
                 break;
             default:
                 break;
         }
     }
 }
Beispiel #2
0
 public function testDefaultInclusiveTrueatValidatorWhenInclusiveIsNotSetOnAttributes()
 {
     $element = new NumberElement();
     $element->setAttributes(array('min' => 5));
     $inputSpec = $element->getInputSpecification();
     foreach ($inputSpec['validators'] as $validator) {
         if (get_class($validator) == 'Zend\\Validator\\GreaterThan') {
             $this->assertTrue($validator->getInclusive());
             break;
         }
     }
 }
Beispiel #3
0
 /**
  * Builds fieldset with additional properties for the "yearly" repeat picker value.
  * It returns the built fieldset (used as a child of the "repeat" fieldset).
  * 
  * @return Fieldset
  */
 public function getRepeatYearlyFieldset()
 {
     $repeatYearlyFieldset = new Fieldset(self::YEARLY);
     $repeatYearlyFieldset->setLabel('Pick date');
     $month = new Element\Select('month');
     $month->setAttributes(array('class' => 'form-control month pull-left', 'autocomplete' => 'off'));
     $month->setValueOptions($this->_monthOptions);
     $repeatYearlyFieldset->add($month);
     $day = new Element\Number('dayOfMonth');
     $day->setValue(1);
     $day->setAttributes(array('class' => 'form-control input-day pull-left', 'autocomplete' => 'off', 'maxlength' => 2, 'min' => 1, 'max' => 31));
     $repeatYearlyFieldset->add($day);
     return $repeatYearlyFieldset;
 }
Beispiel #4
0
 public function __construct(EntityManager $em, OrmRelatorio $orm = null)
 {
     parent::__construct("formRelatorio");
     /*
      * txtID
      */
     $txtId = new Element\Hidden("id");
     /*
      * txtAno
      */
     $option = array();
     $ano = 0;
     if (date("m") >= 9) {
         $ano = 1;
     }
     $ano = $ano + date("Y");
     $option[$ano] = $ano;
     $option[$ano - 1] = $ano - 1;
     $cmbAno = new Element\Select('ano');
     $cmbAno->setValueOptions($option);
     $cmbAno->setEmptyOption("Escolha o ano");
     $cmbAno->setAttributes(array('class' => 'chosen-select', 'style' => 'width:140px;', 'required' => 'true'));
     /*
      * txtMes
      */
     setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
     date_default_timezone_set('America/Sao_Paulo');
     $option = array();
     for ($index = 1; $index < 13; $index++) {
         $option[$index] = strftime("%B", strtotime(date("Y") . "/" . $index . "/01"));
     }
     $cmbMes = new Element\Select('mes');
     $cmbMes->setValueOptions($option);
     $cmbMes->setEmptyOption("Escolha o ano");
     $cmbMes->setAttributes(array('class' => 'chosen-select', 'style' => 'width:140px;', 'required' => 'true'));
     /*
      *  cmbPublicador
      */
     $dao = $em->getRepository('Stj\\Entity\\OrmPublicador');
     $lista = $dao->findAll();
     $option = array();
     foreach ($lista as $key => $value) {
         $congregacao = new OrmCongregacao();
         $congregacao = $value;
         $option[$congregacao->getId()] = $congregacao->getNome();
     }
     $cmbPublicador = new Element\Select('publicador');
     $cmbPublicador->setValueOptions($option);
     $cmbPublicador->setEmptyOption("Escolha o publicador");
     $cmbPublicador->setAttributes(array('class' => 'chosen-select', 'style' => 'width:140px;', 'required' => 'true'));
     /*
      * txtLivros
      */
     $txtPublicacoes = new Element\Number("publicacoes");
     $txtPublicacoes->setAttributes(array('class' => 'form-control', 'placeholder' => 'Quantidade', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+$/', 'data-parsley-maxlength' => "3", 'required' => 'true'));
     /*
      * $txtVideos
      */
     $txtVideos = new Element\Number("videos");
     $txtVideos->setAttributes(array('class' => 'form-control', 'placeholder' => 'Quantidade', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+$/', 'data-parsley-maxlength' => "3", 'required' => 'true'));
     /*
      * $txtPublicacoes
      */
     $txtHoras = new Element\Text("horas");
     $txtHoras->setAttributes(array('class' => 'form-control', 'placeholder' => 'HH:MM', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+\\:[0-9]{2}$/', 'data-parsley-maxlength' => "6", 'required' => 'true'));
     /*
      * txtRevisitas
      */
     $txtRevisitas = new Element\Number("revisitas");
     $txtRevisitas->setAttributes(array('class' => 'form-control', 'placeholder' => 'Quantidade', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+$/', 'data-parsley-maxlength' => "2", 'required' => 'true'));
     /*
      * txtEstudos
      */
     $txtEstudos = new Element\Number("estudos");
     $txtEstudos->setAttributes(array('class' => 'form-control', 'placeholder' => 'Quantidade', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+$/', 'data-parsley-maxlength' => "2", 'required' => 'true'));
     /*
      *  txtObs
      */
     $txtObs = new Element\Textarea("obs");
     $txtObs->setAttributes(array('class' => 'form-control', 'placeholder' => 'Digites suas observações aqui'));
     /*
      * Itoken
      */
     $iToken = new Element\Csrf("iToken");
     /*
      * btnSalvar
      */
     $btnSalvar = new Element\Button('salvar');
     $btnSalvar->setAttributes(array('class' => 'btn btn-darkgray btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
     /*
      * btnVoltar
      */
     $btnVoltar = new Element\Button('voltar');
     $btnVoltar->setAttributes(array('class' => 'btn btn-blue btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
     /*
      * Preencher Componentes
      */
     if ($orm != null) {
         $txtId->setValue($orm->getId());
         $cmbAno->setValue($orm->getAno());
         $cmbMes->setValue($orm->getMes());
         $cmbPublicador->setValue($orm->getPublicador()->getId());
         $txtPublicacoes->setValue($orm->getPublicacoes());
         $txtVideos->setValue($orm->getVideos());
         $txtHoras->setValue($orm->getHoras());
         $txtRevisitas->setValue($orm->getRevisitas());
         $txtEstudos->setValue($orm->getEstudos());
     }
     // Adiciona componetes no form
     $this->add($txtId);
     //        $this->add();
     $this->add($cmbAno);
     $this->add($cmbMes);
     $this->add($cmbPublicador);
     $this->add($txtPublicacoes);
     $this->add($txtVideos);
     $this->add($txtHoras);
     $this->add($txtRevisitas);
     $this->add($txtEstudos);
     $this->add($txtObs);
     $this->add($iToken);
     $this->add($btnSalvar);
     $this->add($btnVoltar);
     $this->setAttributes(array('id' => 'form', 'data-parsley-validate' => NULL));
 }
Beispiel #5
0
 public function buildForm()
 {
     $this->setAttributes(array('id' => 'post-form', 'method' => 'post'));
     $category = new Element\Select('category');
     $category->setLabel('Categoria');
     $category->setValueOptions(array_combine($this->categories, $this->categories));
     $category->setAttribute('class', 'form-control');
     $title = new Element\Text('title');
     $title->setLabel('Título');
     $title->setAttributes(array('maxlength' => 128, 'class' => 'form-control'));
     $description = new Element\Textarea('description');
     $description->setAttribute('class', 'form-control');
     $description->setLabel('Descrição');
     $photoFilename = new Element\Url('photo_filename');
     $photoFilename->setAttribute('class', 'form-control');
     $photoFilename->setLabel('Foto');
     $contactName = new Element\Text('contact_name');
     $contactName->setAttribute('class', 'form-control');
     $contactName->setLabel('Nome completo');
     $contactEmail = new Element\Email('contact_email');
     $contactEmail->setAttribute('class', 'form-control');
     $contactEmail->setLabel('E-mail');
     $contactPhone = new Element\Text('contact_phone');
     $contactPhone->setAttribute('class', 'form-control');
     $contactPhone->setLabel('Contato');
     $cityCode = new Element\Select('cityCode');
     $cityCode->setAttribute('class', 'form-control');
     $cityCode->setValueOptions($this->cities);
     $cityCode->setLabel('Cidade');
     $deleteCode = new Element\Number('delete_code');
     $deleteCode->setAttribute('class', 'form-control');
     $deleteCode->setLabel('Código de deleção');
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new ImageCaptcha(array('font' => './public/fonts/arial.ttf', 'imgDir' => './public/img/captcha', 'imgUrl' => '/img/captcha'));
     $captchaAdapter->setWordlen(4);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Você é um ser humano ou um robô?')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Você é um ser humano ou um robô?');
     /*$captcha = new Element\Captcha('captcha');
             $captcha->setCaptcha(new \Zend\Captcha\Dumb());
             $captcha->setAttribute('class', 'form-control');
             $captcha->setOptions(array('label' => 'Você é um ser humano ou um robô?'));
     */
     $price = new Element\Number('price');
     $price->setAttributes(array('class' => 'form-control', 'maxlength' => 12, 'min' => 0, 'max' => '999999999999'));
     $price->setLabel('Preço');
     $dateExpires = new Element\Radio('date_expires');
     $dateExpires->setLabel('Expira em (dias)');
     $dateExpires->setValueOptions(array_combine($this->dateExpires, $this->dateExpires));
     $csrf = new Element\Csrf('security');
     $submit = new Element\Submit('submit');
     $submit->setAttributes(array('class' => 'btn btn-default', 'value' => 'Enviar formulário'));
     $this->add($category)->add($title)->add($price)->add($dateExpires)->add($description)->add($photoFilename)->add($contactName)->add($contactEmail)->add($contactPhone)->add($cityCode)->add($deleteCode)->add($captcha)->add($csrf)->add($submit);
     /*
             $factory = new \Zend\Form\Factory();
             $factory->createForm(array(
                 'hydrator' => 'Zend\Stdlib\Hydrator\ArraySerializable',
                 'elements' => array(
                     array(
                         'name' => 'category',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Category'
                         )
                     ),
                     array(
                         'name' => 'title',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Title'
                         )
                     ),
                 )
             )); */
 }