function compare($X, $Y) { return($Y['count'] - $X['count']); } // Build the data for the collage and the torrent list // TODO: Cache this $DB->query(" SELECT ct.GroupID, ct.UserID FROM collages_torrents AS ct JOIN torrents_group AS tg ON tg.ID = ct.GroupID WHERE ct.CollageID = '$CollageID' ORDER BY ct.Sort"); $GroupIDs = $DB->collect('GroupID'); $Contributors = $DB->to_pair('GroupID', 'UserID', false); if (count($GroupIDs) > 0) { $TorrentList = Torrents::get_groups($GroupIDs); $UserVotes = Votes::get_user_votes($LoggedUser['ID']); } else { $TorrentList = array(); } // Loop through the result set, building up $Collage and $TorrentTable // Then we print them. $Collage = array(); $TorrentTable = ''; $NumGroups = count($TorrentList); $NumGroupsByUser = 0; $TopArtists = array(); $UserAdditions = array(); $Number = 0; foreach ($GroupIDs as $GroupID) { if (!isset($TorrentList[$GroupID])) { continue; } $Group = $TorrentList[$GroupID]; extract(Torrents::array_group($Group)); $UserID = $Contributors[$GroupID]; $TorrentTags = new Tags($TagList); // Handle stats and stuff $Number++; if ($UserID == $LoggedUser['ID']) { $NumGroupsByUser++; } $CountArtists = $Artists; if ($CountArtists) { foreach ($CountArtists as $Artist) { if (!isset($TopArtists[$Artist['id']])) { $TopArtists[$Artist['id']] = array('name' => $Artist['name'], 'count' => 1); } else { $TopArtists[$Artist['id']]['count']++; } } } if (!isset($UserAdditions[$UserID])) { $UserAdditions[$UserID] = 0; } $UserAdditions[$UserID]++; $DisplayName = "$Number - "; $DisplayName .= Artists::display_artists($Artists); $DisplayName .= "$GroupName"; if ($GroupYear > 0) { $DisplayName = "$DisplayName [$GroupYear]"; } if ($GroupStudio) { $DisplayName .= " [$GroupStudio]"; } if ($GroupCatalogueNumber) { $DisplayName .= " [$GroupCatalogueNumber]"; } if ($GroupDLSiteID) { $DisplayName .= " [$GroupDLSiteID]"; } $SnatchedGroupClass = ($GroupFlags['IsSnatched'] ? ' snatched_group' : ''); $UserVote = isset($UserVotes[$GroupID]) ? $UserVotes[$GroupID]['Type'] : ''; // Start an output buffer, so we can store this output in $TorrentTable ob_start(); if (count($Torrents) > 1) { // Grouped torrents $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1); ?>
Report