Пример #1
0
 /**
  * Valida las variables de un objeto o de un array en base a una definicion de configuracion de validacion
  * Se puede utilizar la libreria que se desee pere debe respetar la inerfaz de la proporcionada por el framework.
  * @param type $var
  * @param string $lib
  * @param string $locale
  * @return bool
  */
 protected function validate($var, $locale = NULL, $lib = '\\Enola\\Lib\\Validation')
 {
     $validacion = new $lib($locale);
     $reglas = $this->configValidation();
     if (is_object($var)) {
         $reflection = new Reflection($var);
         foreach ($reglas as $key => $regla) {
             $validacion->add_rule($key, $reflection->getProperty($key), $regla);
         }
     } else {
         foreach ($reglas as $key => $regla) {
             $validacion->add_rule($key, $var[$key], $regla);
         }
     }
     if (!$validacion->validate()) {
         //Consigo los errores y retorno FALSE
         $this->errors = $validacion->error_messages();
         return FALSE;
     } else {
         return TRUE;
     }
 }
Пример #2
0
 public function selectFull($simple, $label, $id, $name, $value, $options, $varLabel = 0, $varValue = 1, $defaultLabel = NULL, $defaultValue = NULL, $onchange = NULL, $multiple = FALSE, $message = NULL, $typeError = NULL, $size = 'md')
 {
     $form = 'select';
     if ($simple) {
         $form = 'select_simple';
     }
     $valores = array('config.seccion' => 'cabecera', 'config.label' => $label, 'config.id' => $id, 'config.name' => $name, 'config.onchange' => $onchange, 'config.multiple' => $multiple ? 'si' : 'no', 'config.typeError' => $typeError, 'config.size' => $size);
     if (!$simple) {
         $valores['config.message'] = $message;
     }
     //Imprimo lo que seria el Head
     $this->api->component($form, $valores);
     //Imprimo los hijos
     if ($defaultLabel != NULL) {
         $valores_option = array('config.label' => $defaultLabel, 'config.value' => $defaultValue, 'config.checked' => 'no');
         $this->api->component('select_option', $valores_option);
     }
     foreach ($options as $option) {
         $optionLab = "";
         $optionVal = "";
         if (is_object($option)) {
             $reflection = new Reflection($option);
             $optionLab = $reflection->getProperty($varLabel);
             $optionVal = $reflection->getProperty($varValue);
         } else {
             if (is_array($option)) {
                 $optionLab = $option[$varLabel];
                 $optionVal = $option[$varValue];
             } else {
                 $optionLab = $option;
                 $optionVal = $option;
             }
         }
         $valores_option = array('config.label' => $optionLab, 'config.value' => $optionVal);
         $checked = FALSE;
         if (is_array($value)) {
             if (in_array($optionVal, $value)) {
                 $checked = TRUE;
             }
         } else {
             if ($optionVal == $value) {
                 $checked = TRUE;
             }
         }
         if ($checked == TRUE) {
             $valores_option['config.checked'] = 'si';
         } else {
             $valores_option['config.checked'] = 'no';
         }
         $this->api->component('select_option', $valores_option);
     }
     //Armo el Pie
     $valores = array('config.seccion' => 'pie');
     if (!$simple) {
         $valores['config.message'] = $message;
     }
     $this->api->component($form, $valores);
 }