Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Merge branch 'f/sinceBlocks' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
canni committed Jan 7, 2011
2 parents 4f6562e + 8a1b823 commit 6b6e607
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 15 deletions.
52 changes: 51 additions & 1 deletion EMongoCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
* For operators list {@see EMongoCriteria::$operators}
*
* @author Dariusz Górecki <[email protected]>
*
* @since v1.0
*/
class EMongoCriteria extends CComponent
{
/**
* @since v1.0
* @var array $operators supported operators lists
*/
public static $operators = array(
'greater' => '$gt',
'>' => '$gt',
Expand Down Expand Up @@ -99,6 +103,7 @@ class EMongoCriteria extends CComponent
* );
* </PRE>
* @param mixed $criteria
* @since v1.0
*/
public function __construct($criteria=null)
{
Expand Down Expand Up @@ -142,6 +147,7 @@ public function __construct($criteria=null)
* - Select fields list will be merged
* - Sort fields list will be merged
* @param array|EMongoCriteria $criteria
* @since v1.0
*/
public function mergeWith($criteria)
{
Expand Down Expand Up @@ -190,6 +196,7 @@ public function mergeWith($criteria)
/**
* If we have operator add it otherwise call parent implementation
* @see CComponent::__call()
* @since v1.0
*/
public function __call($fieldName, $parameters)
{
Expand Down Expand Up @@ -226,12 +233,18 @@ public function __call($fieldName, $parameters)
return parent::__call($fieldName, $parameters);
}

/**
* @since v1.0.2
*/
public function __get($name)
{
array_push($this->_workingFields, $name);
return $this;
}

/**
* @since v1.0.2
*/
public function __set($name, $value)
{
array_push($this->_workingFields, $name);
Expand All @@ -243,42 +256,64 @@ public function __set($name, $value)
/**
* Return query array
* @return array query array
* @since v1.0
*/
public function getConditions()
{
return $this->_conditions;
}

/**
* @since v1.0
*/
public function setConditions(array $conditions)
{
$this->_conditions = $conditions;
}

/**
* @since v1.0
*/
public function getLimit()
{
return $this->_limit;
}

/**
* @since v1.0
*/
public function setLimit($limit)
{
$this->limit($limit);
}

/**
* @since v1.0
*/
public function getOffset()
{
return $this->_offset;
}

/**
* @since v1.0
*/
public function setOffset($offset)
{
$this->offset($offset);
}

/**
* @since v1.0
*/
public function getSort()
{
return $this->_sort;
}

/**
* @since v1.0
*/
public function setSort(array $sort)
{
$this->_sort = $sort;
Expand All @@ -291,23 +326,33 @@ public function setSort(array $sort)
* the fields to be specified as a hashmap. When this
* parameter is set to true, then we'll return
* the fields in this format
* @since v1.3.1
*/
public function getSelect($forCursor = false)
{
if (!$forCursor) return $this->_select;
return array_fill_keys($this->_select, true); // PHP 5.2.0+ required!
}

/**
* @since v1.3.1
*/
public function setSelect(array $select)
{
$this->_select = $select;
}

/**
* @since v1.3.1
*/
public function getWorkingFields()
{
return $this->_workingFields;
}

/**
* @since v1.3.1
*/
public function setWorkingFields(array $select)
{
$this->_workingFields = $select;
Expand All @@ -318,6 +363,7 @@ public function setWorkingFields(array $select)
* Multiple calls to this method will merge all given fields
*
* @param array $fieldList list of fields to select
* @since v1.0
*/
public function select(array $fieldList=null)
{
Expand All @@ -331,6 +377,7 @@ public function select(array $fieldList=null)
* Multiple calls will overrride previous value of limit
*
* @param integer $limit limit
* @since v1.0
*/
public function limit($limit)
{
Expand All @@ -343,6 +390,7 @@ public function limit($limit)
* Multiple calls will override previous value
*
* @param integer $offset offset
* @since v1.0
*/
public function offset($offset)
{
Expand All @@ -355,6 +403,7 @@ public function offset($offset)
* Each call will be groupped with previous calls
* @param string $fieldName
* @param integer $order
* @since v1.0
*/
public function sort($fieldName, $order)
{
Expand All @@ -369,6 +418,7 @@ public function sort($fieldName, $order)
* @param string $fieldName
* @param string $op operator
* @param mixed $value
* @since v1.0
*/
public function addCond($fieldName, $op, $value)
{
Expand Down
14 changes: 14 additions & 0 deletions EMongoCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
*
* Cursor object, that behaves much like the MongoCursor,
* but this one returns instantiated objects
* @since v1.3.4
*/
class EMongoCursor
implements Iterator, Countable
{
/**
* @var MongoCursor $_cursor the MongoCursor returned by the query
* @since v1.3.4
*/
protected $_cursor;

/**
* @var EMongoDocument $_model the model used for instantiating objects
* @since v1.3.4
*/
protected $_model;

Expand All @@ -39,6 +42,7 @@ class EMongoCursor
*
* @param MongoCursor $cursor the cursor returned by the query
* @param EMongoDocument $model the model for instantiating objects
* @since v1.3.4
*/
public function __construct(MongoCursor $cursor, EMongoDocument $model)
{
Expand All @@ -50,6 +54,7 @@ public function __construct(MongoCursor $cursor, EMongoDocument $model)
* Return MongoCursor for additional tuning
*
* @return MongoCursor the cursor used for this query
* @since v1.3.4
*/
public function getCursor()
{
Expand All @@ -59,6 +64,7 @@ public function getCursor()
/**
* Return the current element
* @return EMongoDocument
* @since v1.3.4
*/
public function current()
{
Expand All @@ -72,6 +78,7 @@ public function current()
/**
* Return the key of the current element
* @return scalar
* @since v1.3.4
*/
public function key()
{
Expand All @@ -81,6 +88,7 @@ public function key()
/**
* Move forward to next element
* @return void
* @since v1.3.4
*/
public function next()
{
Expand All @@ -90,6 +98,7 @@ public function next()
/**
* Rewind the Iterator to the first element
* @return void
* @since v1.3.4
*/
public function rewind()
{
Expand All @@ -99,6 +108,7 @@ public function rewind()
/**
* Checks if current position is valid
* @return boolean
* @since v1.3.4
*/
public function valid()
{
Expand All @@ -110,6 +120,7 @@ public function valid()
* {@see http://www.php.net/manual/en/mongocursor.count.php}
* @param boolean $foundOnly default FALSE
* @return integer count of documents found
* @since v1.3.4
*/
public function count($foundOnly = false)
{
Expand All @@ -120,6 +131,7 @@ public function count($foundOnly = false)
* Apply a limit to this cursor
* {@see http://www.php.net/manual/en/mongocursor.limit.php}
* @param integer $limit new limit
* @since v1.3.4
*/
public function limit($limit)
{
Expand All @@ -130,6 +142,7 @@ public function limit($limit)
* Skip a $offset records
* {@see http://www.php.net/manual/en/mongocursor.skip.php}
* @param integer $skip new skip
* @since v1.3.4
*/
public function offset($offset)
{
Expand All @@ -140,6 +153,7 @@ public function offset($offset)
* Apply sorting directives
* {@see http://www.php.net/manual/en/mongocursor.sort.php}
* @param array $sort sorting directives
* @since v1.3.4
*/
public function sort(array $fields)
{
Expand Down
Loading

0 comments on commit 6b6e607

Please sign in to comment.