From abd60eeee0e697090168b7ba59fd57ffd9c8431b Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 28 Dec 2015 06:30:25 -0800 Subject: [PATCH] Rough data fetch for previous/next posts on a blog Summary: Ref T9897. Not pretty, but pulls data. Test Plan: {F1046464} Reviewers: chad Reviewed By: chad Maniphest Tasks: T9897 Differential Revision: https://secure.phabricator.com/D14903 --- .../post/PhamePostViewController.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 240f8f3a69..0472db20bd 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -120,15 +120,29 @@ final class PhamePostViewController $add_comment = phutil_tag_div('mlb mlt', $add_comment); } + list($prev, $next) = $this->loadAdjacentPosts($post); + $properties = id(new PHUIPropertyListView()) ->setUser($viewer) ->setObject($post); + if ($next) { + $properties->addProperty( + pht('Later Posts'), + $viewer->renderHandleList(mpull($next, 'getPHID'))); + } + + if ($prev) { + $properties->addProperty( + pht('Earlier Posts'), + $viewer->renderHandleList(mpull($prev, 'getPHID'))); + } + $properties->invokeWillRenderEvent(); $crumbs = $this->buildApplicationCrumbs(); - $page = $this->newPage() + $page = $this->newPage() ->setTitle($post->getTitle()) ->setPageObjectPHIDs(array($post->getPHID())) ->setCrumbs($crumbs) @@ -236,4 +250,24 @@ final class PhamePostViewController return phutil_tag_div('phui-document-view-pro-box', $box); } + private function loadAdjacentPosts(PhamePost $post) { + $viewer = $this->getViewer(); + + $query = id(new PhamePostQuery()) + ->setViewer($viewer) + ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) + ->withBlogPHIDs(array($post->getBlog()->getPHID())) + ->setLimit(2); + + $prev = id(clone $query) + ->setAfterID($post->getID()) + ->execute(); + + $next = id(clone $query) + ->setBeforeID($post->getID()) + ->execute(); + + return array($prev, $next); + } + }