eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter::applySelect PHP Метод

applySelect() публичный Метод

Apply select parts of sort clauses to query.
public applySelect ( eZ\Publish\Core\Persistence\Database\SelectQuery $query, array $sortClauses )
$query eZ\Publish\Core\Persistence\Database\SelectQuery
$sortClauses array
    public function applySelect(SelectQuery $query, array $sortClauses)
    {
        foreach ($sortClauses as $nr => $sortClause) {
            foreach ($this->handlers as $handler) {
                if ($handler->accept($sortClause)) {
                    foreach ((array) $handler->applySelect($query, $sortClause, $nr) as $column) {
                        if (strrpos($column, '_null', -6) === false) {
                            $direction = $sortClause->direction;
                        } else {
                            // Always sort null last
                            $direction = SelectQuery::ASC;
                        }
                        $this->sortColumns[$column] = $direction;
                    }
                    continue 2;
                }
            }
            throw new RuntimeException('No handler available for sort clause: ' . get_class($sortClause));
        }
    }

Usage Example

Пример #1
0
 /**
  * Returns total count and data for all Locations satisfying the parameters.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
  * @param int $offset
  * @param int $limit
  * @param null|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses
  * @param bool $doCount
  *
  * @return mixed[][]
  */
 public function find(Criterion $criterion, $offset, $limit, array $sortClauses = null, $doCount = true)
 {
     $count = $doCount ? $this->getTotalCount($criterion, $sortClauses) : null;
     if (!$doCount && $limit === 0) {
         throw new \RuntimeException('Invalid query, can not disable count and request 0 items at the same time');
     }
     if ($limit === 0 || $count !== null && $count <= $offset) {
         return array('count' => $count, 'rows' => array());
     }
     $selectQuery = $this->handler->createSelectQuery();
     $selectQuery->select('ezcontentobject_tree.*');
     if ($sortClauses !== null) {
         $this->sortClauseConverter->applySelect($selectQuery, $sortClauses);
     }
     $selectQuery->from($this->handler->quoteTable('ezcontentobject_tree'))->innerJoin('ezcontentobject', 'ezcontentobject_tree.contentobject_id', 'ezcontentobject.id')->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id');
     if ($sortClauses !== null) {
         $this->sortClauseConverter->applyJoin($selectQuery, $sortClauses);
     }
     $selectQuery->where($this->criteriaConverter->convertCriteria($selectQuery, $criterion), $selectQuery->expr->eq('ezcontentobject.status', $selectQuery->bindValue(1, null, PDO::PARAM_INT)), $selectQuery->expr->eq('ezcontentobject_version.status', $selectQuery->bindValue(1, null, PDO::PARAM_INT)), $selectQuery->expr->neq($this->handler->quoteColumn('depth', 'ezcontentobject_tree'), $selectQuery->bindValue(0, null, PDO::PARAM_INT)));
     if ($sortClauses !== null) {
         $this->sortClauseConverter->applyOrderBy($selectQuery);
     }
     $selectQuery->limit($limit, $offset);
     $statement = $selectQuery->prepare();
     $statement->execute();
     return array('count' => $count, 'rows' => $statement->fetchAll(PDO::FETCH_ASSOC));
 }
All Usage Examples Of eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter::applySelect