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