public static function getLogin($nombre = NULL, $password = NULL)
 {
     $id = \Validator::int($id);
     $conexion = \Db\Singleton::getInstance();
     $sqlusu = "select * from dbusuarios where usuario = '" . $nombre . "'";
     $resultado = $conexion->query($sqlusu);
     if (!$resultado) {
         throw new Exception("fallo en query {$sql}\n" . $conexion->error);
     }
     if (!$resultado->num_rows) {
         throw new Exception("No existe un cliente con nombre {$nombre}");
     } else {
         $sqlpass = "******" . $password . "' and idusuario = " . $resultado->result(0, 0);
         $resultado = $conexion->query($sqlpass);
         if (!$resultado) {
             throw new Exception("fallo en query {$sql}\n" . $conexion->error);
         }
         if (!$resultado->num_rows) {
             throw new Exception("No existe un cliente con password {$password}");
         }
     }
     $resultado = $resultado->fetch_assoc();
     $_SESSION['adclie_usuario'] = $nombre;
     $_SESSION['adclie_pass'] = $password;
     return self::getInstanceBySQLRow($resultado);
 }
 public function setCantidad($cantidad = NULL)
 {
     $mensaje = "La cantidad no puede ser vacia";
     $cantidad = Validator::emptyString($cantidad, $mensaje);
     $mensaje = "La cantidad no puede ser menor a 1";
     $cantidad = Validator::int($cantidad, $mensaje, 1);
     $this->cantidad = $cantidad;
 }
Example #3
0
 public function testInt()
 {
     $this->assertFalse(Validator::int()->valid(''));
     $this->assertTrue(Validator::int()->valid("0"));
     $this->assertTrue(Validator::int()->valid(0));
     $this->assertTrue(Validator::int()->valid('2'));
     $this->assertFalse(Validator::int($min = 3)->valid('2'));
     $this->assertFalse(Validator::int($min = 0, $max = 1)->valid('2'));
 }
Example #4
0
 public function testSetupRecursively()
 {
     $handler = $this->getMock('\\PHPVS\\RuleSet');
     $handler->expects($this->atLeastOnce())->method('handle');
     RuleSet::filter(['array' => ['age' => -1, 'email' => 'not an email']], ['array' => RuleSet::setup(['age' => Validator::int()->prepare(), 'email' => Validator::email()->prepare()], $required = true)], "", $handler);
     // test not required
     $handler2 = $this->getMock('\\PHPVS\\RuleSet');
     $handler2->expects($this->never())->method('handle');
     RuleSet::filter(['array' => ['age' => "", 'email' => ""]], ['array' => RuleSet::setup(['age' => Validator::int()->required(false)->prepare(), 'email' => Validator::email()->required(false)->prepare()], $required = true)], "", $handler2);
 }
