From cff98438593a7c2c283c7c9323014260a20e2ed6 Mon Sep 17 00:00:00 2001 From: Bryan Cuccioli Date: Thu, 21 Mar 2013 16:04:29 -0700 Subject: [PATCH] Add basic token leader board functionality. Summary: Implement basic token leader board. No pagination yet. Test Plan: Assign some tasks tokens and check that they are displayed properly. Reviewers: epriestley CC: aran, Korvin, chad Maniphest Tasks: T2689 Differential Revision: https://secure.phabricator.com/D5379 --- src/__phutil_library_map__.php | 4 ++ .../PhabricatorApplicationTokens.php | 1 + .../controller/PhabricatorTokenController.php | 2 +- .../PhabricatorTokenLeaderController.php | 58 +++++++++++++++++++ .../query/PhabricatorTokenReceiverQuery.php | 35 +++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/applications/tokens/controller/PhabricatorTokenLeaderController.php create mode 100644 src/applications/tokens/query/PhabricatorTokenReceiverQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d0535ba46a..e2eb1ec777 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1390,8 +1390,10 @@ phutil_register_library_map(array( 'PhabricatorTokenGivenEditor' => 'applications/tokens/editor/PhabricatorTokenGivenEditor.php', 'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php', 'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php', + 'PhabricatorTokenLeaderController' => 'applications/tokens/controller/PhabricatorTokenLeaderController.php', 'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php', 'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php', + 'PhabricatorTokenReceiverQuery' => 'applications/tokens/query/PhabricatorTokenReceiverQuery.php', 'PhabricatorTokenUIEventListener' => 'applications/tokens/event/PhabricatorTokenUIEventListener.php', 'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php', 'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php', @@ -2992,7 +2994,9 @@ phutil_register_library_map(array( 'PhabricatorTokenGivenEditor' => 'PhabricatorEditor', 'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory', 'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorTokenLeaderController' => 'PhabricatorTokenController', 'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorTokenUIEventListener' => 'PhutilEventListener', 'PhabricatorTransactionView' => 'AphrontView', 'PhabricatorTransformedFile' => 'PhabricatorFileDAO', diff --git a/src/applications/tokens/application/PhabricatorApplicationTokens.php b/src/applications/tokens/application/PhabricatorApplicationTokens.php index 8a56fdc987..2879634161 100644 --- a/src/applications/tokens/application/PhabricatorApplicationTokens.php +++ b/src/applications/tokens/application/PhabricatorApplicationTokens.php @@ -36,6 +36,7 @@ final class PhabricatorApplicationTokens extends PhabricatorApplication { '' => 'PhabricatorTokenGivenController', 'given/' => 'PhabricatorTokenGivenController', 'give/(?[^/]+)/' => 'PhabricatorTokenGiveController', + 'leaders/' => 'PhabricatorTokenLeaderController', ), ); } diff --git a/src/applications/tokens/controller/PhabricatorTokenController.php b/src/applications/tokens/controller/PhabricatorTokenController.php index d1ebe28636..3253e9301f 100644 --- a/src/applications/tokens/controller/PhabricatorTokenController.php +++ b/src/applications/tokens/controller/PhabricatorTokenController.php @@ -8,9 +8,9 @@ abstract class PhabricatorTokenController extends PhabricatorController { $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->addFilter('given/', pht('Tokens Given')); + $nav->addFilter('leaders/', pht('Leader Board')); return $nav; } - } diff --git a/src/applications/tokens/controller/PhabricatorTokenLeaderController.php b/src/applications/tokens/controller/PhabricatorTokenLeaderController.php new file mode 100644 index 0000000000..71dfbbfbf8 --- /dev/null +++ b/src/applications/tokens/controller/PhabricatorTokenLeaderController.php @@ -0,0 +1,58 @@ +getRequest(); + $user = $request->getUser(); + $pager = id(new AphrontCursorPagerView()) + ->readFromRequest($request); + + $query = id(new PhabricatorTokenReceiverQuery()); + $objects = $query->setViewer($user)->execute(); + $counts = $query->getTokenCounts(); + + $handles = array(); + if ($counts) { + $phids = mpull($objects, 'getPHID'); + $handles = id(new PhabricatorObjectHandleData($phids)) + ->setViewer($user) + ->loadHandles(); + } + + $list = new PhabricatorObjectItemListView(); + foreach ($phids as $object) { + $count = idx($counts, $object, 0); + $item = id(new PhabricatorObjectItemView()); + $handle = $handles[$object]; + + $item->setHeader($handle->getFullName()); + $item->setHref($handle->getURI()); + $item->addAttribute(pht('Tokens: %s', $count)); + $list->addItem($item); + } + + $title = pht('Token Leader Board'); + + $nav = $this->buildSideNav(); + $nav->setCrumbs( + $this->buildApplicationCrumbs() + ->addCrumb( + id(new PhabricatorCrumbView()) + ->setName($title))); + $nav->selectFilter('leaders/'); + + $nav->appendChild($list); + $nav->appendChild($pager); + + return $this->buildApplicationPage( + $nav, + array( + 'title' => $title, + 'device' => true, + 'dust' => true + )); + } + +} diff --git a/src/applications/tokens/query/PhabricatorTokenReceiverQuery.php b/src/applications/tokens/query/PhabricatorTokenReceiverQuery.php new file mode 100644 index 0000000000..6b7833f23d --- /dev/null +++ b/src/applications/tokens/query/PhabricatorTokenReceiverQuery.php @@ -0,0 +1,35 @@ +establishConnection('r'); + + $rows = queryfx_all( + $conn_r, + 'SELECT objectPHID, tokenCount FROM %T ORDER BY tokenCount DESC', + $table->getTableName()); + + $this->tokenCounts = ipull($rows, 'tokenCount', 'objectPHID'); + return ipull($rows, 'objectPHID'); + } + + public function willFilterPage(array $phids) { + if (!$phids) { + return array(); + } + $objects = id(new PhabricatorObjectHandleData($phids)) + ->setViewer($this->getViewer()) + ->loadObjects(); + return $objects; + } + + public function getTokenCounts() { + return $this->tokenCounts; + } + +}