Bug 10602: Set default value for authority fields via the framework
authorJonathan Druart <jonathan.druart@biblibre.com>
Wed, 17 Jul 2013 12:38:55 +0000 (14:38 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 10 Oct 2013 23:25:47 +0000 (23:25 +0000)
This patch allows to define default values in the authorities framework.

Some code already existed but the feature did not work.

Test plan:
1/ Choose a framework, field and subfields.
2/ Define a default value.
3/ Create a new authority and check that the subfield is
automatically filled with the default value.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Work as described. koha-qa reports some tabs, fixed in followup

Test
1) Apply patch, run updatedatabase.pl
2) Edit auth framework, put default value someware, save
3) Add new auth, default value present

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Verified database update is done correctly.

Controlfields 0xx
- Edited an existing field (001)
- Set a default value for subfield @
- Edited subfield again, checking default was saved correctly
- Verified the default shows up correctly when creating a
  new authority using this authority type

Fields
- Edited an existing field (100)
- Set a default value for subfield e
- Edited subfield again, checking default was saved correctly
- Verified the default shows up correctly when creating a
  new authority using this authority type

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/AuthoritiesMarc.pm
admin/auth_subfields_structure.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt

index f1b4935..7443f36 100644 (file)
@@ -520,7 +520,7 @@ sub GetTagsLabels {
         $res->{$tag}->{repeatable} = $repeatable;
   }
   $sth=      $dbh->prepare(
-"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl 
+"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue
 FROM auth_subfield_structure 
 WHERE authtypecode=? 
 ORDER BY tagfield,tagsubfield"
@@ -535,12 +535,13 @@ ORDER BY tagfield,tagsubfield"
     my $hidden;
     my $isurl;
     my $link;
+    my $defaultvalue;
 
     while (
         ( $tag,         $subfield,   $liblibrarian,   , $libopac,      $tab,
         $mandatory,     $repeatable, $authorised_value, $authtypecode,
         $value_builder, $kohafield,  $seealso,          $hidden,
-        $isurl,            $link )
+        $isurl,         $defaultvalue, $link )
         = $sth->fetchrow
       )
     {
@@ -556,6 +557,7 @@ ORDER BY tagfield,tagsubfield"
         $res->{$tag}->{$subfield}->{hidden}           = $hidden;
         $res->{$tag}->{$subfield}->{isurl}            = $isurl;
         $res->{$tag}->{$subfield}->{link}            = $link;
+        $res->{$tag}->{$subfield}->{defaultvalue}     = $defaultvalue;
     }
     return $res;
 }
index 537f0ea..b4f9512 100755 (executable)
@@ -139,6 +139,7 @@ if ($op eq 'add_form') {
        while ($data =$sth->fetchrow_hashref) {
 
                my %row_data;  # get a fresh hash for the row data
+        $row_data{defaultvalue} = $data->{defaultvalue};
                $row_data{tab} = CGI::scrolling_list(-name=>'tab',
                                        -id=>"tab$i",
                                         -values =>
@@ -386,9 +387,9 @@ if ($op eq 'add_form') {
        $template->param(tagfield => "$input->param('tagfield')");
 #      my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
 #                                                                      values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
-       my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
+       my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue)
                                                                        values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
-       my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?
+       my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?
                                                                        where authtypecode=? and tagfield=? and tagsubfield=?");
        my @tagsubfield = $input->param('tagsubfield');
        my @liblibrarian        = $input->param('liblibrarian');
@@ -404,6 +405,7 @@ if ($op eq 'add_form') {
        my $authtypecode        = $input->param('authtypecode');
        my @frameworkcodes      = $input->param('frameworkcode');
        my @value_builder       =$input->param('value_builder');
+    my @defaultvalue = $input->param('defaultvalue');
        for (my $i=0; $i<= $#tagsubfield ; $i++) {
                my $tagfield                    =$input->param('tagfield');
                my $tagsubfield         =$tagsubfield[$i];
@@ -418,6 +420,7 @@ if ($op eq 'add_form') {
                my $authorised_value            =$authorised_values[$i];
                my $frameworkcode               =$frameworkcodes[$i];
                my $value_builder=$value_builder[$i];
+        my $defaultvalue = $defaultvalue[$i];
                #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
                my $hidden = $ohidden[$i]; #collate from 3 hiddens;
                my $isurl = $input->param("isurl$i")?1:0;
@@ -440,6 +443,7 @@ if ($op eq 'add_form') {
                                                $value_builder,
                                                $hidden,
                                                $isurl,
+                        $defaultvalue,
                                                (
                                                        $authtypecode,
                                                        $tagfield,
@@ -463,6 +467,7 @@ if ($op eq 'add_form') {
                                                $value_builder,
                                                $hidden,
                                                $isurl,
+                        $defaultvalue,
                                        );
                                }
                        }
index 82da018..c1a8b8d 100644 (file)
@@ -56,6 +56,7 @@ CREATE TABLE `auth_subfield_structure` (
   `linkid` tinyint(1) NOT NULL default 0,
   `kohafield` varchar(45) NULL default '',
   `frameworkcode` varchar(10) NOT NULL default '',
+  `defaultvalue` TEXT DEFAULT '',
   PRIMARY KEY  (`authtypecode`,`tagfield`,`tagsubfield`),
   KEY `tab` (`authtypecode`,`tab`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
index e5e60f4..20f0f95 100755 (executable)
@@ -7176,6 +7176,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
    SetVersion ($DBversion);
 }
 
+$DBversion = "3.13.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        ALTER TABLE auth_subfield_structure ADD COLUMN defaultvalue TEXT DEFAULT NULL AFTER frameworkcode
+    |);
+    print "Upgrade to $DBversion done (Bug 10602: Add the column auth_subfield_structure.defaultvalue)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 688bd71..3d22192 100644 (file)
@@ -99,7 +99,18 @@ function displayMoreConstraint(numlayer){
                         </ol>
                     </fieldset>
                 </li>
-                <li><label for="isurl[% loo.row %]">Is a URL:</label>[% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)</li>
+                <li>
+                    <fieldset class="rows">
+                        <legend>Advanced constraints:</legend>
+                        <ol>
+                            <li><label for="isurl[% loo.row %]">Is a URL:</label>[% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)</li>
+                            <li>
+                                <label for="defaultvalue[% loo.row %]">Default value:</label>
+                                <input type="text" name="defaultvalue" id="defaultvalue[% loo.row %]" value="[% loo.defaultvalue %]" />
+                            </li>
+                        </ol>
+                    </fieldset>
+                </li>
                 <li>
                     <fieldset><legend>Help input</legend>    
                         <ol>