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 309-316 Link Here
309
                    return { "like": start_with + "%" }
309
                    return { "like": start_with + "%" }
310
                },
310
                },
311
                "-and": function(){
311
                "-and": function(){
312
                    let filter = $("#search_patron_filter").val();
312
                    let pattern = $("#search_patron_filter").val();
313
                    if (!filter) return "";
313
                    if (!pattern) return "";
314
                    let patterns = pattern.split(' ').filter(function(s){ return s.length });
314
315
315
                    let filters = [];
316
                    let filters = [];
316
                    let search_type = $("#searchtype_filter").val() || "contain";
317
                    let search_type = $("#searchtype_filter").val() || "contain";
Lines 318-331 Link Here
318
                    if ( !search_fields ) {
319
                    if ( !search_fields ) {
319
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]";
320
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]";
320
                    }
321
                    }
321
                    search_fields.split(',').forEach(function(e,i){
322
322
                        filters.push({["me."+e]:{"like":(search_type == "contain" ? "%" : "" ) + filter + "%"}});
323
                    let subquery_and = [];
324
                    patterns.forEach(function(pattern,i){
325
                        let sub_or = [];
326
                        search_fields.split(',').forEach(function(attr,ii){
327
                            sub_or.push({["me."+attr]:{"like":(search_type == "contain" ? "%" : "" ) + pattern + "%"}});
328
                        });
329
                        subquery_and.push(sub_or);
323
                    });
330
                    });
331
                    filters.push({"-and": subquery_and});
332
324
                    [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %]
333
                    [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %]
325
                        filters.push({
334
                        subquery_and = [];
326
                            "extended_attributes.value": { "like": "%" + filter + (search_type == "contain" ? "%" : "" )},
335
                        patterns.forEach(function(pattern,i){
327
                            "extended_attributes.code": extended_attribute_types
336
                            let sub_or = [];
337
                            sub_or.push({
338
                                "extended_attributes.value": { "like": "%" + pattern + (search_type == "contain" ? "%" : "" )},
339
                                "extended_attributes.code": extended_attribute_types
340
                            });
341
                            subquery_and.push(sub_or);
328
                        });
342
                        });
343
                        filters.push({"-and": subquery_and});
329
                    [% END %]
344
                    [% END %]
330
                    return filters;
345
                    return filters;
331
                }
346
                }
(-)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