@@ -, +, @@ functionality with the new hierarchical groups system __SEARCH_GROUPS__ group if you had any --- C4/Auth.pm | 6 +- Koha/Library.pm | 19 --- Koha/Library/Group.pm | 34 ++++-- Koha/Library/Groups.pm | 23 ++++ admin/branches.pl | 85 +------------ catalogue/search.pl | 17 ++- installer/data/mysql/updatedatabase.pl | 38 ++++++ .../intranet-tmpl/prog/en/includes/admin-menu.inc | 2 +- .../prog/en/modules/admin/admin-home.tt | 6 +- .../prog/en/modules/admin/branches.tt | 136 +-------------------- .../prog/en/modules/catalogue/advsearch.tt | 20 +-- .../opac-tmpl/bootstrap/en/includes/masthead.inc | 26 ++-- .../bootstrap/en/modules/opac-advsearch.tt | 6 +- opac/opac-search.pl | 10 +- t/db_dependent/Koha/Libraries.t | 37 +----- t/db_dependent/RotatingCollections.t | 1 - 16 files changed, 145 insertions(+), 321 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -33,8 +33,8 @@ use C4::Search::History; use Koha; use Koha::Caches; use Koha::AuthUtils qw(get_script_name hash_password); +use Koha::Library::Groups; use Koha::Libraries; -use Koha::LibraryCategories; use Koha::Patrons; use POSIX qw/strftime/; use List::MoreUtils qw/ any /; @@ -511,11 +511,11 @@ sub get_template_and_user { $opac_name = C4::Context->userenv->{'branch'}; } - my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']}); + my $search_groups = Koha::Library::Groups->get_search_groups(); $template->param( OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"), AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), - BranchCategoriesLoop => $library_categories, + LibrarySearchGroups => $search_groups, opac_name => $opac_name, LibraryName => "" . C4::Context->preference("LibraryName"), LibraryNameTitle => "" . $LibraryNameTitle, --- a/Koha/Library.pm +++ a/Koha/Library.pm @@ -35,25 +35,6 @@ Koha::Library - Koha Library Object class =cut -sub get_categories { - my ( $self, $params ) = @_; - # TODO This should return Koha::LibraryCategories - return $self->{_result}->categorycodes( $params ); -} - -sub update_categories { - my ( $self, $categories ) = @_; - $self->_result->delete_related( 'branchrelations' ); - $self->add_to_categories( $categories ); -} - -sub add_to_categories { - my ( $self, $categories ) = @_; - for my $category ( @$categories ) { - $self->_result->add_to_categorycodes( $category->_result ); - } -} - =head3 type =cut --- a/Koha/Library/Group.pm +++ a/Koha/Library/Group.pm @@ -59,7 +59,7 @@ sub children { my $children = Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } ); - return $children; + return wantarray ? $children->as_list : $children; } =head3 library @@ -80,16 +80,22 @@ sub library { return $self->{_library}; } -=head3 libraries_not_direct_children +=head3 libraries -my @libraries = $group->libraries_not_direct_children(); +my @libraries = $group->libraries( { [invert => 1] } ); -Returns the libraries *not* set as direct children of this group +Returns the libraries set as direct children of this group. + +If invert param is true, the returned list will be libraries +that are *not* direct children of this group. =cut -sub libraries_not_direct_children { - my ($self) = @_; +sub libraries { + my ($self, $params) = @_; + my $invert = $params->{invert}; + + my $in_or_not = $invert ? '-not_in' : '-in'; my @children = Koha::Library::Groups->search( { @@ -103,7 +109,7 @@ sub libraries_not_direct_children { return Koha::Libraries->search( { - branchcode => { -not_in => \@branchcodes } + branchcode => { $in_or_not => \@branchcodes } }, { order_by => 'branchname' @@ -111,6 +117,20 @@ sub libraries_not_direct_children { ); } +=head3 libraries_not_direct_children + +my @libraries = $group->libraries_not_direct_children(); + +Returns the libraries *not* set as direct children of this group + +=cut + +sub libraries_not_direct_children { + my ($self) = @_; + + return $self->libraries( { invert => 1 } ); +} + =head3 store =cut --- a/Koha/Library/Groups.pm +++ a/Koha/Library/Groups.pm @@ -45,6 +45,29 @@ sub get_root_groups { return $self->search( { parent_id => undef }, { order_by => 'title' } ); } +=head3 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']})) + +Returns search groups for the specified interface. +Defaults to OPAC if no interface is specified. + +=cut + +sub get_search_groups { + my ( $self, $params ) = @_; + my $interface = $params->{interface} || q{}; + + my $title = $interface eq 'staff' ? '__SEARCH_GROUPS__' : '__SEARCH_GROUPS_OPAC__'; + + my ($search_groups_root) = + $self->search( { parent_id => undef, title => $title } ); + + return unless $search_groups_root; + + my $children = $search_groups_root->children(); + + return wantarray ? $children->as_list : $children; +} + =head3 type =cut --- a/admin/branches.pl +++ a/admin/branches.pl @@ -27,7 +27,6 @@ use C4::Koha; use Koha::Patrons; use Koha::Items; use Koha::Libraries; -use Koha::LibraryCategories; my $input = new CGI; my $branchcode = $input->param('branchcode'); @@ -53,8 +52,6 @@ if ( $op eq 'add_form' ) { $template->param( library => $library, - categories => [ Koha::LibraryCategories->search( {}, { order_by => [ 'categorytype', 'categoryname' ] } ) ], - $library ? ( selected_categorycodes => [ map { $_->categorycode } $library->get_categories ] ) : (), ); } elsif ( $op eq 'add_validate' ) { my @fields = qw( @@ -79,18 +76,11 @@ if ( $op eq 'add_form' ) { ); my $is_a_modif = $input->param('is_a_modif'); - my @categories; - for my $category ( Koha::LibraryCategories->search ) { - push @categories, $category - if $input->param( "selected_categorycode_" . $category->categorycode ); - } if ($is_a_modif) { my $library = Koha::Libraries->find($branchcode); for my $field (@fields) { $library->$field( scalar $input->param($field) ); } - $library->update_categories( \@categories ); - eval { $library->store; }; if ($@) { push @messages, { type => 'alert', code => 'error_on_update' }; @@ -105,7 +95,6 @@ if ( $op eq 'add_form' ) { } ); eval { $library->store; }; - $library->add_to_categories( \@categories ); if ($@) { push @messages, { type => 'alert', code => 'error_on_insert' }; } else { @@ -152,85 +141,13 @@ if ( $op eq 'add_form' ) { push @messages, { type => 'message', code => 'success_on_delete' }; } $op = 'list'; -} elsif ( $op eq 'add_form_category' ) { - my $category; - if ($categorycode) { - $category = Koha::LibraryCategories->find($categorycode); - } - $template->param( category => $category, ); -} elsif ( $op eq 'add_validate_category' ) { - my $is_a_modif = $input->param('is_a_modif'); - my @fields = qw( - categoryname - codedescription - categorytype - ); - if ($is_a_modif) { - my $category = Koha::LibraryCategories->find($categorycode); - for my $field (@fields) { - $category->$field( scalar $input->param($field) ); - } - $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' ); - eval { $category->store; }; - if ($@) { - push @messages, { type => 'alert', code => 'error_on_update_category' }; - } else { - push @messages, { type => 'message', code => 'success_on_update_category' }; - } - } else { - my $category = Koha::LibraryCategory->new( - { categorycode => $categorycode, - ( map { $_ => scalar $input->param($_) || undef } @fields ) - } - ); - $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' ); - eval { $category->store; }; - if ($@) { - push @messages, { type => 'alert', code => 'error_on_insert_category' }; - } else { - push @messages, { type => 'message', code => 'success_on_insert_category' }; - } - } - $op = 'list'; -} elsif ( $op eq 'delete_confirm_category' ) { - my $category = Koha::LibraryCategories->find($categorycode); - if ( my $libraries_count = $category->libraries->count ) { - push @messages, - { type => 'alert', - code => 'cannot_delete_category', - data => { libraries_count => $libraries_count, }, - }; - $op = 'list'; - } else { - $template->param( category => $category ); - } -} elsif ( $op eq 'delete_confirmed_category' ) { - my $category = Koha::LibraryCategories->find($categorycode); - my $deleted = eval { $category->delete; }; - - if ( $@ or not $deleted ) { - push @messages, { type => 'alert', code => 'error_on_delete_category' }; - } else { - push @messages, { type => 'message', code => 'success_on_delete_category' }; - } - $op = 'list'; } else { $op = 'list'; } if ( $op eq 'list' ) { my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); - $template->param( - libraries => $libraries, - group_types => [ - { categorytype => 'searchdomain', - categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], - }, - { categorytype => 'properties', - categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], - }, - ] - ); + $template->param( libraries => $libraries, ); } $template->param( --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -151,8 +151,9 @@ use POSIX qw(ceil floor); use C4::Search::History; use Koha::ItemTypes; -use Koha::LibraryCategories; use Koha::Patrons; +use Koha::Library::Groups; +use Koha::Virtualshelves; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Virtualshelves; @@ -213,12 +214,16 @@ if($cgi->cookie("intranet_bib_list")){ @cart_list = split(/\//, $cart_list); } -# load the branches -my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } ); +my @search_groups_opac = + Koha::Library::Groups->get_search_groups( { interface => 'opac' } ); +my @search_groups_staff = + Koha::Library::Groups->get_search_groups( { interface => 'staff' } ); +my @search_groups = ( @search_groups_opac, @search_groups_staff ); +@search_groups = sort { $a->title cmp $b->title } @search_groups; $template->param( selected_branchcode => ( C4::Context->IsSuperLibrarian ? C4::Context->userenv : '' ), - searchdomainloop => $categories + search_groups => \@search_groups, ); # load the Type stuff @@ -399,8 +404,8 @@ my %is_nolimit = map { $_ => 1 } @nolimits; @limits = grep { not $is_nolimit{$_} } @limits; if($params->{'multibranchlimit'}) { - my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} ); - my @libraries = $library_category->libraries; + my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); + my @libraries = $search_group->libraries; my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')'; push @limits, $multibranch if ($multibranch ne '()'); } --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -14595,6 +14595,44 @@ if ( CheckVersion($DBversion) ) { print "Upgrade to $DBversion done (Bug 18801 - Update incorrect Default auth type codes)\n"; } +$DBversion = "XXX"; +if ( CheckVersion($DBversion) ) { + require Koha::Library::Group; + + my $search_groups_staff_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS__', description => "Library search groups - Staff only" } )->store(); + my $search_groups_opac_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS_OPAC__', description => "Library search groups - OPAC & Staff" } )->store(); + + my $sth = $dbh->prepare("SELECT * FROM branchcategories"); + $sth->execute(); + + while ( my $lc = $sth->fetchrow_hashref ) { + my $description = $lc->{categorycode}; + $description .= " - " . $lc->{codedescription} if $lc->{codedescription}; + + my $subgroup = Koha::Library::Group->new( + { + parent_id => $lc->{show_in_pulldown} ? $search_groups_opac_root->id : $search_groups_staff_root->id, + title => $lc->{categoryname}, + description => $description, + } + )->store(); + + my $sth2 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?"); + $sth2->execute( $lc->{categorycode} ); + + while ( my $l = $sth2->fetchrow_hashref ) { + Koha::Library::Group->new( { parent_id => $subgroup->id, branchcode => $l->{branchcode} } )->store(); + } + } + +# RM Should uncomment these +# $dbh->do("DROP TABLE branchrelations"); +# $dbh->do("DROP TABLE branchcategories"); + + print "Upgrade to $DBversion done (Bug 16735 - Replace existing library search groups functionality with the new hierarchical groups system)\n"; + SetVersion($DBversion); +} + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -23,7 +23,7 @@
Basic parameters