From f353a6caacb8bc0c075106a1b1060db0495fdecf Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 7 Feb 2018 19:44:28 +0000 Subject: [PATCH] Bug 20157: Use group 'features' to decide which groups to use for group searching functionality Instead of basing the group searches on the group name, which is an inherently touchy system, we should use the same checkbox style that Jonathan introduced for the patron limits by group feature. Test Plan: 1) Check to ensure existing group searches still show as they used to Signed-off-by: Jonathan Druart --- C4/Auth.pm | 4 +- Koha/Library/Groups.pm | 11 ++- .../data/mysql/atomicupdate/bug_20157.perl | 13 +++ installer/data/mysql/kohastructure.sql | 2 + .../prog/en/modules/admin/library_groups.tt | 87 +++++++++++++------ opac/opac-search.pl | 4 +- 6 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_20157.perl diff --git a/C4/Auth.pm b/C4/Auth.pm index f642264cfb..430c287efc 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -513,11 +513,11 @@ sub get_template_and_user { $opac_name = C4::Context->userenv->{'branch'}; } - my $search_groups = Koha::Library::Groups->get_search_groups(); + my @search_groups = Koha::Library::Groups->get_search_groups(); $template->param( OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"), AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), - LibrarySearchGroups => $search_groups, + LibrarySearchGroups => \@search_groups, opac_name => $opac_name, LibraryName => "" . C4::Context->preference("LibraryName"), LibraryNameTitle => "" . $LibraryNameTitle, diff --git a/Koha/Library/Groups.pm b/Koha/Library/Groups.pm index 1a8b8fb6cf..4bad9e1512 100644 --- a/Koha/Library/Groups.pm +++ b/Koha/Library/Groups.pm @@ -60,16 +60,15 @@ sub get_search_groups { my ( $self, $params ) = @_; my $interface = $params->{interface} || q{}; - my $title = $interface eq 'staff' ? '__SEARCH_GROUPS__' : '__SEARCH_GROUPS_OPAC__'; + my $field = $interface eq 'staff' ? 'ft_search_groups_staff' : 'ft_search_groups_opac'; - my ($search_groups_root) = - $self->search( { parent_id => undef, title => $title } ); + my @search_groups = $self->search( { $field => 1 } ); - return unless $search_groups_root; + return unless @search_groups; - my $children = $search_groups_root->children(); + my @children = map { $_->children() } @search_groups; - return wantarray ? $children->as_list : $children; + return @children; } =head3 type diff --git a/installer/data/mysql/atomicupdate/bug_20157.perl b/installer/data/mysql/atomicupdate/bug_20157.perl new file mode 100644 index 0000000000..de87756934 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_20157.perl @@ -0,0 +1,13 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + if( !column_exists( 'library_groups', 'ft_search_groups_opac' ) ) { + $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_search_groups_opac tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info" ); + $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0 AFTER ft_search_groups_opac" ); + $dbh->do( "UPDATE library_groups SET ft_search_groups_staff = 1 WHERE title = '__SEARCH_GROUPS__'" ); + $dbh->do( "UPDATE library_groups SET ft_search_groups_opac = 1 WHERE title = '__SEARCH_GROUPS_OPAC__'" ); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 20157 - Use group 'features' to decide which groups to use for group searching functionality)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 9ee4a29d26..7fb34e883a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4144,6 +4144,8 @@ CREATE TABLE library_groups ( title VARCHAR(100) NULL DEFAULT NULL, -- Short description of the goup description TEXT NULL DEFAULT NULL, -- Longer explanation of the group, if necessary ft_hide_patron_info tinyint(1) NOT NULL DEFAULT 0, -- Turn on the feature "Hide patron's info" for this group + ft_search_groups_opac tinyint(1) NOT NULL DEFAULT 0, -- Use this group for staff side search groups + ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0, -- Use this group for opac side search groups created_on TIMESTAMP NULL, -- Date and time of creation updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Date and time of last PRIMARY KEY id ( id ), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt index 3d90144f01..e54a08a9e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt @@ -26,7 +26,9 @@ var title = $(this).data('groupTitle'); var description = $(this).data('groupDescription'); var ft_hide_patron_info = $(this).data('groupFt_hide_patron_info'); - edit_group( id, parent_id, title, description, ft_hide_patron_info ); + var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac'); + var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff'); + edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff ); }); $('.delete-group').on('click', function() { @@ -54,30 +56,31 @@ }); $('#add-group-modal-ft_hide_patron_info').prop('checked', false); + $('#add-group-modal-ft_search_groups_opac').prop('checked', false); + $('#add-group-modal-ft_search_groups_staff').prop('checked', false); if ( parent_id ) { - $('#add-group-modal-ft_hide_patron_info').parent().hide(); + $('#root-group-features-edit').hide(); } else { - $('#add-group-modal-ft_hide_patron_info').parent().show(); + $('#root-group-features-edit').show(); } $('#add-group-modal').modal('show'); } - function edit_group( id, parent_id, title, description, ft_hide_patron_info ) { + function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff ) { $('#edit-group-modal-id').val( id ); $('#edit-group-modal-title').val( title ); $('#edit-group-modal-description').val( description ); if ( parent_id ) { $('#edit-group-modal-ft_hide_patron_info').prop('checked', false); - $('#edit-group-modal-ft_hide_patron_info').parent().hide(); + $('#edit-group-modal-ft_search_groups_opac').prop('checked', false); + $('#edit-group-modal-ft_search_groups_staff').prop('checked', false); + $('#root-group-features-edit').hide(); } else { - if ( ft_hide_patron_info ) { - $('#edit-group-modal-ft_hide_patron_info').prop('checked', true); - } else { - $('#edit-group-modal-ft_hide_patron_info').prop('checked', false); - } - - $('#edit-group-modal-ft_hide_patron_info').parent().show(); + $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false ); + $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false ); + $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false ); + $('#root-group-features-edit').show(); } $('#edit-group-modal').on('shown', function() { @@ -188,12 +191,24 @@

-

Features

-
- +
+

Features

+
+ +

+ +

+ +