Bug 5685: (RM followup) opac.less and opac.css out of sync
[koha.git] / C4 / Category.pm
blob72ed42432e82c90dc7736b04d978a4b45e72d985
1 package C4::Category;
3 # Copyright 2009 Liblime
4 # Parts Copyright 2011 Tamil
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 use warnings;
23 use C4::Context;
25 our $AUTOLOAD;
30 =head1 NAME
32 C4::Category - objects from the categories table
34 =head1 SYNOPSIS
36 use C4::Category;
37 my @categories = C4::Category->all;
38 print join("\n", map { $_->description } @categories), "\n";
40 =head1 DESCRIPTION
42 Objects of this class represent a row in the C<categories> table.
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.
48 =head1 API
50 =head2 Class Methods
52 =cut
54 =head3 C4::Category->new(\%opts)
56 Given a hashref, a new (in-memory) C4::Category object will be instantiated.
57 The database is not touched.
59 =cut
61 sub new {
62 my ($class, $opts) = @_;
63 bless $opts => $class;
69 =head3 C4::Category->all
71 This returns all the categories as objects. By default they're ordered by
72 C<description>.
74 =cut
76 sub all {
77 my ( $class ) = @_;
78 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
79 my $dbh = C4::Context->dbh;
80 # The categories table is small enough for
81 # `SELECT *` to be harmless.
82 my $query = "SELECT categories.* FROM categories";
83 $query .= qq{
84 LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode
85 WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL
86 } if $branch_limit;
87 $query .= " ORDER BY description";
88 return map { $class->new($_) } @{
89 $dbh->selectall_arrayref(
90 $query,
91 { Slice => {} },
92 $branch_limit ? $branch_limit : ()
100 =head2 Object Methods
102 These are read-only accessors for attributes of a C4::Category object.
104 =head3 $category->categorycode
106 =cut
108 =head3 $category->description
110 =cut
112 =head3 $category->enrolmentperiod
114 =cut
116 =head3 $category->upperagelimit
118 =cut
120 =head3 $category->dateofbirthrequired
122 =cut
124 =head3 $category->finetype
126 =cut
128 =head3 $category->bulk
130 =cut
132 =head3 $category->enrolmentfee
134 =cut
136 =head3 $category->overduenoticerequired
138 =cut
140 =head3 $category->issuelimit
142 =cut
144 =head3 $category->reservefee
146 =cut
148 =head3 $category->category_type
150 =cut
152 sub AUTOLOAD {
153 my $self = shift;
154 my $attr = $AUTOLOAD;
155 $attr =~ s/.*://;
156 if (exists $self->{$attr}) {
157 return $self->{$attr};
158 } else {
159 return undef;
163 sub DESTROY { }
168 =head1 SEE ALSO
170 The following modules make reference to the C<categories> table.
172 L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
175 =head1 AUTHOR
177 John Beppu <john.beppu@liblime.com>
179 =cut