Created
September 16, 2010 17:14
-
-
Save jdeveloper/582779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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