/**
  * Constructor
  * Argument list is used as array of valid values expected
  */
 function __construct()
 {
     $validValues = func_get_args();
     $ff = FilterFactory::getInstance();
     $this->inFilter = $ff->newFilter('InNonStrict', $validValues);
     $this->intFilter = $ff->newFilter('Int');
 }
 public function execute()
 {
     //SESSION
     $session = SessionFactory::create();
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $session = SessionFactory::create();
     if (!$session->get("authenticated") and $params->get('public_key') == $session->get('randLogin')) {
         //PARAMETERS:
         $params = RequestParametersFactory::create();
         $username = $params->get('user-name');
         $userpassword = $params->get('user-password');
         $filter = FilterFactory::create();
         $filteredUsername = $filter->filters($username);
         //DATAHANDLER
         $datahandler = DatahandlerFactory::create('D_ReadUserByName');
         $datahandler->setInData($filteredUsername);
         $existingUser = $datahandler->getOutData();
         //ENCRYPTOR
         $isAuthenticate = crypt($userpassword, $existingUser['password']) === $existingUser['password'];
         if ($isAuthenticate) {
             //SET SESSION DATA
             $session->set('session-user-name', $existingUser['name']);
             $session->set('session-user-id', $existingUser['id']);
             $session->set("authenticated", true);
         } else {
             $session->set("authenticated", false);
         }
     }
 }
Beispiel #3
0
 public function validate($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('page', new Validate\Rule\NumNatural())->addRule('page', new Validate\Rule\NumMin(1))->addRule('take', new Validate\Rule\NumNatural())->addRule('take', new Validate\Rule\NumMin(1))->addRule('take', new Validate\Rule\NumMax(100))->addFilter('endless', FilterFactory::booleanFilter())->addOptional('page')->addOptional('take')->addOptional('endless');
     if (!$vdt->validate($data)) {
         throw new BearableException('Parámetros de paginación incorrectos.');
     }
     return $vdt;
 }
Beispiel #4
0
 public function addFilters($filtrables = array(), $searchable = false)
 {
     if (isset($this->params['where'])) {
         $filtros = explode(',', $this->params['where']);
         foreach ($filtros as $filtro) {
             $regla = explode('-', $filtro);
             if (count($regla) != 3) {
                 throw new BearableException('Parámetros de filtrado incorrectos.');
             }
             list($atr, $ope, $val) = $regla;
             if (!in_array($atr, $filtrables)) {
                 throw new BearableException('Filtro inexistente.');
             } else {
                 if (isset($this->operators[$ope])) {
                     $this->query = $this->query->where($atr, $this->operators[$ope], $val);
                 } else {
                     if ($ope == 'in') {
                         $this->query = $this->query->wherein($atr, explode('.', $val));
                     } else {
                         throw new BearableException('Operador inexistente.');
                     }
                 }
             }
         }
     }
     if (isset($this->params['where_null'])) {
         $filtros = explode(',', $this->params['where_null']);
         foreach ($filtros as $filtro) {
             if (!in_array($filtro, $filtrables)) {
                 throw new BearableException('Filtro inexistente.');
             }
             $this->query = $this->query->whereNull($filtro);
         }
     }
     if (isset($this->params['where_not_null'])) {
         $filtros = explode(',', $this->params['where_not_null']);
         foreach ($filtros as $filtro) {
             if (!in_array($filtro, $filtrables)) {
                 throw new BearableException('Filtro inexistente.');
             }
             $this->query = $this->query->whereNotNull($filtro);
         }
     }
     if (isset($this->params['q']) && $searchable) {
         $filtro = FilterFactory::calcHuella($this->params['q']);
         $this->query = $this->query->where('huella', 'LIKE', "%{$filtro}%");
     }
     if (isset($this->params['tags'])) {
         $tags = array_map(FilterFactory::calcHuella(), explode(',', $this->params['tags']));
         if (count($tags) > 4) {
             throw new BearableException('No puede buscar más de 4 tags a la vez.');
         }
         $this->query = $this->query->whereHas('tags', function ($q) use($tags) {
             $q->whereIn('huella', $tags);
         });
     }
 }
