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

(-)a/Koha/REST/V1/Patrons.pm (-9 / +16 lines)
Lines 472-494 sub guarantors_can_see_checkouts { Link Here
472
472
473
sub _parse_dbic_query_for_dt {
473
sub _parse_dbic_query_for_dt {
474
    my ($q_params,$collector) = @_;
474
    my ($q_params,$collector) = @_;
475
    my %allowed_keys = (
476
        'me.phone' => 1,
477
        'me.phonepro' => 1,
478
        'me.B_phone' => 1,
479
        'me.altcontactphone' => 1,
480
        'me.mobile' => 1,
481
    );
475
    if(ref($q_params) && ref($q_params) eq 'HASH') {
482
    if(ref($q_params) && ref($q_params) eq 'HASH') {
476
        foreach my $key (keys %{$q_params}) {
483
        foreach my $key (keys %{$q_params}) {
477
            #FIXME: The table preference is always required so we might want to handle other scenarios...
484
            if ($allowed_keys{$key}){
478
            if ($key eq 'me.phone'){
479
                my $query = $q_params->{$key};
485
                my $query = $q_params->{$key};
480
                if ($query->{'like'}){
486
                if ($query->{'like'}){
481
                    my $like = $query->{'like'};
487
                    my $like = $query->{'like'};
482
                    #NOTE: Remove the hashref, and add a data structure to add to the WHERE clause via the attributes...
488
                    #NOTE: Remove the hashref, and add a data structure to add to the WHERE clause via the attributes...
483
                    delete $q_params->{$key};
489
                    delete $q_params->{$key};
484
                    my $collection = \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$like];
490
                    my $collection = \["regexp_replace($key,?,?) LIKE ?","[^0-9]","",$like];
485
                    push(@$collector,$collection);
491
                    push(@$collector,$collection);
486
                    #NOTE: Rewrite the query to use a subquery where we can perform phone number normalization (but it's slow)
487
                    #$q_params->{$key} = {
488
                    #   '-in' => \["SELECT phone FROM borrowers WHERE regexp_replace(phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}],
489
                    #};
490
                    #NOTE: Technically, you could replace the whole hashref, but that would nuke any OR query in the same hashref
491
                    #return \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}];
492
                }
492
                }
493
            }
493
            }
494
            else {
494
            else {
Lines 506-511 sub _parse_dbic_query_for_dt { Link Here
506
    }
506
    }
507
}
507
}
508
508
509
=head3 preprocess_dbic_for_datatables
510
511
Method for preprocessing DBIC queries sent from DataTables, so a WHERE
512
clause can be injected into the query if one doesn't already exist.
513
514
=cut
515
509
sub preprocess_dbic_for_datatables {
516
sub preprocess_dbic_for_datatables {
510
    my ($c,$q_params,$attributes) = @_;
517
    my ($c,$q_params,$attributes) = @_;
511
    my @collector = ();
518
    my @collector = ();
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-3 / +1 lines)
Lines 308-317 Link Here
308
                    if ( !search_fields ) {
308
                    if ( !search_fields ) {
309
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
309
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
310
                    }
310
                    }
311
                    if (search_fields == 'phone'){
311
                    if (search_fields == 'phone,phonepro,B_phone,altcontactphone,mobile'){
312
                        patterns = [pattern.replace(/[^\+0-9]/g,'')];
312
                        patterns = [pattern.replace(/[^\+0-9]/g,'')];
313
                    }
313
                    }
314
315
                    let subquery_and = [];
314
                    let subquery_and = [];
316
                    patterns.forEach(function(pattern,i){
315
                    patterns.forEach(function(pattern,i){
317
                        let sub_or = [];
316
                        let sub_or = [];
318
- 

Return to bug 23817