Example #1
0
 public function &getTracks($userid, $start = 0, $display = 30)
 {
     if ($this->id == NULL) {
         throw new Exception("Missing playlist ID when getting playlist's tracks");
     }
     if ($this->tracks == NULL) {
         $this->load->static_model('Track');
         $query = "SELECT SQL_CALC_FOUND_ROWS a.name AS `album_name`, a.id AS `album_id`, t.*, art.id AS `artist_id`, art.name AS `artist_name`, ut.bought\n\t    FROM `track` t, `artist` art,`album` a, `album_track` at, `playlist_track` pt\n\t    LEFT JOIN `user_track` ut ON(ut.trackid = pt.trackid AND ut.userid = " . $this->db->escape($userid) . ")\n\t    WHERE pt.playlistid = " . $this->db->escape($this->id) . " AND pt.albumid = a.id AND pt.trackid = t.id   \n\t    AND t.main_artistid = art.id AND t.id = at.`trackid` AND a.id = at.`albumid` ORDER BY pt.`play_order`";
         if ($display > 0) {
             $query .= " LIMIT {$start}, {$display}";
         }
         $this->tracks = Track::getTrackList($query);
     }
     $result = array("tracks" => NULL, "rows" => NULL);
     $result["tracks"] = $this->tracks;
     $res = $this->db->query("SELECT FOUND_ROWS() AS num_rows")->first_row();
     $result["rows"] = $res->num_rows;
     return $result;
 }
Example #2
0
 /**
  * get the tracks where this
  * artist is the main
  * @return array of Track
  */
 public function getTracks()
 {
     if ($this->artistid == NULL) {
         throw new Exception("Missing track ID when requesting artist' track");
     }
     //find the track id
     $query = "SELECT trackid FROM artist_track WHERE artistid = " . $this->db->escape($this->artistid);
     $tids = $this->db->query($query)->result();
     if (count($tids) > 0) {
         $track_ids = "";
         foreach ($tids as $tid) {
             $track_ids .= $tid->trackid . ",";
         }
         //remove the last comma
         $track_ids = substr($track_ids, 0, -1);
         $query = "SELECT a.`year`, a.name AS `album_name`, a.id AS `album_id`, t.*, art.id AS `artist_id`, art.name AS `artist_name`\n    FROM `album_track` at, `track` t, `artist` art,`album` a, `track_genre` tg, `genre` g\n     \n    WHERE t.main_artistid = art.id AND t.id in ({$track_ids}) \n    AND t.id = at.`trackid` AND a.id = at.`albumid` AND g.id = tg.genreid AND t.id = tg.trackid \n    ORDER BY a.`year`";
         return Track::getTrackList($query);
     }
     return array();
 }