Bug 15758: Koha::Libraries - Remove GetBranches
[koha.git] / C4 / Branch.pm
1 package C4::Branch;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19 use strict;
20 #use warnings; FIXME - Bug 2505
21 require Exporter;
22 use C4::Context;
23 use Koha::LibraryCategories;
24
25 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
26
27 BEGIN {
28         @ISA    = qw(Exporter);
29         @EXPORT = qw(
30                 &GetBranch
31         );
32     @EXPORT_OK = qw( &onlymine );
33 }
34
35 =head1 NAME
36
37 C4::Branch - Koha branch module
38
39 =head1 SYNOPSIS
40
41 use C4::Branch;
42
43 =head1 DESCRIPTION
44
45 The functions in this module deal with branches.
46
47 =head1 FUNCTIONS
48
49 =cut
50
51 sub onlymine {
52     return
53          C4::Context->preference('IndependentBranches')
54       && C4::Context->userenv
55       && !C4::Context->IsSuperLibrarian()
56       && C4::Context->userenv->{branch};
57 }
58
59 =head2 GetBranch
60
61 $branch = GetBranch( $query, $branches );
62
63 =cut
64
65 sub GetBranch {
66     my ( $query, $branches ) = @_;    # get branch for this query from branches
67     my $branch = $query->param('branch');
68     my %cookie = $query->cookie('userenv');
69     ($branch)                || ($branch = $cookie{'branchname'});
70     ( $branches->{$branch} ) || ( $branch = ( keys %$branches )[0] );
71     return $branch;
72 }
73
74 1;
75 __END__
76
77 =head1 AUTHOR
78
79 Koha Development Team <http://koha-community.org/>
80
81 =cut