<?php

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

//require APPPATH . '/libraries/MY_Controller.php';
//use Restserver\Libraries\MY_Controller;

class Note extends CI_Controller {

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

    public function listing(){
        $request = $this->input->get();
        $data = $this->Note_model->listing($request);
        echo json_encode($this->Note_model->build_datatables($request['draw'], $this->Note_model->totalCount(), $this->Note_model->filteredCount($request), $data), JSON_UNESCAPED_UNICODE);
    }    
    
    public function getunits(){        
        $courseId = $this->input->get('course_id');
        $units = $this->Note_model->getUnits($courseId,$this->session->userdata('tenant_no'));
        echo json_encode(['success'=>true, 'data'=>$units, JSON_UNESCAPED_UNICODE]);
    }

    public function getcategories(){        
        $categories = $this->Note_model->getCategories();
        echo json_encode(['success'=>true, 'data'=>$categories, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getsubcategories(){       
        $categoryId = $this->input->get('course_category_id');
        $subcategories = $this->Note_model->getSubCategories($categoryId);
        echo json_encode(['success'=>true, 'data'=>$subcategories, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getcourses(){     
        $categoryId = $this->input->get('course_category_id');
        $subcategoryId = $this->input->get('course_subcategory_id');        
        $data = $this->Note_model->getCourses($categoryId,$subcategoryId);        
        echo json_encode(['success'=>true, 'data'=>$data, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getfilteringdata(){
		$request = $this->input->get();
        $data['unit'] = $this->Note_model->getAllUnits_filter($request['tenantno']);
        $data['course'] = $this->Note_model->getAllCourses_filter($request['tenantno']);
        $data['category'] = $this->Note_model->getAllCategories_filter(); 
        $data['subcategory'] = $this->Note_model->getAllSubCategories_filter(); 
        echo json_encode(['success'=>true, 'data'=>$data, JSON_UNESCAPED_UNICODE]);
    }
}
