From fd591d84d957284d3d77daf3f4de11106ddca2e1 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 16 Jul 2015 07:56:18 -0400
Subject: [PATCH] Bug 8483 - Add record and item related classes

Signed-off-by: Heather Braum <hbraum@nekls.org>
---
 Koha/BiblioItem.pm          | 52 ++++++++++++++++++++++++++++++++++++
 Koha/BiblioItems.pm         | 58 ++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/Biblio.pm      | 57 ++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/BiblioItem.pm  | 57 ++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/BiblioItems.pm | 63 ++++++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/Biblios.pm     | 64 +++++++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/Item.pm        | 58 ++++++++++++++++++++++++++++++++++++++++
 Koha/Deleted/Items.pm       | 63 ++++++++++++++++++++++++++++++++++++++++++++
 Koha/Item.pm                | 48 ++++++++++++++++++++++++++++++++++
 9 files changed, 520 insertions(+)
 create mode 100644 Koha/BiblioItem.pm
 create mode 100644 Koha/BiblioItems.pm
 create mode 100644 Koha/Deleted/Biblio.pm
 create mode 100644 Koha/Deleted/BiblioItem.pm
 create mode 100644 Koha/Deleted/BiblioItems.pm
 create mode 100644 Koha/Deleted/Biblios.pm
 create mode 100644 Koha/Deleted/Item.pm
 create mode 100644 Koha/Deleted/Items.pm

