Skip to content

Default $current for paginator in v0.3.1 #185

@urieluvd

Description

@urieluvd

The plugin versions for older php and elasticsearch has no $current argument in the SearchBuilder->paginate($limit = 25) and SearchBuilder->getCurrentPage() like in latest versions.

tag <= v0.3.1

    public function paginate($limit = 25)
    {
        $page = $this->getCurrentPage();
        $from = $limit * ($page - 1);
        $size = $limit;
        $result = $this->from($from)->size($size)->get();
        return new PlasticPaginator($result, $size, $page);
    }

tag >= v0.5.0

    public function paginate($limit = 25, $current = null)
    {
        $page = $this->getCurrentPage($current);
        $from = $limit * ($page - 1);
        $size = $limit;
        $result = $this->from($from)->size($size)->get();
        return new PlasticPaginator($result, $size, $page);
    }

tag <= v0.3.1

    protected function getCurrentPage()
    {
        return \Request::get('page') ? (int) \Request::get('page') : 1;
    }

tag >= v0.5.0

    protected function getCurrentPage($current)
    {
        return $current ?: (int) \Request::get('page', 1);
    }

It's a minimal change but it is really helpful for projects running on PHP 5.4.* and elasticsearch <= 5.* to return a paginated collection in an api instead of returning the pagination links.

I made a fork to use this asap but i think it would be a good enhancement for the real repo.
By the way thanks for the plugin, makes my life easier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions