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