[mb-commits] r9888 - in mb_server/trunk: cgi-bin/MusicBrainz/Server htdocs/show/tag htdocs/show/user htdocs/user htdocs/user/tags

root at musicbrainz.org root at musicbrainz.org
Thu Jun 26 13:45:25 UTC 2008


Author: luks
Date: 2008-06-26 13:45:25 +0000 (Thu, 26 Jun 2008)
New Revision: 9888

Added:
   mb_server/trunk/htdocs/user/tags/
   mb_server/trunk/htdocs/user/tags/index.html
   mb_server/trunk/htdocs/user/tags/tag.html
Modified:
   mb_server/trunk/cgi-bin/MusicBrainz/Server/Tag.pm
   mb_server/trunk/htdocs/show/tag/index.html
   mb_server/trunk/htdocs/show/user/index.html
Log:
User tag cloud + list of entities tagged by user. (Closes #3293)


Modified: mb_server/trunk/cgi-bin/MusicBrainz/Server/Tag.pm
===================================================================
--- mb_server/trunk/cgi-bin/MusicBrainz/Server/Tag.pm	2008-06-26 09:43:21 UTC (rev 9887)
+++ mb_server/trunk/cgi-bin/MusicBrainz/Server/Tag.pm	2008-06-26 13:45:25 UTC (rev 9888)
@@ -395,6 +395,40 @@
 	return \%tags;
 }
 
