From 8f42f4b538b21fd96084faff5ee8e05a1b5158a1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 May 2014 08:40:59 -0700 Subject: [PATCH] Move Slowvote rendering into SearchEngine Summary: Ref T4986. This adds a bit of structure for handles, since we used to have Controller utilities but no longer do. Hopefully these will start going faster soon... Test Plan: - Checked feed for collateral damage. - Checked slowvote for collateral damage. - Made a slowvote panel. {F151550} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9010 --- src/__phutil_library_map__.php | 6 +-- .../query/PhabricatorFeedSearchEngine.php | 5 +- .../PhabricatorApplicationSearchEngine.php | 25 ++++++++++ .../PhabricatorSlowvoteListController.php | 48 +----------------- .../query/PhabricatorSlowvoteSearchEngine.php | 49 +++++++++++++++++++ 5 files changed, 79 insertions(+), 54 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f6d979de86..f87a48141b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -5066,11 +5066,7 @@ phutil_register_library_map(array( 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', 'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor', - 'PhabricatorSlowvoteListController' => - array( - 0 => 'PhabricatorSlowvoteController', - 1 => 'PhabricatorApplicationSearchResultsControllerInterface', - ), + 'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvoteOption' => 'PhabricatorSlowvoteDAO', 'PhabricatorSlowvotePHIDTypePoll' => 'PhabricatorPHIDType', 'PhabricatorSlowvotePoll' => diff --git a/src/applications/feed/query/PhabricatorFeedSearchEngine.php b/src/applications/feed/query/PhabricatorFeedSearchEngine.php index 7aca133cc3..725e2d474e 100644 --- a/src/applications/feed/query/PhabricatorFeedSearchEngine.php +++ b/src/applications/feed/query/PhabricatorFeedSearchEngine.php @@ -124,9 +124,10 @@ final class PhabricatorFeedSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } - public function renderResults( + public function renderResultList( array $objects, - PhabricatorSavedQuery $query) { + PhabricatorSavedQuery $query, + array $handles) { $builder = new PhabricatorFeedBuilder($objects); $builder->setShowHovercards(true); diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index a999635fde..e05261bd47 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -561,6 +561,31 @@ abstract class PhabricatorApplicationSearchEngine { public function renderResults( array $objects, PhabricatorSavedQuery $query) { + + $phids = $this->getRequiredHandlePHIDsForResultList($objects, $query); + + if ($phids) { + $handles = id(new PhabricatorHandleQuery()) + ->setViewer($this->requireViewer()) + ->witHPHIDs($phids) + ->execute(); + } else { + $handles = array(); + } + + return $this->renderResultList($objects, $query, $handles); + } + + public function getRequiredHandlePHIDsForResultList( + array $objects, + PhabricatorSavedQuery $query) { + return array(); + } + + public function renderResultList( + array $objects, + PhabricatorSavedQuery $query, + array $handles) { throw new Exception(pht('Not supported here yet!')); } diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteListController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteListController.php index 9a47753196..866b25c76c 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvoteListController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteListController.php @@ -1,11 +1,7 @@ delegateToController($controller); } - public function renderResultsList( - array $polls, - PhabricatorSavedQuery $query) { - assert_instances_of($polls, 'PhabricatorSlowvotePoll'); - $viewer = $this->getRequest()->getUser(); - - $list = id(new PHUIObjectItemListView()) - ->setUser($viewer); - - $phids = mpull($polls, 'getAuthorPHID'); - $handles = $this->loadViewerHandles($phids); - - foreach ($polls as $poll) { - $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); - if ($poll->getAuthorPHID()) { - $author = $handles[$poll->getAuthorPHID()]->renderLink(); - } else { - $author = null; - } - - $item = id(new PHUIObjectItemView()) - ->setObjectName('V'.$poll->getID()) - ->setHeader($poll->getQuestion()) - ->setHref('/V'.$poll->getID()) - ->setDisabled($poll->getIsClosed()) - ->addIcon('none', $date_created); - - $description = $poll->getDescription(); - if (strlen($description)) { - $item->addAttribute(phutil_utf8_shorten($poll->getDescription(), 120)); - } - - if ($author) { - $item->addByline(pht('Author: %s', $author)); - } - - $list->addItem($item); - } - - return $list; - } - } diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php index 5217336501..1377cfaab9 100644 --- a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php +++ b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php @@ -115,4 +115,53 @@ final class PhabricatorSlowvoteSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + public function getRequiredHandlePHIDsForResultList( + array $polls, + PhabricatorSavedQuery $query) { + return mpull($polls, 'getAuthorPHID'); + } + + public function renderResultList( + array $polls, + PhabricatorSavedQuery $query, + array $handles) { + + assert_instances_of($polls, 'PhabricatorSlowvotePoll'); + $viewer = $this->requireViewer(); + + $list = id(new PHUIObjectItemListView()) + ->setUser($viewer); + + $phids = mpull($polls, 'getAuthorPHID'); + + foreach ($polls as $poll) { + $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); + if ($poll->getAuthorPHID()) { + $author = $handles[$poll->getAuthorPHID()]->renderLink(); + } else { + $author = null; + } + + $item = id(new PHUIObjectItemView()) + ->setObjectName('V'.$poll->getID()) + ->setHeader($poll->getQuestion()) + ->setHref('/V'.$poll->getID()) + ->setDisabled($poll->getIsClosed()) + ->addIcon('none', $date_created); + + $description = $poll->getDescription(); + if (strlen($description)) { + $item->addAttribute(phutil_utf8_shorten($poll->getDescription(), 120)); + } + + if ($author) { + $item->addByline(pht('Author: %s', $author)); + } + + $list->addItem($item); + } + + return $list; + } + }