<?php

class Biblioteca extends Conexion {

    public function Consultar($fil) {
        $conectar = parent::conectar();
        parent::set_names();
        switch ($fil) {
            case "all":
                $sql = "SELECT * FROM clasificacion";
                break;
            case "tipo":
                $sql = "SELECT tipo FROM libros where tipo != '' GROUP BY tipo";
                break;
            case "anioL":
                $sql = "SELECT anio FROM libros where anio != '' and clase = 'libro' GROUP BY anio ORDER BY anio";
                break;
            case "autorL":
                $sql = "SELECT autor FROM libros WHERE autor !='' and clase = 'libro' GROUP BY autor ORDER BY autor ";
                break;
            case "anioA":
                $sql = "SELECT anio FROM libros where anio != '' and clase = 'articulo' GROUP BY anio ORDER BY anio";
                break;
            case "autorA":
                $sql = "SELECT autor FROM libros WHERE autor !='' and clase = 'articulo' GROUP BY autor ORDER BY autor ";
                break;
            case "anioT":
                $sql = "SELECT anio FROM libros where anio != '' and clase = 'tesis' GROUP BY anio ORDER BY anio";
                break;
            case "autorT":
                $sql = "SELECT autor FROM libros WHERE autor !='' and clase = 'tesis' GROUP BY autor ORDER BY autor ";
                break;
            case "anioR":
                $sql = "SELECT anio FROM libros where anio != '' and clase = 'revista' GROUP BY anio ORDER BY anio";
                break;
            case "autorR":
                $sql = "SELECT autor FROM libros WHERE autor !='' and clase = 'revista' GROUP BY autor ORDER BY autor ";
                break; 
            case "anioV":
                $sql = "SELECT anio FROM libros where anio != '' and clase = 'video' GROUP BY anio ORDER BY anio";
                break;
            case "autorV":
                $sql = "SELECT autor FROM libros WHERE autor !='' and clase = 'video' GROUP BY autor ORDER BY autor ";
                break;             
            case "libro":
                $sql = "SELECT * FROM libros WHERE clase = 'libro'";
                break;
            case "articulo":
                $sql = "SELECT * FROM libros WHERE clase = 'articulo'";
                break;
            case "revista":
                $sql = "SELECT * FROM libros WHERE clase = 'revista'";
                break;   
            case "video":
                $sql = "SELECT * FROM libros WHERE clase = 'video'";
                break;  
            case "tesis":
                $sql = "SELECT * FROM libros WHERE clase = 'tesis'";
                break;  
        }
        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }

    public function ConsultarFiltro($clasificaciondbk) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from subclasificacion where clasificaciondbk = ?";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $clasificaciondbk);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }

    public function BuscarL($clasificacion, $subclasificacion) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from libros WHERE clase = 'libro' ";
        if ($clasificacion > 0) {
            $sql .= " and clasificacion = " . $clasificacion;
        }
        if ($subclasificacion > 0) {
            $sql .= " and subclasificacion = " . $subclasificacion;
        }

        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }

    public function BuscarA($clasificacion, $subclasificacion) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from libros WHERE clase = 'articulo' ";
        if ($clasificacion > 0) {
            $sql .= " and clasificacion = " . $clasificacion;
        }
        if ($subclasificacion > 0) {
            $sql .= " and subclasificacion = " . $subclasificacion;
        }
        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function BuscarT($clasificacion, $subclasificacion) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from libros WHERE clase = 'tesis' ";
        if ($clasificacion > 0) {
            $sql .= " and clasificacion = " . $clasificacion;
        }
        if ($subclasificacion > 0) {
            $sql .= " and subclasificacion = " . $subclasificacion;
        }
        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function BuscarR($clasificacion, $subclasificacion) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from libros WHERE clase = 'revista' ";
        if ($clasificacion > 0) {
            $sql .= " and clasificacion = " . $clasificacion;
        }
        if ($subclasificacion > 0) {
            $sql .= " and subclasificacion = " . $subclasificacion;
        }
        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function BuscarV($clasificacion, $subclasificacion, $tipo, $anio, $autor) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * from libros WHERE clase = 'video' ";
        if ($clasificacion > 0) {
            $sql .= " and clasificacion = " . $clasificacion;
        }
        if ($subclasificacion > 0) {
            $sql .= " and subclasificacion = " . $subclasificacion;
        }
        if ($tipo != '') {
            $sql .= " and tipo = '" . $tipo . "'";
        }
        if ($anio != '') {
            $sql .= " and anio = '" . $anio . "'";
        }
        if ($autor != '') {
            $sql .= " and autor = '" . $autor . "'";
        }

        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
}
?>

