[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorDashboardAddPanelController
   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      $redirect_uri = $this->getApplicationURI('manage/'.$dashboard->getID().'/');
  30  
  31      $v_panel = $request->getStr('panel');
  32      $e_panel = true;
  33      $errors = array();
  34      if ($request->isFormPost()) {
  35        if (strlen($v_panel)) {
  36          $panel = id(new PhabricatorDashboardPanelQuery())
  37            ->setViewer($viewer)
  38            ->withIDs(array($v_panel))
  39            ->executeOne();
  40          if (!$panel) {
  41            $errors[] = pht('No such panel!');
  42            $e_panel = pht('Invalid');
  43          }
  44        } else {
  45          $errors[] = pht('Select a panel to add.');
  46          $e_panel = pht('Required');
  47        }
  48  
  49        if (!$errors) {
  50          PhabricatorDashboardTransactionEditor::addPanelToDashboard(
  51            $viewer,
  52            PhabricatorContentSource::newFromRequest($request),
  53            $panel,
  54            $dashboard,
  55            $request->getInt('column', 0));
  56  
  57          return id(new AphrontRedirectResponse())->setURI($redirect_uri);
  58        }
  59      }
  60  
  61      $panels = id(new PhabricatorDashboardPanelQuery())
  62        ->setViewer($viewer)
  63        ->withArchived(false)
  64        ->execute();
  65  
  66      if (!$panels) {
  67        return $this->newDialog()
  68          ->setTitle(pht('No Panels Exist Yet'))
  69          ->appendParagraph(
  70            pht(
  71              'You have not created any dashboard panels yet, so you can not '.
  72              'add an existing panel.'))
  73          ->appendParagraph(
  74            pht('Instead, add a new panel.'))
  75          ->addCancelButton($redirect_uri);
  76      }
  77  
  78      $panel_options = array();
  79      foreach ($panels as $panel) {
  80        $panel_options[$panel->getID()] = pht(
  81          '%s %s',
  82          $panel->getMonogram(),
  83          $panel->getName());
  84      }
  85  
  86      $form = id(new AphrontFormView())
  87        ->setUser($viewer)
  88        ->addHiddenInput('column', $request->getInt('column'))
  89        ->appendRemarkupInstructions(
  90          pht('Choose a panel to add to this dashboard:'))
  91        ->appendChild(
  92          id(new AphrontFormSelectControl())
  93            ->setName('panel')
  94            ->setLabel(pht('Panel'))
  95            ->setValue($v_panel)
  96            ->setError($e_panel)
  97            ->setOptions($panel_options));
  98  
  99      return $this->newDialog()
 100        ->setTitle(pht('Add Panel'))
 101        ->setErrors($errors)
 102        ->appendChild($form->buildLayoutView())
 103        ->addCancelButton($redirect_uri)
 104        ->addSubmitButton(pht('Add Panel'));
 105    }
 106  
 107  }


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