Bug 5791 - Robust handling of deleted/non-existent biblios and authority records
[koha.git] / C4 / Category.pm
1 package C4::Category;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use warnings;
20 use C4::Context;
21
22 our $AUTOLOAD;
23
24
25
26
27 =head1 NAME
28
29 C4::Category - objects from the categories table
30
31 =head1 SYNOPSIS
32
33     use C4::Category;
34     my @categories = C4::Category->all;
35     print join("\n", map { $_->description } @categories), "\n";
36
37 =head1 DESCRIPTION
38
39 Objects of this class represent a row in the C<categories> table.
40
41 Currently, the bare minimum for using this as a read-only data source has
42 been implemented.  The API was designed to make it easy to transition to
43 an ORM later on.
44
45 =head1 API
46
47 =head2 Class Methods
48
49 =cut
50
51 =head3 C4::Category->new(\%opts)
52
53 Given a hashref, a new (in-memory) C4::Category object will be instantiated.
54 The database is not touched.
55
56 =cut
57
58 sub new {
59     my ($class, $opts) = @_;
60     bless $opts => $class;
61 }
62
63
64
65
66 =head3 C4::Category->all
67
68 This returns all the categories as objects.  By default they're ordered by
69 C<description>.
70
71 =cut
72
73 sub all {
74     my ($class) = @_;
75     my $dbh = C4::Context->dbh;
76     return    map { $class->new($_) }    @{$dbh->selectall_arrayref(
77         # The categories table is small enough for
78         # `SELECT *` to be harmless.
79         "SELECT * FROM categories ORDER BY description",
80         { Slice => {} },
81     )};
82 }
83
84
85
86
87 =head2 Object Methods
88
89 These are read-only accessors for attributes of a C4::Category object.
90
91 =head3 $category->categorycode
92
93 =cut
94
95 =head3 $category->description
96
97 =cut
98
99 =head3 $category->enrolmentperiod
100
101 =cut
102
103 =head3 $category->upperagelimit
104
105 =cut
106
107 =head3 $category->dateofbirthrequired
108
109 =cut
110
111 =head3 $category->finetype
112
113 =cut
114
115 =head3 $category->bulk
116
117 =cut
118
119 =head3 $category->enrolmentfee
120
121 =cut
122
123 =head3 $category->overduenoticerequired
124
125 =cut
126
127 =head3 $category->issuelimit
128
129 =cut
130
131 =head3 $category->reservefee
132
133 =cut
134
135 =head3 $category->category_type
136
137 =cut
138
139 sub AUTOLOAD {
140     my $self = shift;
141     my $attr = $AUTOLOAD;
142     $attr =~ s/.*://;
143     if (exists $self->{$attr}) {
144         return $self->{$attr};
145     } else {
146         return undef;
147     }
148 }
149
150 sub DESTROY { }
151
152
153
154
155 =head1 SEE ALSO
156
157 The following modules make reference to the C<categories> table.
158
159 L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
160
161
162 =head1 AUTHOR
163
164 John Beppu <john.beppu@liblime.com>
165
166 =cut
167
168 1;