From fb6f37781b4411aac8a58ab85f483dbc0d591a35 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 11 Apr 2023 23:01:02 +0200
Subject: [PATCH] Bug 33105: Add Koha object classes
Content-Type: text/plain; charset=utf-8

Signed-off-by: Jonathan Field <jonathan.fieeld@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 Koha/Acquisition/Bookseller.pm        | 12 +++++
 Koha/Acquisition/Bookseller/Issue.pm  | 77 +++++++++++++++++++++++++++
 Koha/Acquisition/Bookseller/Issues.pm | 49 +++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 Koha/Acquisition/Bookseller/Issue.pm
 create mode 100644 Koha/Acquisition/Bookseller/Issues.pm

diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm
index 0ce6b9dd95..2fc1c0a95d 100644
--- a/Koha/Acquisition/Bookseller.pm
+++ b/Koha/Acquisition/Bookseller.pm
@@ -20,6 +20,7 @@ use Modern::Perl;
 use Koha::Acquisition::Bookseller::Aliases;
 use Koha::Acquisition::Bookseller::Contacts;
 use Koha::Acquisition::Bookseller::Interfaces;
+use Koha::Acquisition::Bookseller::Issues;
 use Koha::Subscriptions;
 
 use base qw( Koha::Object );
@@ -137,6 +138,17 @@ sub interfaces {
     return Koha::Acquisition::Bookseller::Interfaces->_new_from_dbic( $rs );
 }
 
+=head3 issues
+
+    my $issues = $vendor->issues
+
+=cut
+
+sub issues {
+    my ($self) = @_;
+    my $rs = $self->_result->aqbookseller_issues;
+    return Koha::Acquisition::Bookseller::Issues->_new_from_dbic( $rs );
+}
 
 =head3 to_api_mapping
 
diff --git a/Koha/Acquisition/Bookseller/Issue.pm b/Koha/Acquisition/Bookseller/Issue.pm
new file mode 100644
index 0000000000..40e19aad6e
--- /dev/null
+++ b/Koha/Acquisition/Bookseller/Issue.pm
@@ -0,0 +1,77 @@
+package Koha::Acquisition::Bookseller::Issue;
+
+# 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, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+
+use Koha::Database;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Acquisition::Bookseller::Issue - Koha Issue Object class
+
+=head1 API
+
+=head2 Class methods
+
+=head3 strings_map
+
+=cut
+
+sub strings_map {
+    my ( $self, $params ) = @_;
+
+    my $strings = {};
+
+    if ( defined $self->type ) {
+        my $type_av_category = 'VENDOR_ISSUE_TYPE';
+        my $av = Koha::AuthorisedValues->search(
+            {
+                category => $type_av_category,
+                authorised_value => $self->type,
+            }
+        );
+
+        my $type_str = $av->count
+          ? $params->{public}
+              ? $av->next->opac_description
+              : $av->next->lib
+          : $self->type;
+
+        $strings->{type} = {
+            category => 'VENDOR_ISSUE_TYPE',
+            str      => $type_str,
+            type     => 'av',
+        };
+    }
+
+    return $strings;
+}
+
+=head2 Internal methods
+
+=head3 _type
+
+=cut
+
+sub _type {
+    return 'AqbooksellerIssue';
+}
+
+1;
diff --git a/Koha/Acquisition/Bookseller/Issues.pm b/Koha/Acquisition/Bookseller/Issues.pm
new file mode 100644
index 0000000000..e797aba163
--- /dev/null
+++ b/Koha/Acquisition/Bookseller/Issues.pm
@@ -0,0 +1,49 @@
+package Koha::Acquisition::Bookseller::Issues;
+
+# 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, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+
+use Koha::Database;
+
+use Koha::Acquisition::Bookseller::Issue;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Acquisition::Bookseller::Issues
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub _type {
+    return 'AqbooksellerIssue';
+}
+
+sub object_class {
+    return 'Koha::Acquisition::Bookseller::Issue';
+}
+
+1;
-- 
2.30.2