Bug 16735: Migrate library search groups into the new hierarchical groups
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 22 Jun 2016 17:10:23 +0000 (17:10 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Feb 2018 18:41:25 +0000 (15:41 -0300)
Test Plan:
1) Apply this patch set
2) Note your existing search groups have been ported over to the new
   __SEARCH_GROUPS__ group if you had any
3) Create the group __SEARCH_GROUPS__ if one does not already exist
4) Add some first level subgroups to this group, add libraries to those groups
5) Search the library group searching in the intranet and opac
6) Note you get the same results as pre-patch

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

16 files changed:
C4/Auth.pm
Koha/Library.pm
Koha/Library/Group.pm
Koha/Library/Groups.pm
admin/branches.pl
catalogue/search.pl
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
opac/opac-search.pl
t/db_dependent/Koha/Libraries.t
t/db_dependent/RotatingCollections.t

index 838b0d2..7fac6df 100644 (file)
@@ -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 /;
@@ -513,11 +513,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,
index 151f30e..5862aa8 100644 (file)
@@ -41,37 +41,6 @@ TODO: Ask the author to add a proper description
 
 =cut
 
-sub get_categories {
-    my ( $self, $params ) = @_;
-    # TODO This should return Koha::LibraryCategories
-    return $self->{_result}->categorycodes( $params );
-}
-
-=head3 update_categories
-
-TODO: Ask the author to add a proper description
-
-=cut
-
-sub update_categories {
-    my ( $self, $categories ) = @_;
-    $self->_result->delete_related( 'branchrelations' );
-    $self->add_to_categories( $categories );
-}
-
-=head3 add_to_categories
-
-TODO: Ask the author to add a proper description
-
-=cut
-
-sub add_to_categories {
-    my ( $self, $categories ) = @_;
-    for my $category ( @$categories ) {
-        $self->_result->add_to_categorycodes( $category->_result );
-    }
-}
-
 =head3 get_effective_marcorgcode
 
     my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
index 43291e8..cc4bd6d 100644 (file)
@@ -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
index 9b1356a..d3cb72a 100644 (file)
@@ -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
index bcd712f..ab1021c 100755 (executable)
@@ -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(
@@ -80,18 +77,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' };
@@ -106,7 +96,6 @@ if ( $op eq 'add_form' ) {
             }
         );
         eval { $library->store; };
-        $library->add_to_categories( \@categories );
         if ($@) {
             push @messages, { type => 'alert', code => 'error_on_insert' };
         } else {
@@ -153,85 +142,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(
index 812bd4f..4041bd8 100755 (executable)
@@ -150,7 +150,7 @@ use POSIX qw(ceil floor);
 use C4::Search::History;
 
 use Koha::ItemTypes;
-use Koha::LibraryCategories;
+use Koha::Library::Groups;
 use Koha::Patrons;
 use Koha::SearchEngine::Search;
 use Koha::SearchEngine::QueryBuilder;
@@ -209,12 +209,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
@@ -395,8 +399,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  '()');
 }
index f3ebe14..8a4b3c8 100755 (executable)
@@ -15245,6 +15245,39 @@ if( CheckVersion( $DBversion ) ) {
     print "Upgrade to $DBversion done (Bug 15707 - Add new table library_groups)\n";
 }
 
+$DBversion = '17.12.00.008';
+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();
+        }
+    }
+
+    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
index b2a330c..4a52ef3 100644 (file)
@@ -9,7 +9,7 @@
 
 <h5>Basic parameters</h5>
 <ul>
-    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
+    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></li>
     <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
     <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
     <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
index 652c796..c1233b0 100644 (file)
                 <div class="hint"><h4>Hint:</h4><p>Configure these parameters in the order they appear.</p></div>
                 <h3>Basic parameters</h3>
                 <dl>
-                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
-                    <dd>Define libraries and groups.</dd>
+                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></dt>
+                    <dd>Define libraries.</dd>
                     <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
-                    <dd>Define library hierarchies.</dd>
+                    <dd>Define hierarchical library groups.</dd>
                     <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
                     <dd>Define item types used for circulation rules.</dd>
                     <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
index 72eef12..3e6c65b 100644 (file)
@@ -1,12 +1,8 @@
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Administration &rsaquo; Libraries and groups
-[% IF op == 'editcategory' %]
-    &rsaquo; [% IF category.categorycode %] Edit group [% category.categorycode%] [% ELSE %] New group [% END %]
-[% ELSIF op == 'delete_confirm_category' %]
-    &rsaquo; Confirm deletion of group [% category.categorycode %]
-[% ELSIF op == 'add_form' %]
-    &rsaquo; [% IF library %] Modify library [% library.branchcode | html %] [% ELSE %] New library [% END %]
+<title>Koha &rsaquo; Administration &rsaquo; Libraries
+[% IF op == 'add_form' %]
+    &rsaquo;[% IF library %]Modify library[% ELSE %]New library [% library.branchcode | html %][% END %]
 [% ELSIF op == 'delete_confirm' %]
     &rsaquo; Confirm deletion of library '[% library.branchcode | html %]'
 [% END %]
 <div id="breadcrumbs">
     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
 &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
