1 | <?php |
||
45 | class DataProvider implements DataProviderInterface |
||
46 | { |
||
47 | |||
48 | /** |
||
49 | * Instance of model |
||
50 | * @var Document |
||
51 | * @since v1.0 |
||
52 | */ |
||
53 | public $model; |
||
54 | |||
55 | /** |
||
56 | * Finder instance |
||
57 | * @var FinderInterface |
||
58 | */ |
||
59 | private $finder = null; |
||
60 | |||
61 | /** |
||
62 | * @var CriteriaInterface |
||
63 | */ |
||
64 | private $criteria; |
||
65 | |||
66 | /** |
||
67 | * @var SortInterface |
||
68 | */ |
||
69 | private $sort; |
||
70 | private $data = null; |
||
71 | private $totalItemCount = null; |
||
72 | |||
73 | /** |
||
74 | * Pagination instance |
||
75 | * @var PaginationInterface |
||
76 | */ |
||
77 | private $pagination = null; |
||
78 | |||
79 | /** |
||
80 | * Constructor. |
||
81 | * @param mixed $modelClass the model class (e.g. 'Post') or the model finder instance |
||
82 | * (e.g. <code>Post::model()</code>, <code>Post::model()->published()</code>). |
||
83 | * @param array $config configuration (name=>value) to be applied as the initial property values of this class. |
||
84 | * @since v1.0 |
||
85 | */ |
||
86 | 1 | public function __construct($modelClass, $config = []) |
|
148 | |||
149 | /** |
||
150 | * Get model used by this dataprovider |
||
151 | * @return AnnotatedInterface |
||
152 | */ |
||
153 | public function getModel() |
||
157 | |||
158 | /** |
||
159 | * Returns the criteria. |
||
160 | * @return Criteria the query criteria |
||
161 | * @since v1.0 |
||
162 | */ |
||
163 | public function getCriteria() |
||
172 | |||
173 | /** |
||
174 | * Sets the query criteria. |
||
175 | * @param CriteriaInterface|array $criteria the query criteria. Array representing the MongoDB query criteria. |
||
176 | * @since v1.0 |
||
177 | */ |
||
178 | public function setCriteria($criteria) |
||
193 | |||
194 | /** |
||
195 | * Returns the sort object. |
||
196 | * @return Sort the sorting object. If this is false, it means the sorting is disabled. |
||
197 | */ |
||
198 | 1 | public function getSort() |
|
207 | |||
208 | /** |
||
209 | * Set sort |
||
210 | * @param SortInterface $sort |
||
211 | * @return DataProvider |
||
212 | */ |
||
213 | public function setSort(SortInterface $sort) |
||
219 | |||
220 | /** |
||
221 | * Returns the pagination object. |
||
222 | * @param string $className the pagination object class name, use this param to override default pagination class. |
||
223 | * @return Pagination|false the pagination object. If this is false, it means the pagination is disabled. |
||
224 | */ |
||
225 | 1 | public function getPagination($className = Pagination::class) |
|
248 | |||
249 | /** |
||
250 | * Returns the number of data items in the current page. |
||
251 | * This is equivalent to <code>count($provider->getData())</code>. |
||
252 | * When {@link pagination} is set false, this returns the same value as {@link totalItemCount}. |
||
253 | * @param boolean $refresh whether the number of data items should be re-calculated. |
||
254 | * @return integer the number of data items in the current page. |
||
255 | */ |
||
256 | public function getItemCount($refresh = false) |
||
260 | |||
261 | /** |
||
262 | * Returns the total number of data items. |
||
263 | * When {@link pagination} is set false, this returns the same value as {@link itemCount}. |
||
264 | * @return integer total number of possible data items. |
||
265 | */ |
||
266 | 1 | public function getTotalItemCount() |
|
274 | |||
275 | /** |
||
276 | * Fetches the data from the persistent data storage. |
||
277 | * @return Document[]|Cursor list of data items |
||
278 | * @since v1.0 |
||
279 | */ |
||
280 | 1 | protected function fetchData() |
|
297 | |||
298 | /** |
||
299 | * Returns the data items currently available, ensures that result is at leas empty array |
||
300 | * @param boolean $refresh whether the data should be re-fetched from persistent storage. |
||
301 | * @return array the list of data items currently available in this data provider. |
||
302 | */ |
||
303 | 1 | public function getData($refresh = false) |
|
315 | |||
316 | } |
||
317 |