Skip to content

Instantly share code, notes, and snippets.

@rileyrg
Created June 14, 2017 20:23
Show Gist options
  • Save rileyrg/92e9598ec875c244f131d152935f0549 to your computer and use it in GitHub Desktop.
Save rileyrg/92e9598ec875c244f131d152935f0549 to your computer and use it in GitHub Desktop.
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (empty($values['value'])) {
return null;
}
$paramName = sprintf('p_%s', str_replace('.', '_', $field));
// expression that represent the condition
$expression = $filterQuery->getExpr()->eq($field, ':' . $paramName);
// expression parameters
$parameters = array($paramName => $values['value']); // [ name => value ]
// or if you need to define the parameter's type
// $parameters = array($paramName => array($values['value'], \PDO::PARAM_STR)); // [ name => [value, type] ]
return $filterQuery->createCondition($expression, $parameters);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment