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

class m_relation_article extends CI_Model{

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

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


    #---------------------------------------------------------------------------
    # PURPOSE :	관련기사 insert
    # CREATE  :	2018-03-06
    #---------------------------------------------------------------------------
	function relation_article_insert($req_data){
        # request
        $content_idx        = $req_data['content_idx'];
        $content_type       = $req_data['content_type'];
        $relation_idxs      = $req_data['relation_idxs'];

        $user_id    = $this->session->userdata('Adm_Id');
        $now_date   = date("Y-m-d H:i:s");

        $i = 0;
        $arr_word = array();
        foreach($relation_idxs as $val) {
            $arr_word[$i]['content_idx']            = $content_idx;
            $arr_word[$i]['content_type']           = $content_type;
            $arr_word[$i]['relation_article_idx']   = $val;
            $arr_word[$i]['reg_id']                 = $user_id;
            $arr_word[$i]['reg_date']               = $now_date;
            $i++;
        }
        $row = $this->db->insert_batch('relation_article', $arr_word);
        return $row;

    }



    #---------------------------------------------------------------------------
    # PURPOSE :	delete
    # CREATE  : 2018-03-11
    #---------------------------------------------------------------------------
	function relation_article_delete($req_data){
        # request
	    $content_idx        = $req_data['content_idx'];
        $content_type       = $req_data['content_type'];


        $delete_data = array('content_idx' => $content_idx,
                             'content_type' => $content_type
        );
        $row = $this->db->delete('relation_article', $delete_data);

        return $row;

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	arr delete
    # CREATE  : 2018-03-11
    #---------------------------------------------------------------------------
	function relation_article_arr_delete($req_data){
        # request
	    $content_idx        = $req_data['content_idx'];
        $content_type       = $req_data['content_type'];

        $delete_data = array();
        foreach ($content_idx as $val) {
            $delete_data = array('content_idx' => $val, 'content_type' => $content_type);
            $this->db->delete('relation_article', $delete_data);
        }
        

    }




    #---------------------------------------------------------------------------
    # PURPOSE :	count
    # CREATE  :	2018-03-11
    #---------------------------------------------------------------------------
	function relation_article_count($req_data){
	    # request
	    $content_idx        = $req_data['content_idx'];
        $content_type       = $req_data['content_type'];

        $this->db->where('content_idx', $content_idx);
        $this->db->where('content_type', $content_type);
        $this->db->from('relation_article');
        $row = $this->db->count_all_results();

        return $row;
    }


}
?>