-&rsaquo; <a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a>
-[% IF op == 'add_form_category' %]
-&rsaquo; [% IF category.categorycode %] Edit group [% category.categorycode %] [% ELSE %] New group [% END %]
-[% ELSIF op == 'delete_confirm_category' %]
-&rsaquo; Confirm deletion of group [% category.categorycode %]
-[% ELSIF op == 'add_form'  %]
-&rsaquo; [% IF library %] Modify library [% library.branchcode | html %] [% ELSE %] New library [% END %]
+&rsaquo; <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
+[% IF op == 'add_form'  %]
+&rsaquo; [% IF library %]Modify library[% ELSE %]New library [% library.branchcode | html %][% END %]
 [% ELSIF op == 'delete_confirm' %]
 &rsaquo; Confirm deletion of library '[% library.branchcode | html %]'
 [% END %]
@@ -87,7 +79,6 @@
 [% IF op == 'list' %]
     <div id="toolbar" class="btn-toolbar">
         <a class="btn btn-default btn-sm" id="newbranch" href="/cgi-bin/koha/admin/branches.pl?op=add_form"><i class="fa fa-plus"></i> New library</a>
-        <a class="btn btn-default btn-sm" id="newcategory" href="/cgi-bin/koha/admin/branches.pl?op=add_form_category"><i class="fa fa-plus"></i> New group</a>
     </div>
 [% END %]
 
     [% ELSE %]
         <div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">Start defining libraries</a>.</div>
     [% END %]
-
-    [% IF group_types %]
-        [% FOREACH group_type IN group_types %]
-            <h3>[% IF group_type.categorytype == 'properties' %]Properties[% ELSIF group_type.categorytype == 'searchdomain' %]Search domain[% END %]</h3>
-            [% IF group_type.categories.size %]
-                <table>
-                    <thead>
-                        <tr>
-                            <th>Name</th>
-                            <th>Code</th>
-                            <th>Description</th>
-                            <th>Actions</th>
-                        </tr>
-                    </thead>
-                    <tbody>
-                        [% FOREACH category IN group_type.categories %]
-                            <tr>
-                                <td>[% category.categoryname |html %]</td>
-                                <td>[% category.categorycode %]</td>
-                                <td>[% category.codedescription |html %]</td>
-                                <td class="actions">
-                                  <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?categorycode=[% category.categorycode %]&amp;op=add_form_category"><i class="fa fa-pencil"></i> Edit</a>
-                                  <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?categorycode=[% category.categorycode %]&amp;op=delete_confirm_category"><i class="fa fa-trash"></i> Delete</a>
-                                </td>
-                            </tr>
-                        [% END %]
-                    </tbody>
-                </table>
-            [% ELSE %]
-                [% IF group_type.categorytype == 'properties' %]
-                    No properties defined.
-                [% ELSIF group_type.categorytype == 'searchdomain' %]
-                    No search domain defined.
-                [% END %]
-                <a href="/cgi-bin/koha/admin/branches.pl?op=add_form_category">Add a new group</a>.
-            [% END %]
-        [% END %]
-    [% ELSE %]
-        <p>No groups defined.</p>
-    [% END %]
-[% END %]
-
-[% IF op == 'add_form_category' %]
-    <h3>[% IF category.categorycode %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
-    <form action="/cgi-bin/koha/admin/branches.pl" name="Aform" method="post" class="validated">
-        <input type="hidden" name="op" value="add_validate_category" />
-        [% IF category.categorycode %]
-            <input type="hidden" name="is_a_modif" value="1" />
-        [% END %]
-        <fieldset class="rows">
-            <ol>
-                <li>
-                    [% IF category.categorycode %]
-                        <span class="label">Category code: </span>
-                        <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode |html %]" />
-                        [% category.categorycode %]
-                    [% ELSE %]
-                        <label for="categorycode" class="required">Category code:</label>
-                        <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" class="required" required="required" />
-                        <span class="required">Required</span>
-                    [% END %]
-                </li>
-                <li>
-                    <label for="categoryname" class="required">Name: </label>
-                    <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname |html %]" class="required" required="required" />
-                    <span class="required">Required</span>
-                </li>
-                <li>
-                    <label for="codedescription">Description: </label>
-                    <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription |html %]" />
-                </li>
-                <li>
-                    <label for="categorytype">Category type: </label>
-                    <select id="categorytype" name="categorytype">
-                        [% IF category.categorytype == 'properties' %]
-                            <option value="searchdomain">Search domain</option>
-                            <option value="properties" selected="selected">Properties</option>
-                        [% ELSE %]
-                            <option value="searchdomain">Search domain</option>
-                            <option value="properties">Properties</option>
-
-                        [% END %]
-                    </select>
-                </li>
-                <li>
-                    <label for="show_in_pulldown">Show in search pulldown: </label>
-                    [% IF category.show_in_pulldown %]
-                        <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
-                    [% ELSE %]
-                        <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
-                    [% END %]
-                </li>
-            </ol>
-        </fieldset>
-        <fieldset class="action">
-            <input type="submit" value="Submit" />
-            <a href="/cgi-bin/koha/admin/branches.pl" class="cancel">Cancel</a>
-        </fieldset>
-    </form>
-[% END %]
-
-[% IF op == 'delete_confirm_category' %]
-    <div class="dialog alert">
-    <h3>Are you sure you want to delete the group '[% category.codedescription |html %]' ([% category.categorycode %])?</h3>
-    <form action="/cgi-bin/koha/admin/branches.pl" method="post">
-        <input type="hidden" name="op" value="delete_confirmed_category" />
-        <input type="hidden" name="categorycode" value="[% category.categorycode |html %]" />
-        <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
-    </form>
-    <form action="/cgi-bin/koha/admin/branches.pl" method="get">
-        <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
-    </form>
-    </div>
 [% END %]
 
 </div>
