12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- /*
- * This file is part of the Sonata package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * 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))
- );
- }
- }
|