Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jdeveloper/582779 to your computer and use it in GitHub Desktop.
Save jdeveloper/582779 to your computer and use it in GitHub Desktop.
<?php
/**
* For now only works with Text filters and only for sfFormFilterDoctrine
* The problem of not escaping quotes was found with mysql
* Since the task doctrine:build-filters generates all formfilters extended from BaseFormFilterDoctrine we rewtirte there the addTextQuery method
*/
abstract class BaseFormFilterDoctrine extends sfFormFilterDoctrine
{
public function setup()
{
}
protected function addTextQuery(Doctrine_Query $query, $field, $values)
{
$fieldName = $this->getFieldName($field);
if (is_array($values) && isset($values['is_empty']) && $values['is_empty'])
{
$query->addWhere(sprintf('(%s.%s IS NULL OR %1$s.%2$s = ?)', $query->getRootAlias(), $fieldName), array(''));
}
else if (is_array($values) && isset($values['text']) && '' != $values['text'])
{
$quotedValue = $query->getConnection()->getDbh()->quote('%'.$values['text'].'%', PDO::PARAM_STR); //escapes the quotes in the value, maybe you want to search text witch has quotes
$query->addWhere(sprintf('%s.%s LIKE %s', $query->getRootAlias(), $fieldName,$quotedValue));
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment