<?php

class Event extends Conexion
{
    public function GetEvents()
    {
        $conectar = parent::conectar();
        parent::set_names();
        $sql = "SELECT * FROM eventos";
        $sql = $conectar->prepare($sql);
        $sql->execute();

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

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

        $sql = "INSERT INTO eventos (color_evento, titulo_evento) VALUES (?,?)";
        $sql = $conectar->prepare($sql);

        $sql->bindValue(1, $datos["color"]);
        $sql->bindValue(2, $datos["title"]);
        $sql->execute();

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

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

        $sql = "DELETE FROM eventos WHERE eventodbk = ?";
        $sql = $conectar->prepare($sql);

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

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

    public function Update($data) 
    {
        $conectar = parent::conectar();
        parent::set_names();

        $sql = "UPDATE eventos SET titulo_evento = ? WHERE eventodbk = ?";
        $sql = $conectar->prepare($sql);

        $sql->bindValue(1, $data["title"]);
        $sql->bindValue(2, $data["id"]);
        $sql->execute();

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