(bug #3370) add keyword to MARC field mapping
This add the support of keyword => MARC field mapping, ton abstract the relation between human readable fields like subtitle, title, authors, location, ... and MARC fields in each framework. This will allow to koha developper to be more flexible with each framework and don't care about the MARC flavour, just require some "keywords" to the user. Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
This commit is contained in:
parent
2152d95b3c
commit
b21a5bdadc
7 changed files with 302 additions and 1 deletions
114
C4/Biblio.pm
114
C4/Biblio.pm
|
@ -52,6 +52,7 @@ BEGIN {
|
|||
|
||||
# to get something
|
||||
push @EXPORT, qw(
|
||||
&Get
|
||||
&GetBiblio
|
||||
&GetBiblioData
|
||||
&GetBiblioItemData
|
||||
|
@ -59,6 +60,10 @@ BEGIN {
|
|||
&GetBiblioItemByBiblioNumber
|
||||
&GetBiblioFromItemNumber
|
||||
|
||||
GetFieldMapping
|
||||
SetFieldMapping
|
||||
DeleteFieldMapping
|
||||
|
||||
&GetISBDView
|
||||
|
||||
&GetMarcNotes
|
||||
|
@ -466,6 +471,115 @@ sub LinkBibHeadingsToAuthorities {
|
|||
return $num_headings_changed;
|
||||
}
|
||||
|
||||
=head2 Get
|
||||
|
||||
=over 4
|
||||
|
||||
my $values = Get($field, $record, $frameworkcode);
|
||||
|
||||
=back
|
||||
|
||||
Get MARC fields from a keyword defined in fieldmapping table.
|
||||
|
||||
=cut
|
||||
|
||||
sub Get {
|
||||
my ($field, $record, $frameworkcode) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?');
|
||||
$sth->execute($frameworkcode, $field);
|
||||
|
||||
my @result = ();
|
||||
|
||||
while(my $row = $sth->fetchrow_hashref){
|
||||
foreach my $field ($record->field($row->{fieldcode})){
|
||||
if( ($row->{subfieldcode} ne "" && $field->subfield($row->{subfieldcode}))){
|
||||
foreach my $subfield ($field->subfield($row->{subfieldcode})){
|
||||
push @result, { 'subfield' => $subfield };
|
||||
}
|
||||
|
||||
}elsif($row->{subfieldcode} eq "") {
|
||||
push @result, {'subfield' => $field->as_string()};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return @result;
|
||||
}
|
||||
|
||||
=head2 SetFieldMapping
|
||||
|
||||
=over 4
|
||||
|
||||
SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
|
||||
|
||||
=back
|
||||
|
||||
Set a Field to MARC mapping value, if it already exists we don't add a new one.
|
||||
|
||||
=cut
|
||||
|
||||
sub SetFieldMapping {
|
||||
my ($framework, $field, $fieldcode, $subfieldcode) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
my $sth = $dbh->prepare('SELECT * FROM fieldmapping WHERE fieldcode = ? AND subfieldcode = ? AND frameworkcode = ? AND field = ?');
|
||||
$sth->execute($fieldcode, $subfieldcode, $framework, $field);
|
||||
if(not $sth->fetchrow_hashref){
|
||||
my @args;
|
||||
$sth = $dbh->prepare('INSERT INTO fieldmapping (fieldcode, subfieldcode, frameworkcode, field) VALUES(?,?,?,?)');
|
||||
|
||||
$sth->execute($fieldcode, $subfieldcode, $framework, $field);
|
||||
}
|
||||
}
|
||||
|
||||
=head2 DeleteFieldMapping
|
||||
|
||||
=over 4
|
||||
|
||||
DeleteFieldMapping($id);
|
||||
|
||||
=back
|
||||
|
||||
Delete a field mapping from an $id.
|
||||
|
||||
=cut
|
||||
|
||||
sub DeleteFieldMapping{
|
||||
my ($id) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?');
|
||||
$sth->execute($id);
|
||||
}
|
||||
|
||||
=head2 GetFieldMapping
|
||||
|
||||
=over 4
|
||||
|
||||
GetFieldMapping($frameworkcode);
|
||||
|
||||
=back
|
||||
|
||||
Get all field mappings for a specified frameworkcode
|
||||
|
||||
=cut
|
||||
|
||||
sub GetFieldMapping {
|
||||
my ($framework) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
my $sth = $dbh->prepare('SELECT * FROM fieldmapping where frameworkcode = ?');
|
||||
$sth->execute($framework);
|
||||
|
||||
my @return;
|
||||
while(my $row = $sth->fetchrow_hashref){
|
||||
push @return, $row;
|
||||
}
|
||||
return \@return;
|
||||
}
|
||||
|
||||
=head2 GetBiblioData
|
||||
|
||||
=over 4
|
||||
|
|
77
admin/fieldmapping.pl
Executable file
77
admin/fieldmapping.pl
Executable file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright 2009 SARL BibLibre
|
||||
#
|
||||
# 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., 59 Temple Place,
|
||||
# Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use CGI;
|
||||
use C4::Auth;
|
||||
use C4::Biblio;
|
||||
use C4::Koha;
|
||||
use C4::Output;
|
||||
|
||||
my $query = new CGI;
|
||||
|
||||
my $framework = $query->param('framework') || "";
|
||||
|
||||
my $field = $query->param('fieldname');
|
||||
my $fieldcode = $query->param('marcfield');
|
||||
my $subfieldcode = $query->param('marcsubfield');
|
||||
my $op = $query->param('op');
|
||||
my $id = $query->param('id');
|
||||
|
||||
my ($template, $loggedinuser, $cookie)
|
||||
= get_template_and_user({template_name => "admin/fieldmapping.tmpl",
|
||||
query => $query,
|
||||
type => "intranet",
|
||||
authnotrequired => 0,
|
||||
flagsrequired => {parameters => 1},
|
||||
debug => 1,
|
||||
});
|
||||
|
||||
# get framework list
|
||||
my $frameworks = getframeworks();
|
||||
my @frameworkloop;
|
||||
foreach my $thisframeworkcode (keys %$frameworks) {
|
||||
my $selected = 1 if $thisframeworkcode eq $framework;
|
||||
my %row =(value => $thisframeworkcode,
|
||||
selected => $selected,
|
||||
frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
|
||||
);
|
||||
push @frameworkloop, \%row;
|
||||
}
|
||||
|
||||
if($op eq "delete" and $id){
|
||||
DeleteFieldMapping($id);
|
||||
print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$framework);
|
||||
exit;
|
||||
}
|
||||
|
||||
# insert operation
|
||||
if($field and $fieldcode){
|
||||
SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
|
||||
}
|
||||
|
||||
my $fieldloop = GetFieldMapping($framework);
|
||||
warn Data::Dumper::Dumper($fieldloop->[1]);
|
||||
|
||||
$template->param( frameworkloop => \@frameworkloop,
|
||||
framework => $framework,
|
||||
fields => $fieldloop,
|
||||
);
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
|
@ -2301,6 +2301,21 @@ CREATE TABLE `borrower_message_transport_preferences` (
|
|||
CONSTRAINT `borrower_message_transport_preferences_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Table structure for table `fieldmapping`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `fieldmapping`;
|
||||
CREATE TABLE `fieldmapping` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`field` varchar(255) NOT NULL,
|
||||
`frameworkcode` char(4) NOT NULL default '',
|
||||
`fieldcode` char(3) NOT NULL,
|
||||
`subfieldcode` char(1) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
|
|
|
@ -552,6 +552,22 @@ ENDOFRENEWAL
|
|||
SetVersion ($DBversion);
|
||||
}
|
||||
|
||||
#$DBversion = "3.01.00.040";
|
||||
$DBversion = "3.00.04.016";
|
||||
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
|
||||
$dbh->do("
|
||||
CREATE TABLE `fieldmapping` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`field` varchar(255) NOT NULL,
|
||||
`frameworkcode` char(4) NOT NULL default '',
|
||||
`fieldcode` char(3) NOT NULL,
|
||||
`subfieldcode` char(1) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
");
|
||||
SetVersion ($DBversion);
|
||||
}
|
||||
|
||||
=item DropAllForeignKeys($table)
|
||||
|
||||
Drop all foreign keys of the table $table
|
||||
|
|
|
@ -64,6 +64,8 @@
|
|||
<dd>Create and manage Bibliographic frameworks that define the characteristics of your MARC Records (field and subfield definitions) as well as templates for the MARC editor.</dd>
|
||||
<dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
|
||||
<dd>Define the mapping between the Koha transactional database (SQL) and the MARC Bibliographic records. Note that the mapping can be defined through MARC Bibliographic Framework. This tool is just a shortcut to speed up linkage.</dd>
|
||||
<dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
|
||||
<dd>Define the mapping between keywords and MARC fields, those keywords are used to find some datas independently of the framework.</dd>
|
||||
<dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
|
||||
<dd>Checks the MARC structure. If you change your MARC Bibliographic framework it's recommended that you run this tool to test for errors in your definition.</dd>
|
||||
<dt><a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a></dt>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
|
||||
<title>Koha › Administration › Keyword to MARC Mapping</title>
|
||||
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
|
||||
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$(document).ready(function() {
|
||||
$('#selectframework').find("input:submit").hide();
|
||||
$('#framework').change(function() {
|
||||
$('#selectframework').submit();
|
||||
});
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- TMPL_INCLUDE NAME="header.inc" -->
|
||||
<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
|
||||
|
||||
<div id="doc3" class="yui-t2">
|
||||
<div id="yui-main">
|
||||
<div class="yui-b">
|
||||
<h1>Keyword to MARC Mapping</h1>
|
||||
<form method="get" action="/cgi-bin/koha/admin/fieldmapping.pl" id="selectframework">
|
||||
<label for="framework">Framework :</label>
|
||||
<select name="framework" id="framework" style="width:20em;">
|
||||
<option value="">Default</option>
|
||||
<!-- TMPL_LOOP NAME="frameworkloop" -->
|
||||
<!-- TMPL_IF NAME="selected" -->
|
||||
<option selected="selected" value="<!-- TMPL_VAR NAME='value' -->"><!--TMPL_VAR NAME='frameworktext' --></option>
|
||||
<!-- TMPL_ELSE -->
|
||||
<option value="<!-- TMPL_VAR NAME="value" -->"><!--TMPL_VAR NAME="frameworktext" --></option>
|
||||
<!-- /TMPL_IF -->
|
||||
|
||||
<!-- /TMPL_LOOP -->
|
||||
</select>
|
||||
</form>
|
||||
|
||||
|
||||
<form method="post" action="" id="addfield">
|
||||
<input type="hidden" name="framework" value="<!-- TMPL_VAR NAME="framework" -->" />
|
||||
<table>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>MARC Field</th>
|
||||
<th>MARC Subfield</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<!-- TMPL_LOOP NAME="fields" -->
|
||||
<tr>
|
||||
<td><!-- TMPL_VAR NAME="field" --></td>
|
||||
<td><!-- TMPL_VAR NAME="fieldcode" --></td>
|
||||
<td><!-- TMPL_VAR NAME="subfieldcode" --></td>
|
||||
<td><a href="?op=delete&id=<!-- TMPL_VAR NAME="id" -->&framework=<!-- TMPL_VAR NAME="framework" -->">Delete</a></td>
|
||||
</tr>
|
||||
<!-- /TMPL_LOOP -->
|
||||
<tr>
|
||||
<td><input type="text" name="fieldname" /></td>
|
||||
<td><input type="text" name="marcfield" size="3" /></td>
|
||||
<td><input type="text" name="marcsubfield" size="1" /></td>
|
||||
<td><input type="submit" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="yui-b">
|
||||
<!-- TMPL_INCLUDE NAME="admin-menu.inc" -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
|
|
@ -10,7 +10,7 @@
|
|||
use strict;
|
||||
|
||||
sub kohaversion {
|
||||
our $VERSION = '3.00.04.015';
|
||||
our $VERSION = '3.00.04.016';
|
||||
# version needs to be set this way
|
||||
# so that it can be picked up by Makefile.PL
|
||||
# during install
|
||||
|
|
Loading…
Reference in a new issue