GetBiblionumberFromItemnumber
&GetRecordValue
- &GetFieldMapping
- &SetFieldMapping
- &DeleteFieldMapping
&GetISBDView
return \@result;
}
-=head2 SetFieldMapping
-
- SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
-
-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
-
- DeleteFieldMapping($id);
-
-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
-
- GetFieldMapping($frameworkcode);
-
-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
$data = &GetBiblioData($biblionumber);
#!/usr/bin/perl
# Copyright 2009 SARL BibLibre
+# Copyright 2017 Koha Development Team
#
# This file is part of Koha.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
-use strict;
-use warnings;
+use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Biblio;
-use C4::Koha;
use C4::Output;
use Koha::BiblioFrameworks;
+use Koha::FieldMappings;
my $query = new CGI;
my $op = $query->param('op') || q{};
my $id = $query->param('id');
-my ($template, $loggedinuser, $cookie)
- = get_template_and_user({template_name => "admin/fieldmapping.tt",
- query => $query,
- type => "intranet",
- authnotrequired => 0,
- flagsrequired => {parameters => 'parameters_remaining_permissions'},
- debug => 1,
- });
-
-if($op eq "delete" and $id){
- DeleteFieldMapping($id);
- print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$frameworkcode);
- exit;
-}
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ {
+ template_name => "admin/fieldmapping.tt",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { parameters => 'parameters_remaining_permissions' },
+ debug => 1,
+ }
+);
-# insert operation
-if($field and $fieldcode){
- SetFieldMapping($frameworkcode, $field, $fieldcode, $subfieldcode);
+# FIXME Add exceptions
+if ( $op eq "delete" and $id ) {
+ Koha::FieldMappings->find($id)->delete;
+} elsif ( $field and $fieldcode ) {
+ my $params = { frameworkcode => $frameworkcode, field => $field, fieldcode => $fieldcode, subfieldcode => $subfieldcode };
+ my $exists = Koha::FieldMappings->search( $params )->count;;
+ unless ( $exists ) {
+ Koha::FieldMapping->new( $params )->store;
+ }
}
-my $fieldloop = GetFieldMapping($frameworkcode);
+my $fields = Koha::FieldMappings->search({ frameworkcode => $frameworkcode });
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
my $framework = $frameworks->search( { frameworkcode => $frameworkcode } )->next;
$template->param(
frameworks => $frameworks,
framework => $framework,
- fields => $fieldloop,
+ fields => $fields,
);
output_html_with_http_headers $query, $cookie, $template->output;
<div id="yui-main">
<div class="yui-b">
<h2>Keyword to MARC mapping</h2>
- [% UNLESS ( fields ) %]
- <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div>
- [% END %]
+ [% UNLESS ( fields.count ) %]
+ <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div>
+ [% END %]
<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;">
</fieldset>
</form>
- [% IF ( fields ) %]<table>
+ [% IF ( fields.count ) %]
+ <table>
<caption>Mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework</caption>
<tr>
<th>Field</th>
<td>[% field.field %]</td>
<td>[% field.fieldcode %]</td>
<td>[% field.subfieldcode %]</td>
- <td><a class="btn btn-default btn-xs" href="?op=delete&id=[% field.id %]&framework=[% field.framework %]"><i class="fa fa-trash"></i> Delete</a></td>
+ <td><a class="btn btn-default btn-xs" href="?op=delete&id=[% field.id %]&framework=[% field.frameworkcode %]"><i class="fa fa-trash"></i> Delete</a></td>
</tr>
[% END %]
</table>[% END %]
use Test::More tests => 4;
use MARC::Record;
-use C4::Biblio qw( AddBiblio SetFieldMapping GetMarcFromKohaField );
+use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
use C4::Context;
use C4::Charset qw( SanitizeRecord );