<?php
namespace App\Controllers\results;

use App\Controllers\BaseController;
use App\Models\results\M415Model;

class M415 extends BaseController
{
    private $model;
    public function __construct()
    {
        $this->model = new M415Model();
    }

    public function stats(): string
    {
        return view("pages/results/m415/stats", $this->data);
    }


    public function getResultList()
    {
        $data = [
            'sdate' => $this->request->getGet('sdate'),
            'edate' => $this->request->getGet('edate'),
        ];

        $totalCount = $this->model->getTotalCount($data);

        $datas = $this->model->getResultList($data);

        return $this->response->setJSON(body: [
            'recordsTotal' => $totalCount,
            'recordsFiltered' => $totalCount,
            'data' => $datas,
        ]);
    }

    // 엑셀 다운로드
    public function excel()
    {
        try {

            $data = [
                'sdate' => $this->request->getGet('sdate'),
                'edate' => $this->request->getGet('edate'),
            ];

            $datas = $this->model->getResultList($data);

            return $this->response->setJSON(body: [
                'data' => $datas,
            ]);

        } catch (\Exception $e) {
            $e->getPrevious()->getTraceAsString();
        }
    }
}