From 93f622cfb9904d748a8cb84c0e2a8edc63bc17f7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 25 Oct 2022 13:07:44 +0100 Subject: [PATCH] Bug 31028: Add new Koha::Object(s) classes This patch adds new Koha::Object(s) for the newly introduced tables, including updateing existing Koha::Objects adding new relations as required. --- Koha/Biblio.pm | 15 ++++++ Koha/Ticket.pm | 111 +++++++++++++++++++++++++++++++++++++++++ Koha/Ticket/Update.pm | 68 +++++++++++++++++++++++++ Koha/Ticket/Updates.pm | 48 ++++++++++++++++++ Koha/Tickets.pm | 49 ++++++++++++++++++ 5 files changed, 291 insertions(+) create mode 100644 Koha/Ticket.pm create mode 100644 Koha/Ticket/Update.pm create mode 100644 Koha/Ticket/Updates.pm create mode 100644 Koha/Tickets.pm diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 3c8e5cb4b2..21aa502657 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -48,6 +48,7 @@ use Koha::Subscriptions; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; +use Koha::Tickets; =head1 NAME @@ -119,6 +120,20 @@ sub active_orders { return $self->orders->search({ datecancellationprinted => undef }); } +=head3 tickets + + my $tickets = $biblio->tickets(); + +Returns all tickets linked to the biblio + +=cut + +sub tickets { + my ( $self ) = @_; + my $rs = $self->_result->tickets; + return Koha::Tickets->_new_from_dbic( $rs ); +} + =head3 item_groups my $item_groups = $biblio->item_groups(); diff --git a/Koha/Ticket.pm b/Koha/Ticket.pm new file mode 100644 index 0000000000..2435d31e38 --- /dev/null +++ b/Koha/Ticket.pm @@ -0,0 +1,111 @@ +package Koha::Ticket; + +# 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 . + +use Modern::Perl; + +use base qw(Koha::Object); + +use Koha::Ticket::Update; +use Koha::Ticket::Updates; + +=head1 NAME + +Koha::Ticket - Koha Ticket Object class + +=head1 API + +=head2 Relations + +=cut + +=head3 reporter + +Return the patron who submitted this ticket + +=cut + +sub reporter { + my ($self) = @_; + my $rs = $self->_result->reporter; + return unless $rs; + return Koha::Patron->_new_from_dbic($rs); +} + +=head3 resolver + +Return the user who resolved this ticket + +=cut + +sub resolver { + my ($self) = @_; + my $rs = $self->_result->resolver; + return unless $rs; + return Koha::Patron->_new_from_dbic($rs) if $rs; +} + +=head3 biblio + +Return the biblio linked to this ticket + +=cut + +sub biblio { + my ($self) = @_; + my $rs = $self->_result->biblio; + return unless $rs; + return Koha::Biblio->_new_from_dbic($rs); +} + +=head3 updates + +Return any updates attached to this ticket + +=cut + +sub updates { + my ($self) = @_; + my $rs = $self->_result->ticket_updates; + return unless $rs; + return Koha::Ticket::Updates->_new_from_dbic($rs) if $rs; +} + +=head2 Actions + +=head3 add_update + +=cut + +sub add_update { + my ( $self, $params ) = @_; + + my $rs = $self->_result->add_to_ticket_updates($params)->discard_changes; + + return Koha::Ticket::Updates->_new_from_dbic($rs); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'Ticket'; +} + +1; diff --git a/Koha/Ticket/Update.pm b/Koha/Ticket/Update.pm new file mode 100644 index 0000000000..b954d59f03 --- /dev/null +++ b/Koha/Ticket/Update.pm @@ -0,0 +1,68 @@ +package Koha::Ticket::Update; + +# 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 . + +use Modern::Perl; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Ticket::Update - Koha Ticket Update Object class + +=head1 API + +=head2 Relations + +=cut + +=head3 ticket + +Return the ticket this update relates to + +=cut + +sub ticket { + my ($self) = @_; + my $rs = $self->_result->ticket; + return unless $rs; + return Koha::Ticket->_new_from_dbic($rs); +} + +=head3 user + +Return the patron who submitted this update + +=cut + +sub user { + my ($self) = @_; + my $rs = $self->_result->user; + return unless $rs; + return Koha::Patron->_new_from_dbic($rs); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'TicketUpdate'; +} + +1; diff --git a/Koha/Ticket/Updates.pm b/Koha/Ticket/Updates.pm new file mode 100644 index 0000000000..d3e7433e76 --- /dev/null +++ b/Koha/Ticket/Updates.pm @@ -0,0 +1,48 @@ +package Koha::Ticket::Updates; + +# 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 . + +use Modern::Perl; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Ticket::Updates - Koha Ticket Update Objects class + +=head1 API + +=head2 Internal methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'TicketUpdate'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Ticket::Update'; +} + +1; diff --git a/Koha/Tickets.pm b/Koha/Tickets.pm new file mode 100644 index 0000000000..69fc4fb3a0 --- /dev/null +++ b/Koha/Tickets.pm @@ -0,0 +1,49 @@ +package Koha::Tickets; + +# 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 . + +use Modern::Perl; + + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Tickets - Koha Ticket Objects class + +=head1 API + +=head2 Internal methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'Ticket'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Ticket'; +} + +1; -- 2.20.1