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

(-)a/C4/Auth.pm (-1 / +4 lines)
Lines 32-37 use C4::Branch; # GetBranches Link Here
32
use C4::Search::History;
32
use C4::Search::History;
33
use Koha;
33
use Koha;
34
use Koha::AuthUtils qw(hash_password);
34
use Koha::AuthUtils qw(hash_password);
35
use Koha::LibraryCategories;
35
use POSIX qw/strftime/;
36
use POSIX qw/strftime/;
36
use List::MoreUtils qw/ any /;
37
use List::MoreUtils qw/ any /;
37
use Encode qw( encode is_utf8);
38
use Encode qw( encode is_utf8);
Lines 501-512 sub get_template_and_user { Link Here
501
            $opac_name = C4::Context->userenv->{'branch'};
502
            $opac_name = C4::Context->userenv->{'branch'};
502
        }
503
        }
503
504
505
        my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
504
        $template->param(
506
        $template->param(
505
            OpacAdditionalStylesheet                   => C4::Context->preference("OpacAdditionalStylesheet"),
507
            OpacAdditionalStylesheet                   => C4::Context->preference("OpacAdditionalStylesheet"),
506
            AnonSuggestions                       => "" . C4::Context->preference("AnonSuggestions"),
508
            AnonSuggestions                       => "" . C4::Context->preference("AnonSuggestions"),
507
            AuthorisedValueImages                 => C4::Context->preference("AuthorisedValueImages"),
509
            AuthorisedValueImages                 => C4::Context->preference("AuthorisedValueImages"),
508
            BranchesLoop                          => GetBranchesLoop($opac_name),
510
            BranchesLoop                          => GetBranchesLoop($opac_name),
509
            BranchCategoriesLoop                  => GetBranchCategories( 'searchdomain', 1, $opac_name ),
511
            BranchCategoriesLoop                  => $library_categories,
512
            opac_name                             => $opac_name,
510
            LibraryName                           => "" . C4::Context->preference("LibraryName"),
513
            LibraryName                           => "" . C4::Context->preference("LibraryName"),
511
            LibraryNameTitle                      => "" . $LibraryNameTitle,
514
            LibraryNameTitle                      => "" . $LibraryNameTitle,
512
            LoginBranchname                       => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "",
515
            LoginBranchname                       => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "",
(-)a/C4/Branch.pm (-46 / +4 lines)
Lines 20-25 use strict; Link Here
20
#use warnings; FIXME - Bug 2505
20
#use warnings; FIXME - Bug 2505
21
require Exporter;
21
require Exporter;
22
use C4::Context;
22
use C4::Context;
23
use Koha::LibraryCategories;
23
24
24
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
25
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
25
26
Lines 37-43 BEGIN { Link Here
37
		&ModBranch
38
		&ModBranch
38
		&GetBranchInfo
39
		&GetBranchInfo
39
		&GetCategoryTypes
40
		&GetCategoryTypes
40
		&GetBranchCategories
41
		&GetBranchesInCategory
41
		&GetBranchesInCategory
42
		&ModBranchCategoryInfo
42
		&ModBranchCategoryInfo
43
		&mybranch
43
		&mybranch
Lines 243-251 sub ModBranch { Link Here
243
    }
243
    }
244
    # sort out the categories....
244
    # sort out the categories....
245
    my @checkedcats;
245
    my @checkedcats;
246
    my $cats = GetBranchCategories();
246
    my @cats = Koha::LibraryCategories->search;
247
    foreach my $cat (@$cats) {
247
    foreach my $cat (@cats) {
248
        my $code = $cat->{'categorycode'};
248
        my $code = $cat->categorycode;
249
        if ( $data->{$code} ) {
249
        if ( $data->{$code} ) {
250
            push( @checkedcats, $code );
250
            push( @checkedcats, $code );
251
        }
251
        }
Lines 283-330 sub ModBranch { Link Here
283
    }
283
    }
284
}
284
}
285
285
286
=head2 GetBranchCategories
287
288
  my $categories = GetBranchCategories($categorytype,$show_in_pulldown,$selected_in_pulldown);
289
290
Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
291
i.e. categorydescription, categorytype, categoryname.
292
293
=cut
294
295
sub GetBranchCategories {
296
    my ( $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_;
297
    my $dbh = C4::Context->dbh();
298
299
    my $query = "SELECT * FROM branchcategories ";
300
301
    my ( @where, @bind );
302
    if ( $categorytype ) {
303
        push @where, " categorytype = ? ";
304
        push @bind, $categorytype;
305
    }
306
307
    if ( defined( $show_in_pulldown ) ) {
308
        push( @where, " show_in_pulldown = ? " );
309
        push( @bind, $show_in_pulldown );
310
    }
311
312
    $query .= " WHERE " . join(" AND ", @where) if(@where);
313
    $query .= " ORDER BY categorytype, categorycode";
314
    my $sth=$dbh->prepare( $query);
315
    $sth->execute(@bind);
316
317
    my $branchcats = $sth->fetchall_arrayref({});
318
319
    if ( $selected_in_pulldown ) {
320
        foreach my $bc ( @$branchcats ) {
321
            $bc->{selected} = 1 if $bc->{categorycode} eq $selected_in_pulldown;
322
        }
323
    }
324
325
    return $branchcats;
326
}
327
328
=head2 GetCategoryTypes
286
=head2 GetCategoryTypes
329
287
330
$categorytypes = GetCategoryTypes;
288
$categorytypes = GetCategoryTypes;
(-)a/catalogue/search.pl (-1 / +2 lines)
Lines 152-157 use POSIX qw(ceil floor); Link Here
152
use C4::Branch; # GetBranches
152
use C4::Branch; # GetBranches
153
use C4::Search::History;
153
use C4::Search::History;
154
154
155
use Koha::LibraryCategories;
155
use Koha::Virtualshelves;
156
use Koha::Virtualshelves;
156
157
157
use URI::Escape;
158
use URI::Escape;
Lines 244-250 my @branch_loop = map { Link Here
244
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
245
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
245
} keys %$branches;
246
} keys %$branches;
246
247
247
my $categories = GetBranchCategories('searchdomain');
248
my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
248
249
249
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
250
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
250
251
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc (-1 / +1 lines)
Lines 234-240 Link Here
234
                                                </optgroup>
234
                                                </optgroup>
235
                                                <optgroup label="Groups">
235
                                                <optgroup label="Groups">
236
                                                    [% FOREACH bc IN BranchCategoriesLoop %]
236
                                                    [% FOREACH bc IN BranchCategoriesLoop %]
237
                                                        [% IF ( bc.selected ) %]
237
                                                        [% IF bc.categorycode == opac_name %]
238
                                                            <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
238
                                                            <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
239
                                                        [% ELSE %]
239
                                                        [% ELSE %]
240
                                                            <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
240
                                                            <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
(-)a/opac/opac-search.pl (-3 / +4 lines)
Lines 43-48 use C4::SocialData; Link Here
43
use C4::Ratings;
43
use C4::Ratings;
44
use C4::External::OverDrive;
44
use C4::External::OverDrive;
45
45
46
use Koha::LibraryCategories;
47
46
use POSIX qw(ceil floor strftime);
48
use POSIX qw(ceil floor strftime);
47
use URI::Escape;
49
use URI::Escape;
48
use JSON qw/decode_json encode_json/;
50
use JSON qw/decode_json encode_json/;
Lines 201-209 if ($cgi->cookie("search_path_code")) { Link Here
201
}
203
}
202
204
203
my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
205
my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
204
$template->param(
206
my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
205
    searchdomainloop => GetBranchCategories('searchdomain'),
207
$template->param( searchdomainloop => $library_categories );
206
);
207
208
208
# load the language limits (for search)
209
# load the language limits (for search)
209
my $languages_limit_loop = getLanguages($lang, 1);
210
my $languages_limit_loop = getLanguages($lang, 1);
(-)a/t/db_dependent/Branch.t (-15 / +6 lines)
Lines 21-27 use Modern::Perl; Link Here
21
use C4::Context;
21
use C4::Context;
22
use Data::Dumper;
22
use Data::Dumper;
23
23
24
use Test::More tests => 26;
24
use Test::More tests => 24;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
use Koha::Libraries;
27
use Koha::Libraries;
Lines 43-49 can_ok( Link Here
43
      ModBranch
43
      ModBranch
44
      GetBranchInfo
44
      GetBranchInfo
45
      GetCategoryTypes
45
      GetCategoryTypes
46
      GetBranchCategories
47
      GetBranchesInCategory
46
      GetBranchesInCategory
48
      ModBranchCategoryInfo
47
      ModBranchCategoryInfo
49
      mybranch
48
      mybranch
Lines 165-172 $b1->{issuing} = undef; Link Here
165
is_deeply( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA");
164
is_deeply( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA");
166
165
167
#Test categories
166
#Test categories
168
my $categories = GetBranchCategories();
167
my $count_cat  = Koha::LibraryCategories->search->count;
169
my $count_cat  = scalar( @$categories );
170
168
171
my $cat1 = {
169
my $cat1 = {
172
    add              => 1,
170
    add              => 1,
Lines 201-218 ModBranchCategoryInfo({ Link Here
201
ModBranchCategoryInfo($cat1);
199
ModBranchCategoryInfo($cat1);
202
ModBranchCategoryInfo($cat2);
200
ModBranchCategoryInfo($cat2);
203
201
204
$categories = GetBranchCategories();
202
my $categories = Koha::LibraryCategories->search;
205
is( scalar( @$categories ), $count_cat + 3, "Two categories added" );
203
is( $categories->count, $count_cat + 3, "Two categories added" );
206
delete $cat1->{add};
204
delete $cat1->{add};
207
delete $cat2->{add};
205
delete $cat2->{add};
208
delete $new_category{add};
206
delete $new_category{add};
209
is_deeply($categories, [ $cat1,$cat2,\%new_category ], 'retrieve all expected library categories (bug 10515)');
210
207
211
my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete;
208
my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete;
212
is( $del, 1, 'One row affected' );
209
is( $del, 1, 'One row affected' );
213
210
214
$categories = GetBranchCategories();
211
is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
215
is( scalar( @$categories ), $count_cat + 2, "Category  CAT2 deleted" );
216
212
217
$b2->{CAT1} = 1;
213
$b2->{CAT1} = 1;
218
ModBranch($b2);
214
ModBranch($b2);
Lines 232-239 $b2->{categories} = \@cat; Link Here
232
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
228
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
233
229
234
ModBranchCategoryInfo({add => 1,%$cat2});
230
ModBranchCategoryInfo({add => 1,%$cat2});
235
$categories = GetBranchCategories();
231
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two catgories added" );
236
is( scalar( @$categories ), $count_cat + 3, "Two categories added" );
237
$b2 = {
232
$b2 = {
238
    branchcode     => 'BRB',
233
    branchcode     => 'BRB',
239
    branchname     => 'BranchB',
234
    branchname     => 'BranchB',
Lines 302-310 is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' ); Link Here
302
my @category_types = GetCategoryTypes();
297
my @category_types = GetCategoryTypes();
303
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
298
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
304
299
305
$categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
306
is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
307
308
#TODO later: test mybranchine and onlymine
300
#TODO later: test mybranchine and onlymine
309
# Actually we cannot mock C4::Context->userenv in unit tests
301
# Actually we cannot mock C4::Context->userenv in unit tests
310
302
311
- 

Return to bug 15295