From 2e0582ea3111120b9e0ddfb6b64b819293e547b7 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 12 Jun 2024 12:54:47 +0000 Subject: [PATCH] Bug 2486: Show user comments in staff interface This patch the staff interface's bibliographic detail page, adding a tab that shows comments submitted by users from the OPAC. To test, apply the patch and restart services. - If necessary, enable the "OPACComments" system preference and submit some comments in the OPAC. - In the staff interface, locate the title you submitted comments on. - The bibliographic detail page should show a "Comments" tab with a count of the number of all comments (approved and unapproved). Sponsored-By: Athens County Public Libraries Signed-off-by: Lucas Gass Signed-off-by: Laura_Escamilla Signed-off-by: Katrin Fischer --- admin/columns_settings.yml | 15 +++ catalogue/detail.pl | 39 ++++++- .../prog/css/src/staff-global.scss | 9 ++ .../prog/en/modules/catalogue/detail.tt | 102 +++++++++++++++++- reviews/reviewswaiting.pl | 6 ++ 5 files changed, 167 insertions(+), 4 deletions(-) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index 4dfb152a6c..0a9fc82fa1 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -531,6 +531,21 @@ modules: - columnname: subscription_callnumber + comments-table: + columns: + - + columnname: patron + - + columnname: date + - + columnname: status + - + columnname: comment + - + columnname: actions + cannot_be_toggled: 1 + cannot_be_modified: 1 + checkoutshistory-table: default_display_length: 20 columns: diff --git a/catalogue/detail.pl b/catalogue/detail.pl index dd0802c025..343146937e 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -57,6 +57,7 @@ use Koha::Patrons; use Koha::Virtualshelves; use Koha::Plugins; use Koha::Recalls; +use Koha::Reviews; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Serial::Items; @@ -85,10 +86,15 @@ if ( C4::Context->config('enable_plugins') ) { ); } +my $activetab = $query->param('activetab'); my $biblionumber = $query->param('biblionumber'); $biblionumber = HTML::Entities::encode($biblionumber); my $biblio = Koha::Biblios->find( $biblionumber ); -$template->param( 'biblio', $biblio ); + +$template->param( + biblio => $biblio, + activetab => $activetab, +); unless ( $biblio ) { # biblionumber invalid -> report and exit @@ -382,6 +388,37 @@ if (C4::Context->preference("AlternateHoldingsField") && $items_to_display->coun ); } +if ( C4::Context->preference('OPACComments') ) { + my $reviews = Koha::Reviews->search( + { biblionumber => $biblionumber }, + { order_by => { -desc => 'datereviewed' } } + )->unblessed; + my $libravatar_enabled = 0; + if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto') ) { + eval { + require Libravatar::URL; + Libravatar::URL->import(); + }; + if ( !$@ ) { + $libravatar_enabled = 1; + } + } + for my $review (@$reviews) { + my $review_patron = + Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar + + # setting some borrower info into this hash + if ($review_patron) { + $review->{patron} = $review_patron; + if ( $libravatar_enabled and $review_patron->email ) { + $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} ); + } + } + } + $template->param( 'reviews' => $reviews ); + +} + my @results = ( $dat, ); foreach ( keys %{$dat} ) { $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' ); diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index 2d3bed2ad2..5b702b4477 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -2753,6 +2753,15 @@ fieldset > .toptabs { font-style: italic; } +.commentline { + border-bottom: 1px solid #CCC; + + .btn-toolbar { + margin-bottom: 0; + margin-left: 0; + } +} + .contents { width: 75%; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 0a71edd3b4..6c2048aee8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -51,7 +51,6 @@ [% END %] - [% WRAPPER 'header.inc' %] [% INCLUDE 'cat-search.inc' %] [% END %] @@ -381,6 +380,12 @@ [% END %] [% END %] + [% IF ( reviews ) %] + [% WRAPPER tab_item tabname= "comments" %] + Comments [% ' ( ' _ ( reviews.size ) _ ' )' | html %] + [% END %] + [% END %] + [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && Koha.Preference('NovelistSelectStaffView') == 'tab' ) %] [% WRAPPER tab_item tabname= "NovelistSelect" %] NoveList Select @@ -837,6 +842,82 @@ [% END # /tab_panel %] [% END # /IF HTML5MediaEnabled %] + [% IF ( reviews ) %] + [% WRAPPER tab_panel tabname="comments" %] + [% SET ShowReviewerPhoto = Koha.Preference( "ShowReviewerPhoto" ) %] + + + + + + + + + + + + [% FOREACH review IN reviews %] + + + + + + [% IF ( CAN_user_tools_moderate_comments ) %] + + [% END # /IF CAN_user_tools_moderate_comments %] + + [% END # / FOREACH reviews %] + +
CommenterDateStatusCommentActions
+ [% IF ( review.patron ) %] + [% IF ( review.avatarurl ) %] + + [% END %] + [% INCLUDE 'patron-title.inc' patron=review.patron hide_patron_infos_if_needed=1 %] + [% ELSE %] + Patron deleted + [% END %] + + [% review.datereviewed | $KohaDates %] + + [% IF ( review.approved ) %] + Approved + [% ELSE %] + Unapproved + [% END %] + + [% FILTER html_break %] + [% review.review | html %] + [% END %] + + [% IF ( review.approved ) %] +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+ [% ELSE %] +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+ [% END %] +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+
+ [% END %] + [% END # /IF reviews %] + [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && Koha.Preference('NovelistSelectStaffView') == 'tab' ) %] [% WRAPPER tab_panel tabname="NovelistSelect" %]
@@ -847,7 +928,7 @@ [% WRAPPER tab_panel tabname="${ plugins_intranet_catalog_biblio_tab.id }" %] [% plugins_intranet_catalog_biblio_tab.content | $raw %] [% END # /tab_panel %] - [% END %] + [% END # /WRAPPER comments %] [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] @@ -1441,7 +1522,9 @@ $(document).ready(function() { // Pick details tab to display by default - [% IF count == 0 %] + [% IF activetab == "comments" %] + $("#bibliodetails a[href='#comments_panel']").tab("show"); + [% ELSIF count == 0 %] [% IF ( Koha.Preference('HTML5MediaEnabled') == 'staff' or Koha.Preference('HTML5MediaEnabled') == 'both' ) && HTML5MediaSets.size %] $("#bibliodetails a[href='#html5media_panel']").tab("show"); [% ELSIF ComponentParts && ComponentParts.size %] @@ -1927,6 +2010,14 @@ })); [% END %] + [% IF ( reviews ) %] + var comment_table_settings = [% TablesSettings.GetTableSettings('catalogue', 'detail', 'comments-table', 'json') | $raw %]; + var comments_table = KohaTable("comments_table", { + "paginate": false, + "autoWidth": false, + "order": [[ 2, "desc" ]], + }, comment_table_settings); + [% END %] }); [% IF found1 && Koha.Preference('RetainCatalogSearchTerms') %] @@ -2176,8 +2267,13 @@ $('#modal-item-group-unset').modal('hide'); }); + [% END # /IF EnableItemGroups %] + $(".delete-comment").on("click", function(){ + return confirm( _("Are you sure you want to delete this comment?") ); + }); + [%# The following PROCESS needs: %] diff --git a/reviews/reviewswaiting.pl b/reviews/reviewswaiting.pl index b17dc8b9e1..1954482c0d 100755 --- a/reviews/reviewswaiting.pl +++ b/reviews/reviewswaiting.pl @@ -41,6 +41,7 @@ my $reviewid = $query->param('reviewid'); my $page = $query->param('page') || 1; my $count = C4::Context->preference('numSearchResults') || 20; my $total = Koha::Reviews->search_limited({ approved => $status })->count; +my $biblionumber = $query->param('biblionumber'); if ( $op eq 'cud-approve' ) { my $review = Koha::Reviews->find( $reviewid ); @@ -55,6 +56,11 @@ elsif ( $op eq 'cud-delete' ) { $review->delete if $review; } +if ( $op && $biblionumber ) { + print scalar $query->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&activetab=comments"); + exit; # You can only send 1 redirect! After that, content or other headers don't matter. +} + my $reviews = Koha::Reviews->search_limited( { approved => $status }, { -- 2.39.5