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

class Course extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
         var $menu;
         var $default = '國際英語考試';

        
        public function __construct()
        {
            parent::__construct();
            $this->load->model('Section', 'section_model');
            $this->menu = $this->section_model->buildTopMenuItem();
            $this->breadcrumbs = [];

            $this->load->model('CourseContent', 'course_model');
        }

        public function index()
	{
            redirect ('/course/details/' . $this->default);
        }

        public function details()
	{
            if (! $this->uri->segment(3)) {
                redirect('/course', 'refresh');
            }
            
            $param = urldecode($this->uri->segment(3));
           
            $coursecontent=$this->course_model->getCoursecontents($param);
            $courselist=$this->course_model->getCoursecontentsAll();
            // $coursecontent=$this->course_model->getCoursecontentsAll();        
		//$this->load->view('welcome_message');
            $this->breadcrumbs[] = array (
                'label' => '課程介紹',
                'link' => '/course'
            );
            $this->breadcrumbs[] = array (
                'label' => $param,
                'link' => ''
            );
            $this->twig->display('main', array(
                'path' => array(
                    'vendor' => $this->config->item('vendor_path'),
                    'script' => $this->config->item('script_path'),
                    'css' => $this->config->item('css_path'),
                    'image' => $this->config->item('image_path')
                ),
                'breadcrumbs' => $this->breadcrumbs,
                'menus' => $this->menu,
                'session' => 'course',
                'coursedata'=>$coursecontent,
                'courselist'=>$courselist,
                'page' => 'details'
            ));
        }
        
}
