X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FKoha.pm;h=420295793d1a8842e55770532241442c423cd755;hb=e52b493611766b61a0018350adc590ab07e9c94b;hp=c0040f63bd3af0d60a10d6d3e44852f6f43e250b;hpb=6e13cc1aad8d0523bd06d9f6bfecbae9e524ff6c;p=koha_fer diff --git a/C4/Koha.pm b/C4/Koha.pm index c0040f63bd..420295793d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -25,10 +25,11 @@ 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); +use DBI qw(:sql_types); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); @@ -41,7 +42,6 @@ BEGIN { &subfield_is_koha_internal_p &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo - &GetCcodes &GetSupportName &GetSupportList &get_itemtypeinfos_of &getframeworks &getframeworkinfo @@ -57,12 +57,14 @@ BEGIN { &getitemtypeimagelocation &GetAuthorisedValues &GetAuthorisedValueCategories + &IsAuthorisedValueCategory &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib &GetAuthorisedValueByCode &GetKohaImageurlFromAuthorisedValues &GetAuthValCode + &AddAuthorisedValue &GetNormalizedUPC &GetNormalizedISBN &GetNormalizedEAN @@ -172,16 +174,16 @@ build a HTML select with the following code : =head3 in TEMPLATE -
- - "> - -
+ =cut @@ -204,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 @@ -240,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; @@ -250,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 { @@ -272,27 +286,6 @@ END_SQL return get_infos_of( $query, 'itemtype', undef, \@itemtypes ); } -# this is temporary until we separate collection codes and item types -sub GetCcodes { - my $count = 0; - my @results; - my $dbh = C4::Context->dbh; - my $sth = - $dbh->prepare( - "SELECT * FROM authorised_values ORDER BY authorised_value"); - $sth->execute; - while ( my $data = $sth->fetchrow_hashref ) { - if ( $data->{category} eq "CCODE" ) { - $count++; - $results[$count] = $data; - - #warn "data: $data"; - } - } - $sth->finish; - return ( $count, @results ); -} - =head2 getauthtypes $authtypes = &getauthtypes(); @@ -708,7 +701,7 @@ sub getFacets { idx => 'au', label => 'Authors', tags => [ qw/ 700ab 701ab 702ab / ], - sep => ', ', + sep => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"), }, { idx => 'se', @@ -716,6 +709,11 @@ sub getFacets { tags => [ qw/ 225a / ], sep => ', ', }, + { + idx => 'location', + label => 'Location', + tags => [ qw/ 995c / ], + } ]; my $library_facet; @@ -725,12 +723,6 @@ sub getFacets { label => 'Libraries', tags => [ qw/ 995b / ], }; - } else { - $library_facet = { - idx => 'location', - label => 'Location', - tags => [ qw/ 995c / ], - }; } push( @$facets, $library_facet ); } @@ -778,6 +770,11 @@ sub getFacets { tags => [ qw/ 952y 942c / ], sep => ', ', }, + { + idx => 'location', + label => 'Location', + tags => [ qw / 952c / ], + }, ]; my $library_facet; @@ -787,12 +784,6 @@ sub getFacets { label => 'Libraries', tags => [ qw / 952b / ], }; - } else { - $library_facet = { - idx => 'location', - label => 'Location', - tags => [ qw / 952c / ], - }; } push( @$facets, $library_facet ); } @@ -911,13 +902,13 @@ like: { '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, }, @@ -1062,7 +1053,11 @@ sub GetAuthorisedValues { if(@where_strings > 0) { $query .= " WHERE " . join(" AND ", @where_strings); } - $query .= " GROUP BY lib ORDER BY category, lib, lib_opac"; + $query .= " GROUP BY lib"; + $query .= ' ORDER BY category, ' . ( + $opac ? 'COALESCE(lib_opac, lib)' + : 'lib, lib_opac' + ); my $sth = $dbh->prepare($query); @@ -1104,9 +1099,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 @@ -1226,6 +1243,26 @@ sub GetKohaAuthorisedValueLib { 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); @@ -1405,24 +1442,23 @@ sub GetDailyQuote { $sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;'); $sth->execute; my $range = ($sth->fetchrow_array)[0]; - if ($range > 1) { - # chose a random id within that range if there is more than one quote - my $id = int(rand($range)); - # grab it - $query = 'SELECT * FROM quotes WHERE id = ?;'; - $sth = C4::Context->dbh->prepare($query); - $sth->execute($id); - } - else { - $query = 'SELECT * FROM quotes;'; - $sth = C4::Context->dbh->prepare($query); - $sth->execute(); - } + # chose a random id within that range if there is more than one quote + my $offset = int(rand($range)); + # grab it + $query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?'; + $sth = C4::Context->dbh->prepare($query); + # see http://www.perlmonks.org/?node_id=837422 for why + # we're being verbose and using bind_param + $sth->bind_param(1, $offset, SQL_INTEGER); + $sth->execute(); $quote = $sth->fetchrow_hashref(); # 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; }