diff --git a/EMongoDataProvider.php b/EMongoDataProvider.php index 879aaa0..83fa939 100644 --- a/EMongoDataProvider.php +++ b/EMongoDataProvider.php @@ -13,7 +13,7 @@ class EMongoDataProvider extends CActiveDataProvider * @var string */ public $modelClass; - + /** * The AR finder instance (eg Post::model()). * This property can be set by passing the finder instance as the first parameter @@ -21,25 +21,25 @@ class EMongoDataProvider extends CActiveDataProvider * @var EMongoModel */ public $model; - + /** * The name of key attribute for {@link modelClass}. If not set, * it means the primary key of the corresponding database table will be used. * @var string */ public $keyAttribute = '_id'; - + /** * @var array The criteria array */ private $_criteria; - + /** * The internal MongoDB cursor as a MongoCursor instance * @var EMongoCursor|MongoCursor */ private $_cursor; - + /** * @var EMongoSort */ @@ -99,7 +99,7 @@ public function fetchData() // I have not refactored this line considering that the condition may have changed from total item count to here, maybe. $this->_cursor = $this->model->find( isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : array(), - isset($criteria['project']) && !empty($criteria['project']) ? $criteria['project'] : array() + isset($criteria['project']) && !empty($criteria['project']) ? $criteria['project'] : array() ); // If we have sort and limit and skip setup within the incoming criteria let's set it @@ -159,6 +159,25 @@ public function calculateTotalItemCount() return $this->_cursor->count(); } + public function setSort($value) + { + if(is_array($value)) + { + if(isset($value['class'])) + { + $sort=$this->getSort($value['class']); + unset($value['class']); + } + else + $sort=$this->getSort(); + + foreach($value as $k=>$v) + $sort->$k=$v; + } + else + $this->_sort=$value; + } + /** * Returns the sort object. We don't use the newer getSort function because it does not have the same functionality * between 1.1.10 and 1.1.13, the functionality we need is actually in 1.1.13 only