1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 02:40:58 +01:00

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
This commit is contained in:
Bryan Cuccioli 2013-03-21 16:04:29 -07:00 committed by epriestley
parent 4674b88ff6
commit cff9843859
5 changed files with 99 additions and 1 deletions

View file

@ -1390,8 +1390,10 @@ phutil_register_library_map(array(
'PhabricatorTokenGivenEditor' => 'applications/tokens/editor/PhabricatorTokenGivenEditor.php', 'PhabricatorTokenGivenEditor' => 'applications/tokens/editor/PhabricatorTokenGivenEditor.php',
'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php', 'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php',
'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php', 'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php',
'PhabricatorTokenLeaderController' => 'applications/tokens/controller/PhabricatorTokenLeaderController.php',
'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php', 'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php',
'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php', 'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php',
'PhabricatorTokenReceiverQuery' => 'applications/tokens/query/PhabricatorTokenReceiverQuery.php',
'PhabricatorTokenUIEventListener' => 'applications/tokens/event/PhabricatorTokenUIEventListener.php', 'PhabricatorTokenUIEventListener' => 'applications/tokens/event/PhabricatorTokenUIEventListener.php',
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php', 'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php', 'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php',
@ -2992,7 +2994,9 @@ phutil_register_library_map(array(
'PhabricatorTokenGivenEditor' => 'PhabricatorEditor', 'PhabricatorTokenGivenEditor' => 'PhabricatorEditor',
'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory', 'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory',
'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenLeaderController' => 'PhabricatorTokenController',
'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenUIEventListener' => 'PhutilEventListener', 'PhabricatorTokenUIEventListener' => 'PhutilEventListener',
'PhabricatorTransactionView' => 'AphrontView', 'PhabricatorTransactionView' => 'AphrontView',
'PhabricatorTransformedFile' => 'PhabricatorFileDAO', 'PhabricatorTransformedFile' => 'PhabricatorFileDAO',

View file

@ -36,6 +36,7 @@ final class PhabricatorApplicationTokens extends PhabricatorApplication {
'' => 'PhabricatorTokenGivenController', '' => 'PhabricatorTokenGivenController',
'given/' => 'PhabricatorTokenGivenController', 'given/' => 'PhabricatorTokenGivenController',
'give/(?<phid>[^/]+)/' => 'PhabricatorTokenGiveController', 'give/(?<phid>[^/]+)/' => 'PhabricatorTokenGiveController',
'leaders/' => 'PhabricatorTokenLeaderController',
), ),
); );
} }

View file

@ -8,9 +8,9 @@ abstract class PhabricatorTokenController extends PhabricatorController {
$nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addFilter('given/', pht('Tokens Given')); $nav->addFilter('given/', pht('Tokens Given'));
$nav->addFilter('leaders/', pht('Leader Board'));
return $nav; return $nav;
} }
} }

View file

@ -0,0 +1,58 @@
<?php
final class PhabricatorTokenLeaderController
extends PhabricatorTokenController {
public function processRequest() {
$request = $this->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
));
}
}

View file

@ -0,0 +1,35 @@
<?php
final class PhabricatorTokenReceiverQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $tokenCounts;
protected function loadPage() {
$table = new PhabricatorTokenCount();
$conn_r = $table->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;
}
}