Exemplo n.º 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;
         }
     }
 }
Exemplo n.º 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;
         }
     }
 }
 public function getForm(array $currencies, array $companies, array $contacts, array $statusList)
 {
     if (!$this->form) {
         $hidId = new Element\Hidden();
         $hidId->setName('proposalId');
         $txtCompanyId = new Element\Select();
         $txtCompanyId->setLabel('Company Name')->setName("companyId")->setAttribute('class', 'form-control')->setEmptyOption("--Choose Company--")->setValueOptions($companies);
         $txtContactId = new Element\Select();
         $txtContactId->setLabel('Contact Name')->setName('contactId')->setAttribute('class', 'form-control')->setEmptyOption("--Choose Contact--")->setValueOptions($contacts);
         $txtCode = new Element\Text();
         $txtCode->setLabel('Code')->setName('code')->setAttribute('class', 'form-control');
         $txtName = new Element\Text();
         $txtName->setLabel('Name')->setName('name')->setAttribute('class', 'form-control');
         $txtAmount = new Element\Number();
         $txtAmount->setName("amount")->setLabel('Amount')->setAttribute('class', 'form-control')->setAttributes(array('min' => '100', 'max' => '99999999999', 'step' => '100'));
         $selectCurrency = new Element\Select();
         $selectCurrency->setName('currencyId')->setLabel('Currency')->setAttribute('class', 'form-control')->setValueOptions($currencies);
         $txtProposalDate = new Element\Date('proposalDate');
         $txtProposalDate->setLabel('Date')->setAttributes(array('class' => 'form-control', 'allowPastDates' => true, 'momentConfig' => array('format' => 'YYYY-MM-DD')));
         $txtProposalFile = new Element\File();
         $txtProposalFile->setName('proposalFile')->setLabel('Upload file');
         $txtNodes = new Element\Textarea();
         $txtNodes->setLabel('Notes')->setName('notes')->setAttribute('class', 'form-control');
         $txtProposalBy = new Element\Text();
         $txtProposalBy->setName('proposalBy')->setLabel('Proposal By')->setAttribute('class', 'form-control');
         $txtGroupCode = new Element\Text();
         $txtGroupCode->setLabel('Group Code')->setName('group_code')->setAttribute('class', 'form-control');
         $txtStatus = new Element\Select();
         $txtStatus->setName('status')->setLabel('Status')->setAttribute('class', 'form-control')->setValueOptions($statusList);
         $form = new Form();
         $form->setAttribute('class', 'form-horizontal');
         $form->setAttribute('enctype', 'multipart/form-data');
         $form->add($hidId);
         $form->add($txtCompanyId);
         $form->add($txtContactId);
         $form->add($txtCode);
         $form->add($txtName);
         $form->add($txtAmount);
         $form->add($selectCurrency);
         $form->add($txtProposalDate);
         $form->add($txtProposalFile);
         $form->add($txtNodes);
         $form->add($txtProposalBy);
         $form->add($txtGroupCode);
         $form->add($txtStatus);
         $this->form = $form;
     }
     return $this->form;
 }
Exemplo n.º 4
0
 public function getForm(array $usersData, array $positionsData, array $currencyData, array $defaultStatus)
 {
     if (!$this->form) {
         $hidId = new Element\Hidden();
         $hidId->setName('staffId');
         $selectUsers = new Element\Select();
         $selectUsers->setName('userId')->setLabel('User')->setAttribute('class', 'form-control')->setEmptyOption("--Choose User --")->setValueOptions($usersData);
         $staffCode = new Element\Text();
         $staffCode->setLabel('Code')->setName("staffCode")->setAttribute('class', 'form-control');
         $staffName = new Element\Text();
         $staffName->setLabel('Name')->setName("staffName")->setAttribute('class', 'form-control');
         $selectPosition = new Element\Select();
         $selectPosition->setName('positionId')->setLabel('Position')->setAttribute('class', 'form-control')->setEmptyOption("-- Choose Position --")->setValueOptions($positionsData);
         $selectDepartment = new Element\Hidden('departmentId');
         $salary = new Element\Number();
         $salary->setLabel('Salary')->setName("salary")->setAttributes(array('min' => '0', 'max' => '999999999999', 'step' => '1'));
         $leave = new Element\Number();
         $leave->setLabel('Leave')->setName("annual_leave")->setAttributes(array('min' => '0.5', 'max' => '100', 'step' => '0.5'));
         $PermanentDate = new Element\Date('permanentDate');
         $PermanentDate->setLabel('P-Date')->setAttributes(array('allowPastDates' => true, 'momentConfig' => array('format' => 'YYYY-MM-DD')));
         $birthDay = new Element\Date('birthday');
         $birthDay->setLabel('Birthday')->setAttributes(array('allowPastDates' => true, 'momentConfig' => array('format' => 'YYYY-MM-DD')));
         $selectCurrency = new Element\Select();
         $selectCurrency->setName('currencyId')->setAttribute('class', 'form-control')->setValueOptions($currencyData);
         $status = new Element\Select();
         $status->setName('status')->setLabel('Status')->setAttribute('class', 'form-control')->setValueOptions($defaultStatus);
         $bankCode = new Element\Text('bankCode');
         $bankCode->setLabel('Bank Account')->setAttributes(array('class' => 'form-control', 'placeholder' => 'Aya Bank Account No'));
         $form = new Form();
         $form->setAttribute('class', 'form-horizontal');
         $form->add($hidId);
         $form->add($selectUsers);
         $form->add($staffCode);
         $form->add($staffName);
         $form->add($selectPosition);
         $form->add($selectDepartment);
         $form->add($salary);
         $form->add($leave);
         $form->add($PermanentDate);
         $form->add($status);
         $form->add($birthDay);
         $form->add($selectCurrency);
         $form->add($bankCode);
         $this->form = $form;
     }
     return $this->form;
 }
Exemplo n.º 5
0
 /**
  * Add Currency formatted number filter
  * @see Zend\Form\Element\Number
  * @return array
  */
 public function getInputSpecification()
 {
     $inputSpec = parent::getInputSpecification();
     //FILTHY HACK
     //CLEAN THIS UP
     $inputSpec['filters'][] = array('name' => 'Callback', 'options' => array('callback' => function ($value) {
         $value = str_replace(',', '', $value);
         return floatval($value);
     }));
     $inputSpec['filters'][] = array('name' => 'NumberFormat', 'style' => NumberFormatter::CURRENCY, 'type' => NumberFormatter::TYPE_CURRENCY);
     return $inputSpec;
 }
 public function getForm(array $currencies)
 {
     if (!$this->form) {
         $hidId = new Element\Hidden();
         $hidId->setName('receiveVoucherId');
         $txtVoucherNo = new Element\Text();
         $txtVoucherNo->setLabel('Number')->setName("voucherNo")->setAttribute('class', 'form-control text-center')->setAttribute('readonly', 'readonly');
         $txtVoucherDate = new Element\Date('voucherDate');
         $txtVoucherDate->setLabel('Date')->setAttributes(array('class' => 'form-control', 'allowPastDates' => true, 'momentConfig' => array('format' => 'YYYY-MM-DD')));
         $txtAccountType = new Element\Hidden('accountType');
         $txtDescription = new Element\Textarea();
         $txtDescription->setName("description")->setLabel('Description')->setAttribute('class', 'form-control');
         $txtAmount = new Element\Number();
         $txtAmount->setName("amount")->setLabel('Amount')->setAttribute('class', 'form-control')->setattributes(array('min' => '10', 'max' => '99999999999', 'step' => '1'));
         $cboCurrency = new Element\Select();
         $cboCurrency->setName('currencyId')->setLabel('Currency Type')->setAttribute('class', 'form-control')->setEmptyOption('-- Choose --')->setValueOptions($currencies);
         $txtDepositBy = new Element\Hidden();
         $txtDepositBy->setName("depositBy");
         $txtReason = new Element\Textarea();
         $txtReason->setName('reason');
         $txtGroupCode = new Element\Text();
         $txtGroupCode->setName('group_code')->setLabel('Group Code (optional)')->setAttribute('class', 'form-control');
         $form = new Form();
         $form->setAttribute('role', 'form');
         $form->add($hidId);
         $form->add($txtVoucherNo);
         $form->add($txtVoucherDate);
         $form->add($txtAccountType);
         $form->add($txtDescription);
         $form->add($txtAmount);
         $form->add($cboCurrency);
         $form->add($txtDepositBy);
         $form->add($txtReason);
         $form->add($txtGroupCode);
         $this->form = $form;
     }
     return $this->form;
 }
