From bce11d34518fe5ccdc72e34758c701d4eba958d6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 5 Oct 2015 11:54:59 +0100 Subject: [PATCH] Bug 12478: Remove Koha::ItemType[s] Class::Accessor classes --- Koha/ItemType.pm | 70 --------------------------------- Koha/ItemTypes.pm | 113 ------------------------------------------------------ 2 files changed, 183 deletions(-) delete mode 100644 Koha/ItemType.pm delete mode 100644 Koha/ItemTypes.pm diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm deleted file mode 100644 index f2bfd6f..0000000 --- a/Koha/ItemType.pm +++ /dev/null @@ -1,70 +0,0 @@ -package Koha::ItemType; - -# This represents a single itemtype - -# Copyright 2014 Catalyst IT -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -=head1 NAME - -Koha::ItemType - represents a single itemtype - -=head1 DESCRIPTION - -This contains the data relating to a single itemtype - -=head1 SYNOPSIS - - use Koha::ItemTypes; - my $types = Koha::ItemTypes->new(); - my $type = $types->get_itemtype('CODE'); - print $type->code, $type->description, $type->rentalcharge, - $type->imageurl, $type->summary, $type->checkinmsg, - $type->checkinmsgtype; - -Creating an instance of C without using L -can be done simply by passing a hashref containing the values to C. -Note when doing this that a value for C will become a value for -C. - -=head1 FUNCTIONS - -In addition to the read-only accessors mentioned above, the following functions -exist. - -=cut - -use Modern::Perl; - -use base qw(Class::Accessor); - -# TODO can we make these auto-generate from the input hash so it doesn't -# have to be updated when the database is? -__PACKAGE__->mk_ro_accessors( - qw(code description rentalcharge imageurl - summary checkinmsg checkinmsgtype) -); - -sub new { - my $class = shift @_; - - my %data = ( %{ $_[0] }, code => $_[0]->{itemtype} ); - my $self = $class->SUPER::new( \%data ); - return $self; -} - -1; diff --git a/Koha/ItemTypes.pm b/Koha/ItemTypes.pm deleted file mode 100644 index 9cf0b37..0000000 --- a/Koha/ItemTypes.pm +++ /dev/null @@ -1,113 +0,0 @@ -package Koha::ItemTypes; - -# This contains the item types that the system knows about. - -# Copyright 2014 Catalyst IT -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -=head1 NAME - -Koha::ItemTypes - handles the item types that Koha knows about - -=head1 DESCRIPTION - -This contains functions to access the item types. - -Note that any changes that happen to the database while this object is live -may not be reflected, so best don't hold onto it for a long time - -=cut - -use Koha::Database; -use Koha::ItemType; -use Modern::Perl; - -use Data::Dumper; # TODO remove -use base qw(Class::Accessor); - -__PACKAGE__->mk_accessors(qw()); - -=head1 FUNCTIONS - -=head2 new - - my $itypes = Koha::ItemTypes->new(); - -Creates a new instance of the object. - -=cut - -# Handled by Class::Accessor - -=head2 get_itemtype - - my @itype = $itypes->get_itemtype('CODE1', 'CODE2'); - -This returns a L object for each of the provided codes. For -any that don't exist, an C is returned. - -=cut - -sub get_itemtype { - my ($self, @codes) = @_; - - my $schema = Koha::Database->new()->schema(); - my @res; - - foreach my $c (@codes) { - if (exists $self->{cached}{$c}) { - push @res, $self->{cached}{$c}; - next; - } - my $rs = $schema->resultset('Itemtype')->search( { itemtype => $c } ); - my $r = $rs->next; - if (!$r) { - push @res, undef; - next; - } - my %data = $r->get_inflated_columns; - my $it = Koha::ItemType->new(\%data); - push @res, $it; - $self->{cached}{$c} = $it; - } - if (wantarray) { - return @res; - } else { - return @res ? $res[0] : undef; - } -} - -=head2 get_description_for_code - - my $desc = $itypes->get_description_for_code($code); - -This returns the description for an itemtype code. As a special case, if -there is no itemtype for this code, it'll return what it was given. - -It is mostly as a convenience function rather than using L. - -=cut - -sub get_description_for_code { - my ($self, $code) = @_; - - my $itype = $self->get_itemtype($code); - return $code if !$itype; - return $itype->description; -} - -1; -- 2.1.0