mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
Paginate the profile badges view
Summary: Ref T12270. Adds a pager, plus a few little cleanups from copy/paste and accumulated cruft. Test Plan: - Paginated a user with 180 badges. - Viewed a user with 0 badges. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12270 Differential Revision: https://secure.phabricator.com/D17561
This commit is contained in:
parent
8b553d2f18
commit
6f80a04699
1 changed files with 32 additions and 38 deletions
|
@ -10,13 +10,7 @@ final class PhabricatorPeopleProfileBadgesController
|
|||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needProfile(true)
|
||||
->needProfileImage(true)
|
||||
->needAvailability(true)
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
return new Aphront404Response();
|
||||
|
@ -50,6 +44,7 @@ final class PhabricatorPeopleProfileBadgesController
|
|||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->setLimit(1)
|
||||
->execute();
|
||||
|
||||
$button = id(new PHUIButtonView())
|
||||
|
@ -59,7 +54,7 @@ final class PhabricatorPeopleProfileBadgesController
|
|||
->setWorkflow(true)
|
||||
->setHref('/badges/award/'.$user->getID().'/');
|
||||
|
||||
if (count($badges)) {
|
||||
if ($badges) {
|
||||
$header->addActionLink($button);
|
||||
}
|
||||
|
||||
|
@ -80,47 +75,43 @@ final class PhabricatorPeopleProfileBadgesController
|
|||
|
||||
private function buildBadgesView(PhabricatorUser $user) {
|
||||
$viewer = $this->getViewer();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$awards = id(new PhabricatorBadgesAwardQuery())
|
||||
$pager = id(new AphrontCursorPagerView())
|
||||
->readFromRequest($request);
|
||||
|
||||
$query = id(new PhabricatorBadgesAwardQuery())
|
||||
->setViewer($viewer)
|
||||
->withRecipientPHIDs(array($user->getPHID()))
|
||||
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
|
||||
->execute();
|
||||
$awards = mpull($awards, null, 'getBadgePHID');
|
||||
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE));
|
||||
|
||||
$badges = array();
|
||||
foreach ($awards as $award) {
|
||||
$badge = $award->getBadge();
|
||||
$badges[$award->getBadgePHID()] = $badge;
|
||||
}
|
||||
$awards = $query->executeWithCursorPager($pager);
|
||||
|
||||
if (count($badges)) {
|
||||
if ($awards) {
|
||||
$flex = new PHUIBadgeBoxView();
|
||||
foreach ($awards as $award) {
|
||||
$badge = $award->getBadge();
|
||||
|
||||
foreach ($badges as $badge) {
|
||||
if ($badge) {
|
||||
$awarder_info = array();
|
||||
$awarder_info = array();
|
||||
|
||||
$award = idx($awards, $badge->getPHID(), null);
|
||||
$awarder_phid = $award->getAwarderPHID();
|
||||
$awarder_handle = $viewer->renderHandle($awarder_phid);
|
||||
$awarded_date = phabricator_date($award->getDateCreated(), $viewer);
|
||||
$awarder_phid = $award->getAwarderPHID();
|
||||
$awarder_handle = $viewer->renderHandle($awarder_phid);
|
||||
$awarded_date = phabricator_date($award->getDateCreated(), $viewer);
|
||||
|
||||
$awarder_info = pht(
|
||||
'Awarded by %s',
|
||||
$awarder_handle->render());
|
||||
$awarder_info = pht(
|
||||
'Awarded by %s',
|
||||
$awarder_handle->render());
|
||||
|
||||
$item = id(new PHUIBadgeView())
|
||||
->setIcon($badge->getIcon())
|
||||
->setHeader($badge->getName())
|
||||
->setSubhead($badge->getFlavor())
|
||||
->setQuality($badge->getQuality())
|
||||
->setHref($badge->getViewURI())
|
||||
->addByLine($awarder_info)
|
||||
->addByLine($awarded_date);
|
||||
$item = id(new PHUIBadgeView())
|
||||
->setIcon($badge->getIcon())
|
||||
->setHeader($badge->getName())
|
||||
->setSubhead($badge->getFlavor())
|
||||
->setQuality($badge->getQuality())
|
||||
->setHref($badge->getViewURI())
|
||||
->addByLine($awarder_info)
|
||||
->addByLine($awarded_date);
|
||||
|
||||
$flex->addItem($item);
|
||||
}
|
||||
$flex->addItem($item);
|
||||
}
|
||||
} else {
|
||||
$flex = id(new PHUIInfoView())
|
||||
|
@ -128,6 +119,9 @@ final class PhabricatorPeopleProfileBadgesController
|
|||
->appendChild(pht('User has not been awarded any badges.'));
|
||||
}
|
||||
|
||||
return $flex;
|
||||
return array(
|
||||
$flex,
|
||||
$pager,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue