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