[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/tokens/controller/ -> PhabricatorTokenGiveController.php (source)

   1  <?php
   2  
   3  final class PhabricatorTokenGiveController extends PhabricatorTokenController {
   4  
   5    private $phid;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->phid = $data['phid'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $user = $request->getUser();
  14  
  15      $handle = id(new PhabricatorHandleQuery())
  16        ->setViewer($user)
  17        ->withPHIDs(array($this->phid))
  18        ->executeOne();
  19      if (!$handle->isComplete()) {
  20        return new Aphront404Response();
  21      }
  22  
  23      $current = id(new PhabricatorTokenGivenQuery())
  24        ->setViewer($user)
  25        ->withAuthorPHIDs(array($user->getPHID()))
  26        ->withObjectPHIDs(array($handle->getPHID()))
  27        ->execute();
  28  
  29      if ($current) {
  30        $is_give = false;
  31        $title = pht('Rescind Token');
  32      } else {
  33        $is_give = true;
  34        $title = pht('Give Token');
  35      }
  36  
  37      $done_uri = $handle->getURI();
  38      if ($request->isDialogFormPost()) {
  39        $content_source = PhabricatorContentSource::newFromRequest($request);
  40  
  41        $editor = id(new PhabricatorTokenGivenEditor())
  42          ->setActor($user)
  43          ->setContentSource($content_source);
  44        if ($is_give) {
  45          $token_phid = $request->getStr('tokenPHID');
  46          $editor->addToken($handle->getPHID(), $token_phid);
  47        } else {
  48          $editor->deleteToken($handle->getPHID());
  49        }
  50  
  51        return id(new AphrontReloadResponse())->setURI($done_uri);
  52      }
  53  
  54      if ($is_give) {
  55        $dialog = $this->buildGiveTokenDialog();
  56      } else {
  57        $dialog = $this->buildRescindTokenDialog(head($current));
  58      }
  59  
  60      $dialog->setUser($user);
  61      $dialog->addCancelButton($done_uri);
  62  
  63      return id(new AphrontDialogResponse())->setDialog($dialog);
  64    }
  65  
  66    private function buildGiveTokenDialog() {
  67      $user = $this->getRequest()->getUser();
  68  
  69      $tokens = id(new PhabricatorTokenQuery())
  70        ->setViewer($user)
  71        ->execute();
  72  
  73      $buttons = array();
  74      $ii = 0;
  75      foreach ($tokens as $token) {
  76        $aural = javelin_tag(
  77          'span',
  78          array(
  79            'aural' => true,
  80          ),
  81          pht('Award "%s" Token', $token->getName()));
  82  
  83        $buttons[] = javelin_tag(
  84          'button',
  85          array(
  86            'class' => 'token-button',
  87            'name' => 'tokenPHID',
  88            'value' => $token->getPHID(),
  89            'type' => 'submit',
  90            'sigil' => 'has-tooltip',
  91            'meta' => array(
  92              'tip' => $token->getName(),
  93            ),
  94          ),
  95          array(
  96            $aural,
  97            $token->renderIcon(),
  98          ));
  99        if ((++$ii % 4) == 0) {
 100          $buttons[] = phutil_tag('br');
 101        }
 102      }
 103  
 104      $buttons = phutil_tag(
 105        'div',
 106        array(
 107          'class' => 'token-grid',
 108        ),
 109        $buttons);
 110  
 111      $dialog = new AphrontDialogView();
 112      $dialog->setTitle(pht('Give Token'));
 113      $dialog->appendChild($buttons);
 114  
 115      return $dialog;
 116    }
 117  
 118    private function buildRescindTokenDialog(PhabricatorTokenGiven $token_given) {
 119      $dialog = new AphrontDialogView();
 120      $dialog->setTitle(pht('Rescind Token'));
 121  
 122      $dialog->appendChild(
 123        pht('Really rescind this lovely token?'));
 124  
 125      $dialog->addSubmitButton(pht('Rescind Token'));
 126  
 127      return $dialog;
 128    }
 129  
 130  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1