Browse Source

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.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Helen Oliver <HOliver@tavi-port.ac.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
23.05.x
Martin Renvoize 2 years ago
committed by Tomas Cohen Arazi
parent
commit
f49861006f
  1. 15
      Koha/Biblio.pm
  2. 110
      Koha/Ticket.pm
  3. 68
      Koha/Ticket/Update.pm
  4. 48
      Koha/Ticket/Updates.pm
  5. 50
      Koha/Tickets.pm
  6. 30
      t/db_dependent/Koha/Biblio.t
  7. 147
      t/db_dependent/Koha/Ticket.t
  8. 74
      t/db_dependent/Koha/Ticket/Update.t

15
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();

110
Koha/Ticket.pm

@ -0,0 +1,110 @@
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 <http://www.gnu.org/licenses>.
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::Update->_new_from_dbic($rs);
}
=head2 Internal methods
=head3 _type
=cut
sub _type {
return 'Ticket';
}
1;

68
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 <http://www.gnu.org/licenses>.
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;

48
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 <http://www.gnu.org/licenses>.
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;

50
Koha/Tickets.pm

@ -0,0 +1,50 @@
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 <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Ticket;
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;

30
t/db_dependent/Koha/Biblio.t

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 22; # +1
use Test::More tests => 23; # +1
use Test::Warn;
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
@ -650,6 +650,34 @@ subtest 'orders() and active_orders() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'tickets() tests' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $biblio = $builder->build_sample_biblio();
my $tickets = $biblio->tickets;
is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
is( $tickets->count, 0, 'Koha::Biblio->tickets should return a count of 0 when there are no related tickets' );
# Add two tickets
foreach (1..2) {
$builder->build_object(
{
class => 'Koha::Tickets',
value => { biblio_id => $biblio->biblionumber }
}
);
}
$tickets = $biblio->tickets;
is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
is( $tickets->count, 2, 'Koha::Biblio->tickets should return the correct number of tickets' );
$schema->storage->txn_rollback;
};
subtest 'subscriptions() tests' => sub {
plan tests => 4;

147
t/db_dependent/Koha/Ticket.t

@ -0,0 +1,147 @@
#!/usr/bin/perl
# Copyright 2023 Koha Development team
#
# 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 Test::More tests => 5;
use t::lib::TestBuilder;
use Koha::Database;
my $builder = t::lib::TestBuilder->new;
my $schema = Koha::Database->new->schema;
subtest 'reporter() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $ticket = $builder->build_object(
{
class => 'Koha::Tickets',
value => {
reporter_id => $patron->id
}
}
);
my $reporter = $ticket->reporter;
is( ref($reporter), 'Koha::Patron', 'Koha::Ticket->reporter returns a Koha::Patron object' );
is( $reporter->id, $patron->id, 'Koha::Ticket->reporter returns the right Koha::Patron' );
$schema->storage->txn_rollback;
};
subtest 'resolver() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $ticket = $builder->build_object(
{
class => 'Koha::Tickets',
value => {
resolver_id => $patron->id
}
}
);
my $resolver = $ticket->resolver;
is( ref($resolver), 'Koha::Patron', 'Koha::Ticket->resolver returns a Koha::Patron object' );
is( $resolver->id, $patron->id, 'Koha::Ticket->resolver returns the right Koha::Patron' );
$schema->storage->txn_rollback;
};
subtest 'biblio() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
my $ticket = $builder->build_object(
{
class => 'Koha::Tickets',
value => {
biblio_id => $biblio->id
}
}
);
my $related_biblio = $ticket->biblio;
is( ref($related_biblio), 'Koha::Biblio', 'Koha::Ticket->biblio returns a Koha::Biblio object' );
is( $related_biblio->id, $biblio->id, 'Koha::Ticket->biblio returns the right Koha::Biblio' );
$schema->storage->txn_rollback;
};
subtest 'updates() tests' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $ticket = $builder->build_object( { class => 'Koha::Tickets' } );
my $updates = $ticket->updates;
is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' );
is( $updates->count, 0, 'Koha::Ticket->updates should return a count of 0 when there are no related updates' );
# Add two updates
foreach (1..2) {
$builder->build_object(
{
class => 'Koha::Ticket::Updates',
value => { ticket_id => $ticket->id }
}
);
}
$updates = $ticket->updates;
is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' );
is( $updates->count, 2, 'Koha::Ticket->updates should return the correct number of updates' );
$schema->storage->txn_rollback;
};
subtest 'add_update() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $ticket = $builder->build_object( { class => 'Koha::Tickets' } );
my $update = $ticket->add_update(
{ user_id => $patron->id, public => 1, message => "Some message" } );
is( ref($update), 'Koha::Ticket::Update',
'Koha::Ticket->add_update should return a Koha::Ticket::Update object'
);
my $updates = $ticket->updates;
is( $updates->count, 1,
'Koha::Ticket->add_update should have added 1 update linked to this ticket'
);
$schema->storage->txn_rollback;
};

74
t/db_dependent/Koha/Ticket/Update.t

@ -0,0 +1,74 @@
#!/usr/bin/perl
# Copyright 2023 Koha Development team
#
# 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 Test::More tests => 2;
use t::lib::TestBuilder;
use Koha::Database;
my $builder = t::lib::TestBuilder->new;
my $schema = Koha::Database->new->schema;
subtest 'ticket() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $ticket = $builder->build_object({ class => 'Koha::Tickets' });
my $update = $builder->build_object(
{
class => 'Koha::Ticket::Updates',
value => {
ticket_id => $ticket->id
}
}
);
my $linked_ticket = $update->ticket;
is( ref($linked_ticket), 'Koha::Ticket', 'Koha::Ticket::Update->ticket returns a Koha::Ticket object' );
is( $linked_ticket->id, $ticket->id, 'Koha::Ticket::Update->ticket returns the right Koha::Ticket' );
$schema->storage->txn_rollback;
};
subtest 'user() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $user = $builder->build_object({ class => 'Koha::Patrons' });
my $update = $builder->build_object(
{
class => 'Koha::Ticket::Updates',
value => {
user_id => $user->id
}
}
);
my $linked_user = $update->user;
is( ref($linked_user), 'Koha::Patron', 'Koha::Ticket::Update->user returns a Koha::Patron object' );
is( $linked_user->id, $user->id, 'Koha::Ticket::Update->user returns the right Koha::Patron' );
$schema->storage->txn_rollback;
};
Loading…
Cancel
Save