1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Badges ... on your profile

Summary: Shows badges on profile if you have them. Check if app is installed, show badges.

Test Plan:
Gave myself a liberal selection of badge. Gave notchad one badge. Gave chadtwo absolutely nothing.

{F651069}

Reviewers: btrahan, lpriestley, epriestley

Reviewed By: epriestley

Subscribers: johnny-bit, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13692
This commit is contained in:
Chad Little 2015-07-23 11:46:34 -07:00
parent 875dc54516
commit ded654b8e2
3 changed files with 71 additions and 0 deletions

View file

@ -23,6 +23,7 @@ final class PhabricatorPeopleProfileController
$user = id(new PhabricatorPeopleQuery()) $user = id(new PhabricatorPeopleQuery())
->setViewer($viewer) ->setViewer($viewer)
->withUsernames(array($this->username)) ->withUsernames(array($this->username))
->needBadges(true)
->needProfileImage(true) ->needProfileImage(true)
->needAvailability(true) ->needAvailability(true)
->executeOne(); ->executeOne();
@ -157,9 +158,12 @@ final class PhabricatorPeopleProfileController
->setHeaderText(pht('Recent Activity')) ->setHeaderText(pht('Recent Activity'))
->appendChild($this->buildPeopleFeed($user, $viewer)); ->appendChild($this->buildPeopleFeed($user, $viewer));
$badges = $this->buildBadgesView($user);
$nav = $this->buildIconNavView($user); $nav = $this->buildIconNavView($user);
$nav->selectFilter("{$name}/"); $nav->selectFilter("{$name}/");
$nav->appendChild($object_box); $nav->appendChild($object_box);
$nav->appendChild($badges);
$nav->appendChild($feed); $nav->appendChild($feed);
return $this->buildApplicationPage( return $this->buildApplicationPage(
@ -187,6 +191,39 @@ final class PhabricatorPeopleProfileController
return $view; return $view;
} }
private function buildBadgesView(
PhabricatorUser $user) {
$viewer = $this->getViewer();
$class = 'PhabricatorBadgesApplication';
$box = null;
if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
$badge_phids = $user->getBadgePHIDs();
if ($badge_phids) {
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withPHIDs($badge_phids)
->execute();
$flex = new PHUIBadgeBoxView();
foreach ($badges as $badge) {
$item = id(new PHUIBadgeView())
->setIcon($badge->getIcon())
->setHeader($badge->getName())
->setSubhead($badge->getFlavor())
->setQuality($badge->getQuality());
$flex->addItem($item);
}
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Badges'))
->appendChild($flex);
}
}
return $box;
}
private function buildPeopleFeed( private function buildPeopleFeed(
PhabricatorUser $user, PhabricatorUser $user,
$viewer) { $viewer) {

View file

@ -22,6 +22,7 @@ final class PhabricatorPeopleQuery
private $needProfile; private $needProfile;
private $needProfileImage; private $needProfileImage;
private $needAvailability; private $needAvailability;
private $needBadges;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -113,6 +114,11 @@ final class PhabricatorPeopleQuery
return $this; return $this;
} }
public function needBadges($need) {
$this->needBadges = $need;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new PhabricatorUser(); return new PhabricatorUser();
} }
@ -147,6 +153,24 @@ final class PhabricatorPeopleQuery
} }
} }
if ($this->needBadges) {
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($users, 'getPHID'))
->withEdgeTypes(
array(
PhabricatorRecipientHasBadgeEdgeType::EDGECONST,
));
$edge_query->execute();
foreach ($users as $user) {
$phids = $edge_query->getDestinationPHIDs(
array(
$user->getPHID(),
));
$user->attachBadgePHIDs($phids);
}
}
if ($this->needProfileImage) { if ($this->needProfileImage) {
$rebuild = array(); $rebuild = array();
foreach ($users as $user) { foreach ($users as $user) {

View file

@ -55,6 +55,7 @@ final class PhabricatorUser
private $preferences = null; private $preferences = null;
private $omnipotent = false; private $omnipotent = false;
private $customFields = self::ATTACHABLE; private $customFields = self::ATTACHABLE;
private $badgePHIDs = self::ATTACHABLE;
private $alternateCSRFString = self::ATTACHABLE; private $alternateCSRFString = self::ATTACHABLE;
private $session = self::ATTACHABLE; private $session = self::ATTACHABLE;
@ -1145,6 +1146,15 @@ final class PhabricatorUser
return $this->loadHandles($phids)->renderList(); return $this->loadHandles($phids)->renderList();
} }
public function attachBadgePHIDs(array $phids) {
$this->badgePHIDs = $phids;
return $this;
}
public function getBadgePHIDs() {
return $this->assertAttached($this->badgePHIDs);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */