Bugzilla – Attachment 35539 Details for
Bug 13622
Add option to display datetimes as dates in notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13536: Display a datetime without time in a notice
Bug-13536-Display-a-datetime-without-time-in-a-not.patch (text/plain), 8.24 KB, created by
Jonathan Druart
on 2015-01-26 16:30:33 UTC
(
hide
)
Description:
Bug 13536: Display a datetime without time in a notice
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-01-26 16:30:33 UTC
Size:
8.24 KB
patch
obsolete
>From 76202208250078535fcaf3a5a8bc7a4730edbed7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 26 Jan 2015 17:24:36 +0100 >Subject: [PATCH] Bug 13536: Display a datetime without time in a notice > >For some needs, a librarian would like to display a datetime or >timestamp field without the time. > >This patch a filter logic in the notice/letter parsing process. > >Test plan: >1/ Defined a notice using a datetime or timestamp DB field >(biblio.timestamp for instance). >2/ Generate the notice >3/ Verify that the letter is generated with the time >4/ Use the "dateonly" filter like: > <<your_table.your_field | dateonly>> > <<biblio.timestamp | dateonly>> >5/ Generate the notice >6/ Confirm the the letter is generated without the time for this field. > >http://bugs.koha-community.org/show_bug.cgi?id=13622 >--- > C4/Letters.pm | 43 +++++++++++++++++++++++++++++-------------- > t/db_dependent/Letters.t | 40 +++++++++++++++++++++++++++++++++++++--- > 2 files changed, 66 insertions(+), 17 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index a11c862..ded286c 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -788,14 +788,14 @@ sub _parseletter { > } > > while ( my ($field, $val) = each %$values ) { >- my $replacetablefield = "<<$table.$field>>"; >- my $replacefield = "<<$field>>"; > $val =~ s/\p{P}$// if $val && $table=~/biblio/; > #BZ 9886: Assuming that we want to eliminate ISBD punctuation here > #Therefore adding the test on biblio. This includes biblioitems, > #but excludes items. Removed unneeded global and lookahead. > > $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/; >+ >+ # Dates replacement > my $replacedby = defined ($val) ? $val : ''; > if ( $replacedby > and not $replacedby =~ m|0000-00-00| >@@ -804,19 +804,34 @@ sub _parseletter { > { > # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date > my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds. >- eval { >- $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly }); >- }; >- warn "$replacedby seems to be a date but an error occurs on generating it ($@)" if $@; >+ my $re_dateonly_filter = qr{ $field( \s* \| \s* dateonly\s*)?>> }xms; >+ >+ for my $letter_field ( qw( title content ) ) { >+ my $filter_string_used = q{}; >+ if ( $letter->{ $letter_field } =~ $re_dateonly_filter ) { >+ # We overwrite $dateonly if the filter exists and we have a time in the datetime >+ $filter_string_used = $1 || q{}; >+ $dateonly = $1 unless $dateonly; >+ } >+ eval { >+ $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly }); >+ }; >+ >+ if ( $letter->{ $letter_field } ) { >+ $letter->{ $letter_field } =~ s/\Q<<$table.$field$filter_string_used>>\E/$replacedby/g; >+ $letter->{ $letter_field } =~ s/\Q<<$field$filter_string_used>>\E/$replacedby/g; >+ } >+ } >+ } >+ # Other fields replacement >+ else { >+ for my $letter_field ( qw( title content ) ) { >+ if ( $letter->{ $letter_field } ) { >+ $letter->{ $letter_field } =~ s/<<$table.$field>>/$replacedby/g; >+ $letter->{ $letter_field } =~ s/<<$field>>/$replacedby/g; >+ } >+ } > } >- ($letter->{title} ) and do { >- $letter->{title} =~ s/$replacetablefield/$replacedby/g; >- $letter->{title} =~ s/$replacefield/$replacedby/g; >- }; >- ($letter->{content}) and do { >- $letter->{content} =~ s/$replacetablefield/$replacedby/g; >- $letter->{content} =~ s/$replacefield/$replacedby/g; >- }; > } > > if ($table eq 'borrowers' && $letter->{content}) { >diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t >index f53e75b..08fca6e 100644 >--- a/t/db_dependent/Letters.t >+++ b/t/db_dependent/Letters.t >@@ -18,7 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 58; >+use Test::More tests => 61; > use Test::MockModule; > use Test::Warn; > >@@ -137,7 +137,7 @@ my $letters = C4::Letters::GetLetters(); > is( @$letters, 0, 'GetLetters returns the correct number of letters' ); > > my $title = q|<<branches.branchname>> - <<status>>|; >-my $content = q|Dear <<borrowers.firstname>> <<borrowers.surname>>, >+my $content = q{Dear <<borrowers.firstname>> <<borrowers.surname>>, > According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible. > > <<branches.branchname>> >@@ -151,7 +151,7 @@ The following item(s) is/are currently <<status>>: > Thank-you for your prompt attention to this matter. > Don't forget your date of birth: <<borrowers.dateofbirth>>. > Look at this wonderful biblio timestamp: <<biblio.timestamp>>. >-|; >+}; > > $dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('CPL','my module','my code','my name',1,?,?,'email')|, undef, $title, $content ); > $letters = C4::Letters::GetLetters(); >@@ -260,6 +260,7 @@ The following item(s) is/are currently $substitute->{status}: > Thank-you for your prompt attention to this matter. > Don't forget your date of birth: | . output_pref({ dt => $date, dateonly => 1 }) . q|. > Look at this wonderful biblio timestamp: | . output_pref({ dt => $date }) . ".\n"; >+ > is( $prepared_letter->{title}, $my_title_letter, 'GetPreparedLetter returns the title correctly' ); > is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' ); > >@@ -275,6 +276,39 @@ $prepared_letter = GetPreparedLetter(( > $my_content_letter = qq|This is a SMS for an $substitute->{status}|; > is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' ); > >+$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test_date','TEST_DATE','Test dates','Test dates','This one only contains the date: <<biblio.timestamp | dateonly>>.');}); >+$prepared_letter = GetPreparedLetter(( >+ module => 'test_date', >+ branchcode => '', >+ letter_code => 'test_date', >+ tables => $tables, >+ substitute => $substitute, >+ repeat => $repeat, >+)); >+is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| ); >+ >+$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp | dateonly>>.' WHERE code = 'test_date';}); >+$prepared_letter = GetPreparedLetter(( >+ module => 'test_date', >+ branchcode => '', >+ letter_code => 'test_date', >+ tables => $tables, >+ substitute => $substitute, >+ repeat => $repeat, >+)); >+is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| ); >+ >+$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp|dateonly >>.' WHERE code = 'test_date';}); >+$prepared_letter = GetPreparedLetter(( >+ module => 'test_date', >+ branchcode => '', >+ letter_code => 'test_date', >+ tables => $tables, >+ substitute => $substitute, >+ repeat => $repeat, >+)); >+is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| ); >+ > $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimacquisition','TESTACQCLAIM','Acquisition Claim','Item Not Received','<<aqbooksellers.name>>|<<aqcontacts.name>>|<order>Ordernumber <<aqorders.ordernumber>> (<<biblio.title>>) (<<aqorders.quantity>> ordered)</order>');}); > > my $booksellerid = C4::Bookseller::AddBookseller( >-- >2.1.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 13622
:
35539
|
39281
|
39282
|
40794
|
40795
|
42519
|
42520