Bug 7821 - {langcode} will be replaced with current interface language
[koha.git] / C4 / Category.pm
blob85361286a762f079283bf2e15b08445ea15ea3d5
1 package C4::Category;
3 # This file is part of Koha.
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.
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.
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
18 use strict;
19 use warnings;
20 use C4::Context;
22 our $AUTOLOAD;
27 =head1 NAME
29 C4::Category - objects from the categories table
31 =head1 SYNOPSIS
33 use C4::Category;
34 my @categories = C4::Category->all;
35 print join("\n", map { $_->description } @categories), "\n";
37 =head1 DESCRIPTION
39 Objects of this class represent a row in the C<categories> table.
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.
45 =head1 API
47 =head2 Class Methods
49 =cut
51 =head3 C4::Category->new(\%opts)
53 Given a hashref, a new (in-memory) C4::Category object will be instantiated.
54 The database is not touched.
56 =cut
58 sub new {
59 my ($class, $opts) = @_;
60 bless $opts => $class;
66 =head3 C4::Category->all
68 This returns all the categories as objects. By default they're ordered by
69 C<description>.
71 =cut
73 sub all {
74 my $class = shift;
75 map {
76 utf8::encode($_->{description});
77 $class->new($_);
78 } @{C4::Context->dbh->selectall_arrayref(
79 "SELECT * FROM categories ORDER BY description", { Slice => {} }
80 )};
86 =head2 Object Methods
88 These are read-only accessors for attributes of a C4::Category object.
90 =head3 $category->categorycode
92 =cut
94 =head3 $category->description
96 =cut
98 =head3 $category->enrolmentperiod
100 =cut
102 =head3 $category->upperagelimit
104 =cut
106 =head3 $category->dateofbirthrequired
108 =cut
110 =head3 $category->finetype
112 =cut
114 =head3 $category->bulk
116 =cut
118 =head3 $category->enrolmentfee
120 =cut
122 =head3 $category->overduenoticerequired
124 =cut
126 =head3 $category->issuelimit
128 =cut
130 =head3 $category->reservefee
132 =cut
134 =head3 $category->category_type
136 =cut
138 sub AUTOLOAD {
139 my $self = shift;
140 my $attr = $AUTOLOAD;
141 $attr =~ s/.*://;
142 if (exists $self->{$attr}) {
143 return $self->{$attr};
144 } else {
145 return undef;
149 sub DESTROY { }
154 =head1 SEE ALSO
156 The following modules make reference to the C<categories> table.
158 L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
161 =head1 AUTHOR
163 John Beppu <john.beppu@liblime.com>
165 =cut