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

(-)a/C4/Utils/DataTables/Members.pm (-1 / +13 lines)
Lines 88-100 sub search { Link Here
88
    foreach my $term (@terms) {
88
    foreach my $term (@terms) {
89
        next unless $term;
89
        next unless $term;
90
90
91
        my $termsearchfieldstype;
92
        my $term_is_dt = eval { local $SIG{__WARN__}={}; Koha::DateUtils::output_pref( { str=>$term, dateonly=>1, dateformat=>'sql' } ); };
93
94
        if ( $term_is_dt ){
95
            $termsearchfieldstype = 'dateofbirth' ;
96
            $term = $term_is_dt;
97
        } else {
98
            $termsearchfieldstype = $searchfieldstype;
91
        $term .= '%' # end with anything
99
        $term .= '%' # end with anything
92
            if $term !~ /%$/;
100
            if $term !~ /%$/;
93
        $term = "%$term" # begin with anythin unless start_with
101
        $term = "%$term" # begin with anythin unless start_with
94
            if $searchtype eq 'contain' && $term !~ /^%/;
102
            if $searchtype eq 'contain' && $term !~ /^%/;
103
        }
95
104
96
        my @where_strs_or;
105
        my @where_strs_or;
97
        for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) {
106
        for my $searchfield ( split /,/, $searchfields->{$termsearchfieldstype} ) {
98
            push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?";
107
            push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?";
99
            push @where_args, $term;
108
            push @where_args, $term;
100
        }
109
        }
Lines 136-141 sub search { Link Here
136
        ($limit ? $limit : "")
145
        ($limit ? $limit : "")
137
    );
146
    );
138
    my $sth = $dbh->prepare($query);
147
    my $sth = $dbh->prepare($query);
148
    warn Data::Dumper::Dumper( $query );
149
    warn Data::Dumper::Dumper( @where_args );
150
139
    $sth->execute(@where_args);
151
    $sth->execute(@where_args);
140
    my $patrons = $sth->fetchall_arrayref({});
152
    my $patrons = $sth->fetchall_arrayref({});
141
153
(-)a/t/db_dependent/Utils/Datatables_Members.t (-7 / +71 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 27;
20
use Test::More tests => 47;
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
23
use C4::Members;
Lines 60-66 my %john_doe = ( Link Here
60
    surname      => 'Doe',
60
    surname      => 'Doe',
61
    categorycode => $categorycode,
61
    categorycode => $categorycode,
62
    branchcode   => $branchcode,
62
    branchcode   => $branchcode,
63
    dateofbirth  => '',
63
    dateofbirth  => '1983-03-01',
64
    dateexpiry   => '9999-12-31',
64
    dateexpiry   => '9999-12-31',
65
    userid       => 'john.doe'
65
    userid       => 'john.doe'
66
);
66
);
Lines 71-77 my %john_smith = ( Link Here
71
    surname      => 'Smith',
71
    surname      => 'Smith',
72
    categorycode => $categorycode,
72
    categorycode => $categorycode,
73
    branchcode   => $branchcode,
73
    branchcode   => $branchcode,
74
    dateofbirth  => '',
74
    dateofbirth  => '1982-02-01',
75
    dateexpiry   => '9999-12-31',
75
    dateexpiry   => '9999-12-31',
76
    userid       => 'john.smith'
76
    userid       => 'john.smith'
77
);
77
);
Lines 82-88 my %jane_doe = ( Link Here
82
    surname      => 'Doe',
82
    surname      => 'Doe',
83
    categorycode => $categorycode,
83
    categorycode => $categorycode,
84
    branchcode   => $branchcode,
84
    branchcode   => $branchcode,
85
    dateofbirth  => '',
85
    dateofbirth  => '1983-03-01',
86
    dateexpiry   => '9999-12-31',
86
    dateexpiry   => '9999-12-31',
87
    userid       => 'jane.doe'
87
    userid       => 'jane.doe'
88
);
88
);
Lines 93-99 my %jeanpaul_dupont = ( Link Here
93
    surname      => 'Dupont',
93
    surname      => 'Dupont',
94
    categorycode => $categorycode,
94
    categorycode => $categorycode,
95
    branchcode   => $branchcode,
95
    branchcode   => $branchcode,
96
    dateofbirth  => '',
96
    dateofbirth  => '1982-02-01',
97
    dateexpiry   => '9999-12-31',
97
    dateexpiry   => '9999-12-31',
98
    userid       => 'jeanpaul.dupont'
98
    userid       => 'jeanpaul.dupont'
99
);
99
);
Lines 104-110 my %dupont_brown = ( Link Here
104
    surname      => 'Brown',
104
    surname      => 'Brown',
105
    categorycode => $categorycode,
105
    categorycode => $categorycode,
106
    branchcode   => $branchcode,
106
    branchcode   => $branchcode,
107
    dateofbirth  => '',
107
    dateofbirth  => '1979-01-01',
108
    dateexpiry   => '9999-12-31',
108
    dateexpiry   => '9999-12-31',
109
    userid       => 'dupont.brown'
109
    userid       => 'dupont.brown'
110
);
110
);
Lines 362-367 $search_results = C4::Utils::DataTables::Members::search({ Link Here
362
is( $search_results->{ iTotalDisplayRecords }, 1,
362
is( $search_results->{ iTotalDisplayRecords }, 1,
363
    "Jean Paul Dupont is found using contains and two terms search 'Jea Pau' (Bug 15252)");
363
    "Jean Paul Dupont is found using contains and two terms search 'Jea Pau' (Bug 15252)");
364
364
365
my @datetimeprefs = ("dmydot","iso","metric","us");
366
my %dates_in_pref = (
367
        dmydot  => ["01.02.1982","01.03.1983","01.01.1979","01.01.1988"],
368
        iso     => ["1982-02-01","1983-03-01","1979-01-01","1988-01-01"],
369
        metric  => ["01/02/1982","01/03/1983","01/01/1979","01/01/1988"],
370
        us      => ["02/01/1982","03/01/1983","01/01/1979","01/01/1988"],
371
        );
372
foreach my $dateformloo (@datetimeprefs){
373
    t::lib::Mocks::mock_preference('dateformat', $dateformloo);
374
    $search_results = C4::Utils::DataTables::Members::search({
375
        searchmember     => $dates_in_pref{$dateformloo}[0],
376
        searchfieldstype => 'standard',
377
        searchtype       => 'contain',
378
        branchcode       => $branchcode,
379
        dt_params        => \%dt_params
380
    });
381
382
    is( $search_results->{ iTotalDisplayRecords }, 2,
383
        "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[0], standard search fields overriden");
384
385
    $search_results = C4::Utils::DataTables::Members::search({
386
        searchmember     => $dates_in_pref{$dateformloo}[2],
387
        searchfieldstype => 'standard',
388
        searchtype       => 'contain',
389
        branchcode       => $branchcode,
390
        dt_params        => \%dt_params
391
    });
392
393
    is( $search_results->{ iTotalDisplayRecords }, 1,
394
        "dateformat: $dateformloo One borrower has dob $dates_in_pref{$dateformloo}[2], standard search fields overriden");
395
396
    $search_results = C4::Utils::DataTables::Members::search({
397
        searchmember     => $dates_in_pref{$dateformloo}[1],
398
        searchfieldstype => 'dateofbirth',
399
        searchtype       => 'contain',
400
        branchcode       => $branchcode,
401
        dt_params        => \%dt_params
402
    });
403
404
    is( $search_results->{ iTotalDisplayRecords }, 2,
405
        "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[1], dateofbirth search field works");
406
407
    $search_results = C4::Utils::DataTables::Members::search({
408
        searchmember     => $dates_in_pref{$dateformloo}[3],
409
        searchfieldstype => 'dateofbirth',
410
        searchtype       => 'contain',
411
        branchcode       => $branchcode,
412
        dt_params        => \%dt_params
413
    });
414
415
    is( $search_results->{ iTotalDisplayRecords }, 0,
416
        "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], dateofbirth search field works");
417
418
    $search_results = C4::Utils::DataTables::Members::search({
419
        searchmember     => $dates_in_pref{$dateformloo}[3],
420
        searchfieldstype => 'standard',
421
        searchtype       => 'contain',
422
        branchcode       => $branchcode,
423
        dt_params        => \%dt_params
424
    });
425
426
    is( $search_results->{ iTotalDisplayRecords }, 0,
427
        "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], standard search field overridden");
428
}
429
365
# End
430
# End
366
$dbh->rollback;
431
$dbh->rollback;
367
432
368
- 

Return to bug 14874