Maslosoft Mangan API
Class Conditions
Conditions builder helper class. This exposes fluid interface for building complex queries.
Building complex queries can lead to (semi) manually constructing deeply nested array of conditions,
which is both unreadable and unreliable, espacially when user with $or
, $and
, $not
etc.
This class is meant to overcome this issue, by providing fluid, cascading interface.
Example for simple query, let's find visits
larger than 30 and lesser than 100:
$conditions = new Conditions($model) $conditions->visits->gt(30)->lt(100);
However real improvement comes when used with more complex query. In this example we
search for visits
greater than 10 and lesser than 200 or greater than 100 and
lesser than 200, where active
is true:
$c1 = new Conditions($model); $c1->visits->gt(10)->lt(20); $c2->visits->gt(100)->lt(200); $condtions = new Conditions($model); $conditions->active = true; $conditions->or($c1, $c2);
In above example mongodb conditions array is quite verbose and depth, however
with Conditions
class it is fairly clean and easy to create it.
When conditions setup is finished, this should be passed to Criteria
by setCriteria
:
$criteria = new Criteria(); $criteria->setconditions($conditions);
Or alternatively it can be passed directly into constructor:
$criteria = new Criteria($conditions);
Methods summary
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|