Bug 12068 - label-create-pdf.pl Add support for RTL language
[koha.git] / opac / svc / suggestion
blob9c08565a7915a27a1c0461de0a28b3e3dd71b6b8
1 #!/usr/bin/perl
3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 =head1 NAME
22 opac-suggestion.pl : script to render suggestions for the OPAC
24 =head1 SYNOPSIS
26 =cut
28 =head1 DESCRIPTION
30 This script produces suggestions for the OPAC given a search string.
32 It takes the following parameters:
34 =over 8
36 =item I<q>
38 Required. Query string.
40 =item I<render>
42 If set to 'stub' render a stub HTML page suitable for inclusion into a
43 div via AJAX. If set to 'standalone', return a full page instead of the stub.
44 If not set, return JSON.
46 =item I<count>
48 Number of suggestions to display. Defaults to 4 in stub mode, 20 otherwise.
50 =back
52 =cut
54 use strict;
55 use warnings;
57 use C4::Auth;
58 use C4::Context;
59 use C4::Output;
60 use CGI;
61 use JSON;
62 use Koha::SuggestionEngine;
64 my $query = new CGI;
66 my $dbh = C4::Context->dbh;
68 my $search = $query->param('q') || '';
69 my $render = $query->param('render') || '';
70 my $count = $query->param('count') || ( $render eq 'stub' ? 4 : 20 );
72 # open template
73 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
75 template_name => "svc/suggestion.tt",
76 query => $query,
77 type => "opac",
78 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
79 debug => 1,
83 my @plugins = ();
85 my $pluginsconfig = from_json(C4::Context->preference('OPACdidyoumean') || '[]');
87 foreach my $plugin (@$pluginsconfig) {
88 push @plugins, $plugin->{name} if ($plugin->{enabled});
91 unless ( @plugins ) {
92 print $query->header;
93 exit;
96 my $suggestor = Koha::SuggestionEngine->new( { plugins => \@plugins } );
98 my $suggestions =
99 $suggestor->get_suggestions( { search => $search, count => $count } );
101 if ($render) {
102 $template->{VARS}->{render} = $render;
103 $template->{VARS}->{suggestions} = $suggestions if $suggestions;
104 output_html_with_http_headers $query, $cookie, $template->output;
106 else {
107 print $query->header;
108 print to_json($suggestions);