diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php index 243e0ad764..dbdaf7e8b9 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php @@ -23,6 +23,7 @@ final class PhabricatorPeopleProfileController $user = id(new PhabricatorPeopleQuery()) ->setViewer($viewer) ->withUsernames(array($this->username)) + ->needBadges(true) ->needProfileImage(true) ->needAvailability(true) ->executeOne(); @@ -157,9 +158,12 @@ final class PhabricatorPeopleProfileController ->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 @@ final class PhabricatorPeopleProfileController 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 index b8a0851252..f1286f0a5a 100644 --- a/src/applications/people/query/PhabricatorPeopleQuery.php +++ b/src/applications/people/query/PhabricatorPeopleQuery.php @@ -22,6 +22,7 @@ final class PhabricatorPeopleQuery private $needProfile; private $needProfileImage; private $needAvailability; + private $needBadges; public function withIDs(array $ids) { $this->ids = $ids; @@ -113,6 +114,11 @@ final class PhabricatorPeopleQuery return $this; } + public function needBadges($need) { + $this->needBadges = $need; + return $this; + } + public function newResultObject() { 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) { $rebuild = array(); foreach ($users as $user) { diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 52db2f38f5..148a2168b4 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -55,6 +55,7 @@ final class PhabricatorUser 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 @@ final class PhabricatorUser return $this->loadHandles($phids)->renderList(); } + public function attachBadgePHIDs(array $phids) { + $this->badgePHIDs = $phids; + return $this; + } + + public function getBadgePHIDs() { + return $this->assertAttached($this->badgePHIDs); + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */