X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FKoha.pm;h=ea8c2a69bbcda25f1725adfba9992c3721275ff5;hb=a36b3ad43a6a91f800d0d8a148a217d738236d7e;hp=6869ab07788a651ae64945cc3a2c4308eecc7ef1;hpb=7928a05201cc19955bc808f3ba98fa0e3846e0df;p=koha.git diff --git a/C4/Koha.pm b/C4/Koha.pm index 6869ab0778..ea8c2a69bb 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -25,8 +25,8 @@ use strict; 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); @@ -57,6 +57,7 @@ BEGIN { &getitemtypeimagelocation &GetAuthorisedValues &GetAuthorisedValueCategories + &IsAuthorisedValueCategory &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib @@ -205,10 +206,15 @@ sub GetSupportList{ } =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 @@ -241,6 +247,8 @@ build a HTML select with the following code : =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; @@ -251,10 +259,15 @@ sub GetItemTypes { |; 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 { @@ -1105,9 +1118,31 @@ sub 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 @@ -1443,7 +1478,10 @@ sub GetDailyQuote { # 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; }