Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Paginate Method #32

Open
nicklee1990 opened this issue Jul 22, 2015 · 0 comments
Open

Implement Paginate Method #32

nicklee1990 opened this issue Jul 22, 2015 · 0 comments

Comments

@nicklee1990
Copy link
Collaborator

Need to implement pagination as handling hundreds of ParseObjects is a bit unwieldy. There's a couple of ways this can be done. One way could be to just get the whole result set, slice it and pass it to the paginate method with the current page and per page, though I personally think because of how Parse works that is against one the main aims of pagination i.e. selecting a specific chunk from the DB.

An alternative would be to just leave the all() method alone and have paginate return paginated results? I say this because I do think having an unpaginated all() method is still quite useful.

A sample solution could be to do something like:

public function paginate($results, $currentPage = 1, $perPage = 10, $keysToInclude = [])
{
    $this->query->count(); // This is for length aware paginator.
    $this->query->limit($perPage);
    for ($i = 0; $i < count($keyToInclude); $i++) {
        $this->query->includeKey($keyToInclude[$i]);
    }
    $this->query->skip((1-$currentPage) * $perPage);
    $results = $this->query->find($this->useMasterKey);

    return $this->paginator->make($results, $currentPage, $perPage)
}

As per Issue #30 we'd need to do the count up front. @hipsterjazzbo any thoughts/suggestions on how you originally envisaged this working? I haven't ran or tested the above code at all, just a thought whilst on my lunch break!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant