Bug 7045: Use <<tag>> for default value placeholders

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>
(cherry picked from commit 50abf24ff0)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
(cherry picked from commit 60ab076953)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
Jonathan Druart 2016-08-16 09:09:53 +01:00 committed by Julian Maurice
parent 9af21daf52
commit 81399156f8
2 changed files with 23 additions and 15 deletions

View File

@ -35,6 +35,7 @@ use C4::Branch; # XXX subfield_is_koha_internal_p
use C4::ClassSource;
use C4::ImportBatch;
use C4::Charset;
use Koha::DateUtils;
use Date::Calc qw(Today);
use MARC::File::USMARC;
@ -293,15 +294,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;

View File

@ -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));