<?php

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

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

class Unit extends CI_Controller {

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

    public function listing(){
        $request = $this->input->get();
        $data = $this->Unit_model->listing($request);
        echo json_encode($this->Unit_model->build_datatables($request['draw'], $this->Unit_model->totalCount(), $this->Unit_model->filteredCount($request), $data), JSON_UNESCAPED_UNICODE);
    }
    
    public function getallids(){
        $ids = $this->Unit_model->getAllIds();
//        echo json_encode(['success' => true, 'data' => $result], JSON_UNESCAPED_UNICODE);
        echo json_encode(['success'=>true, 'data'=>$ids, JSON_UNESCAPED_UNICODE]);
    }

    public function getcategories(){        
        $categories = $this->Unit_model->getCategories();
        echo json_encode(['success'=>true, 'data'=>$categories, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getsubcategories(){       
        $categoryId = $this->input->get('course_category_id');
        $subcategories = $this->Unit_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->Unit_model->getCourses($categoryId,$subcategoryId);        
        echo json_encode(['success'=>true, 'data'=>$data, JSON_UNESCAPED_UNICODE]);
    }
    
    public function getfilteringdata(){
		$request = $this->input->get();
        $data['course'] = $this->Unit_model->getAllCourses_filter($request['tenantno']);
        $data['category'] = $this->Unit_model->getAllCategories_filter(); 
        $data['subcategory'] = $this->Unit_model->getAllSubCategories_filter(); 
        echo json_encode(['success'=>true, 'data'=>$data, JSON_UNESCAPED_UNICODE]);
    }
}