Exemplo n.º 7
0
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $inputSpec = parent::getInputSpecification();
     $inputSpec['allow_empty'] = true;
     return $inputSpec;
 }
Exemplo n.º 8
0
 public function addElements()
 {
     $id = new Element\Text('id');
     $id->setLabel('ID')->setAttribute('class', 'form-control')->setAttribute('type', 'hidden');
     $this->add($id);
     $rating = new Element\Number('rating');
     $rating->setLabel('Rating .Max = 5 (Good) , Min=0 (no rating)')->setAttribute('class', 'form-control')->setAttribute('type', 'hidden');
     $this->add($rating);
     $name = new Element\Text('name');
     $name->setLabel('Lazada name')->setAttribute('class', 'form-control')->setAttribute('required', 'true')->setAttribute('onchange', 'get_alias();')->setAttribute('id', 'name');
     $this->add($name);
     $alias = new Element\Text('alias');
     $alias->setLabel('Lazada alias')->setAttribute('required', 'true')->setAttribute('class', 'form-control')->setAttribute('id', 'alias');
     $this->add($alias);
     $availability = new Element\Number('availability');
     $availability->setLabel('Availability')->setAttribute('class', 'form-control')->setAttribute('required', 'true')->setAttribute('id', 'availability');
     $this->add($availability);
     $descripts = new Element\Textarea('description');
     $descripts->setLabel('Description short')->setAttribute('class', 'form-control')->setAttribute('id', 'descripts');
     $this->add($descripts);
     $description = new Element\Textarea('detail_product');
     $description->setLabel('Detail Lazada')->setAttribute('class', 'form-control')->setAttribute('id', 'detail_product');
     $this->add($description);
     $hot = new Element\Radio('hot');
     $hot->setLabel('Choice hot')->setValueOptions(array('0' => 'No Hot', '1' => 'Hot'))->setAttribute('id', 'hot');
     $this->add($hot);
     $promotions = new Element\Number('promotions');
     $promotions->setLabel('Promotions')->setAttribute('class', 'form-control')->setAttribute('id', 'promotions');
     $this->add($promotions);
     $new = new Element\Radio('new');
     $new->setLabel('Choice new')->setValueOptions(array('0' => 'No New', '1' => 'New'))->setAttribute('id', 'new');
     $this->add($new);
     $status = new Element\Radio('status');
     $status->setLabel('status')->setAttribute('required', 'true')->setValueOptions(array('0' => 'Pause', '1' => 'Active'))->setAttribute('id', 'status');
     $this->add($status);
     $about_price = new Element\Number('about_price');
     $about_price->setLabel('About Price')->setAttribute('class', 'form-control')->setAttribute('id', 'about_price');
     $this->add($about_price);
     $weekly_featured = new Element\Radio('weekly_featured');
     $weekly_featured->setLabel('Weekly featured')->setValueOptions(array('0' => 'No', '1' => 'Yes'))->setAttribute('id', 'weekly_featured');
     $this->add($weekly_featured);
     $featured_products = new Element\Radio('featured_products');
     $featured_products->setLabel('Featured Lazadas')->setValueOptions(array('0' => 'No', '1' => 'Yes'))->setAttribute('id', 'featured_products');
     $this->add($featured_products);
     $new_products = new Element\Radio('new_products');
     $new_products->setLabel('New Lazadas')->setValueOptions(array('0' => 'No', '1' => 'Yes'))->setAttribute('id', 'new_products');
     $this->add($new_products);
     $sale_products = new Element\Radio('sale_products');
     $sale_products->setLabel('Sale Lazadas')->setValueOptions(array('0' => 'No', '1' => 'Yes'))->setAttribute('id', 'sale_products');
     $this->add($sale_products);
     $img = new Element\File('img');
     $img->setLabel('file img (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img');
     $this->add($img);
     $img1 = new Element\File('img1');
     $img1->setLabel('file img1 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img1');
     $this->add($img1);
     $img2 = new Element\File('img2');
     $img2->setLabel('file img2 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img2');
     $this->add($img2);
     $img3 = new Element\File('img3');
     $img3->setLabel('file img3 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img3');
     $this->add($img3);
     $img4 = new Element\File('img4');
     $img4->setLabel('file img4 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img4');
     $this->add($img4);
     $img5 = new Element\File('img5');
     $img5->setLabel('file img5 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img5');
     $this->add($img5);
     $img6 = new Element\File('img6');
     $img6->setLabel('file img6 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img6');
     $this->add($img6);
     $img7 = new Element\File('img7');
     $img7->setLabel('file img7 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img7');
     $this->add($img7);
     $img8 = new Element\File('img8');
     $img8->setLabel('file img8 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img8');
     $this->add($img8);
     $img9 = new Element\File('img9');
     $img9->setLabel('file img9 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img9');
     $this->add($img9);
     $img10 = new Element\File('img10');
     $img10->setLabel('file img10 (* not support .png , .gif)')->setAttribute('class', 'form-control')->setAttribute('type', 'file')->setAttribute('accept', '.jpg, .jpeg, .JPG, .JPEG')->setAttribute('id', 'img10');
     $this->add($img10);
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
 public function __construct(ObjectManager $objectManager)
 {
     parent::__construct('register');
     $this->filter = new InputFilter();
     $primary = new Element\Hidden('primary');
     $this->add($primary);
     $callName = new Element\Text('callName');
     $callName->setAttribute('required', true);
     $callName->setAttribute('placeholder', 'Call Name');
     $this->add($callName);
     $callNameFilter = new Input('callName');
     $callNameFilter->setRequired(true);
     $callNameFilter->getFilterChain()->attach(new AppFilter\TitleCase());
     $callNameFilter->getFilterChain()->attach(new Filter\StringTrim());
     $callNameFilter->getFilterChain()->attach(new Filter\StripTags());
     $callNameFilter->getValidatorChain()->attach(new Validator\StringLength(array('max' => 15)));
     $callNameFilter->getValidatorChain()->attach(new LocaleValidator\Alpha(array('allowWhiteSpace' => true)));
     $this->filter->add($callNameFilter);
     $regName = new Element\Text('regName');
     $regName->setAttribute('placeholder', 'Registered Name');
     $this->add($regName);
     $regNameFilter = new Input('regName');
     $regNameFilter->setRequired(false);
     $regNameFilter->getFilterChain()->attach(new AppFilter\TitleCase());
     $regNameFilter->getFilterChain()->attach(new Filter\StringTrim());
     $regNameFilter->getFilterChain()->attach(new Filter\StripTags());
     $regNameFilter->getValidatorChain()->attach(new Validator\StringLength(array('max' => 50)));
     $regNameFilter->getValidatorChain()->attach(new Validator\Regex("/^[a-z][a-z\\'\\- ]*\$/i"));
     $this->filter->add($regNameFilter);
     $sex = new Element\Select('sex');
     $sex->setAttribute('required', true);
     $sex->setValueOptions(array(1 => 'Male', 2 => 'Female'));
     $sex->setEmptyOption('Select a Sex');
     $this->add($sex);
     $sexFilter = new Input('sex');
     $sexFilter->setRequired(true);
     $this->filter->add($sexFilter);
     $breed = new AppElement\ObjectLiveSearch('breed');
     $breed->setOption('object_manager', $objectManager);
     $breed->setOption('target_class', 'Application\\Entity\\Breed');
     $breed->setOption('find_method', array('name' => 'findBy', 'params' => array('criteria' => array(), 'orderBy' => array('name' => 'ASC'))));
     $breed->setEmptyOption('Select a Breed');
     $this->add($breed);
     $breedFilter = new Input('breed');
     $breedFilter->setRequired(true);
     $this->filter->add($breedFilter);
     $dateOfBirth = new Element\Date('dateOfBirth');
     $dateOfBirth->setAttribute('required', true);
     $dateOfBirth->setAttribute('data-placeholder', 'Date of Birth');
     // placeholder attr is invalid for date input
     $dateOfBirth->setAttribute('data-mask', '0000-00-00');
     $dateOfBirth->setAttribute('class', 'datepicker');
     $this->add($dateOfBirth);
     $dateOfBirthFilter = new Input('dateOfBirth');
     $dateOfBirthFilter->setRequired(true);
     $dateOfBirthFilter->getValidatorChain()->attach(new Validator\Date());
     $this->filter->add($dateOfBirthFilter);
     $height = new Element\Number('height');
     $height->setAttribute('required', true);
     $height->setAttribute('placeholder', 'Height (Inches)');
     $this->add($height);
     $heightFilter = new Input('height');
     $heightFilter->setRequired(true);
     $heightFilter->getValidatorChain()->attach(new Validator\Between(array('min' => 6, 'max' => 30)));
     $this->filter->add($heightFilter);
     $champion = new Element\Checkbox('champion');
     $champion->setLabel('Dog is a champion of record.');
     $this->add($champion);
     $championFilter = new Input('champion');
     $championFilter->setRequired(false);
     $this->filter->add($championFilter);
     $rescue = new Element\Checkbox('rescue');
     $rescue->setLabel('Dog is a rescue.');
     $this->add($rescue);
     $rescueFilter = new Input('rescue');
     $rescueFilter->setRequired(false);
     $this->filter->add($rescueFilter);
     $buttons = new Form('buttons');
     $buttons->setOption('twb-layout', 'inline');
     $buttons->setAttribute('class', 'form-group');
     $submit = new Element\Submit('submit');
     $submit->setAttribute('class', 'btn-primary pull-right');
     $submit->setOption('glyphicon', 'circle-arrow-up');
     $submit->setLabel('Register');
     $buttons->add($submit);
     $cancel = new Element\Submit('cancel');
     $cancel->setAttribute('formnovalidate', true);
     $cancel->setAttribute('class', 'btn-warning pull-right');
     $cancel->setOption('glyphicon', 'ban-circle');
     $cancel->setLabel('Cancel');
     $buttons->add($cancel);
     $this->add($buttons);
 }
Exemplo n.º 11
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));
 }
