forked from factorenergia/yii2-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveDataProvider.php
64 lines (60 loc) · 1.81 KB
/
ActiveDataProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @link https://github.com/chrmorandi/yii2-ldap for the canonical source repository
* @package yii2-ldap
* @author Christopher Mota <[email protected]>
* @license MIT License - view the LICENSE file that was distributed with this source code.
*/
namespace websvc\ldap;
use yii\base\InvalidConfigException;
use yii\db\QueryInterface;
/**
* ActiveDataProvider implements a data provider based on [[\yii\db\Query]] and [[\yii\db\ActiveQuery]].
*
* ActiveDataProvider provides data by performing DB queries using [[query]].
*
* The following is an example of using ActiveDataProvider to provide ActiveRecord instances:
*
* ```php
* $provider = new ActiveDataProvider([
* 'query' => Post::find(),
* 'pagination' => [
* 'pageSize' => 20,
* ],
* ]);
*
* // get the posts in the current page
* $posts = $provider->getModels();
* ```
*
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
*
* ```php
* $query = new Query();
* $provider = new ActiveDataProvider([
* 'query' => $query->from('post'),
* 'pagination' => [
* 'pageSize' => 20,
* ],
* ]);
*
* // get the posts in the current page
* $posts = $provider->getModels();
* ```
*
* @author Christopher Mota <[email protected]>
* @since 1.0.0
*/
class ActiveDataProvider extends \yii\data\ActiveDataProvider
{
/**
* @inheritdoc
*/
protected function prepareTotalCount()
{
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
return (int) $this->query->limit($this->getPagination()->getLimit())->offset(-1)->orderBy([])->count('*', $this->db);
}
}