<?php
class Evaluacion extends Conexion {   
    public function mdlIngresarValoracion($datos) {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "INSERT INTO " . $datos["tabla"] . "  
                (mallacurriculardbk,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,mejora,reconocimiento,semana,estudiante)
                VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        $sql = $conectar->prepare($sql);
        $sql->bindValue(1, $datos["mallacurriculardbk"]);
        $sql->bindValue(2, $datos["p1"]);        
        $sql->bindValue(3, $datos["p2"]);
        $sql->bindValue(4, $datos["p3"]);
        $sql->bindValue(5, $datos["p4"]);
        $sql->bindValue(6, $datos["p5"]);
        $sql->bindValue(7, $datos["p6"]);
        $sql->bindValue(8, $datos["p7"]);
        $sql->bindValue(9, $datos["p8"]);
        $sql->bindValue(10, $datos["p9"]);
        $sql->bindValue(11, $datos["p10"]);
        $sql->bindValue(12, $datos["p11"]);
        $sql->bindValue(13, $datos["p12"]);
        $sql->bindValue(14, $datos["p13"]);
        $sql->bindValue(15, $datos["p4"]);
        $sql->bindValue(16, $datos["mejora"]);
        $sql->bindValue(17, $datos["reconocimiento"]);         
        $sql->bindValue(18, $datos["semana"]);
        $sql->bindValue(19, $datos["estudiante"]);
        $sql->execute();
        return $resultado = $sql->fetchAll();
    }
    public function ConsultarValoracion($mallacurricularId,$semana) {
        $conectar = parent::conectar();
        parent::set_names();       
        $sql = "SELECT *
                FROM evaluacion
                WHERE mallacurriculardbk = $mallacurricularId
                AND semana = $semana;";                                              
        $sql = $conectar->prepare($sql);
        $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 EvaluacionDisponible($mallacurriculardbk,$semana,$estudiante) {
        $conectar = parent::conectar();
        parent::set_names();       
        $sql = "SELECT count(*)as registro
                FROM evaluacion
                WHERE mallacurriculardbk = $mallacurriculardbk
                AND semana = $semana
                AND estudiante = $estudiante                    
                ;";                                              
        $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();
    }     
}
?>