Bug 8753: [QA Follow-up] Primary key and collation
[srvgit] / opac / opac-search.pl
index 7d21354..8157e7d 100755 (executable)
@@ -43,6 +43,8 @@ use C4::SocialData;
 use C4::Ratings;
 use C4::External::OverDrive;
 
+use Koha::LibraryCategories;
+
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
 use JSON qw/decode_json encode_json/;
@@ -201,9 +203,8 @@ if ($cgi->cookie("search_path_code")) {
 }
 
 my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
-$template->param(
-    searchdomainloop => GetBranchCategories('searchdomain'),
-);
+my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
+$template->param( searchdomainloop => $library_categories );
 
 # load the language limits (for search)
 my $languages_limit_loop = getLanguages($lang, 1);
@@ -211,6 +212,15 @@ $template->param(search_languages_loop => $languages_limit_loop,);
 
 # load the Type stuff
 my $itemtypes = GetItemTypesCategorized;
+# add translated_description to itemtypes
+foreach my $itemtype ( keys %{$itemtypes} ) {
+    # Itemtypes search categories don't have (yet) translated descriptions, they are auth values
+    my $translated_description = getitemtypeinfo( $itemtype, 'opac' )->{translated_description};
+    $itemtypes->{$itemtype}->{translated_description} =
+            ( $translated_description ) ? $translated_description : $itemtypes->{$itemtype}->{description};
+}
+# Load the Type stuff without search categories for facets
+my $itemtypes_nocategory = GetItemTypes;
 # the index parameter is different for item-level itemtypes
 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
 my @advancedsearchesloop;
@@ -236,13 +246,13 @@ foreach my $advanced_srch_type (@advanced_search_types) {
    if ($advanced_srch_type eq 'itemtypes') {
    # itemtype is a special case, since it's not defined in authorized values
         my @itypesloop;
-       foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
+        foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } keys %$itemtypes ) {
             next if $hidingrules->{itype} && any { $_ eq $thisitemtype } @{$hidingrules->{itype}};
             next if $hidingrules->{itemtype} && any { $_ eq $thisitemtype } @{$hidingrules->{itemtype}};
            my %row =(  number=>$cnt++,
                ccl => "$itype_or_itemtype,phr",
                 code => $thisitemtype,
-                description => $itemtypes->{$thisitemtype}->{'description'},
+                description => $itemtypes->{$thisitemtype}->{translated_description},
                 imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
                 cat => $itemtypes->{$thisitemtype}->{'iscat'},
                 hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'},
@@ -508,16 +518,17 @@ my $hits;
 my $expanded_facet = $params->{'expand'};
 
 # Define some global variables
-my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type);
+my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
 
 my @results;
 
 ## I. BUILD THE QUERY
-( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
+( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
 
 sub _input_cgi_parse {
     my @elements;
-    for my $this_cgi ( split('&',shift) ) {
+    my $query_cgi = shift or return @elements;
+    for my $this_cgi ( split('&',$query_cgi) ) {
         next unless $this_cgi;
         $this_cgi =~ /(.*?)=(.*)/;
         push @elements, { input_name => $1, input_value => Encode::decode_utf8( uri_unescape($2) ) };
@@ -546,7 +557,7 @@ if (C4::Context->preference('OpacSuppression')) {
         my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
         if ($IPAddress !~ /^$IPRange/)  {
             if ( $query_type eq 'pqf' ) {
-                $query = '@not '.$query.' @attr 1=9011 1';
+                $query = '@not '.$query.' @attr 14=1 @attr 1=9011 1';
             } else {
                 $query = "($query) not Suppress=1";
             }
@@ -555,7 +566,7 @@ if (C4::Context->preference('OpacSuppression')) {
     else {
         if ( $query_type eq 'pqf' ) {
             #$query = "($query) && -(suppress:1)"; #QP syntax
-            $query = '@not '.$query.' @attr 1=9011 1'; #PQF syntax
+            $query = '@not '.$query.' @attr 14=1 @attr 1=9011 1'; #PQF syntax
         } else {
             $query = "($query) not Suppress=1";
         }
@@ -592,7 +603,7 @@ if ($tag) {
     $pasarParams .= '&simple_query=' . uri_escape_utf8($simple_query);
     $pasarParams .= '&query_type=' . uri_escape_utf8($query_type) if ($query_type);
     eval {
-        ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan,1);
+        ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes_nocategory,$query_type,$scan,1);
     };
 }
 # This sorts the facets into alphabetical order
@@ -768,7 +779,6 @@ for (my $i=0;$i<@servers;$i++) {
             if ($query_desc || $limit_desc) {
                 $template->param(searchdesc => 1);
             }
-            $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed;
             $template->param(results_per_page =>  $results_per_page);
             my $hide = C4::Context->preference('OpacHiddenItems');
             $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines
@@ -939,19 +949,29 @@ if ($query_desc || $limit_desc) {
 }
 
 # VI. BUILD THE TEMPLATE
-# Build drop-down list for 'Add To:' menu...
-my ($totalref, $pubshelves, $barshelves)=
-       C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
+my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 1,
+    }
+);
+my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 2,
+    }
+);
+
 $template->param(
-       addbarshelves     => $totalref->{bartotal},
-       addbarshelvesloop => $barshelves,
-       addpubshelves     => $totalref->{pubtotal},
-       addpubshelvesloop => $pubshelves,
-       );
+    add_to_some_private_shelves => $some_private_shelves,
+    add_to_some_public_shelves  => $some_public_shelves,
+);
 
 my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
 
-# If GoogleIndicTransliteration system preference is On Set paramter to load Google's javascript in OPAC search screens 
+# If GoogleIndicTransliteration system preference is On Set parameter to load Google's javascript in OPAC search screens
 if (C4::Context->preference('GoogleIndicTransliteration')) {
         $template->param('GoogleIndicTransliteration' => 1);
 }