Bug 24419: Add Koha::Suggestion->suggester accessor
This patch adds a ->suggester accessor to the Koha::Suggestion class. It will return undef if no suggester, and a Koha::Patron object otherwise. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Suggestion.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
000cf4eba3
commit
d0446c835c
|
|
@ -443,6 +443,18 @@ __PACKAGE__->belongs_to(
|
|||
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UsG/gxLa0HMMbcpbscV29Q
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
"suggester",
|
||||
"Koha::Schema::Result::Borrower",
|
||||
{ "foreign.borrowernumber" => "self.suggestedby" },
|
||||
{
|
||||
is_deferrable => 1,
|
||||
join_type => "LEFT",
|
||||
on_delete => "SET NULL",
|
||||
on_update => "CASCADE",
|
||||
},
|
||||
);
|
||||
|
||||
sub koha_objects_class {
|
||||
'Koha::Suggestions';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use Carp;
|
|||
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils qw(dt_from_string);
|
||||
use Koha::Patrons;
|
||||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ Koha::Suggestion - Koha Suggestion object class
|
|||
|
||||
=head1 API
|
||||
|
||||
=head2 Class Methods
|
||||
=head2 Class methods
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -53,7 +54,26 @@ sub store {
|
|||
return $self->SUPER::store();
|
||||
}
|
||||
|
||||
=head3 type
|
||||
=head3 suggester
|
||||
|
||||
my $patron = $suggestion->suggester
|
||||
|
||||
Returns the I<Koha::Patron> for the suggestion generator. I<undef> is
|
||||
returned if no suggester is linked.
|
||||
|
||||
=cut
|
||||
|
||||
sub suggester {
|
||||
my ($self) = @_;
|
||||
|
||||
my $suggester_rs = $self->_result->suggester;
|
||||
return unless $suggester_rs;
|
||||
return Koha::Patron->_new_from_dbic($suggester_rs);
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
|
||||
=head3 _type
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright 2020 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 => 1;
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::Suggestions;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
||||
subtest 'suggester() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
my $suggestion = $builder->build_object(
|
||||
{ class => 'Koha::Suggestions', value => { suggestedby => undef } } );
|
||||
|
||||
is( $suggestion->suggester, undef, 'Returns undef if no suggester' );
|
||||
# Set a borrowernumber
|
||||
$suggestion->suggestedby($patron->borrowernumber)->store->discard_changes;
|
||||
my $suggester = $suggestion->suggester;
|
||||
is( ref($suggester), 'Koha::Patron', 'Type is correct for suggester' );
|
||||
is_deeply( $patron->unblessed, $suggester->unblessed, 'It returns the right patron' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
Loading…
Reference in New Issue