View | Details | Raw Unified | Return to bug 16735
Collapse All | Expand All

(-)a/C4/Auth.pm (-3 / +3 lines)
Lines 33-40 use C4::Search::History; Link Here
33
use Koha;
33
use Koha;
34
use Koha::Caches;
34
use Koha::Caches;
35
use Koha::AuthUtils qw(get_script_name hash_password);
35
use Koha::AuthUtils qw(get_script_name hash_password);
36
use Koha::Library::Groups;
36
use Koha::Libraries;
37
use Koha::Libraries;
37
use Koha::LibraryCategories;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use POSIX qw/strftime/;
39
use POSIX qw/strftime/;
40
use List::MoreUtils qw/ any /;
40
use List::MoreUtils qw/ any /;
Lines 512-522 sub get_template_and_user { Link Here
512
            $opac_name = C4::Context->userenv->{'branch'};
512
            $opac_name = C4::Context->userenv->{'branch'};
513
        }
513
        }
514
514
515
        my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
515
        my $search_groups = Koha::Library::Groups->get_search_groups();
516
        $template->param(
516
        $template->param(
517
            OpacAdditionalStylesheet                   => C4::Context->preference("OpacAdditionalStylesheet"),
517
            OpacAdditionalStylesheet                   => C4::Context->preference("OpacAdditionalStylesheet"),
518
            AnonSuggestions                       => "" . C4::Context->preference("AnonSuggestions"),
518
            AnonSuggestions                       => "" . C4::Context->preference("AnonSuggestions"),
519
            BranchCategoriesLoop                  => $library_categories,
519
            LibrarySearchGroups                   => $search_groups,
520
            opac_name                             => $opac_name,
520
            opac_name                             => $opac_name,
521
            LibraryName                           => "" . C4::Context->preference("LibraryName"),
521
            LibraryName                           => "" . C4::Context->preference("LibraryName"),
522
            LibraryNameTitle                      => "" . $LibraryNameTitle,
522
            LibraryNameTitle                      => "" . $LibraryNameTitle,
(-)a/Koha/Library.pm (-31 lines)
Lines 41-77 TODO: Ask the author to add a proper description Link Here
41
41
42
=cut
42
=cut
43
43
44
sub get_categories {
45
    my ( $self, $params ) = @_;
46
    # TODO This should return Koha::LibraryCategories
47
    return $self->{_result}->categorycodes( $params );
48
}
49
50
=head3 update_categories
51
52
TODO: Ask the author to add a proper description
53
54
=cut
55
56
sub update_categories {
57
    my ( $self, $categories ) = @_;
58
    $self->_result->delete_related( 'branchrelations' );
59
    $self->add_to_categories( $categories );
60
}
61
62
=head3 add_to_categories
63
64
TODO: Ask the author to add a proper description
65
66
=cut
67
68
sub add_to_categories {
69
    my ( $self, $categories ) = @_;
70
    for my $category ( @$categories ) {
71
        $self->_result->add_to_categorycodes( $category->_result );
72
    }
73
}
74
75
=head3 get_effective_marcorgcode
44
=head3 get_effective_marcorgcode
76
45
77
    my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
46
    my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
(-)a/Koha/Library/Group.pm (-7 / +27 lines)
Lines 59-65 sub children { Link Here
59
    my $children =
59
    my $children =
60
      Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } );
60
      Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } );
61
61
62
    return $children;
62
    return wantarray ? $children->as_list : $children;
