<?php
class RubroEmpresa
{
    public $id;
    public $rubro;
    public $fechaRegistro;

    function __construct()
    {
        !empty($this->fechaRegistro) && $this->fechaRegistro = date("d-m-Y h:i a", strtotime($this->fechaRegistro));
    }

    public static function obtenerTodos(): object
    {
        $db = obtenerConexion();

        $query = "SELECT * FROM general.view_rubrosEmpresa WHERE estado = 1";
        $stmt = $db->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);

        try {
            $stmt->execute();

            $data = $stmt->fetchAll(PDO::FETCH_CLASS, __CLASS__);

            return (object)[
                'message' => 'success',
                'data' => $data,
                'status' => 200
            ];
        } catch (PDOException $e) {
            return (object)[
                'message' => $e->getMessage(),
                'status' => 500
            ];
        }
    }
}
