<?php
class Clases extends Conexion {   
    public function mdlIngresarClases($datos) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "INSERT INTO " . $datos["tabla"] . "  
                (mallacurricular,semana,fecha,link)
                VALUES (?,?,?,?)";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $datos["mallacurricular"]);
        $sql->bindValue(2, $datos["semana"]);        
        $sql->bindValue(3, $datos["fecha"]);
        $sql->bindValue(4, $datos["link"]);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function ConsultarClases($mallacurricularId) {
        $conectar = parent::conectar();
        parent::set_names();       
        $sql = "SELECT clasedbk, 
                CASE
                    WHEN semana = 1 THEN 'SEMANA 1'        
                    WHEN semana = 2 THEN 'SEMANA 2'
                    WHEN semana = 3 THEN 'SEMANA 3'
                    WHEN semana = 4 THEN 'SEMANA 4'
                    WHEN semana = 5 THEN 'SEMANA 5'
                    WHEN semana = 6 THEN 'SEMANA 6'
                    WHEN semana = 7 THEN 'SEMANA 7'
                    WHEN semana = 8 THEN 'SEMANA 8'
                END AS semana,
                fecha,link,mallacurricular
                FROM clases_grabadas
                WHERE mallacurricular = $mallacurricularId;";                                              
        $sql = $conectar->prepare($sql);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function EliminarClase_por_ID($claseId) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "
                DELETE FROM clases_grabadas WHERE clasedbk = ?
                ";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $claseId);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }     
    public function ClasesGrabadas($carrera,$asignatura,$periodo) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "                
                SELECT *
                FROM mallacurricular,clases_grabadas
                WHERE carrera=?
                AND asignatura=?
                AND periodo = ?
                AND mallacurriculardbk=mallacurricular
                ";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $carrera);
        $sql->bindValue(2, $asignatura);
        $sql->bindValue(3, $periodo);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    } 
    public function ResumenGrabacion($periodo) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "                
                SELECT carrera.descripcion as carrera, asignatura.descripcion as asignatura, 
                concat(papellido,' ',sapellido,' ',pnombre,' ',snombre)as docente,count(*)as videos
                FROM clases_grabadas,mallacurricular,persona,carrera,asignatura
                WHERE mallacurriculardbk=mallacurricular
                AND docente=personadbk
                AND carreradbk=carrera
                AND asignaturadbk=asignatura
                AND periodo = ?
                GROUP BY(asignatura)
                ";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $periodo);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }     
}
?>