Skip to content

Commit

Permalink
Fixed: #254
Browse files Browse the repository at this point in the history
  • Loading branch information
sammi authored and sammi committed Oct 3, 2015
1 parent 6015d84 commit 5422718
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions EMongoDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ class EMongoDataProvider extends CActiveDataProvider
* @var string
*/
public $modelClass;

/**
* The AR finder instance (eg <code>Post::model()</code>).
* This property can be set by passing the finder instance as the first parameter
* to the constructor. For example, <code>Post::model()->published()</code>.
* @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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5422718

Please sign in to comment.