index 28b61ac..e5539c3 100644 (file)
         [% PROCESS options_for_libraries prefix => "branch:" libraries => Branches.all( selected => selected_branchcode, unfiltered => 1 ) %]
         </select></p>
     <!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
-        [% IF searchdomainloop.count %]
-    <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
-        <p><label for="categoryloop">Groups of libraries: </label><select name="multibranchlimit" id="categoryloop">
-        <option value=""> -- none -- </option>
-        [% FOREACH searchdomainloo IN searchdomainloop %]
-        <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
-        [% END %]
-        </select></p>
+        [% IF search_groups %]
+            <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
+
+            <p>
+                <label for="categoryloop">Groups of libraries: </label>
+                <select name="multibranchlimit" id="categoryloop">
+                    <option value=""> -- none -- </option>
+                    [% FOREACH sg IN search_groups %]
+                        <option value="[% sg.id %]">[% sg.title %]</option>
+                    [% END %]
+                </select>
+            </p>
     [% END %]
 </fieldset>
     </fieldset>
index fd37f6e..608cc17 100644 (file)
                                     <div class="input-append">
                                         <select name="branch_group_limit" id="select_library">
                                             <option value="">All libraries</option>
-                                            [% IF BranchCategoriesLoop %]<optgroup label="Libraries">[% END %]
-                                                [% FOREACH BranchesLoo IN Branches.all( selected => opac_name ) %]
-                                                    [% IF BranchesLoo.selected %]
-                                                        <option selected="selected" value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
-                                                    [% ELSE %]
-                                                        <option value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
-                                                    [% END %]
-                                                [% END %]
-                                            [% IF BranchCategoriesLoop %]
+
+                                            [% IF LibrarySearchGroups %]<optgroup label="Libraries">[% END %]
+
+                                            [% FOREACH BranchesLoo IN BranchesLoop %]
+                                                [% IF ( BranchesLoo.selected ) %]<option selected="selected" value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>
+                                                [% ELSE %]<option value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>[% END %]
+                                            [% END %]
+
+                                            [% IF LibrarySearchGroups %]
                                                 </optgroup>
                                                 <optgroup label="Groups">
-                                                    [% FOREACH bc IN BranchCategoriesLoop %]
-                                                        [% IF bc.categorycode == opac_name %]
-                                                            <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
+                                                    [% FOREACH lsg IN LibrarySearchGroups %]
+                                                        [% IF lsg.id == opac_name %]
+                                                            <option selected="selected" value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
                                                         [% ELSE %]