Exemplo n.º 12
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'
                         )
                     ),
                 )
             )); */
 }
Exemplo n.º 13
0
 /**
  * Prepara os campos do formulário
  * @param  string    $fieldName
  * @param  array     $fieldParams
  * @param  array     $options
  * @return object
  * @throws Exception
  */
 private function prepareFields($fieldName, array $fieldParams, array $options = array())
 {
     $element = null;
     $extraLabel = " ";
     $this->aOptions = array();
     $this->aAttributes = array();
     /* Define o tooltip do campo */
     $tooltip = (isset($fieldParams['tooltip']) and $fieldParams['tooltip'] == 'true') ? "<a class=\"tooltip-marc\" href=\"#\" data-toggle=\"tooltip\" title=\"{$this->getTranslator($fieldName . '_tooltip')}\">[?]</a>" : null;
     $this->aOptions['tooltip'] = $tooltip;
     /* Define como será mostrado o nome do campo (se é obrigatório ou não) */
     if (strtolower($fieldParams['type']) != 'hidden') {
         if (isset($fieldParams['validation']) and stristr(strtolower($fieldParams['validation']), "required")) {
             $extraLabel = " * ";
         }
     }
     switch (strtolower($fieldParams['type'])) {
         /* Caso hidden */
         case 'primary':
         case 'hidden':
             $element = new ZendFormElement\Hidden($fieldName);
             break;
             /* Caso Csrf */
         /* Caso Csrf */
         case 'csrf':
         case 'sec':
             $element = new ZendFormElement\Csrf($fieldName);
             $element->setCsrfValidatorOptions(array('timeout' => '600'));
             break;
             /* Caso text */
         /* Caso text */
         case 'text':
             $element = new ZendFormElement\Text($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso textarea */
         /* Caso textarea */
         case 'textarea':
             $element = new ZendFormElement\Textarea($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             /* Define os padrões de colunas e linhas do campo */
             $this->aAttributes['rows'] = (isset($fieldParams['rows']) and !empty($fieldParams['rows'])) ? $fieldParams['rows'] : 5;
             $this->aAttributes['cols'] = (isset($fieldParams['cols']) and !empty($fieldParams['cols'])) ? $fieldParams['cols'] : 10;
             $this->aAttributes['class'] = 'form-input';
             $this->aAttributes['data-editor'] = 'false';
             break;
             /* Caso editor */
         /* Caso editor */
         case 'editor':
             $element = new ZendFormElement\Textarea($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             /* Define os padrões de colunas e linhas do campo */
             $this->aAttributes['rows'] = (isset($fieldParams['rows']) and !empty($fieldParams['rows'])) ? $fieldParams['rows'] : 5;
             $this->aAttributes['cols'] = (isset($fieldParams['cols']) and !empty($fieldParams['cols'])) ? $fieldParams['cols'] : 10;
             /* Verifica se utilizará o editor */
             $this->aAttributes['class'] = 'editorw';
             $this->aAttributes['data-editor'] = 'true';
             /* Verifica a pasta de upload */
             if (isset($this->formDefaultConfig['destination']) and !empty($this->formDefaultConfig['destination'])) {
                 /* Caso não exista a pasta cria o mesmo */
                 if (!is_dir(UPLOAD_PATH . $this->formDefaultConfig['destination'])) {
                     mkdir(UPLOAD_PATH . $this->formDefaultConfig['destination'], 0777, true);
                     chmod(UPLOAD_PATH . $this->formDefaultConfig['destination'], 0777);
                 }
                 $_SESSION['KCFINDER'] = array();
                 $_SESSION['KCFINDER']['disabled'] = false;
                 $_SESSION['KCFINDER']['uploadURL'] = URL_UPLOAD . $this->formDefaultConfig['destination'];
                 $_SESSION['KCFINDER']['uploadDir'] = UPLOAD_PATH . $this->formDefaultConfig['destination'];
             } else {
                 throw new \Exception('Defina a pasta de destino de upload das imagens do editor!', 500);
             }
             break;
             /* Caso password */
         /* Caso password */
         case 'password':
             $element = new ZendFormElement\Password($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['renderPassword'] = true;
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso radio */
         /* Caso radio */
         case 'radio':
             $element = new ZendFormElement\Radio($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'radio';
             break;
             /* Caso checkbox */
         /* Caso checkbox */
         case 'checkbox':
             $element = new ZendFormElement\Checkbox($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $element->setUncheckedValue(null);
             $this->aAttributes['class'] = 'checkbox';
             break;
             /* Caso multicheckbox */
         /* Caso multicheckbox */
         case 'multicheckbox':
             $element = new ZendFormElement\MultiCheckbox($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $element->setUncheckedValue(null);
             break;
             /* Caso select */
         /* Caso select */
         case 'select':
             $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true));
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->selectOptions = array();
             if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') {
                 $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder');
             } else {
                 $this->selectOptions[''] = "---------";
             }
             $this->aAttributes['class'] = 'form-input-select';
             break;
             /* Caso selectgroup */
         /* Caso selectgroup */
         case 'selectgroup':
             $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true));
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->selectOptions = array();
             if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') {
                 $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder');
             } else {
                 $this->selectOptions[''] = "---------";
             }
             $this->aAttributes['class'] = 'form-input-select';
             break;
             /* Caso multiselect */
         /* Caso multiselect */
         case 'multiselect':
             $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true));
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input-select ms';
             $this->aAttributes['multiple'] = 'multiple';
             break;
             /* Caso fileimage */
         /* Caso fileimage */
         case 'fileimage':
             $element = new ZendFormElement\File($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             //$this->aAttributes['multiple'] = true;
             $this->aAttributes['class'] = 'hiddenImageFile';
             /* Verifica a pasta de upload */
             if (isset($this->formDefaultConfig['pathfiles']) and !empty($this->formDefaultConfig['pathfiles'])) {
                 /* Caso não exista a pasta cria o mesmo */
                 if (!is_dir(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'])) {
                     mkdir(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'], 0777, true);
                     chmod(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'], 0777);
                 }
                 $this->aAttributes['data-path'] = LINK_DEFAULT . 'uploads/' . $this->formDefaultConfig['pathfiles'];
             } else {
                 throw new \Exception('Defina a pasta de destino de upload das imagens do editor!', 500);
             }
             break;
             /* Caso file */
         /* Caso file */
         case 'file':
             $element = new ZendFormElement\File($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             break;
         case 'money':
             $element = new ZendFormElement\Text($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input';
             break;
             /* HTML5 Elements */
             /* Caso url */
         /* HTML5 Elements */
         /* Caso url */
         case 'url':
             $element = new ZendFormElement\Url($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso date */
         /* Caso date */
         case 'date':
             $element = new ZendFormElement\Date($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['min'] = date("Y") - 10 . '-01-01';
             $this->aAttributes['max'] = date("Y") + 10 . '-12-31';
             $this->aAttributes['class'] = 'form-input';
             break;
         case 'dateage':
             $element = new ZendFormElement\Date($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['min'] = date("Y") - 100 . '-01-01';
             $this->aAttributes['max'] = date("Y") + 100 . '-12-31';
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso time */
         /* Caso time */
         case 'time':
             $element = new ZendFormElement\DateTime($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input';
             $this->aAttributes['min'] = '00:00:00';
             $this->aAttributes['max'] = '23:59:59';
             $this->aOptions['format'] = 'H:i:s';
             break;
             /* Caso date */
         /* Caso date */
         case 'datetime':
             $element = new ZendFormElement\DateTime($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['min'] = date("Y") - 10 . '-01-01 00:00:00';
             $this->aAttributes['max'] = date("Y") + 10 . '-12-31 23:59:59';
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso email */
         /* Caso email */
         case 'email':
             $element = new ZendFormElement\Email($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Caso number */
         /* Caso number */
         case 'number':
             $element = new ZendFormElement\Number($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['step'] = '1';
             $this->aAttributes['class'] = 'form-input';
             break;
         case 'integer':
             $element = new ZendFormElement\Number($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['min'] = '0';
             $this->aAttributes['max'] = '99999999999999999999';
             $this->aAttributes['step'] = '1';
             $this->aAttributes['class'] = 'form-input';
             break;
         case 'float':
             $element = new ZendFormElement\Number($fieldName);
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             $this->aAttributes['step'] = '0.001';
             $this->aAttributes['class'] = 'form-input';
             break;
             /* Plataforma */
             /* Caso select */
         /* Plataforma */
         /* Caso select */
         case 'status':
             $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true));
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') {
                 $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder');
             } else {
                 $this->selectOptions[''] = "---------";
             }
             $this->aAttributes['class'] = 'form-input-select';
             break;
             /* Caso boolean */
         /* Caso boolean */
         case 'boolean':
             $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true));
             $element->setLabel($this->getTranslator($fieldName) . $extraLabel);
             if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') {
                 $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder');
             } else {
                 $this->selectOptions[''] = "---------";
             }
             $this->aAttributes['class'] = 'form-input-select';
             break;
     }
     /* Verifica se foi setado classe de estilo e implementa */
     if (isset($fieldParams['class']) and !empty($fieldParams['class'])) {
         if (isset($this->aAttributes['class']) and $this->aAttributes['class'] != "") {
             $this->aAttributes['class'] = $this->aAttributes['class'] . " " . $fieldParams['class'];
         } else {
             $this->aAttributes['class'] = $fieldParams['class'];
         }
     }
     /* Define a descrição abaixo do campo */
     if (isset($fieldParams['description']) and $fieldParams['description'] == 'true') {
         $this->aOptions['help-block'] = $this->getTranslator($fieldName . '_description');
     }
     /* Verifica se foi setado grupo do campo e implementa */
     if (isset($fieldParams['group']) and !empty($fieldParams['group'])) {
         $this->aOptions['group'] = $fieldParams['group'];
     }
     /* Verifica se foi setado placeholder no campo e implementa */
     if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') {
         $this->aAttributes['placeholder'] = $this->getTranslator($fieldName . '_placeholder');
     }
     /* Verifica se foi setado somente leitura e implementa */
     if (isset($fieldParams['readonly']) and strtolower($fieldParams['readonly']) == 'true') {
         $this->aAttributes['readonly'] = 'readonly';
     }
     /* Verifica se foi setado desabilitado e implementa */
     if (isset($fieldParams['disabled']) and strtolower($fieldParams['disabled']) == 'true') {
         $this->aAttributes['disabled'] = true;
     }
     /* Verifica se utilizará mascara no campo */
     if (isset($fieldParams['mask']) and !empty($fieldParams['mask'])) {
         $this->aAttributes['data-inputmask'] = $fieldParams['mask'];
     }
     /* Verifica se foi setado inputgroup tipo append e implementa */
     if (isset($fieldParams['groupappend']) and !empty($fieldParams['groupappend'])) {
         $this->aOptions['add-on-append'] = $fieldParams['groupappend'];
     }
     /* Verifica se foi setado inputgroup tipo prepend e implementa */
     if (isset($fieldParams['groupprepend']) and !empty($fieldParams['groupprepend'])) {
         $this->aOptions['add-on-prepend'] = $fieldParams['groupprepend'];
     }
     /* Verifica se foi setado como array e implementa */
     if (isset($fieldParams['array']) and strtolower($fieldParams['array']) == 'true') {
         $this->aOptions['disable_inarray_validator'] = false;
     }
     if (strtolower($fieldParams['type']) !== 'checkbox' and strtolower($fieldParams['type']) !== 'button') {
         if (strtolower($fieldParams['type']) !== 'textarea' and strtolower($fieldParams['type']) !== 'editor') {
             //$this->aOptions['column-size'] = 'col4';
         } else {
             //$this->aOptions['column-size'] = 'col6';
         }
         $this->aOptions['labelattributes'] = array('class' => 'form-label');
     } else {
         //$this->aOptions['column-size'] = 'col6 col-sm-offset-2';
         unset($this->aOptions['labelattributes']);
     }
     return array('element' => $element, 'params' => $fieldParams);
 }