Bug 11897: Stockrotation
[koha-equinox.git] / Koha / Library.pm
1 package Koha::Library;
2
3 # Copyright 2015 Koha Development team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use C4::Context;
25
26 use Koha::Database;
27 use Koha::StockRotationStages;
28
29 use base qw(Koha::Object);
30
31 =head1 NAME
32
33 Koha::Library - Koha Library Object class
34
35 =head1 API
36
37 =head2 Class methods
38
39 =head3 get_categories
40
41 TODO: Ask the author to add a proper description
42
43 =cut
44
45 sub get_categories {
46     my ( $self, $params ) = @_;
47     # TODO This should return Koha::LibraryCategories
48     return $self->{_result}->categorycodes( $params );
49 }
50
51 =head3 update_categories
52
53 TODO: Ask the author to add a proper description
54
55 =cut
56
57 sub update_categories {
58     my ( $self, $categories ) = @_;
59     $self->_result->delete_related( 'branchrelations' );
60     $self->add_to_categories( $categories );
61 }
62
63 =head3 add_to_categories
64
65 TODO: Ask the author to add a proper description
66
67 =cut
68
69 sub add_to_categories {
70     my ( $self, $categories ) = @_;
71     for my $category ( @$categories ) {
72         $self->_result->add_to_categorycodes( $category->_result );
73     }
74 }
75
76 =head3 stockrotationstages
77
78   my $stages = Koha::Library->stockrotationstages;
79
80 Returns the stockrotation stages associated with this Library.
81
82 =cut
83
84 sub stockrotationstages {
85     my ( $self ) = @_;
86     my $rs = $self->_result->stockrotationstages;
87     return Koha::StockRotationStages->_new_from_dbic( $rs );
88 }
89
90 =head3 get_effective_marcorgcode
91
92     my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
93
94 Returns the effective MARC organization code of the library. It falls back to the value
95 from the I<MARCOrgCode> syspref if undefined for the library.
96
97 =cut
98
99 sub get_effective_marcorgcode {
100     my ( $self )  = @_;
101
102     return $self->marcorgcode || C4::Context->preference("MARCOrgCode");
103 }
104
105 =head3 library_groups
106
107 Return the Library groups of this library
108
109 =cut
110
111 sub library_groups {
112     my ( $self ) = @_;
113     my $rs = $self->_result->library_groups;
114     return Koha::Library::Groups->_new_from_dbic( $rs );
115 }
116
117 =head2 Internal methods
118
119 =head3 _type
120
121 =cut
122
123 sub _type {
124     return 'Branch';
125 }
126
127 1;