Bug 32983: ERM - Retrieve AVs from an endpoint
[koha-ffzg.git] / opac / opac-ISBDdetail.pl
index c79167c..b3b29de 100755 (executable)
@@ -41,21 +41,31 @@ the items attached to the biblio
 
 use Modern::Perl;
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Output;
+use C4::Output qw( parametrized_url output_html_with_http_headers );
 use CGI qw ( -utf8 );
-use C4::Biblio;
-use C4::Items;
+use C4::Biblio qw(
+    CountItemsIssued
+    GetISBDView
+    GetMarcControlnumber
+    GetMarcISSN
+    TransformMarcToKoha
+);
 use C4::Reserves;
-use C4::Acquisition;
-use C4::Serials;    # uses getsubscriptionfrom biblionumber
-use C4::Koha;
-use Koha::IssuingRules;
+use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
+use C4::Koha qw(
+    GetNormalizedEAN
+    GetNormalizedISBN
+    GetNormalizedOCLCNumber
+    GetNormalizedUPC
+);
+use Koha::CirculationRules;
 use Koha::ItemTypes;
 use Koha::Patrons;
 use Koha::RecordProcessor;
 use Koha::Biblios;
+use Koha::Util::MARC;
 
 my $query = CGI->new();
 my $biblionumber = $query->param('biblionumber');
@@ -73,17 +83,12 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         query           => $query,
         type            => "opac",
         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
-        debug           => 1,
     }
 );
 
 my $patron = Koha::Patrons->find($loggedinuser);
 
-my $opachiddenitems_rules;
-eval {
-    my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n";
-    $opachiddenitems_rules = YAML::Load($yaml);
-};
+my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
 
 unless ( $patron and $patron->category->override_hidden_items ) {
     # only skip this check if there's a logged in user
@@ -94,16 +99,18 @@ unless ( $patron and $patron->category->override_hidden_items ) {
     }
 }
 
-my $record      = $biblio->metadata->record;
-my $marcflavour = C4::Context->preference("marcflavour");
+my $record = $biblio->metadata->record;
+my @items  = $biblio->items->filter_by_visible_in_opac({ patron => $patron })->as_list;
 
-my $record_processor = Koha::RecordProcessor->new({
-    filters => 'ViewPolicy',
-    options => {
-        interface => 'opac',
-        frameworkcode => $biblio->frameworkcode
+my $record_processor = Koha::RecordProcessor->new(
+    {   filters => [ 'EmbedItems', 'ViewPolicy' ],
+        options => {
+            interface     => 'opac',
+            frameworkcode => $biblio->frameworkcode,
+            items         => \@items
+        }
     }
-});
+);
 $record_processor->process($record);
 
 # get biblionumbers stored in the cart
@@ -114,6 +121,7 @@ if(my $cart_list = $query->cookie("bib_list")){
     }
 }
 
+my $marcflavour = C4::Context->preference("marcflavour");
 # some useful variables for enhanced content;
 # in each case, we're grabbing the first value we find in
 # the record and normalizing it
@@ -135,7 +143,7 @@ $template->param(
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
-my $dat                 = TransformMarcToKoha( $record );
+my $dat                 = TransformMarcToKoha({ record => $record });
 
 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
 my @subs;
@@ -160,7 +168,6 @@ $template->param(
     subscriptionsnumber => $subscriptionsnumber,
 );
 
-my $norequests = 1;
 my $allow_onshelf_holds;
 my $res = GetISBDView({
     'record'    => $record,
@@ -170,15 +177,8 @@ my $res = GetISBDView({
 
 my $items = $biblio->items;
 while ( my $item = $items->next ) {
-    $norequests = 0
-      if $norequests
-        && !$item->withdrawn
-        && !$item->itemlost
-        && ($item->notforloan < 0 || not $item->notforloan )
-        && !Koha::ItemTypes->find($item->effective_itemtype)->notforloan
-        && $item->itemnumber;
-
-    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
+
+    $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
       unless $allow_onshelf_holds;
 }
 
@@ -186,8 +186,9 @@ if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_item
     $template->param( ReservableItems => 1 );
 }
 
+my $norequests = ! $items->filter_by_for_hold->count;
+
 $template->param(
-    RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
     norequests   => $norequests,
     ISBD         => $res,
     biblio       => $biblio,
@@ -201,6 +202,7 @@ my $issn = $marcissns->[0] || '';
 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
     $dat->{title} =~ s/\/+$//; # remove trailing slash
     $dat->{title} =~ s/\s+$//; # remove trailing space
+    my $oclc_no =  Koha::Util::MARC::oclc_number( $record );
     $search_for_title = parametrized_url(
         $search_for_title,
         {
@@ -210,6 +212,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
             ISSN          => $issn,
             CONTROLNUMBER => $marccontrolnumber,
             BIBLIONUMBER  => $biblionumber,
+            OCLC_NO       => $oclc_no,
         }
     );
     $template->param('OPACSearchForTitleIn' => $search_for_title);