Bugzilla – Attachment 117486 Details for
Bug 22544
Move C4:NewsChannels to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22544: Refactor searching of news items
Bug-22544-Refactor-searching-of-news-items.patch (text/plain), 9.11 KB, created by
Jonathan Druart
on 2021-03-02 09:51:41 UTC
(
hide
)
Description:
Bug 22544: Refactor searching of news items
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-03-02 09:51:41 UTC
Size:
9.11 KB
patch
obsolete
>From c90594bd371d0695f7d3b8d9ca1ba460b891114c Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Wed, 20 Mar 2019 11:07:22 +0000 >Subject: [PATCH] Bug 22544: Refactor searching of news items > >Test plan: >1) Go to tools and define some news >2) Try different parameters, try to edit new items, and delete some >3) Go to all places where news are presented and ensure that there are >the right ones shown: > 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 >4) run tests: >prove t/db_dependent/Koha/News.t > >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/Members.pm | 13 ++--- > Koha/News.pm | 50 ++++++++++++++++++- > Koha/Template/Plugin/KohaNews.pm | 25 +++------- > .../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 ++--- > 8 files changed, 74 insertions(+), 59 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index d14b1a2fbd..5b6e826dfc 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -588,15 +588,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; >diff --git a/Koha/News.pm b/Koha/News.pm >index c7d93faa0a..f0106a7852 100644 >--- a/Koha/News.pm >+++ b/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 >diff --git a/Koha/Template/Plugin/KohaNews.pm b/Koha/Template/Plugin/KohaNews.pm >index d602646234..a82461466e 100644 >--- a/Koha/Template/Plugin/KohaNews.pm >+++ b/Koha/Template/Plugin/KohaNews.pm >@@ -35,26 +35,15 @@ sub get { > my $blocktitle = $params->{blocktitle}; > my $lang = $params->{lang}; > my $library = $params->{library}; >- my $news_lang; > >- if( !$display_location ){ >- $news_lang = $lang; >- } else { >- $news_lang = $display_location."_".$lang; >- } >+ my $content = Koha::News->search_for_display({ >+ type => $display_location, >+ lang => $lang, >+ library_id => $library, >+ }); >+ > >- 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' >- }); >- >- if( @$content ){ >+ if( $content ){ > return { > content => $content, > location => $display_location, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt >index 920c9b3901..151e6591c8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt >@@ -21,9 +21,7 @@ > [% IF ( koha_news.count ) %] > <div id="area-news"> > <h3><span class="news_title">News</span></h3> >- [% SET show_author = >- Koha.Preference('NewsAuthorDisplay') == 'staff' >- || Koha.Preference('NewsAuthorDisplay') == 'both' %] >+ [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'staff' || Koha.Preference('NewsAuthorDisplay') == 'both' %] > [% FOREACH koha_new IN koha_news %] > <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4> > <div class="newsbody">[% koha_new.content | $raw %]</div> >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 89793525f3..74154abfa7 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt >@@ -93,9 +93,7 @@ > [% ELSE %] > > <div id="news" class="newscontainer"> >- [% SET show_author = >- Koha.Preference('NewsAuthorDisplay') == 'opac' >- || Koha.Preference('NewsAuthorDisplay') == 'both' %] >+ [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %] > [% FOREACH koha_new IN koha_news %] > <div class="newsitem"> > <h4 class="newsheader"> >diff --git a/mainpage.pl b/mainpage.pl >index 6d2c79783c..4c46811c77 100755 >--- a/mainpage.pl >+++ b/mainpage.pl >@@ -49,13 +49,10 @@ my $homebranch; > if (C4::Context->userenv) { > $homebranch = C4::Context->userenv->{'branch'}; > } >-my $koha_news = Koha::News->search({ >- lang => 'koha', >- branchcode => [ $homebranch, undef ] >-}, >-{ >- order_by => 'number' >-}); >+my $koha_news = Koha::News->search_for_display({ >+ type => 'koha', >+ library_id => $homebranch >+ }); > > $template->param( > koha_news => $koha_news, >diff --git a/opac/opac-main.pl b/opac/opac-main.pl >index f11aecdf01..40e9466a88 100755 >--- a/opac/opac-main.pl >+++ b/opac/opac-main.pl >@@ -70,15 +70,10 @@ if (defined $news_id){ > $template->param( single_news_error => 1 ); > } > } else { >- my $params; >- $params->{lang} = [ $template->lang, '' ]; >- $params->{branchcode} = [ $homebranch, undef ] if $homebranch; >- $params->{-or} = [ expirationdate => { '>=' => \'NOW()' }, >- expirationdate => undef ]; >- $koha_news = Koha::News->search( >- $params, >- { >- order_by => 'number' >+ $koha_news = Koha::News->search_for_display({ >+ type => 'opac', >+ lang => $template->lang, >+ library_id => $homebranch, > }); > } > >diff --git a/opac/opac-news-rss.pl b/opac/opac-news-rss.pl >index ff00cdfe24..29b0bef5b9 100755 >--- a/opac/opac-news-rss.pl >+++ b/opac/opac-news-rss.pl >@@ -43,15 +43,10 @@ my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Con > > my $branchcode = $input->param('branchcode'); > >-my $params; >-$params->{lang} = [ $news_lang, '' ]; >-$params->{branchcode} = [ $branchcode, undef ] if $branchcode; >-$params->{-or} = [ expirationdate => { '>=' => \'NOW()' }, >- expirationdate => undef ]; >-my $koha_news = Koha::News->search( >- $params, >- { >- order_by => 'number' >+my $koha_news = Koha::News->search_for_display({ >+ type => 'opac', >+ lang => $news_lang, >+ library_id => $branchcode, > }); > > $template->param( koha_news => $koha_news ); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22544
:
86772
|
86773
|
86774
|
86775
|
86776
|
86777
|
86780
|
86781
|
90103
|
90104
|
90105
|
90106
|
90107
|
90108
|
90109
|
90110
|
92005
|
92006
|
92007
|
92008
|
92009
|
92010
|
92011
|
92012
|
95613
|
95614
|
95615
|
95627
|
95628
|
95629
|
95630
|
95631
|
95632
|
95633
|
95634
|
99849
|
99850
|
99851
|
99852
|
99853
|
99854
|
99855
|
99856
|
99857
|
104176
|
104177
|
104178
|
104179
|
104180
|
104181
|
104182
|
104183
|
104184
|
111012
|
111013
|
111014
|
111015
|
111016
|
111017
|
111018
|
111019
|
111020
|
111021
|
111022
|
111023
|
115135
|
115136
|
115137
|
115138
|
115139
|
115140
|
115141
|
115142
|
115143
|
115144
|
115145
|
115146
|
115218
|
115296
|
115297
|
115298
|
115299
|
116933
|
116934
|
116935
|
117479
|
117480
|
117481
|
117482
|
117483
|
117484
|
117485
|
117486
|
117487
|
117488
|
117489
|
117490
|
117491
|
117492
|
117493
|
117494
|
117495
|
117496
|
117497
|
118054
|
118055
|
118056
|
118057
|
118058
|
118059
|
118060
|
118061
|
118062
|
118063
|
118064
|
118065
|
118066
|
118067
|
118068
|
118069
|
118070
|
118071
|
118072
|
118073
|
118087
|
118088
|
118089
|
118090
|
118091
|
118092
|
118093
|
118094
|
118095
|
118096
|
118097
|
118098
|
118099
|
118100
|
118101
|
118102
|
118103
|
118104
|
118105
|
118106
|
120377
|
120378
|
120379
|
120380
|
120381
|
120382
|
120383
|
120384
|
120385
|
120386
|
120387
|
120388
|
120389
|
120390
|
120391
|
120392
|
120393
|
120394
|
120395
|
120396
|
122396
|
122397
|
122398
|
122399
|
122400
|
122401
|
122402
|
122403
|
122404
|
122405
|
122406
|
122407
|
122408
|
122409
|
122410
|
122411
|
122412
|
122413
|
122414
|
122415