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

class m_bbs_faq extends CI_Model{

	// 생성자, 해당 모델이 생성될때 항상 실행되는 초기화작업
	function __construct(){
		parent::__construct();

        $this->load->database();
        $this->load->library('session');
	}


	#---------------------------------------------------------------------------
    # PURPOSE :	list
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function bbs_faq_list($req_data){
        # request
        $offset                 = $req_data['offset'];
        $limit                  = $req_data['limit'];
        $search_type            = $req_data['search_type'];
        $search_keyword         = $req_data['search_keyword'];
        $faq_category_code1     = $req_data['faq_category_code1'];
        $faq_category_code2     = $req_data['faq_category_code2'];

        if($search_type!='' && $search_keyword != '')   $this->db->where($search_type.' like "%'.$search_keyword.'%"');
        if($faq_category_code1 !='')    $this->db->where('faq_category_code1', $faq_category_code1);
        if($faq_category_code2 !='')    $this->db->where('faq_category_code2', $faq_category_code2);

        $this->db->where('is_del', 'N');
        $this->db->from('bbs_faq');
        $this->db->limit($limit, $offset);
        $this->db->order_by('reg_date',  'desc');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	list - total count
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function bbs_faq_list_total_count($req_data){
        # request
        $search_type            = $req_data['search_type'];
        $search_keyword         = $req_data['search_keyword'];
        $faq_category_code1     = $req_data['faq_category_code1'];
        $faq_category_code2     = $req_data['faq_category_code2'];

        if($search_type!='' && $search_keyword != '')   $this->db->where($search_type.' like "%'.$search_keyword.'%"');
        if($faq_category_code1 !='')    $this->db->where('faq_category_code1', $faq_category_code1);
        if($faq_category_code2 !='')    $this->db->where('faq_category_code2', $faq_category_code2);

	    $this->db->where('is_del', 'N');
        $this->db->from('bbs_faq');
        $row = $this->db->count_all_results();

        return $row;
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	select
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function bbs_faq_select($idx){

	    $this->db->where('idx', $idx);
	    $this->db->where('is_del', 'N');
        $this->db->from('bbs_faq');
        $res = $this->db->get();
        $row = $res->row_array();

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	next_list
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function bbs_faq_next_list($req_data){
		# request
		$offset                 = $req_data['offset'];
		$limit                  = $req_data['limit'];
		$search_type            = $req_data['search_type'];
		$search_keyword         = $req_data['search_keyword'];
		$faq_category_code1     = $req_data['faq_category_code1'];
		$faq_category_code2     = $req_data['faq_category_code2'];
		$idx                    = $req_data['idx'];

		if($search_type!='' && $search_keyword != '')   $this->db->where($search_type.' like "%'.$search_keyword.'%"');
		if($faq_category_code1 !='')    $this->db->where('faq_category_code1', $faq_category_code1);
		if($faq_category_code2 !='')    $this->db->where('faq_category_code2', $faq_category_code2);

		$this->db->where('idx < '.$idx);
		$this->db->where('is_del', 'N');
		$this->db->from('bbs_faq');
		$this->db->limit($limit, $offset);
		$this->db->order_by('reg_date',  'desc');
		$res = $this->db->get();
		$row = $res->result_array();

		return $row;
	}

	function bbs_faq_other_list($req_data){
		# request
		$offset                 = $req_data['offset'];
		$limit                  = $req_data['limit'];
		$search_type            = $req_data['search_type'];
		$search_keyword         = $req_data['search_keyword'];
		$faq_category_code1     = $req_data['faq_category_code1'];
		$faq_category_code2     = $req_data['faq_category_code2'];
		$idx                    = $req_data['idx'];

		if($search_type!='' && $search_keyword != '')   $this->db->where($search_type.' like "%'.$search_keyword.'%"');
		if($faq_category_code1 !='')    $this->db->where('faq_category_code1', $faq_category_code1);
		if($faq_category_code2 !='')    $this->db->where('faq_category_code2', $faq_category_code2);

		$this->db->where('idx != '.$idx);
		$this->db->where('is_del', 'N');
		$this->db->from('bbs_faq');
		$this->db->limit($limit, $offset);
		$this->db->order_by('reg_date',  'desc');
		$res = $this->db->get();
		$row = $res->result_array();

		return $row;
	}






}
?>
