From 614c8497bb4a33cb02c1c63338aabad081b142e6 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Tue, 7 Mar 2017 14:19:26 -0800 Subject: [PATCH] Add badges to TransactionCommentView Summary: Fixes T10698. This shows badges under the comment preview if the application uses TransactionCommentView. I suspect not everything does, but will pick the fix up for free when modernized. Test Plan: Test commenting on a task with and without a user that has a badge. See badge preview. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T10698 Differential Revision: https://secure.phabricator.com/D17480 --- ...catorApplicationTransactionCommentView.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php index 2d4c5e6f95..0847edd666 100644 --- a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php @@ -238,11 +238,15 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView { 'class' => 'phui-timeline-wedge', ), ''); + + $badge_view = $this->renderBadgeView(); + $comment_box = id(new PHUIObjectBoxView()) ->setFlush(true) ->addClass('phui-comment-form-view') ->addSigil('phui-comment-form') ->appendChild($image) + ->appendChild($badge_view) ->appendChild($wedge) ->appendChild($comment); @@ -512,4 +516,47 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView { return $options; } + private function renderBadgeView() { + $user = $this->getUser(); + $can_use_badges = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorBadgesApplication', + $user); + if (!$can_use_badges) { + return null; + } + + $awards = id(new PhabricatorBadgesAwardQuery()) + ->setViewer($this->getUser()) + ->withRecipientPHIDs(array($user->getPHID())) + ->setLimit(2) + ->execute(); + + $badge_view = null; + if ($awards) { + $badges = mpull($awards, 'getBadge'); + $badge_list = array(); + foreach ($badges as $badge) { + $badge_view = id(new PHUIBadgeMiniView()) + ->setIcon($badge->getIcon()) + ->setQuality($badge->getQuality()) + ->setHeader($badge->getName()) + ->setTipDirection('E') + ->setHref('/badges/view/'.$badge->getID()); + + $badge_list[] = $badge_view; + } + $flex = new PHUIBadgeBoxView(); + $flex->addItems($badge_list); + $flex->setCollapsed(true); + $badge_view = phutil_tag( + 'div', + array( + 'class' => 'phui-timeline-badges', + ), + $flex); + } + + return $badge_view; + } + }