Bugzilla – Attachment 95628 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: Move get_opac_news to Koha namespace
Bug-22544-Move-getopacnews-to-Koha-namespace.patch (text/plain), 10.92 KB, created by
David Nind
on 2019-11-20 22:10:46 UTC
(
hide
)
Description:
Bug 22544: Move get_opac_news to Koha namespace
Filename:
MIME Type:
Creator:
David Nind
Created:
2019-11-20 22:10:46 UTC
Size:
10.92 KB
patch
obsolete
>From 0b0e072b395add4979a21faf3b62332557636592 Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Tue, 19 Mar 2019 10:17:31 +0000 >Subject: [PATCH] Bug 22544: Move get_opac_news to Koha namespace > >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/NewsChannels.pm | 42 +----------------- > Koha/NewsItem.pm | 51 ++++++++++++++++++++++ > .../prog/en/modules/tools/koha-news.tt | 16 +++---- > t/db_dependent/NewsChannels.t | 41 ++--------------- > tools/koha-news.pl | 22 ++++------ > 5 files changed, 70 insertions(+), 102 deletions(-) > >diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm >index 5ed50817a1..1dcee7698b 100644 >--- a/C4/NewsChannels.pm >+++ b/C4/NewsChannels.pm >@@ -28,7 +28,7 @@ BEGIN { > @ISA = qw(Exporter); > @EXPORT = qw( > &GetNewsToDisplay >- &add_opac_new &upd_opac_new &del_opac_new &get_opac_news >+ &add_opac_new &upd_opac_new &del_opac_new > ); > } > >@@ -121,46 +121,6 @@ sub del_opac_new { > } > } > >-sub get_opac_news { >- my ($limit, $lang, $branchcode) = @_; >- my @values; >- my $dbh = C4::Context->dbh; >- my $query = q{ >- SELECT opac_news.*, branches.branchname, >- timestamp AS newdate, >- borrowers.title AS author_title, >- borrowers.firstname AS author_firstname, >- borrowers.surname AS author_surname >- FROM opac_news LEFT JOIN branches >- ON opac_news.branchcode=branches.branchcode >- LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber >- }; >- $query .= ' WHERE 1'; >- if ($lang) { >- $query .= " AND (opac_news.lang='' OR opac_news.lang=?)"; >- push @values,$lang; >- } >- if ($branchcode) { >- $query .= ' AND (opac_news.branchcode IS NULL OR opac_news.branchcode=?)'; >- push @values,$branchcode; >- } >- $query.= ' ORDER BY timestamp DESC '; >- #if ($limit) { >- # $query.= 'LIMIT 0, ' . $limit; >- #} >- my $sth = $dbh->prepare($query); >- $sth->execute(@values); >- my @opac_news; >- my $count = 0; >- while (my $row = $sth->fetchrow_hashref) { >- if ((($limit) && ($count < $limit)) || (!$limit)) { >- push @opac_news, $row; >- } >- $count++; >- } >- return ($count, \@opac_news); >-} >- > =head2 GetNewsToDisplay > > $news = &GetNewsToDisplay($lang,$branch); >diff --git a/Koha/NewsItem.pm b/Koha/NewsItem.pm >index 9d0dd63f9a..4cf875b659 100644 >--- a/Koha/NewsItem.pm >+++ b/Koha/NewsItem.pm >@@ -22,6 +22,9 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::DateUtils; >+use Koha::Libraries; >+use Koha::Patrons; > > use base qw(Koha::Object); > >@@ -37,6 +40,54 @@ Koha::NewsItem represents a single piece of news from the opac_news table > > =cut > >+=head3 is_expired >+ >+my $is_expired = $news_item->is_expired; >+ >+Returns 1 if the news item is expired or 0; >+ >+=cut >+ >+sub is_expired { >+ my ( $self ) = @_; >+ >+ return 0 unless $self->expirationdate; >+ return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' ); >+ return 0; >+} >+ >+=head3 library >+ >+my $library = $news_item->library; >+ >+Returns Koha::Library object or undef >+ >+=cut >+ >+sub library { >+ my ( $self ) = @_; >+ >+ my $library_rs = $self->_result->branchcode; >+ return unless $library_rs; >+ return Koha::Library->_new_from_dbic( $library_rs ); >+} >+ >+=head3 author >+ >+my $patron = $news_item->author; >+ >+Returns Koha::Patron object or undef >+ >+=cut >+ >+sub author { >+ my ( $self ) = @_; >+ >+ my $author_rs = $self->_result->borrowernumber; >+ return unless $author_rs; >+ return Koha::Patron->_new_from_dbic( $author_rs ); >+} >+ > =head3 type > > =cut >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt >index 6621e0c878..1d5b86f368 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt >@@ -6,8 +6,6 @@ > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Tools › News</title> > [% INCLUDE 'doc-head-close.inc' %] >-[% IF ( opac_news_count ) %] >-[% END %] > </head> > > <body id="tools_koha-news" class="tools"> >@@ -100,7 +98,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div> > <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset> > </form> > [% ELSE %] >- [% IF ( opac_news_count ) %] >+ [% IF ( opac_news.count ) %] > <form id="del_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl"> > <table id="newst"> > <thead> <tr> >@@ -116,7 +114,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div> > <th class="NoSort">Actions</th> > </tr></thead> > <tbody>[% FOREACH opac_new IN opac_news %] >- [% IF ( opac_new.expired ) %] >+ [% IF ( opac_new.is_expired ) %] > <tr class="expired"> > [% ELSE %] > <tr> >@@ -137,13 +135,13 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div> > </td> > <td>[% IF ( opac_new.branchcode == "" ) -%] > All libraries >- [% ELSE %][% opac_new.branchname | html %] >+ [% ELSE %][% opac_new.library.branchname | html %] > [% END %]</td> > <td>[% opac_new.number | html %]</td> >- <td><span title="[% opac_new.newdate | html %]">[% opac_new.newdate | $KohaDates %]</span></td> >- <td><span title="[% opac_new.expirationdate | html %]">[% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</span></td> >+ <td><span title="[% opac_new.timestamp | html %]">[% opac_new.timestamp | $KohaDates %]</span></td> >+ <td><span title="[% opac_new.expirationdate | html %]">[% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.is_expired ) %](<span class="expired">expired</span>)[% END %]</span></td> > <td>[% opac_new.title | html %]</td> >- <td>[% opac_new.author_title | html %] [% opac_new.author_firstname | html %] [% opac_new.author_surname | html %]</td> >+ <td>[% IF ( opac_new.author) %][% INCLUDE 'patron-title.inc' patron=opac_new.author hide_patron_infos_if_needed=1 %][% END %]</td> > <td> > [% opac_new.content | $raw %] > </td> >@@ -206,7 +204,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div> > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'calendar.inc' %] > [% Asset.js("js/tools-menu.js") | $raw %] >- [% IF ( opac_news_count ) %] >+ [% IF ( opac_news.count ) %] > [% INCLUDE 'datatables.inc' %] > <script> > function Checkbox(){ >diff --git a/t/db_dependent/NewsChannels.t b/t/db_dependent/NewsChannels.t >index 5fa6974669..f14d48939e 100644 >--- a/t/db_dependent/NewsChannels.t >+++ b/t/db_dependent/NewsChannels.t >@@ -4,8 +4,9 @@ use Modern::Perl; > use Koha::Database; > use Koha::DateUtils; > use Koha::Libraries; >+use Koha::News; > >-use Test::More tests => 11; >+use Test::More tests => 9; > > BEGIN { > use_ok('C4::NewsChannels'); >@@ -134,43 +135,7 @@ $href_entry2->{idnew} = $idnew2; > $rv = upd_opac_new($href_entry2); > is( $rv, 1, 'Successfully updated second dummy news item!' ); > >-# Test get_opac_news (multiple news items) >-my ( $opac_news_count, $arrayref_opac_news ) = get_opac_news( 0, q{}, 'LIB1' ); >- >-# using >= 2, because someone may have LIB1 news already. >-ok( $opac_news_count >= 2, 'Successfully tested get_opac_news for LIB1!' ); >- > # Test GetNewsToDisplay >-( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' ); >+my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' ); > ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' ); > >-# Regression test 14248 -- make sure author_title, author_firstname, and >-# author_surname exist. >- >-subtest 'Regression tests on author title, firstname, and surname.', sub { >- my ( $opac_news_count, $opac_news ) = get_opac_news( 0, q{}, 'LIB1' ); >- my $check = 0; # bitwise flag to confirm NULL and not NULL borrowernumber. >- ok($opac_news_count>0,'Data exists for regression testing'); >- foreach my $news_item (@$opac_news) { >- ok(exists $news_item->{author_title}, 'Author title exists'); >- ok(exists $news_item->{author_firstname},'Author first name exists'); >- ok(exists $news_item->{author_surname}, 'Author surname exists'); >- if ($news_item->{borrowernumber}) { >- ok(defined $news_item->{author_title} || >- defined $news_item->{author_firstname} || >- defined $news_item->{author_surname}, 'Author data defined'); >- $check = $check | 2; # bitwise flag; >- } >- else { >- ok(!defined $news_item->{author_title}, >- 'Author title undefined as expected'); >- ok(!defined $news_item->{author_firstname}, >- 'Author first name undefined as expected'); >- ok(!defined $news_item->{author_surname}, >- 'Author surname undefined as expected'); >- $check = $check | 1; # bitwise flag; >- } >- } >- ok($check==3,'Both with and without author data tested'); >- done_testing(); >-}; >diff --git a/tools/koha-news.pl b/tools/koha-news.pl >index 614cb666bc..e1fdeab992 100755 >--- a/tools/koha-news.pl >+++ b/tools/koha-news.pl >@@ -144,21 +144,15 @@ elsif ( $op eq 'del' ) { > } > > else { >- >- my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, undef, undef ); >- >- foreach my $new ( @$opac_news ) { >- next unless $new->{'expirationdate'}; >- my @date = split (/-/,$new->{'expirationdate'}); >- if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days( @date ) < Date_to_Days(&Today) ){ >- $new->{'expired'} = 1; >+ my $params; >+ $params->{lang} = $lang if $lang; >+ my $opac_news = Koha::News->search( >+ $params, >+ { >+ order_by => { -desc => 'timestamp' }, > } >- } >- >- $template->param( >- opac_news => $opac_news, >- opac_news_count => $opac_news_count, >- ); >+ ); >+ $template->param( opac_news => $opac_news ); > } > $template->param( lang => $lang ); > output_html_with_http_headers $cgi, $cookie, $template->output; >-- >2.11.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 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