Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / badges / view / PhabricatorBadgesRecipientsListView.php
blobce84971d41053dbff7ae173bf51df834a925d220
1 <?php
3 final class PhabricatorBadgesRecipientsListView extends AphrontView {
5 private $badge;
6 private $awards;
7 private $handles;
9 public function setBadge(PhabricatorBadgesBadge $badge) {
10 $this->badge = $badge;
11 return $this;
14 public function setAwards(array $awards) {
15 $this->awards = $awards;
16 return $this;
19 public function setHandles(array $handles) {
20 $this->handles = $handles;
21 return $this;
24 public function render() {
25 $viewer = $this->getViewer();
27 $badge = $this->badge;
28 $handles = $this->handles;
29 $awards = mpull($this->awards, null, 'getRecipientPHID');
31 $can_edit = PhabricatorPolicyFilter::hasCapability(
32 $viewer,
33 $badge,
34 PhabricatorPolicyCapability::CAN_EDIT);
36 $award_button = id(new PHUIButtonView())
37 ->setTag('a')
38 ->setIcon('fa-plus')
39 ->setText(pht('Add Recipients'))
40 ->setWorkflow(true)
41 ->setDisabled(!$can_edit)
42 ->setHref('/badges/recipients/'.$badge->getID().'/add/');
44 $header = id(new PHUIHeaderView())
45 ->setHeader(pht('Recipients'))
46 ->addActionLink($award_button);
48 $list = id(new PHUIObjectItemListView())
49 ->setNoDataString(pht('This badge does not have any recipients.'))
50 ->setFlush(true);
52 foreach ($handles as $handle) {
53 $remove_uri = '/badges/recipients/'.
54 $badge->getID().'/remove/?phid='.$handle->getPHID();
56 $award = $awards[$handle->getPHID()];
57 $awarder_handle = $viewer->renderHandle($award->getAwarderPHID());
58 $award_date = phabricator_date($award->getDateCreated(), $viewer);
59 $awarder_info = pht(
60 'Awarded by %s on %s',
61 $awarder_handle->render(),
62 $award_date);
64 $item = id(new PHUIObjectItemView())
65 ->setHeader($handle->getFullName())
66 ->setSubhead($awarder_info)
67 ->setHref($handle->getURI())
68 ->setImageURI($handle->getImageURI());
70 if ($can_edit) {
71 $item->addAction(
72 id(new PHUIListItemView())
73 ->setIcon('fa-times')
74 ->setName(pht('Remove'))
75 ->setHref($remove_uri)
76 ->setWorkflow(true));
79 $list->addItem($item);
82 $box = id(new PHUIObjectBoxView())
83 ->setHeader($header)
84 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
85 ->setObjectList($list);
87 return $box;