From 0ca7475fa38ed6d086969da36825f862d682a82d Mon Sep 17 00:00:00 2001 From: Juan Romay Sieira Date: Mon, 11 Jan 2016 19:18:12 +0100 Subject: [PATCH] Bug 15544 - Facets must be managed from the intranet Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Romay Sieira --- C4/Koha.pm | 170 ++-------------- admin/facets.pl | 211 +++++++++++++++++++ .../prog/en/modules/admin/admin-home.tt | 2 + .../intranet-tmpl/prog/en/modules/admin/facets.tt | 212 ++++++++++++++++++++ 4 files changed, 445 insertions(+), 150 deletions(-) create mode 100644 admin/facets.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/facets.tt diff --git a/C4/Koha.pm b/C4/Koha.pm index 12ac19c..e24a82b 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -754,158 +754,28 @@ sub getallthemes { sub getFacets { my $facets; - if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) { - $facets = [ - { - idx => 'su-to', - label => 'Topics', - tags => [ qw/ 600ab 601ab 602a 604at 605a 606ax 610a / ], - sep => ' - ', - }, - { - idx => 'su-geo', - label => 'Places', - tags => [ qw/ 607a / ], - sep => ' - ', - }, - { - idx => 'su-ut', - label => 'Titles', - tags => [ qw/ 500a 501a 503a / ], - sep => ', ', - }, - { - idx => 'au', - label => 'Authors', - tags => [ qw/ 700ab 701ab 702ab / ], - sep => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"), - }, - { - idx => 'se', - label => 'Series', - tags => [ qw/ 225a / ], - sep => ', ', - }, - { - idx => 'location', - label => 'Location', - tags => [ qw/ 995e / ], - } - ]; - - unless ( C4::Context->preference("singleBranchMode") - || GetBranchesCount() == 1 ) - { - my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets'); - if ( $DisplayLibraryFacets eq 'both' - || $DisplayLibraryFacets eq 'holding' ) - { - push( - @$facets, - { - idx => 'holdingbranch', - label => 'HoldingLibrary', - tags => [qw / 995c /], - } - ); - } - - if ( $DisplayLibraryFacets eq 'both' - || $DisplayLibraryFacets eq 'home' ) - { - push( - @$facets, - { - idx => 'homebranch', - label => 'HomeLibrary', - tags => [qw / 995b /], - } - ); - } - } + + my $dbh = C4::Context->dbh; + + my $query = "SELECT idx, label, tags, position, vlength, expanded, category, authorised_value, sep "; + $query .= "FROM facets WHERE marcflavour = '".C4::Context->preference("marcflavour")."' "; + $query .= "AND active = 1 "; + + if (C4::Context->preference("singleBranchMode")){ + $query .= "AND singleBranchMode = 0"; } - else { - $facets = [ - { - idx => 'su-to', - label => 'Topics', - tags => [ qw/ 650a / ], - sep => '--', - }, - # { - # idx => 'su-na', - # label => 'People and Organizations', - # tags => [ qw/ 600a 610a 611a / ], - # sep => 'a', - # }, - { - idx => 'su-geo', - label => 'Places', - tags => [ qw/ 651a / ], - sep => '--', - }, - { - idx => 'su-ut', - label => 'Titles', - tags => [ qw/ 630a / ], - sep => '--', - }, - { - idx => 'au', - label => 'Authors', - tags => [ qw/ 100a 110a 700a / ], - sep => ', ', - }, - { - idx => 'se', - label => 'Series', - tags => [ qw/ 440a 490a / ], - sep => ', ', - }, - { - idx => 'itype', - label => 'ItemTypes', - tags => [ qw/ 952y 942c / ], - sep => ', ', - }, - { - idx => 'location', - label => 'Location', - tags => [ qw / 952c / ], - }, - ]; - - unless ( C4::Context->preference("singleBranchMode") - || GetBranchesCount() == 1 ) - { - my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets'); - if ( $DisplayLibraryFacets eq 'both' - || $DisplayLibraryFacets eq 'holding' ) - { - push( - @$facets, - { - idx => 'holdingbranch', - label => 'HoldingLibrary', - tags => [qw / 952b /], - } - ); - } - - if ( $DisplayLibraryFacets eq 'both' - || $DisplayLibraryFacets eq 'home' ) - { - push( - @$facets, - { - idx => 'homebranch', - label => 'HomeLibrary', - tags => [qw / 952a /], - } - ); - } - } + + my $sth = $dbh->prepare($query); + + $sth->execute(); + + while (my $row = $sth->fetchrow_hashref) { + $row->{'tags'} = [ split (',', $row->{'tags'}) ]; + push @$facets, $row; } + + $sth->finish; + return $facets; } diff --git a/admin/facets.pl b/admin/facets.pl new file mode 100644 index 0000000..72ef959 --- /dev/null +++ b/admin/facets.pl @@ -0,0 +1,211 @@ +#!/usr/bin/perl + +# Copyright 2012 Xercode Media Software S.L. +# +# 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. + +use strict; +use warnings; +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Koha; +use C4::Languages qw(getTranslatedLanguages); +use Data::Dumper; + +my $input = new CGI; +our $dbh = C4::Context->dbh; +my $ERROR = $input->param('ERROR') || 0; +my $query; +my $script_name = "/cgi-bin/koha/admin/facets.pl"; + +my $op = $input->param('op') || ""; +my $id = $input->param('idFacet'); + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "admin/facets.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 1 }, + debug => 1, + } +); + +sub getTabListAuthValues { + my $selected = shift; + + my $sth = $dbh->prepare("SELECT DISTINCT category FROM authorised_values"); + $sth->execute; + my @category_list; + my %categories; # a hash, to check that some hardcoded categories exist. + push(@category_list,""); + while ( my ($category) = $sth->fetchrow_array) { + push(@category_list,$category); + } + + #reorder the list + @category_list = sort {$a cmp $b} @category_list; + my $tab_list = CGI::scrolling_list(-name=>'authorised_value', + -id=>'authorised_value', + -values => \@category_list, + -default => $selected, + -size => 1, + -multiple=> 0, + ); + + return $tab_list; +} + + +if ($op eq "add_form"){ + my $tabListAuthValues = getTabListAuthValues(''); + $template->param('tabListAuthValues', $tabListAuthValues); + +}elsif ($op eq "save_facet"){ + + $query = "INSERT INTO facets "; + $query.= "(marcflavour, idx, label, authorised_value, tags, position, vlength, expanded, singleBranchMode, active, category, sep) "; + $query.= "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; + my $sth3 = $dbh->prepare($query); + + $sth3->execute( + $input->param('marcflavour'), + $input->param('idx'), + $input->param('label'), + $input->param('authorised_value'), + $input->param('tags'), + $input->param('position'), + $input->param('vlength'), + ($input->param('expanded')?1:0), + ($input->param('singleBranchMode')?1:0), + ($input->param('active')?1:0), + $input->param('category'), + $input->param('sep') + ); + $sth3->finish; + print $input->redirect($script_name); + +}elsif( $op eq "edit_form" ){ + + $query = "SELECT * FROM facets WHERE idFacet = ?"; + my $sth3 = $dbh->prepare($query); + $sth3->execute($id); + my $data = $sth3->fetchrow_hashref; + $template->param( + idFacet => $data->{idFacet}, + marcflavour => $data->{marcflavour}, + idx => $data->{idx}, + label => $data->{label}, + authorised_value => $data->{authorised_value}, + tags => $data->{tags}, + position => $data->{position}, + vlength => $data->{vlength}, + expanded => $data->{expanded}, + singleBranchMode => $data->{singleBranchMode}, + active => $data->{active}, + category => $data->{category}, + sep => $data->{sep} + ); + $sth3->finish; + + my $tabListAuthValues = getTabListAuthValues($data->{authorised_value}); + $template->param('tabListAuthValues', $tabListAuthValues); + +}elsif( $op eq "update_facet" ){ + + $query = "UPDATE facets SET "; + $query.= "marcflavour = ?, idx = ?, label = ?, authorised_value = ?, tags = ?, "; + $query.= "position = ?, vlength = ?, expanded = ?, singleBranchMode = ?, "; + $query.= "active = ?, category = ?, sep = ? "; + $query.= "WHERE idFacet = ?"; + my $sth3 = $dbh->prepare($query); + $sth3->execute( + $input->param('marcflavour'), + $input->param('idx'), + $input->param('label'), + $input->param('authorised_value'), + $input->param('tags'), + $input->param('position'), + $input->param('vlength'), + ($input->param('expanded')?1:0), + ($input->param('singleBranchMode')?1:0), + ($input->param('active')?1:0), + $input->param('category'), + $input->param('sep'), + $input->param('idFacet') ); + $sth3->finish; + print $input->redirect($script_name); + +}elsif( $op eq "delete_confirmed"){ + + $query = "DELETE FROM facets WHERE idFacet = ?"; + my $sth3 = $dbh->prepare($query); + $sth3->execute( $id ); + $sth3->finish; + + print $input->redirect($script_name); + +}elsif( $op eq "delete_confirm"){ + + $query = "SELECT * FROM facets WHERE idFacet = ?"; + my $sth3 = $dbh->prepare($query); + $sth3->execute($id); + my $data = $sth3->fetchrow_hashref; + $template->param( + idFacet => $data->{idFacet}, + marcflavour => $data->{marcflavour}, + label => $data->{label}, + tags => $data->{tags} + ); + $sth3->finish; + +}else{ + + $query = "SELECT * FROM facets "; + my $sth3 = $dbh->prepare($query); + $sth3->execute(); + my @loop_data; + while ( my $r = $sth3->fetchrow_hashref ) { + push @loop_data, { + idFacet => $r->{idFacet}, + marcflavour => $r->{marcflavour}, + idx => $r->{idx}, + label => $r->{label}, + authorised_value => $r->{authorised_value}, + tags => $r->{tags}, + expanded => $r->{expanded}, + singleBranchMode => $r->{singleBranchMode}, + active => $r->{active} + }; + } + $template->param( loop => \@loop_data ); + $template->param( op => $op ) if ($op ne ""); + $template->param( else => 1 ); + $sth3->finish; + +} + +$template->param( op => $op ) if ($op ne ""); +$template->param( id => $id ); +$template->param( script_name => $script_name ); + +my $use_zebra_facets = C4::Context->config('use_zebra_facets'); +$template->param( use_zebra_facets => $use_zebra_facets ); + +output_html_with_http_headers $input, $cookie, $template->output; + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 633b3cc..96b4810 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -84,6 +84,8 @@
Manage OAI Sets
Items search fields
Manage custom fields for items search
+
Facet indexes manager
+
Manage indexes to build facets

Acquisition parameters

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/facets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/facets.tt new file mode 100644 index 0000000..368e7c7 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/facets.tt @@ -0,0 +1,212 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › Facets +[% IF ( op == 'add_form' || op == 'edit_form' ) %] +› [% IF ( idFacet ) %]Modify facet[% ELSE %]New facet[% END %] +[% ELSIF ( delete_confirm ) %] +› Confirm deletion of facet +[% END %] + +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
+
+
+
+ +[% IF ( op == 'add_form' || op == 'edit_form' ) %] + +
+
+ + [% IF ( idFacet ) %] + Modify facet + [% ELSE %] + New facet + [% END %] + +
    +
  1. + +
  2. +
  3. +
  4. +
  5. +
  6. +
  7. +
  8. +
  9. + [% tabListAuthValues %] +
  10. +
  11. +
  12. +
  13. +
  14. +
  15. +
  16. +
  17. +
  18. +
  19. +
  20. + +
  21. +
  22. + +
  23. +
  24. + +
  25. +
  26. +
  27. +
  28. +
  29. +
  30. +
  31. + + + [% IF ( idFacet ) %] + + + [% ELSE %] + + [% END %] +
  32. +
+
+
+ Cancel +
+
+[% END %] + +[% IF ( op == 'delete_confirm' ) %] +
+

Confirm deletion of facet with

+

index '[% label %]'

+

tags '[% tags %]'

+

marc flavour '[% marcflavour %]'

+ [% IF ( total ) %] +

This record is used [% total %] times

+ [% END %] +
+ +
+ +
+
+[% END %] + +[% IF ( else ) %] + +[% IF ( else ) %][% END %] + +

Facets

+

Definition of indexes to build facets

+[% IF (use_zebra_facets) %] +
+

USE ZEBRA FACETS ENABLED

+ Controlfields only works if "use_zebra_facets" is disabled +
+[% END %] + + + + + + + + + + + + + + + [% FOREACH loo IN loop %] + [% IF ( loop.odd ) %] + + [% ELSE %] + + [% END %] + + + + + + + + + + + + [% END %] +
Marc flavourIndexLabelAuthorised valueTagsExpandedSingle branch modeActiveEditDelete
[% loo.marcflavour %][% loo.idx %][% loo.label %][% loo.authorised_value %][% loo.tags %][% IF ( loo.expanded ) %]YES[% ELSE %]NO[% END %][% IF ( loo.singleBranchMode ) %]YES[% ELSE %]NO[% END %][% IF ( loo.active ) %]YES[% ELSE %]NO[% END %]EditDelete
+ + [% IF ( previous ) %]

<< Previous

[% END %] + [% IF ( next ) %]

Next >>

[% END %] + +[% END %] +
+
+
+[% INCLUDE 'admin-menu.inc' %] +
+
+[% INCLUDE 'intranet-bottom.inc' %] -- 1.7.2.5