1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report_views_monthly_model extends CI_Model
{
protected $_table='reports_views_monthly';
public function __construct(){
parent::__construct();
date_default_timezone_set("Asia/Ho_Chi_Minh");
}
public function cmsCountAll($name = null)
{
$this->db->select('COUNT(*) AS totalResults');
$this->db->from($this->_table);
$query = $this->db->get();
$result = $query->result_array();
if ($result) {
return $result[0]['totalResults'];
} else {
return 0;
}
}
public function cmsGetPagination($record, $start, $name = null)
{
$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 = 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');
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->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();
}
}