[Koha-patches] [PATCH] bug 1448: improve subject classification browser

Galen Charlton galen.charlton at liblime.com
Fri May 15 16:40:00 CEST 2009


* turn on warnings
* fix problem where the top level of the classification
  hiearchy wasn't displayed, instead pointing to
  the link to the Wiki page with instructions on
  how to set up the feature.
* fix XHTML validation errors
---
 .../opac-tmpl/prog/en/modules/opac-browser.tmpl    |   21 ++++++-----
 opac/opac-browser.pl                               |   38 +++++++++++++++----
 2 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-browser.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-browser.tmpl
index 726d218..05f974f 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-browser.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-browser.tmpl
@@ -10,35 +10,36 @@
 	<div class="yui-b"><div class="yui-g">
 <div class="container">
     <h1>Browse our catalogue</h1>
-        <!-- TMPL_IF name="HIERARCHY_LOOP" -->
+        <!-- TMPL_IF name="have_hierarchy" -->
         <ul>
         <li>
             <!-- TMPL_VAR name="description" --> <a href="opac-browser.pl">Top level</a>
         </li>
-        <ul>
+        <li style="list-style-type: none;"><ul>
         <!-- TMPL_LOOP name="HIERARCHY_LOOP" -->
                 <li>
-                    <a href="opac-browser.pl?level=<!-- TMPL_VAR name="level"-->&filter=<!-- TMPL_VAR name="classification"-->"><!-- TMPL_VAR name="description" --></a>
+                    <a href="opac-browser.pl?level=<!-- TMPL_VAR name="level"-->&amp;filter=<!-- TMPL_VAR name="classification" ESCAPE="uri" -->"><!-- TMPL_VAR name="description" ESCAPE="html" --></a>
                 </li>
-            <ul>
+            <li  style="list-style-type: none;"><ul>
         <!-- /TMPL_LOOP -->
-        <table><tr>
+        <li style="list-style-type: none;"><table><tr>
         <!-- TMPL_LOOP name="LEVEL_LOOP" -->
                 <td width="33%">
                 <p>
                 <!-- TMPL_IF name="endnode" -->
-                    <a href="opac-search.pl?q=Dewey-classification:<!-- TMPL_VAR name="classification" -->"><!-- TMPL_VAR name="description" --></a>
+                    <a href="opac-search.pl?q=Dewey-classification:<!-- TMPL_VAR name="classification" ESCAPE="uri" -->"><!-- TMPL_VAR name="description" ESCAPE="html" --></a>
                 <!-- TMPL_ELSE -->
-                    <a href="opac-browser.pl?level=<!-- TMPL_VAR name="level"-->&filter=<!-- TMPL_VAR name="classification"-->"><!-- TMPL_VAR name="description" --></a>
+                    <a href="opac-browser.pl?level=<!-- TMPL_VAR name="level"-->&amp;filter=<!-- TMPL_VAR name="classification" ESCAPE="uri" -->"><!-- TMPL_VAR name="description" ESCAPE="html" --></a>
                 <!-- /TMPL_IF --></p>
                 <p style="font-size:0.75em"><i>(<!-- TMPL_VAR name="number"--> biblios)</i></p>
                 </td>
                 <!-- TMPL_IF name="count3" --></tr><tr><!-- /TMPL_IF -->
         <!-- /TMPL_LOOP -->
+        </tr></table></li>
         <!-- TMPL_LOOP name="HIERARCHY_LOOP" -->
-            </ul>
+            </ul></li>
         <!-- /TMPL_LOOP -->
-        </ul>
+        </ul></li></ul>
         <!-- TMPL_ELSE -->
             <div class="warning">The browser table is empty. this feature is not fully set-up. See the <a href="http://wiki.koha.org/doku.php?id=opacbrowser">Koha Wiki</a> for more information on what it does and how to configure it.</div>
         <!-- /TMPL_IF -->
@@ -52,4 +53,4 @@
 </div>
 </div><!-- /TMPL_IF -->
 </div>
-<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
\ No newline at end of file
+<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
diff --git a/opac/opac-browser.pl b/opac/opac-browser.pl
index f1d98f0..df9c3ca 100755
--- a/opac/opac-browser.pl
+++ b/opac/opac-browser.pl
@@ -18,13 +18,15 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 
-=head1 opac-tags_subject.pl
+=head1 opac-browser.pl
 
 TODO :: Description here
 
 =cut
 
 use strict;
+use warnings;
+
 use C4::Auth;
 use C4::Context;
 use C4::Output;
@@ -50,6 +52,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 # the level of browser to display
 my $level = $query->param('level') || 0;
 my $filter = $query->param('filter');
+$filter = '' unless defined $filter;
 $level++; # the level passed is the level of the PREVIOUS list, not the current one. Thus the ++
 
 # build this level loop
@@ -59,24 +62,43 @@ my @level_loop;
 my $i=0;
 while (my $line = $sth->fetchrow_hashref) {
     $line->{description} =~ s/\((.*)\)//g;
-    $i++;
-    $line->{count3}=1 unless $i %3;
     push @level_loop,$line;
 }
 
+my $have_hierarchy = 0;
+
 # now rebuild hierarchy loop
-$sth = $dbh->prepare("SELECT * FROM browser where classification=?");
 $filter =~ s/\.//g;
 my @hierarchy_loop;
-for (my $i=1;$i <=length($filter);$i++) {
-    $sth->execute(substr($filter,0,$i));
-    my $line = $sth->fetchrow_hashref;
-    push @hierarchy_loop,$line;
+if ($filter eq '' and $level == 1) {
+    # we're starting from the top
+    $have_hierarchy = 1 if @level_loop;
+    unless (@level_loop) {
+        $sth->execute(1, "%");
+        while (my $line = $sth->fetchrow_hashref) {
+            $line->{description} =~ s/\((.*)\)//g;
+            push @level_loop,$line;
+        }
+    }
+} else {
+    $sth = $dbh->prepare("SELECT * FROM browser where classification=?");
+    for (my $i=1;$i <=length($filter);$i++) {
+        $sth->execute(substr($filter,0,$i));
+        my $line = $sth->fetchrow_hashref;
+        push @hierarchy_loop,$line;
+    }
+    $have_hierarchy = 1 if @hierarchy_loop;
+}
+
+# mark every third entry in level_loop
+for (my $i = 0; $i <= $#level_loop; $i++) {
+    $level_loop[$i]->{count3} = 1 if 2 == $i % 3 && $i != $#level_loop;
 }
 
 $template->param(
     LEVEL_LOOP => \@level_loop,
     HIERARCHY_LOOP => \@hierarchy_loop,
+    have_hierarchy => $have_hierarchy,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.5.6.5




More information about the Koha-patches mailing list