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

(-)a/Koha/REST/Plugin/Objects.pm (+7 lines)
Lines 193-198 shouldn't be called twice in it. Link Here
193
            $result_set = $result_set->search_limited,
193
            $result_set = $result_set->search_limited,
194
                if $result_set->can('search_limited');
194
                if $result_set->can('search_limited');
195
195
196
            # Pre-process DBIC queries if controller supports it
197
            if ( $reserved_params->{'x-koha-request-id'} ){
198
                if ($c->can('preprocess_dbic_for_datatables')){
199
                    $c->preprocess_dbic_for_datatables($filtered_params,$attributes);
200
                }
201
            }
202
196
            # Perform search
203
            # Perform search
197
            my $objects = $result_set->search( $filtered_params, $attributes );
204
            my $objects = $result_set->search( $filtered_params, $attributes );
198
            my $total   = $result_set->search->count;
205
            my $total   = $result_set->search->count;
(-)a/Koha/REST/V1/Patrons.pm (+48 lines)
Lines 458-461 sub guarantors_can_see_checkouts { Link Here
458
    };
458
    };
459
}
459
}
460
460
461
sub _parse_dbic_query_for_dt {
462
    my ($q_params,$collector) = @_;
463
    if(ref($q_params) && ref($q_params) eq 'HASH') {
464
        foreach my $key (keys %{$q_params}) {
465
            #FIXME: The table preference is always required so we might want to handle other scenarios...
466
            if ($key eq 'me.phone'){
467
                my $query = $q_params->{$key};
468
                if ($query->{'like'}){
469
                    my $like = $query->{'like'};
470
                    #NOTE: Remove the hashref, and add a data structure to add to the WHERE clause via the attributes...
471
                    delete $q_params->{$key};
472
                    my $collection = \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$like];
473
                    push(@$collector,$collection);
474
                    #NOTE: Rewrite the query to use a subquery where we can perform phone number normalization (but it's slow)
475
                    #$q_params->{$key} = {
476
                    #   '-in' => \["SELECT phone FROM borrowers WHERE regexp_replace(phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}],
477
                    #};
478
                    #NOTE: Technically, you could replace the whole hashref, but that would nuke any OR query in the same hashref
479
                    #return \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}];
480
                }
481
            }
482
            else {
483
                $q_params->{$key} = _parse_dbic_query_for_dt($q_params->{$key},$collector);
484
            }
485
        }
486
       return $q_params;
487
    } elsif (ref($q_params) && ref($q_params) eq 'ARRAY') {
488
        foreach my $param (@$q_params){
489
            $param = _parse_dbic_query_for_dt($param,$collector);
490
        }
491
        return $q_params;
492
    } else {
493
        return $q_params;
494
    }
495
}
496
497
sub preprocess_dbic_for_datatables {
498
    my ($c,$q_params,$attributes) = @_;
499
    my @collector = ();
500
    my $rewritten_q_params = _parse_dbic_query_for_dt($q_params,\@collector);
501
    unless ($attributes->{where}){
502
        foreach my $collection (@collector){
503
            push(@{$attributes->{where}},$collection);
504
        }
505
    }
506
    return 1;
507
}
508
461
1;
509
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-1 / +3 lines)
Lines 322-327 Link Here
322
                    if ( !search_fields ) {
322
                    if ( !search_fields ) {
323
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
323
                        search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
324
                    }
324
                    }
325
                    if (search_fields == 'phone'){
326
                        patterns = [pattern.replace(/[^\+0-9]/g,'')];
327
                    }
325
328
326
                    let subquery_and = [];
329
                    let subquery_and = [];
327
                    patterns.forEach(function(pattern,i){
330
                    patterns.forEach(function(pattern,i){
328
- 

Return to bug 23817