=== modified file 'gnukebox/install.php' --- gnukebox/install.php 2009-06-06 14:51:17 +0000 +++ gnukebox/install.php 2009-06-12 18:56:58 +0000 @@ -255,8 +255,12 @@ mbid VARCHAR(36), track INTEGER NOT NULL)"); + $adodb->Execute("CREATE TABLE Love( + userid INTEGER REFERENCES Users(uniqueid), + trackid INTEGER REFERENCES Track(id))"); + $adodb->Execute("CREATE VIEW Free_Scrobbles AS - SELECT s.username, s.track, s.artist, s.time, s.mbid, s.album, s.source, s.rating, s.length + SELECT s.userid, s.track, s.artist, s.time, s.mbid, s.album, s.source, s.rating, s.length FROM Scrobbles s JOIN Scrobble_Track st ON s.stid = st.id JOIN Track t ON st.track = t.id === modified file 'nixtape/data/Server.php' --- nixtape/data/Server.php 2009-06-11 18:24:08 +0000 +++ nixtape/data/Server.php 2009-06-13 17:07:01 +0000 @@ -62,7 +62,8 @@ l.mbid AS album_mbid, l.image AS album_image, l.artwork_license, - t.license + t.license, + t.id as trackid FROM Scrobbles s LEFT JOIN Artist a ON s.artist=a.name @@ -90,7 +91,8 @@ l.mbid AS album_mbid, l.image AS album_image, l.artwork_license, - t.license + t.license, + t.id AS trackid FROM Scrobbles s LEFT JOIN Artist a ON s.artist=a.name @@ -196,7 +198,8 @@ ClientCodes.url, ClientCodes.free, n.mbid, - t.license + t.license, + t.id AS trackid FROM Now_Playing n LEFT OUTER JOIN Scrobble_Sessions ss ON n.sessionid=ss.sessionid @@ -220,7 +223,8 @@ ClientCodes.url, ClientCodes.free, n.mbid, - t.license + t.license, + t.id AS trackid FROM Now_Playing n LEFT OUTER JOIN Scrobble_Sessions ss ON n.sessionid=ss.sessionid @@ -265,6 +269,97 @@ return $result; } + + /** + * Adds a loved track + * + * @param int $trackid ID of the track to love + * @param int $userid ID of the user who loves the track + * @return True or false depending on the success + */ + + static function addLove ($trackid, $userid) { + global $adodb; + + $adodb->SetFetchMode(ADODB_FETCH_ASSOC); + try { + $data = $adodb->GetAll('SELECT + userid FROM Love WHERE + trackid = ' . (int)($trackid)); + } catch (exception $e) { + return false; + } + + if(!$data) { + try { + $adodb->Execute('INSERT INTO Love (userid, trackid) VALUES (' + . (int)($userid) . ', ' + . (int)($trackid) . ');'); + } catch (exception $e) { + return false; + } + } + + return true; + } + + /** + * Retrieves a list of loved tracks + * + * @param int $number Number of tracks to list + * @param int $index Starting from this index + * @param int $userid ID of the user whose tracks to retrieve + * @return An array of loved track data or null on failure + */ + static function getLove($number, $index, $userid) { + global $adodb; + + $adodb->SetFetchMode(ADODB_FETCH_ASSOC); + try { + $data = $adodb->CacheGetAll(60,'SELECT + t.name AS track, + t.id, + t.license, + t.artist_name AS artist, + t.album_name AS album, + a.image AS album_image + FROM Track t + LEFT JOIN Album a + ON t.album_name = a.name + WHERE t.id = ANY (SELECT + trackid FROM Love + WHERE userid = ' + . (int)($userid) . ') + LIMIT ' . (int)($index) . ', ' + . (int)($number)); + } catch (exception $e) { + return null; + } + + foreach($data as &$i) { + $row = sanitize($i); + + $row['username'] = uniqueid_to_username($row['userid']); + $row['userurl'] = Server::getUserURL($row['username']); + $row['artisturl'] = Server::getArtistURL($row['artist']); + $row['trackurl'] = Server::getTrackURL($row['artist'], $row['album'], $row['track']); + + if (!$row['album_image']) { + $row['album_image'] = false; + } else { + $row['album_image'] = resolve_external_url($row['album_image']); + } + + $row['licenseurl'] = $row['license']; + $row['license'] = simplify_license($row['licenseurl']); + + + $result[] = $row; + } + + return $result; + + } /** * The get*URL functions are implemented here rather than in their respective === modified file 'nixtape/data/User.php' --- nixtape/data/User.php 2009-06-03 13:50:26 +0000 +++ nixtape/data/User.php 2009-06-13 14:44:23 +0000 @@ -198,6 +198,24 @@ function getNowPlaying($number) { return Server::getNowPlaying($number, $this->name); } + + /** + * Add a track to the user's loved tracks + * + * @param string $track Name of the track to be loved + */ + function addLove($trackid) { + return Server::addLove($trackid, $this->uniqueid); + } + + /** + * Get user's loved tracks + * + * @return An array of loved tracks data + */ + function getLove($number) { + return Server::getLove($number, $index, $this->uniqueid); + } /** * Log in to the gnukebox server === added file 'nixtape/themes/librefm/templates/user-love.tpl' --- nixtape/themes/librefm/templates/user-love.tpl 1970-01-01 00:00:00 +0000 +++ nixtape/themes/librefm/templates/user-love.tpl 2009-06-13 16:24:43 +0000 @@ -0,0 +1,41 @@ +{include file='header.tpl'} +{include file='maxiprofile.tpl'} + +