mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22: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:
parent
8b553d2f18
commit
6f80a04699
1 changed files with 32 additions and 38 deletions
|
@ -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,28 +75,25 @@ 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);
|
||||||
|
|
||||||
|
if ($awards) {
|
||||||
|
$flex = new PHUIBadgeBoxView();
|
||||||
foreach ($awards as $award) {
|
foreach ($awards as $award) {
|
||||||
$badge = $award->getBadge();
|
$badge = $award->getBadge();
|
||||||
$badges[$award->getBadgePHID()] = $badge;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($badges)) {
|
|
||||||
$flex = new PHUIBadgeBoxView();
|
|
||||||
|
|
||||||
foreach ($badges as $badge) {
|
|
||||||
if ($badge) {
|
|
||||||
$awarder_info = array();
|
$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);
|
||||||
|
@ -121,13 +113,15 @@ final class PhabricatorPeopleProfileBadgesController
|
||||||
|
|
||||||
$flex->addItem($item);
|
$flex->addItem($item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$flex = id(new PHUIInfoView())
|
$flex = id(new PHUIInfoView())
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
||||||
->appendChild(pht('User has not been awarded any badges.'));
|
->appendChild(pht('User has not been awarded any badges.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $flex;
|
return array(
|
||||||
|
$flex,
|
||||||
|
$pager,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue