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

class GalleryContent extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function getGallerycontents($param_var)
    {
        $this->db->from('nchmcblog_photo');
        
        // $this->db->order_by('rank');
        // $query = $this->db->get();
        // return $query->result();
        $this->db->select('nchmcblog_photo.ep_pic, nchmcblog_photo.ep_web');
        $this->db->where(array('nchmcblog_photo.show' => 1));
        $this->db->join('nchmcblog_photocat', 'nchmcblog_photocat.cat_id = nchmcblog_photo.ep_web') 
         ->where('nchmcblog_photocat.cp_cat_name', $param_var);
        // $this->db->where(array('id' => 1));
        $this->db->order_by('nchmcblog_photo.rank');
        $query = $this->db->get();
        return $query->result();
    }
    function getGallerycontentsAll()
    {
        $this->db->from('nchmcblog_photocat');
        $this->db->where(array('show' => 1));
        $this->db->order_by('rank');
        // $this->db->from('album');
        // $this->db->where(array('show' => 1));
        // $this->db->order_by('rank');
        $query = $this->db->get();
        return $query->result();
    }
    function getTopTenGallery()
    {
        $this->db->from('nchmcblog_photocat');
        
        // $this->db->order_by('rank');
        // $query = $this->db->get();
        // return $query->result();
        // $this->db->select('news_id, cp_subject, ep_date,ep_pic,cp_brief');
        $this->db->where(array('show' => 1));
        $this->db->limit(10,0);
        // $this->db->where(array('id' => 1));
        $this->db->order_by('rank');
        $query = $this->db->get();
        return $query->result();
    }
    // function getTopCourse()
    // {
    //     $this->db->from('nchmcblog_course');
        
    //     // $this->db->order_by('rank');
    //     // $query = $this->db->get();
    //     // return $query->result();
    //     $this->db->select('cp_subject');
    //     $this->db->where(array('ep_web'=>1,'show' => 1));
    //     // $this->db->where(array('id' => 1));
    //     $this->db->order_by('rank');
    //     $query = $this->db->get()->row();
    //     return $query;
    // }
    function buildTopMenuItem()
    {
        $menu = array();
        
        $result = $this->getSectionAll();
        foreach ($result as $row)
        {
            $menu[] = array(
                'name_zh' => $row->cp_name,
                'name_cn' => $row->sp_name,
                'name_en' => $row->ep_name,
                'link' => $row->link
            );
        }
        return $menu;
        
    }
}