[Koha-patches] [PATCH] bugfix for 2899

Paul Poulain paul.poulain at biblibre.com
Thu Jul 23 17:23:36 CEST 2009


Tag cloud fixes :
* ordering cloud by tag name, not by weight
* improve behaviour : either display everyone cloud or my cloud only. When clicquing on "Tag cloud" on the top, will display by default everyone cloud. when clicquing on "My tag" (left tab when logged in), the page will display only my tags and my tags only
---
 C4/Tags.pm                                         |    5 +-
 koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc  |    2 +-
 koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl |   68 ++++++++++++++------
 opac/opac-tags.pl                                  |   12 ++--
 4 files changed, 58 insertions(+), 29 deletions(-)

diff --git a/C4/Tags.pm b/C4/Tags.pm
index 5f2ff69..ecd9758 100644
--- a/C4/Tags.pm
+++ b/C4/Tags.pm
@@ -261,7 +261,7 @@ sub get_tags (;$) {		# i.e., from tags_index
 
 sub get_approval_rows (;$) {		# i.e., from tags_approval
 	my $hash = shift || {};
-	my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort);
+	my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort borrowernumber);
 	my $wheres;
 	my $limit  = "";
 	my $order  = "";
@@ -279,7 +279,7 @@ sub get_approval_rows (;$) {		# i.e., from tags_approval
 		if ($key eq 'limit') {
 			my $val = $hash->{$key};
 			unless ($val =~ /^(\d+,)?\d+$/) {
-				carp "Non-nuerical limit value '$val' ignored!";
+				carp "Non-numerical limit value '$val' ignored!";
 				next;
 			}
 			$limit = " LIMIT $val\n";
@@ -288,6 +288,7 @@ sub get_approval_rows (;$) {		# i.e., from tags_approval
 				unless (
 					$by =~ /^([-+])?(term)/            or
 					$by =~ /^([-+])?(biblionumber)/    or
+                    $by =~ /^([-+])?(borrowernumber)/  or
 					$by =~ /^([-+])?(weight_total)/    or
 					$by =~ /^([-+])?(approved(_by)?)/  or
 					$by =~ /^([-+])?(date_approved)/
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
index 8e8ee6a..8131917 100644
--- a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
@@ -5,7 +5,7 @@
   <!-- TMPL_IF NAME="accountview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-account.pl">my fines</a></li>
   <!-- TMPL_IF NAME="userupdateview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-userupdate.pl">my personal details</a></li>
   <!-- TMPL_IF NAME="TagsEnabled" -->
-    <!-- TMPL_IF NAME="tagsview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-tags.pl">my tags</a></li>
+    <!-- TMPL_IF NAME="tagsview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-tags.pl?mine=1">my tags</a></li>
   <!-- /TMPL_IF -->
   <!-- TMPL_IF NAME="OpacPasswordChange" -->
     <!-- TMPL_IF NAME="passwdview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-passwd.pl">change my password</a></li>
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
index 2f4aa9e..c372247 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
@@ -111,30 +111,56 @@
 		<div class="dialog message"><!-- TMPL_VAR NAME="deleted_count" --><!-- TMPL_IF EXPR="deleted_count ==1" --> tag<!-- TMPL_ELSE -->tags<!-- /TMPL_IF --> successfully deleted.</div>
 	  <!-- /TMPL_IF -->
 	<!-- /TMPL_IF -->
+    <!-- TMPL_IF NAME="mine" -->
+        <!-- TMPL_IF NAME="MY_TAGS" -->
+            <form method="post" action="opac-tags.pl">
+            <h1>My Tags</h1>
+            <table id="mytagst">
+            <thead><tr><th>Term</th><th>Title</th><th>Date Added</th><th>Delete</th>
+            </tr></thead>
+        <tbody><!-- TMPL_LOOP NAME="MY_TAGS" -->
+            <tr><td><a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&amp;q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->">
+                    <!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a>
+                </td>
+                <td><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
+                    <!-- TMPL_VAR NAME="bib_summary" ESCAPE="HTML" --></a></td>
+                <td><!-- TMPL_VAR NAME="date_created_display" --></td>
+                <td><input type="submit" name="del<!-- TMPL_VAR NAME="tag_id" -->" value="Delete" /></td>
+            </tr>
+        <!-- /TMPL_LOOP --></tbody>
+            </table>
+            </form>
+        <!-- /TMPL_IF -->
+    <!-- /TMPL_IF -->
 
-	<!-- TMPL_UNLESS NAME="hidemytags" -->
-	<!-- TMPL_IF NAME="MY_TAGS" -->
-		<form method="post" action="opac-tags.pl">
-		<h2>My Tags</h2>
-		<table id="mytagst">
-		<thead><tr><th>Term</th><th>Title</th><th>Date Added</th><th>Delete</th>
-		</tr></thead>
-	<tbody><!-- TMPL_LOOP NAME="MY_TAGS" -->
-		<tr><td><a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&amp;q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->">
-				<!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a>
-			</td>
-			<td><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
-				<!-- TMPL_VAR NAME="bib_summary" ESCAPE="HTML" --></a></td>
-			<td><!-- TMPL_VAR NAME="date_created_display" --></td>
-			<td><input type="submit" name="del<!-- TMPL_VAR NAME="tag_id" -->" value="Delete" /></td>
-		</tr>
-	<!-- /TMPL_LOOP --></tbody>
-		</table>
+    <!-- TMPL_IF name="mine" -->
+        <h1>My cloud</h1>
+    <!-- TMPL_ELSE -->
+        <h1>Everyone cloud</h1>
+    <!-- /TMPL_IF -->
+	
+		<form method="get" action="opac-tags.pl">
+		<fieldset>Show up to <input name="limit" style="text-align: right;" maxlength="4" size="4" value="<!-- TMPL_VAR NAME="limit" DEFAULT="100" -->" /> tags. 
+            <!-- TMPL_IF name="mine" -->
+                (<input type="checkbox" name="mine" value="1" checked="1"/>Mine only)
+            <!-- TMPL_ELSE -->
+                (<input type="checkbox" name="mine" value="1" />Mine only)
+            <!-- /TMPL_IF -->
+			<input type="submit" value="OK" /> <!-- TMPL_UNLESS NAME="MY_TAGS" --><a href="/cgi-bin/koha/opac-user.pl">Log in</a> to see your own saved tags.<!-- /TMPL_UNLESS --></fieldset>
 		</form>
+	
+	<!-- TMPL_IF NAME="TAGLOOP" -->
+	<div id="tagcloud">
+	<!-- TMPL_LOOP NAME="TAGLOOP" -->
+	<span class="tag" id="tag<!-- TMPL_VAR NAME="__counter__" -->" title="<!-- TMPL_VAR NAME="cloudweight" -->">
+		<a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&amp;q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->">
+		<!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a>
+			<span class="tagweight"><!-- TMPL_VAR NAME="weight_total" --></span>
+	</span>
+	<!-- /TMPL_LOOP -->
+	</div>
 	<!-- /TMPL_IF -->
-	<!-- /TMPL_UNLESS -->
-
-
+    
 </div>
 </div>
 </div>
diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl
index 296fa07..dc229fd 100755
--- a/opac/opac-tags.pl
+++ b/opac/opac-tags.pl
@@ -219,7 +219,7 @@ if ($is_ajax) {
 my $results = [];
 my $my_tags = [];
 
-if ($loggedinuser and not $query->param('hidemytags')) {
+if ($loggedinuser) {
 	$my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
 	foreach (@$my_tags) {
 		my $biblio = GetBiblioData($_->{biblionumber});
@@ -244,12 +244,14 @@ if ($add_op) {
 		deleted_count => $dels,
 	);
 } else {
-	my ($arg,$limit);
+	my ($arg,$limit,$mine);
 	my $hardmax = 100;	# you might disagree what this value should be, but there definitely should be a max
 	$limit = $query->param('limit') || $hardmax;
+    $mine =  $query->param('mine') || 0; # set if the patron want to see only his own tags.
 	($limit =~ /^\d+$/ and $limit <= $hardmax) or $limit = $hardmax;
 	$template->param(limit => $limit);
 	my $arghash = {approved=>1, limit=>$limit, 'sort'=>'-weight_total'};
+    $arghash->{'borrowernumber'} = $loggedinuser if $mine;
 	# ($openadds) or $arghash->{approved} = 1;
 	if ($arg = $query->param('tag')) {
 		$arghash->{term} = $arg;
@@ -259,7 +261,7 @@ if ($add_op) {
 	$results = get_approval_rows($arghash);
 
 	my $count = scalar @$results;
-	$template->param(TAGLOOP_COUNT => $count);
+	$template->param(TAGLOOP_COUNT => $count, mine => $mine);
 	# Here we make a halfhearted attempt to separate the tags into "strata" based on weight_total
 	# FIXME: code4lib probably has a better algorithm, iirc
 	# FIXME: when we get a better algorithm, move to C4
@@ -286,9 +288,9 @@ if ($add_op) {
 		$previous = $current;
 	}
 }
-$query->param('hidemytags') and $template->param(hidemytags => 1);
 (scalar @errors  ) and $template->param(ERRORS  => \@errors);
-(scalar @$results) and $template->param(TAGLOOP => $results);
+my @orderedresult = sort { $a->{'term'} cmp $b->{'term'} } @$results;
+(scalar @$results) and $template->param(TAGLOOP => \@orderedresult );
 (scalar @$my_tags) and $template->param(MY_TAGS => $my_tags);
 
 output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.6.0.4




More information about the Koha-patches mailing list