[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/dashboard/controller/ -> PhabricatorDashboardRemovePanelController.php (source)

   1  <?php
   2  
   3  final class PhabricatorDashboardRemovePanelController
   4    extends PhabricatorDashboardController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = idx($data, 'id');
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $viewer = $request->getUser();
  15  
  16      $dashboard = id(new PhabricatorDashboardQuery())
  17        ->setViewer($viewer)
  18        ->withIDs(array($this->id))
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_VIEW,
  22            PhabricatorPolicyCapability::CAN_EDIT,
  23          ))
  24        ->executeOne();
  25      if (!$dashboard) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $v_panel = $request->getStr('panelPHID');
  30      $panel = id(new PhabricatorDashboardPanelQuery())
  31        ->setViewer($viewer)
  32        ->withPHIDs(array($v_panel))
  33        ->executeOne();
  34      if (!$panel) {
  35        return new Aphront404Response();
  36      }
  37  
  38      $redirect_uri = $this->getApplicationURI(
  39        'manage/'.$dashboard->getID().'/');
  40      $layout_config = $dashboard->getLayoutConfigObject();
  41  
  42      if ($request->isFormPost()) {
  43        $xactions = array();
  44        $xactions[] = id(new PhabricatorDashboardTransaction())
  45          ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
  46          ->setMetadataValue(
  47            'edge:type',
  48            PhabricatorEdgeConfig::TYPE_DASHBOARD_HAS_PANEL)
  49            ->setNewValue(
  50              array(
  51                '-' => array(
  52                  $panel->getPHID() => $panel->getPHID(),
  53                ),
  54              ));
  55  
  56        $layout_config->removePanel($panel->getPHID());
  57        $dashboard->setLayoutConfigFromObject($layout_config);
  58  
  59        $editor = id(new PhabricatorDashboardTransactionEditor())
  60          ->setActor($viewer)
  61          ->setContentSourceFromRequest($request)
  62          ->setContinueOnMissingFields(true)
  63          ->setContinueOnNoEffect(true)
  64          ->applyTransactions($dashboard, $xactions);
  65  
  66        return id(new AphrontRedirectResponse())->setURI($redirect_uri);
  67      }
  68  
  69      $form = id(new AphrontFormView())
  70        ->setUser($viewer)
  71        ->addHiddenInput('confirm', true)
  72        ->addHiddenInput('panelPHID', $v_panel)
  73        ->appendChild(pht('Are you sure you want to remove this panel?'));
  74  
  75      return $this->newDialog()
  76        ->setTitle(pht('Remove Panel %s', $panel->getMonogram()))
  77        ->appendChild($form->buildLayoutView())
  78        ->addCancelButton($redirect_uri)
  79        ->addSubmitButton(pht('Remove Panel'));
  80    }
  81  
  82  }


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