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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-7 / +22 lines)
Lines 296-303 Link Here
296
                    return { "like": start_with + "%" }
296
                    return { "like": start_with + "%" }
297
                },
297
                },
298
                "-and": function(){
298
                "-and": function(){
299
                    let filter = $("#search_patron_filter").val();
299
                    let pattern = $("#search_patron_filter").val();
300
                    if (!filter) return "";
300
                    if (!pattern) return "";
301
                    let patterns = pattern.split(' ').filter(function(s){ return s.length });
301
302
302
                    let filters = [];
303
                    let filters = [];
303
                    let search_type = $("#searchtype_filter").val() || "contain";
304
                    let search_type = $("#searchtype_filter").val() || "contain";
Lines 305-318 Link Here
305
                    if ( !search_fields ) {
306
                    if ( !search_fields ) {
306
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]";
307
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]";
307
                    }
308
                    }
308
                    search_fields.split(',').forEach(function(e,i){
309
309
                        filters.push({["me."+e]:{"like":(search_type == "contain" ? "%" : "" ) + filter + "%"}});
310
                    let subquery_and = [];
311
                    patterns.forEach(function(pattern,i){
312
                        let sub_or = [];
313
                        search_fields.split(',').forEach(function(attr,ii){
314
                            sub_or.push({["me."+attr]:{"like":(search_type == "contain" ? "%" : "" ) + pattern + "%"}});
315
                        });
316
                        subquery_and.push(sub_or);
310
                    });
317
                    });
318
                    filters.push({"-and": subquery_and});
319
311
                    [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %]
320
                    [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %]
312
                        filters.push({
321
                        subquery_and = [];
313
                            "extended_attributes.value": { "like": "%" + filter + (search_type == "contain" ? "%" : "" )},
322
                        patterns.forEach(function(pattern,i){
314
                            "extended_attributes.code": extended_attribute_types
323
                            let sub_or = [];
324
                            sub_or.push({
325
                                "extended_attributes.value": { "like": "%" + pattern + (search_type == "contain" ? "%" : "" )},
326
                                "extended_attributes.code": extended_attribute_types
327
                            });
328
                            subquery_and.push(sub_or);
315
                        });
329
                        });
330
                        filters.push({"-and": subquery_and});
316
                    [% END %]
331
                    [% END %]
317
                    return filters;
332
                    return filters;
318
                }
333
                }
(-)a/t/db_dependent/selenium/patrons_search.t (-2 / +27 lines)
Lines 51-57 my $base_url = $s->base_url; Link Here
51
my $builder       = t::lib::TestBuilder->new;
51
my $builder       = t::lib::TestBuilder->new;
52
52
53
subtest 'Search patrons' => sub {
53
subtest 'Search patrons' => sub {
54
    plan tests => 23;
54
    plan tests => 24;
55
55
56
    if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) {
56
    if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) {
57
        BAIL_OUT("Cannot run this test, data we need to create already exist in the DB");
57
        BAIL_OUT("Cannot run this test, data we need to create already exist in the DB");
Lines 91-96 subtest 'Search patrons' => sub { Link Here
91
            }
91
            }
92
          );
92
          );
93
    }
93
    }
94
95
    push @patrons, $builder->build_object(
96
        {
97
            class => 'Koha::Patrons',
98
            value => {
99
                surname   => "test",
100
                firstname => "not_p_a_t_r_o_n",    # won't match 'patron'
101
                categorycode  => $patron_category->categorycode,
102
                branchcode    => $library->branchcode,
103
                borrowernotes => $borrowernotes,
104
                address       => $address,
105
                email         => $email,
106
            }
107
        }
108
    );
109
94
    my $library_2 = $builder->build_object(
110
    my $library_2 = $builder->build_object(
95
        { class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } }
111
        { class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } }
96
    );
112
    );
Lines 221-226 subtest 'Search patrons' => sub { Link Here
221
    # And make sure all the patrons are present
237
    # And make sure all the patrons are present
222
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' );
238
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' );
223
239
240
    # Pattern terms must be split
241
    $s->fill_form( { search_patron_filter => 'test patron' } );
242
    $s->submit_form;
243
244
    $s->wait_for_ajax;
245
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) );
246
    $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
247
    $s->submit_form;
248
    $s->wait_for_ajax;
249
224
    # Search on non-searchable attribute, we expect no result!
250
    # Search on non-searchable attribute, we expect no result!
225
    $s->fill_form( { search_patron_filter => 'test_attr_1' } );
251
    $s->fill_form( { search_patron_filter => 'test_attr_1' } );
226
    $s->submit_form;
252
    $s->submit_form;
227
- 

Return to bug 30639