<?php

namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\Exceptions\PageNotFoundException;
use App\Models\Log\LogModel;

class LogFilter implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
    	//empty
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
    	//SIMPAN LOG------------------------------------------------------
        $id_user = session()->get('user')['id'];

        if ($id_user) {
            $logModel = new LogModel();
            $logModel->save([
                'id_user' => $id_user,
                'aksi' => $request->getMethod() . ' ' . $request->getURI()
            ]);
        }
        //END SIMPAN LOG--------------------------------------------------
    }
}