@@ -, +, @@ them --- Koha/Item.pm | 22 ++++++++++++++--- Koha/TrackedLink.pm | 43 +++++++++++++++++++++++++++++++++ Koha/TrackedLinks.pm | 49 ++++++++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Item.t | 22 ++++++++++++++--- 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 Koha/TrackedLink.pm create mode 100644 Koha/TrackedLinks.pm --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -44,6 +44,7 @@ use Koha::Plugins; use Koha::Libraries; use Koha::StockRotationItem; use Koha::StockRotationRotas; +use Koha::TrackedLinks; use base qw(Koha::Object); @@ -1188,6 +1189,21 @@ sub orders { return Koha::Acquisition::Orders->_new_from_dbic($orders); } +=head3 tracked_links + + my $tracked_links = $item->tracked_links(); + +Returns a Koha::TrackedLinks object + +=cut + +sub tracked_links { + my ( $self ) = @_; + + my $tracked_links = $self->_result->linktrackers; + return Koha::TrackedLinks->_new_from_dbic($tracked_links); +} + =head3 move_to_biblio $item->move_to_biblio($to_biblio[, $params]); @@ -1254,9 +1270,9 @@ sub move_to_biblio { } ); - # linktrackers (there's no Koha object set available yet) - my $linktrackers = $self->_result->linktrackers; - $linktrackers->update_all({ biblionumber => $to_biblionumber }); + # tracked_links + my $tracked_links = $self->tracked_links; + $tracked_links->update({ biblionumber => $to_biblionumber }); return $to_biblionumber; } --- a/Koha/TrackedLink.pm +++ a/Koha/TrackedLink.pm @@ -0,0 +1,43 @@ +package Koha::TrackedLink; + +# 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 Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::TrackedLink - Koha TrackedLink Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'Linktracker'; +} + +1; --- a/Koha/TrackedLinks.pm +++ a/Koha/TrackedLinks.pm @@ -0,0 +1,49 @@ +package Koha::TrackedLinks; + +# 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 Koha::Database; + +use Koha::TrackedLink; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::TrackedLinks - Koha TrackedLink Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'Linktracker'; +} + +sub object_class { + return 'Koha::TrackedLink'; +} + +1; --- a/t/db_dependent/Koha/Item.t +++ a/t/db_dependent/Koha/Item.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use Test::Exception; use C4::Biblio qw( GetMarcSubfieldStructure ); @@ -38,6 +38,22 @@ use t::lib::Mocks; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +subtest 'tracked_links relationship' => sub { + plan tests => 3; + + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + }); + my $tracked_links = $item->tracked_links; + is( ref($tracked_links), 'Koha::TrackedLinks', 'tracked_links returns a Koha::TrackedLinks object set' ); + is($item->tracked_links->count, 0, "Empty Koha::TrackedLinks set returned if no tracked_links"); + my $link1 = $builder->build({ source => 'Linktracker', value => { itemnumber => $item->itemnumber }}); + my $link2 = $builder->build({ source => 'Linktracker', value => { itemnumber => $item->itemnumber }}); + + is($item->tracked_links()->count,2,"Two tracked links found"); +}; + subtest 'hidden_in_opac() tests' => sub { plan tests => 4; @@ -1034,8 +1050,8 @@ subtest 'move_to_biblio() tests' => sub { my $get_linktracker1 = $schema->resultset('Linktracker')->search({ itemnumber => $linktracker1->{itemnumber} })->single; my $get_linktracker2 = $schema->resultset('Linktracker')->search({ itemnumber => $linktracker2->{itemnumber} })->single; - is($get_linktracker1->biblionumber, $target_biblionumber, 'move_to_biblio moves linktracker for item 1'); - is($get_linktracker2->biblionumber, $source_biblionumber, 'move_to_biblio does not move linktracker for item 2'); + is($get_linktracker1->biblionumber->biblionumber, $target_biblionumber, 'move_to_biblio moves linktracker for item 1'); + is($get_linktracker2->biblionumber->biblionumber, $source_biblionumber, 'move_to_biblio does not move linktracker for item 2'); $schema->storage->txn_rollback; }; --