63
}
63
}
64
64
65
=head3 library
65
=head3 library
Lines 80-95 sub library { Link Here
80
    return $self->{_library};
80
    return $self->{_library};
81
}
81
}
82
82
83
=head3 libraries_not_direct_children
83
=head3 libraries
84
84
85
my @libraries = $group->libraries_not_direct_children();
85
my @libraries = $group->libraries( { [invert => 1] } );
86
86
87
Returns the libraries *not* set as direct children of this group
87
Returns the libraries set as direct children of this group.
88
89
If invert param is true, the returned list will be libraries
90
that are *not* direct children of this group.
88
91
89
=cut
92
=cut
90
93
91
sub libraries_not_direct_children {
94
sub libraries {
92
    my ($self) = @_;
95
    my ($self, $params) = @_;
96
    my $invert = $params->{invert};
97
98
    my $in_or_not = $invert ? '-not_in' : '-in';
93
99
94
    my @children = Koha::Library::Groups->search(
100
    my @children = Koha::Library::Groups->search(
95
        {
101
        {
Lines 103-109 sub libraries_not_direct_children { Link Here
103
109
104
    return Koha::Libraries->search(
110
    return Koha::Libraries->search(
105
        {
111
        {
106
            branchcode => { -not_in => \@branchcodes }
112
            branchcode => { $in_or_not => \@branchcodes }
107
        },
113
        },
108
        {
114
        {
109
            order_by => 'branchname'
115
            order_by => 'branchname'
Lines 111-116 sub libraries_not_direct_children { Link Here
111
    );
117
    );
112
}
118
}
113
119
120
=head3 libraries_not_direct_children
121
122
my @libraries = $group->libraries_not_direct_children();
123
124
Returns the libraries *not* set as direct children of this group
125
126
=cut
127
128
sub libraries_not_direct_children {
129
    my ($self) = @_;
130
131
    return $self->libraries( { invert => 1 } );
132
}
133
114
=head3 store
134
=head3 store
115
135
116
=cut
136
=cut
(-)a/Koha/Library/Groups.pm (+23 lines)
Lines 45-50 sub get_root_groups { Link Here
45
    return $self->search( { parent_id => undef }, { order_by => 'title' } );
45
    return $self->search( { parent_id => undef }, { order_by => 'title' } );
46
}
46
}
47
47
48
=head3 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']}))
49
50
Returns search groups for the specified interface.
51
Defaults to OPAC if no interface is specified.
52
53
=cut
54
55
sub get_search_groups {
56
    my ( $self, $params ) = @_;
57
    my $interface = $params->{interface} || q{};
58
59
    my $title = $interface eq 'staff' ? '__SEARCH_GROUPS__' : '__SEARCH_GROUPS_OPAC__';
60
61
    my ($search_groups_root) =
62
      $self->search( { parent_id => undef, title => $title } );
63
64
    return unless $search_groups_root;
65
66
    my $children = $search_groups_root->children();
67
68
    return wantarray ? $children->as_list : $children;
69
}
70
48
=head3 type
71
=head3 type
49
72
50
=cut
73
=cut
(-)a/admin/branches.pl (-84 / +1 lines)
Lines 27-33 use C4::Koha; Link Here
27
use Koha::Patrons;
27
use Koha::Patrons;
28
use Koha::Items;
28
use Koha::Items;
29
use Koha::Libraries;
29
use Koha::Libraries;
30
use Koha::LibraryCategories;
31
30
32
my $input        = new CGI;
31
my $input        = new CGI;
33
my $branchcode   = $input->param('branchcode');
32
my $branchcode   = $input->param('branchcode');
Lines 53-60 if ( $op eq 'add_form' ) { Link Here
53
52
54
    $template->param(
53
    $template->param(
55
        library    => $library,
54
        library    => $library,
56
        categories => [ Koha::LibraryCategories->search( {}, { order_by => [ 'categorytype', 'categoryname' ] } ) ],
57
        $library ? ( selected_categorycodes => [ map { $_->categorycode } $library->get_categories ] ) : (),
58
    );
55
    );
59
} elsif ( $op eq 'add_validate' ) {
56
} elsif ( $op eq 'add_validate' ) {
60
    my @fields = qw(
57
    my @fields = qw(
Lines 80-97 if ( $op eq 'add_form' ) { Link Here
80
    );
77
    );
81
    my $is_a_modif = $input->param('is_a_modif');
78
    my $is_a_modif = $input->param('is_a_modif');
82
79
83
    my @categories;
84
    for my $category ( Koha::LibraryCategories->search ) {
85
        push @categories, $category
86
          if $input->param( "selected_categorycode_" . $category->categorycode );
87
    }
88
    if ($is_a_modif) {
80
    if ($is_a_modif) {
89
        my $library = Koha::Libraries->find($branchcode);
81
        my $library = Koha::Libraries->find($branchcode);
90
        for my $field (@fields) {
82
        for my $field (@fields) {
91
            $library->$field( scalar $input->param($field) );
83
            $library->$field( scalar $input->param($field) );
92
        }
84
        }
93
        $library->update_categories( \@categories );
94
95
        eval { $library->store; };
85
        eval { $library->store; };
96
        if ($@) {
86
        if ($@) {
97
            push @messages, { type => 'alert', code => 'error_on_update' };
87
            push @messages, { type => 'alert', code => 'error_on_update' };
Lines 106-112 if ( $op eq 'add_form' ) { Link Here
106
            }
96
            }
107
        );
97
        );
108
        eval { $library->store; };
98
        eval { $library->store; };
109
        $library->add_to_categories( \@categories );
110
        if ($@) {
99
        if ($@) {
111
            push @messages, { type => 'alert', code => 'error_on_insert' };
100
            push @messages, { type => 'alert', code => 'error_on_insert' };
112
        } else {
101
        } else {
Lines 153-237 if ( $op eq 'add_form' ) { Link Here
153
        push @messages, { type => 'message', code => 'success_on_delete' };
142
        push @messages, { type => 'message', code => 'success_on_delete' };
154
    }
143
    }
155
    $op = 'list';
144
    $op = 'list';
156
} elsif ( $op eq 'add_form_category' ) {
157
    my $category;
158
    if ($categorycode) {
159
        $category = Koha::LibraryCategories->find($categorycode);
160
    }
161
    $template->param( category => $category, );
162
} elsif ( $op eq 'add_validate_category' ) {
163
    my $is_a_modif = $input->param('is_a_modif');
164
    my @fields     = qw(
165
      categoryname
166
      codedescription
167
      categorytype
168
    );
169
    if ($is_a_modif) {
170
        my $category = Koha::LibraryCategories->find($categorycode);
171
        for my $field (@fields) {
172
            $category->$field( scalar $input->param($field) );
173
        }
174
        $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' );
175
        eval { $category->store; };
176
        if ($@) {
177
            push @messages, { type => 'alert', code => 'error_on_update_category' };
178
        } else {
179
            push @messages, { type => 'message', code => 'success_on_update_category' };
180
        }
181
    } else {
182
        my $category = Koha::LibraryCategory->new(
183
            {   categorycode => $categorycode,
184
                ( map { $_ => scalar $input->param($_) || undef } @fields )
185
            }
186
        );
187
        $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' );
188
        eval { $category->store; };
189
        if ($@) {
190
            push @messages, { type => 'alert', code => 'error_on_insert_category' };
191
        } else {
192
            push @messages, { type => 'message', code => 'success_on_insert_category' };
193
        }
194
    }
195
    $op = 'list';
196
} elsif ( $op eq 'delete_confirm_category' ) {
197
    my $category = Koha::LibraryCategories->find($categorycode);
198
    if ( my $libraries_count = $category->libraries->count ) {
199
        push @messages,
200
          { type => 'alert',
201
            code => 'cannot_delete_category',
202
            data => { libraries_count => $libraries_count, },
203
          };
204
        $op = 'list';
205
    } else {
206
        $template->param( category => $category );
207
    }
208
} elsif ( $op eq 'delete_confirmed_category' ) {
209
    my $category = Koha::LibraryCategories->find($categorycode);
210
    my $deleted = eval { $category->delete; };
211
212
    if ( $@ or not $deleted ) {
213
        push @messages, { type => 'alert', code => 'error_on_delete_category' };
214
    } else {
215
        push @messages, { type => 'message', code => 'success_on_delete_category' };
216
    }
217
    $op = 'list';
218
} else {
145
} else {
219
    $op = 'list';
146
    $op = 'list';
220
}
147
}
221
148
222
if ( $op eq 'list' ) {
149
if ( $op eq 'list' ) {
223
    my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
150
    my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
224
    $template->param(
151
    $template->param( libraries => $libraries, );
225
        libraries   => $libraries,
226
        group_types => [
227
            {   categorytype => 'searchdomain',
228
                categories   => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ],
229
            },
230
            {   categorytype => 'properties',
231
                categories   => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ],
232
            },
233
        ]
234
    );
235
}
152
}
236
153
237
$template->param(
154
$template->param(
(-)a/catalogue/search.pl (-6 / +10 lines)
Lines 151-157 use POSIX qw(ceil floor); Link Here
151
use C4::Search::History;
151
use C4::Search::History;
152
152
153
use Koha::ItemTypes;
153
use Koha::ItemTypes;
154
use Koha::LibraryCategories;
154
use Koha::Library::Groups;
155
use Koha::Patrons;
155
use Koha::Patrons;
156
use Koha::SearchEngine::Search;
156
use Koha::SearchEngine::Search;
157
use Koha::SearchEngine::QueryBuilder;
157
use Koha::SearchEngine::QueryBuilder;
Lines 213-224 if($cgi->cookie("intranet_bib_list")){ Link Here
213
    @cart_list = split(/\//, $cart_list);
213
    @cart_list = split(/\//, $cart_list);
214
}
214
}
215
215
216
# load the branches
216
my @search_groups_opac =
217
my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
217
  Koha::Library::Groups->get_search_groups( { interface => 'opac' } );
218
my @search_groups_staff =
219
  Koha::Library::Groups->get_search_groups( { interface => 'staff' } );
220
my @search_groups = ( @search_groups_opac, @search_groups_staff );
221
@search_groups = sort { $a->title cmp $b->title } @search_groups;
218
222
219
$template->param(
223
$template->param(
220
    selected_branchcode => ( C4::Context->IsSuperLibrarian ? C4::Context->userenv : '' ),
224
    selected_branchcode => ( C4::Context->IsSuperLibrarian ? C4::Context->userenv : '' ),
221
    searchdomainloop => $categories
225
    search_groups    => \@search_groups,
222
);
226
);
223
227
224
# load the Type stuff
228
# load the Type stuff
Lines 399-406 my %is_nolimit = map { $_ => 1 } @nolimits; Link Here
399
@limits = grep { not $is_nolimit{$_} } @limits;
403
@limits = grep { not $is_nolimit{$_} } @limits;
400
404
401
if($params->{'multibranchlimit'}) {
405
if($params->{'multibranchlimit'}) {
402
    my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} );
406
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
403
    my @libraries = $library_category->libraries;
407
    my @libraries = $search_group->libraries;
404
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
408
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
405
    push @limits, $multibranch if ($multibranch ne  '()');
409
    push @limits, $multibranch if ($multibranch ne  '()');
406
}
410
}
(-)a/installer/data/mysql/updatedatabase.pl (+38 lines)
Lines 15050-15055 if( CheckVersion( $DBversion ) ) { Link Here
15050
    print "Upgrade to $DBversion done (Tē tōia, tē haumatia)\n";
15050
    print "Upgrade to $DBversion done (Tē tōia, tē haumatia)\n";
15051
}
15051
}
15052
15052
15053
$DBversion = "XXX";
15054
if ( CheckVersion($DBversion) ) {
15055
    require Koha::Library::Group;
15056
15057
    my $search_groups_staff_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS__', description => "Library search groups - Staff only" } )->store();
15058
    my $search_groups_opac_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS_OPAC__', description => "Library search groups - OPAC & Staff" } )->store();
15059
15060
    my $sth = $dbh->prepare("SELECT * FROM branchcategories");
15061
    $sth->execute();
15062
15063
    while ( my $lc = $sth->fetchrow_hashref ) {
15064
        my $description = $lc->{categorycode};
15065
        $description .= " - " . $lc->{codedescription} if $lc->{codedescription};
15066
15067
        my $subgroup = Koha::Library::Group->new(
15068
            {
15069
                parent_id   => $lc->{show_in_pulldown} ? $search_groups_opac_root->id : $search_groups_staff_root->id,
15070
                title       => $lc->{categoryname},
15071
                description => $description,
15072
            }
15073
        )->store();
15074
15075
        my $sth2 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?");
15076
        $sth2->execute( $lc->{categorycode} );
15077
15078
        while ( my $l = $sth2->fetchrow_hashref ) {
15079
            Koha::Library::Group->new( { parent_id => $subgroup->id, branchcode => $l->{branchcode} } )->store();
15080
        }
15081
    }
15082
15083
# RM Should uncomment these
15084
#    $dbh->do("DROP TABLE branchrelations");
15085
#    $dbh->do("DROP TABLE branchcategories");
15086
15087
    print "Upgrade to $DBversion done (Bug 16735 - Replace existing library search groups functionality with the new hierarchical groups system)\n";
15088
    SetVersion($DBversion);
15089
}
15090
15053
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
15091
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
15054
# SEE bug 13068
15092
# SEE bug 13068
15055
# if there is anything in the atomicupdate, read and execute it.
15093
# if there is anything in the atomicupdate, read and execute it.
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (-1 / +1 lines)
Lines 23-29 Link Here
23
23
24
<h5>Basic parameters</h5>
24
<h5>Basic parameters</h5>
25
<ul>
25
<ul>
26
    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
26
    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></li>
27
    <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
27
    <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
28
    <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
28
    <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
29
    <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
29
    <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-3 / +3 lines)
Lines 29-38 Link Here
29
                <div class="hint"><h4>Hint:</h4><p>Configure these parameters in the order they appear.</p></div>
29
                <div class="hint"><h4>Hint:</h4><p>Configure these parameters in the order they appear.</p></div>
30
                <h3>Basic parameters</h3>
30
                <h3>Basic parameters</h3>
31
                <dl>
31
                <dl>
32
                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
32
                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></dt>
33
                    <dd>Define libraries and groups.</dd>
33
                    <dd>Define libraries.</dd>
34
                    <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
34
                    <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
35
                    <dd>Define library hierarchies.</dd>
35
                    <dd>Define hierarchical library groups.</dd>
36
                    <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
36
                    <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
37
                    <dd>Define item types used for circulation rules.</dd>
37
                    <dd>Define item types used for circulation rules.</dd>
38
                    <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
38
                    <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-132 / +4 lines)
Lines 1-10 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Libraries and groups
2
<title>Koha &rsaquo; Administration &rsaquo; Libraries
3
[% IF op == 'editcategory' %]
3
[% IF op == 'add_form' %]
4
    &rsaquo;[% IF category.categorycode %]Edit group [% category.categorycode%][% ELSE %]New group[% END %]
5
[% ELSIF op == 'delete_confirm_category' %]
6
    &rsaquo; Confirm deletion of group [% category.categorycode %]
7
[% ELSIF op == 'add_form' %]
8
    &rsaquo;[% IF library %]Modify library[% ELSE %]New library [% library.branchcode %][% END %]
4
    &rsaquo;[% IF library %]Modify library[% ELSE %]New library [% library.branchcode %][% END %]
9
[% ELSIF op == 'delete_confirm' %]
5
[% ELSIF op == 'delete_confirm' %]
10
    &rsaquo; Confirm deletion of library '[% library.branchcode %]'
6
    &rsaquo; Confirm deletion of library '[% library.branchcode %]'
Lines 61-72 tinyMCE.init({ Link Here
61
<div id="breadcrumbs">
57
<div id="breadcrumbs">
62
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
58
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
63
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
59
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
64
&rsaquo; <a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a>
60
&rsaquo; <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
65
[% IF op == 'add_form_category' %]
61
[% IF op == 'add_form'  %]
66
&rsaquo; [% IF category.categorycode %]Edit group [% category.categorycode %][% ELSE %]New group[% END %]
67
[% ELSIF op == 'delete_confirm_category' %]
68
&rsaquo; Confirm deletion of group [% category.categorycode %]
69
[% ELSIF op == 'add_form'  %]
70
&rsaquo; [% IF library %]Modify library[% ELSE %]New library [% library.branchcode %][% END %]
62
&rsaquo; [% IF library %]Modify library[% ELSE %]New library [% library.branchcode %][% END %]
71
[% ELSIF op == 'delete_confirm' %]
63
[% ELSIF op == 'delete_confirm' %]
72
&rsaquo; Confirm deletion of library '[% library.branchcode %]'
64
&rsaquo; Confirm deletion of library '[% library.branchcode %]'
Lines 126-132 tinyMCE.init({ Link Here
126
[% IF op == 'list' %]
118
[% IF op == 'list' %]
127
    <div id="toolbar" class="btn-toolbar">
119
    <div id="toolbar" class="btn-toolbar">
128
        <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>
120
        <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>
129
        <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>
130
    </div>
121
    </div>
131
[% END %]
122
[% END %]
132
123
Lines 226-232 tinyMCE.init({ Link Here
226
                    <th>Name</th>
217
                    <th>Name</th>
227
                    <th>Code</th>
218
                    <th>Code</th>
228
                    <th>Address</th>
219
                    <th>Address</th>
229
                    <th>Properties</th>
230
                    <th>IP</th>
220
                    <th>IP</th>
231
                    <th>Actions</th>
221
                    <th>Actions</th>
232
                </tr>
222
                </tr>
Lines 263-273 tinyMCE.init({ Link Here
263
                            [% IF library.branchnotes %]
253
                            [% IF library.branchnotes %]
264
                                <br />Notes: [% library.branchnotes |html %][% END %]
254
                                <br />Notes: [% library.branchnotes |html %][% END %]
265
                        </td>
255
                        </td>
266
                        <td>
267
                            [% FOREACH category IN library.get_categories %]
268
                                [% category.categoryname |html %]<br />
269
                            [% END %]
270
                        </td>
271
                        <td>[% library.branchip %]</td>
256
                        <td>[% library.branchip %]</td>
272
                        <td class="actions">
257
                        <td class="actions">
273
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?op=add_form&amp;branchcode=[% library.branchcode %]"><i class="fa fa-pencil"></i> Edit</a>
258
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?op=add_form&amp;branchcode=[% library.branchcode %]"><i class="fa fa-pencil"></i> Edit</a>
Lines 280-398 tinyMCE.init({ Link Here
280
    [% ELSE %]
265
    [% ELSE %]
281
        <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>
266
        <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>
282
    [% END %]
267
    [% END %]
283
284
    [% IF group_types %]
285
        [% FOREACH group_type IN group_types %]
286
            <h3>[% IF group_type.categorytype == 'properties' %]Properties[% ELSIF group_type.categorytype == 'searchdomain' %]Search domain[% END %]</h3>
287
            [% IF group_type.categories.size %]
288
                <table>
289
                    <thead>
290
                        <tr>
291
                            <th>Name</th>
292
                            <th>Code</th>
293
                            <th>Description</th>
294
                            <th>Actions</th>
295
                        </tr>
296
                    </thead>
297
                    <tbody>
298
                        [% FOREACH category IN group_type.categories %]
299
                            <tr>
300
                                <td>[% category.categoryname |html %]</td>
301
                                <td>[% category.categorycode %]</td>
302
                                <td>[% category.codedescription |html %]</td>
303
                                <td class="actions">
304
                                  <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>
305
                                  <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>
306
                                </td>
307
                            </tr>
308
                        [% END %]
309
                    </tbody>
310
                </table>
311
            [% ELSE %]
312
                [% IF group_type.categorytype == 'properties' %]
313
                    No properties defined.
314
                [% ELSIF group_type.categorytype == 'searchdomain' %]
315
                    No search domain defined.
316
                [% END %]
317
                <a href="/cgi-bin/koha/admin/branches.pl?op=add_form_category">Add a new group</a>.
318
            [% END %]
319
        [% END %]
320
    [% ELSE %]
321
        <p>No groups defined.</p>
322
    [% END %]
323
[% END %]
324
325
[% IF op == 'add_form_category' %]
326
    <h3>[% IF category.categorycode %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
327
    <form action="/cgi-bin/koha/admin/branches.pl" name="Aform" method="post" class="validated">
328
        <input type="hidden" name="op" value="add_validate_category" />
329
        [% IF category.categorycode %]
330
            <input type="hidden" name="is_a_modif" value="1" />
331
        [% END %]
332
        <fieldset class="rows">
333
            <ol>
334
                <li>
335
                    [% IF category.categorycode %]
336
                        <span class="label">Category code: </span>
337
                        <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode |html %]" />
338
                        [% category.categorycode %]
339
                    [% ELSE %]
340
                        <label for="categorycode" class="required">Category code:</label>
341
                        <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" class="required" required="required" />
342
                        <span class="required">Required</span>
343
                    [% END %]
344
                </li>
345
                <li>
346
                    <label for="categoryname" class="required">Name: </label>
347
                    <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname |html %]" class="required" required="required" />
348
                    <span class="required">Required</span>
349
                </li>
350
                <li>
351
                    <label for="codedescription">Description: </label>
352
                    <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription |html %]" />
353
                </li>
354
                <li>
355
                    <label for="categorytype">Category type: </label>
356
                    <select id="categorytype" name="categorytype">
357
                        [% IF category.categorytype == 'properties' %]
358
                            <option value="searchdomain">Search domain</option>
359
                            <option value="properties" selected="selected">Properties</option>
360
                        [% ELSE %]
361
                            <option value="searchdomain">Search domain</option>
362
                            <option value="properties">Properties</option>
363
364
                        [% END %]
365
                    </select>
366
                </li>
367
                <li>
368
                    <label for="show_in_pulldown">Show in search pulldown: </label>
369
                    [% IF category.show_in_pulldown %]
370
                        <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
371
                    [% ELSE %]
372
                        <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
373
                    [% END %]
374
                </li>
375
            </ol>
376
        </fieldset>
377
        <fieldset class="action">
378
            <input type="submit" value="Submit" />
379
            <a href="/cgi-bin/koha/admin/branches.pl" class="cancel">Cancel</a>
380
        </fieldset>
381
    </form>
382
[% END %]
383
384
[% IF op == 'delete_confirm_category' %]
385
    <div class="dialog alert">
386
    <h3>Are you sure you want to delete the group '[% category.codedescription |html %]' ([% category.categorycode %])?</h3>
387
    <form action="/cgi-bin/koha/admin/branches.pl" method="post">
388
        <input type="hidden" name="op" value="delete_confirmed_category" />
389
        <input type="hidden" name="categorycode" value="[% category.categorycode |html %]" />
390
        <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
391
    </form>
392
    <form action="/cgi-bin/koha/admin/branches.pl" method="get">
393
        <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
394
    </form>
395
    </div>
396
[% END %]
268
[% END %]
397
269
398
</div>
270
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (-8 / +12 lines)
Lines 242-255 Link Here
242
        [% PROCESS options_for_libraries prefix => "branch:" libraries => Branches.all( selected => selected_branchcode, unfiltered => 1 ) %]
242
        [% PROCESS options_for_libraries prefix => "branch:" libraries => Branches.all( selected => selected_branchcode, unfiltered => 1 ) %]
243
        </select></p>
243
        </select></p>
244
    <!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
244
    <!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
245
        [% IF searchdomainloop.count %]
245
        [% IF search_groups %]
246
    <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
246
            <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
247
        <p><label for="categoryloop">Groups of libraries: </label><select name="multibranchlimit" id="categoryloop">
247
248
        <option value=""> -- none -- </option>
248
            <p>
249
        [% FOREACH searchdomainloo IN searchdomainloop %]
249
                <label for="categoryloop">Groups of libraries: </label>
250
        <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
250
                <select name="multibranchlimit" id="categoryloop">
251
        [% END %]
251
                    <option value=""> -- none -- </option>
252
        </select></p>
252
                    [% FOREACH sg IN search_groups %]
253
                        <option value="[% sg.id %]">[% sg.title %]</option>
254
                    [% END %]
255
                </select>
256
            </p>
253
    [% END %]
257
    [% END %]
254
</fieldset>
258
</fieldset>
255
    </fieldset>
259
    </fieldset>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc (-13 / +13 lines)
Lines 229-250 Link Here
229
                                    <div class="input-append">
229
                                    <div class="input-append">
230
                                        <select name="branch_group_limit" id="select_library">
230
                                        <select name="branch_group_limit" id="select_library">
231
                                            <option value="">All libraries</option>
231
                                            <option value="">All libraries</option>
232
                                            [% IF BranchCategoriesLoop %]<optgroup label="Libraries">[% END %]
232
233
                                                [% FOREACH BranchesLoo IN Branches.all( selected => opac_name ) %]
233
                                            [% IF LibrarySearchGroups %]<optgroup label="Libraries">[% END %]
234
                                                    [% IF BranchesLoo.selected %]
234
235
                                                        <option selected="selected" value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
235
                                            [% FOREACH BranchesLoo IN BranchesLoop %]
236
                                                    [% ELSE %]
236
                                                [% IF ( BranchesLoo.selected ) %]<option selected="selected" value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>
237
                                                        <option value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
237
                                                [% ELSE %]<option value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>[% END %]
238
                                                    [% END %]
238
                                            [% END %]
239
                                                [% END %]
239
240
                                            [% IF BranchCategoriesLoop %]
240
                                            [% IF LibrarySearchGroups %]
241
                                                </optgroup>
241
                                                </optgroup>
242
                                                <optgroup label="Groups">
242
                                                <optgroup label="Groups">
243
                                                    [% FOREACH bc IN BranchCategoriesLoop %]
243
                                                    [% FOREACH lsg IN LibrarySearchGroups %]
244
                                                        [% IF bc.categorycode == opac_name %]
244
                                                        [% IF lsg.id == opac_name %]
245
                                                            <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
245
                                                            <option selected="selected" value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
246
                                                        [% ELSE %]
246
                                                        [% ELSE %]
247
                                                            <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
247
                                                            <option value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
248
                                                        [% END # / bc.selected %]
248
                                                        [% END # / bc.selected %]
249
                                                    [% END %]
249
                                                    [% END %]
250
                                                </optgroup>
250
                                                </optgroup>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt (-3 / +3 lines)
Lines 223-235 Link Here
223
                                        [% END %]
223
                                        [% END %]
224
                                    [% END %]
224
                                    [% END %]
225
                                    </select>
225
                                    </select>
226
                                    [% IF ( searchdomainloop && searchdomainloop.count > 0) %]
226
                                    [% IF search_groups %]
227
                                        <p>OR</p>
227
                                        <p>OR</p>
228
                                        <label for="categoryloop">Groups of libraries</label>
228
                                        <label for="categoryloop">Groups of libraries</label>
229
                                        <select name="multibranchlimit" id="categoryloop">
229
                                        <select name="multibranchlimit" id="categoryloop">
230
                                            <option value=""> -- none -- </option>
230
                                            <option value=""> -- none -- </option>
231
                                            [% FOREACH searchdomainloo IN searchdomainloop %]
231
                                            [% FOREACH sg IN search_groups %]
232
                                                <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
232
                                                <option value="[% sg.id %]">[% sg.title %]</option>
233
                                            [% END %]
233
                                            [% END %]
234
                                        </select>
234
                                        </select>
235
                                    [% END %]
235
                                    [% END %]
(-)a/opac/opac-search.pl (-5 / +5 lines)
Lines 53-61 use C4::SocialData; Link Here
53
use C4::External::OverDrive;
53
use C4::External::OverDrive;
54
54
55
use Koha::ItemTypes;
55
use Koha::ItemTypes;
56
use Koha::LibraryCategories;
57
use Koha::Ratings;
56
use Koha::Ratings;
58
use Koha::Virtualshelves;
57
use Koha::Virtualshelves;
58
use Koha::Library::Groups;
59
59
60
use POSIX qw(ceil floor strftime);
60
use POSIX qw(ceil floor strftime);
61
use URI::Escape;
61
use URI::Escape;
Lines 214-221 if ($cgi->cookie("search_path_code")) { Link Here
214
    }
214
    }
215
}
215
}
216
216
217
my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
217
my $search_groups = Koha::Library::Groups->get_search_groups();
218
$template->param( searchdomainloop => $library_categories );
218
$template->param( search_groups => $search_groups );
219
219
220
# load the language limits (for search)
220
# load the language limits (for search)
221
my $languages_limit_loop = getLanguages($lang, 1);
221
my $languages_limit_loop = getLanguages($lang, 1);
Lines 491-498 if (@searchCategories > 0) { Link Here
491
@limits = map { uri_unescape($_) } @limits;
491
@limits = map { uri_unescape($_) } @limits;
492
492
493
if($params->{'multibranchlimit'}) {
493
if($params->{'multibranchlimit'}) {
494
    my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} );
494
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
495
    my @libraries = $library_category->libraries;
495
    my @libraries = $search_group->libraries;
496
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
496
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
497
    push @limits, $multibranch if ($multibranch ne  '()');
497
    push @limits, $multibranch if ($multibranch ne  '()');
498
}
498
}
(-)a/t/db_dependent/Koha/Libraries.t (-36 / +1 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 4;
23
23
24
use Koha::Library;
24
use Koha::Library;
25
use Koha::Libraries;
25
use Koha::Libraries;
26
use Koha::LibraryCategory;
27
use Koha::LibraryCategories;
28
use Koha::Database;
26
use Koha::Database;
29
27
30
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 35-41 $schema->storage->txn_begin; Link Here
35
33
36
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
37
my $nb_of_libraries = Koha::Libraries->search->count;
35
my $nb_of_libraries = Koha::Libraries->search->count;
38
my $nb_of_categories = Koha::LibraryCategories->search->count;
39
my $new_library_1 = Koha::Library->new({
36
my $new_library_1 = Koha::Library->new({
40
    branchcode => 'my_bc_1',
37
    branchcode => 'my_bc_1',
41
    branchname => 'my_branchname_1',
38
    branchname => 'my_branchname_1',
Lines 47-93 my $new_library_2 = Koha::Library->new({ Link Here
47
    branchname => 'my_branchname_2',
44
    branchname => 'my_branchname_2',
48
    branchnotes => 'my_branchnotes_2',
45
    branchnotes => 'my_branchnotes_2',
49
})->store;
46
})->store;
50
my $new_category_1 = Koha::LibraryCategory->new({
51
    categorycode => 'my_cc_1',
52
    categoryname => 'my_categoryname_1',
53
    codedescription => 'my_codedescription_1',
54
    categorytype => 'properties',
55
} )->store;
56
my $new_category_2 = Koha::LibraryCategory->new( {
57
          categorycode    => 'my_cc_2',
58
          categoryname    => 'my_categoryname_2',
59
          codedescription => 'my_codedescription_2',
60
          categorytype    => 'searchdomain',
61
} )->store;
62
my $new_category_3 = Koha::LibraryCategory->new( {
63
          categorycode    => 'my_cc_3',
64
          categoryname    => 'my_categoryname_3',
65
          codedescription => 'my_codedescription_3',
66
          categorytype    => 'searchdomain',
67
} )->store;
68
47
69
is( Koha::Libraries->search->count,         $nb_of_libraries + 2,  'The 2 libraries should have been added' );
48
is( Koha::Libraries->search->count,         $nb_of_libraries + 2,  'The 2 libraries should have been added' );
70
is( Koha::LibraryCategories->search->count, $nb_of_categories + 3, 'The 3 library categories should have been added' );
71
49
72
$new_library_1->add_to_categories( [$new_category_1] );
73
$new_library_2->add_to_categories( [$new_category_2] );
74
my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
50
my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
75
is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
51
is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
76
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 1, '1 library should have been linked to the category 1' );
77
78
$retrieved_library_1->update_categories( [ $new_category_2, $new_category_3 ] );
79
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 2, '2 libraries should have been linked to the category 2' );
80
81
my $retrieved_category_2 = Koha::LibraryCategories->find( $new_category_2->categorycode );
82
is( $retrieved_category_2->libraries->count, 2, '2 libraries should have been linked to the category_2' );
83
is( $retrieved_category_2->categorycode, uc('my_cc_2'), 'The Koha::LibraryCategory constructor should have upercased the categorycode' );
84
52
85
$retrieved_library_1->delete;
53
$retrieved_library_1->delete;
86
is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
54
is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
87
55
88
$retrieved_category_2->delete;
89
is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
90
91
$schema->storage->txn_rollback;
56
$schema->storage->txn_rollback;
92
57
93
subtest '->get_effective_marcorgcode' => sub {
58
subtest '->get_effective_marcorgcode' => sub {
(-)a/t/db_dependent/RotatingCollections.t (-2 lines)
Lines 57-63 $dbh->do(q|DELETE FROM collections_tracking |); Link Here
57
$dbh->do(q|DELETE FROM collections |);
57
$dbh->do(q|DELETE FROM collections |);
58
$dbh->do(q|DELETE FROM branches |);
58
$dbh->do(q|DELETE FROM branches |);
59
$dbh->do(q|DELETE FROM categories|);
59
$dbh->do(q|DELETE FROM categories|);
60
$dbh->do(q|DELETE FROM branchcategories|);
61
60
62
#Test CreateCollection
61
#Test CreateCollection
63
my $collections     = GetCollections();
62
my $collections     = GetCollections();
64
- 

Return to bug 16735