View | Details | Raw Unified | Return to bug 17170
Collapse All | Expand All

(-)a/Koha/SearchFilter.pm (+92 lines)
Line 0 Link Here
1
package Koha::SearchFilter;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
20
use Koha::Database;
21
22
use base qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::SearchFilter - Koha Search filter object class
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 to_api_mapping
33
34
=cut
35
36
sub to_api_mapping {
37
    return {
38
        id                  => 'search_filter_id',
39
        query               => 'filter_query',
40
        limits              => 'filter_limits',
41
    };
42
}
43
44
=head3 expand_filter
45
46
    my $expanded_filter = $filter->expand_filter;
47
48
    Returns the filter as an arrayref of limit queries suitable to
49
    be passed to QueryBuilder
50
51
=cut
52
53
sub expand_filter {
54
    my $self = shift;
55
56
    my $query_part = $self->query;
57
    my $limits_part = $self->limits;
58
59
    my $limits = decode_json($limits_part)->{limits};
60
61
    my $query = decode_json($query_part);
62
    my $operators = $query->{operators};
63
    my $operands = $query->{operands};
64
    my $indexes = $query->{indexes};
65
66
    my $query_limit;
67
    for( my $i = 0; $i < scalar @$operands; $i++ ){
68
        next unless @$operands[$i];
69
        my $index = @$indexes[$i] ? @$indexes[$i] . "=" : "";
70
        my $query = "(" . @$operands[$i] . ")";
71
        my $operator = "";
72
        $operator = @$operators[$i-1] ? " " . @$operators[$i-1] . " " : scalar @$operands > $i ? " AND " : "" if $i > 0;
73
        my $limit = $operator . $index . $query;
74
        $query_limit .= $limit;
75
    }
76
77
    push @$limits, "(".$query_limit.")" if $query_limit;
78
79
    return $limits;
80
}
81
82
=head2 Internal methods
83
84
=head3 _type
85
86
=cut
87
88
sub _type {
89
    return 'SearchFilter';
90
}
91
92
1;
(-)a/Koha/SearchFilters.pm (+52 lines)
Line 0 Link Here
1
package Koha::SearchFilters;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
20
use Koha::Database;
21
22
use Koha::SearchFilter;
23
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::SearchFilters - Koha Search filters object set class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'SearchFilter';
42
}
43
44
=head3 object_class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::SearchFilter';
50
}
51
52
1;
(-)a/installer/data/mysql/atomicupdate/bug_17170.pl (+36 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "17170",
5
    description => "Add permission for creating saved search filters",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
10
            INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
11
            (3, 'manage_search_filters', 'Manage custom search filters');
12
        });
13
        say $out "Added manage_search_filters permission";
14
        unless( TableExists( 'search_filters' ) ){
15
            $dbh->do(q{
16
                CREATE TABLE `search_filters` (
17
                  id int(11) NOT NULL auto_increment, -- unique identifier for each search filter
18
                  name varchar(100) NOT NULL, -- display name for this filter
19
                  query mediumtext DEFAULT NULL, -- query part of the filter, can be blank
20
                  limits mediumtext DEFAULT NULL, -- limits part of the filter, can be blank
21
                  opac tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown on OPAC
22
                  staff_client tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown in staff client
23
                  PRIMARY KEY (id)
24
                ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
25
            });
26
            say $out "Added search_filters table";
27
        } else {
28
            say $out "search_filters table already created";
29
        }
30
        $dbh->do(q{
31
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
32
            ('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo')
33
        });
34
        say $out "Added SavedSearchFilters system preference";
35
    },
36
}
(-)a/installer/data/mysql/kohastructure.sql (+18 lines)
Lines 4523-4528 CREATE TABLE `search_field` ( Link Here
4523
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4523
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4524
/*!40101 SET character_set_client = @saved_cs_client */;
4524
/*!40101 SET character_set_client = @saved_cs_client */;
4525
4525
4526
--
4527
-- Table structure for table `search_filters`
4528
--
4529
4530
DROP TABLE IF EXISTS `search_filters`;
4531
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4532
/*!40101 SET character_set_client = utf8 */;
4533
CREATE TABLE `search_filters` (
4534
  `id` int(11) NOT NULL AUTO_INCREMENT,
4535
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
4536
  `query` mediumtext COLLATE utf8mb4_unicode_ci,
4537
  `limits` mediumtext COLLATE utf8mb4_unicode_ci,
4538
  `opac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown on OPAC',
4539
  `staff_client` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown in staff client',
4540
  PRIMARY KEY (`id`)
4541
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4542
/*!40101 SET character_set_client = @saved_cs_client */;
4543
4526
--
4544
--
4527
-- Table structure for table `search_history`
4545
-- Table structure for table `search_history`
4528
--
4546
--
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 588-593 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
588
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
588
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
589
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
589
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
590
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
590
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
591
('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'),
591
('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
592
('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
592
('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'),
593
('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'),
593
('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'),
594
('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'),
(-)a/installer/data/mysql/mandatory/userpermissions.sql (+1 lines)
Lines 37-42 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
37
   ( 3, 'manage_keyboard_shortcuts', 'Manage keyboard shortcuts for the advanced cataloging editor'),
37
   ( 3, 'manage_keyboard_shortcuts', 'Manage keyboard shortcuts for the advanced cataloging editor'),
38
   ( 3, 'manage_smtp_servers', 'Manage SMTP servers configuration'),
38
   ( 3, 'manage_smtp_servers', 'Manage SMTP servers configuration'),
39
   ( 3, 'manage_background_jobs', 'Manage background jobs'),
39
   ( 3, 'manage_background_jobs', 'Manage background jobs'),
40
   ( 3, 'manage_search_filters', 'Manage custom search filters'),
40
   ( 4, 'delete_borrowers', 'Delete patrons'),
41
   ( 4, 'delete_borrowers', 'Delete patrons'),
41
   ( 4, 'edit_borrowers', 'Add, modify and view patron information'),
42
   ( 4, 'edit_borrowers', 'Add, modify and view patron information'),
42
   ( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'),
43
   ( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc (+5 lines)
Lines 208-213 Link Here
208
            Manage item search fields
208
            Manage item search fields
209
        </span>
209
        </span>
210
        <span class="permissioncode">([% name | html %])</span>
210
        <span class="permissioncode">([% name | html %])</span>
211
    [%- CASE 'manage_search_filters' -%]
212
        <span class="sub_permission manage_search_filters_subpermission">
213
            Manage saved search filters
214
        </span>
215
        <span class="permissioncode">([% name | html %])</span>
211
    [%- CASE 'manage_search_engine_config' -%]
216
    [%- CASE 'manage_search_engine_config' -%]
212
        <span class="sub_permission manage_search_engine_config_subpermission">
217
        <span class="sub_permission manage_search_engine_config_subpermission">
213
            Manage search engine configuration
218
            Manage search engine configuration
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (-1 / +7 lines)
Lines 87-92 Searching: Link Here
87
                  0: Disable
87
                  0: Disable
88
            - "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above."
88
            - "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above."
89
            - "See documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields"
89
            - "See documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields"
90
        -
91
            - pref: SavedSearchFilters
92
              default: 0
93
              choices:
94
                  1: Enable
95
                  0: Disable
96
            - "the option for staff with permission to create/edit custom saved search filters."
90
    Search form:
97
    Search form:
91
        -
98
        -
92
            - pref : LoadSearchHistoryToTheFirstLoggedUser
99
            - pref : LoadSearchHistoryToTheFirstLoggedUser
93
- 

Return to bug 17170