Example #5
0
 public function delete()
 {
     $id_list = Json::decode(Request::post('id_list'));
     if (!$id_list) {
         throw new ValidatorException('Некорректный список ID');
     }
     foreach ($id_list as $value) {
         Validator::int($value, 'ID должен быть числом');
     }
     echo $this->_delete($id_list);
 }
 public static function getInstanceByIdUsuario($id = NULL)
 {
     $id = \Validator::int($id);
     $conexion = \Db\Singleton::getInstance();
     $sql = "SELECT idcliente,url,fechaingreso,estado,tb.descripcion,acceso,fechabaja \r\n                                 FROM dbclientes c\r\n                                 inner\r\n                                 join tbformaspago tb\r\n                                 on   c.refformapago = tb.idformapago\r\n\t\t\t\t\t\t\t\t inner\r\n\t\t\t\t\t\t\t\t join dbusuariosclientes uc\r\n\t\t\t\t\t\t\t\t on\t  uc.refcliente = c.idcliente\r\n\t\t\t\t\t\t\t\t inner\r\n\t\t\t\t\t\t\t\t join dbusuarios u\r\n\t\t\t\t\t\t\t\t on   u.idusuario = uc.refusuario\r\n                                 WHERE u.idusuario=" . $id;
     $resultado = $conexion->query($sql);
     if (!$resultado) {
         throw new Exception("fallo en query {$sql}\n" . $conexion->error);
     }
     if (!$resultado->num_rows) {
         throw new Exception("No existe un cliente con id");
     }
     $resultado = $resultado->fetch_assoc();
     return self::getInstanceBySQLRow($resultado);
 }
 public static function traerIdFactura($id = NULL)
 {
     $id = \Validator::int($id, 'Debe seleccionar un id de Factura');
     $conexion = \Db\Singleton::getInstance();
     $sql = "select idfactura,nrofactura from dbfacturas where idfactura= {$id}";
     $resultado = $conexion->query($sql);
     if (!$resultado) {
         throw new Exception("fallo en query {$sql}\n" . $conexion->error);
     }
     if (!$resultado->num_rows) {
         throw new Exception("El usuario no posee facturas con id {$id}");
     }
     $resultado = $resultado->fetch_assoc();
     return self::getInstanceBySQLRow($resultado);
 }
 public static function getInstanceById($id = NULL)
 {
     $id = \Validator::int($id);
     $conexion = \Db\Singleton::getInstance();
     $sql = "SELECT idusuario,usuario,password,tr.descripcion,email,nombrecompleto\r\n                                 FROM dbusuarios u\r\n                                 inner\r\n                                 join tbroles tr\r\n                                 on   u.refroll = tr.idrol\r\n                                 WHERE idusuario=" . $id;
     $resultado = $conexion->query($sql);
     if (!$resultado) {
         throw new Exception("fallo en query {$sql}\n" . $conexion->error);
     }
     if (!$resultado->num_rows) {
         throw new Exception("No existe un usuario con id {$id}");
     }
     $resultado = $resultado->fetch_assoc();
     return self::getInstanceBySQLRow($resultado);
 }
Example #9
0
 public function update()
 {
     $data = Json::decode(Request::post('data'));
     $id = Request::post('id', true, Validator::INT);
     if (isset($data['item_params'])) {
         if (!isset($data['type'])) {
             throw new ValidatorException('Не передан параметр type');
         }
         Validator::int($data['type']);
         $url_maker = $this->db->getOne('SELECT `url_maker` FROM ##items_types WHERE `id`=?i LIMIT 1', [$data['type']]);
         if (!$url_maker) {
             throw new ValidatorException('Некорректный параметр type');
         }
         $real_url = eval($url_maker) . '.html';
         $data['params'] = Json::encode($data['item_params']);
         $this->db->query('UPDATE ##url_redirects SET `old_url`=?s,`new_url`=?s WHERE `comment`=?i', [$data['item_url'], $real_url, $id]);
         unset($data['item_params']);
     }
     $this->_update($data, $id);
 }
 /**
  * Obtiene una instancia de un objeto de conexion a la base de datos
  * @param array $parametros
  * @return \mysqli Mysqli Instance
  * @throws string
  */
 public static function getInstance(array $parametros = array())
 {
     if (self::$instance) {
         return self::$instance;
     }
     $parametrosRequeridos = array("host", "user", "pass", "db");
     \Validator::validateArrayKeys($parametrosRequeridos, $parametros);
     if (!array_key_exists("port", $parametros)) {
         $parametros["port"] = 3306;
     } elseif (empty($parametros["port"])) {
         $parametros["port"] = 3306;
     }
     $mysqli = new \MySQLi(\Validator::emptyString($parametros["host"]), \Validator::emptyString($parametros["user"]), $parametros["pass"], \Validator::emptyString($parametros["db"]), \Validator::int($parametros["port"]));
     if ($mysqli->connect_error) {
         $msg = "No se pudo conectar a la base de datos " . $mysqli->connect_errno . ':' . $mysqli->error;
         throw new Exception($msg);
     }
     $mysqli->set_charset("utf8");
     self::$instance = $mysqli;
     return self::$instance;
 }
Example #11
0
 public function testNotShouldWorkByBuilder()
 {
     $this->assertFalse(Validator::not(Validator::int())->validate(10));
 }