Browse Source
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
8 changed files with 541 additions and 1 deletions
@ -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; |
@ -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; |
@ -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; |
@ -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; |
@ -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; |
|||
}; |
@ -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…
Reference in new issue