[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorDashboardInstallController
   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        ->executeOne();
  20      if (!$dashboard) {
  21        return new Aphront404Response();
  22      }
  23      $dashboard_phid = $dashboard->getPHID();
  24  
  25      $object_phid = $request->getStr('objectPHID', $viewer->getPHID());
  26      switch ($object_phid) {
  27        case PhabricatorHomeApplication::DASHBOARD_DEFAULT:
  28          if (!$viewer->getIsAdmin()) {
  29            return new Aphront404Response();
  30          }
  31          break;
  32        default:
  33          $object = id(new PhabricatorObjectQuery())
  34            ->setViewer($viewer)
  35            ->requireCapabilities(
  36              array(
  37                PhabricatorPolicyCapability::CAN_VIEW,
  38                PhabricatorPolicyCapability::CAN_EDIT,
  39              ))
  40            ->withPHIDs(array($object_phid))
  41            ->executeOne();
  42          if (!$object) {
  43            return new Aphront404Response();
  44          }
  45          break;
  46      }
  47  
  48      $installer_phid = $viewer->getPHID();
  49      $application_class = $request->getStr(
  50        'applicationClass',
  51        'PhabricatorHomeApplication');
  52  
  53      $handles = $this->loadHandles(array(
  54        $object_phid,
  55        $installer_phid,
  56      ));
  57  
  58      if ($request->isFormPost()) {
  59        $dashboard_install = id(new PhabricatorDashboardInstall())
  60          ->loadOneWhere(
  61            'objectPHID = %s AND applicationClass = %s',
  62            $object_phid,
  63            $application_class);
  64        if (!$dashboard_install) {
  65          $dashboard_install = id(new PhabricatorDashboardInstall())
  66            ->setObjectPHID($object_phid)
  67            ->setApplicationClass($application_class);
  68        }
  69        $dashboard_install
  70          ->setInstallerPHID($installer_phid)
  71          ->setDashboardPHID($dashboard_phid)
  72          ->save();
  73        return id(new AphrontRedirectResponse())
  74          ->setURI($this->getRedirectURI($application_class, $object_phid));
  75      }
  76  
  77      $dialog = $this->newDialog()
  78        ->setTitle(pht('Install Dashboard'))
  79        ->addHiddenInput('objectPHID', $object_phid)
  80        ->addCancelButton($this->getCancelURI($application_class, $object_phid))
  81        ->addSubmitButton(pht('Install Dashboard'));
  82  
  83      switch ($application_class) {
  84        case 'PhabricatorHomeApplication':
  85          if ($viewer->getPHID() == $object_phid) {
  86            if ($viewer->getIsAdmin()) {
  87              $dialog->setWidth(AphrontDialogView::WIDTH_FORM);
  88  
  89              $form = id(new AphrontFormView())
  90                ->setUser($viewer)
  91                ->appendRemarkupInstructions(
  92                  pht('Choose where to install this dashboard.'))
  93                ->appendChild(
  94                  id(new AphrontFormRadioButtonControl())
  95                    ->setName('objectPHID')
  96                    ->setValue(PhabricatorHomeApplication::DASHBOARD_DEFAULT)
  97                    ->addButton(
  98                      PhabricatorHomeApplication::DASHBOARD_DEFAULT,
  99                      pht('Default Dashboard for All Users'),
 100                      pht(
 101                        'Install this dashboard as the global default dashboard '.
 102                        'for all users. Users can install a personal dashboard '.
 103                        'to replace it. All users who have not configured '.
 104                        'a personal dashboard will be affected by this change.'))
 105                    ->addButton(
 106                      $viewer->getPHID(),
 107                      pht('Personal Home Page Dashboard'),
 108                      pht(
 109                        'Install this dashboard as your personal home page '.
 110                        'dashboard. Only you will be affected by this change.')));
 111  
 112              $dialog->appendChild($form->buildLayoutView());
 113            } else {
 114              $dialog->appendParagraph(
 115                pht('Install this dashboard on your home page?'));
 116            }
 117          } else {
 118            $dialog->appendParagraph(
 119              pht(
 120                'Install this dashboard as the home page dashboard for %s?',
 121                phutil_tag(
 122                  'strong',
 123                  array(),
 124                  $this->getHandle($object_phid)->getName())));
 125          }
 126          break;
 127        default:
 128          throw new Exception(
 129            pht(
 130              'Unknown dashboard application class "%s"!',
 131              $application_class));
 132      }
 133  
 134      return $dialog;
 135    }
 136  
 137    private function getCancelURI($application_class, $object_phid) {
 138      $uri = null;
 139      switch ($application_class) {
 140        case 'PhabricatorHomeApplication':
 141          $uri = '/dashboard/view/'.$this->id.'/';
 142          break;
 143      }
 144      return $uri;
 145    }
 146  
 147    private function getRedirectURI($application_class, $object_phid) {
 148      $uri = null;
 149      switch ($application_class) {
 150        case 'PhabricatorHomeApplication':
 151          $uri = '/';
 152          break;
 153      }
 154      return $uri;
 155    }
 156  
 157  }


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