public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $dashboard = id(new PhabricatorDashboardQuery())->setViewer($viewer)->withIDs(array($id))->needPanels(true)->executeOne();
     if (!$dashboard) {
         return new Aphront404Response();
     }
     $manage_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     if ($request->isFormPost()) {
         $copy = PhabricatorDashboard::initializeNewDashboard($viewer);
         $copy = PhabricatorDashboard::copyDashboard($copy, $dashboard);
         $copy->setName(pht('Copy of %s', $copy->getName()));
         // Set up all the edges for the new dashboard.
         $xactions = array();
         $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('=' => array_fuse($dashboard->getPanelPHIDs())));
         $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->applyTransactions($copy, $xactions);
         $manage_uri = $this->getApplicationURI('edit/' . $copy->getID() . '/');
         return id(new AphrontRedirectResponse())->setURI($manage_uri);
     }
     return $this->newDialog()->setTitle(pht('Copy Dashboard'))->appendParagraph(pht('Create a copy of the dashboard "%s"?', phutil_tag('strong', array(), $dashboard->getName())))->addCancelButton($manage_uri)->addSubmitButton(pht('Create Copy'));
 }
 private function processBuildTemplateRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $template = $request->getStr('template');
     $bare_panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
     $panel_phids = array();
     switch ($template) {
         case 'simple':
             $v_name = pht('New Simple Dashboard');
             $welcome_panel = $this->newPanel($request, $viewer, 'text', pht('Welcome'), array('text' => pht("This is a simple template dashboard. You can edit this panel " . "to change this text and replace it with a welcome message, or " . "leave this placeholder text as-is to give your dashboard a " . "rustic, authentic feel.\n\n" . "You can drag, remove, add, and edit panels to customize the " . "rest of this dashboard to show the information you want.\n\n" . "To install this dashboard on the home page, use the " . "**Install Dashboard** action link above.")));
             $panel_phids[] = $welcome_panel->getPHID();
             $feed_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Activity'), array('class' => 'PhabricatorFeedSearchEngine', 'key' => 'all'));
             $panel_phids[] = $feed_panel->getPHID();
             $task_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Tasks'), array('class' => 'ManiphestTaskSearchEngine', 'key' => 'all'));
             $panel_phids[] = $task_panel->getPHID();
             $commit_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Commits'), array('class' => 'PhabricatorCommitSearchEngine', 'key' => 'all'));
             $panel_phids[] = $commit_panel->getPHID();
             $mode_2_and_1 = PhabricatorDashboardLayoutConfig::MODE_THIRDS_AND_THIRD;
             $layout = id(new PhabricatorDashboardLayoutConfig())->setLayoutMode($mode_2_and_1)->setPanelLocation(0, $welcome_panel->getPHID())->setPanelLocation(0, $task_panel->getPHID())->setPanelLocation(0, $commit_panel->getPHID())->setPanelLocation(1, $feed_panel->getPHID());
             break;
         default:
             throw new Exception(pht('Unknown dashboard template %s!', $template));
     }
     // Create the dashboard.
     $dashboard = PhabricatorDashboard::initializeNewDashboard($viewer)->setLayoutConfigFromObject($layout);
     $xactions = array();
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorDashboardTransaction::TYPE_NAME)->setNewValue($v_name);
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('+' => array_fuse($panel_phids)));
     $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->applyTransactions($dashboard, $xactions);
     $manage_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     return id(new AphrontRedirectResponse())->setURI($manage_uri);
 }