From 4e282d78e6dac9f09ca7a0e19d170c4c30773f45 Mon Sep 17 00:00:00 2001
From: Srdjan Jankovic <[email protected]>
Date: Mon, 13 Feb 2012 17:47:54 +1300
Subject: [PATCH] Bug 5668 - star ratings in the OPAC
Created ratings table.
RatingsEnabled syspref.
---
C4/Auth.pm | 5 +-
C4/Output.pm | 23 +++-
C4/Ratings.pm | 143 ++++++++++++++++++++
installer/data/mysql/kohastructure.sql | 16 +++
installer/data/mysql/updatedatabase.pl | 19 +++
.../prog/en/modules/admin/preferences/opac.pref | 6 +
koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css | 12 ++
.../en/lib/jquery/plugins/jquery.rating.pack.js | 11 ++
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 50 +++++++-
.../opac-tmpl/prog/en/modules/opac-results.tt | 58 ++++++++
koha-tmpl/opac-tmpl/prog/images/delete.gif | Bin 0 -> 752 bytes
koha-tmpl/opac-tmpl/prog/images/star.gif | Bin 0 -> 815 bytes
opac/opac-detail.pl | 32 +++++
opac/opac-ratings.pl | 104 ++++++++++++++
opac/opac-search.pl | 29 ++++-
15 files changed, 500 insertions(+), 8 deletions(-)
create mode 100644 C4/Ratings.pm
create mode 100644 koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css
create mode 100644 koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.pack.js
create mode 100644 koha-tmpl/opac-tmpl/prog/images/delete.gif
create mode 100644 koha-tmpl/opac-tmpl/prog/images/star.gif
create mode 100755 opac/opac-ratings.pl
diff --git a/C4/Auth.pm b/C4/Auth.pm
index e4bd119..798b916 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -351,6 +351,7 @@ sub get_template_and_user {
LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
TagsEnabled => C4::Context->preference("TagsEnabled"),
+ RatingsEnabled => C4::Context->preference("RatingsEnabled"),
hide_marc => C4::Context->preference("hide_marc"),
item_level_itypes => C4::Context->preference('item-level_itypes'),
patronimages => C4::Context->preference("patronimages"),
@@ -993,9 +994,9 @@ sub checkauth {
OpacAuthorities => C4::Context->preference("OpacAuthorities"),
OpacBrowser => C4::Context->preference("OpacBrowser"),
opacheader => C4::Context->preference("opacheader"),
- TagsEnabled => C4::Context->preference("TagsEnabled"),
- OPACUserCSS => C4::Context->preference("OPACUserCSS"),
opacstylesheet => C4::Context->preference("opacstylesheet"),
+ TagsEnabled => C4::Context->preference("TagsEnabled"),
+ OPACUserCSS => C4::Context->preference("OPACUserCSS"),
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
diff --git a/C4/Output.pm b/C4/Output.pm
index 75ced46..86a8f8d 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -41,13 +41,16 @@ BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
- %EXPORT_TAGS = ( all =>[qw(&pagination_bar
- &output_with_http_headers &output_html_with_http_headers)],
- ajax =>[qw(&output_with_http_headers is_ajax)],
+ %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie &pagination_bar
+ &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
+ ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
);
push @EXPORT, qw(
- &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
+ &themelanguage &gettemplate setlanguagecookie getlanguagecookie
+ );
+ push @EXPORT, qw(
+ &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
);
}
@@ -306,6 +309,18 @@ sub output_html_with_http_headers ($$$;$) {
output_with_http_headers( $query, $cookie, $data, 'html', $status );
}
+
+sub output_ajax_with_http_headers ($$) {
+ my ( $query, $js ) = @_;
+ print $query->header(
+ -type => 'text/javascript',
+ -charset => 'UTF-8',
+ -Pragma => 'no-cache',
+ -'Cache-Control' => 'no-cache',
+ -expires => '-1d',
+ ), $js;
+}
+
sub is_ajax () {
my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
diff --git a/C4/Ratings.pm b/C4/Ratings.pm
new file mode 100644
index 0000000..553a1c7
--- /dev/null
+++ b/C4/Ratings.pm
@@ -0,0 +1,143 @@
+package C4::Ratings;
+
+# Copyright 2010 KohaAloha, NZ
+# Parts copyright 2011, Catalyst IT, NZ.
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+=head1 C4::Ratings - the Koha API for dealing with star ratings for biblios
+
+This provides an interface to the ratings system, in order to allow them
+to be manipulated or queried.
+
+=cut
+
+use strict;
+use warnings;
+use Carp;
+use Exporter;
+
+use C4::Debug;
+use C4::Context;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+
+BEGIN {
+ $VERSION = 3.00;
+ @ISA = qw(Exporter);
+
+ @EXPORT = qw(
+ get_rating add_rating
+ );
+
+ # %EXPORT_TAGS = ();
+}
+
+=head2 get_rating
+
+ get_rating($biblionumber, $borrowernumber)
+
+This returns the rating for the supplied biblionumber. It will also return
+the rating that the supplied user gave to the provided biblio. If a particular
+value can't be supplied, '0' is returned for that value.
+
+=head 3 RETURNS
+
+A hashref containing:
+
+=over
+
+=item total - the total number of ratings
+=item avg - the average of the ratings
+=item avgint - the integer form of the average
+=item value - the user's rating
+
+=back
+
+=cut
+
+my ($total_query_sth, $user_query_sth);
+sub get_rating {
+ my ( $biblionumber, $borrowernumber ) = @_;
+ my $dbh = C4::Context->dbh;
+
+ my $total_query = "
+ SELECT AVG(value) AS average,COUNT(value) AS total FROM ratings
+ WHERE biblionumber = ?";
+ $total_query_sth = $total_query_sth || $dbh->prepare($total_query);
+
+ $total_query_sth->execute($biblionumber);
+ my $total_query_res = $total_query_sth->fetchrow_hashref();
+
+ my $user_rating = 0;
+ if ($borrowernumber) {
+ my $user_query = "
+ SELECT value from ratings
+ WHERE biblionumber = ? and borrowernumber = ?";
+ $user_query_sth ||= $dbh->prepare($user_query);
+
+ $user_query_sth->execute( $biblionumber, $borrowernumber );
+ my $user_query_res = $user_query_sth->fetchrow_hashref();
+ $user_rating = $user_query_res->{value} || 0;
+ }
+ my ( $avg, $avgint ) = 0;
+ $avg = $total_query_res->{average} || 0;
+ $avgint = sprintf( "%.0f", $avg );
+
+ my %rating_hash;
+ $rating_hash{total} = $total_query_res->{total} || 0;
+ $rating_hash{avg} = $avg;
+ $rating_hash{avgint} = $avgint;
+ $rating_hash{value} = $user_rating;
+ return \%rating_hash;
+}
+
+=head2 add_rating
+
+ add_rating($biblionumber, $borrowernumber, $value)
+
+This adds or updates a rating for a particular user on a biblio. If the value
+is 0, then the rating will be deleted. If the value is out of the range of
+0-5, nothing will happen.
+
+=cut
+
+my ($delete_query_sth, $insert_query_sth);
+sub add_rating {
+ my ( $biblionumber, $borrowernumber, $value ) = @_;
+ if (!defined($biblionumber) || !defined($borrowernumber) ||
+ $value < 0 || $value > 5) {
+ # Seen this happen, want to know about it if it happens again.
+ carp "Invalid input coming in to C4::Ratings::add_rating";
+ return;
+ }
+ if ($borrowernumber == 0) {
+ carp "Attempted to add a rating for borrower number 0";
+ return;
+ }
+ my $dbh = C4::Context->dbh;
+ my $delete_query = "DELETE FROM ratings WHERE borrowernumber = ? AND biblionumber = ? LIMIT 1";
+ my $delete_query_sth ||= $dbh->prepare($delete_query);
+ $delete_query_sth->execute( $borrowernumber, $biblionumber );
+ return if $value == 0; # We don't add a rating for zero
+
+ my $insert_query = "INSERT INTO ratings (borrowernumber,biblionumber,value)
+ VALUES (?,?,?)";
+ $insert_query_sth ||= $dbh->prepare($insert_query);
+ $insert_query_sth->execute( $borrowernumber, $biblionumber, $value );
+}
+
+1;
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 37113c2..66a931c 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -2686,6 +2686,22 @@ CREATE TABLE `bibliocoverimage` (
CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+--
+-- 'Ratings' table. This tracks the star ratings set by borrowers.
+--
+
+DROP TABLE IF EXISTS `ratings`;
+CREATE TABLE `ratings` (
+ `borrowernumber` int(11) NOT NULL, -- the borrower this rating is for
+ `biblionumber` int(11) NOT NULL, -- the biblio it's for
+ `value` tinyint(1) NOT NULL, -- the rating, from 1-5
+ `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+ PRIMARY KEY (`borrowernumber`,`biblionumber`),
+ CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index d4ac31d..c6f051d 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4671,6 +4671,25 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
SetVersion ($DBversion);
}
+$DBversion = '3.07.00.XXX';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do( qq |
+ CREATE TABLE `ratings` (
+ `borrowernumber` int(11) NOT NULL,
+ `biblionumber` int(11) NOT NULL,
+ `value` tinyint(1) NOT NULL,
+ `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+ PRIMARY KEY (`borrowernumber`, `biblionumber`),
+ CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 | );
+
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('RatingsEnabled','','Enabled or disables ratings feature in the OPAC',NULL,'YesNo')");
+
+ print "Upgrade to $DBversion done (Added 'ratings' table, and 'RatingsEnabled' syspref\n";
+ SetVersion ($DBversion);
+}
+
=head1 FUNCTIONS
=head2 DropAllForeignKeys($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
index d6ae2b2..3cd74b5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
@@ -292,6 +292,12 @@ OPAC:
- pref: numSearchRSSResults
class: long
- search results in the RSS feed.
+ -
+ - pref: RatingsEnabled
+ choices:
+ yes: Show
+ no: "Don't show"
+ - star ratings
Policy:
-
- pref: singleBranchMode
diff --git a/koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css b/koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css
new file mode 100644
index 0000000..f59c0a2
--- /dev/null
+++ b/koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css
@@ -0,0 +1,12 @@
+/* jQuery.Rating Plugin CSS - http://www.fyneworks.com/jquery/star-rating/ */
+div.rating-cancel,div.star-rating{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden}
+div.rating-cancel,div.rating-cancel a{background:url(../../images/delete.gif) no-repeat 0 -16px}
+div.star-rating,div.star-rating a{background:url(../../images/star.gif) no-repeat 0 0px}
+div.rating-cancel a,div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0}
+div.star-rating-on a{background-position:0 -16px!important}
+div.star-rating-hover a{background-position:0 -32px}
+/* Read Only CSS */
+div.star-rating-readonly a{cursor:default !important}
+/* Partial Star CSS */
+div.star-rating{background:transparent!important;overflow:hidden!important}
+/* END jQuery.Rating Plugin CSS */
diff --git a/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.pack.js b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.pack.js
new file mode 100644
index 0000000..5da9f93
--- /dev/null
+++ b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.pack.js
@@ -0,0 +1,11 @@
+/*
+ ### jQuery Star Rating Plugin v3.14 - 2012-01-26 ###
+ * Home: http://www.fyneworks.com/jquery/star-rating/
+ * Code: http://code.google.com/p/jquery-star-rating-plugin/
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ ###
+*/
+eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(1W.1z)(7($){5($.21.1Y)1X{1u.1Q("1P",M,t)}1O(e){};$.n.3=7(i){5(4.S==0)l 4;5(H Q[0]==\'1s\'){5(4.S>1){8 j=Q;l 4.11(7(){$.n.3.G($(4),j)})};$.n.3[Q[0]].G(4,$.20(Q).1T(1)||[]);l 4};8 i=$.U({},$.n.3.1k,i||{});$.n.3.O++;4.1K(\'.k-3-1j\').p(\'k-3-1j\').11(7(){8 a,9=$(4);8 b=(4.28||\'26-3\').1g(/\\[|\\]/g,\'10\').1g(/^\\10+|\\10+$/g,\'\');8 c=$(4.1N||1u.1B);8 d=c.6(\'3\');5(!d||d.1d!=$.n.3.O)d={B:0,1d:$.n.3.O};8 e=d[b];5(e)a=e.6(\'3\');5(e&&a)a.B++;C{a=$.U({},i||{},($.1c?9.1c():($.1C?9.6():u))||{},{B:0,F:[],v:[]});a.w=d.B++;e=$(\'<23 14="k-3-1I"/>\');9.1M(e);e.p(\'3-18-19-1a\');5(9.T(\'J\')||9.12(\'J\'))a.m=t;5(9.12(\'Y\'))a.Y=t;e.1o(a.D=$(\'<L 14="3-D"><a 13="\'+a.D+\'">\'+a.1e+\'</a></L>\').1f(7(){$(4).3(\'R\');$(4).p(\'k-3-P\')}).1h(7(){$(4).3(\'x\');$(4).E(\'k-3-P\')}).1i(7(){$(4).3(\'r\')}).6(\'3\',a))};8 f=$(\'<L 14="k-3 q-\'+a.w+\'"><a 13="\'+(4.13||4.1l)+\'">\'+4.1l+\'</a></L>\');e.1o(f);5(4.17)f.T(\'17\',4.17);5(4.1m)f.p(4.1m);5(a.1Z)a.s=2;5(H a.s==\'1n\'&&a.s>0){8 g=($.n.Z?f.Z():0)||a.1p;8 h=(a.B%a.s),W=1D.1E(g/a.s);f.Z(W).1F(\'a\').1G({\'1H-1A\':\'-\'+(h*W)+\'1J\'})};5(a.m)f.p(\'k-3-1q\');C f.p(\'k-3-1L\').1f(7(){$(4).3(\'1r\');$(4).3(\'I\')}).1h(7(){$(4).3(\'x\');$(4).3(\'z\')}).1i(7(){$(4).3(\'r\')});5(4.N)a.o=f;5(4.1R=="A"){5($(4).12(\'1S\'))a.o=f};9.1t();9.1U(7(){$(4).3(\'r\')});f.6(\'3.9\',9.6(\'3.k\',f));a.F[a.F.S]=f[0];a.v[a.v.S]=9[0];a.q=d[b]=e;a.1V=c;9.6(\'3\',a);e.6(\'3\',a);f.6(\'3\',a);c.6(\'3\',d)});$(\'.3-18-19-1a\').3(\'x\').E(\'3-18-19-1a\');l 4};$.U($.n.3,{O:0,I:7(){8 a=4.6(\'3\');5(!a)l 4;5(!a.I)l 4;8 b=$(4).6(\'3.9\')||$(4.V==\'15\'?4:u);5(a.I)a.I.G(b[0],[b.K(),$(\'a\',b.6(\'3.k\'))[0]])},z:7(){8 a=4.6(\'3\');5(!a)l 4;5(!a.z)l 4;8 b=$(4).6(\'3.9\')||$(4.V==\'15\'?4:u);5(a.z)a.z.G(b[0],[b.K(),$(\'a\',b.6(\'3.k\'))[0]])},1r:7(){8 a=4.6(\'3\');5(!a)l 4;5(a.m)l;4.3(\'R\');4.1v().1w().X(\'.q-\'+a.w).p(\'k-3-P\')},R:7(){8 a=4.6(\'3\');5(!a)l 4;5(a.m)l;a.q.22().X(\'.q-\'+a.w).E(\'k-3-1x\').E(\'k-3-P\')},x:7(){8 a=4.6(\'3\');5(!a)l 4;4.3(\'R\');5(a.o){a.o.6(\'3.9\').T(\'N\',\'N\');a.o.1v().1w().X(\'.q-\'+a.w).p(\'k-3-1x\')}C $(a.v).1y(\'N\');a.D[a.m||a.Y?\'1t\':\'24\']();4.25()[a.m?\'p\':\'E\'](\'k-3-1q\')},r:7(a,b){8 c=4.6(\'3\');5(!c)l 4;5(c.m)l;c.o=u;5(H a!=\'y\'){5(H a==\'1n\')l $(c.F[a]).3(\'r\',y,b);5(H a==\'1s\')$.11(c.F,7(){5($(4).6(\'3.9\').K()==a)$(4).3(\'r\',y,b)})}C c.o=4[0].V==\'15\'?4.6(\'3.k\'):(4.27(\'.q-\'+c.w)?4:u);4.6(\'3\',c);4.3(\'x\');8 d=$(c.o?c.o.6(\'3.9\'):u);5((b||b==y)&&c.1b)c.1b.G(d[0],[d.K(),$(\'a\',c.o)[0]])},m:7(a,b){8 c=4.6(\'3\');5(!c)l 4;c.m=a||a==y?t:M;5(b)$(c.v).T("J","J");C $(c.v).1y("J");4.6(\'3\',c);4.3(\'x\')},29:7(){4.3(\'m\',t,t)},2a:7(){4.3(\'m\',M,M)}});$.n.3.1k={D:\'2b 2c\',1e:\'\',s:0,1p:16};$(7(){$(\'9[2d=2e].k\').3()})})(1z);',62,139,'|||rating|this|if|data|function|var|input|||||||||||star|return|readOnly|fn|current|addClass|rater|select|split|true|null|inputs|serial|draw|undefined|blur||count|else|cancel|removeClass|stars|apply|typeof|focus|disabled|val|div|false|checked|calls|hover|arguments|drain|length|attr|extend|tagName|spw|filter|required|width|_|each|hasClass|title|class|INPUT||id|to|be|drawn|callback|metadata|call|cancelValue|mouseover|replace|mouseout|click|applied|options|value|className|number|append|starWidth|readonly|fill|string|hide|document|prevAll|andSelf|on|removeAttr|jQuery|left|body|meta|Math|floor|find|css|margin|control|px|not|live|before|form|catch|BackgroundImageCache|execCommand|nodeName|selected|slice|change|context|window|try|msie|half|makeArray|browser|children|span|show|siblings|unnamed|is|name|disable|enable|Cancel|Rating|type|radio'.split('|'),0,{}))
\ No newline at end of file
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
index dd1c33f..a292d4c 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
@@ -1,6 +1,8 @@
[% INCLUDE 'doc-head-open.inc' %][% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog › Details for: [% title |html %][% FOREACH subtitl IN subtitle %], [% subtitl.subfield |html %][% END %]
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.pack.js"></script>
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
[% IF ( busc ) %]
@@ -206,7 +208,30 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
});
-
+
+[% IF (RatingsEnabled) %]
+$(document).ready(function() {
+
+$(".auto-submit-star").rating({
+ callback: function(value, link){
+ $.post("/cgi-bin/koha/opac-ratings.pl",
+ { rating: value,
+ biblionumber: "[% biblionumber %]"
+ },
+ function(data){
+ $("#rating_total").html(' ('+data.total+' '+ (data.total==1 ? _('vote') : _('votes'))+')');
+ if (data.value) {
+ $("#rating_user").text(_('your rating added: ')+data.value);
+ } else {
+ $("#rating_user").text('');
+ }
+ }
+ , "json");
+ }
+});
+
+});
+[% END %]
//]]>
</script>
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
@@ -471,6 +496,29 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
</span>
[% END %][% END %][% END %]
+ [% IF (RatingsEnabled) %]
+ <div class="results_summary">
+ <input class="auto-submit-star" type="radio" name="rating[% biblionumber %]" value="1" [% IF (rating_val_1) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% biblionumber %]" value="2" [% IF (rating_val_2) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% biblionumber %]" value="3" [% IF (rating_val_3) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% biblionumber %]" value="4" [% IF (rating_val_4) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% biblionumber %]" value="5" [% IF (rating_val_5) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %] />
+
+ <input type="hidden" name='biblionumber' value="[% biblionumber %]" />
+
+ <span id="rating_total" >
+[% IF(rating_total) %] ([% rating_total %] [% IF (rating_total==1) %]vote[% ELSE %]votes[% END %])[% END %]
+</span>
+
+ <span id="rating_user">[% IF (rating_value) %]your rating: [% rating_value %][% END %]</span>
+ [% IF (rating_readonly) %]
+ <span id="rating_login">Log in to add your rating.</span>
+ [% END %]
+</div>
+
+[% END %]
+
+
[% IF ( BakerTaylorContentURL ) %]
<span class="results_summary">
<span class="label">Enhanced Content: </span>
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt
index 2f3c7d5..d0e17c3 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt
@@ -8,6 +8,10 @@
[% INCLUDE 'doc-head-close.inc' %]
<link rel="alternate" type="application/rss+xml" title="[% LibraryName |html %] Search RSS Feed" href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&count=[% countrss |html %]&sort_by=acqdate_dsc&format=rss2" />
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.pack.js"></script>
+
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />
+
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
@@ -78,6 +82,8 @@ function tagAdded() {
KOHA.Tags.add_multitags_button(bibs, tag);
return false;
}[% END %][% END %]
+
+
[% IF ( OpacHighlightedWords ) %]
var q_array = new Array(); // holds search terms if available
@@ -231,7 +237,32 @@ $(document).ready(function(){
[% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
[% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
[% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
+
+
+}); // end of $(document).ready
+
+[% IF ( RatingsEnabled ) %]
+$(document).ready(function() {
+ $('.auto-submit-star').rating({
+ callback: function(value, link){
+ var bibnum = this.name.replace(/^rating/, "");
+
+ $.post("/cgi-bin/koha/opac-ratings.pl", {
+ rating: value,
+ biblionumber: bibnum
+ }, function(data){
+ $("#rating_total_"+bibnum).html(" ("+data.total+' '+ (data.total==1 ? _('vote') : _('votes'))+')');
+ if (data.value) {
+ $("#rating_value_"+bibnum).text(_('your rating added: ')+data.value);
+ } else {
+ $("#rating_value_"+bibnum).text('');
+ }
+ }, "json");
+ }
+ });
});
+[% END %]
+
//]]>
</script>
</head>
@@ -501,6 +532,33 @@ $(document).ready(function(){
</div>[% END %]
[% END %]
[% END %][% END %]
+
+[% IF ( RatingsEnabled ) %]
+<div class="results_summary">
+ <form name="ratingform[% SEARCH_RESULT.biblionumber %]" method="post" action="/cgi-bin/koha/opac-ratings.pl">
+ <input class="auto-submit-star" type="radio" name="rating[% SEARCH_RESULT.biblionumber %]" value="1" [% IF ( SEARCH_RESULT.rating_val_1 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% SEARCH_RESULT.biblionumber %]" value="2" [% IF ( SEARCH_RESULT.rating_val_2 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% SEARCH_RESULT.biblionumber %]" value="3" [% IF ( SEARCH_RESULT.rating_val_3 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% SEARCH_RESULT.biblionumber %]" value="4" [% IF ( SEARCH_RESULT.rating_val_4 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %] />
+ <input class="auto-submit-star" type="radio" name="rating[% SEARCH_RESULT.biblionumber %]" value="5" [% IF ( SEARCH_RESULT.rating_val_5 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %] />
+ <input type="hidden" name='[% SEARCH_RESULT.biblionumber %]' value="[% SEARCH_RESULT.biblionumber %]" />
+ <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">
+ [% IF (SEARCH_RESULT.rating_total) %]
+ ([% SEARCH_RESULT.rating_total %] [% IF (SEARCH_RESULT.rating_total==1) %]vote[% ELSE %]votes[% END %])
+ [% END %]
+ </span>
+
+ <span id="rating_value_[% SEARCH_RESULT.biblionumber %]">
+ [% IF ( SEARCH_RESULT.rating_value ) %] your rating: [% SEARCH_RESULT.rating_value %][% END %]
+ </span>
+
+ </form>
+ <br />
+</div>
+[% END %]
+
+
+
[% IF ( SEARCH_RESULT.searchhighlightblob ) %]<span class="results_summary"><span class="label">Match:</span> [% SEARCH_RESULT.searchhighlightblob %]</span>[% END %]
<span class="results_summary actions"><span class="label">Actions:</span>
diff --git a/koha-tmpl/opac-tmpl/prog/images/delete.gif b/koha-tmpl/opac-tmpl/prog/images/delete.gif
new file mode 100644
index 0000000000000000000000000000000000000000..43c6ca8763d79bde87bcf437e497af00c8be562d
GIT binary patch
literal 752
zcmZ?wbhEHb6kt$bc*el6GthYN-n}zt&b)vB{*)<GZZDnssVwQ*wQJ8pz3-M6ef|3N
zTw?I^BRjWl-THaiqIb<TR|-<zzkh%9=+U)n*M2*H{@2X5mq}6Aa+CK)+kfaTd)M9Y
zW&YeVXU=?m_V93u_p1$S-kmu7EY$ycOu&bh{H05m9`-kWR9EwH&eRVR>i+-#|NQy$
zABXln&Q1FL`t{#CH*SY|{oJwc*Qz;h;)0))7aYq9ewP~fc2e)_P3vAY)$9wl{IzJp
zy{ydlr;a^HiGHwZ{*SH8FZkJhE{gei`OM?;ir*_{?@ji478&@mD*tSH_`A&5@6Vqe
z@G<&xeCOwiq-WvY-<q?(PpbX8Zpp{q%CC#&{pc>eS5f?;vgCP8#IHGBw=+^cY}xvy
zx8c*8mDl2ff1W;kCeZrNm9vlQYJg5<pbb#`$->Caki?(^G9DBs4DA0KlA4-ZT3fl8
z8F_gb*}2-1v>0WWwY1oIg_&Emc-aM+Wn|bpRc1GF^$N-etzA1qr9X*XNNWw_j-BjG
zGEKc(x)1gUF{(82E@ad^eMXp9hUxg0Q)f<}lVRDncBb&%dq*yAR+(|<o-jL$(28?2
zo;??45^QExc`no~#IC}^-ui`UvIUER!h-n=LseJ=rYP`FI@~V6z4by;((yhm^C*W!
z21kx@DaO@p*l}R7K&xy_%z+DytsIk;xgB`2439K+b7?GbXmoN_5mIg1@_?b4)vHb2
zW4=iz(~<TC27yT_6CAg$YSazO;JC%ee5xbs^c)q-iOvDjBs>l-D@bZwvw%g)cL7VG
z)An_f*+XqOetkIP*eg{wS7K(+qJ{-x0ue3?v&y~1d1To>MqD_2keNGNE=Pc|!BJ7b
fV_(F^#N=Z_Jo9)pKRPly^YODPxtB<AFjxZs(@{iI
literal 0
HcmV?d00001
diff --git a/koha-tmpl/opac-tmpl/prog/images/star.gif b/koha-tmpl/opac-tmpl/prog/images/star.gif
new file mode 100644
index 0000000000000000000000000000000000000000..d0948a70843bf01952d1f81dcfcdadc92976a04a
GIT binary patch
literal 815
zcmZ?wbhEHb6ksr5c*el6(A@m!(W5UnOP^`reSRqFN=wUy;^KSv?mbz*{y;*);~mc5
z-|RUW6m;#{wMW}bp6pHg_U+rN({8s`u6+0I-Q5+MAMeb%w`<p%^ObAe+`hkj`DTyO
z+d~E~k2$_RJM(N#&bNn2U+&-kax?1Vx!~u|pC6Bkx;a<%e0BBpNt3?6-n!q(>5!M#
z{q=^=j}*N*e*EQepZ7;K-(U6l^W*)qy-uI5Mx04YJ9FmD@2@w0e|`3BzvYV!svmDJ
zy1UBt<DL4wUS5~`l~&o?KiTc|?y&dMwH9wLt^WW2|BarW%QZD$t~tCq+4%9S{-+DB
zU+=}f+^q2P-MdfMLf>A9dUx3IVz=bW<9TmSpMHPB|LHc1x92?H@6~*NPV?1P?R#4d
zPbMV1-s|#ytJ9}D;U7+0e!n;8#jahi&$Zv4GUd&Fk1akv*Jf&ey1!wEi_7<GUO*ce
zC<BT=Ss2+FvKVwg#(?64f&G6&R#S79fN)Dk2QP1DuW+|=Z&!EEq$XuvcJ`T_!n3+(
zPg$TWFniYgMJuxwEHYhZ+HLC6v}WVFjRGxe*Yle0Y?-ll&zz2hYr8v-tu*bNVmfR6
znT~Z6o0Ux&=T2&$rVu=>gU#eYv#yB=$CE4*Ha3+f942mV(XO4k$!yUkYI4!<crrvB
zCM=xaSm|bCkl=8r*<OezWJO^_0~=?DVCaekf*U&*6uTK@`5X*vJ?{A5Yn6wikt>^v
z(7()>%8M?Gl%7kx>Gn`^RAQF96>H<Z$Y)U-PmqX3BO7nCe5XmDq6#B(gG-`HBtv>~
zqm`q-QcY~aQ7_g~!8sNO9r=2u3Mlqi#CWtc9T(=ypIRf>c$iT@(<;xV@nLFbqN;ve
z&H|wp@2R5NS2`L#KJ=KR(rKEJaLDyUmqb%cL}by=)-=YHmH-A@k7GPXma%d?aC*qL
zh)X7I#x;cnUQ^jS^;|kOFmg@Nv0U}W!=<5%L(6DYL1B*CL?*3JjSUV#i&`dVbSiW!
SUO9NY!6jXVS5kz7!5RQ<r+B^q
literal 0
HcmV?d00001
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index c4d8218..61b2bd9 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -37,6 +37,7 @@ use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
use C4::External::Amazon;
use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
use C4::Review;
+use C4::Ratings;
use C4::Members;
use C4::VirtualShelves;
use C4::XSLT;
@@ -47,6 +48,8 @@ use MARC::Field;
use List::MoreUtils qw/any none/;
use C4::Images;
+#use Smart::Comments '####';
+
BEGIN {
if (C4::Context->preference('BakerTaylorEnabled')) {
require C4::External::BakerTaylor;
@@ -632,6 +635,20 @@ foreach ( @$reviews ) {
$_->{userid} = $borrowerData->{'userid'};
$_->{cardnumber} = $borrowerData->{'cardnumber'};
$_->{datereviewed} = format_date($_->{datereviewed});
+
+
+
+
+# my $value = get_rating_by_review($_->{reviewid});
+ my $rating = get_rating( $biblionumber , $_->{borrowernumber});
+
+ $_->{"borr_rating_val_".$rating->{value}} = 1;
+ $_->{rating} = $rating->{value} ;
+
+ #### $rating
+#### $_
+
+
if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
$_->{your_comment} = 1;
$loggedincommenter = 1;
@@ -891,6 +908,21 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) {
$template->param(covernewwindow => 'false');
}
+if (C4::Context->preference('RatingsEnabled') ) {
+my $rating = get_rating( $biblionumber, $borrowernumber );
+$template->param(
+ RatingsShowOnDetail => 1,
+ RatingsEnabled => 1,
+ rating_value => $rating->{'value'},
+ rating_total => $rating->{'total'},
+ rating_avg => $rating->{'avg'},
+ rating_avgint => $rating->{'avgint'},
+ rating_readonly => ( $borrowernumber ? 0 : 1 ),
+ borrowernumber => $borrowernumber,
+ "rating_val_" . "$rating->{'avgint'}" => $rating->{'avgint'},
+ );
+}
+
#Search for title in links
my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
diff --git a/opac/opac-ratings.pl b/opac/opac-ratings.pl
new file mode 100755
index 0000000..e0c3ec4
--- /dev/null
+++ b/opac/opac-ratings.pl
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+
+# Copyright 2010 KohaAloha, NZ
+# Parts copyright 2011, Catalyst IT, NZ
+#
+# 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
+
+=head1
+
+opac-ratings.pl - API endpoint for setting rating values
+
+This receives a POST containing biblionumber and rating. It
+updates rating for the logged in user.
+
+=cut
+
+use strict;
+use warnings;
+use CGI;
+use CGI::Cookie; # need to check cookies before having CGI parse the POST request
+use JSON;
+
+use C4::Auth qw(:DEFAULT check_cookie_auth);
+use C4::Context;
+use C4::Debug;
+use C4::Output 3.02 qw(:html :ajax pagination_bar);
+use C4::Ratings;
+
+use Data::Dumper;
+
+my %ratings = ();
+my %counts = ();
+my @errors = ();
+
+my $is_ajax = is_ajax();
+
+my $query = ($is_ajax) ? &ajax_auth_cgi( {} ) : CGI->new();
+
+my $biblionumber = $query->param('biblionumber');
+my $value;
+
+foreach ( $query->param ) {
+ if (/^rating(.*)/) {
+ $value = $query->param($_);
+ last;
+ }
+}
+
+my ( $template, $loggedinuser, $cookie );
+
+if ($is_ajax) {
+ $loggedinuser = C4::Context->userenv->{'number'};
+ add_rating( $biblionumber, $loggedinuser, $value );
+ my $rating = get_rating($biblionumber, $loggedinuser);
+ my $js_reply = "{total: $rating->{'total'}, value: $rating->{'value'}}";
+
+ output_ajax_with_http_headers( $query, $js_reply );
+ exit;
+}
+
+# Future enhancements could have this have its own template to
+# display the users' ratings, or tie in with their reading history
+# to get them to rate things they read recently.
+( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ { template_name => "opac-user.tmpl",
+ query => $query,
+ type => "opac",
+ authnotrequired => 0, # auth required to add ratings
+ debug => 0,
+ }
+);
+
+my $results = [];
+
+( scalar @errors ) and $template->param( ERRORS => \@errors );
+
+output_html_with_http_headers $query, $cookie, $template->output;
+
+sub ajax_auth_cgi ($) { # returns CGI object
+ my $needed_flags = shift;
+ my %cookies = fetch CGI::Cookie;
+ my $input = CGI->new;
+ my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
+ my ( $auth_status, $auth_sessid ) = check_cookie_auth( $sessid, $needed_flags );
+ if ( $auth_status ne "ok" ) {
+ output_ajax_with_http_headers $input, "window.alert('Your CGI session cookie ($sessid) is not current. " . "Please refresh the page and try again.');\n";
+ exit 0;
+ }
+ return $input;
+}
+
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 87d2890..7cb690f 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -36,10 +36,14 @@ use C4::Biblio; # GetBiblioData
use C4::Koha;
use C4::Tags qw(get_tags);
use C4::Branch; # GetBranches
+use C4::Ratings;
+
use POSIX qw(ceil floor strftime);
use URI::Escape;
use Storable qw(thaw freeze);
+#use Smart::Comments '####';
+
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
# create a new CGI object
@@ -111,6 +115,7 @@ if (C4::Context->preference('BakerTaylorEnabled')) {
BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
);
}
+
if (C4::Context->preference('TagsEnabled')) {
$template->param(TagsEnabled => 1);
foreach (qw(TagsShowOnList TagsInputOnList)) {
@@ -118,6 +123,15 @@ if (C4::Context->preference('TagsEnabled')) {
}
}
+if (C4::Context->preference('RatingsEnabled')) {
+#### $borrowernumber
+ $template->param(RatingsEnabled => 1);
+ $template->param(rating_readonly => 1) unless $borrowernumber ;
+ $template->param(borrowernumber => $borrowernumber );
+}
+
+
+
## URI Re-Writing
# Deprecated, but preserved because it's interesting :-)
# The same thing can be accomplished with mod_rewrite in
@@ -516,6 +530,20 @@ for (my $i=0;$i<@servers;$i++) {
}
}
+ if (C4::Context->preference('RatingsEnabled')) {
+ foreach (@newresults) {
+ my $rating = get_rating( $_->{'biblionumber'}, $borrowernumber );
+
+ my $bib = $_->{'biblionumber'};
+ $_->{'rating_user'} = $rating->{'user'};
+ $_->{'rating_total'} = $rating->{'total'};
+ $_->{'rating_avg'} = $rating->{'avg'};
+ $_->{'rating_avgint'} = $rating->{'avgint'};
+ $_->{ 'rating_val_' . $rating->{'avgint'} } = $rating->{'avgint'};
+ $_->{'rating_value'} = $rating->{'value'};
+ }
+ }
+
if ($results_hashref->{$server}->{"hits"}){
$total = $total + $results_hashref->{$server}->{"hits"};
}
@@ -655,7 +683,6 @@ for (my $i=0;$i<@servers;$i++) {
};
}
-
}
# now, show twenty pages, with the current one smack in the middle
else {
--
1.6.5
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/