-                                                            <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
+                                                            <option value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
                                                         [% END # / bc.selected %]
                                                     [% END %]
                                                 </optgroup>
index 51c5dda..1705184 100644 (file)
                                         [% END %]
                                     [% END %]
                                     </select>
-                                    [% IF ( searchdomainloop && searchdomainloop.count > 0) %]
+                                    [% IF search_groups %]
                                         <p>OR</p>
                                         <label for="categoryloop">Groups of libraries</label>
                                         <select name="multibranchlimit" id="categoryloop">
                                             <option value=""> -- none -- </option>
-                                            [% FOREACH searchdomainloo IN searchdomainloop %]
-                                                <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
+                                            [% FOREACH sg IN search_groups %]
+                                                <option value="[% sg.id %]">[% sg.title %]</option>
                                             [% END %]
                                         </select>
                                     [% END %]
index ebe870b..81e6b3c 100755 (executable)
@@ -53,9 +53,9 @@ use C4::SocialData;
 use C4::External::OverDrive;
 
 use Koha::ItemTypes;
-use Koha::LibraryCategories;
 use Koha::Ratings;
 use Koha::Virtualshelves;
+use Koha::Library::Groups;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
@@ -214,8 +214,8 @@ if ($cgi->cookie("search_path_code")) {
     }
 }
 
-my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
-$template->param( searchdomainloop => $library_categories );
+my $search_groups = Koha::Library::Groups->get_search_groups();
+$template->param( search_groups => $search_groups );
 
 # load the language limits (for search)
 my $languages_limit_loop = getLanguages($lang, 1);
@@ -491,8 +491,8 @@ if (@searchCategories > 0) {
 @limits = map { uri_unescape($_) } @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  '()');
 }
index 22c7047..d24ba3d 100644 (file)
 
 use Modern::Perl;
 
-use Test::More tests => 10;
+use Test::More tests => 4;
 
 use Koha::Library;
 use Koha::Libraries;
-use Koha::LibraryCategory;
-use Koha::LibraryCategories;
 use Koha::Database;
 
 use t::lib::Mocks;
@@ -35,7 +33,6 @@ $schema->storage->txn_begin;
 
 my $builder = t::lib::TestBuilder->new;
 my $nb_of_libraries = Koha::Libraries->search->count;
-my $nb_of_categories = Koha::LibraryCategories->search->count;
 my $new_library_1 = Koha::Library->new({
     branchcode => 'my_bc_1',
     branchname => 'my_branchname_1',
@@ -47,47 +44,15 @@ my $new_library_2 = Koha::Library->new({
     branchname => 'my_branchname_2',
     branchnotes => 'my_branchnotes_2',
 })->store;
-my $new_category_1 = Koha::LibraryCategory->new({
-    categorycode => 'my_cc_1',
-    categoryname => 'my_categoryname_1',
-    codedescription => 'my_codedescription_1',
-    categorytype => 'properties',
-} )->store;
-my $new_category_2 = Koha::LibraryCategory->new( {
-          categorycode    => 'my_cc_2',
-          categoryname    => 'my_categoryname_2',
-          codedescription => 'my_codedescription_2',
-          categorytype    => 'searchdomain',
-} )->store;
-my $new_category_3 = Koha::LibraryCategory->new( {
-          categorycode    => 'my_cc_3',
-          categoryname    => 'my_categoryname_3',
-          codedescription => 'my_codedescription_3',
-          categorytype    => 'searchdomain',
-} )->store;
 
 is( Koha::Libraries->search->count,         $nb_of_libraries + 2,  'The 2 libraries should have been added' );
-is( Koha::LibraryCategories->search->count, $nb_of_categories + 3, 'The 3 library categories should have been added' );
 
-$new_library_1->add_to_categories( [$new_category_1] );
-$new_library_2->add_to_categories( [$new_category_2] );
 my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
 is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
-is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 1, '1 library should have been linked to the category 1' );
-
-$retrieved_library_1->update_categories( [ $new_category_2, $new_category_3 ] );
-is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 2, '2 libraries should have been linked to the category 2' );
-
-my $retrieved_category_2 = Koha::LibraryCategories->find( $new_category_2->categorycode );
-is( $retrieved_category_2->libraries->count, 2, '2 libraries should have been linked to the category_2' );
-is( $retrieved_category_2->categorycode, uc('my_cc_2'), 'The Koha::LibraryCategory constructor should have upercased the categorycode' );
 
 $retrieved_library_1->delete;
 is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
 
-$retrieved_category_2->delete;
-is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
-
 $schema->storage->txn_rollback;
 
 subtest '->get_effective_marcorgcode' => sub {
index a5bdb4a..9c46b33 100644 (file)
@@ -57,7 +57,6 @@ $dbh->do(q|DELETE FROM collections_tracking |);
 $dbh->do(q|DELETE FROM collections |);
 $dbh->do(q|DELETE FROM branches |);
 $dbh->do(q|DELETE FROM categories|);
-$dbh->do(q|DELETE FROM branchcategories|);
 
 #Test CreateCollection
 my $collections     = GetCollections();