Page MenuHomePhabricator

D13692.id33098.diff
No OneTemporary

D13692.id33098.diff

diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php
--- a/src/applications/people/controller/PhabricatorPeopleProfileController.php
+++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php
@@ -23,6 +23,7 @@
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withUsernames(array($this->username))
+ ->needBadges(true)
->needProfileImage(true)
->needAvailability(true)
->executeOne();
@@ -157,9 +158,12 @@
->setHeaderText(pht('Recent Activity'))
->appendChild($this->buildPeopleFeed($user, $viewer));
+ $badges = $this->buildBadgesView($user);
+
$nav = $this->buildIconNavView($user);
$nav->selectFilter("{$name}/");
$nav->appendChild($object_box);
+ $nav->appendChild($badges);
$nav->appendChild($feed);
return $this->buildApplicationPage(
@@ -187,6 +191,39 @@
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(
PhabricatorUser $user,
$viewer) {
diff --git a/src/applications/people/query/PhabricatorPeopleQuery.php b/src/applications/people/query/PhabricatorPeopleQuery.php
--- a/src/applications/people/query/PhabricatorPeopleQuery.php
+++ b/src/applications/people/query/PhabricatorPeopleQuery.php
@@ -22,6 +22,7 @@
private $needProfile;
private $needProfileImage;
private $needAvailability;
+ private $needBadges;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -113,6 +114,11 @@
return $this;
}
+ public function needBadges($need) {
+ $this->needBadges = $need;
+ return $this;
+ }
+
public function newResultObject() {
return new PhabricatorUser();
}
@@ -147,6 +153,24 @@
}
}
+ 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) {
$rebuild = array();
foreach ($users as $user) {
diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php
--- a/src/applications/people/storage/PhabricatorUser.php
+++ b/src/applications/people/storage/PhabricatorUser.php
@@ -55,6 +55,7 @@
private $preferences = null;
private $omnipotent = false;
private $customFields = self::ATTACHABLE;
+ private $badgePHIDs = self::ATTACHABLE;
private $alternateCSRFString = self::ATTACHABLE;
private $session = self::ATTACHABLE;
@@ -1145,6 +1146,15 @@
return $this->loadHandles($phids)->renderList();
}
+ public function attachBadgePHIDs(array $phids) {
+ $this->badgePHIDs = $phids;
+ return $this;
+ }
+
+ public function getBadgePHIDs() {
+ return $this->assertAttached($this->badgePHIDs);
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 1:06 AM (21 h, 25 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6784132
Default Alt Text
D13692.id33098.diff (4 KB)

Event Timeline