Bug 25416: Let OPAC XSLTs know if the context is an anonymous session
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 7 May 2020 17:23:40 +0000 (14:23 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 15 May 2020 08:33:22 +0000 (09:33 +0100)
This patch makes use of the 'variables' parameter in XSLTParse4Display
method in the different places that it is used in the OPAC. It does by
passing this parameter with

    anonymous_session => 1|0

The value will depend on the output from get_template_and_user (i.e. if
there's a returned borrowernumber).

A special case takes place in search results, as the call to
XSLTParse4Display happens in C4::Search::searchResults. So a new
parameter 'xslt_variables' is added to it.

To test:
1. Apply the [DO NOT PUSH] patch
2. Open the OPAC in your browser
3. Try detail pages, search results, tags and lists/shelves pages with
   or without an active session
=> FAIL: It always says (somewhere) 'Anonymous session: Yes'
4. Apply this patch, restart_all
5. Repeat 3
=> SUCCESS: It will tell the Yes/No correctly regarding anonymous
sessions!
6. Sign off :-D

Sponsored-by: Universidad ORT Uruguay
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Search.pm
opac/opac-detail.pl
opac/opac-search.pl
opac/opac-shelves.pl
opac/opac-tags.pl

index a10e50f..0ab24a5 100644 (file)
@@ -1677,7 +1677,7 @@ Format results in a form suitable for passing to the template
 # IMO this subroutine is pretty messy still -- it's responsible for
 # building the HTML output for the template
 sub searchResults {
-    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_;
+    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults, $xslt_variables ) = @_;
     my $dbh = C4::Context->dbh;
     my @newresults;
 
@@ -2087,7 +2087,7 @@ sub searchResults {
         # XSLT processing of some stuff
         # we fetched the sysprefs already before the loop through all retrieved record!
         if (!$scan && $xslfile) {
-            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang);
+            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables);
         }
 
         # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
index b3e8dbd..5c1880f 100755 (executable)
@@ -170,11 +170,16 @@ my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
 
 if ( $xslfile ) {
+
+    my $variables = {
+        anonymous_session => ($borrowernumber) ? 0 : 1
+    };
+
     $template->param(
         XSLTBloc => XSLTParse4Display(
-                        $biblionumber, $record, "OPACXSLTDetailsDisplay",
-                        1, undef, $sysxml, $xslfile, $lang
-                    )
+            $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
+            $sysxml, $xslfile, $lang, $variables
+        )
     );
 }
 
index 01887f2..54655d8 100755 (executable)
@@ -650,6 +650,8 @@ if (C4::Context->preference('OpacHiddenItemsExceptions')){
     $search_context->{'category'} = $patron ? $patron->categorycode : q{};
 }
 
+my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1 };
+
 for (my $i=0;$i<@servers;$i++) {
     my $server = $servers[$i];
     if ($server && $server =~/biblioserver/) { # this is the local bibliographic server
@@ -662,12 +664,12 @@ for (my $i=0;$i<@servers;$i++) {
                 # we want as specified by $offset and $results_per_page,
                 # we need to set the offset parameter of searchResults to 0
                 my @group_results = searchResults( $search_context, $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
-                                                   $group->{"RECORDS"});
+                                                   $group->{"RECORDS"}, $variables);
                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
             }
         } else {
             @newresults = searchResults( $search_context, $query_desc, $hits, $results_per_page, $offset, $scan,
-                                        $results_hashref->{$server}->{"RECORDS"});
+                                        $results_hashref->{$server}->{"RECORDS"}, $variables);
         }
         $hits = 0 unless @newresults;
 
index c0140c7..e2ac9aa 100755 (executable)
@@ -316,9 +316,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");
index 39e756a..b125f8c 100755 (executable)
@@ -284,10 +284,16 @@ if ($loggedinuser) {
         my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
         my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
 
-        if ( $xslfile ) {
+        if ($xslfile) {
+            my $variables = {
+                anonymous_session => ($loggedinuser) ? 0 : 1
+            };
             $tag->{XSLTBloc} = XSLTParse4Display(
-                    $tag->{ biblionumber }, $record, "OPACXSLTResultsDisplay",
-                    1, $hidden_items, $sysxml, $xslfile, $lang
+                $tag->{biblionumber},     $record,
+                "OPACXSLTResultsDisplay", 1,
+                $hidden_items,            $sysxml,
+                $xslfile,                 $lang,
+                $variables
             );
         }