<?php

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

class Exercise extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Exercise_model');
    }

    public function listing() {
        $request = $this->input->get();
        $data = $this->Exercise_model->listing($request);
        echo json_encode($this->Exercise_model->build_datatables($request['draw'], $this->Exercise_model->totalCount(), $this->Exercise_model->filteredCount($request), $data), JSON_UNESCAPED_UNICODE);
    }

    public function getunits() {
        $courseId = $this->input->get('course_id');
        $units = $this->Exercise_model->getUnits($courseId);
        echo json_encode(['success' => true, 'data' => $units, JSON_UNESCAPED_UNICODE]);
    }

    public function getcourses() {
        $categoryId = $this->input->get('course_category_id');
        $subcategoryId = $this->input->get('course_subcategory_id');
        $data = $this->Exercise_model->getCourses($categoryId, $subcategoryId);
        echo json_encode(['success' => true, 'data' => $data, JSON_UNESCAPED_UNICODE]);
    }

    public function getfilteringdata(){
        $data['unit'] = $this->Exercise_model->getAllUnits();
        $data['course'] = $this->Exercise_model->getAllCourses();
        $data['teacher'] = $this->Exercise_model->getAllTeachers(); 
        echo json_encode(['success'=>true, 'data'=>$data, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getallunits() {
        $data = $this->Exercise_model->getAllUnits();
        echo json_encode(['success' => true, 'data' => $data, JSON_UNESCAPED_UNICODE]);
    }

    public function getallcourses() {
        $data = $this->Exercise_model->getAllCourses();
        echo json_encode(['success' => true, 'data' => $data, JSON_UNESCAPED_UNICODE]);
    }

    public function getallteachers() {
        $data = $this->Exercise_model->getAllTeachers();
        echo json_encode(['success' => true, 'data' => $data, JSON_UNESCAPED_UNICODE]);
    }

    public function detail() {
        $exId = $this->input->get('exId');
        $data = $this->Exercise_model->detail($exId);
        echo json_encode(['success' => true, 'data' => $data, JSON_UNESCAPED_UNICODE]);
    }

}
