Bug 7045: Use <<tag>> for default value placeholders
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 16 Aug 2016 08:09:53 +0000 (09:09 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 2 Sep 2016 14:21:28 +0000 (14:21 +0000)
When adding a biblio, the default value of a MARC subfield defined in
the frameworks can be used as placeholders to set the current date or
the surname of the logged in user (use cases?).
The different placeholders are 'YYYY', 'MM', 'DD', 'user'.
When adding an item, same behavior except that 'user' is not replaced.

This patch makes behaviors consistent between the 2 editors and
surrounds placeholders with << >>
We will now have: <<YYYY>>, <<MM>>, <<DD>> and <<USER>>

Test plan:
Define default values for biblio and item subfields.
Create a bibliographic record and attach it an item.
The default values should be used and replaced if you used placeholders.

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
cataloguing/addbiblio.pl
cataloguing/additem.pl

index 1e7cb61..3db9d8c 100755 (executable)
@@ -36,6 +36,7 @@ use C4::ClassSource;
 use C4::ImportBatch;
 use C4::Charset;
 use Koha::BiblioFrameworks;
+use Koha::DateUtils;
 
 use Date::Calc qw(Today);
 use MARC::File::USMARC;
@@ -294,15 +295,17 @@ sub create_input {
     if ( $value eq '' ) {
         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
 
-        # get today date & replace YYYY, MM, DD if provided in the default value
-        my ( $year, $month, $day ) = Today();
-        $month = sprintf( "%02d", $month );
-        $day   = sprintf( "%02d", $day );
-        $value =~ s/YYYY/$year/g;
-        $value =~ s/MM/$month/g;
-        $value =~ s/DD/$day/g;
-        my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");    
-        $value=~s/user/$username/g;
+        # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+        my $today_dt = dt_from_string;
+        my $year = $today_dt->year;
+        my $month = $today_dt->month;
+        my $day = $today_dt->day;
+        $value =~ s/<<YYYY>>/$year/g;
+        $value =~ s/<<MM>>/$month/g;
+        $value =~ s/<<DD>>/$day/g;
+        # And <<USER>> with surname (?)
+        my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
+        $value=~s/<<USER>>/$username/g;
     
     }
     my $dbh = C4::Context->dbh;
index a15eb17..86abc57 100755 (executable)
@@ -128,12 +128,17 @@ sub generate_subfield_form {
         $value =~ s/"/&quot;/g;
         if ( ! defined( $value ) || $value eq '')  {
             $value = $subfieldlib->{defaultvalue};
-            # get today date & replace YYYY, MM, DD if provided in the default value
-            my $today_iso = output_pref( { dt=>dt_from_string, dateonly => 1, dateformat => 'iso' } );
-            my ( $year, $month, $day ) = split ('-', $today_iso);
-            $value =~ s/YYYY/$year/g;
-            $value =~ s/MM/$month/g;
-            $value =~ s/DD/$day/g;
+            # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+            my $today_dt = dt_from_string;
+            my $year = $today_dt->year;
+            my $month = $today_dt->month;
+            my $day = $today_dt->day;
+            $value =~ s/<<YYYY>>/$year/g;
+            $value =~ s/<<MM></$month/g;
+            $value =~ s/<<DD>>/$day/g;
+            # And <<USER>> with surname (?)
+            my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
+            $value=~s/<<USER>>/$username/g;
         }
         
         $subfield_data{visibility} = "display:none;" if (($subfieldlib->{hidden} > 4) || ($subfieldlib->{hidden} <= -4));