<?php
namespace App\Model;


class Auditoria extends GenericObject
{
    static $table_name = 'auditoria';

    static $primary_key = 'aud_codigo';

    public function cargar($data){
        $this->aud_msj = $data->mensaje;
        $this->aud_usu = $data->usuario;
        $this->aud_fecha = date("Y-m-d",strtotime(str_replace("/","-",$data->fecha)));
        $this->aud_hora = $data->hora;
    }

    public static function toJSON($result)
    {
        if ($result === null) return $result;
        $temp = array();
        if(!isset($result->aud_msj)){
            foreach($result as $item){
                $object = array(
                    "mensaje" => $item->aud_msj,
                    "usuario" => $item->aud_usu,
                    "fecha" => $item->aud_fecha,
                    "hora" => $item->aud_hora
                );
                $temp[] = $object;
            }
        }else{
            $temp = array(
                "mensaje" => $result->aud_msj,
                "usuario" => $result->aud_usu,
                "fecha" => $result->aud_fecha,
                "hora" => $result->aud_hora
            );
        }
        return json_encode($temp);
    }

}