&getitemtypeimagelocation
&GetAuthorisedValues
&GetAuthorisedValueCategories
+ &IsAuthorisedValueCategory
&GetKohaAuthorisedValues
&GetKohaAuthorisedValuesFromField
&GetKohaAuthorisedValueLib
&GetAuthorisedValueByCode
&GetKohaImageurlFromAuthorisedValues
&GetAuthValCode
+ &AddAuthorisedValue
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
}
=head2 GetItemTypes
- $itemtypes = &GetItemTypes();
+ $itemtypes = &GetItemTypes( style => $style );
Returns information about existing itemtypes.
+Params:
+ style: either 'array' or 'hash', defaults to 'hash'.
+ 'array' returns an arrayref,
+ 'hash' return a hashref with the itemtype value as the key
+
build a HTML select with the following code :
=head3 in PERL SCRIPT
=cut
sub GetItemTypes {
+ my ( %params ) = @_;
+ my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash';
# returns a reference to a hash of references to itemtypes...
my %itemtypes;
|;
my $sth = $dbh->prepare($query);
$sth->execute;
- while ( my $IT = $sth->fetchrow_hashref ) {
- $itemtypes{ $IT->{'itemtype'} } = $IT;
+
+ if ( $style eq 'hash' ) {
+ while ( my $IT = $sth->fetchrow_hashref ) {
+ $itemtypes{ $IT->{'itemtype'} } = $IT;
+ }
+ return ( \%itemtypes );
+ } else {
+ return $sth->fetchall_arrayref({});
}
- return ( \%itemtypes );
}
sub get_itemtypeinfos_of {
=head2 getitemtypeinfo
- $itemtype = &getitemtype($itemtype);
+ $itemtype = &getitemtypeinfo($itemtype, [$interface]);
-Returns information about an itemtype.
+Returns information about an itemtype. The optional $interface argument
+sets which interface ('opac' or 'intranet') to return the imageurl for.
+Defaults to intranet.
=cut
sub getitemtypeinfo {
- my ($itemtype) = @_;
+ my ($itemtype, $interface) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("select * from itemtypes where itemtype=?");
$sth->execute($itemtype);
my $res = $sth->fetchrow_hashref;
- $res->{imageurl} = getitemtypeimagelocation( 'intranet', $res->{imageurl} );
+ $res->{imageurl} = getitemtypeimagelocation( ( ( defined $interface && $interface eq 'opac' ) ? 'opac' : 'intranet' ), $res->{imageurl} );
return $res;
}
idx => 'au',
label => 'Authors',
tags => [ qw/ 700ab 701ab 702ab / ],
- sep => ', ',
+ sep => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"),
},
{
idx => 'se',
{
'checked' => 'checked',
- 'encoding' => 'MARC-8'
+ 'encoding' => 'utf8',
'icon' => undef,
'id' => 'LIBRARY OF CONGRESS',
'label' => '',
'name' => 'server',
'opensearch' => '',
- 'value' => 'z3950.loc.gov:7090/',
+ 'value' => 'lx2.loc.gov:210/',
'zed' => 1,
},
=cut
sub GetAuthorisedValues {
- my ($category,$selected,$opac) = @_;
+ my ( $category, $selected, $opac ) = @_;
+ my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
my @results;
my $dbh = C4::Context->dbh;
- my $query = "SELECT * FROM authorised_values";
- $query .= " WHERE category = '" . $category . "'" if $category;
- $query .= " ORDER BY category, lib, lib_opac";
+ my $query = qq{
+ SELECT *
+ FROM authorised_values
+ };
+ $query .= qq{
+ LEFT JOIN authorised_values_branches ON ( id = av_id )
+ } if $branch_limit;
+ my @where_strings;
+ my @where_args;
+ if($category) {
+ push @where_strings, "category = ?";
+ push @where_args, $category;
+ }
+ if($branch_limit) {
+ push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
+ push @where_args, $branch_limit;
+ }
+ if(@where_strings > 0) {
+ $query .= " WHERE " . join(" AND ", @where_strings);
+ }
+ $query .= " GROUP BY lib ORDER BY category, lib, lib_opac";
+
my $sth = $dbh->prepare($query);
- $sth->execute;
+
+ $sth->execute( @where_args );
while (my $data=$sth->fetchrow_hashref) {
- if ( (defined($selected)) && ($selected eq $data->{'authorised_value'}) ) {
- $data->{'selected'} = 1;
+ if ( defined $selected and $selected eq $data->{authorised_value} ) {
+ $data->{selected} = 1;
}
else {
- $data->{'selected'} = 0;
+ $data->{selected} = 0;
}
- if ($opac && $data->{'lib_opac'}) {
- $data->{'lib'} = $data->{'lib_opac'};
+
+ if ($opac && $data->{lib_opac}) {
+ $data->{lib} = $data->{lib_opac};
}
push @results, $data;
}
- #my $data = $sth->fetchall_arrayref({});
- return \@results; #$data;
+ $sth->finish;
+ return \@results;
}
=head2 GetAuthorisedValueCategories
return \@results;
}
+=head2 IsAuthorisedValueCategory
+
+ $is_auth_val_category = IsAuthorisedValueCategory($category);
+
+Returns whether a given category name is a valid one
+
+=cut
+
+sub IsAuthorisedValueCategory {
+ my $category = shift;
+ my $query = '
+ SELECT category
+ FROM authorised_values
+ WHERE BINARY category=?
+ LIMIT 1
+ ';
+ my $sth = C4::Context->dbh->prepare($query);
+ $sth->execute($category);
+ $sth->fetchrow ? return 1
+ : return 0;
+}
+
=head2 GetAuthorisedValueByCode
-$authhorised_value = GetAuthorisedValueByCode( $category, $authvalcode );
+$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
Return the lib attribute from authorised_values from the row identified
by the passed category and code
return $value;
}
+=head2 AddAuthorisedValue
+
+ AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl);
+
+Create a new authorised value.
+
+=cut
+
+sub AddAuthorisedValue {
+ my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my $query = qq{
+ INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl)
+ VALUES (?,?,?,?,?)
+ };
+ my $sth = $dbh->prepare($query);
+ $sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl);
+}
+
=head2 display_marc_indicators
my $display_form = C4::Koha::display_marc_indicators($field);