# to get something
push @EXPORT, qw(
+ &Get
&GetBiblio
&GetBiblioData
&GetBiblioItemData
&GetBiblioItemByBiblioNumber
&GetBiblioFromItemNumber
+ &GetRecordValue
+ &GetFieldMapping
+ &SetFieldMapping
+ &DeleteFieldMapping
+
&GetISBDView
&GetMarcNotes
return $num_headings_changed;
}
+=head2 GetRecordValue
+
+=over 4
+
+my $values = GetRecordValue($field, $record, $frameworkcode);
+
+=back
+
+Get MARC fields from a keyword defined in fieldmapping table.
+
+=cut
+
+sub GetRecordValue {
+ 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
return $marc_structure_cache->{$forlibrarian}->{$frameworkcode};
}
+# my $sth = $dbh->prepare(
+# "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
+# $sth->execute($frameworkcode);
+# my ($total) = $sth->fetchrow;
+# $frameworkcode = "" unless ( $total > 0 );
my $sth = $dbh->prepare(
- "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
- $sth->execute($frameworkcode);
- my ($total) = $sth->fetchrow;
- $frameworkcode = "" unless ( $total > 0 );
- $sth = $dbh->prepare(
"SELECT tagfield,liblibrarian,libopac,mandatory,repeatable
FROM marc_tag_structure
WHERE frameworkcode=?
=over 4
my $subfieldvalue =get_authorised_value_desc(
- $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category);
+ $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category, $opac);
Retrieve the complete description for a given authorised value.
Now takes $category and $value pair too.
my $auth_value_desc =GetAuthorisedValueDesc(
'','', 'DVD' ,'','','CCODE');
+If the optional $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
+
+
=back
=cut
sub GetAuthorisedValueDesc {
- my ( $tag, $subfield, $value, $framework, $tagslib, $category ) = @_;
+ my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
my $dbh = C4::Context->dbh;
if (!$category) {
if ( $category ne "" ) {
my $sth =
$dbh->prepare(
- "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?"
+ "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?"
);
$sth->execute( $category, $value );
my $data = $sth->fetchrow_hashref;
- return $data->{'lib'};
+ return ($opac && $data->{'lib_opac'}) ? $data->{'lib_opac'} : $data->{'lib'};
}
else {
return $value; # if nothing is found return the original value
=over 4
-PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
+PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
Returns a hash with all the fields for Display a given item data in a template
+The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
+
=back
=cut
sub PrepareItemrecordDisplay {
- my ( $bibnum, $itemnum, $defaultvalues ) = @_;
+ my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
my $dbh = C4::Context->dbh;
- my $frameworkcode = &GetFrameworkCode( $bibnum );
+ $frameworkcode = &GetFrameworkCode( $bibnum ) if $bibnum;
my ( $itemtagfield, $itemtagsubfield ) =
&GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
my $tagslib = &GetMarcStructure( 1, $frameworkcode );
+ # return nothing if we don't have found an existing framework.
+ return "" unless $tagslib;
my $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum) if ($itemnum);
my @loop_data;
my $authorised_values_sth =
}
if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
'items.itemcallnumber'
- && $defaultvalues->{'callnumber'} )
+ && $defaultvalues && $defaultvalues->{'callnumber'} )
{
my $temp = $itemrecord->field($subfield) if ($itemrecord);
unless ($temp) {
- $value = $defaultvalues->{'callnumber'};
+ $value = $defaultvalues->{'callnumber'} if $defaultvalues;
}
}
if ( ($tagslib->{$tag}->{$subfield}->{kohafield} eq
'items.holdingbranch' ||
$tagslib->{$tag}->{$subfield}->{kohafield} eq
'items.homebranch')
- && $defaultvalues->{'branchcode'} )
+ && $defaultvalues && $defaultvalues->{'branchcode'} )
{
my $temp = $itemrecord->field($subfield) if ($itemrecord);
unless ($temp) {
- $value = $defaultvalues->{branchcode};
+ $value = $defaultvalues->{branchcode} if $defaultvalues;
}
}
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {