|
Lines 470-473
sub guarantors_can_see_checkouts {
Link Here
|
| 470 |
}; |
470 |
}; |
| 471 |
} |
471 |
} |
| 472 |
|
472 |
|
|
|
473 |
sub _parse_dbic_query_for_dt { |
| 474 |
my ($q_params,$collector) = @_; |
| 475 |
if(ref($q_params) && ref($q_params) eq 'HASH') { |
| 476 |
foreach my $key (keys %{$q_params}) { |
| 477 |
#FIXME: The table preference is always required so we might want to handle other scenarios... |
| 478 |
if ($key eq 'me.phone'){ |
| 479 |
my $query = $q_params->{$key}; |
| 480 |
if ($query->{'like'}){ |
| 481 |
my $like = $query->{'like'}; |
| 482 |
#NOTE: Remove the hashref, and add a data structure to add to the WHERE clause via the attributes... |
| 483 |
delete $q_params->{$key}; |
| 484 |
my $collection = \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$like]; |
| 485 |
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 |
} |
| 493 |
} |
| 494 |
else { |
| 495 |
$q_params->{$key} = _parse_dbic_query_for_dt($q_params->{$key},$collector); |
| 496 |
} |
| 497 |
} |
| 498 |
return $q_params; |
| 499 |
} elsif (ref($q_params) && ref($q_params) eq 'ARRAY') { |
| 500 |
foreach my $param (@$q_params){ |
| 501 |
$param = _parse_dbic_query_for_dt($param,$collector); |
| 502 |
} |
| 503 |
return $q_params; |
| 504 |
} else { |
| 505 |
return $q_params; |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
sub preprocess_dbic_for_datatables { |
| 510 |
my ($c,$q_params,$attributes) = @_; |
| 511 |
my @collector = (); |
| 512 |
my $rewritten_q_params = _parse_dbic_query_for_dt($q_params,\@collector); |
| 513 |
unless ($attributes->{where}){ |
| 514 |
foreach my $collection (@collector){ |
| 515 |
push(@{$attributes->{where}},$collection); |
| 516 |
} |
| 517 |
} |
| 518 |
return 1; |
| 519 |
} |
| 520 |
|
| 473 |
1; |
521 |
1; |