Bugzilla – Attachment 149932 Details for
Bug 29691
Use template plugins to display OPAC news on homepage
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29691: Use template to display news on opac homepage
Bug-29691-Use-template-to-display-news-on-opac-hom.patch (text/plain), 11.44 KB, created by
Martin Renvoize (ashimema)
on 2023-04-20 11:26:22 UTC
(
hide
)
Description:
Bug 29691: Use template to display news on opac homepage
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-04-20 11:26:22 UTC
Size:
11.44 KB
patch
obsolete
>From 5eb02a3d6d945e594cd41cf63be22dca4c6a52a8 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 14 Dec 2021 13:35:45 +0000 >Subject: [PATCH] Bug 29691: Use template to display news on opac homepage > >This patch moves the fetching of news to the template and >adds a p[lugin method to get news by id > >TO test: >1 - Define some general and library specific news items >2 - Define in various languages >3 - Define some 'Additional contents' as well >4 - Apply patch >5 - Confirm onlly 'all libraries' news show if not loigged in to opac >6 - Confirm correct library news show when logged in >7 - View specific news items: > http://localhost:8080/cgi-bin/koha/opac-main.pl?news_id=12 >8 - Confirm that non-existent ids show " This news item does not exist. " >9 - Confirm if you enter ID for additional contents you get 'does not exist' > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Template/Plugin/AdditionalContents.pm | 38 +++++- > .../bootstrap/en/modules/opac-main.tt | 109 +++++++++--------- > opac/opac-main.pl | 24 +--- > 3 files changed, 91 insertions(+), 80 deletions(-) > >diff --git a/Koha/Template/Plugin/AdditionalContents.pm b/Koha/Template/Plugin/AdditionalContents.pm >index c37abece4e..455ba848e1 100644 >--- a/Koha/Template/Plugin/AdditionalContents.pm >+++ b/Koha/Template/Plugin/AdditionalContents.pm >@@ -55,6 +55,26 @@ sub get { > } > } > >+sub get_opac_news_by_id { >+ my ( $self, $params ) = @_; >+ >+ my $news_id = $params->{news_id}; >+ >+ my $content = Koha::AdditionalContents->search( >+ { >+ location => ['opac_only', 'staff_and_opac'], >+ idnew => $news_id, >+ category => 'news', >+ } >+ ); >+ >+ if ( $content->count ) { >+ return { >+ content => $content, >+ }; >+ } >+} >+ > 1; > > =head1 NAME >@@ -71,8 +91,22 @@ Koha::Template::Plugin::AdditionalContents - TT Plugin for displaying additional > > =head2 get > >-In a template, you can get the all categories with >-the following TT code: [% AdditionalContents.get() %] >+In a template, you can get the news categories with >+the following TT code: [% AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %] >+ >+The function returns a hashref with keys: >+ contents: a Koha::AdditionalContents object >+ location: the passed in location param returned >+ blocktitle: the passed in blocktitle param returned >+ >+=head2 get_opac_news_by_id >+ >+In a template, you can get a specific news item by passing >+the news id. E.g.: >+ >+[% SET news_item = AdditionalContents.get_news_by_id( news_id => news_id ) %] >+ >+The function returns a hashref with a Koha::AdditionalContents object in the 'contents' key > > =head1 AUTHOR > >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 4ffbc8e024..820d5035cd 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt >@@ -72,7 +72,7 @@ > <h1 class="sr-only">Koha home</h1> > > [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] >- [% UNLESS news_item %] >+ [% UNLESS news_id %] > <form id="news-branch-select" class="form-inline" name="news-branch-select" method="get" action="/cgi-bin/koha/opac-main.pl"> > <legend class="sr-only">News</legend> > <label for="news-branch">Display news for: </label> >@@ -88,67 +88,62 @@ > [% END %] > [% END %] > >- [% IF koha_news.count %] >- >- [% IF single_news_error %] >- >- <div class="alert alert-error"> >- This news item does not exist. >- </div> >- >- [% ELSE %] >+ [% IF news_id %] >+ [% SET koha_news = AdditionalContents.get_opac_news_by_id( news_id => news_id ) %] >+ [% ELSE %] >+ [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %] >+ [% END %] >+ [% IF koha_news.content.count %] >+ <div id="news" class="newscontainer"> >+ [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %] >+ [% FOREACH koha_new IN koha_news.content %] >+ <div class="newsitem"> >+ <h4 class="newsheader"> >+ [% IF ( news_item ) %] >+ [% koha_new.title | html %] >+ [% ELSE %] >+ <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]">[% koha_new.title | html %]</a> >+ [% END %] >+ </h4> >+ <div class="newsbody">[% koha_new.content | $raw %]</div> >+ <div class="newsfooter"> >+ Published on [% koha_new.published_on | $KohaDates %] >+ [% IF ( show_author && koha_new.author ) %] >+ by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]</span> >+ [% END %] >+ [% IF ( news_id ) %] >+ • <a href="/cgi-bin/koha/opac-main.pl">Show all news</a> >+ [% END %] >+ </div> >+ </div> >+ [% END %] > >- <div id="news" class="newscontainer"> >- [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %] >- [% FOREACH koha_new IN koha_news %] >- [% IF koha_new.category == 'news' %] >- <div class="newsitem"> >- <h4 class="newsheader"> >- [% IF ( news_item ) %] >- [% koha_new.title | html %] >+ [% UNLESS news_id %] >+ <div id="rssnews-container"> >+ <!-- Logged in users have a branch code or it could be explicitly set --> >+ <a href="[% OPACBaseURL | url %]/cgi-bin/koha/opac-news-rss.pl?branchcode=[% branchcode | uri %]"> >+ <i class="fa fa-rss" aria-hidden="true"></i> >+ [% IF Branches.all.size == 1 %] >+ [% IF branchcode %] >+ <span>RSS feed for [% Branches.GetName( branchcode ) | html %] library news</span> > [% ELSE %] >- <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]">[% koha_new.title | html %]</a> >- [% END %] >- </h4> >- <div class="newsbody">[% koha_new.content | $raw %]</div> >- <div class="newsfooter"> >- Published on [% koha_new.published_on | $KohaDates %] >- [% IF ( show_author && koha_new.author ) %] >- by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]</span> >- [% END %] >- [% IF ( news_item ) %] >- • <a href="/cgi-bin/koha/opac-main.pl">Show all news</a> >+ <span>RSS feed for library news</span> > [% END %] >- </div> >- </div> >- [% END %] >- [% END %] >- >- [% UNLESS news_item %] >- <div id="rssnews-container"> >- <!-- Logged in users have a branch code or it could be explicitly set --> >- <a href="[% OPACBaseURL | url %]/cgi-bin/koha/opac-news-rss.pl?branchcode=[% branchcode | uri %]"> >- <i class="fa fa-rss" aria-hidden="true"></i> >- [% IF Branches.all.size == 1 %] >- [% IF branchcode %] >- <span>RSS feed for [% Branches.GetName( branchcode ) | html %] library news</span> >- [% ELSE %] >- <span>RSS feed for library news</span> >- [% END %] >+ [% ELSE %] >+ [% IF branchcode %] >+ <span>RSS feed for [% Branches.GetName( branchcode ) | html %] and system-wide library news</span> > [% ELSE %] >- [% IF branchcode %] >- <span>RSS feed for [% Branches.GetName( branchcode ) | html %] and system-wide library news</span> >- [% ELSE %] >- <span>RSS feed for system-wide library news</span> >- [% END %] >+ <span>RSS feed for system-wide library news</span> > [% END %] >- </a> >- </div> >- [% END %] >- </div> >- >- [% END # /IF single_news_error %] >- >+ [% END %] >+ </a> >+ </div> >+ [% END %] >+ </div> >+ [% ELSIF news_id %] <!-- news_id but no koha_news.content --> >+ <div class="alert alert-error"> >+ This news item does not exist. >+ </div> > [% ELSE %] <!-- koha news --> > [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] > <div id="news" class="newscontainer"> >diff --git a/opac/opac-main.pl b/opac/opac-main.pl >index 78f7975a10..f90d98cdcf 100755 >--- a/opac/opac-main.pl >+++ b/opac/opac-main.pl >@@ -58,26 +58,9 @@ elsif (C4::Context->userenv and defined $input->param('branch') and length $inpu > $homebranch = ""; > } > >-my $news_id = $input->param('news_id'); >-my $koha_news; > >-if (defined $news_id){ >- $koha_news = Koha::AdditionalContents->search({ idnew => $news_id, location => ['opac_only', 'staff_and_opac'] }); # get news that is not staff-only news >- if ( $koha_news->count > 0){ >- $template->param( news_item => $koha_news->next ); >- } else { >- $template->param( single_news_error => 1 ); >- } >-} else { >- $koha_news = Koha::AdditionalContents->search_for_display( >- { >- category => 'news', >- location => ['opac_only', 'staff_and_opac'], >- lang => $template->lang, >- library_id => $homebranch, >- } >- ); >-} >+my $news_id = $input->param('news_id'); >+$template->param( news_id => $news_id ); > > # For dashboard > my $patron = Koha::Patrons->find( $borrowernumber ); >@@ -114,9 +97,8 @@ if ( $patron ) { > } > } > >+$template->param( branchcode => $homebranch ) if $homebranch; > $template->param( >- koha_news => $koha_news, >- branchcode => $homebranch, > daily_quote => Koha::Quotes->get_daily_quote(), > ); > >-- >2.40.0
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 29691
:
128506
|
128508
|
149903
|
149904
|
149932
|
149933
|
151481
|
151482