<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 25/12/2015
 * Time: 2:22 CH
 */
if (!defined('BASEPATH')) exit('No direct script access allowed');

class CmsRanking extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
        //
        $this->load->model('track_model');
        $this->load->model('report_views_daily_model');
        $this->load->model('report_views_weekly_model');
        $this->load->model('report_views_monthly_model');
    }

    public function listByDaily()
    {
        $this->_data['functionName'] = 'BXH theo ngày';
        $this->_data['action'] = 'listByDaily';
        $this->_data['titlePage'] = 'BXH theo ngày';
        $this->_data['loadPage'] = 'backend/cms_ranking/list_by_daily_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    public function listByDailyAjax()
    {
        $data = array();
        $fByName = $this->input->post('fByName');
        $pageId = $this->input->post('pageId');
        //
        $pageId = ($pageId == 0) ? 1 : $pageId;
        //
        $limit = 25;
        $offset = ($pageId - 1) * $limit;
        $data['offset'] = ($pageId - 1) * $limit;
        $totalRecord = $this->track_model->cmsCountAll($fByName);
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
        $data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
        //
        $this->load->view('backend/ajax/cms_ranking/list_by_daily_view', $data);
    }

    /**
     * BXH theo tuần ---------------------------------------------------------------------------------------------------
     */
    public function listByWeekly()
    {
        $this->_data['functionName'] = 'BXH theo tuần';
        $this->_data['action'] = 'listByDaily';
        $this->_data['titlePage'] = 'BXH theo tuần';
        $this->_data['loadPage'] = 'backend/cms_ranking/list_by_weekly_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    public function listByWeeklyAjax()
    {
        $data = array();
        $fByName = $this->input->post('fByName');
        $pageId = $this->input->post('pageId');
        //
        $pageId = ($pageId == 0) ? 1 : $pageId;
        //
        $limit = 25;
        $offset = ($pageId - 1) * $limit;
        $data['offset'] = ($pageId - 1) * $limit;
        $totalRecord = $this->track_model->cmsCountAll($fByName);
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
        $data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
        //
        $this->load->view('backend/ajax/cms_ranking/list_by_weekly_view', $data);
    }

    /**
     * BXH theo tháng --------------------------------------------------------------------------------------------------
     */
    public function listByMonthly()
    {
        $this->_data['functionName'] = 'BXH theo tháng';
        $this->_data['action'] = 'listByDaily';
        $this->_data['titlePage'] = 'BXH theo tháng';
        $this->_data['loadPage'] = 'backend/cms_ranking/list_by_monthly_view';
        $this->load->view('backend/admin_template_view', $this->_data);
    }

    public function listByMonthlyAjax()
    {
        $data = array();
        $fByName = $this->input->post('fByName');
        $pageId = $this->input->post('pageId');
        //
        $pageId = ($pageId == 0) ? 1 : $pageId;
        //
        $limit = 25;
        $offset = ($pageId - 1) * $limit;
        $data['offset'] = ($pageId - 1) * $limit;
        $totalRecord = $this->track_model->cmsCountAll($fByName);
        $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
        $data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
        //
        $this->load->view('backend/ajax/cms_ranking/list_by_monthly_view', $data);
    }

} 