/** * {@inheritdoc} */ public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) { if (!$data || !is_array($data) || !array_key_exists('value', $data)) { return; } $data['value'] = trim($data['value']); if (strlen($data['value']) == 0) { return; } $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type']; $operator = $this->getOperator((int) $data['type']); if (!$operator) { $operator = 'LIKE'; } $entities = $queryBuilder->getRootEntities(); $classMetadata = $this->listener->getTranslatableMetadata(current($entities)); $transMetadata = $this->listener->getTranslatableMetadata($classMetadata->targetEntity); // Add inner join if (!$this->hasJoin($queryBuilder, $alias)) { $parameterName = $this->getNewParameterName($queryBuilder); $queryBuilder->innerJoin(sprintf('%s.%s', $alias, $classMetadata->translations->name), 'trans', Expr\Join::WITH, sprintf('trans.%s = :%s', $transMetadata->locale->name, $parameterName)); $queryBuilder->setParameter($parameterName, $this->listener->getCurrentLocale()); } // c.name > '1' => c.name OPERATOR :FIELDNAME $parameterName = $this->getNewParameterName($queryBuilder); $this->applyWhere($queryBuilder, sprintf('%s.%s %s :%s', 'trans', $field, $operator, $parameterName)); if ($data['type'] == ChoiceType::TYPE_EQUAL) { $queryBuilder->setParameter($parameterName, $data['value']); } else { $queryBuilder->setParameter($parameterName, sprintf($this->getOption('format'), $data['value'])); } }
/** * Set request locale * * @param GetResponseEvent $event * @return void */ public function onKernelRequest(GetResponseEvent $event) { $this->translatableListener->setCurrentLocale($event->getRequest()->getLocale()); }