[Koha-cvs] koha koha-tmpl/opac-tmpl/prog/en/opac-tags_subj... [rel_3_0]

paul poulain paul at koha-fr.org
Wed Dec 20 11:39:23 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	paul poulain <tipaul>	06/12/20 10:39:23

Added files:
	koha-tmpl/opac-tmpl/prog/en: opac-tags_subject.tmpl 
	misc/cronjobs  : build_tags.pl 
	opac           : opac-tags_subject.pl 

Log message:
	NEW FEATURE : opac tagclouds
	
	It relies on a small table (updatedatabase still to do), that stores the subjects/weight.
	The patron can select how many tags he sees in the page.
	
	It works, but we still need to :
	- make the build_tags script marc flavour independant (atm, it's unimarc related only)
	- improve the build_tags script to enable incremental building (=each night and each week). We still can have the complete build, running 1 month. note that the incremental builg don't need to be 100% right : a deleted subject, for example, can be ignored (& can't be traced easily). That's why we need a monthly complete rebuild.
	- create a package  for SQL query in opac-tags_subjects.pl (that will be useful somewhere else)
	- add an author tag cloud (add a column in the table, or create a new table)
	- add an edito tag cloud (same note)
	- add the subject cloud on opac-main.pl (with only, say 50 subjects) and a "see more tag ..." link

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/opac-tmpl/prog/en/opac-tags_subject.tmpl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/cronjobs/build_tags.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-tags_subject.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1

Patches:
Index: koha-tmpl/opac-tmpl/prog/en/opac-tags_subject.tmpl
===================================================================
RCS file: koha-tmpl/opac-tmpl/prog/en/opac-tags_subject.tmpl
diff -N koha-tmpl/opac-tmpl/prog/en/opac-tags_subject.tmpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ koha-tmpl/opac-tmpl/prog/en/opac-tags_subject.tmpl	20 Dec 2006 10:39:23 -0000	1.1.2.1
@@ -0,0 +1,16 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_VAR NAME="LibraryNameTitle" --> Catalog -- ISBD
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
+<!--TMPL_INCLUDE NAME="masthead.inc" -->
+<!--TMPL_INCLUDE NAME="navigation.inc" -->
+
+    <div id="action">
+        <form>
+            <p>Show me <input type="text" name="number" value="<!-- TMPL_VAR name="number" -->" size="4" maxlength="4"/> subjects <input type="submit" value="OK"></p>
+        </form>
+    </div>
+    <h1>Subjects</h1>
+        <!-- TMPL_LOOP name="LOOP" -->
+            <a href="/cgi-bin/koha/opac-search.pl?q=su:<!-- TMPL_VAR name="entry" ESCAPE="HTML" -->" style="font-size:<!-- TMPL_VAR name="weight" -->px;"><!-- TMPL_VAR name="entry" --></a>
+        <!-- /TMPL_LOOP -->
+<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->

Index: misc/cronjobs/build_tags.pl
===================================================================
RCS file: misc/cronjobs/build_tags.pl
diff -N misc/cronjobs/build_tags.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ misc/cronjobs/build_tags.pl	20 Dec 2006 10:39:23 -0000	1.1.2.1
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+# small script that rebuilds the non-MARC DB
+
+use strict;
+
+# Koha modules used
+# use MARC::File::USMARC;
+# use MARC::Record;
+# use MARC::Batch;
+use C4::Koha;
+use C4::Context;
+use C4::Biblio;
+use Date::Calc;
+use Time::HiRes qw(gettimeofday);
+use ZOOM;
+use MARC::File::USMARC;
+use Getopt::Long;
+my ( $input_marc_file, $number) = ('',0);
+my ($version, $confirm,$test_parameter);
+GetOptions(
+	'c' => \$confirm,
+	'h' => \$version,
+	't' => \$test_parameter,
+);
+
+if ($version || (!$confirm)) {
+	print <<EOF
+    TO BE WRITTEN
+EOF
+;
+die;
+}
+
+##################################
+#
+# MAIN PARAMETERS
+#
+###################################
+
+my $tag = '606';
+my $subfield = 'a';
+
+my $verbose = 0;
+
+my $dbh = C4::Context->dbh;
+my $starttime = time();
+
+my $i=0;
+$|=1; # flushes output
+my $starttime = gettimeofday;
+
+##################################
+#
+# Parse all the database.
+#
+###################################
+#FIXME : could be improved to get directly only biblios that have to be updated.
+
+my $sth = $dbh->prepare("select biblionumber from biblioitems");
+$sth->execute;
+my %result;
+while ((my ($biblionumber)= $sth->fetchrow)) {
+    $i++;
+    print ".";
+    #now, parse the record, extract the item fields, and store them in somewhere else.
+    my $Koharecord = GetMarcBiblio($biblionumber);
+#     warn $Koharecord->as_formatted;
+    foreach ($Koharecord->field($tag)) {
+        my $line;
+        foreach ($_->subfields()) {
+            next if $_->[0]=~ /\d/;
+            $line .= $_->[1].' -- ';
+        }
+        $line =~ s/ -- $//;
+        $result{$line}++;
+    }
+	my $timeneeded = gettimeofday - $starttime;
+	print "$i in $timeneeded s\n" unless ($i % 50);
+}
+# use Data::Dumper;
+# print "==> ".Dumper(%result);
+# die;
+
+$dbh->do("truncate tags");
+my $sth = $dbh->prepare("insert into tags (entry,weight) values (?,?)");
+foreach (keys %result) {
+#     warn "insert";
+    $sth->execute($_,$result{$_});
+}
+
+# $dbh->do("unlock tables");
+my $timeneeded = time() - $starttime;
+print "$i MARC record done in $timeneeded seconds\n";

Index: opac/opac-tags_subject.pl
===================================================================
RCS file: opac/opac-tags_subject.pl
diff -N opac/opac-tags_subject.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ opac/opac-tags_subject.pl	20 Dec 2006 10:39:23 -0000	1.1.2.1
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+# $Id: opac-tags_subject.pl,v 1.1.2.1 2006/12/20 10:39:23 tipaul Exp $
+
+=head1 NAME
+
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+use strict;
+require Exporter;
+use C4::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use CGI;
+use C4::Biblio;
+use C4::Koha;       # use getitemtypeinfo
+
+my $query = new CGI;
+
+my $dbh = C4::Context->dbh;
+
+# open template
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "opac-tags_subject.tmpl",
+        query           => $query,
+        type            => "opac",
+        authnotrequired => 1,
+        debug           => 1,
+    }
+);
+
+
+my $number = $query->param('number') || 100;
+
+my $sth = $dbh->prepare("SELECT entry,weight FROM tags ORDER BY weight DESC LIMIT $number");
+$sth->execute;
+
+my %result;
+my $max=0;
+my $min=9999;
+my ($entry,$weight);
+while (($entry,$weight) = $sth->fetchrow) {
+    $result{$entry}=$weight;
+#     warn "==".$weight;
+    $max = $weight if $weight > $max;
+    $min = $weight if $weight < $min;
+}
+
+$min++ if $min == $max;
+
+my @loop;
+foreach my $entry (sort keys %result) {
+    my %line;
+    $line{entry} = $entry;
+    $line{weight} = int(($result{$entry}-$min)/($max-$min)*25)+10;
+    push @loop, \%line;
+}
+$template->param(
+    LOOP => \@loop,
+    number => $number,
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;
\ No newline at end of file





More information about the Koha-cvs mailing list