Skip to content

Commit 614c849

Browse files
author
Chad Little
committedMar 7, 2017
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
1 parent 0b4ccda commit 614c849

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
 

‎src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php

+47
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,15 @@ public function render() {
238238
'class' => 'phui-timeline-wedge',
239239
),
240240
'');
241+
242+
$badge_view = $this->renderBadgeView();
243+
241244
$comment_box = id(new PHUIObjectBoxView())
242245
->setFlush(true)
243246
->addClass('phui-comment-form-view')
244247
->addSigil('phui-comment-form')
245248
->appendChild($image)
249+
->appendChild($badge_view)
246250
->appendChild($wedge)
247251
->appendChild($comment);
248252

@@ -512,4 +516,47 @@ private function newCommentActionOptions(array $action_map) {
512516
return $options;
513517
}
514518

519+
private function renderBadgeView() {
520+
$user = $this->getUser();
521+
$can_use_badges = PhabricatorApplication::isClassInstalledForViewer(
522+
'PhabricatorBadgesApplication',
523+
$user);
524+
if (!$can_use_badges) {
525+
return null;
526+
}
527+
528+
$awards = id(new PhabricatorBadgesAwardQuery())
529+
->setViewer($this->getUser())
530+
->withRecipientPHIDs(array($user->getPHID()))
531+
->setLimit(2)
532+
->execute();
533+
534+
$badge_view = null;
535+
if ($awards) {
536+
$badges = mpull($awards, 'getBadge');
537+
$badge_list = array();
538+
foreach ($badges as $badge) {
539+
$badge_view = id(new PHUIBadgeMiniView())
540+
->setIcon($badge->getIcon())
541+
->setQuality($badge->getQuality())
542+
->setHeader($badge->getName())
543+
->setTipDirection('E')
544+
->setHref('/badges/view/'.$badge->getID());
545+
546+
$badge_list[] = $badge_view;
547+
}
548+
$flex = new PHUIBadgeBoxView();
549+
$flex->addItems($badge_list);
550+
$flex->setCollapsed(true);
551+
$badge_view = phutil_tag(
552+
'div',
553+
array(
554+
'class' => 'phui-timeline-badges',
555+
),
556+
$flex);
557+
}
558+
559+
return $badge_view;
560+
}
561+
515562
}

0 commit comments

Comments
 (0)
Failed to load comments.