Files
2020-06-10 06:19:03 +09:00

351 lines
13 KiB
PHP
Executable File

<?
defined('BASEPATH') or exit('No direct script access allowed');
class m_life extends CI_Model
{
// 생성자, 해당 모델이 생성될때 항상 실행되는 초기화작업
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
}
// ---------------------------------------------------------------------------
// PURPOSE : life - list
// CREATE : 2018-04-11
// ---------------------------------------------------------------------------
function life_list($req_data)
{
// request
$offset = $req_data['offset'];
$limit = $req_data['limit'];
$sort_column = $req_data['sort_column'];
$start_date = '';
$end_date = '';
$search_type = '';
$search_key = '';
$search_keyword = '';
if (isset($req_data['start_date']) == true)
$start_date = $req_data['start_date'];
if (isset($req_data['end_date']) == true)
$end_date = $req_data['end_date'];
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 (isset($req_data['search_keyword']) == true)
$search_keyword = $req_data['search_keyword'];
if ($search_type == 'main_search' && $search_keyword != '') {
$keywordAsteriskRemoved = str_replace('*', '', $search_keyword);
$this->db->group_start()
->like('a.title', $keywordAsteriskRemoved)
// ->or_like('a.content', $keywordAsteriskRemoved)
// ->or_like('a.tag', $keywordAsteriskRemoved)
->group_end();
// $this->db->where("match(a.title, a.content, a.tag) against('" . $search_keyword . "' in boolean mode)");
}
if ($search_type == 'main_search_and_video_url' && $search_keyword != '') {
$this->db->where("match(a.title, a.content, a.tag) against('" . $search_keyword . "' in boolean mode)");
$this->db->where('a.video_url!=', '');
}
if ($search_type != '' && $search_key != '')
$this->db->where('a.' . $search_type, $search_key);
if ($start_date != '')
$this->db->where('a.display_date >=', $start_date);
if ($end_date != '')
$this->db->where('a.display_date <=', $end_date);
$this->db->select('a.*, "3" as content_type, b.partner_img, (select category_name from category where a.category_idx = idx) as category_name');
$this->db->where('a.is_del', 'N');
// 크맵TV, 기도공감, 성경지식인, 자료실, 라이프에 연결된 채널이 은혜에서 안 보이게 설정
// $this->db->where_not_in('a.channel_idx', array(8 ,51, 42, 43, 44, 45, 49, 18, 46, 47, 50));
$this->db->where('a.is_display', 'Y');
$this->db->from('life as a');
$this->db->join('partner as b', 'a.partner_idx=b.idx');
$this->db->limit($limit, $offset);
$this->db->order_by('a.' . $sort_column, 'desc');
$this->db->order_by('a.display_date', 'desc');
$res = $this->db->get();
$row = $res->result_array();
// echo $this->db->last_query();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : life - list - total count
// CREATE : 2018-04-11
// ---------------------------------------------------------------------------
function life_list_total_count($req_data)
{
$start_date = '';
$end_date = '';
$search_type = '';
$search_key = '';
if (isset($req_data['start_date']) == true)
$start_date = $req_data['start_date'];
if (isset($req_data['end_date']) == true)
$end_date = $req_data['end_date'];
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 (isset($req_data['search_keyword']) == true)
$search_keyword = $req_data['search_keyword'];
if ($start_date != '')
$this->db->where('display_date >=', $start_date);
if ($end_date != '')
$this->db->where('display_date <=', $end_date);
if ($search_type != '' && $search_key != '')
$this->db->where($search_type, $search_key);
if ($search_type == 'main_search' && $search_keyword != '')
$this->db->where("match(title, content, tag) against('" . $search_keyword . "' in boolean mode)");
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$this->db->where_not_in('channel_idx', array(
8,
51,
42,
43,
44,
45,
49,
18,
46,
47,
50
));
$row = $this->db->count_all_results();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : join select
// CREATE : 2018-04-11
// ---------------------------------------------------------------------------
function life_join_editor_category_channel_select($idx)
{
$this->db->select('a.*, b.partner_img, c.category_name, d.channel_name, d.main_img as channel_main_img');
$this->db->where('a.idx', $idx);
$this->db->where('a.is_del', 'N');
$this->db->where('c.is_del', 'N');
$this->db->where('d.is_del', 'N');
$this->db->where('a.is_display', 'Y');
$this->db->from('life as a');
$this->db->join('partner as b', 'a.partner_idx=b.idx');
$this->db->join('category as c', 'a.category_idx=c.idx');
$this->db->join('channel as d', 'a.channel_idx=d.idx');
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : prev select
// CREATE : 2018-04-11
// ---------------------------------------------------------------------------
function life_prev_select($idx)
{
$this->db->where('idx <', $idx);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$this->db->order_by('display_date', 'desc');
$this->db->limit(1);
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : next select
// CREATE : 2018-04-11
// ---------------------------------------------------------------------------
function life_next_select($idx)
{
$this->db->where('idx >', $idx);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->order_by('display_date', 'asc');
$this->db->from('life');
$this->db->limit(1);
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : update
// CREATE : 2018-04-17
// ---------------------------------------------------------------------------
function life_like_count_update($req_data)
{
// request
$idx = $req_data['idx'];
$value = $req_data['value'];
$sql = "update life
set like_count = like_count + " . $value . "
where idx= " . $idx;
$row = $this->db->query($sql);
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : select
// CREATE : 2018-04-17
// ---------------------------------------------------------------------------
function life_select($idx)
{
$this->db->select('*, (select category_name from category where life.category_idx = idx) as category_name');
$this->db->where('idx', $idx);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : select
// CREATE : 2018-04-17
// ---------------------------------------------------------------------------
function life_select_idx($idx)
{
$this->db->where('idx', $idx);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : hit +1 update
// CREATE : 2018-04-26
// ---------------------------------------------------------------------------
function life_hit_count_update($idx)
{
$sql = "update life
set hit_count = hit_count + 1
where idx= " . $idx;
$row = $this->db->query($sql);
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : update
// CREATE : 2018-04-28
// ---------------------------------------------------------------------------
function life_share_count_update($req_data)
{
// request
$idx = $req_data['idx'];
$value = $req_data['value'];
$sql = "update life
set share_count = share_count + " . $value . "
where idx= " . $idx;
$row = $this->db->query($sql);
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : life where channel_idx
// CREATE : 2018-05-07
// ---------------------------------------------------------------------------
function life_where_channel_idx_list_limit1($req_data)
{
// request
$channel_idx = $req_data['channel_idx'];
$this->db->where('channel_idx', $channel_idx);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$this->db->limit(1, 0);
$this->db->order_by('display_date', 'desc');
$res = $this->db->get();
$row = $res->row_array();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : life where now_date
// CREATE : 2018-05-07
// ---------------------------------------------------------------------------
function life_where_display_date_count($req_data)
{
// request
$reg_date = $req_data;
$this->db->where('display_date >=', $reg_date);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$row = $this->db->count_all_results();
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : comment_count +1 update
// CREATE : 2018-05-11
// ---------------------------------------------------------------------------
function life_comment_count_update($idx)
{
$sql = "update life
set comment_count = comment_count + 1
where idx= " . $idx;
$row = $this->db->query($sql);
return $row;
}
// ---------------------------------------------------------------------------
// PURPOSE : life where now_date + channle_idx
// CREATE : 2018-05-30
// ---------------------------------------------------------------------------
function life_where_display_date_channel_idx_count($req_data)
{
// request
$now_date = $req_data['now_date'];
$channel_idx = $req_data['channel_idx'];
$this->db->where('channel_idx', $channel_idx);
$this->db->where('display_date >=', $now_date);
$this->db->where('is_del', 'N');
$this->db->where('is_display', 'Y');
$this->db->from('life');
$row = $this->db->count_all_results();
return $row;
}
}
?>