+# Get a hash of { tag1 => count, tag2 => count } value from user's tags.
+sub GetRawTagHash
+{
+	my ($self, $moderator_id) = @_;
+
+	my $maindb = Sql->new($self->GetDBH());
+
+	my $tags = MusicBrainz->new;
+    $tags->Login(db => 'RAWDATA');
+	my $tagdb = Sql->new($tags->{DBH});
+
+	my %counts;
+
+	my @entity_types = ('artist', 'label', 'track', 'release');
+	foreach my $entity_type (@entity_types) {
+		my $assoc_table = $entity_type . '_tag_raw';
+		my $rows = $tagdb->SelectListOfLists("SELECT tag, COUNT(*)
+		                                        FROM $assoc_table
+		                                       WHERE $assoc_table.moderator = ?
+		                                       GROUP BY tag", $moderator_id);
+		foreach my $row (@$rows) {
+			$counts{$row->[0]} += $row->[1];
+		}
+	}
+	
+	my %result;
+	return \%result if (scalar(%counts) == 0);
+
+	my $rows = $maindb->SelectListOfLists("SELECT id, name FROM tag
+	                                        WHERE id IN (" . join(",", keys(%counts)) . ")");
+	%result = map { $_->[1] => $counts{$_->[0]} } @$rows;
+	return \%result;
+}
+
 # Get a hash of { tag1 => count, tag2 => count } value from tags for the
 # speficied entity.
 sub GetTagHashForEntity
@@ -502,12 +536,52 @@
 	return (\@rows, $offset + $total_rows);
 }
 
+sub GetEntitiesForRawTag
+{
+	my ($self, $entity_type, $tag, $moderator_id, $limit, $offset) = @_;
+
+	my $maindb = Sql->new($self->GetDBH());
+
+	my $tags = MusicBrainz->new;
+    $tags->Login(db => 'RAWDATA');
+	my $tagdb = Sql->new($tags->{DBH});   
+
+	# lookup tag ID by name
+	my $tag_id = $maindb->SelectSingleValue(
+		"SELECT id FROM tag WHERE name = ?", $tag);
+    return [] if (!$tag_id);
+
+	# select all entity IDs
+	my $assoc_table = $entity_type . '_tag_raw';
+	my $rows = $tagdb->SelectSingleColumnArray(
+		"SELECT $entity_type FROM $assoc_table
+		 WHERE tag = ? AND moderator = ?", $tag_id, $moderator_id);
+    return [] if (scalar(@$rows) == 0);
+
+	my $entity_table = $entity_type eq "release" ? "album" : $entity_type;
+	
+	$offset ||= 0;
+	$maindb->Select("SELECT id, name, gid FROM $entity_table WHERE id IN (".join(",", @$rows).") ORDER BY name OFFSET ?", $offset);
+
+	my @rows;
+	while ($limit--)
+	{
+		my $row = $maindb->NextRowHashRef or last;
+		push @rows, $row;
+	}
+
+	my $total_rows = $maindb->Rows;
+	$maindb->Finish;
+
+	return (\@rows, $offset + $total_rows);
+}
+
 sub GetModerator	{ $_[0]{'moderator'} }
 sub SetModerator	{ $_[0]{'moderator'} = $_[1] }
 
 sub GenerateTagCloud
 {
-	my ($self, $tags, $type, $minsize, $maxsize, $rawtagslist) = @_;
+	my ($self, $tags, $type, $minsize, $maxsize, $rawtagslist, $urlprefix) = @_;
 	my ($key, $value, $tag, $sizedelta, @res, %mytags);
 
 	my @counts = sort { $a <=> $b } values %$tags;
@@ -516,6 +590,8 @@
 
     %mytags = map { $_->{name} => $_->{id} } @{$rawtagslist} if ($rawtagslist);
 
+	$urlprefix = '/show/tag/?' if !defined($urlprefix);
+
 	my $min = $counts[0];
 	my $max = $counts[$ntags - 1];
 	my $med = $ntags % 2
@@ -559,7 +635,7 @@
 		push @res, '<span style="font-size:' . int($minsize + $value * $sizedelta + 0.5) . 'px;' . ($value > $boldthreshold ? "font-weight:bold;" : "") . '">';
 		$tag = encode_entities($key);
 		$tag =~ s/\s+/&nbsp;/;
-		push @res, '<a '.$mine.'href="/show/tag/?tag=' . uri_escape($key) . "&show=$type\">".$tag.'</a></span> &nbsp; ';
+		push @res, '<a '.$mine.'href="' . $urlprefix . 'tag=' . uri_escape($key) . "&amp;show=$type\">".$tag.'</a></span> &nbsp; ';
 	}
 	return join "", @res;
 }

Modified: mb_server/trunk/htdocs/show/tag/index.html
===================================================================
--- mb_server/trunk/htdocs/show/tag/index.html	2008-06-26 09:43:21 UTC (rev 9887)
+++ mb_server/trunk/htdocs/show/tag/index.html	2008-06-26 13:45:25 UTC (rev 9888)
@@ -43,27 +43,27 @@
 [ <a href="/show/tag/all.html">Show all tags</a> |
  show tag <% $tag %> for:
 % if ($show ne 'all') {
-    <a href="/show/tag/?tag=<% uri_escape($tag) %>&show=all">all</a> |
+    <a href="/show/tag/?tag=<% uri_escape($tag) %>&amp;show=all">all</a> |
 % }
 % if ($show eq 'artist') {
     artists |
 % } else {
-    <a href="/show/tag/?tag=<% uri_escape($tag) %>&show=artist">artists</a> |
+    <a href="/show/tag/?tag=<% uri_escape($tag) %>&amp;show=artist">artists</a> |
 % }
 % if ($show eq 'label') {
     labels |
 % } else {
-    <a href="/show/tag/?tag=<% uri_escape($tag) %>&show=label">labels</a> |
+    <a href="/show/tag/?tag=<% uri_escape($tag) %>&amp;show=label">labels</a> |
 % }
 % if ($show eq 'release') {
     releases |
 % } else {
-    <a href="/show/tag/?tag=<% uri_escape($tag) %>&show=release">releases</a> |
+    <a href="/show/tag/?tag=<% uri_escape($tag) %>&amp;show=release">releases</a> |
 % }
 % if ($show eq 'track') {
     tracks ]
 % } else {
-    <a href="/show/tag/?tag=<% uri_escape($tag) %>&show=track">tracks</a> ]
+    <a href="/show/tag/?tag=<% uri_escape($tag) %>&amp;show=track">tracks</a> ]
 % }
 
 %	my @types = ($show eq 'all') ? ("artist", "label", "release", "track") : ($show);

Modified: mb_server/trunk/htdocs/show/user/index.html
===================================================================
--- mb_server/trunk/htdocs/show/user/index.html	2008-06-26 09:43:21 UTC (rev 9887)
+++ mb_server/trunk/htdocs/show/user/index.html	2008-06-26 13:45:25 UTC (rev 9888)
@@ -92,6 +92,7 @@
 	);
 
 	my $subscriptions_public = UserPreference::get_for_user("subscriptions_public", $user);
+	my $tags_public = UserPreference::get_for_user("tags_public", $user);
 
 </%perl>
 
@@ -123,6 +124,10 @@
 %	{
 					| <a href="/user/subscriptions.html?userid=<% $userid %>">Subscriptions</a>
 % 	}
+% 	if ($tags_public or $is_me)
+%	{
+					| <a href="/user/tags/?userid=<% $userid %>">Tags</a>
+% 	}
 				</td>
 			</tr>
 

Added: mb_server/trunk/htdocs/user/tags/index.html

Added: mb_server/trunk/htdocs/user/tags/tag.html




More information about the MusicBrainz-commits mailing list