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

class m_partner extends CI_Model{

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

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


	#---------------------------------------------------------------------------
    # PURPOSE :	list
    # CREATE  :	2018-04-11
    #---------------------------------------------------------------------------
	function partner_list($req_data){
        # request
        $offset                 = $req_data['offset'];
        $limit                  = $req_data['limit'];
        $sort_column            = $req_data['sort_column'];
        $member_group_idx       = $req_data['member_group_idx'];

        $search_type = '';  $search_key = '';
        if(isset($req_data['search_type']) == true)     $search_type = $req_data['search_type'];
        if(isset($req_data['search_key']) == true)      $search_key = $req_data['search_key'];

        if($search_type!='' && $search_key !='')    $this->db->where($search_type, $search_key);


        $this->db->where('member_group_idx', $member_group_idx);
        $this->db->where('is_del', 'N');
        $this->db->from('partner');
        $this->db->limit($limit, $offset);
        $this->db->order_by($sort_column,  'desc');
        $this->db->order_by('display_sort',  'desc');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	list
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function partner_life_aritcle_count_list($req_data){
        # request
        $offset                 = $req_data['offset'];
        $limit                  = $req_data['limit'];
        $sort_column            = $req_data['sort_column'];
        $member_group_idx       = $req_data['member_group_idx'];
        
        //var_dump($req_data);

        $search_type = '';  $search_key = '';
        if(isset($req_data['search_type']) == true)     $search_type = $req_data['search_type'];
        if(isset($req_data['search_key']) == true)      $search_key = $req_data['search_key'];

        if($search_type!='' && $search_key !='')    $this->db->where($search_type, $search_key);

        $this->db->select('*, (select count(*) from life where is_del="N" and is_display ="Y" and partner.idx=life.partner_idx) as article_count');
        $this->db->where('member_group_idx', $member_group_idx);
        $this->db->where('is_del', 'N');
        $this->db->from('partner');
        $this->db->limit($limit, $offset);
        $this->db->order_by($sort_column,  'desc');
        $this->db->order_by('display_sort',  'desc');
        
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }



    #---------------------------------------------------------------------------
    # PURPOSE :	list - total count
    # CREATE  :	2018-04-11
    #---------------------------------------------------------------------------
	function partner_list_total_count($req_data){
	    # request
        $member_group_idx       = $req_data['member_group_idx'];

        $search_type = '';  $search_key = '';
        if(isset($req_data['search_type']) == true)     $search_type = $req_data['search_type'];
        if(isset($req_data['search_key']) == true)      $search_key = $req_data['search_key'];

        if($search_type!='' && $search_key !='')    $this->db->where($search_type, $search_key);

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

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	all list
    # CREATE  :	2018-04-28
    #---------------------------------------------------------------------------
	function partner_all_list($req_data){
        # request
        $sort_column            = $req_data['sort_column'];
        $member_group_idx       = $req_data['member_group_idx'];

        $this->db->where('member_group_idx', $member_group_idx);
        $this->db->where('is_del', 'N');
        $this->db->from('partner');
        $this->db->order_by($sort_column,  'asc');
        $this->db->order_by('reg_date',  'desc');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	select
    # CREATE  :	2018-04-28
    #---------------------------------------------------------------------------
	function partner_select($idx){


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

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	select
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function partner_join_category_channel_select($idx){


        $this->db->select('a.*, b.category_name, c.channel_name');
        $this->db->where('a.idx', $idx);
        $this->db->where('a.is_del', 'N');
        $this->db->where('b.is_del', 'N');
        $this->db->where('c.is_del', 'N');
        $this->db->from('partner as a');
        $this->db->join('category as b', 'a.category_idx=b.idx');
        $this->db->join('channel as c', 'a.channel_idx=c.idx');
        $res = $this->db->get();
        $row = $res->row_array();

        return $row;
    }




















}
?>
