@ISA = qw(Exporter);
@EXPORT = qw(
&GetPrinters &GetPrinter
- &GetItemTypes &getitemtypeinfo
+ &getitemtypeinfo
&GetItemTypesCategorized
&getallthemes
&getFacets
=cut
-=head2 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
-
- my $itemtypes = GetItemTypes;
- my @itemtypesloop;
- foreach my $thisitemtype (sort keys %$itemtypes) {
- my $selected = 1 if $thisitemtype eq $itemtype;
- my %row =(value => $thisitemtype,
- selected => $selected,
- description => $itemtypes->{$thisitemtype}->{'description'},
- );
- push @itemtypesloop, \%row;
- }
- $template->param(itemtypeloop => \@itemtypesloop);
-
-=head3 in TEMPLATE
-
- <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
- <select name="itemtype">
- <option value="">Default</option>
- <!-- TMPL_LOOP name="itemtypeloop" -->
- <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="description" --></option>
- <!-- /TMPL_LOOP -->
- </select>
- <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
- <input type="submit" value="OK" class="button">
- </form>
-
-=cut
-
-sub GetItemTypes {
- my ( %params ) = @_;
- my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash';
-
- require C4::Languages;
- my $language = C4::Languages::getlanguage();
- # returns a reference to a hash of references to itemtypes...
- my $dbh = C4::Context->dbh;
- my $query = q|
- SELECT
- itemtypes.itemtype,
- itemtypes.description,
- itemtypes.rentalcharge,
- itemtypes.notforloan,
- itemtypes.imageurl,
- itemtypes.summary,
- itemtypes.checkinmsg,
- itemtypes.checkinmsgtype,
- itemtypes.sip_media_type,
- itemtypes.hideinopac,
- itemtypes.searchcategory,
- COALESCE( localization.translation, itemtypes.description ) AS translated_description
- FROM itemtypes
- LEFT JOIN localization ON itemtypes.itemtype = localization.code
- AND localization.entity = 'itemtypes'
- AND localization.lang = ?
- ORDER BY itemtype
- |;
- my $sth = $dbh->prepare($query);
- $sth->execute( $language );
-
- if ( $style eq 'hash' ) {
- my %itemtypes;
- while ( my $IT = $sth->fetchrow_hashref ) {
- $itemtypes{ $IT->{'itemtype'} } = $IT;
- }
- return ( \%itemtypes );
- } else {
- return [ sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @{ $sth->fetchall_arrayref( {} ) } ];
- }
-}
-
=head2 GetItemTypesCategorized
$categories = GetItemTypesCategorized();
use Koha::AuthorisedValue;
use Koha::AuthorisedValueCategories;
-use Test::More tests => 8;
+use Test::More tests => 7;
use DateTime::Format::MySQL;
BEGIN {
is_deeply(\@results,\@expected, 'GetItemTypesCategorized: grouped and ungrouped items returned as expected.');
};
-subtest 'GetItemTypes test' => sub {
- plan tests => 1;
- $dbh->do(q|DELETE FROM itemtypes|);
- $dbh->do(q|INSERT INTO itemtypes(itemtype, description) VALUES ('a', 'aa desc'), ('b', 'zz desc'), ('d', 'dd desc'), ('c', 'yy desc')|);
- my $itemtypes = C4::Koha::GetItemTypes( style => 'array' );
- $itemtypes = [ map { $_->{itemtype} } @$itemtypes ];
- is_deeply( $itemtypes, [ 'a', 'd', 'c', 'b' ], 'GetItemTypes(array) should return itemtypes ordered by description');
-};
-
$dbh->rollback();