[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/subscriptions/controller/ -> PhabricatorSubscriptionsTransactionController.php (source)

   1  <?php
   2  
   3  final class PhabricatorSubscriptionsTransactionController
   4    extends PhabricatorController {
   5  
   6    private $phid;
   7    private $changeType;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->phid = idx($data, 'phid');
  11      $this->changeType = idx($data, 'type');
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16  
  17      $viewer = $request->getUser();
  18      $xaction_phid = $this->phid;
  19  
  20      $xaction = id(new PhabricatorObjectQuery())
  21        ->withPHIDs(array($xaction_phid))
  22        ->setViewer($viewer)
  23        ->executeOne();
  24      if (!$xaction) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $old = $xaction->getOldValue();
  29      $new = $xaction->getNewValue();
  30      switch ($this->changeType) {
  31        case 'add':
  32          $subscriber_phids = array_diff($new, $old);
  33          break;
  34        case 'rem':
  35          $subscriber_phids = array_diff($old, $new);
  36          break;
  37        default:
  38          return id(new Aphront404Response());
  39      }
  40  
  41      $object_phid = $xaction->getObjectPHID();
  42      $author_phid = $xaction->getAuthorPHID();
  43      $handle_phids = $subscriber_phids;
  44      $handle_phids[] = $object_phid;
  45      $handle_phids[] = $author_phid;
  46  
  47      $handles = id(new PhabricatorHandleQuery())
  48        ->setViewer($viewer)
  49        ->withPHIDs($handle_phids)
  50        ->execute();
  51      $author_handle = $handles[$author_phid];
  52      if (!in_array($author_phid, $subscriber_phids)) {
  53        unset($handles[$author_phid]);
  54      }
  55  
  56      switch ($this->changeType) {
  57        case 'add':
  58          $title = pht(
  59            'All %d subscribers added by %s',
  60            count($subscriber_phids),
  61            $author_handle->renderLink());
  62          break;
  63        case 'rem':
  64          $title = pht(
  65            'All %d subscribers removed by %s',
  66            count($subscriber_phids),
  67            $author_handle->renderLink());
  68          break;
  69      }
  70  
  71      $dialog = id(new SubscriptionListDialogBuilder())
  72        ->setViewer($viewer)
  73        ->setTitle($title)
  74        ->setObjectPHID($object_phid)
  75        ->setHandles($handles)
  76        ->buildDialog();
  77  
  78      return id(new AphrontDialogResponse())->setDialog($dialog);
  79    }
  80  
  81  }


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