123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?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\DoctrineORMAdminBundle\Filter;
- use Sonata\AdminBundle\Filter\Filter as BaseFilter;
- use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
- abstract class Filter extends BaseFilter
- {
- protected $active = false;
- /**
- * {@inheritdoc}
- */
- public function apply($queryBuilder, $value)
- {
- $this->value = $value;
- list($alias, $field) = $this->association($queryBuilder, $value);
- $this->filter($queryBuilder, $alias, $field, $value);
- }
- /**
- * {@inheritdoc}
- */
- protected function association(ProxyQueryInterface $queryBuilder, $value)
- {
- $alias = $queryBuilder->entityJoin($this->getParentAssociationMappings());
- return array($alias, $this->getFieldName());
- }
- /**
- * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryBuilder
- * @param mixed $parameter
- */
- protected function applyWhere(ProxyQueryInterface $queryBuilder, $parameter)
- {
- if ($this->getCondition() == self::CONDITION_OR) {
- $queryBuilder->orWhere($parameter);
- } else {
- $queryBuilder->andWhere($parameter);
- }
- // filter is active since it's added to the queryBuilder
- $this->active = true;
- }
- /**
- * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryBuilder
- *
- * @return string
- */
- protected function getNewParameterName(ProxyQueryInterface $queryBuilder)
- {
- // dots are not accepted in a DQL identifier so replace them
- // by underscores.
- return str_replace('.', '_', $this->getName()) . '_' . $queryBuilder->getUniqueParameterId();
- }
- /**
- * {@inheritdoc}
- */
- public function isActive()
- {
- return $this->active;
- }
- }
|