diff --git a/Koha/BiblioItem.pm b/Koha/BiblioItem.pm
new file mode 100644
index 0000000..19c6525
--- /dev/null
+++ b/Koha/BiblioItem.pm
@@ -0,0 +1,52 @@
+package Koha::BiblioItem;
+
+# Copyright ByWater Solutions 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);
+
+=head1 NAME
+
+Koha::BiblioItem - Koha BiblioItem Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Biblioitem';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/BiblioItems.pm b/Koha/BiblioItems.pm
new file mode 100644
index 0000000..76f2023
--- /dev/null
+++ b/Koha/BiblioItems.pm
@@ -0,0 +1,58 @@
+package Koha::BiblioItems;
+
+# Copyright ByWater Solutions 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::BiblioItem;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::BiblioItem - Koha BiblioItem Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Biblioitem';
+}
+
+sub object_class {
+    return 'Koha::BiblioItem';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/Biblio.pm b/Koha/Deleted/Biblio.pm
new file mode 100644
index 0000000..86b64f2
--- /dev/null
+++ b/Koha/Deleted/Biblio.pm
@@ -0,0 +1,57 @@
+package Koha::Deleted::Biblio;
+
+# Copyright ByWater Solutions 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::Biblio);
+
+=head1 NAME
+
+Koha::Deleted::Biblio - Koha Biblio Object class
+
+This class is an extension of Koha::Biblio.
+
+New methods should only be added to Koha::Biblio unless they are specifically
+and only for dealing with deleted bibs.
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deletedbiblio';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/BiblioItem.pm b/Koha/Deleted/BiblioItem.pm
new file mode 100644
index 0000000..ca4a43b
--- /dev/null
+++ b/Koha/Deleted/BiblioItem.pm
@@ -0,0 +1,57 @@
+package Koha::Deleted::BiblioItem;
+
+# Copyright ByWater Solutions 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::BiblioItem);
+
+=head1 NAME
+
+Koha::Deleted::BiblioItem - Koha Deleted BiblioItem Object class
+
+This class is an extension of Koha::BiblioItem.
+
+New methods should only be added to Koha::BiblioItem unless they are specifically
+and only for dealing with deleted biblioitems.
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deletedbiblioitem';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/BiblioItems.pm b/Koha/Deleted/BiblioItems.pm
new file mode 100644
index 0000000..084af5a
--- /dev/null
+++ b/Koha/Deleted/BiblioItems.pm
@@ -0,0 +1,63 @@
+package Koha::Deleted::BiblioItems;
+
+# Copyright ByWater Solutions 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::Deleted::BiblioItem;
+
+use base qw(Koha::BiblioItems);
+
+=head1 NAME
+
+Koha::BiblioItem - Koha BiblioItem Object class
+
+This class is an extension of Koha::BiblioItems.
+
+New methods should only be added to Koha::BiblioItems unless they are specifically
+and only for dealing with deleted biblioitem sets
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deletedbiblioitem';
+}
+
+sub object_class {
+    return 'Koha::Deleted::BiblioItem';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/Biblios.pm b/Koha/Deleted/Biblios.pm
new file mode 100644
index 0000000..7c15130
--- /dev/null
+++ b/Koha/Deleted/Biblios.pm
@@ -0,0 +1,64 @@
+package Koha::Deleted::Biblios;
+
+# Copyright ByWater Solutions 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::Deleted::Biblio;
+
+use base qw(Koha::Biblios);
+
+=head1 NAME
+
+Koha::Deleted::Biblios - Koha Deleted Bibliographic Record set object class
+
+This class is an extension of Koha::Biblios.
+
+New methods should only be added to Koha::Biblios unless they are specifically
+and only for dealing with deleted bib sets
+
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deletedbiblio';
+}
+
+sub object_class {
+    return 'Koha::Deleted::Biblio';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/Item.pm b/Koha/Deleted/Item.pm
new file mode 100644
index 0000000..77a0a2a
--- /dev/null
+++ b/Koha/Deleted/Item.pm
@@ -0,0 +1,58 @@
+package Koha::Deleted::Item;
+
+# Copyright ByWater Solutions 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::Item);
+
+=head1 NAME
+
+Koha::Deleted::Item - Koha Deleted Item Object class
+
+This class is an extension of Koha::Item.
+
+New methods should only be added to Koha::Item unless they are specifically
+and only for dealing with deleted items only.
+
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deleteditem';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Deleted/Items.pm b/Koha/Deleted/Items.pm
new file mode 100644
index 0000000..363c01b
--- /dev/null
+++ b/Koha/Deleted/Items.pm
@@ -0,0 +1,63 @@
+package Koha::Deleted::Items;
+
+# Copyright ByWater Solutions 2014
+#
+# 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::Deleted::Item;
+
+use base qw(Koha::Items);
+
+=head1 NAME
+
+Koha::Deleted::Items - Koha Deleted Items Object class
+
+This class is an extension of Koha::Items.
+
+New methods should only be added to Koha::Items unless they are specifically
+and only for dealing with deleted item sets
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub type {
+    return 'Deleteditem';
+}
+
+sub object_class {
+    return 'Koha::Deleted::Item';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Item.pm b/Koha/Item.pm
index d721537..14f9853 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -25,6 +25,10 @@ use Koha::Database;
 
 use Koha::Patrons;
 use Koha::Libraries;
+use Koha::Biblios;
+use Koha::Deleted::Biblios;
+use Koha::BiblioItems;
+use Koha::Deleted::BiblioItems;
 
 use base qw(Koha::Object);
 
@@ -107,6 +111,50 @@ sub last_returned_by {
     }
 }
 
+=head3 biblio
+
+my $biblio = $checkout->biblio({ deleted => 1 });
+
+Returns the related Koha::Biblio for this checkout.
+
+If the parameter delete is passed and true, and the biblionumber
+is not found for current biblios, this method will look for a matching
+deleted biblio.
+
+=cut
+
+sub biblio {
+    my ( $self, $params ) = @_;
+
+    my $biblio = Koha::Biblios->search( { biblionumber => $self->biblionumber() } )->next();
+
+    $biblio ||= Koha::Deleted::Biblios->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} );
+
+    return $biblio || undef;
+}
+
+=head3 biblioitem
+
+my $biblioitem = $checkout->biblio({ deleted => 1 });
+
+Returns the related Koha::Biblio for this checkout.
+
+If the parameter delete is passed and true, and the biblioitemnumber
+is not found for current biblioitems, this method will look for a matching
+deleted biblioitem.
+
+=cut
+
+sub biblioitem {
+    my ( $self, $params ) = @_;
+
+    my $biblioitem = Koha::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next();
+
+    $biblioitem ||= Koha::Deleted::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} );
+
+    return $biblioitem || undef;
+}
+
 =head3 type
 
 =cut
-- 
2.1.4