From 57b3b951c113f8603673540a880e6a7e78e38241 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Tue, 29 Apr 2008 18:20:26 -0500 Subject: [PATCH] Bug 2047: adding images to arbitrary authorized values I've refactored the subs I added in the previous commit so that they make a little more sense and are in better places in the code base. I was really hoping to make use of existing subs, but they all seemed so specific to particular uses. The icons now show up on the OPAC item details page. TODO: The icons still don't show up in the OPAC search results page. Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 60 +++++++++++ C4/Items.pm | 100 ++++++++++++++++++ C4/Search.pm | 1 + .../prog/en/modules/catalogue/results.tmpl | 9 ++ .../prog/en/modules/opac-detail.tmpl | 10 +- opac/opac-detail.pl | 50 +++++---- 6 files changed, 211 insertions(+), 19 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index a6f0a2837a..08c17c34b5 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3075,6 +3075,66 @@ sub set_service_options { return $serviceOptions; } +=head3 get_biblio_authorised_values + + find the types and values for all authorised values assigned to this biblio. + + parameters: + biblionumber + + returns: a hashref malling the authorised value to the value set for this biblionumber + + $authorised_values = { + 'Scent' => 'flowery', + 'Audience' => 'Young Adult', + 'itemtypes' => 'SER', + }; + + Notes: forlibrarian should probably be passed in, and called something different. + + +=cut + +sub get_biblio_authorised_values { + my $biblionumber = shift; + + my $forlibrarian = 1; # are we in staff or opac? + my $frameworkcode = GetFrameworkCode( $biblionumber ); + + my $authorised_values; + + my $record = GetMarcBiblio( $biblionumber ); + my $tagslib = GetMarcStructure( $forlibrarian, $frameworkcode ); + + # assume that these entries in the authorised_value table are bibliolevel. + # ones that start with 'item%' are item level. + my $query = q(SELECT distinct authorised_value, kohafield + FROM marc_subfield_structure + WHERE authorised_value !='' + AND (kohafield like 'biblio%' + OR kohafield like '') ); + my $bibliolevel_authorised_values = C4::Context->dbh->selectall_hashref( $query, 'authorised_value' ); + + foreach my $tag ( keys( %$tagslib ) ) { + foreach my $subfield ( keys( %{$tagslib->{ $tag }} ) ) { + # warn "checking $subfield. type is: " . ref $tagslib->{ $tag }{ $subfield }; + if ( 'HASH' eq ref $tagslib->{ $tag }{ $subfield } ) { + if ( exists $tagslib->{ $tag }{ $subfield }{'authorised_value'} && exists $bibliolevel_authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } ) { + if ( defined $record->field( $tag ) ) { + my $this_subfield_value = $record->field( $tag )->subfield( $subfield ); + if ( defined $this_subfield_value ) { + $authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } = $this_subfield_value; + } + } + } + } + } + } + # warn ( Data::Dumper->Dump( [ $authorised_values ], [ 'authorised_values' ] ) ); + return $authorised_values; +} + + 1; __END__ diff --git a/C4/Items.pm b/C4/Items.pm index 825667f8a6..685d85e408 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1315,6 +1315,106 @@ sub GetItemnumberFromBarcode { return ($result); } +=head3 get_item_authorised_values + + find the types and values for all authorised values assigned to this item. + + parameters: + itemnumber + + returns: a hashref malling the authorised value to the value set for this itemnumber + + $authorised_values = { + 'CCODE' => undef, + 'DAMAGED' => '0', + 'LOC' => '3', + 'LOST' => '0' + 'NOT_LOAN' => '0', + 'RESTRICTED' => undef, + 'STACK' => undef, + 'WITHDRAWN' => '0', + 'branches' => 'CPL', + 'cn_source' => undef, + 'itemtypes' => 'SER', + }; + + Notes: see C4::Biblio::get_biblio_authorised_values for a similar method at the biblio level. + +=cut + +sub get_item_authorised_values { + my $itemnumber = shift; + + # assume that these entries in the authorised_value table are item level. + my $query = q(SELECT distinct authorised_value, kohafield + FROM marc_subfield_structure + WHERE kohafield like 'item%' + AND authorised_value != '' ); + + my $itemlevel_authorised_values = C4::Context->dbh->selectall_hashref( $query, 'authorised_value' ); + my $iteminfo = GetItem( $itemnumber ); + # warn( Data::Dumper->Dump( [ $itemlevel_authorised_values ], [ 'itemlevel_authorised_values' ] ) ); + my $return; + foreach my $this_authorised_value ( keys %$itemlevel_authorised_values ) { + my $field = $itemlevel_authorised_values->{ $this_authorised_value }->{'kohafield'}; + $field =~ s/^items\.//; + if ( exists $iteminfo->{ $field } ) { + $return->{ $this_authorised_value } = $iteminfo->{ $field }; + } + } + # warn( Data::Dumper->Dump( [ $return ], [ 'return' ] ) ); + return $return; +} + +=head3 get_authorised_value_images + + find a list of icons that are appropriate for display based on the + authorised values for a biblio. + + parameters: listref of authorised values, such as comes from + get_item_ahtorised_values or + from C4::Biblio::get_biblio_authorised_values + + returns: listref of hashrefs for each image. Each hashref looks like + this: + + { imageurl => '/intranet-tmpl/prog/img/itemtypeimg/npl/WEB.gif', + label => '', + category => '', + value => '', } + + Notes: Currently, I put on the full path to the images on the staff + side. This should either be configurable or not done at all. Since I + have to deal with 'intranet' or 'opac' in + get_biblio_authorised_values, perhaps I should be passing it in. + +=cut + +sub get_authorised_value_images { + my $authorised_values = shift; + + my @imagelist; + + my $authorised_value_list = GetAuthorisedValues(); + # warn ( Data::Dumper->Dump( [ $authorised_value_list ], [ 'authorised_value_list' ] ) ); + foreach my $this_authorised_value ( @$authorised_value_list ) { + if ( exists $authorised_values->{ $this_authorised_value->{'category'} } + && $authorised_values->{ $this_authorised_value->{'category'} } eq $this_authorised_value->{'authorised_value'} ) { + # warn ( Data::Dumper->Dump( [ $this_authorised_value ], [ 'this_authorised_value' ] ) ); + if ( defined $this_authorised_value->{'imageurl'} ) { + push @imagelist, { imageurl => C4::Koha::getitemtypeimagesrc( 'intranet' ) . '/' . $this_authorised_value->{'imageurl'}, + label => $this_authorised_value->{'lib'}, + category => $this_authorised_value->{'category'}, + value => $this_authorised_value->{'authorised_value'}, }; + } + } + } + + # warn ( Data::Dumper->Dump( [ \@imagelist ], [ 'imagelist' ] ) ); + return \@imagelist; + +} + =head1 LIMITED USE FUNCTIONS The following functions, while part of the public API, diff --git a/C4/Search.pm b/C4/Search.pm index bab365e5dc..4b597ebc47 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1481,6 +1481,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g; $oldbiblio->{orderedcount} = $ordered_count; $oldbiblio->{isbn} =~ s/-//g; # deleting - in isbn to enable amazon content + $oldbiblio->{'authorised_value_images'} = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'} ) ); push( @newresults, $oldbiblio ); } return @newresults; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl index 990a562acc..61a2d961b0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl @@ -298,6 +298,15 @@ $(window).load(function() { [">]

+ + +

+ + " /> + +

+ + No holds allowed diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index 7f4d51fad5..11c573156e 100755 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -171,6 +171,14 @@ + +
+ + " alt="" title=""> + +
+ +
@@ -259,7 +267,7 @@ - Item lost + " alt="" title="">Item lost Item Cancelled diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 792d204dfe..d881bbaa3c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -118,6 +118,8 @@ if (C4::Context->preference("RequestOnOpac")) { $RequestOnOpac = 1; } +my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber ) ); + my $norequests = 1; my %itemfields; for my $itm (@items) { @@ -139,29 +141,41 @@ for my $itm (@items) { $itemfields{ccode} = 1 if($itm->{ccode}); $itemfields{enumchron} = 1 if($itm->{enumchron}); $itemfields{copynumber} = 1 if($itm->{copynumber}); + + # walk through the item-level authorised values and populate some images + my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) ); + # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) ); + + if ( $itm->{'itemlost'} ) { + my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images; + $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' }; + $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' }; + } + } ## get notes and subjects from MARC record - my $dbh = C4::Context->dbh; - my $marcflavour = C4::Context->preference("marcflavour"); - my $record = GetMarcBiblio($biblionumber); - my $marcnotesarray = GetMarcNotes ($record,$marcflavour); - my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); - my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); - my $marcseriesarray = GetMarcSeries ($record,$marcflavour); - my $marcurlsarray = GetMarcUrls ($record,$marcflavour); +my $dbh = C4::Context->dbh; +my $marcflavour = C4::Context->preference("marcflavour"); +my $record = GetMarcBiblio($biblionumber); +my $marcnotesarray = GetMarcNotes ($record,$marcflavour); +my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); +my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); +my $marcseriesarray = GetMarcSeries ($record,$marcflavour); +my $marcurlsarray = GetMarcUrls ($record,$marcflavour); $template->param( - MARCNOTES => $marcnotesarray, - MARCSUBJCTS => $marcsubjctsarray, - MARCAUTHORS => $marcauthorsarray, - MARCSERIES => $marcseriesarray, - MARCURLS => $marcurlsarray, - norequests => $norequests, - RequestOnOpac=>$RequestOnOpac, - itemdata_ccode => $itemfields{ccode}, - itemdata_enumchron => $itemfields{enumchron}, - itemdata_copynumber => $itemfields{copynumber}, + MARCNOTES => $marcnotesarray, + MARCSUBJCTS => $marcsubjctsarray, + MARCAUTHORS => $marcauthorsarray, + MARCSERIES => $marcseriesarray, + MARCURLS => $marcurlsarray, + norequests => $norequests, + RequestOnOpac => $RequestOnOpac, + itemdata_ccode => $itemfields{ccode}, + itemdata_enumchron => $itemfields{enumchron}, + itemdata_copynumber => $itemfields{copynumber}, + authorised_value_images => $biblio_authorised_value_images, ); foreach ( keys %{$dat} ) { -- 2.39.5