Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / badges / controller / PhabricatorBadgesAwardController.php
blob63af70b7914df73c22a7f7ba3cd0a0865640c606
1 <?php
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())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->executeOne();
14 if (!$user) {
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())
23 ->setViewer($viewer)
24 ->withPHIDs($badge_phids)
25 ->requireCapabilities(
26 array(
27 PhabricatorPolicyCapability::CAN_EDIT,
28 PhabricatorPolicyCapability::CAN_VIEW,
30 ->execute();
31 if (!$badges) {
32 return new Aphront404Response();
34 $award_phids = array($user->getPHID());
36 foreach ($badges as $badge) {
37 $xactions = array();
38 $xactions[] = id(new PhabricatorBadgesTransaction())
39 ->setTransactionType(
40 PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
41 ->setNewValue($award_phids);
43 $editor = id(new PhabricatorBadgesEditor())
44 ->setActor($viewer)
45 ->setContentSourceFromRequest($request)
46 ->setContinueOnNoEffect(true)
47 ->setContinueOnMissingFields(true)
48 ->applyTransactions($badge, $xactions);
51 return id(new AphrontRedirectResponse())
52 ->setURI($view_uri);
55 $form = id(new AphrontFormView())
56 ->setUser($viewer)
57 ->appendControl(
58 id(new AphrontFormTokenizerControl())
59 ->setLabel(pht('Badge'))
60 ->setName('badgePHIDs')
61 ->setDatasource(
62 id(new PhabricatorBadgesDatasource())
63 ->setParameters(
64 array(
65 'recipientPHID' => $user->getPHID(),
66 ))));
68 $dialog = $this->newDialog()
69 ->setTitle(pht('Award Badge'))
70 ->appendForm($form)
71 ->addCancelButton($view_uri)
72 ->addSubmitButton(pht('Award'));
74 return $dialog;