use C4::Context;
use Koha::Caches;
use Koha::DateUtils qw(dt_from_string);
+use Koha::AuthorisedValues;
use Koha::Libraries;
+use Koha::MarcSubfieldStructures;
use DateTime::Format::MySQL;
use Business::ISBN;
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
&getitemtypeimagelocation
&GetAuthorisedValues
&GetAuthorisedValueCategories
- &GetKohaAuthorisedValues
- &GetKohaAuthorisedValuesFromField
- &GetKohaAuthorisedValuesMapping
- &GetAuthorisedValueByCode
- &GetAuthValCode
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
return \%notforloan_label_of;
}
-=head2 GetAuthValCode
-
- $authvalcode = GetAuthValCode($kohafield,$frameworkcode);
-
-=cut
-
-sub GetAuthValCode {
- my ($kohafield,$fwcode) = @_;
- my $dbh = C4::Context->dbh;
- $fwcode='' unless $fwcode;
- my $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=? and frameworkcode=?');
- $sth->execute($kohafield,$fwcode);
- my ($authvalcode) = $sth->fetchrow_array;
- return $authvalcode;
-}
-
-=head2 GetAuthValCodeFromField
-
- $authvalcode = GetAuthValCodeFromField($field,$subfield,$frameworkcode);
-
-C<$subfield> can be undefined
-
-=cut
-
-sub GetAuthValCodeFromField {
- my ($field,$subfield,$fwcode) = @_;
- my $dbh = C4::Context->dbh;
- $fwcode='' unless $fwcode;
- my $sth;
- if (defined $subfield) {
- $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?');
- $sth->execute($field,$subfield,$fwcode);
- } else {
- $sth = $dbh->prepare('select authorised_value from marc_tag_structure where tagfield=? and frameworkcode=?');
- $sth->execute($field,$fwcode);
- }
- my ($authvalcode) = $sth->fetchrow_array;
- return $authvalcode;
-}
-
=head2 GetAuthorisedValues
$authvalues = GetAuthorisedValues([$category]);
return \@results;
}
-=head2 GetAuthorisedValueByCode
-
-$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
-
-Return the lib attribute from authorised_values from the row identified
-by the passed category and code
-
-=cut
-
-sub GetAuthorisedValueByCode {
- my ( $category, $authvalcode, $opac ) = @_;
-
- my $field = $opac ? 'lib_opac' : 'lib';
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT $field FROM authorised_values WHERE category=? AND authorised_value =?");
- $sth->execute( $category, $authvalcode );
- while ( my $data = $sth->fetchrow_hashref ) {
- return $data->{ $field };
- }
-}
-
-=head2 GetKohaAuthorisedValues
-
-Takes $kohafield, $fwcode as parameters.
-
-If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
-
-Returns hashref of Code => description
-
-Returns undef if no authorised value category is defined for the kohafield.
-
-=cut
-
-sub GetKohaAuthorisedValues {
- my ($kohafield,$fwcode,$opac) = @_;
- $fwcode='' unless $fwcode;
- my %values;
- my $dbh = C4::Context->dbh;
- my $avcode = GetAuthValCode($kohafield,$fwcode);
- if ($avcode) {
- my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
- $sth->execute($avcode);
- while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
- $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
- }
- return \%values;
- } else {
- return;
- }
-}
-
-=head2 GetKohaAuthorisedValuesFromField
-
-Takes $field, $subfield, $fwcode as parameters.
-
-If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
-$subfield can be undefined
-
-Returns hashref of Code => description
-
-Returns undef if no authorised value category is defined for the given field and subfield
-
-=cut
-
-sub GetKohaAuthorisedValuesFromField {
- my ($field, $subfield, $fwcode,$opac) = @_;
- $fwcode='' unless $fwcode;
- my %values;
- my $dbh = C4::Context->dbh;
- my $avcode = GetAuthValCodeFromField($field, $subfield, $fwcode);
- if ($avcode) {
- my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
- $sth->execute($avcode);
- while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
- $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
- }
- return \%values;
- } else {
- return;
- }
-}
-
-=head2 GetKohaAuthorisedValuesMapping
-
-Takes a hash as a parameter. The interface key indicates the
-description to use in the mapping.
-
-Returns hashref of:
- "{kohafield},{frameworkcode},{authorised_value}" => "{description}"
-for all the kohafields, frameworkcodes, and authorised values.
-
-Returns undef if nothing is found.
-
-=cut
-
-sub GetKohaAuthorisedValuesMapping {
- my ($parameter) = @_;
- my $interface = $parameter->{'interface'} // '';
-
- my $query_mapping = q{
-SELECT TA.kohafield,TA.authorised_value AS category,
- TA.frameworkcode,TB.authorised_value,
- IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC,
- TB.lib AS Intranet,TB.lib_opac
-FROM marc_subfield_structure AS TA JOIN
- authorised_values as TB ON
- TA.authorised_value=TB.category
-WHERE TA.kohafield>'' AND TA.authorised_value>'';
- };
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare($query_mapping);
- $sth->execute();
- my $avmapping;
- if ($interface eq 'opac') {
- while (my $row = $sth->fetchrow_hashref) {
- $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC};
- }
- }
- else {
- while (my $row = $sth->fetchrow_hashref) {
- $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet};
- }
- }
- return $avmapping;
-}
-
=head2 xml_escape
my $escaped_string = C4::Koha::xml_escape($string);