Commit 58d59362 by Trần Văn Minh

hiển thị danh sách bảng xếp hạng theo ngày, tuần, tháng

parent ff73b82f
......@@ -6,7 +6,7 @@
* Time: 2:22 CH
*/
if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/PHPExcel.php";
class CmsRanking extends CI_Controller
{
public function __construct()
......@@ -37,12 +37,12 @@ class CmsRanking extends CI_Controller
//
$pageId = ($pageId == 0) ? 1 : $pageId;
//
$limit = 25;
$limit = 100;
$offset = ($pageId - 1) * $limit;
$data['offset'] = ($pageId - 1) * $limit;
$totalRecord = $this->track_model->cmsCountAll($fByName);
$totalRecord = $this->report_views_daily_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
$data['listData'] = $this->report_views_daily_model->cmsGetPagination($limit, $offset, $fByName);
//
$this->load->view('backend/ajax/cms_ranking/list_by_daily_view', $data);
}
......@@ -67,13 +67,15 @@ class CmsRanking extends CI_Controller
//
$pageId = ($pageId == 0) ? 1 : $pageId;
//
$limit = 25;
$limit = 100;
$offset = ($pageId - 1) * $limit;
$data['offset'] = ($pageId - 1) * $limit;
$totalRecord = $this->track_model->cmsCountAll($fByName);
$totalRecord = $this->report_views_weekly_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
$data['listData'] = $this->report_views_weekly_model->cmsGetPagination($limit, $offset, $fByName);
//
// print_r($fByName);
$this->load->view('backend/ajax/cms_ranking/list_by_weekly_view', $data);
}
......@@ -97,14 +99,67 @@ class CmsRanking extends CI_Controller
//
$pageId = ($pageId == 0) ? 1 : $pageId;
//
$limit = 25;
$limit = 100;
$offset = ($pageId - 1) * $limit;
$data['offset'] = ($pageId - 1) * $limit;
$totalRecord = $this->track_model->cmsCountAll($fByName);
$totalRecord = $this->report_views_monthly_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->track_model->cmsGetPagination($limit, $offset, $fByName);
$data['listData'] = $this->report_views_monthly_model->cmsGetPagination($limit, $offset, $fByName);
//
$this->load->view('backend/ajax/cms_ranking/list_by_monthly_view', $data);
}
public function exportExcel() {
$data = array();
$fByName = $this->input->post('fByName');
//
print_r($fByName);
$limit = 100;
$data = $this->report_views_monthly_model->cmsGetPagination($limit, '', $fByName);
//Khởi tạo đối tượng
$excel = new PHPExcel();
//Chọn trang cần ghi (là số từ 0->n)
$excel->setActiveSheetIndex(0);
//Tạo tiêu đề cho trang. (có thể không cần)
$excel->getActiveSheet()->setTitle('demo ghi dữ liệu');
//Xét chiều rộng cho từng, nếu muốn set height thì dùng setRowHeight()
$excel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$excel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$excel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
//Xét in đậm cho khoảng cột
$excel->getActiveSheet()->getStyle('A1:C1')->getFont()->setBold(true);
//Tạo tiêu đề cho từng cột
//Vị trí có dạng như sau:
/**
* |A1|B1|C1|..|n1|
* |A2|B2|C2|..|n1|
* |..|..|..|..|..|
* |An|Bn|Cn|..|nn|
*/
$excel->getActiveSheet()->setCellValue('A1', 'Tên Bài Hát');
$excel->getActiveSheet()->setCellValue('B1', 'Ca Sĩ');
$excel->getActiveSheet()->setCellValue('C1', 'Tổng điểm');
// thực hiện thêm dữ liệu vào từng ô bằng vòng lặp
// dòng bắt đầu = 2
$numRow = 2;
foreach ($data as $row) {
$excel->getActiveSheet()->setCellValue('A' . $numRow, $row['name_song']);
$excel->getActiveSheet()->setCellValue('B' . $numRow, $row['all_name']);
$excel->getActiveSheet()->setCellValue('C' . $numRow, $row['total_point']);
$numRow++;
}
// Khởi tạo đối tượng PHPExcel_IOFactory để thực hiện ghi file
// ở đây mình lưu file dưới dạng excel2007header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=$fByName");
PHPExcel_IOFactory::createWriter($excel, 'Excel5')->save('php://output');
}
}
\ No newline at end of file
......@@ -13,12 +13,6 @@ class Report_views_daily_model extends CI_Model
{
$this->db->select('COUNT(*) AS totalResults');
$this->db->from($this->_table);
if ($name != null) {
$this->db->like('title', $name, 'both');
$this->db->or_like('description', $name, 'both');
$this->db->or_like('slug', $name, 'both');
$this->db->or_like('tag', $name, 'both');
}
$query = $this->db->get();
$result = $query->result_array();
if ($result) {
......@@ -30,20 +24,36 @@ class Report_views_daily_model extends CI_Model
public function cmsGetPagination($record, $start, $name = null)
{
$this->db->select($this->_table . '.*, u1.full_name AS singer_name, u2.full_name AS composer_name, track_user.name AS singer_name2, track_artists.name AS composer_name2');
print_r($name);
$this->db->select($this->_table . '.*, u1.full_name AS singer_name, track_user.name AS singer_name2,
tracks.title AS name_song, GROUP_CONCAT(track_user.`name` SEPARATOR ",") AS all_name, tracks.art AS art');
$this->db->from($this->_table);
$this->db->join('track_user', 'track_user.track_id = tracks.id', 'left');
$this->db->join('track_artists', 'track_artists.track_id = tracks.id', 'left');
$this->db->join('track_user', 'track_user.track_id = report_views_daily.track_id', 'left');
$this->db->join('tracks', 'tracks.id = report_views_daily.track_id', 'left');
$this->db->join('users u1', 'u1.id = track_user.user_id', 'left');
$this->db->join('users u2', 'u2.id = track_artists.user_id', 'left');
if ($name != null) {
$this->db->like('tracks.title', $name, 'both');
$this->db->or_like('tracks.description', $name, 'both');
$this->db->or_like('tracks.slug', $name, 'both');
$this->db->or_like('tracks.tag', $name, 'both');
$data = explode('-', $name);
$this->db->where('day', $data[0]);
$this->db->where('month', $data[1]);
$this->db->where('year', $data[2]);
}
$this->db->order_by($this->_table . '.title', 'asc');
$this->db->limit($record, $start);
$this->db->group_by('report_views_daily.id');
$this->db->order_by($this->_table . '.total_point', 'desc');
$this->db->limit($record);
$query = $this->db->get();
return $query->result_array();
}
public function selectSearch() {
$this->db->select('day,month, year');
$this->db->from($this->_table);
$this->db->distinct($this->_table . '.day');
$this->db->order_by( $this->_table . '.year desc');
$this->db->order_by( $this->_table . '.month desc');
$this->db->order_by( $this->_table . '.day desc');
$this->db->limit(15);
$query = $this->db->get();
return $query->result_array();
......
......@@ -13,12 +13,6 @@ class Report_views_monthly_model extends CI_Model
{
$this->db->select('COUNT(*) AS totalResults');
$this->db->from($this->_table);
if ($name != null) {
$this->db->like('title', $name, 'both');
$this->db->or_like('description', $name, 'both');
$this->db->or_like('slug', $name, 'both');
$this->db->or_like('tag', $name, 'both');
}
$query = $this->db->get();
$result = $query->result_array();
if ($result) {
......@@ -30,23 +24,48 @@ class Report_views_monthly_model extends CI_Model
public function cmsGetPagination($record, $start, $name = null)
{
$this->db->select($this->_table . '.*, u1.full_name AS singer_name, u2.full_name AS composer_name, track_user.name AS singer_name2, track_artists.name AS composer_name2');
$this->db->select($this->_table . '.*, u1.full_name AS singer_name,
track_user.name AS singer_name2, tracks.title AS name_song,
GROUP_CONCAT(track_user.`name` SEPARATOR ",") AS all_name, tracks.art AS art');
$this->db->from($this->_table);
$this->db->join('track_user', 'track_user.track_id = tracks.id', 'left');
$this->db->join('track_artists', 'track_artists.track_id = tracks.id', 'left');
$this->db->join('track_user', 'track_user.track_id = reports_views_monthly.track_id', 'left');
$this->db->join('tracks', 'tracks.id = reports_views_monthly.track_id', 'left');
$this->db->join('users u1', 'u1.id = track_user.user_id', 'left');
$this->db->join('users u2', 'u2.id = track_artists.user_id', 'left');
if ($name != null) {
$this->db->like('tracks.title', $name, 'both');
$this->db->or_like('tracks.description', $name, 'both');
$this->db->or_like('tracks.slug', $name, 'both');
$this->db->or_like('tracks.tag', $name, 'both');
if($name != null) {
$data = explode('-', $name);
$this->db->where('month', $data[0]);
$this->db->where('year', $data[1]);
} else {
// $this->db->select('month, year');
// $this->db->from($this->_table);
// $this->db->distinct($this->_table . '.month');
// $this->db->order_by( $this->_table . '.year desc');
// $this->db->order_by( $this->_table . '.month desc');
// $this->db->limit(1);
// $query = $this->db->get();
// $data = $query->result_array();
// $this->db->where('month', $data[0]['month']);
// $this->db->where('year', $data[0]['year']);
}
$this->db->order_by($this->_table . '.title', 'asc');
$this->db->limit($record, $start);
$this->db->group_by('reports_views_monthly.id');
$this->db->order_by($this->_table . '.total_point', 'desc');
// $this->db->order_by($this->_table . '.title', 'asc');
$this->db->limit($record);
$query = $this->db->get();
return $query->result_array();
}
public function selectSearch() {
$this->db->select('month, year');
$this->db->from($this->_table);
$this->db->distinct($this->_table . '.month');
$this->db->order_by( $this->_table . '.year desc');
$this->db->order_by( $this->_table . '.month desc');
$this->db->limit(3);
$query = $this->db->get();
return $query->result_array();
}
}
\ No newline at end of file
......@@ -13,12 +13,12 @@ class Report_views_weekly_model extends CI_Model
{
$this->db->select('COUNT(*) AS totalResults');
$this->db->from($this->_table);
if ($name != null) {
$this->db->like('title', $name, 'both');
$this->db->or_like('description', $name, 'both');
$this->db->or_like('slug', $name, 'both');
$this->db->or_like('tag', $name, 'both');
}
// if ($name != null) {
// $this->db->like('title', $name, 'both');
// $this->db->or_like('description', $name, 'both');
// $this->db->or_like('slug', $name, 'both');
// $this->db->or_like('tag', $name, 'both');
// }
$query = $this->db->get();
$result = $query->result_array();
if ($result) {
......@@ -30,20 +30,31 @@ class Report_views_weekly_model extends CI_Model
public function cmsGetPagination($record, $start, $name = null)
{
$this->db->select($this->_table . '.*, u1.full_name AS singer_name, u2.full_name AS composer_name, track_user.name AS singer_name2, track_artists.name AS composer_name2');
$this->db->select($this->_table . '.*, u1.full_name AS singer_name, track_user.name AS singer_name2,
tracks.title AS name_song, GROUP_CONCAT(track_user.`name` SEPARATOR ",") AS all_name, tracks.art AS art');
$this->db->from($this->_table);
$this->db->join('track_user', 'track_user.track_id = tracks.id', 'left');
$this->db->join('track_artists', 'track_artists.track_id = tracks.id', 'left');
$this->db->join('track_user', 'track_user.track_id = report_views_weekly.track_id', 'left');
$this->db->join('tracks', 'tracks.id = report_views_weekly.track_id', 'left');
$this->db->join('users u1', 'u1.id = track_user.user_id', 'left');
$this->db->join('users u2', 'u2.id = track_artists.user_id', 'left');
if ($name != null) {
$this->db->like('tracks.title', $name, 'both');
$this->db->or_like('tracks.description', $name, 'both');
$this->db->or_like('tracks.slug', $name, 'both');
$this->db->or_like('tracks.tag', $name, 'both');
$data = explode('-', $name);
$this->db->where('week', $data[0]);
$this->db->where('year', $data[1]);
}
$this->db->order_by($this->_table . '.title', 'asc');
$this->db->limit($record, $start);
$this->db->group_by('report_views_weekly.id');
$this->db->order_by($this->_table . '.total_point', 'desc');
$this->db->limit($record);
$query = $this->db->get();
return $query->result_array();
}
public function selectSearch() {
$this->db->select('week, year');
$this->db->from($this->_table);
$this->db->distinct($this->_table . '.week');
$this->db->order_by( $this->_table . '.year desc');
$this->db->order_by( $this->_table . '.week desc');
$this->db->limit(15);
$query = $this->db->get();
return $query->result_array();
......
......@@ -4,6 +4,7 @@
<tr>
<th style="text-align: center">TT</th>
<th style="text-align: center">#ID</th>
<th style="text-align: center">Ảnh</th>
<th style="text-align: center">Tên bài hát</th>
<th style="text-align: center">Ca sĩ</th>
<th style="text-align: center">Nhạc sĩ</th>
......@@ -15,9 +16,10 @@
<tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['id']; ?></td>
<td style="text-align: left"><?php echo $data['title']; ?></td>
<td style="text-align: left"><?php echo ($data['singer_name']) ? $data['singer_name'] : $data['singer_name2']; ?></td>
<td style="text-align: left"><?php echo ($data['composer_name']) ? $data['composer_name'] : $data['composer_name2']; ?></td>
<td style="text-align: center"><img src="<?php echo base_url($data['art']); ?>"></td>
<td style="text-align: left"><?php echo $data['name_song']; ?></td>
<td style="text-align: left"><?php echo $data['all_name']; ?></td>
<td style="text-align: left"><?php echo $data['total_point']; ?></td>
<td style="text-align: center">
<a href="<?php echo base_url().'backend/cmsTrack/editTrack/'.$data['id']; ?>" title="Xem chi tiết">
<i class="ace-icon fa fa-pencil bigger-130"></i>
......
......@@ -4,9 +4,10 @@
<tr>
<th style="text-align: center">TT</th>
<th style="text-align: center">#ID</th>
<th style="text-align: center">Ảnh</th>
<th style="text-align: center">Tên bài hát</th>
<th style="text-align: center">Ca sĩ</th>
<th style="text-align: center">Nhạc sĩ</th>
<th style="text-align: center">Tổng điểm</th>
<th style="text-align: center">Xử lý</th>
</tr>
</thead>
......@@ -15,9 +16,10 @@
<tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['id']; ?></td>
<td style="text-align: left"><?php echo $data['title']; ?></td>
<td style="text-align: left"><?php echo ($data['singer_name']) ? $data['singer_name'] : $data['singer_name2']; ?></td>
<td style="text-align: left"><?php echo ($data['composer_name']) ? $data['composer_name'] : $data['composer_name2']; ?></td>
<td style="text-align: center"><img src="<?php echo base_url($data['art']); ?>"></td>
<td style="text-align: left"><?php echo $data['name_song']; ?></td>
<td style="text-align: left"><?php echo $data['all_name']; ?></td>
<td style="text-align: left"><?php echo $data['total_point']; ?></td>
<td style="text-align: center">
<a href="<?php echo base_url().'backend/cmsTrack/editTrack/'.$data['id']; ?>" title="Xem chi tiết">
<i class="ace-icon fa fa-pencil bigger-130"></i>
......@@ -34,4 +36,4 @@
</table>
</div>
<!-- /.row -->
<div style="text-align: center;"><?php echo $pagination; ?></div>
\ No newline at end of file
<!-- <div style="text-align: center;"><?php echo $pagination; ?></div> -->
\ No newline at end of file
......@@ -4,9 +4,10 @@
<tr>
<th style="text-align: center">TT</th>
<th style="text-align: center">#ID</th>
<th style="text-align: center">Ảnh</th>
<th style="text-align: center">Tên bài hát</th>
<th style="text-align: center">Ca sĩ</th>
<th style="text-align: center">Nhạc sĩ</th>
<th style="text-align: center">Tổng điểm</th>
<th style="text-align: center">Xử lý</th>
</tr>
</thead>
......@@ -15,9 +16,10 @@
<tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['id']; ?></td>
<td style="text-align: left"><?php echo $data['title']; ?></td>
<td style="text-align: left"><?php echo ($data['singer_name']) ? $data['singer_name'] : $data['singer_name2']; ?></td>
<td style="text-align: left"><?php echo ($data['composer_name']) ? $data['composer_name'] : $data['composer_name2']; ?></td>
<td style="text-align: center"><img src="<?php echo base_url($data['art']); ?>"></td>
<td style="text-align: left"><?php echo $data['name_song']; ?></td>
<td style="text-align: left"><?php echo $data['all_name']; ?></td>
<td style="text-align: left"><?php echo $data['total_point']; ?></td>
<td style="text-align: center">
<a href="<?php echo base_url().'backend/cmsTrack/editTrack/'.$data['id']; ?>" title="Xem chi tiết">
<i class="ace-icon fa fa-pencil bigger-130"></i>
......@@ -34,4 +36,4 @@
</table>
</div>
<!-- /.row -->
<div style="text-align: center;"><?php echo $pagination; ?></div>
\ No newline at end of file
<!-- <div style="text-align: center;"><?php echo $pagination; ?></div> -->
\ No newline at end of file
......@@ -24,11 +24,21 @@
<div class="row">
<?php echo form_open(base_url().'backend/cmsRanking/listByDailyAjax'); ?>
<div class="col-lg-3">
<input
class="form-control" type="text"
name="input-name"
id="input-name"
placeholder="Nhập tên bài hát..."/>
<select class="form-control" name="input-name" id="input-name">
<?php
$listSearch= $this->report_views_daily_model->selectSearch();
if ($listSearch == array()) {
?>
<option value = "">None</option>
<?php
} else
foreach ($listSearch as $data):
?>
<option value = "<?php echo $data['day'].'-'.$data['month'].'-'.$data['year']; ?>">Ngày<?php echo $data['day']; ?>/ <?php echo $data['month']; ?>/ <?php echo $data['year']; ?></option>
<?php
endforeach;
?>
</select>
</div>
<div class="col-lg-1">
<button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
......@@ -53,7 +63,7 @@
// Tìm kiếm theo cú pháp
var oldTimeout2 = '';
$('#input-name').keyup(function(){
$('#input-name').change(function(){
clearTimeout(oldTimeout2);
oldTimeout2 = setTimeout(function(){
loadDataByAjaxFromInput(url);
......
......@@ -24,16 +24,26 @@
<div class="row">
<?php echo form_open(base_url().'backend/cmsRanking/listByMonthlyAjax'); ?>
<div class="col-lg-3">
<input
<select class="form-control" name="input-name" id="input-name">
<?php
$listSearch= $this->report_views_monthly_model->selectSearch();
foreach ($listSearch as $data):
?>
<option value = "<?php echo $data['month'].'-'.$data['year']; ?>">Tháng <?php echo $data['month']; ?>/<?php echo $data['year']; ?></option>
<?php
endforeach;
?>
</select>
<!-- <input
class="form-control" type="text"
name="input-name"
id="input-name"
placeholder="Nhập tên bài hát..."/>
placeholder="Nhập tên bài hát..."/> -->
</div>
<?php echo form_close(); ?>
<div class="col-lg-1">
<button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
<button class="btn btn-sm btn-default" id="excel">Xuất Excel</button>
</div>
<?php echo form_close(); ?>
</div>
<!-- /.row -->
<div class="space-6"></div>
......@@ -50,25 +60,43 @@
//Thuc hien viec ve bieu do$data
$(document).ready(function() {
var url = '<?php echo base_url("backend/cmsRanking/listByMonthlyAjax"); ?>';
var url1 = '<?php echo base_url("backend/cmsRanking/exportExcel"); ?>';
// Tìm kiếm theo cú pháp
var oldTimeout2 = '';
$('#input-name').keyup(function(){
$('#input-name').change(function(){
clearTimeout(oldTimeout2);
oldTimeout2 = setTimeout(function(){
loadDataByAjaxFromInput(url);
}, 250);
});
// Xóa bộ lọc
$('#delete-filter').click(function(){
$("#input-name").val('');
changePagination('0');
return false;
$('#excel').click(function(){
exportExcel(url1);
// alert('hi');
});
changePagination('0');
});
function exportExcel(url1){
$('#data-loading').show();
var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
var fByName = $("#input-name").val();
//Ajax ve bieu do
$.ajax({
type: "POST",
url: url1,
data: {
csrf_name: csrf_value,
fByName: fByName
},
dataType: "text",
cache: false,
success: function(data){
$('#data-loading').hide();
changePagination('0');
}
});
}
//Ham chung cho cac input
function loadDataByAjaxFromInput(url){
$('#data-loading').show();
......
......@@ -24,11 +24,16 @@
<div class="row">
<?php echo form_open(base_url().'backend/cmsRanking/listByWeeklyAjax'); ?>
<div class="col-lg-3">
<input
class="form-control" type="text"
name="input-name"
id="input-name"
placeholder="Nhập tên bài hát..."/>
<select class="form-control" name="input-name" id="input-name">
<?php
$listSearch= $this->report_views_weekly_model->selectSearch();
foreach ($listSearch as $data):
?>
<option value = "<?php echo $data['week'].'-'.$data['year']; ?>">Tuần <?php echo $data['week']; ?> (Năm <?php echo $data['year']; ?>)</option>
<?php
endforeach;
?>
</select>
</div>
<div class="col-lg-1">
<button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
......@@ -50,24 +55,15 @@
//Thuc hien viec ve bieu do$data
$(document).ready(function() {
var url = '<?php echo base_url("backend/cmsRanking/listByWeeklyAjax"); ?>';
// Tìm kiếm theo cú pháp
var oldTimeout2 = '';
$('#input-name').keyup(function(){
$('#input-name').change(function(){
clearTimeout(oldTimeout2);
oldTimeout2 = setTimeout(function(){
loadDataByAjaxFromInput(url);
}, 250);
});
// Xóa bộ lọc
$('#delete-filter').click(function(){
$("#input-name").val('');
changePagination('0');
return false;
});
changePagination('0');
});
//Ham chung cho cac input
function loadDataByAjaxFromInput(url){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment