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

class m_spam extends CI_Model{

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

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


	#---------------------------------------------------------------------------
    # PURPOSE :	where comment_idx list
    # CREATE  :	2018-03-28
    #---------------------------------------------------------------------------
	function spam_where_comment_idx_list($req_data){
        # request
        $comment_idx    = $req_data['comment_idx'];
        $reason_type    = $req_data['reason_type'];

        if($reason_type!='')    $this->db->where('reason_type', $reason_type);
        $this->db->where('comment_idx', $comment_idx);
        $this->db->from('spam');
        $this->db->order_by('idx', 'asc');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE : reason_type group by count
    # CREATE  :	2018-03-28
    #---------------------------------------------------------------------------
	function spam_where_comment_idx_reason_type_group_by_count($req_data){
	    # request
        $comment_idx    = $req_data['comment_idx'];
        $reason_type    = $req_data['reason_type'];

        $this->db->select('reason_type, count(reason_type) as cnt');
        if($reason_type!='')    $this->db->where('reason_type', $reason_type);
	    $this->db->where('comment_idx', $comment_idx);
	    $this->db->group_by("reason_type");
        $this->db->from('spam');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	list
    # CREATE  :	2018-03-28
    #---------------------------------------------------------------------------
	function spam_where_block_list($req_data){
        # request
        $content_type       = $req_data['content_type'];
        $block_call_count   = $req_data['block_call_count'];
        
        $sql = "select comment_idx, count(*) as cnt 
                  from spam
                 where content_type = '".$content_type."' and is_blind = 'N'
                 group by comment_idx having count(*) >= ".$block_call_count;
        $res = $this->db->query($sql);
        $row = $res->result_array();

        return $row;
    }



    #---------------------------------------------------------------------------
    # PURPOSE :	is_blind update
    # CREATE  :	2018-02-22
    #---------------------------------------------------------------------------
	function spam_is_blind_where_comment_idx_update($comment_idx){

        $user_id            = 'system';
        $now_date           = date("Y-m-d H:i:s");

        $update_data = array('is_blind' => 'Y');
        $this->db->where('is_blind', 'N');
        $this->db->where('comment_idx', $comment_idx);
        $row = $this->db->update('spam', $update_data);
        return $row;

    }










}
?>



