Passed
Push — master ( 83b985...d96c9f )
by Andrii
10:36
created

ActiveDataProvider::enableSynchronousCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart;
12
13
class ActiveDataProvider extends \yii\data\ActiveDataProvider
14
{
15
    /**
16
     * @var ActiveQuery the query that is used to fetch data models and [[totalCount]]
17
     * if it is not explicitly set
18
     */
19
    public $query;
20
21
    /**
22
     * To improve performance, implemented grid summary and pager loading via AJAX when this attribute is `false`
23
     * There is a possibility set this attribute via DI
24
     * @see \hipanel\base\SearchModelTrait::search()
25
     *
26
     * @var bool
27
     */
28
    public bool $countSynchronously = false;
29
30
    public function enableSynchronousCount(): void
31
    {
32
        $this->countSynchronously = true;
33
    }
34
35
    protected function prepareTotalCount()
36
    {
37
        return $this->countSynchronously ? parent::prepareTotalCount() : $this->getPagination()->pageSize + 1;
38
    }
39
}
40