<?php

use app\libraries\Export2Csv;

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Slip_signed_export extends MY_BackendController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->model('Slip_model');
        $this->load->model('Slip_signed_model');

        $id = $this->input->get('id');
        $slip = $this->Slip_model->get_slip($id);
        $params = $this->Slip_signed_model->datatable($id);
        /**
         * @var CI_DB_query_builder
         */
        $builder = $params['query'];
        $res = $builder->get()->result_array();

        $filename = sprintf("%s 簽署記錄.csv", $slip['title']);
        $e = new Export2Csv();
        return $e->run(
            [
                'id' => ['omitted' => true],
                'eng_name' => ['value' => '學生英文名稱'],
                'chi_name' => ['value' => '學生中文名稱'],
                'student_no' => ['value' => '學生編號'],
                'motherphone' => ['value' => '母親電話'],
                'fatherphone' => ['value' => '父親電話'],
                'guardianphone' => ['value' => '監護人電話'],
                'signed_status' => ['value' => '簽署狀態'],
                'signed_datetime' => ['value' => '簽署時間'],
                'attended' => ['value' => '出席'],
                'agreed' => ['value' => '同意'],
                'opted'  => ['value' => '是 / 否'],
            ],
            $res,
            $filename
        );
    }
}
