@@ -, +, @@ opac main page - based on language opac righ column (formerly syspref OpacNavRight) - based on language opac news rss feed circulation slip (not quick slip) intranet main page --- C4/Members.pm | 13 ++--- Koha/News.pm | 50 ++++++++++++++++++- Koha/Template/Plugin/KohaNews.pm | 24 +++------ .../prog/en/modules/intranet-main.tt | 4 +- .../bootstrap/en/modules/opac-main.tt | 4 +- mainpage.pl | 11 ++-- opac/opac-main.pl | 13 ++--- opac/opac-news-rss.pl | 13 ++--- tools/koha-news.pl | 2 +- 9 files changed, 74 insertions(+), 60 deletions(-) --- a/C4/Members.pm +++ a/C4/Members.pm @@ -580,15 +580,10 @@ sub IssueSlip { issues => $all, }; } - my $news = Koha::News->search({ - lang => [ 'slip', '' ], - branchcode => [ $branch, undef ], - -or => [ expirationdate => { '>=' => \'NOW()' }, - expirationdate => undef ] - },{ - order_by => 'number' - } - ); + my $news = Koha::News->search_for_display({ + type => 'slip', + library_id => $branch, + }); my @news; while ( my $n = $news->next ) { my $all = $n->unblessed_all_relateds; --- a/Koha/News.pm +++ a/Koha/News.pm @@ -22,7 +22,7 @@ use Modern::Perl; use Carp; use Koha::Database; - +use Koha::Exceptions; use Koha::NewsItem; use base qw(Koha::Objects); @@ -37,6 +37,54 @@ Koha::News - Koha News object set class =cut +=head3 search_for_display + +my $news = Koha::News->search_for_display({ + type => 'slip', + lang => 'en', + library_id => $branchcode +}) + +Return Koha::News set for display to user + +You can limit the results by type(lang) and library by optional params + +library_id should be valid branchcode of defined library + +type is one of this: +- slip - for ISSUESLIP notice +- koha - for intranet +- opac - for online catalogue +- OpanNavRight - Right column in the online catalogue + +lang is language code - it is used only when type is opac or OpacNavRight + +=cut + +sub search_for_display { + my ( $self, $params ) = @_; + + my $search_params; + if ($params->{type} ) { + if ( $params->{type} eq 'slip' || $params->{type} eq 'koha') { + $search_params->{lang} = [ $params->{type}, '' ]; + } elsif ( $params->{type} eq 'opac' && $params->{lang} ) { + $search_params->{lang} = [ $params->{lang}, '' ]; + } elsif ( $params->{type} eq 'OpacNavRight' && $params->{lang} ) { + $search_params->{lang} = $params->{type} . '_' . $params->{lang}; + } else { + Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid"); + } + } + + $search_params->{branchcode} = [ $params->{library_id}, undef ] if $params->{library_id}; + $search_params->{timestamp} = { '<=' => \'NOW()' }; + $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' }, + expirationdate => undef ]; + + return $self->SUPER::search($search_params, { order_by => 'number' }); +} + =head3 type =cut --- a/Koha/Template/Plugin/KohaNews.pm +++ a/Koha/Template/Plugin/KohaNews.pm @@ -34,24 +34,12 @@ sub get { my $display_location = $params->{location}; my $lang = $params->{lang}; my $library = $params->{library}; - my $news_lang; - - if( !$display_location ){ - $news_lang = $lang; - } else { - $news_lang = $display_location."_".$lang; - } - - my $search_params; - $search_params->{lang} = $news_lang; - $search_params->{branchcode} = [ $library, undef ] if $library; - $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' }, - expirationdate => undef ]; - my $content = Koha::News->search( - $search_params, - { - order_by => 'number' - }); + + my $content = Koha::News->search_for_display({ + type => $display_location, + lang => $lang, + library_id => $library, + }); return $content; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -20,9 +20,7 @@ [% IF ( koha_news.count ) %]