<?php

namespace App\Controllers;

use App\Models\Home_model;
use CodeIgniter\Database\Exceptions\DatabaseException;

class Home extends BaseController
{
    private $Home_model;
    public function __construct()
    {
        $this->Home_model = new Home_model();
    }
    public function maintenance()
    {
        return view('maintenance'); // Mengembalikan view 'maintenance'
    }
    public function notFound()
    {
        return view('404notfound'); // Mengembalikan view 'maintenance'
    }
    public function index(): string
    {

        $data = [
            'title' => 'Dashboard',
            'setting' => $this->appSetting(),
            'count_guru' => $this->Home_model->count_guru(),
            'count_siswa' => $this->Home_model->count_siswa(),
            'count_rombel' => $this->Home_model->count_rombel($this->appSetting()->tahunpelajaran),
            'count_penilaian' => $this->Home_model->count_penilaian($this->appSetting()->tahunpelajaran),
        ];
        return view('Admin/Home/index', $data);
    }
    public function getrombel()
    {
        $exec = $this->Home_model->get_all_Rombel($this->appSetting()->tahunpelajaran);
        $data['data'] = $exec;
        return $this->response->setJSON($data);
    }
    public function getlogs()
    {
        $exec = $this->Home_model->get_log();

        return $this->response->setJSON($exec);
    }
    public function getabsensi()
    {
        $exec = $this->Home_model->get_absensi($this->appSetting()->tahunpelajaran);

        return $this->response->setJSON($exec);
    }
    public function getperingkat()
    {
        $exec = $this->Home_model->get_peringkat($this->appSetting()->tahunpelajaran);

        return $this->response->setJSON($exec);
    }
}
