Track_model.php 5.42 KB
Newer Older
Phạm Văn Đoan committed
1 2
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

3
class Track_model extends CI_Model
Phạm Văn Đoan committed
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
{
    protected $_table = 'tracks';

    public function __construct()
    {
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
    }

    public function add($dataInsert)
    {
        $this->db->insert($this->_table, $dataInsert);
        $insert_id = $this->db->insert_id();
        return $insert_id;
    }

    public function update($id, $dataUpdate)
    {
        $this->db->where('id', $id);
        $this->db->update($this->_table, $dataUpdate);
    }

    public function getById($id)
    {
        $this->db->select($this->_table . '.*');
        $this->db->from($this->_table);
        $this->db->where($this->_table . '.id', $id);
        $query = $this->db->get();
        return $query->result_array();
    }

    /**
     * Lay cuoc thi hien hanh
     * @return mixed
     */
    public function getCurrentContest()
    {
        $this->db->select($this->_table . '.*');
        $this->db->from($this->_table);
        $this->db->where('is_active', 1);
        $this->db->order_by('created_at', 'desc');
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }

    public function cmsCountAll($name = null)
    {
        $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) {
            return $result[0]['totalResults'];
        } else {
            return 0;
        }
    }

    public function cmsGetPagination($record, $start, $name = null)
    {
Phạm Văn Đoan committed
71
        $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');
Phạm Văn Đoan committed
72
        $this->db->from($this->_table);
73 74 75 76
        $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('users u1', 'u1.id = track_user.user_id', 'left');
        $this->db->join('users u2', 'u2.id = track_artists.user_id', 'left');
Phạm Văn Đoan committed
77
        if ($name != null) {
78 79 80 81
            $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');
Phạm Văn Đoan committed
82 83 84 85
        }
        $this->db->order_by($this->_table . '.title', 'asc');
        $this->db->limit($record, $start);
        $query = $this->db->get();
Phạm Văn Đoan committed
86

Phạm Văn Đoan committed
87 88 89 90 91 92 93 94 95 96 97 98 99
        return $query->result_array();
    }

    public function getListForSelectBox()
    {
        $this->db->select('id, fullname, username, sid');
        $this->db->from($this->_table);
        $this->db->where('sid !=', '');
        $this->db->order_by($this->_table . '.username', 'asc');
        $query = $this->db->get();
        return $query->result_array();
    }

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    public function getReportWeekly($week, $year, $limit = 100, $offset = 0)
    {
        //$sql = "SELECT * FROM report_views_weekly WHERE `week` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} ";
        //$query  = $this->db->query($sql, $week, $year);
        $this->db->from('report_views_weekly');
        $this->db->where('week =', $week);
        $this->db->where('year =', $year);
        $this->db->limit($limit, $offset);
        $query = $this->db->get();

        return $query->result_array();
    }

    public function getReportMonthly($month, $year, $limit = 100, $offset = 0)
    {
        //$sql = "SELECT * FROM reports_views_monthly WHERE `month` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} ";
        //$query  = $this->db->query($sql, $month, $year);
        $this->db->from('reports_views_monthly');
        $this->db->where('month =', $month);
        $this->db->where('year =', $year);
        $this->db->limit($limit, $offset);
        $query = $this->db->get();

        return $query->result_array();
    }

    public function getUserByTrack($track_id) {
        //$query = $this->db->query("SELECT * FROM track_user WHERE track_id=?", $track_id);
        //if ($query) $users = $query->result_array();
        //return $users;

        $this->db->from('track_user');
        $this->db->where('track_id =', $track_id);
        $query = $this->db->get();

        return $query->result_array();
    }

    public function getArtistsByTrack($track_id) {
        //$query = $this->db->query("SELECT * FROM track_artists WHERE track_id=?", $track_id);
        //if ($query) $users = $query->result_array();
        //return $users;

        $this->db->from('track_artists');
        $this->db->where('track_id =', $track_id);
        $query = $this->db->get();

        return $query->result_array();
    }

    public function getTrackById($id)
    {
        $this->db->select($this->_table . '.*');
        $this->db->from($this->_table);
        $this->db->where($this->_table . '.id', $id);
        $query = $this->db->get();
        return $query->result_array();
    }

Phạm Văn Đoan committed
159 160 161 162
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */