* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Sonata\AdminBundle\Filter\ORM; use Doctrine\ORM\QueryBuilder; class IntegerFilter extends Filter { public function filter($queryBuilder, $alias, $field, $value) { if ($value == null) { return; } $value = sprintf($this->getOption('format'), $value); // c.name > '1' => c.name OPERATOR :FIELDNAME $queryBuilder->andWhere(sprintf('%s.%s %s :%s', $alias, $field, $this->getOption('operator'), $this->getName() )); $queryBuilder->setParameter($this->getName(), (int)$value); } protected function configure() { $this->addOption('operator', '='); $this->addOption('format', '%d'); parent::configure(); } public function getFormField() { return new \Symfony\Component\Form\TextField( $this->getName(), $this->description->getOption('filter_field_options', array('required' => false)) ); } }