1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

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
This commit is contained in:
Chad Little 2017-03-07 14:19:26 -08:00
parent 0b4ccdade9
commit 614c8497bb

View file

@ -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;
}
}