Skip to content

Commit

Permalink
reverted Top Plays (moved to feature branch)
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed May 5, 2024
1 parent 17c80c4 commit 234c414
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 80 deletions.
2 changes: 1 addition & 1 deletion css/topnav.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ nav .search-icon {
position: absolute;
display: block;
left: 0;
margin-right: -200px;/* TBD fix me */
margin-right: -150px;/* TBD fix me */
}
.nav-items:not(.active) li.selected ul li {
float: left;
Expand Down
4 changes: 2 additions & 2 deletions engine/IPlaylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -98,7 +98,7 @@ function updateTrack($playlistId, $id, $tag, $artist, $track, $album, $label, $d
function insertTrackEntry($playlistId, PlaylistEntry $entry, &$status);
function updateTrackEntry($playlist, PlaylistEntry $entry);
function deleteTrack($id);
function getTopPlays($airname=0, $days=41, $count=10, $excludeAutomation=true);
function getTopPlays($airname=0, $days=41, $count=10);
function getLastPlays($tag, $count=0, $excludeAutomation=true, $excludeRebroadcasts=true);
function getRecentPlays($airname, $count);
function getPlaysBefore($timestamp, $limit);
Expand Down
21 changes: 4 additions & 17 deletions engine/impl/Playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -836,33 +836,20 @@ public function deleteTrack($id) {
return $success;
}

public function getTopPlays($airname=0, $days=41, $count=10, $excludeAutomation=true) {
$zootopia = $excludeAutomation ? $this->getZootopiaAirname() : null;
if($zootopia) {
if(!is_array($zootopia))
$zootopia = [ $zootopia ];

$zootopiaSet = str_repeat("?,", count($zootopia) - 1) . "?";
}

public function getTopPlays($airname=0, $days=41, $count=10) {
$over = $airname?"distinct t.list":"*";
$query = "SELECT max(t.tag) tag, count($over) plays, l.showdate, IFNULL(a.artist, t.artist) artist, t.album, t.label, count(*)" .
$query = "SELECT t.tag, count($over) plays, l.showdate, IFNULL(a.artist, t.artist) artist, t.album, t.label, count(*)" .
" FROM tracks t JOIN lists l ON t.list = l.id " .
($zootopia ? " LEFT JOIN airnames n ON l.airname = n.id " : "") .
" LEFT JOIN albumvol a ON a.tag = t.tag " .
" WHERE t.artist NOT LIKE '".IPlaylist::SPECIAL_TRACK."%' AND".
" t.album <> '' AND t.label <> '' AND" .
($zootopia ? " n.airname NOT IN ($zootopiaSet) AND" : "") ;
" t.album <> '' AND t.label <> '' AND";
if($airname)
$query .= " l.airname = ? AND";
if($days)
$query .= " date_add(l.showdate, interval $days day) > now() ";
$query .= " GROUP BY t.album, t.label ORDER BY 2 DESC, 7 DESC, t.artist LIMIT ?";
$stmt = $this->prepare($query);
$p = 1;
if($zootopia)
foreach($zootopia as $zka)
$stmt->bindValue($p++, $zka);
if($airname)
$stmt->bindValue($p++, (int)$airname, \PDO::PARAM_INT);
$stmt->bindValue($p++, (int)$count, \PDO::PARAM_INT);
Expand Down
61 changes: 1 addition & 60 deletions ui/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -55,7 +55,6 @@ class Playlists extends MenuItem {
[ "u", "editListGetHint", 0, "listManagerGetHint" ],
[ "u", "editListEditor", 0, "emitEditor" ],
[ "a", "viewDJ", "By DJ", "emitViewDJ" ],
[ "a", "viewTop", "Top Plays", "emitTopPlays" ],
[ "u", "import", "Import", "emitImportList" ],
];

Expand Down Expand Up @@ -1022,64 +1021,6 @@ public function emitViewDJ() {

$this->emitViewDJMain();
}

public function emitTopPlays() {
$days = 7;
$limit = 30;

$topPlays = Engine::api(IPlaylist::class)->getTopPlays(0, $days, $limit);

if(!sizeof($topPlays)) {
echo " <h2>No top airplay is available</h2>\n";
return;
}

echo " <h2>Top airplay for the last $days days</h2>\n";
echo " <table class='playlistTable' cellpadding='1'>\n";
echo " <thead>\n";
echo " <tr class='playlistHdr' align=left><th></th><th>Artist</th><th></th><th>Album/Label</th></tr>";
echo " </thead>\n";

Engine::api(ILibrary::class)->markAlbumsReviewed($topPlays);
$observer = (new PlaylistObserver())->on('spin', function($entry) {
$artist = $entry->getArtist();
$artistName = $entry->getTag() ?
PlaylistEntry::swapNames(
preg_match("/^\[coll\]:/i", $artist) ?
"Various Artists" : $artist) :
$artist;
$albumName = $entry->getAlbum();
$labelName = $entry->getLabel();

$reviewCell = $entry->getReviewed() ? "<div class='albumReview'></div>" : "";

if(!empty($albumName)) {
$albumTitle = $entry->getTag() ?
"<a class='nav' href='?action=search&amp;s=byAlbumKey&amp;n=" . htmlentities($entry->getTag()) . "'>" . htmlentities($albumName) . "</a>" :
UI::smartURL($albumName);

if(!empty($labelName))
$albumTitle .= "<span class='songLabel'> / " . UI::smartURL($labelName) . "</span>";
} else
$albumTitle = "";

echo " <tr class='songRow'>" .
"<td>" . htmlentities($entry->getRank()) . ".</td>" .
"<td>" . UI::smartURL($artistName) . "</td>" .
"<td style='width: 15px'>$reviewCell</td>" .
"<td>$albumTitle</td>" .
"</tr>\n";
});

echo " <tbody>\n";
foreach($topPlays as $rank => $entry) {
$entry['rank'] = $rank + 1;
$observer->observe(new PlaylistEntry($entry));
}
echo " </tbody>\n </table>\n";

echo " <h3>For complete album charting, see our <a href='?action=viewChart'><b>Airplay Charts</b></a></h3>";
}

public function emitViewDJMain() {
$viewAll = $this->subaction == "viewDJAll";
Expand Down

0 comments on commit 234c414

Please sign in to comment.