Beispiel #5
0
 /**
  * fillBeans
  * This function wraps the call to getList, but takes an additional Array argument
  * and loads the SugarBean's fields with the results as defined in the connector
  * loadBean configuration mapping
  *
  * @param $args Array of arguments to pass into getItem
  * @param $module String value of the module to map bean to
  * @param $bean Array to load SugarBean intances into
  * @throws Exception Thrown if errors are found
  */
 public function fillBeans($args = array(), $module = null, $beans = array())
 {
     $results = array();
     $args = $this->mapInput($args, $module);
     if (empty($args)) {
         $GLOBALS['log']->fatal($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
         throw new Exception($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
     }
     require_once 'include/connectors/filters/FilterFactory.php';
     $filter = FilterFactory::getInstance(get_class($this->_source));
     $list = $filter->getList($args, $module);
     if (!empty($list)) {
         $resultSize = count($list);
         if (!empty($beans)) {
             if (count($beans) != $resultSize) {
                 throw new Exception($GLOBALS['app_strings']['ERR_CONNECTOR_FILL_BEANS_SIZE_MISMATCH']);
             }
         } else {
             for ($x = 0; $x < $resultSize; $x++) {
                 $beans[$x] = BeanFactory::getBean($module);
             }
         }
         $keys = array_keys($beans);
         $count = 0;
         foreach ($list as $entry) {
             //Change the result keys to lower case.  This has important ramifications.
             //This was done because the listviewdefs.php files may not know the proper casing
             //of the fields to display.  We change the keys to lowercase so that the values
             //may be mapped to the beans without having to rely on the proper string casing
             //in the listviewdefs.php files.
             $entry = array_change_key_case($entry, CASE_LOWER);
             $results[] = $this->mapOutput($beans[$keys[$count]], $entry);
             $count++;
         }
         $field_defs = $this->getFieldDefs();
         $map = $this->getMapping();
         $hasOptions = !empty($map['options']) ? true : false;
         if ($hasOptions) {
             $options = $map['options'];
             $optionFields = array();
             foreach ($field_defs as $name => $field) {
                 if (!empty($field['options']) && !empty($map['options'][$field['options']]) && !empty($map['beans'][$module][$name])) {
                     $optionFields[$name] = $map['beans'][$module][$name];
                 }
             }
             foreach ($results as $key => $bean) {
                 foreach ($optionFields as $sourceField => $sugarField) {
                     $options_map = $options[$field_defs[$sourceField]['options']];
                     $results[$key]->{$sugarField} = !empty($options_map[$results[$key]->{$sugarField}]) ? $options_map[$results[$key]->{$sugarField}] : $results[$key]->{$sugarField};
                 }
             }
             //foreach
         }
     }
     return $results;
 }
Beispiel #6
0
 /**
  * Given various filters and permissions, sets up an entries Query\Builder
  * to be passed on to the caller to optionally add more filtering to
  */
 protected function setupEntries()
 {
     $entries = ee('Model')->get('ChannelEntry')->filter('site_id', $this->site_id);
     // We need to filter by Channel first (if necissary) as that will
     // impact the entry count for the perpage filter
     $channel_id = $this->channel_filter->value();
     // If we have a selected channel filter, and we are not an admin, we
     // first need to ensure it is in the list of assigned channels. If it
     // is we will filter by that id. If not we throw an error.
     $channel = NULL;
     if ($channel_id) {
         if ($this->is_admin || in_array($channel_id, $this->allowed_channels)) {
             $entries->filter('channel_id', $channel_id);
             $channel = ee('Model')->get('Channel', $channel_id)->first();
             $channel_name = $channel->channel_title;
         } else {
             show_error(lang('unauthorized_access'));
         }
     } else {
         if (!$this->is_admin) {
             if (empty($this->allowed_channels)) {
                 show_error(lang('no_channels'));
             }
             $entries->filter('channel_id', 'IN', $this->allowed_channels);
         }
     }
     if ($this->category_filter->value()) {
         $entries->with('Categories')->filter('Categories.cat_id', $this->category_filter->value());
     }
     if ($this->status_filter->value()) {
         $entries->filter('status', $this->status_filter->value());
     }
     if (!empty($this->search_value)) {
         $entries->filter('title', 'LIKE', '%' . $this->search_value . '%');
     }
     $filter_values = $this->filters->values();
     if (!empty($filter_values['filter_by_date'])) {
         if (is_array($filter_values['filter_by_date'])) {
             $entries->filter('entry_date', '>=', $filter_values['filter_by_date'][0]);
             $entries->filter('entry_date', '<', $filter_values['filter_by_date'][1]);
         } else {
             $entries->filter('entry_date', '>=', $this->now - $filter_values['filter_by_date']);
         }
     }
     $entries->with('Autosaves', 'Categories', 'Author', 'Channel');
     $this->entries = $entries;
 }
 public function setInData($datafile)
 {
     //FOR ERROR Allowed memory size of 134217728
     //bytes exhausted (tried to allocate 20 bytes):
     ini_set('memory_limit', '-1');
     ini_set('upload_max_filesize', '500M');
     set_time_limit(100);
     // ini_set('memory_limit', '100M');
     $tmpdata = array();
     $logfile = file($datafile);
     foreach ($logfile as $linenumber => $line) {
         array_push($tmpdata, explode(" ", $line));
     }
     foreach ($tmpdata as $key => $line) {
         $newline = array();
         foreach ($line as $key => $datum) {
             if ($datum != null) {
                 array_push($newline, $datum);
             }
         }
         array_push($this->data, $newline);
     }
     $db = DatabaseFactory::create("SquidDatabase")->connect();
     $queries = array();
     $query1 = "DELETE FROM SquidData";
     array_push($queries, $query1);
     $filter = FilterFactory::create();
     foreach ($this->data as $key => $datum) {
         $date = date('d-m-Y', $filter->filters($datum[0]));
         $time = date('H:i:s', $filter->filters($datum[0]));
         $transaction_time = $datum[1];
         $client_ip = $filter->filters($datum[2]);
         $squid_result_code = $filter->filters($datum[3]);
         $client_data = $datum[4];
         $request_method = $filter->filters($datum[5]);
         $url = $filter->filters($datum[6]);
         $mime_type = $filter->filters($datum[9]);
         $query2 = "INSERT INTO SquidData\n        \t\t\t\t\t   (\n        \t\t\t\t\t\t\tdate, time, transaction_time, \n        \t\t\t\t\t\t\tclient_ip, squid_result_code,\n        \t\t\t\t\t\t\tclient_data, request_method,\n        \t\t\t\t\t\t\turl, mime_type\n        \t\t\t\t\t   ) \n\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t'{$date}', '{$time}', {$transaction_time},\n\t\t\t\t\t\t\t\t\t'{$client_ip}', '{$squid_result_code}',\n\t\t\t\t\t\t\t\t\t{$client_data}, '{$request_method}',\n\t\t\t\t\t\t\t\t\t'{$url}', '{$mime_type}'\n\t\t\t\t\t\t\t   )";
         array_push($queries, $query2);
     }
     $db->SQLTransaction($queries);
 }
Beispiel #8
0
 public function crearModeradores()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('entrantes', new Validate\Rule\Attributes(['usr' => 'ctype_digit', 'pat' => 'ctype_digit']))->addFilter('entrantes', FilterFactory::json_decode());
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     foreach ($vdt->getData('entrantes') as $entrante) {
         $usuario = Usuario::findOrFail($entrante['usr']);
         $patrulla = Patrulla::findOrFail($entrante['pat']);
         $usuario->patrulla()->associate($patrulla);
         $usuario->save();
         $identidad = $usuario->identidad . ' (' . $usuario->id . ')';
         $log = AdminlogCtrl::createLog($identidad, 6, 'new', $this->session->user('id'), $patrulla);
         NotificacionCtrl::createNotif($usuario->id, $log);
     }
     $this->flash('success', 'Los nuevos moderadores han sido agregados exitosamente.');
     $this->redirectTo('shwCrearModerad');
 }
Beispiel #9
0
 public static function getTagIds($tags)
 {
     if (!is_array($tags)) {
         throw new TurnbackException('Tags incorrectas.');
     }
     $vdt = new Validate\Validator();
     $vdt->addRule('tags', new Validate\Rule\AlphaNumeric([' ']))->addRule('tags', new Validate\Rule\MinLength(2))->addRule('tags', new Validate\Rule\MaxLength(32));
     if (!$vdt->validate(['tags' => $tags])) {
         throw new TurnbackException($vdt->getErrors());
     } else {
         if (count($tags) > 8) {
             throw new TurnbackException('No pueden asignarse más de 8 tags.');
         }
     }
     $tagIds = array();
     foreach ($tags as $tag) {
         $tagIds[] = Tag::firstOrCreate(['nombre' => FilterFactory::normalizeWhitespace($tag)])->id;
     }
     return $tagIds;
 }
Beispiel #10
0
 public function adminAjustes()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('tos', new Validate\Rule\MinLength(8))->addRule('tos', new Validate\Rule\MaxLength(8192))->addFilter('tos', FilterFactory::escapeHTML());
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     $ajustes = Ajuste::all();
     foreach ($ajustes as $ajuste) {
         $newValue = $vdt->getData($ajuste->key);
         if (isset($newValue)) {
             $ajuste->value = $newValue;
             $ajuste->save();
             AdminlogCtrl::createLog('', 1, 'mod', $this->session->user('id'), $ajuste);
         }
     }
     $this->flash('success', 'Los ajustes se han modificado exitosamente.');
     $this->redirectTo('shwAdmAjuste');
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('role-name');
     $description = $params->get('role-description');
     //FILTERS
     $filter = FilterFactory::create();
     $filteredName = $filter->filters($name);
     //VALIDATOR//VALIDO QUE EL ROLE YA NO EXISTA
     $datahandler = DatahandlerFactory::create();
     $datahandler['D_ReadRoleByName']->setInData($filteredName);
     $existingRole = $datahandler['D_ReadRoleByName']->getOutData();
     $validator = ValidatorFactory::create();
     $validator->ifFalse($existingRole['name'] == null)->respond(EXISTING_ROLE);
     //DATAHANDLER
     $datahandler['D_CreateRole']->setInData(array("name" => "{$name}", "description" => "{$description}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadRolesPaginated');
 }
Beispiel #12
0
 public function modificar()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(1))->addRule('nombre', new Validate\Rule\MaxLength(32))->addRule('apellido', new Validate\Rule\Alpha(array(' ')))->addRule('apellido', new Validate\Rule\MinLength(1))->addRule('apellido', new Validate\Rule\MaxLength(32))->addRule('url', new Validate\Rule\URL())->addRule('email', new Validate\Rule\Email())->addRule('telefono', new Validate\Rule\Telephone())->addOptional('url')->addOptional('email')->addOptional('telefono')->addFilter('url', FilterFactory::emptyToNull())->addFilter('telefono', FilterFactory::emptyToNull());
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     $usuario = $this->session->getUser();
     $usuario->nombre = $vdt->getData('nombre');
     $usuario->apellido = $vdt->getData('apellido');
     $usuario->save();
     $contacto = $usuario->contacto ?: new Contacto();
     $contacto->email = $vdt->getData('email');
     $contacto->web = $vdt->getData('url');
     $contacto->telefono = $vdt->getData('telefono');
     $contacto->contactable()->associate($usuario);
     $contacto->save();
     $this->flash('success', 'Sus datos fueron modificados exitosamente.');
     $this->redirect($this->request->getReferrer());
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('role-name');
     $description = $params->get('role-description');
     $session = SessionFactory::create();
     $id = $session->get('role-id');
     //FILTERS
     $filter = FilterFactory::create();
     $filteredName = $filter->filters($name);
     $filteredDescription = $filter->filters($description);
     //VALIDATOR
     $validator = ValidatorFactory::create();
     //DATASET
     $datahandler = DatahandlerFactory::create('D_UpdateRole');
     $datahandler->setInData(array("id" => "{$id}", "name" => "{$filteredName}", "description" => "{$filteredDescription}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadRolesPaginated');
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('user-name');
     $password = $params->get('user-password');
     $passwordConfirmation = $params->get('password-confirmation');
     $encryptPassword = crypt($password);
     $session = SessionFactory::create();
     $id = $session->get('user-id');
     //FILTERS
     $filter = FilterFactory::create();
     $filter->filters($name);
     //VALIDATOR
     $validator = ValidatorFactory::create();
     $validator->ifFalse($password == $passwordConfirmation)->respond(PASSWORDS_NOT_MATCH);
     //DATASET
     $datahandler = DatahandlerFactory::create('D_UpdateUser');
     $datahandler->setInData(array("id" => "{$id}", "name" => "{$name}", "password" => "{$encryptPassword}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadUsersPaginated');
 }
 public function execute()
 {
     //FILTERS
     $filter = FilterFactory::create();
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $filter->filters($params->get('user-name'));
     $password = $params->get('user-password');
     $passwordConfirmation = $params->get('password-confirmation');
     $encryptPassword = crypt($password);
     //VALIDATION
     $datahandler = DatahandlerFactory::create();
     $datahandler['D_ReadUserByName']->setInData($name);
     $data = $datahandler['D_ReadUserByName']->getOutData();
     $validator = ValidatorFactory::create();
     $validator->ifTrue($data['name'] != null)->respond(EXISTING_USER);
     $validator->ifFalse($password == $passwordConfirmation)->respond(PASSWORDS_NOT_MATCH);
     //DATAHANDLER
     $datahandler['D_CreateUser']->setInData(array("name" => "{$name}", "password" => "{$encryptPassword}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadUsersPaginated');
 }
Beispiel #16
0
 /**
  * Apply an array of filter to one value
  * @param mixed $value
  * @param array $filters
  * @return mixed
  * @throws FilterException
  */
 static function apply($value = null, array $filters = array())
 {
     //error_log(__METHOD__ . ' value: ' . json_encode($value));
     $filterFactory = FilterFactory::getInstance();
     foreach ($filters as $idx => $filterArr) {
         //error_log(__METHOD__ . ' loop: ' . $idx . ': ' . json_encode($filterArr));
         if (empty($filterArr[0])) {
             continue;
         }
         //skip
         $filterName = $filterArr[0];
         //error_log(__METHOD__ . ' loop: ' . $idx . ' filter ' . $filterName);
         $filterErr = isset($filterArr[1]) ? $filterArr[1] : '';
         $filterParams = isset($filterArr[2]) ? $filterArr[2] : array();
         $filter = $filterFactory->newFilter($filterName, $filterParams);
         try {
             $value = $filter->filter($value);
         } catch (FilterException $ex) {
             $msg = $filterErr !== '' ? $filterErr : $ex->getMessage();
             throw new FilterException($msg);
         }
     }
     return $value;
 }
Beispiel #17
0
 public function setTituloAttribute($value)
 {
     $this->attributes['titulo'] = $value;
     $this->attributes['huella'] = FilterFactory::calcHuella($value);
 }
Beispiel #18
0
 private function validarPartido($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(2))->addRule('nombre', new Validate\Rule\MaxLength(64))->addRule('acronimo', new Validate\Rule\Alpha())->addRule('acronimo', new Validate\Rule\MinLength(2))->addRule('acronimo', new Validate\Rule\MaxLength(8))->addRule('descripcion', new Validate\Rule\MinLength(4))->addRule('descripcion', new Validate\Rule\MaxLength(512))->addRule('fundador', new Validate\Rule\Alpha(array(' ')))->addRule('fundador', new Validate\Rule\MaxLength(32))->addRule('fecha', new Validate\Rule\Date())->addRule('url', new Validate\Rule\URL())->addRule('email', new Validate\Rule\Email())->addRule('telefono', new Validate\Rule\Telephone())->addOptional('fundador')->addOptional('fecha')->addOptional('url')->addOptional('email')->addOptional('telefono')->addFilter('fundador', FilterFactory::emptyToNull())->addFilter('fecha', FilterFactory::emptyToNull())->addFilter('url', FilterFactory::emptyToNull())->addFilter('email', FilterFactory::emptyToNull())->addFilter('telefono', FilterFactory::emptyToNull());
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #19
0
 private function validarEvento($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addRule('lugar', new Validate\Rule\MinLength(4))->addRule('lugar', new Validate\Rule\MaxLength(128))->addRule('fecha', new Validate\Rule\Date('Y-m-d H:i:s'))->addRule('tags', new Validate\Rule\Required())->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML())->addFilter('asociar', FilterFactory::booleanFilter())->addFilter('tags', FilterFactory::explode(','));
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #20
0
 public function setApellidoAttribute($value)
 {
     $this->attributes['apellido'] = $value;
     $nombre = isset($this->attributes['nombre']) ? $this->attributes['nombre'] . ' ' : '';
     $this->attributes['huella'] = FilterFactory::calcHuella($nombre . $value);
 }
Beispiel #21
0
 private function validarPropuesta($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addRule('referido', new Validate\Rule\NumNatural())->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML())->addFilter('referido', FilterFactory::emptyToNull())->addFilter('tags', FilterFactory::explode(','))->addOptional('referido');
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #22
0
 private function validarOrganismo($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(2))->addRule('nombre', new Validate\Rule\MaxLength(64))->addRule('descripcion', new Validate\Rule\MaxLength(512))->addRule('cupo', new Validate\Rule\NumNatural())->addRule('cupo', new Validate\Rule\NumMin(1))->addRule('cupo', new Validate\Rule\NumMax(128))->addRule('url', new Validate\Rule\URL())->addRule('email', new Validate\Rule\Email())->addRule('telefono', new Validate\Rule\Telephone())->addOptional('url')->addOptional('email')->addOptional('telefono')->addFilter('url', FilterFactory::emptyToNull())->addFilter('email', FilterFactory::emptyToNull())->addFilter('telefono', FilterFactory::emptyToNull());
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #23
0
 private function validarDocumento($data, $cuerpo = true)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('descripcion', new Validate\Rule\MinLength(8))->addRule('descripcion', new Validate\Rule\MaxLength(1024))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addFilter('tags', FilterFactory::explode(','));
     if ($cuerpo) {
         $vdt->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML());
     }
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #24
0
 public function setNombreAttribute($value)
 {
     $this->attributes['nombre'] = $value;
     $this->attributes['huella'] = FilterFactory::calcHuella($value);
 }