diff --git a/Koha/NewsItem.pm b/Koha/NewsItem.pm index c09f3f9d00..19bed767a6 100644 --- a/Koha/NewsItem.pm +++ b/Koha/NewsItem.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Patrons; use base qw(Koha::Object); @@ -37,7 +38,12 @@ Koha::NewsItem represents a single piece of news from the opac_news table =cut -=head3 type +sub author { + my ( $self ) = @_; + return Koha::Patron->_new_from_dbic($self->_result->borrowernumber); +} + +=head3 _type =cut diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index af3e8e4af7..94b39afd33 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -96,7 +96,12 @@
Published on [% koha_new.timestamp | $KohaDates with_hours = 1 %] [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %] - by [% koha_new.author_title | html %] [% koha_new.author_firstname | html %] [% koha_new.author_surname | html %] + [% IF news_item %] + [% SET author = koha_new.author %] + by [% author.title | html %] [% author.firstname | html %] [% author.surname | html %] + [% ELSE %] + by [% koha_new.author_title | html %] [% koha_new.author_firstname | html %] [% koha_new.author_surname | html %] + [% END %] [% END %] [% IF ( news_item ) %] • Show all news diff --git a/t/db_dependent/Koha/News.t b/t/db_dependent/Koha/News.t index e1b56f5f3f..731a801a5c 100644 --- a/t/db_dependent/Koha/News.t +++ b/t/db_dependent/Koha/News.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use Koha::NewsItem; use Koha::News; @@ -54,5 +54,12 @@ is( $retrieved_news_item_1->content, $new_news_item_1->content, 'The content met $retrieved_news_item_1->delete; is( Koha::News->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); +subtest '->author' => sub { + plan tests => 1; + + my $news_item = $builder->build_object({ class => 'Koha::News' }); + is( ref($news_item->author), 'Koha::Patron', 'Koha::NewsItem->author returns a Koha::Patron object' ); +}; + $schema->storage->txn_rollback;