\Ceo\Core\ModelHelpersPaginator

Paginator

In theory, makes paginating large data sets easier. In theory.

    $paginator = new Ceo\Core\ModelHelpers\Paginator(1,2)
        ->from('Ceo\Core\Models\Foo')
        ->orderBy('created_at desc')
        ->where('name = :name:', ['name' => $name])
        ->andWhere('type = :type:', ['type' => $type])
        ->paginate();

    echo json_encode($items);

Summary

Methods
Properties
Constants
__construct()
setPage()
setLimit()
setBuilder()
setFilter()
paginate()
getPagination()
getItems()
__call()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$page
$limit
$builder
$filter
$myPagination
$myItems
N/A

Properties

$page

$page : integer

Page

Type

integer

$limit

$limit : integer

Limit

Type

integer

$builder

$builder : \Ceo\Core\ModelHelpers\QueryBuilder

Query builder

Type

\Ceo\Core\ModelHelpers\QueryBuilder

$filter

$filter : callback

Result filter

Type

callback

$myPagination

$myPagination : object

Pagination object

Type

object

$myItems

$myItems : object

Returned items

Type

object

Methods

__construct()

__construct(integer  $page = 1, integer  $limit = 50) 

Constructor

Parameters

integer $page

page number

integer $limit

return limit

setPage()

setPage(integer  $page) : self

Set the page number

Parameters

integer $page

page

Returns

self

setLimit()

setLimit(integer  $limit) : self

Set return limit

Parameters

integer $limit

Returns

self

setBuilder()

setBuilder(\Ceo\Core\ModelHelpers\QueryBuilder  $builder) : self

Reset the query builder

Parameters

\Ceo\Core\ModelHelpers\QueryBuilder $builder

Returns

self

setFilter()

setFilter(callback  $filter) : self

Set the result filter

The filter will be passed the individual result model:

    $paginator = new Ceo\Core\ModelHelpers\Paginator(1,2)
        ->from('Ceo\Core\Models\Foo')
        ->orderBy('created_at desc')
        ->where('name = :name:', array('name' => $name))
        ->andWhere('type = :type:', array('type' => $type))
        ->setFilter(function($model) {
            return $model->toArray();
        })
        ->paginate();

Parameters

callback $filter

Returns

self

paginate()

paginate() : array

Paginate results.

Returns

array

getPagination()

getPagination() : Object

Return the paginator object

Returns

Object

getItems()

getItems() : Object

Return the fetched items

Returns

Object

__call()

__call(string  $f, array  $args) : self

Forward fluent calls for the querybuilder to the actual querybuilder

Parameters

string $f

method name

array $args

arguments

Returns

self