@@ -, +, @@ --- Koha/Serial/Serial.pm | 68 +++++++++++++++++++++++++++++++++++++++++++++++ Koha/Serial/SerialItem.pm | 62 ++++++++++++++++++++++++++++++++++++++++++ Koha/Serial/Serials.pm | 40 ++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 Koha/Serial/Serial.pm create mode 100644 Koha/Serial/SerialItem.pm create mode 100644 Koha/Serial/Serials.pm --- a/Koha/Serial/Serial.pm +++ a/Koha/Serial/Serial.pm @@ -0,0 +1,68 @@ +package Koha::Serial::Serial; + +# Copyright KohaSuomi 2015 +# +# 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. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +sub type { + return 'Serial'; +} + +sub item { + my ($self, $item) = @_; + + if ($item) { + $item = Koha::Items->cast($item); + $self->{item} = $item; + $self->set({item => $item->_result()->id}); + $self->store(); + } + + unless ($self->{item}) { + my $item = $self->_result()->serialitems()->itemnumber(); #itemnumber actually returns the Item-resultset :) + $self->{item} = Koha::Items->cast($item); + } + + return $self->{item}; +} + +sub subscription { + my ($self, $subscription) = @_; + + if ($subscription) { + $subscription = Koha::Serial::Subscriptions->cast($subscription); + $self->{subscription} = $subscription; + $self->set({subscription => $subscription->_result()->id}); + $self->store(); + } + + unless ($self->{subscription}) { + my $subscription = $self->_result()->subscription(); + $self->{subscription} = Koha::Serial::Subscriptions->cast($subscription); + } + + return $self->{subscription}; +} + +1; --- a/Koha/Serial/SerialItem.pm +++ a/Koha/Serial/SerialItem.pm @@ -0,0 +1,62 @@ +package Koha::Serial::SerialItem; + +# Copyright KohaSuomi 2015 +# +# 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. + +use Modern::Perl; +use Carp; + +use Koha::Database; +use Koha::Items; +use Koha::Serial::Serials; + +use Koha::Exception::BadParameter; + +=head SerialItem + +=head SYNOPSIS + +This class deals with displaying Serials, whether or not they have Items or not. + +=cut + +sub new { + my ($class, $serial, $item) = @_; + + my $self = {}; + bless($self, $class); + + Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> You must give a Serial-object as a parameter!") + unless $serial; + $self->{serial} = Koha::Serial::Serials->cast($serial) if $serial; + $item = $serial->_result->serialitems->itemnumber unless $item; + $self->{item} = Koha::Items->cast($item) if $item; + + return $self; +} + +#sub getItem { +# my ($self) = @_; +# return $self->{item}; +#} + +#sub getSerial { +# my ($self) = @_; +# return $self->{serial}; +#} + +1; --- a/Koha/Serial/Serials.pm +++ a/Koha/Serial/Serials.pm @@ -0,0 +1,40 @@ +package Koha::Serial::Serials; + +# Copyright KohaSuomi 2015 +# +# 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. + +use Modern::Perl; + +use Carp; + +use Koha::Serial::Serial; + +use base qw(Koha::Objects); + +sub type { + return 'Serial'; +} + +sub object_class { + return 'Koha::Serial::Serial'; +} + +sub _get_castable_unique_columns { + return ['serialid']; +} + +1; --