[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/controller/ -> DifferentialDiffViewController.php (source)

   1  <?php
   2  
   3  final class DifferentialDiffViewController extends DifferentialController {
   4  
   5    private $id;
   6  
   7    public function shouldAllowPublic() {
   8      return true;
   9    }
  10  
  11    public function willProcessRequest(array $data) {
  12      $this->id = $data['id'];
  13    }
  14  
  15    public function processRequest() {
  16      $request = $this->getRequest();
  17      $viewer = $request->getUser();
  18  
  19      $diff = id(new DifferentialDiffQuery())
  20        ->setViewer($viewer)
  21        ->withIDs(array($this->id))
  22        ->executeOne();
  23      if (!$diff) {
  24        return new Aphront404Response();
  25      }
  26  
  27      $error_view = id(new AphrontErrorView())
  28          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
  29      if ($diff->getRevisionID()) {
  30        $error_view->appendChild(
  31            pht(
  32              'This diff belongs to revision %s.',
  33              phutil_tag(
  34                'a',
  35                array(
  36                  'href' => '/D'.$diff->getRevisionID(),
  37                ),
  38                'D'.$diff->getRevisionID())));
  39      } else {
  40        // TODO: implement optgroup support in AphrontFormSelectControl?
  41        $select = array();
  42        $select[] = hsprintf('<optgroup label="%s">', pht('Create New Revision'));
  43        $select[] = phutil_tag(
  44          'option',
  45          array('value' => ''),
  46          pht('Create a new Revision...'));
  47        $select[] = hsprintf('</optgroup>');
  48  
  49        $revisions = id(new DifferentialRevisionQuery())
  50          ->setViewer($viewer)
  51          ->withAuthors(array($viewer->getPHID()))
  52          ->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
  53          ->execute();
  54  
  55        if ($revisions) {
  56          $select[] = hsprintf(
  57            '<optgroup label="%s">',
  58            pht('Update Existing Revision'));
  59          foreach ($revisions as $revision) {
  60            $select[] = phutil_tag(
  61              'option',
  62              array(
  63                'value' => $revision->getID(),
  64              ),
  65              id(new PhutilUTF8StringTruncator())
  66              ->setMaximumGlyphs(128)
  67              ->truncateString(
  68                'D'.$revision->getID().' '.$revision->getTitle()));
  69          }
  70          $select[] = hsprintf('</optgroup>');
  71        }
  72  
  73        $select = phutil_tag(
  74          'select',
  75          array('name' => 'revisionID'),
  76          $select);
  77  
  78        $form = id(new AphrontFormView())
  79          ->setUser($request->getUser())
  80          ->setAction('/differential/revision/edit/')
  81          ->addHiddenInput('diffID', $diff->getID())
  82          ->addHiddenInput('viaDiffView', 1)
  83          ->addHiddenInput(
  84            id(new DifferentialRepositoryField())->getFieldKey(),
  85            $diff->getRepositoryPHID())
  86          ->appendRemarkupInstructions(
  87            pht(
  88              'Review the diff for correctness. When you are satisfied, either '.
  89              '**create a new revision** or **update an existing revision**.'))
  90          ->appendChild(
  91            id(new AphrontFormMarkupControl())
  92            ->setLabel(pht('Attach To'))
  93            ->setValue($select))
  94          ->appendChild(
  95            id(new AphrontFormSubmitControl())
  96            ->setValue(pht('Continue')));
  97  
  98          $error_view->appendChild($form);
  99      }
 100  
 101      $props = id(new DifferentialDiffProperty())->loadAllWhere(
 102        'diffID = %d',
 103        $diff->getID());
 104      $props = mpull($props, 'getData', 'getName');
 105  
 106      $property_head = id(new PHUIHeaderView())
 107        ->setHeader(pht('Properties'));
 108  
 109      $property_view = new PHUIPropertyListView();
 110  
 111      $changesets = $diff->loadChangesets();
 112      $changesets = msort($changesets, 'getSortKey');
 113  
 114      $table_of_contents = id(new DifferentialDiffTableOfContentsView())
 115        ->setChangesets($changesets)
 116        ->setVisibleChangesets($changesets)
 117        ->setUnitTestData(idx($props, 'arc:unit', array()));
 118  
 119      $refs = array();
 120      foreach ($changesets as $changeset) {
 121        $refs[$changeset->getID()] = $changeset->getID();
 122      }
 123  
 124      $details = id(new DifferentialChangesetListView())
 125        ->setChangesets($changesets)
 126        ->setVisibleChangesets($changesets)
 127        ->setRenderingReferences($refs)
 128        ->setStandaloneURI('/differential/changeset/')
 129        ->setDiff($diff)
 130        ->setTitle(pht('Diff %d', $diff->getID()))
 131        ->setUser($request->getUser());
 132  
 133      $crumbs = $this->buildApplicationCrumbs();
 134      $crumbs->addTextCrumb(pht('Diff %d', $diff->getID()));
 135  
 136      $prop_box = id(new PHUIObjectBoxView())
 137        ->setHeader($property_head)
 138        ->addPropertyList($property_view)
 139        ->setErrorView($error_view);
 140  
 141      return $this->buildApplicationPage(
 142        array(
 143          $crumbs,
 144          $prop_box,
 145          $table_of_contents,
 146          $details,
 147        ),
 148        array(
 149          'title' => pht('Diff View'),
 150        ));
 151    }
 152  
 153  }


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