Bug 24488: perf - Group by at DBMS level
[srvgit] / opac / opac-shelves.pl
index e9dfa25..b94b412 100755 (executable)
@@ -22,6 +22,7 @@ use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Biblio;
+use C4::External::BakerTaylor qw( image_url link_url );
 use C4::Koha;
 use C4::Items;
 use C4::Members;
@@ -32,6 +33,7 @@ use C4::XSLT;
 use Koha::Biblios;
 use Koha::Biblioitems;
 use Koha::CirculationRules;
+use Koha::CsvProfiles;
 use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
@@ -40,7 +42,7 @@ use Koha::RecordProcessor;
 
 use constant ANYONE => 2;
 
-my $query = new CGI;
+my $query = CGI->new;
 
 my $template_name = $query->param('rss') ? "opac-shelves-rss.tt" : "opac-shelves.tt";
 
@@ -50,14 +52,32 @@ if ( ! C4::Context->preference('virtualshelves') ) {
     exit;
 }
 
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
-        template_name   => $template_name,
-        query           => $query,
-        type            => "opac",
-        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
-    });
+my $op = $query->param('op') || 'list';
+my ( $template, $loggedinuser, $cookie );
+
+if( $op eq 'view' || $op eq 'list' ){
+    ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+            template_name   => $template_name,
+            query           => $query,
+            type            => "opac",
+            authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
+        });
+} else {
+    ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+            template_name   => $template_name,
+            query           => $query,
+            type            => "opac",
+            authnotrequired => 0,
+        });
+}
+
+if (C4::Context->preference("BakerTaylorEnabled")) {
+    $template->param(
+        BakerTaylorImageURL => &image_url(),
+        BakerTaylorLinkURL  => &link_url(),
+    );
+}
 
-my $op       = $query->param('op')       || 'list';
 my $referer  = $query->param('referer')  || $op;
 my $category = $query->param('category') || 1;
 my ( $shelf, $shelfnumber, @messages );
@@ -114,7 +134,7 @@ if ( $op eq 'add_form' ) {
     if ( $shelf ) {
         $op = $referer;
         my $sortfield = $query->param('sortfield');
-        $sortfield = 'title' unless grep {/^$sortfield$/}qw( title author copyrightdate itemcallnumber dateadded );
+        $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded );
         if ( $shelf->can_be_managed( $loggedinuser ) ) {
             $shelf->shelfname( scalar $query->param('shelfname') );
             $shelf->sortfield( $sortfield );
@@ -281,7 +301,7 @@ if ( $op eq 'view' ) {
 
             my $art_req_itypes;
             if( C4::Context->preference('ArticleRequests') ) {
-                $art_req_itypes = Koha::IssuingRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
+                $art_req_itypes = Koha::CirculationRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
             }
 
             my @items;
@@ -297,9 +317,17 @@ if ( $op eq 'view' ) {
                 });
                 $record_processor->process($record);
 
-                if ( $xslfile ) {
-                    $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTListsDisplay",
-                                                                1, undef, $sysxml, $xslfile, $lang);
+                if ($xslfile) {
+                    my $variables = {
+                        anonymous_session => ($loggedinuser) ? 0 : 1
+                    };
+                    $this_item->{XSLTBloc} = XSLTParse4Display(
+                        $biblionumber,          $record,
+                        "OPACXSLTListsDisplay", 1,
+                        undef,                  $sysxml,
+                        $xslfile,               $lang,
+                        $variables
+                    );
                 }
 
                 my $marcflavour = C4::Context->preference("marcflavour");
@@ -358,6 +386,11 @@ if ( $op eq 'view' ) {
                 itemsloop          => \@items,
                 sortfield          => $sortfield,
                 direction          => $direction,
+                csv_profiles => [
+                    Koha::CsvProfiles->search(
+                        { type => 'marc', used_for => 'export_records', staff_only => 0 }
+                    )
+                ],
             );
             if ( $page ) {
                 my $pager = $contents->pager;
@@ -406,4 +439,5 @@ $template->param(
     listsview => 1,
 );
 
-output_html_with_http_headers $query, $cookie, $template->output;
+my $content_type = $query->param('rss')? 'rss' : 'html';
+output_with_http_headers $query, $cookie, $template->output, $content_type;