&GetAuthorisedValueDesc
&GetMarcStructure
&GetMarcFromKohaField
+ &GetMarcSubfieldStructureFromKohaField
&GetFrameworkCode
&TransformKohaToMarc
&PrepHostMarcField
($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
Returns the MARC fields & subfields mapped to the koha field
-for the given frameworkcode
+for the given frameworkcode or default framework if $frameworkcode is missing
=cut
sub GetMarcFromKohaField {
- my ( $kohafield, $frameworkcode ) = @_;
- return (0, undef) unless $kohafield and defined $frameworkcode;
+ my $kohafield = shift;
+ my $frameworkcode = shift || '';
+ return (0, undef) unless $kohafield;
my $relations = C4::Context->marcfromkohafield;
if ( my $mf = $relations->{$frameworkcode}->{$kohafield} ) {
return @$mf;
return (0, undef);
}
+=head2 GetMarcSubfieldStructureFromKohaField
+
+ my $subfield_structure = &GetMarcSubfieldStructureFromKohaField($kohafield, $frameworkcode);
+
+Returns a hashref where keys are marc_subfield_structure column names for the
+row where kohafield=$kohafield for the given framework code.
+
+$frameworkcode is optional. If not given, then the default framework is used.
+
+=cut
+
+sub GetMarcSubfieldStructureFromKohaField {
+ my ($kohafield, $frameworkcode) = @_;
+
+ return undef unless $kohafield;
+ $frameworkcode //= '';
+
+ my $dbh = C4::Context->dbh;
+ my $query = qq{
+ SELECT *
+ FROM marc_subfield_structure
+ WHERE kohafield = ?
+ AND frameworkcode = ?
+ };
+ my $sth = $dbh->prepare($query);
+ $sth->execute($kohafield, $frameworkcode);
+ my $result = $sth->fetchrow_hashref;
+ $sth->finish;
+
+ return $result;
+}
+
=head2 GetMarcBiblio
my $record = GetMarcBiblio($biblionumber, [$embeditems]);
my ($marc, $biblionumber, $itemnumbers) = @_;
croak "No MARC record" unless $marc;
+ $itemnumbers = [] unless defined $itemnumbers;
+
my $frameworkcode = GetFrameworkCode($biblionumber);
_strip_item_fields($marc, $frameworkcode);
my @item_fields;
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
while (my ($itemnumber) = $sth->fetchrow_array) {
- next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
+ next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
require C4::Items;
my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
push @item_fields, $item_marc->field($itemtag);