Files
cm-ggotmaeule-backend/application/controllers/admin/contents/Crawlhistory.php

167 lines
6.7 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Crawlhistory class
*/
class Crawlhistory extends MY_Controller
{
/**
* 관리자 페이지 상의 현재 디렉토리입니다
* 페이지 이동시 필요한 정보입니다
*/
public $pagedir = 'contents/crawlhistory';
/**
* 모델을 로딩합니다
*/
protected $models = array('Crawl_list', 'Upload_file', 'Apps', 'Contents_category', 'Contents', 'Contents_tag', 'Crawl_history');
/**
* 이 컨트롤러의 메인 모델 이름입니다
*/
protected $modelname = 'Crawl_history_model';
/**
* 헬퍼를 로딩합니다
*/
protected $helpers = array('form', 'array');
function __construct()
{
parent::__construct();
/**
* 라이브러리를 로딩합니다
*/
$this->load->library(array('pagination', 'querystring'));
}
/**
* 목록을 가져오는 메소드입니다
*/
public function index()
{
$this->accesslevel->check_admin('read');
$view = array();
$view['view'] = array();
/**
* 페이지에 숫자가 아닌 문자가 입력되거나 1보다 작은 숫자가 입력되면 에러 페이지를 보여줍니다.
*/
$param =& $this->querystring;
$page = (((int) $this->input->get('page')) > 0) ? ((int) $this->input->get('page')) : 1;
$findex = $this->input->get('findex') ? $this->input->get('findex') : $this->{$this->modelname}->primary_key;
$forder = $this->input->get('forder', null, 'desc');
$sfield = $this->input->get('sfield', null, '');
$skeyword = $this->input->get('skeyword', null, '');
$per_page = admin_listnum();
$offset = ($page - 1) * $per_page;
/**
* 게시판 목록에 필요한 정보를 가져옵니다.
*/
$this->{$this->modelname}->allow_search_field = array('app_id', 'crawl_title'); // 검색이 가능한 필드
$this->{$this->modelname}->search_field_equal = array('app_id'); // 검색중 like 가 아닌 = 검색을 하는 필드
$this->{$this->modelname}->allow_order_field = array('crawl_id'); // 정렬이 가능한 필드
$where = array();
if ($this->input->get('app_id')) {
$where['crawl_history.app_id'] = $this->input->get('app_id');
}
if ($this->input->get('cat_id')) {
$where['crawl_history.cat_id'] = $this->input->get('cat_id');
}
if ($this->input->get('site_key')) {
$where['crawl_history.site_key'] = $this->input->get('site_key');
}
if ($this->input->get('crawl_category_name')) {
$where['crawl_list.crawl_category_name'] = $this->input->get('crawl_category_name');
}
if ($this->input->get('start_date')) {
$where['crawl_history.history_at >='] = $this->input->get('start_date');
}
if ($this->input->get('end_date')) {
$where['crawl_history.history_at <='] = $this->input->get('end_date');
}
$result = $this->Crawl_history_model->get_admin_list($per_page, $offset, $where, '', $findex, $forder, $sfield, $skeyword);
$list_num = $result['total_rows'] - ($page - 1) * $per_page;
if (element('list', $result)) {
foreach (element('list', $result) as $key => $val) {
$result['list'][$key]['num'] = $list_num--;
if (element('cat_id', $val)) {
$result['list'][$key]['category'] = $this->Contents_category_model->get_one(element('cat_id', $val));
$result['list'][$key]['origin_link'] = '';
if (element('site_type', $val) == '1') {
if (element('crawl_category', $val)) {
$result['list'][$key]['origin_link'] = 'http://m.blog.naver.com/PostList.nhn?blogId=' . element('site_key', $val) . '&categoryNo=' . element('crawl_category', $val);
} else {
$result['list'][$key]['origin_link'] = 'http://m.blog.naver.com/' . element('site_key', $val);
}
}
if (element('site_type', $val) == '2') {
$result['list'][$key]['origin_link'] = 'ttp://m.post.naver.com/my.nhn?memberNo=' . element('site_key', $val);
}
if (element('site_type', $val) == '3') {
if (element('crawl_category', $val)) {
$result['list'][$key]['origin_link'] = 'https://www.vingle.net/collections/' . element('crawl_category', $val);
} else {
$result['list'][$key]['origin_link'] = 'https://www.vingle.net/' . element('site_key', $val);
}
}
if (element('site_type', $val) == '4') {
$result['list'][$key]['origin_link'] = 'https://story.kakao.com/ch/' . element('site_key', $val);
}
}
}
}
$view['view']['data'] = $result;
$view['view']['applist'] = $this->Apps_model->app_list();
$view['view']['crawl_site'] = $this->Crawl_list_model->get_by_site();
$view['view']['crawl_category'] = $this->Crawl_list_model->get_by_category();
if ($this->input->get('app_id')) {
$view['view']['app_category'] = $this->Contents_category_model->cat_list($this->input->get('app_id'));
}
/**
* primary key 정보를 저장합니다
*/
$view['view']['primary_key'] = $this->{$this->modelname}->primary_key;
/**
* 페이지네이션을 생성합니다
*/
$config['base_url'] = admin_url($this->pagedir) . '?' . $param->replace('page');
$config['total_rows'] = $result['total_rows'];
$config['per_page'] = $per_page;
$this->pagination->initialize($config);
$view['view']['paging'] = $this->pagination->create_links();
$view['view']['page'] = $page;
/**
* 쓰기 주소, 삭제 주소등 필요한 주소를 구합니다
*/
$search_option = array('crawl_title' => '제목');
$view['view']['skeyword'] = ($sfield && array_key_exists($sfield, $search_option)) ? $skeyword : '';
$view['view']['search_option'] = search_option($search_option, $sfield);
$view['view']['listall_url'] = admin_url($this->pagedir);
$view['view']['write_url'] = admin_url($this->pagedir . '/write');
$view['view']['list_delete_url'] = admin_url($this->pagedir . '/listdelete/?' . $param->output());
/**
* 어드민 레이아웃을 정의합니다
*/
$layoutconfig = array('layout' => 'layout', 'skin' => 'index');
$view['layout'] = $this->layoutlib->admin($layoutconfig, $this->configlib->get_device_view_type());
$this->data = $view;
$this->layout = element('layout_skin_file', element('layout', $view));
$this->view = element('view_skin_file', element('layout', $view));
}
}