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; |