use C4::Context;
use C4::Branch qw(GetBranchesCount);
+use Koha::DateUtils qw(dt_from_string);
use Memoize;
-use DateTime;
use DateTime::Format::MySQL;
use autouse 'Data::Dumper' => qw(Dumper);
&getitemtypeimagelocation
&GetAuthorisedValues
&GetAuthorisedValueCategories
+ &IsAuthorisedValueCategory
&GetKohaAuthorisedValues
&GetKohaAuthorisedValuesFromField
&GetKohaAuthorisedValueLib
}
=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 {
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
# update the timestamp for that quote
$query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
$sth = C4::Context->dbh->prepare($query);
- $sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $quote->{'id'});
+ $sth->execute(
+ DateTime::Format::MySQL->format_datetime( dt_from_string() ),
+ $quote->{'id'}
+ );
}
return $quote;
}