本文整理匯總了PHP中Sonata\AdminBundle\Datagrid\ProxyQueryInterface::getRootEntities方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProxyQueryInterface::getRootEntities方法的具體用法?PHP ProxyQueryInterface::getRootEntities怎麽用?PHP ProxyQueryInterface::getRootEntities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sonata\AdminBundle\Datagrid\ProxyQueryInterface
的用法示例。
在下文中一共展示了ProxyQueryInterface::getRootEntities方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: filter
/**
* {@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']));
}
}