Bug 929 : Followup fixing date formatting
authorChris Cormack <chrisc@catalyst.net.nz>
Thu, 29 Dec 2011 08:46:51 +0000 (21:46 +1300)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 6 Jan 2012 12:52:08 +0000 (13:52 +0100)
This patch introduces a Filter (KohaDates) for use in templates
[% USE KohaDates %]
[% somevariable | $KohaDates %]

This will format the date in the format specified by the systempreference

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
C4/Templates.pm
Koha/Template/Plugin/KohaDates.pm [new file with mode: 0644]
acqui/ordered.pl
acqui/spent.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt

index 7585727..d150a16 100644 (file)
@@ -58,6 +58,7 @@ sub new {
     my $template = Template->new(
         {   EVAL_PERL    => 1,
             ABSOLUTE     => 1,
+           PLUGIN_BASE => 'Koha::Template::Plugin',
             INCLUDE_PATH => [
                 "$htdocs/$theme/$lang/includes",
                 "$htdocs/$theme/en/includes"
diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm
new file mode 100644 (file)
index 0000000..749f6e2
--- /dev/null
@@ -0,0 +1,31 @@
+package Koha::Template::Plugin::KohaDates;
+
+# Copyright Catalyst IT 2011
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Template::Plugin::Filter;
+use base qw( Template::Plugin::Filter );
+
+use C4::Dates;
+
+sub filter {
+    my ($self,$text) = @_;
+    my $date = C4::Dates->new( $text, 'iso' );
+    return $date->output("syspref");
+}
+
+1;
\ No newline at end of file
index 0ae5dad..b681afb 100755 (executable)
@@ -97,8 +97,6 @@ while ( my $data = $sth->fetchrow_hashref ) {
         push @ordered, $data;
         $total += $subtotal;
     }
-    my $entrydate = C4::Dates->new( $data->{'entrydate'}, 'iso' );
-    $data->{'entrydate'} = $entrydate->output("syspref");
 }
 $total = sprintf( "%.2f", $total );
 
index 7ea9446..a50b7ae 100755 (executable)
@@ -98,10 +98,6 @@ while ( my $data = $sth->fetchrow_hashref ) {
         $data->{'freight'}   = sprintf( "%.2f", $data->{'freight'} );
         $data->{'unitprice'} = sprintf( "%.2f", $data->{'unitprice'} );
         $total += $subtotal;
-        my $entrydate = C4::Dates->new( $data->{'entrydate'}, 'iso' );
-        $data->{'entrydate'} = $entrydate->output("syspref");
-        my $datereceived = C4::Dates->new( $data->{'datereceived'}, 'iso' );
-        $data->{'datereceived'} = $datereceived->output("syspref");
         push @spent, $data;
     }
 
index 14be1ed..018d807 100644 (file)
@@ -1,3 +1,4 @@
+[% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Ordered</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -41,7 +42,7 @@
            [% order.title %]
        </td>
        <td class="cell">
-           <a href=/cgi-bin/koha/acqui/neworderempty.pl?ordernumber=[% order.ordernumber %]&booksellerid=[% order.booksellerid %]&basketno=[% order.basketno %]">[% order.ordernumber %]</a>
+           <a href="/cgi-bin/koha/acqui/neworderempty.pl?ordernumber=[% order.ordernumber %]&booksellerid=[% order.booksellerid %]&basketno=[% order.basketno %]">[% order.ordernumber %]</a>
        </td>
        <td class="cell">
            <a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=[% order.booksellerid %]">[% order.booksellerid %]</a>
@@ -56,7 +57,7 @@
            [% order.ecost %]
        </td>
        <td class="cell">
-           [% order.entrydate %]
+           [% order.entrydate | $KohaDates %]
        </td>
        <td class="cell" align="right">
            [% order.subtotal %]
index 78f7cb5..49bcedb 100644 (file)
@@ -1,3 +1,4 @@
+[% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Spent</title>
 [% INCLUDE 'doc-head-close.inc' %]
            [% order.freight %]
        </td>
        <td class="cell">
-           [% order.entrydate %]
+           [% order.entrydate | $KohaDates %]
        </td>
        <td class="cell">
-           [% order.datereceived %]
+           [% order.datereceived | $KohaDates %]
        </td>
        <td class="cell" align="right">
            [% order.subtotal %]