/** * 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; }
/** * @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); }
/** * {@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; }
/** * 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'); }
/** * 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; }
/** * {@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; }
/** * 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; }
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'); }
/** * 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); }
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); }
/** * @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; } } // 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); } $row->setPrimaryField($primaryColumnId); //Setting the representative repository for entity retrieving $row->setRepository($repository); //call overridden prepareRow or associated closure if (($modifiedRow = $this->prepareRow($row)) != null) { $result->addRow($modifiedRow); } } return $result; }
/** * @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; }
/** * 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(); }
/** * @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; }
/** * 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; }
/** * Prepare certain search condition * * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare * @param string|null $value Condition data * * @return void */ protected function prepareCndSubstring(\Doctrine\ORM\QueryBuilder $queryBuilder, $value) { $searchWords = $this->getSearchWords($value); $searchPhrase = implode(' ', $searchWords); $cnd = new \Doctrine\ORM\Query\Expr\Orx(); foreach ($this->getSubstringSearchFields() as $field) { foreach ($searchWords as $index => $word) { // Collect OR expressions $cnd->add($field . ' LIKE :word' . $index); $queryBuilder->setParameter('word' . $index, '%' . $word . '%'); } } if ($searchPhrase) { $queryBuilder->addSelect(sprintf('RELEVANCE(\'%s\', %s, %s) as relevance', $value, $this->getRelevanceTitleField(), $this->getRelevanceTextField())); $orderBys = $queryBuilder->getDQLPart('orderBy'); $queryBuilder->resetDQLPart('orderBy'); $queryBuilder->addOrderBy('relevance', 'desc'); foreach ($orderBys as $value) { $queryBuilder->add('orderBy', $value, true); } } $queryBuilder->andWhere($cnd); }
/** * * @param type $columns * @param type $page * @param type $limit * @param type $maxResults * @param type $gridDataJunction * @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 (!in_array($column->getId(), $this->excludedColumns)) { $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) { // \Doctrine\Common\Util\Debug::dump($column); $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)); } } if ($this->groupById === true) { $this->query->addGroupBy($this->getGroupByFieldName('id')); } //call overridden prepareQuery or associated closure $this->prepareQuery($this->query); $query = $this->query->getQuery(); foreach ($this->hints as $hintKey => $hintValue) { $query->setHint($hintKey, $hintValue); } $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'TMSolution\\DataGridBundle\\Walker\\MysqlWalker'); $query->setHint("mysqlWalker.count", true); $items = $query->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); $this->prepareTotalCount(); // $oids = array(); // foreach ($items as $item) { // // $oid = ObjectIdentity::fromDomainObject($item); // $oids[] = $oid; // } // // $this->aclProvider->findAcls($oids); // preload Acls from database // // foreach ($items as $item) { // if (false === $this->securityContext->isGranted('VIEW', $item)) { // // denied // throw new AccessDeniedException(); // } // } // var_dump($items); $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; } } // 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)) { //echo $value."\n"; @($value = unserialize($value)); } $row->setField($key, $value); } $row->setPrimaryField($primaryColumnId); //Setting the representative repository for entity retrieving $row->setRepository($repository); //call overridden prepareRow or associated closure if (($modifiedRow = $this->prepareRow($row)) != null) { $result->addRow($modifiedRow); } } return $result; }
/** * @param QueryBuilder $queryBuilder * @param string $dqlPartName ("join", "select", ...) */ public function cleanQueryBuilderDqlPart(QueryBuilder $queryBuilder, $dqlPartName) { $dqlPart = $queryBuilder->getDQLPart($dqlPartName); $newDqlPart = []; if (count($dqlPart)) { $queryBuilder->resetDQLPart($dqlPartName); if ($dqlPartName == 'join') { foreach ($dqlPart as $root => $elements) { foreach ($elements as $element) { preg_match('/^(?P<joinType>[^ ]+) JOIN (?P<join>[^ ]+) (?P<alias>[^ ]+)/', $element->__toString(), $matches); if (!array_key_exists($matches['alias'], $newDqlPart)) { $newDqlPart[$matches['alias']] = $element; } } $dqlPart[$root] = array_values($newDqlPart); } $dqlPart = array_shift($dqlPart); foreach ($dqlPart as $element) { $queryBuilder->add($dqlPartName, [$element], true); } return; } foreach ($dqlPart as $element) { $newDqlPart[$element->__toString()] = $element; } $dqlPart = array_values($newDqlPart); foreach ($dqlPart as $element) { $queryBuilder->add($dqlPartName, $element, true); } } }
/** * @param QueryBuilder $qb * @param array $value */ protected function addOrder(QueryBuilder $qb, $value) { if (isset($value['orderBy'])) { $qb->resetDQLPart('orderBy'); foreach ((array) $value['orderBy'] as $order) { $qb->addOrderBy($order['column'], $order['dir']); } } }
private static function getTotalResult(QueryBuilder $qb, $class) { if (UtilRepository2::getSession()->get("total") === false) { return 0; } $select = $qb->getDQLPart("select"); $qb->select("count(distinct {$class}.id)"); // print $qb->getQuery()->getSQL();die; $r = $qb->getQuery()->getSingleScalarResult(); $qb->resetDQLPart("select"); foreach ($select as $expr) { $qb->add("select", $expr); } return $r; //Esto es para si por esta via no se puede obtener un unico resultado en la consulta(esto pasa a veces con group by a queries con leftJoin) // if(UtilRepository2::getSession()->get("total") !== false) { // // $select = $qb->getDQLPart("select"); // $qb->select("count($class.id)"); // $r = $qb->getQuery()->getSingleScalarResult(); // $qb->resetDQLPart("select"); // foreach ($select as $expr) // $qb->add("select", $expr); // // return $r; // } // else // { // $select = $qb->getDQLPart("select"); // $qb->select("$class.id"); // // $r = count($qb->getQuery()->getScalarResult()); // $qb->resetDQLPart("select"); // foreach ($select as $expr) // $qb->add("select", $expr); // // return $r; // } }