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

class Gallery 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 $gallerycatlist;
        public function __construct()
        {
            parent::__construct();
            $this->load->model('Section', 'section_model');
            $this->menu = $this->section_model->buildTopMenuItem();
            $this->breadcrumbs = [];
            $this->load->model('GalleryContent', 'gallery_model');
            $this->gallerycatlist = $this->gallery_model->getGallerycontentsAll();
            $this->load->model('ContactDetails', 'contactdetails_model');
        }

        public function index()
	{

        $contactusdata = $this->contactdetails_model->getContactus();
		//$this->load->view('welcome_message');
            $this->breadcrumbs[] = array (
                'label' => '相片圖集',
                '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,
                'contactusdata' => $contactusdata,
                'session' => 'gallery',
                'gallerycatlist' => $this->gallerycatlist,
                'page' => 'index'
            ));
        }

        public function details()
	{

        $contactusdata = $this->contactdetails_model->getContactus();
            if (! $this->uri->segment(3)) {
                redirect('/gallery', 'refresh');
            }
            
            $param = urldecode($this->uri->segment(3));
            $gallerycontent=$this->gallery_model->getGallerycontents($param);    
                //$this->load->view('welcome_message');
            $this->breadcrumbs[] = array (
                'label' => '相片圖集',
                'link' => '/gallery'
            );
            $this->breadcrumbs[] = array (
                'label' => $param,
                'link' => ''
            );
            $laststate=$this->db->last_query();
            $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' => 'gallery',
                'contactusdata' =>$contactusdata,
                'gallerydata' =>$gallerycontent,
                'page' => 'details',
                // 'laststate' =>$laststate,
                'record' => array()
            ));
        }
        
}
