public function find(Criterion $criterion, $offset, $limit, array $sortClauses = null, array $languageFilter = array(), $doCount = true)
{
$count = $doCount ? $this->getTotalCount($criterion, $languageFilter) : 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.*', $this->handler->quoteColumn('language_mask', 'ezcontentobject'), $this->handler->quoteColumn('initial_language_id', 'ezcontentobject'));
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, $languageFilter);
}
$selectQuery->where($this->criteriaConverter->convertCriteria($selectQuery, $criterion, $languageFilter), $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 not main-languages query
if (!empty($languageFilter['languages'])) {
$selectQuery->where($selectQuery->expr->gt($selectQuery->expr->bitAnd($this->handler->quoteColumn('language_mask', 'ezcontentobject'), $selectQuery->bindValue($this->getLanguageMask($languageFilter), null, PDO::PARAM_INT)), $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));
}