/**
  * Returns total results count for $criterion and $sortClauses
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
  * @param null|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses
  *
  * @return array
  */
 protected function getTotalCount(Criterion $criterion, $sortClauses)
 {
     $query = $this->handler->createSelectQuery();
     $query->select($query->alias($query->expr->count('*'), 'count'))->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($query, $sortClauses);
     }
     $query->where($this->criteriaConverter->convertCriteria($query, $criterion), $query->expr->eq('ezcontentobject.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->eq('ezcontentobject_version.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->neq($this->handler->quoteColumn("depth"), $query->bindValue(0, null, PDO::PARAM_INT)));
     $statement = $query->prepare();
     $statement->execute();
     $res = $statement->fetchAll(PDO::FETCH_ASSOC);
     return (int) $res[0]['count'];
 }
Exemplo n.º 2
0
 /**
  * Get sorted arrays of content IDs, which should be returned
  *
  * @param Criterion $filter
  * @param array $sort
  * @param mixed $offset
  * @param mixed $limit
  * @param mixed $translations
  *
  * @return int[]
  */
 protected function getContentInfoList(Criterion $filter, $sort, $offset, $limit, $translations)
 {
     $query = $this->handler->createSelectQuery();
     $query->select('DISTINCT ezcontentobject.id', 'ezcontentobject.*', $this->handler->aliasedColumn($query, 'main_node_id', 'main_tree'));
     if ($sort !== null) {
         $this->sortClauseConverter->applySelect($query, $sort);
     }
     $query->from($this->handler->quoteTable('ezcontentobject'))->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id')->leftJoin($this->handler->alias($this->handler->quoteTable('ezcontentobject_tree'), $this->handler->quoteIdentifier('main_tree')), $query->expr->lAnd($query->expr->eq($this->handler->quoteColumn("contentobject_id", "main_tree"), $this->handler->quoteColumn("id", "ezcontentobject")), $query->expr->eq($this->handler->quoteColumn("main_node_id", "main_tree"), $this->handler->quoteColumn("node_id", "main_tree"))));
     if ($sort !== null) {
         $this->sortClauseConverter->applyJoin($query, $sort);
     }
     $query->where($this->getQueryCondition($filter, $query, $translations));
     if ($sort !== null) {
         $this->sortClauseConverter->applyOrderBy($query);
     }
     $query->limit($limit, $offset);
     $statement = $query->prepare();
     $statement->execute();
     return $statement->fetchAll(\PDO::FETCH_ASSOC);
 }
 /**
  * Get sorted arrays of content IDs, which should be returned
  *
  * @param Criterion $filter
  * @param array $sort
  * @param mixed $offset
  * @param mixed $limit
  * @param mixed $translations
  *
  * @return int[]
  */
 protected function getContentIds(Criterion $filter, $sort, $offset, $limit, $translations)
 {
     $query = $this->handler->createSelectQuery();
     $query->select($this->handler->quoteColumn('id', 'ezcontentobject'));
     if ($sort !== null) {
         $this->sortClauseConverter->applySelect($query, $sort);
     }
     $query->from($this->handler->quoteTable('ezcontentobject'));
     $query->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id');
     if ($sort !== null) {
         $this->sortClauseConverter->applyJoin($query, $sort);
     }
     $query->where($this->getQueryCondition($filter, $query, $translations));
     if ($sort !== null) {
         $this->sortClauseConverter->applyOrderBy($query);
     }
     $query->limit($limit, $offset);
     $statement = $query->prepare();
     $statement->execute();
     return $statement->fetchAll(\PDO::FETCH_COLUMN);
 }