3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Collections;
22 use Doctrine\Common\Collections\Expr\Expression;
23 use Doctrine\Common\Collections\Expr\CompositeExpression;
26 * Criteria for filtering Selectable collections.
28 * @author Benjamin Eberlei <kontakt@beberlei.de>
44 * @var \Doctrine\Common\Collections\ExpressionBuilder
46 private static $expressionBuilder;
49 * @var \Doctrine\Common\Collections\Expr\Expression
69 * Creates an instance of the class.
73 public static function create()
79 * Return the expression builder.
81 * @return \Doctrine\Common\Collections\ExpressionBuilder
83 public static function expr()
85 if (self::$expressionBuilder === null) {
86 self::$expressionBuilder = new ExpressionBuilder();
88 return self::$expressionBuilder;
92 * Construct new criteria
94 * @param Expression $expression
95 * @param array $orderings
96 * @param int $firstResult
97 * @param int $maxResults
99 public function __construct(Expression $expression = null, array $orderings = null, $firstResult = null, $maxResults = null)
101 $this->expression = $expression;
102 $this->orderings = $orderings;
103 $this->firstResult = $firstResult;
104 $this->maxResults = $maxResults;
108 * Set the where expression to evaluate when this criteria is searched for.
113 public function where(Expression $expression)
115 $this->expression = $expression;
120 * Append the where expression to evaluate when this criteria is searched for
121 * using an AND with previous expression.
126 public function andWhere(Expression $expression)
128 if ($this->expression === null) {
129 return $this->where($expression);
132 $this->expression = new CompositeExpression(CompositeExpression::TYPE_AND, array(
133 $this->expression, $expression
140 * Append the where expression to evaluate when this criteria is searched for
141 * using an OR with previous expression.
146 public function orWhere(Expression $expression)
148 if ($this->expression === null) {
149 return $this->where($expression);
152 $this->expression = new CompositeExpression(CompositeExpression::TYPE_OR, array(
153 $this->expression, $expression
160 * Get the expression attached to this criteria.
162 * @return Expression|null
164 public function getWhereExpression()
166 return $this->expression;
170 * Get current orderings of this Criteria
174 public function getOrderings()
176 return $this->orderings;
180 * Set the ordering of the result of this criteria.
182 * Keys are field and values are the order, being either ASC or DESC.
185 * @see Criteria::DESC
190 public function orderBy(array $orderings)
192 $this->orderings = $orderings;
197 * Get current first result option of the critera.
199 * @return firstResult.
201 public function getFirstResult()
203 return $this->firstResult;
207 * Set number of first result that this criteria should return.
209 * @param firstResult the value to set.
212 public function setFirstResult($firstResult)
214 $this->firstResult = $firstResult;
221 * @return maxResults.
223 public function getMaxResults()
225 return $this->maxResults;
231 * @param maxResults the value to set.
234 public function setMaxResults($maxResults)
236 $this->maxResults = $maxResults;