1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +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:
epriestley 2017-03-24 13:59:49 -07:00
parent 8b553d2f18
commit 6f80a04699

View file

@ -10,13 +10,7 @@ final class PhabricatorPeopleProfileBadgesController
$user = id(new PhabricatorPeopleQuery()) $user = id(new PhabricatorPeopleQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->needProfile(true)
->needProfileImage(true) ->needProfileImage(true)
->needAvailability(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
))
->executeOne(); ->executeOne();
if (!$user) { if (!$user) {
return new Aphront404Response(); return new Aphront404Response();
@ -50,6 +44,7 @@ final class PhabricatorPeopleProfileBadgesController
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->setLimit(1)
->execute(); ->execute();
$button = id(new PHUIButtonView()) $button = id(new PHUIButtonView())
@ -59,7 +54,7 @@ final class PhabricatorPeopleProfileBadgesController
->setWorkflow(true) ->setWorkflow(true)
->setHref('/badges/award/'.$user->getID().'/'); ->setHref('/badges/award/'.$user->getID().'/');
if (count($badges)) { if ($badges) {
$header->addActionLink($button); $header->addActionLink($button);
} }
@ -80,47 +75,43 @@ final class PhabricatorPeopleProfileBadgesController
private function buildBadgesView(PhabricatorUser $user) { private function buildBadgesView(PhabricatorUser $user) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$request = $this->getRequest();
$awards = id(new PhabricatorBadgesAwardQuery()) $pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$query = id(new PhabricatorBadgesAwardQuery())
->setViewer($viewer) ->setViewer($viewer)
->withRecipientPHIDs(array($user->getPHID())) ->withRecipientPHIDs(array($user->getPHID()))
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) ->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE));
->execute();
$awards = mpull($awards, null, 'getBadgePHID');
$badges = array(); $awards = $query->executeWithCursorPager($pager);
foreach ($awards as $award) {
$badge = $award->getBadge();
$badges[$award->getBadgePHID()] = $badge;
}
if (count($badges)) { if ($awards) {
$flex = new PHUIBadgeBoxView(); $flex = new PHUIBadgeBoxView();
foreach ($awards as $award) {
$badge = $award->getBadge();
foreach ($badges as $badge) { $awarder_info = array();
if ($badge) {
$awarder_info = array();
$award = idx($awards, $badge->getPHID(), null); $awarder_phid = $award->getAwarderPHID();
$awarder_phid = $award->getAwarderPHID(); $awarder_handle = $viewer->renderHandle($awarder_phid);
$awarder_handle = $viewer->renderHandle($awarder_phid); $awarded_date = phabricator_date($award->getDateCreated(), $viewer);
$awarded_date = phabricator_date($award->getDateCreated(), $viewer);
$awarder_info = pht( $awarder_info = pht(
'Awarded by %s', 'Awarded by %s',
$awarder_handle->render()); $awarder_handle->render());
$item = id(new PHUIBadgeView()) $item = id(new PHUIBadgeView())
->setIcon($badge->getIcon()) ->setIcon($badge->getIcon())
->setHeader($badge->getName()) ->setHeader($badge->getName())
->setSubhead($badge->getFlavor()) ->setSubhead($badge->getFlavor())
->setQuality($badge->getQuality()) ->setQuality($badge->getQuality())
->setHref($badge->getViewURI()) ->setHref($badge->getViewURI())
->addByLine($awarder_info) ->addByLine($awarder_info)
->addByLine($awarded_date); ->addByLine($awarded_date);
$flex->addItem($item); $flex->addItem($item);
}
} }
} else { } else {
$flex = id(new PHUIInfoView()) $flex = id(new PHUIInfoView())
@ -128,6 +119,9 @@ final class PhabricatorPeopleProfileBadgesController
->appendChild(pht('User has not been awarded any badges.')); ->appendChild(pht('User has not been awarded any badges.'));
} }
return $flex; return array(
$flex,
$pager,
);
} }
} }