本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::resetDQLPart方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::resetDQLPart方法的具体用法?PHP QueryBuilder::resetDQLPart怎么用?PHP QueryBuilder::resetDQLPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::resetDQLPart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilteredCountQuery
/**
* Build the count of filtered query
*
* @return QueryBuilder
*/
public function getFilteredCountQuery()
{
$this->buildFilteredQuery();
$this->currentQueryBuilder->select('COUNT(DISTINCT ' . $this->getDistinct() . ')');
$this->currentQueryBuilder->resetDQLPart('orderBy');
return $this->currentQueryBuilder;
}
示例2: addQueryTranslationSupport
/**
* @param QueryBuilder $query
* @param $source
* @param $locale
* @param bool $resetJoin
*/
public function addQueryTranslationSupport(QueryBuilder $query, $source, $locale, $resetJoin = true)
{
if ($resetJoin) {
$query->resetDQLPart('join');
}
$query->leftJoin($source->getTableAlias() . '.translations', '_translations', 'WITH', $query->expr()->orX($query->expr()->eq('_translations.locale', ':locale'), $query->expr()->isNull('_translations.id')));
$query->setParameter('locale', $locale);
}
示例3: addAttributeSorter
/**
* {@inheritdoc}
*/
public function addAttributeSorter(AbstractAttribute $attribute, $direction)
{
$aliasPrefix = 'sorter';
$joinAlias = $aliasPrefix . 'V' . $attribute->getCode() . $this->aliasCounter++;
$backendType = $attribute->getBackendType();
// join to value and sort on
$condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias);
// Remove current join in order to put the orderBy related join
// at first place in the join queue for performances reasons
$joinsSet = $this->qb->getDQLPart('join');
$this->qb->resetDQLPart('join');
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
$this->qb->addOrderBy($joinAlias . '.' . $backendType, $direction);
// Reapply previous join after the orderBy related join
$this->applyJoins($joinsSet);
return $this;
}
示例4: reset
/**
* Reset the queryBuilder to an initial state
*/
protected function reset()
{
$this->selectedTableColumns = array();
$this->queryBuilder->resetDQLPart('select');
$this->subQueries = array();
$this->prioritizedSubQueries = array();
$this->queryBuilder->resetDQLPart('join');
}
示例5: setOrderings
/**
* Sets the property names to order the result by. Expected like this:
* array(
* 'foo' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING,
* 'bar' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_DESCENDING
* )
*
* @param array $orderings The property names to order by
* @return \TYPO3\Flow\Persistence\QueryInterface
* @api
*/
public function setOrderings(array $orderings)
{
$this->orderings = $orderings;
$this->queryBuilder->resetDQLPart('orderBy');
foreach ($this->orderings as $propertyName => $order) {
$this->queryBuilder->addOrderBy($this->getPropertyNameWithAlias($propertyName), $order);
}
return $this;
}
示例6: addAttributeSorter
/**
* {@inheritdoc}
*/
public function addAttributeSorter(AttributeInterface $attribute, $direction, $locale = null, $scope = null)
{
$aliasPrefix = 'sorter';
$joinAlias = $aliasPrefix . 'V' . $attribute->getCode();
$backendType = $attribute->getBackendType();
// join to value and sort on
$condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
// Remove current join in order to put the orderBy related join
// at first place in the join queue for performances reasons
$joinsSet = $this->qb->getDQLPart('join');
$this->qb->resetDQLPart('join');
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
$this->qb->addOrderBy($joinAlias . '.' . $backendType, $direction);
$idField = $this->qb->getRootAlias() . '.id';
$this->qb->addOrderBy($idField);
// Reapply previous join after the orderBy related join
// TODO : move this part in re-usable class
$this->applyJoins($joinsSet);
return $this;
}
示例7: initialize
/**
* Load the collection
*
*/
protected function initialize()
{
if ($this->initialized) {
return;
}
// Handle search
if (isset($this->searchExpression)) {
$queryBuilderExpression = $this->buildQueryBuilderExpression($this->searchExpression);
$this->queryBuilder->andWhere($queryBuilderExpression);
}
// Handle filters
if (isset($this->filterExpression)) {
$queryBuilderExpression = $this->buildQueryBuilderExpression($this->filterExpression);
$this->queryBuilder->andWhere($queryBuilderExpression);
}
// Handle sort
if (null !== $this->sortField && null !== $this->sortDirection) {
$oldOrderBys = $this->queryBuilder->getDQLPart('orderBy');
$this->queryBuilder->resetDQLPart('orderBy');
$this->queryBuilder->orderBy($this->sortField, $this->sortDirection);
foreach ($oldOrderBys as $oldOrderBy) {
$this->queryBuilder->add('orderBy', $oldOrderBy, true);
}
}
// Handle pagination
if (isset($this->limitPerPage)) {
$paginator = new DoctrineORMPaginator($this->queryBuilder->getQuery());
$paginator->setLimitPerPage($this->limitPerPage)->setRangeLimit($this->rangeLimit)->setPage($this->page);
$this->iterator = $paginator->getIterator();
$this->paginator = $paginator;
} else {
$items = $this->queryBuilder->getQuery()->getResult();
$this->iterator = new \ArrayIterator($items);
$this->paginator = null;
}
$this->initialized = true;
}
示例8: Expr
function it_adds_a_sorter_in_the_query(QueryBuilder $queryBuilder, AbstractAttribute $sku)
{
$sku->getId()->willReturn(42);
$sku->getCode()->willReturn('sku');
$sku->getBackendType()->willReturn('varchar');
$sku->isLocalizable()->willReturn(false);
$sku->isScopable()->willReturn(false);
$queryBuilder->expr()->willReturn(new Expr());
$queryBuilder->getRootAlias()->willReturn('p');
$queryBuilder->getDQLPart('join')->willReturn([]);
$queryBuilder->resetDQLPart('join')->shouldBeCalled();
$condition = "sorterVsku1.attribute = 42";
$queryBuilder->leftJoin('p.values', 'sorterVsku1', 'WITH', $condition)->shouldBeCalled();
$queryBuilder->addOrderBy('sorterVsku1.varchar', 'DESC')->shouldBeCalled();
$this->addAttributeSorter($sku, 'DESC');
}
示例9: applyMassActionParameters
/**
* Applies mass action parameters on the query builder
*
* @param QueryBuilder $qb
* @param bool $inset
* @param array $values
*/
public function applyMassActionParameters($qb, $inset, $values)
{
if (!empty($values)) {
$valueWhereCondition = $inset ? $qb->expr()->in($this->getAlias(), $values) : $qb->expr()->notIn($this->getAlias(), $values);
$qb->andWhere($valueWhereCondition);
}
if (null !== $qb->getDQLPart('where')) {
$whereParts = $qb->getDQLPart('where')->getParts();
$qb->resetDQLPart('where');
foreach ($whereParts as $part) {
if (!is_string($part) || !strpos($part, 'entityIds')) {
$qb->andWhere($part);
}
}
}
$qb->setParameters($qb->getParameters()->filter(function ($parameter) {
return $parameter->getName() !== 'entityIds';
}));
// remove limit of the query
$qb->setMaxResults(null);
}
示例10: getResult
public function getResult($itemsPerPage, $page, Result $result)
{
$parts = $this->query->getDQLParts();
$from = $parts['from'][0];
$itemsOnPage = clone $this->query;
$itemsOnPage->select('DISTINCT(' . $from->getAlias() . '.id)')->addSelect('(' . $this->getNumRowsSubQuery() . ') as num_rows')->from($from->getFrom(), 'master')->setMaxResults($itemsPerPage)->setFirstResult($itemsPerPage * ($page - 1));
$itemsOnPage = $itemsOnPage->getQuery()->getScalarResult();
$totalResults = 0;
$ids = array();
if ($itemsOnPage) {
$totalResults = $itemsOnPage[0]['num_rows'];
foreach ($itemsOnPage as $itemOnPage) {
$ids[] = $itemOnPage[1];
}
}
$totalPages = ceil($totalResults / $itemsPerPage);
$this->query->resetDQLPart('where');
$this->query->where($from->getAlias() . ' IN (:ids)')->setParameters(array('ids' => $ids));
$results = $this->query->getQuery()->getResult();
return $this->populateResult($result, $totalResults, $totalPages, $page, $results);
}
示例11: execute
/**
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
* @param int $page Page Number
* @param int $limit Rows Per Page
* @param int $gridDataJunction Grid data junction
* @return \APY\DataGridBundle\Grid\Rows
*/
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
{
$this->query = $this->getQueryBuilder();
$this->querySelectfromSource = clone $this->query;
$bindIndex = 123;
$serializeColumns = array();
$where = $gridDataJunction === Column::DATA_CONJUNCTION ? $this->query->expr()->andx() : $this->query->expr()->orx();
foreach ($columns as $column) {
// If a column is a manual field, ie a.col*b.col as myfield, it is added to select from user.
if ($column->getIsManualField() === false) {
$fieldName = $this->getFieldName($column, true);
$this->query->addSelect($fieldName);
$this->querySelectfromSource->addSelect($fieldName);
}
if ($column->isSorted()) {
$this->query->orderBy($this->getFieldName($column), $column->getOrder());
}
if ($column->isFiltered()) {
// Some attributes of the column can be changed in this function
$filters = $column->getFilters('entity');
$isDisjunction = $column->getDataJunction() === Column::DATA_DISJUNCTION;
$hasHavingClause = $column->hasDQLFunction() || $column->getIsAggregate();
$sub = $isDisjunction ? $this->query->expr()->orx() : ($hasHavingClause ? $this->query->expr()->andx() : $where);
foreach ($filters as $filter) {
$operator = $this->normalizeOperator($filter->getOperator());
$q = $this->query->expr()->{$operator}($this->getFieldName($column, false), "?{$bindIndex}");
if ($filter->getOperator() == Column::OPERATOR_NLIKE) {
$q = $this->query->expr()->not($q);
}
$sub->add($q);
if ($filter->getValue() !== null) {
$this->query->setParameter($bindIndex++, $this->normalizeValue($filter->getOperator(), $filter->getValue()));
}
}
if ($hasHavingClause) {
$this->query->andHaving($sub);
} elseif ($isDisjunction) {
$where->add($sub);
}
}
if ($column->getType() === 'array') {
$serializeColumns[] = $column->getId();
}
}
if ($where->count() > 0) {
//Using ->andWhere here to make sure we preserve any other where clauses present in the query builder
//the other where clauses may have come from an external builder
$this->query->andWhere($where);
}
foreach ($this->joins as $alias => $field) {
if (null !== $field['type'] && strtolower($field['type']) === 'inner') {
$join = 'join';
} else {
$join = 'leftJoin';
}
$this->query->{$join}($field['field'], $alias);
$this->querySelectfromSource->{$join}($field['field'], $alias);
}
if ($page > 0) {
$this->query->setFirstResult($page * $limit);
}
if ($limit > 0) {
if ($maxResults !== null && $maxResults - $page * $limit < $limit) {
$limit = $maxResults - $page * $limit;
}
$this->query->setMaxResults($limit);
} elseif ($maxResults !== null) {
$this->query->setMaxResults($maxResults);
}
if (!empty($this->groupBy)) {
$this->query->resetDQLPart('groupBy');
$this->querySelectfromSource->resetDQLPart('groupBy');
foreach ($this->groupBy as $field) {
$this->query->addGroupBy($this->getGroupByFieldName($field));
$this->querySelectfromSource->addGroupBy($this->getGroupByFieldName($field));
}
}
//call overridden prepareQuery or associated closure
$this->prepareQuery($this->query);
$query = $this->query->getQuery();
foreach ($this->hints as $hintKey => $hintValue) {
$query->setHint($hintKey, $hintValue);
}
$items = $query->getResult();
$repository = $this->manager->getRepository($this->entityName);
// Force the primary field to get the entity in the manipulatorRow
$primaryColumnId = null;
foreach ($columns as $column) {
if ($column->isPrimary()) {
$primaryColumnId = $column->getId();
break;
}
}
//.........这里部分代码省略.........
示例12: convertToCount
/**
* @param QueryBuilder $query
* @return QueryBuilder
*/
public function convertToCount(QueryBuilder $query)
{
$selects = $query->getDQLPart('select');
if (count($selects) === 1) {
/** @var Query\Expr\Select $select */
$select = $selects[0];
$selectParts = $select->getParts();
if (count($selectParts) === 1) {
$selectPart = $selectParts[0];
$query->resetDQLPart('select');
$query->select('COUNT(' . $selectPart . ')');
$query->resetDQLPart('orderBy');
$query->setMaxResults(null);
$query->setFirstResult(null);
}
}
return $query;
}
示例13: getQueryCount
/**
* Build and returns Query for count
* @param \Doctrine\ORM\QueryBuilder $queryBuilder
* @param \EMC\TableBundle\Provider\QueryConfigInterface $queryConfig
* @return \Doctrine\ORM\Query
*/
private function getQueryCount(QueryBuilder $queryBuilder, QueryConfigInterface $queryConfig)
{
return $queryBuilder->resetDQLPart('select')->resetDQLPart('orderBy')->resetDQLPart('groupBy')->select('count(distinct ' . $queryBuilder->getRootAlias() . '.id)')->setMaxResults(1)->setFirstResult(0)->getQuery();
}
示例14: execute
/**
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
* @param int $page Page Number
* @param int $limit Rows Per Page
* @param int $gridDataJunction Grid data junction
* @return \APY\DataGridBundle\Grid\Rows
*/
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
{
$this->query = $this->manager->createQueryBuilder($this->class);
$this->query->from($this->class, self::TABLE_ALIAS);
$this->querySelectfromSource = clone $this->query;
$bindIndex = 123;
$serializeColumns = array();
$where = $gridDataJunction === Column::DATA_CONJUNCTION ? $this->query->expr()->andx() : $this->query->expr()->orx();
foreach ($columns as $column) {
$fieldName = $this->getFieldName($column, true);
$this->query->addSelect($fieldName);
$this->querySelectfromSource->addSelect($fieldName);
if ($column->isSorted()) {
$this->query->orderBy($this->getFieldName($column), $column->getOrder());
}
if ($column->isFiltered()) {
// Some attributes of the column can be changed in this function
$filters = $column->getFilters('entity');
$isDisjunction = $column->getDataJunction() === Column::DATA_DISJUNCTION;
$hasHavingClause = $column->hasDQLFunction();
$sub = $isDisjunction ? $this->query->expr()->orx() : ($hasHavingClause ? $this->query->expr()->andx() : $where);
foreach ($filters as $filter) {
$operator = $this->normalizeOperator($filter->getOperator());
$q = $this->query->expr()->{$operator}($this->getFieldName($column, false, $hasHavingClause), "?{$bindIndex}");
if ($filter->getOperator() == Column::OPERATOR_NLIKE) {
$q = $this->query->expr()->not($q);
}
$sub->add($q);
if ($filter->getValue() !== null) {
$this->query->setParameter($bindIndex++, $this->normalizeValue($filter->getOperator(), $filter->getValue()));
}
}
if ($hasHavingClause) {
$this->query->having($sub);
} elseif ($isDisjunction) {
$where->add($sub);
}
}
if ($column->getType() === 'array') {
$serializeColumns[] = $column->getId();
}
}
if ($where->count() > 0) {
$this->query->where($where);
}
foreach ($this->joins as $alias => $field) {
$this->query->leftJoin($field, $alias);
$this->querySelectfromSource->leftJoin($field, $alias);
}
if ($page > 0) {
$this->query->setFirstResult($page * $limit);
}
if ($limit > 0) {
if ($maxResults !== null && $maxResults - $page * $limit < $limit) {
$limit = $maxResults - $page * $limit;
}
$this->query->setMaxResults($limit);
} elseif ($maxResults !== null) {
$this->query->setMaxResults($maxResults);
}
if (!empty($this->groupBy)) {
$this->query->resetDQLPart('groupBy');
$this->querySelectfromSource->resetDQLPart('groupBy');
foreach ($this->groupBy as $field) {
$this->query->addGroupBy($this->getGroupByFieldName($field));
$this->querySelectfromSource->addGroupBy($this->getGroupByFieldName($field));
}
}
//call overridden prepareQuery or associated closure
$this->prepareQuery($this->query);
$query = $this->query->getQuery();
foreach ($this->hints as $hintKey => $hintValue) {
$query->setHint($hintKey, $hintValue);
}
$items = $query->getResult();
// hydrate result
$result = new Rows();
foreach ($items as $item) {
$row = new Row();
foreach ($item as $key => $value) {
$key = str_replace('::', '.', $key);
if (in_array($key, $serializeColumns) && is_string($value)) {
$value = unserialize($value);
}
$row->setField($key, $value);
}
//call overridden prepareRow or associated closure
if (($modifiedRow = $this->prepareRow($row)) != null) {
$result->addRow($modifiedRow);
}
}
return $result;
}
示例15: checkIfSnippetIsDisabled
/**
* Check if a Snippet is disabled
* Internal use only
*
* @param Doctrine\ORM\QueryBuilder $queryBuilder
* @param mixed $result
* @param string $show
*/
protected function checkIfSnippetIsDisabled($queryBuilder, $result, $show)
{
if ($show == 'enabled' && is_null($result)) {
$expr = $queryBuilder->getDQLPart('where')->getParts();
$newExpr = new \Doctrine\ORM\Query\Expr\Andx();
$newExpr->addMultiple(preg_grep("/\\bsnippet.enabled\\b/i", $expr, PREG_GREP_INVERT));
$queryBuilder->resetDQLPart('where');
$queryBuilder->add('where', $newExpr);
if (!is_null($queryBuilder->getQuery()->getOneOrNullResult())) {
throw new \Exception('Result was found but disabled.');
}
}
return $result;
}