[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/slowvote/controller/ -> PhabricatorSlowvoteCloseController.php (source)

   1  <?php
   2  
   3  final class PhabricatorSlowvoteCloseController
   4    extends PhabricatorSlowvoteController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = $data['id'];
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $user = $request->getUser();
  15  
  16      $poll = id(new PhabricatorSlowvoteQuery())
  17        ->setViewer($user)
  18        ->withIDs(array($this->id))
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_VIEW,
  22            PhabricatorPolicyCapability::CAN_EDIT,
  23          ))
  24        ->executeOne();
  25      if (!$poll) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $close_uri = '/V'.$poll->getID();
  30  
  31      if ($request->isFormPost()) {
  32        if ($poll->getIsClosed()) {
  33          $new_status = 0;
  34        } else {
  35          $new_status = 1;
  36        }
  37  
  38        $xactions = array();
  39  
  40        $xactions[] = id(new PhabricatorSlowvoteTransaction())
  41          ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_CLOSE)
  42          ->setNewValue($new_status);
  43  
  44        id(new PhabricatorSlowvoteEditor())
  45          ->setActor($user)
  46          ->setContentSourceFromRequest($request)
  47          ->setContinueOnNoEffect(true)
  48          ->setContinueOnMissingFields(true)
  49          ->applyTransactions($poll, $xactions);
  50  
  51        return id(new AphrontRedirectResponse())->setURI($close_uri);
  52      }
  53  
  54      if ($poll->getIsClosed()) {
  55        $title = pht('Reopen Poll');
  56        $content = pht('Are you sure you want to reopen the poll?');
  57        $submit = pht('Reopen');
  58      } else {
  59        $title = pht('Close Poll');
  60        $content = pht('Are you sure you want to close the poll?');
  61        $submit = pht('Close');
  62      }
  63  
  64      return $this->newDialog()
  65        ->setTitle($title)
  66        ->appendChild($content)
  67        ->addSubmitButton($submit)
  68        ->addCancelButton($close_uri);
  69    }
  70  
  71  }


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