Esempio n. 1
0
 private function insertaDB($listacalles)
 {
     $comando = "INSERT INTO " . self::NOMBRE_TABLA . " (" . self::IDCALLE . ", " . self::NOMCALLE . ")" . " VALUES (?,?)";
     $pdo = ConexionBD::obtenerInstancia()->obtenerBD();
     $sentencia = $pdo->prepare($comando);
     ini_set('max_execution_time', 300);
     for ($i = 0; $i < count($listacalles) - 1; $i++) {
         $calle = $listacalles[$i];
         $id = $calle["idCalle"];
         $nombre = $calle["nombre"];
         $sentencia->bindParam(1, $id, PDO::PARAM_INT);
         $sentencia->bindParam(2, $nombre);
         $resultado = $sentencia->execute();
     }
     return $resultado;
 }
Esempio n. 2
0
 private function obtenerTodosLosPuntos()
 {
     try {
         $comando = "SELECT *" . " FROM " . self::NOMBRE_TABLA;
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             $puntos = $sentencia->fetchAll(PDO::FETCH_ASSOC);
             http_response_code(200);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de puntos exitosa", "puntos" => $puntos];
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 3
0
 public static function obtenerComentariosFestival($idFestival)
 {
     try {
         $comando = "SELECT c." . self::ID_COMENTARIO . " as idComentario" . ", u." . usuarios::NOMBRE . " as nombreAutor" . ", u." . usuarios::CORREO . " as correoAutor" . ", c." . self::ID_FESTIVAL . " as idFestival" . ", c." . self::FECHA . ", c." . self::TEXTO . " FROM " . self::NOMBRE_TABLA . " c" . " INNER JOIN " . usuarios::NOMBRE_TABLA . " u" . " ON c." . self::ID_USUARIO . " = u." . usuarios::ID_USUARIO . " WHERE c." . self::ID_FESTIVAL . " =?" . " ORDER BY " . self::FECHA . " DESC";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ligar idContenedor
         $sentencia->bindParam(1, $idFestival, PDO::PARAM_INT);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             http_response_code(200);
             return $sentencia->fetchAll(PDO::FETCH_ASSOC);
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 4
0
 private function obtenerComentarios($idContenedor, $tipo)
 {
     try {
         $comando = "SELECT c." . self::ID_COMENTARIO . " as idComentario" . ", u." . usuarios::NOMBRE . " as nombreAutor" . ", u." . usuarios::IMAGEN . " as encodedImg" . ", c." . self::FECHA . " as fecha" . ", c." . self::TEXTO . " as cuerpo" . " FROM " . self::NOMBRE_TABLA . " c" . " INNER JOIN " . usuarios::NOMBRE_TABLA . " u" . " ON c." . self::ID_USUARIO . " = u." . usuarios::ID_USUARIO . " WHERE " . self::ID_CONTENEDOR . "=? AND " . self::TIPO . "=?" . " ORDER BY " . self::FECHA . " DESC";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ligar idContenedor
         $sentencia->bindParam(1, $idContenedor, PDO::PARAM_INT);
         $sentencia->bindParam(2, $tipo, PDO::PARAM_INT);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             http_response_code(200);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de comentarios exitosa", "comentarios" => $sentencia->fetchAll(PDO::FETCH_ASSOC)];
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 5
0
 private function obtenerFestivalInfo($id)
 {
     $resultado = array();
     try {
         $comando = "SELECT " . self::ID_FESTIVAL . " as idFestival" . ", " . self::NOMBRE_FESTIVAL . " as nombreFestival" . ", " . self::UBICACION_FESTIVAL . " as ubicacionFestival" . ", " . self::LATITUD_FESTIVAL . " as latitudFestival" . ", " . self::LONGITUD_FESTIVAL . " as longitudFestival" . ", " . self::LOGO_URL . " as logoUrl" . ", " . self::BACK_URL . " as backUrl" . ", " . self::DESCRIPCION_FESTIVAL . " as descripcionFestival" . ", " . self::FACEBOOK_URL . " as facebookUrlFestival" . ", " . self::WEB_URL . " as webUrlFestival" . ", " . self::INSTAGRAM_USER . " as instagramUserFestival" . ", " . self::ENTRADAS_URL . " as entradasUrl" . ", " . self::FECHA_INICIO . " as fechaInicio" . ", " . self::FECHA_FIN . " as fechaFin" . ", " . self::ASISTENTES_FESTIVAL . " as asistentesFestival" . ", " . self::EDICIONES_FESTIVAL . " as edicionesFestival" . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::ID_FESTIVAL . "=? ;";
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         $sentencia->bindParam(1, $id, PDO::PARAM_INT);
         if ($sentencia->execute()) {
             $festival = $sentencia->fetchAll(PDO::FETCH_ASSOC);
             $artistas = artistas::getArtistaFromFestival($id);
             $comentarios = comentarios::obtenerComentariosFestival($id);
             http_response_code(200);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de festivales exitosa", "festivales" => ["info" => $festival, "artistas" => $artistas, "comentarios" => $comentarios]];
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 6
0
 private function crear($alerta)
 {
     if ($alerta) {
         try {
             $tipo = $alerta->tipo;
             $descripcion = $alerta->descripcion;
             $idContenedor = $alerta->idContenedor;
             $tipoContenedor = $alerta->tipoContenedor;
             $dirContenedor = $alerta->dirContenedor;
             $lat = $alerta->lat;
             $lon = $alerta->lon;
             $email = $alerta->email;
             $imagen = $alerta->encodedImg;
             $fecha = date("Y-m-d H:i:s");
             $pdo = ConexionBD::obtenerInstancia()->obtenerBD();
             // Sentencia INSERT
             $comando = "INSERT INTO " . self::NOMBRE_TABLA . " ( " . self::TIPO . "," . self::DESCRIPCION . "," . self::FECHA . "," . self::ID_CONTENEDOR . "," . self::TIPO_CONTENEDOR . "," . self::DIRECCION_CONTENEDOR . "," . self::LATITUD_CONTENEDOR . "," . self::LONGITUD_CONTENEDOR . "," . self::EMAIL_USUARIO . "," . self::IMAGEN . ")" . " VALUES(?,?,?,?,?,?,?,?,?,?)";
             // Preparar la sentencia
             $sentencia = $pdo->prepare($comando);
             $sentencia->bindParam(1, $tipo);
             $sentencia->bindParam(2, $descripcion);
             $sentencia->bindParam(3, $fecha);
             $sentencia->bindParam(4, $idContenedor, PDO::PARAM_INT);
             $sentencia->bindParam(5, $tipoContenedor, PDO::PARAM_INT);
             $sentencia->bindParam(6, $dirContenedor);
             $sentencia->bindParam(7, $lat);
             $sentencia->bindParam(8, $lon);
             $sentencia->bindParam(9, $email);
             $sentencia->bindParam(10, $imagen);
             $sentencia->execute();
             // Retornar en el último id insertado
             return $pdo->lastInsertId();
         } catch (PDOException $e) {
             throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
         }
     } else {
         throw new ExcepcionApi(self::ESTADO_PARAMETROS_INCORRECTOS, utf8_encode("Error en existencia o sintaxis de parámetros"));
     }
 }
Esempio n. 7
0
 public static function obtenerSeguidos($idSig)
 {
     try {
         $comando = "SELECT Us.nomUsuario,Us.imgPerfil,Us.idUsuario,Us.numLikes,Us.idUsuario,Us.numRutas  FROM " . self::NOMBRE_TABLA . " as seg" . " INNER JOIN Usuario as Us ON Us.idUsuario = seg." . self::ID_SEGUIDO . " WHERE " . self::ID_USUARIO . "=?";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ligar idUsuario
         $sentencia->bindParam(1, $idSig, PDO::PARAM_INT);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             $sig = $sentencia->fetchAll(PDO::FETCH_ASSOC);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de usuarios a los que sigues exitosa", "siguiendo" => $sig];
         }
         return array();
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 8
0
 private function crear($idUsuario, $reciclaje)
 {
     if ($reciclaje) {
         try {
             $tipo = $reciclaje->tipo;
             $fecha = date("Y-m-d H:i:s");
             $peso = self::calculaPeso($tipo);
             $pdo = ConexionBD::obtenerInstancia()->obtenerBD();
             // Sentencia INSERT
             $comando = "INSERT INTO " . self::NOMBRE_TABLA . " ( " . self::TIPO . "," . self::PESO . "," . self::FECHA . "," . self::ID_USUARIO . ")" . " VALUES(?,?,?,?)";
             // Preparar la sentencia
             $sentencia = $pdo->prepare($comando);
             $sentencia->bindParam(1, $tipo, PDO::PARAM_INT);
             $sentencia->bindParam(2, $peso);
             $sentencia->bindParam(3, $fecha);
             $sentencia->bindParam(4, $idUsuario);
             $sentencia->execute();
             $idReciclaje = $pdo->lastInsertId();
             return $idReciclaje;
         } catch (PDOException $e) {
             throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
         }
     } else {
         throw new ExcepcionApi(self::ESTADO_PARAMETROS_INCORRECTOS, utf8_encode("Error en existencia o sintaxis de parámetros"));
     }
 }
 public static function obtenerRutasFav($idUsuRutFav)
 {
     try {
         $comando = "SELECT ru.idRuta,ru.nomRuta,ru.valoracion,ru.idCategoriaRut, ru.idUsuario_ruta  FROM " . self::NOMBRE_TABLA . " AS fav" . " INNER JOIN Ruta AS ru ON ru.idRuta = fav." . self::ID_RUTA . " WHERE " . self::ID_USUARIO . "=?";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ligar idUsuario
         $sentencia->bindParam(1, $idUsuRutFav, PDO::PARAM_INT);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             $ruta = $sentencia->fetchAll(PDO::FETCH_ASSOC);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de rutas favorita exitosa", "rutas" => $ruta];
         }
         return array();
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 10
0
 private function obtenerFavoritos($idUsuario)
 {
     try {
         $comando = "SELECT " . self::ID_FAVORITO . " as idFavorito" . ", " . self::ID_CONTENEDOR . " as idContenedor" . ", " . self::TIPO . " as tipo" . ", " . self::DIRECCION . " as direccion" . ", " . self::LATITUD . " as lat" . ", " . self::LONGITUD . " as lon" . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::ID_USUARIO . "=?";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ligar idUsuario
         $sentencia->bindParam(1, $idUsuario, PDO::PARAM_INT);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             http_response_code(200);
             return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de favoritos exitosa", "favoritos" => $sentencia->fetchAll(PDO::FETCH_ASSOC)];
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 11
0
 /**
  * Obtiene el valor de la columna "idUsuario" basado en la clave de api
  * @param $claveApi
  * @return null si este no fue encontrado
  */
 private function obtenerIdUsuario($claveApi)
 {
     $comando = "SELECT " . self::ID_USUARIO . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::CLAVE_API . "=?";
     $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
     $sentencia->bindParam(1, $claveApi);
     if ($sentencia->execute()) {
         $resultado = $sentencia->fetch();
         return $resultado[self::ID_USUARIO];
     } else {
         return null;
     }
 }
Esempio n. 12
0
 public function existeUsuario($correo)
 {
     $pdo = ConexionBD::obtenerInstancia()->obtenerBD();
     $comando = "SELECT * FROM " . SELF::NOMBRE_TABLA . " WHERE " . self::CORREO . " = ?";
     $sentencia = $pdo->prepare($comando);
     $sentencia->bindParam(1, $correo);
     $sentencia->execute();
     $resultado = $sentencia->rowCount();
     if ($resultado > 0) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 13
0
 private function eliminarAmigo($amigo)
 {
     $idUsuario1 = $amigo["idUsuario1"];
     $idUsuario2 = $amigo["idUsuario2"];
     try {
         // Sentencia DELETE
         $comando = "DELETE FROM " . self::NOMBRE_TABLA_RELACION . " WHERE " . self::ID_USUARIO1 . "=? AND " . self::ID_USUARIO2 . "=?";
         // Preparar la sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         $sentencia->bindParam(1, $idUsuario1);
         $sentencia->bindParam(2, $idUsuario2);
         $sentencia->execute();
         // Sentencia DELETE
         $comando = "DELETE FROM " . self::NOMBRE_TABLA_RELACION . " WHERE " . self::ID_USUARIO2 . "=? AND " . self::ID_USUARIO1 . "=?";
         // Preparar la sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         $sentencia->bindParam(1, $idUsuario1);
         $sentencia->bindParam(2, $idUsuario2);
         $sentencia->execute();
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 14
0
 private function obtenerNombreFestival($idFestival)
 {
     try {
         $comando = "SELECT " . self::NOMBRE_FESTIVAL . " FROM " . self::NOMBRE_TABLA_FESTIVALES . " WHERE " . self::ID_FESTIVAL . " = '{$idFestival}' ;";
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         $sentencia->bindParam(1, $idFestival, PDO::PARAM_STR);
         if ($sentencia->execute()) {
             http_response_code(200);
             return $sentencia->fetch();
         } else {
             throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error");
         }
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 15
0
 public static function obtenerUltimasRutas()
 {
     try {
         $comando = "SELECT " . self::ID_RUTA . " , " . self::NOM_RUTA . "," . self::VALORACION . " , " . self::ID_CATEGORIA . "," . self::ID_USUARIO . " FROM " . self::NOMBRE_TABLA . " ORDER BY fechaCreacion DESC LIMIT 15 ;";
         // Preparar sentencia
         $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
         // Ejecutar sentencia preparada
         if ($sentencia->execute()) {
             return $sentencia->fetchAll(PDO::FETCH_ASSOC);
         }
         return array();
     } catch (PDOException $e) {
         throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
     }
 }
Esempio n. 16
0
 private function eliminarFavorito($idUsuario, $favorito)
 {
     $idFestival = $favorito["idFestival"];
     $idArtista = $favorito["idArtista"];
     if (isset($idFestival)) {
         try {
             // Sentencia DELETE
             $comando = "DELETE FROM " . self::NOMBRE_TABLA_FESTIVAL . " WHERE " . self::USUARIOS_ID . "=? AND " . self::FESTIVALES_ID . "=?";
             // Preparar la sentencia
             $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
             $sentencia->bindParam(1, $idUsuario);
             $sentencia->bindParam(2, $idFestival);
             $sentencia->execute();
         } catch (PDOException $e) {
             throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
         }
     } else {
         try {
             // Sentencia DELETE
             $comando = "DELETE FROM " . self::NOMBRE_TABLA_ARTISTA . " WHERE " . self::USUARIOS_ID . "=? AND " . self::ARTISTAS_ID . "=?";
             // Preparar la sentencia
             $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando);
             $sentencia->bindParam(1, $idUsuario);
             $sentencia->bindParam(2, $idArtista);
             $sentencia->execute();
         } catch (PDOException $e) {
             throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage());
         }
     }
 }