3 final class PhabricatorBadgesAwardController
4 extends PhabricatorBadgesController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $user = id(new PhabricatorPeopleQuery())
15 return new Aphront404Response();
18 $view_uri = '/people/badges/'.$user->getID().'/';
20 if ($request->isFormPost()) {
21 $badge_phids = $request->getArr('badgePHIDs');
22 $badges = id(new PhabricatorBadgesQuery())
24 ->withPHIDs($badge_phids)
25 ->requireCapabilities(
27 PhabricatorPolicyCapability
::CAN_EDIT
,
28 PhabricatorPolicyCapability
::CAN_VIEW
,
32 return new Aphront404Response();
34 $award_phids = array($user->getPHID());
36 foreach ($badges as $badge) {
38 $xactions[] = id(new PhabricatorBadgesTransaction())
40 PhabricatorBadgesBadgeAwardTransaction
::TRANSACTIONTYPE
)
41 ->setNewValue($award_phids);
43 $editor = id(new PhabricatorBadgesEditor())
45 ->setContentSourceFromRequest($request)
46 ->setContinueOnNoEffect(true)
47 ->setContinueOnMissingFields(true)
48 ->applyTransactions($badge, $xactions);
51 return id(new AphrontRedirectResponse())
55 $form = id(new AphrontFormView())
58 id(new AphrontFormTokenizerControl())
59 ->setLabel(pht('Badge'))
60 ->setName('badgePHIDs')
62 id(new PhabricatorBadgesDatasource())
65 'recipientPHID' => $user->getPHID(),
68 $dialog = $this->newDialog()
69 ->setTitle(pht('Award Badge'))
71 ->addCancelButton($view_uri)
72 ->addSubmitButton(pht('Award'));