本文整理汇总了PHP中Doctrine\Common\Collections\Criteria::getMaxResults方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::getMaxResults方法的具体用法?PHP Criteria::getMaxResults怎么用?PHP Criteria::getMaxResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Criteria
的用法示例。
在下文中一共展示了Criteria::getMaxResults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConstructor
public function testConstructor()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
$this->assertSame($expr, $criteria->getWhereExpression());
$this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
$this->assertEquals(10, $criteria->getFirstResult());
$this->assertEquals(20, $criteria->getMaxResults());
}
示例2: apply
/**
* {@inheritdoc}
*/
public function apply(Criteria $criteria, FilterValue $value = null)
{
$val = null !== $value ? $value->getValue() : $this->getDefaultValue();
if (null !== $val) {
$pageSize = $criteria->getMaxResults();
if (null !== $pageSize) {
$criteria->setFirstResult(QueryUtils::getPageOffset($val, $pageSize));
}
}
}
示例3: addCriteria
/**
* @param QueryBuilder $qb
* @param Criteria $criteria
*/
public static function addCriteria(QueryBuilder $qb, Criteria $criteria)
{
$rootAlias = $qb->getRootAlias();
$visitor = new QueryExpressionVisitor($rootAlias);
if ($whereExpression = $criteria->getWhereExpression()) {
$qb->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$qb->getParameters()->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$qb->addOrderBy($rootAlias . '.' . $sort, $order);
}
}
// Overwrite limits only if they was set in criteria
if (($firstResult = $criteria->getFirstResult()) !== null) {
$qb->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$qb->setMaxResults($maxResults);
}
}
示例4: loadCriteria
/**
* Loads Entities matching the given Criteria object.
*
* @param \Doctrine\Common\Collections\Criteria $criteria
*
* @return array
*/
public function loadCriteria(Criteria $criteria)
{
$orderBy = $criteria->getOrderings();
$limit = $criteria->getMaxResults();
$offset = $criteria->getFirstResult();
$query = $this->getSelectSQL($criteria, null, 0, $limit, $offset, $orderBy);
list($params, $types) = $this->expandCriteriaParameters($criteria);
$stmt = $this->conn->executeQuery($query, $params, $types);
$hydrator = $this->em->newHydrator(($this->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
return $hydrator->hydrateAll($stmt, $this->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true));
}
示例5: addCriteria
/**
* Adds criteria to the query.
*
* Adds where expressions with AND operator.
* Adds orderings.
* Overrides firstResult and maxResults if they're set.
*
* @param Criteria $criteria
* @return QueryBuilder
* @throws Query\QueryException
*/
public function addCriteria(Criteria $criteria)
{
$allAliases = $this->getAllAliases();
if (!isset($allAliases[0])) {
throw new Query\QueryException('No aliases are set before invoking addCriteria().');
}
$visitor = new QueryExpressionVisitor($this->getAllAliases());
if ($whereExpression = $criteria->getWhereExpression()) {
$this->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$this->parameters->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$hasValidAlias = false;
foreach ($allAliases as $alias) {
if (strpos($sort . '.', $alias . '.') === 0) {
$hasValidAlias = true;
break;
}
}
if (!$hasValidAlias) {
$sort = $allAliases[0] . '.' . $sort;
}
$this->addOrderBy($sort, $order);
}
}
// Overwrite limits only if they was set in criteria
if (($firstResult = $criteria->getFirstResult()) !== null) {
$this->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$this->setMaxResults($maxResults);
}
return $this;
}
示例6: addCriteria
/**
* Add criteria to query.
* Add where expressions with AND operator.
* Add orderings.
* Override firstResult and maxResults if they set.
*
* @param Criteria $criteria
* @return QueryBuilder
*/
public function addCriteria(Criteria $criteria)
{
$visitor = new QueryExpressionVisitor();
if ($whereExpression = $criteria->getWhereExpression()) {
$this->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$this->parameters->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$this->addOrderBy($sort, $order);
}
}
// Overwrite limits only if they was set in criteria
if (($firstResult = $criteria->getFirstResult()) !== null) {
$this->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$this->setMaxResults($maxResults);
}
return $this;
}
示例7: loadCriteria
/**
* {@inheritdoc}
*/
public function loadCriteria(Criteria $criteria)
{
$orderBy = $criteria->getOrderings();
$limit = $criteria->getMaxResults();
$offset = $criteria->getFirstResult();
$query = $this->persister->getSelectSQL($criteria);
$hash = $this->getHash($query, $criteria, $orderBy, $limit, $offset);
$rsm = $this->getResultSetMapping();
$queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey);
$queryCache = $this->cache->getQueryCache($this->regionName);
$cacheResult = $queryCache->get($queryKey, $rsm);
if ($cacheResult !== null) {
if ($this->cacheLogger) {
$this->cacheLogger->queryCacheHit($this->regionName, $queryKey);
}
return $cacheResult;
}
$result = $this->persister->loadCriteria($criteria);
$cached = $queryCache->put($queryKey, $rsm, $result);
if ($this->cacheLogger) {
if ($result) {
$this->cacheLogger->queryCacheMiss($this->regionName, $queryKey);
}
if ($cached) {
$this->cacheLogger->queryCachePut($this->regionName, $queryKey);
}
}
return $result;
}
示例8: loadCriteria
/**
* Load Entities matching the given Criteria object
*
* @param \Doctrine\Common\Collections\Criteria $criteria
*
* @return array
*/
public function loadCriteria(Criteria $criteria)
{
$orderBy = $criteria->getOrderings();
$limit = $criteria->getMaxResults();
$offset = $criteria->getFirstResult();
$sql = $this->_getSelectEntitiesSQL($criteria, null, 0, $limit, $offset, $orderBy);
list($params, $types) = $this->expandCriteriaParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
$hydrator = $this->_em->newHydrator($this->_selectJoinSql ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
return $hydrator->hydrateAll($stmt, $this->_rsm, array('deferEagerLoads' => true));
}
示例9: matching
/**
* {@inheritDoc}
*/
public function matching(Criteria $criteria)
{
$expr = $criteria->getWhereExpression();
$filtered = $this->elements;
if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}
if ($orderings = $criteria->getOrderings()) {
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1);
}
usort($filtered, $next);
}
$offset = $criteria->getFirstResult();
$length = $criteria->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}
return new static($filtered);
}
示例10: matching
/**
* Selects all elements from a selectable that match the expression and
* returns a new collection containing these elements.
*
* @see Selectable::matching()
* @param Criteria $criteria
* @return Collection
*/
public function matching(Criteria $criteria)
{
$visitor = new QueryExpressionVisitor($this->createQueryBuilder());
$queryBuilder = $this->createQueryBuilder();
if ($criteria->getWhereExpression() !== null) {
$expr = $visitor->dispatch($criteria->getWhereExpression());
$queryBuilder->setQueryArray($expr->getQuery());
}
if ($criteria->getMaxResults() !== null) {
$queryBuilder->limit($criteria->getMaxResults());
}
if ($criteria->getFirstResult() !== null) {
$queryBuilder->skip($criteria->getFirstResult());
}
if ($criteria->getOrderings() !== null) {
$queryBuilder->sort($criteria->getOrderings());
}
// @TODO: wrap around a specialized Collection for efficient count on large collections
return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray());
}
示例11: serialize
/**
* Serializes a the given criteria to a PHP serialized format.
*
* @param Criteria $criteria The criteria to serialize.
* @return string
*/
public function serialize(Criteria $criteria)
{
$structure = array('whereExpression' => $this->dispatch($criteria->getWhereExpression()), 'firstResult' => $criteria->getFirstResult(), 'maxResults' => $criteria->getMaxResults(), 'orderings' => $criteria->getOrderings());
return serialize($structure);
}
示例12: testReturnsCorrectCount
/**
* @covers \DoctrineModule\Paginator\Adapter\Selectable::count
*/
public function testReturnsCorrectCount()
{
$selectable = $this->getMock('Doctrine\\Common\\Collections\\Selectable');
$expression = Criteria::expr()->eq('foo', 'bar');
$criteria = new Criteria($expression, array('baz' => Criteria::DESC), 10, 20);
$adapter = new SelectableAdapter($selectable, $criteria);
$selectable->expects($this->once())->method('matching')->with($this->callback(function (Criteria $criteria) use($expression) {
return $criteria->getWhereExpression() == $expression && array('baz' => Criteria::DESC) === $criteria->getOrderings() && null === $criteria->getFirstResult() && null === $criteria->getMaxResults();
}))->will($this->returnValue(new ArrayCollection(range(1, 101))));
$this->assertEquals(101, $adapter->count());
$this->assertSame(10, $criteria->getFirstResult(), 'Original criteria was not modified');
$this->assertSame(20, $criteria->getMaxResults(), 'Original criteria was not modified');
}
示例13: matching
/**
* Select all elements from a selectable that match the criteria and
* return a new collection containing these elements.
*
* @param Criteria $criteria
* @return Collection2
*/
public function matching(Criteria $criteria)
{
$this->initialize();
$expr = $criteria->getWhereExpression();
$filtered = $this->entities;
if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}
if (null !== ($orderings = $criteria->getOrderings())) {
$next = null;
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == 'DESC' ? -1 : 1, $next);
}
usort($filtered, $next);
}
$offset = $criteria->getFirstResult();
$length = $criteria->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}
return new ArrayCollection($filtered);
}
示例14: cloneCriteria
/**
* Makes a clone of the given Criteria
*
* @param Criteria $criteria
*
* @return Criteria
*/
protected function cloneCriteria(Criteria $criteria)
{
return new Criteria($criteria->getWhereExpression(), $criteria->getOrderings(), $criteria->getFirstResult(), $criteria->getMaxResults());
}
示例15: getLimitSql
/**
* @param Criteria $criteria
* @return string
* @throws \Doctrine\DBAL\DBALException
*/
private function getLimitSql(Criteria $criteria)
{
$limit = $criteria->getMaxResults();
$offset = $criteria->getFirstResult();
if ($limit !== null || $offset !== null) {
return $this->platform->modifyLimitQuery('', $limit, $offset);
}
return '';
}