We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 433cba41 authored by Daniel Watkins's avatar Daniel Watkins

Move determination of album scrobbles to data/Album.php.

parent 84ad936d
......@@ -39,7 +39,7 @@ class Album {
* @param string name The name of the album to load
* @param string artist The name of the artist who recorded this album
*/
function __construct($name, $artist, $scrobbles) {
function __construct($name, $artist) {
global $mdb2;
$res = $mdb2->query('SELECT name, artist_name, mbid, releasedate FROM Album WHERE '
. 'name = ' . $mdb2->quote($name, 'text') . ' AND '
......@@ -52,7 +52,15 @@ class Album {
$this->mbid = $row['mbid'];
$this->artist_name = $row['artist_name'];
$this->releasedate = $row['releasedate'];
$this->c = $scrobbles;
}
$res = $mdb2->query('SELECT COUNT(*) AS scrobbles FROM Scrobbles JOIN Track ON Scrobbles.track = Track.name WHERE Scrobbles.artist ='
. $mdb2->quote($artist, 'text') . 'AND Track.album ='
. $mdb2->quote($name, 'text'));
if(!$res->numRows()) {
$this->c = 0;
} else {
$row = sanitize($res->fetchRow(MDB2_FETCHMODE_ASSOC));
$this->c = $row['scrobbles'];
}
}
......
......@@ -72,10 +72,10 @@ class Artist {
*/
function getAlbums() {
global $mdb2;
$res = $mdb2->query("SELECT COUNT(*) as scrobbles,Track.album FROM Scrobbles JOIN Track ON Scrobbles.track = Track.name WHERE Track.artist = "
. $mdb2->quote($this->name, "text") . " AND Track.artist = Scrobbles.artist AND Track.album IS NOT NULL GROUP BY Track.album");
$res = $mdb2->query("SELECT name FROM Album WHERE artist_name = "
. $mdb2->quote($this->name, "text"));
while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
$albums[] = new Album($row["album"], $this->name, $row['scrobbles']);
$albums[] = new Album($row["name"], $this->name);
}
return $albums;
......
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