예제 #1
0
파일: CsrfTest.php 프로젝트: nieldm/zf2
 public function testAllowSettingCsrfValidatorOptions()
 {
     $element = new CsrfElement('foo');
     $element->setCsrfValidatorOptions(array('timeout' => 777));
     $validator = $element->getCsrfValidator();
     $this->assertEquals('foo', $validator->getName());
     $this->assertEquals(777, $validator->getTimeout());
 }
예제 #2
0
파일: Zend.php 프로젝트: cityware/city-form
 /**
  * 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);
 }