<?php

class Calendar extends Conexion
{
    public function GetEvents()
    {
        $conectar = parent::conectar();

        $sql = "SELECT * FROM calendario cal
                INNER JOIN eventos eve
                ON cal.eventodbk = eve.eventodbk";

        $sql = $conectar->prepare($sql);

        $sql->execute();

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

    public function CreateEvent($datos) 
    {
        //Atributtes calendardbk, fecha_evento, eventodbk
        $conectar = parent::conectar();

        $sql = "INSERT INTO calendario (fecha_evento, eventodbk) VALUES (?,?)";

        $sql = $conectar->prepare($sql);

        $sql->bindValue(1, $datos["fecha_evento"]);
        $sql->bindValue(2, $datos["eventodbk"]);

        $sql->execute();

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

    public function UpdateEvent($datos) 
    {
        $conectar = parent::conectar();

        $sql = "UPDATE calendario SET fecha_evento = ? WHERE calendardbk = ?";

        $sql = $conectar->prepare($sql);

        $sql->bindValue(1, $datos["fecha_evento"]);
        $sql->bindValue(2, $datos["calendardbk"]);

        $sql->execute();

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

    public function DeleteEvent($id) 
    {
        $conectar = parent::conectar();

        $sql = "DELETE FROM calendario WHERE calendardbk = ?";

        $sql = $conectar->prepare($sql);

        $sql->bindValue(1, $id);

        $sql->execute();

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