Mgallegos\LaravelJqgrid\Repositories\EloquentRepositoryAbstract::getTotalNumberOfRows PHP Метод

getTotalNumberOfRows() публичный Метод

Calculate the number of rows. It's used for paging the result.
public getTotalNumberOfRows ( array $filters = [] ) : integer
$filters array An array of filters, example: array(array('field'=>'column index/name 1','op'=>'operator','data'=>'searched string column 1'), array('field'=>'column index/name 2','op'=>'operator','data'=>'searched string column 2')) The 'field' key will contain the 'index' column property if is set, otherwise the 'name' column property. The 'op' key will contain one of the following operators: '=', '<', '>', '<=', '>=', '<>', '!=','like', 'not like', 'is in', 'is not in'. when the 'operator' is 'like' the 'data' already contains the '%' character in the appropiate position. The 'data' key will contain the string searched by the user.
Результат integer Total number of rows
    public function getTotalNumberOfRows(array $filters = array())
    {
        return intval($this->Database->whereNested(function ($query) use($filters) {
            foreach ($filters as $filter) {
                if ($filter['op'] == 'is in') {
                    $query->whereIn($filter['field'], explode(',', $filter['data']));
                    continue;
                }
                if ($filter['op'] == 'is not in') {
                    $query->whereNotIn($filter['field'], explode(',', $filter['data']));
                    continue;
                }
                if ($filter['op'] == 'is null') {
                    $query->whereNull($filter['field']);
                    continue;
                }
                if ($filter['op'] == 'is not null') {
                    $query->whereNotNull($filter['field']);
                    continue;
                }
                if ($filter['op'] == 'between') {
                    if (strpos($filter['data'], ' - ') !== false) {
                        list($from, $to) = explode(' - ', $filter['data'], 2);
                        if (!$from or !$to) {
                            throw new \Exception('Invalid between format');
                        }
                    } else {
                        throw new \Exception('Invalid between format');
                    }
                    if ($from == $to) {
                        $query->where($filter['field'], $from);
                    } else {
                        //$query->whereBetween($filter['field'], array($from, $to));
                        $query->where($filter['field'], '>=', $from);
                        $query->where($filter['field'], '<=', $to);
                    }
                    continue;
                }
                $query->where($filter['field'], $filter['op'], $filter['data']);
            }
        })->count());
    }
EloquentRepositoryAbstract