Lines 688-713
sub GetRecordValue {
Link Here
|
688 |
carp 'GetRecordValue called with undefined record'; |
688 |
carp 'GetRecordValue called with undefined record'; |
689 |
return; |
689 |
return; |
690 |
} |
690 |
} |
691 |
my $dbh = C4::Context->dbh; |
|
|
692 |
|
691 |
|
693 |
my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?'); |
692 |
# All field mappings are retrieved from cache, or from DB if not already |
694 |
$sth->execute( $frameworkcode, $field ); |
693 |
# cached. |
|
|
694 |
# The mapping is a data structure that looks like that: |
695 |
# '' => { |
696 |
# subtitle => [ |
697 |
# [ '200', 'e' ], |
698 |
# [ '400', 'e' ], |
699 |
# }, |
700 |
# maintitle => [ |
701 |
# [ '200', 'a' ], |
702 |
# [ '400', 'a' ], |
703 |
# }, |
704 |
# }, |
705 |
# MAIN = { |
706 |
# subtitle => [ |
707 |
# [ '200', 'e' ], |
708 |
# }, |
709 |
# maintitle => [ |
710 |
# [ '200', 'a' ], |
711 |
# }, |
712 |
# }, |
713 |
|
714 |
my $key = 'FieldMapping'; |
715 |
my $cache = Koha::Cache->get_instance(); |
716 |
my $mapping = $cache->get_from_cache($key); |
717 |
unless ( $mapping ) { |
718 |
my $sth = C4::Context->dbh->prepare('SELECT * FROM fieldmapping'); |
719 |
$sth->execute; |
720 |
$mapping = {}; |
721 |
for my $map ( @{ $sth->fetchall_arrayref({}) } ) { |
722 |
my ($field, $framework, $tag, $letter) = ( |
723 |
$map->{field}, |
724 |
$map->{frameworkcode}, |
725 |
$map->{fieldcode}, |
726 |
$map->{subfieldcode} ); |
727 |
$mapping->{$framework} ||= {}; |
728 |
$mapping->{$framework}->{$field} ||= []; |
729 |
push @{ $mapping->{$framework}->{$field} }, [ $tag, $letter ]; |
730 |
} |
731 |
$cache->set_in_cache($key, $mapping); |
732 |
} |
733 |
|
734 |
# Does the requested field mapping exists from the framework? |
735 |
my $maps = $mapping->{$frameworkcode}; |
736 |
return unless $maps; |
737 |
$maps = $maps->{$field}; |
738 |
return unless $maps; |
695 |
|
739 |
|
696 |
my @result = (); |
740 |
my @result = (); |
697 |
|
741 |
for my $map (@$maps) { |
698 |
while ( my $row = $sth->fetchrow_hashref ) { |
742 |
my ($tag, $letter) = @$map; |
699 |
foreach my $field ( $record->field( $row->{fieldcode} ) ) { |
743 |
foreach my $field ( $record->field($tag) ) { |
700 |
if ( ( $row->{subfieldcode} ne "" && $field->subfield( $row->{subfieldcode} ) ) ) { |
744 |
if ( $letter ) { |
701 |
foreach my $subfield ( $field->subfield( $row->{subfieldcode} ) ) { |
745 |
if ( my @values = $field->subfield($letter) ) { |
702 |
push @result, { 'subfield' => $subfield }; |
746 |
push @result, { subfield => $_ } for @values; |
703 |
} |
747 |
} |
704 |
|
748 |
} |
705 |
} elsif ( $row->{subfieldcode} eq "" ) { |
749 |
else { |
706 |
push @result, { 'subfield' => $field->as_string() }; |
750 |
push @result, { subfield => $field->as_string() }; |
707 |
} |
751 |
} |
708 |
} |
752 |
} |
709 |
} |
753 |
} |
710 |
|
|
|
711 |
return \@result; |
754 |
return \@result; |
712 |
} |
755 |
} |
713 |
|
756 |
|
Lines 731-736
sub SetFieldMapping {
Link Here
|
731 |
|
774 |
|
732 |
$sth->execute( $fieldcode, $subfieldcode, $framework, $field ); |
775 |
$sth->execute( $fieldcode, $subfieldcode, $framework, $field ); |
733 |
} |
776 |
} |
|
|
777 |
my $cache = Koha::Cache->get_instance()->clear_from_cache('FieldMapping'); |
734 |
} |
778 |
} |
735 |
|
779 |
|
736 |
=head2 DeleteFieldMapping |
780 |
=head2 DeleteFieldMapping |
Lines 747-752
sub DeleteFieldMapping {
Link Here
|
747 |
|
791 |
|
748 |
my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?'); |
792 |
my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?'); |
749 |
$sth->execute($id); |
793 |
$sth->execute($id); |
|
|
794 |
my $cache = Koha::Cache->get_instance()->clear_from_cache('FieldMapping'); |
750 |
} |
795 |
} |
751 |
|
796 |
|
752 |
=head2 GetFieldMapping |
797 |
=head2 GetFieldMapping |
753 |
- |
|
|