[5.8] Add forPageBeforeId method to query builder #28011
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On my current project, I have the need in the admin area to show a chat post in context of its surrounding posts. This allows admins to view a specific chat post that has been reported for abuse (or other potential issues) within context of the chat thread.
The following is a (terrible) example of what I mean just to illustrate the point.
Post 205
is "focused". The page shows a handful of posts before, and after the focused post to give context to the admin.I stumbled upon the existing
forPageAfterId
method which is mostly sugar over some other methods. This is an undocumented method, and is perhaps meant for internal use (i.e. the chunkById method), however it is the perfect tool for retrieving the posts following the focused post. Unfortunately it only shows the page after the given ID, but I am also looking for the page before so I can show the post in context.This PR introduces the complementary method
forPageBeforeId($perPage, $lastId, $column)
.This allows a developer to do something like this...
which results in a collection of posts that contain the focused post, with 15 posts on either side of the focused post, sorted chronologically.