[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/view/ -> DifferentialTransactionView.php (source)

   1  <?php
   2  
   3  final class DifferentialTransactionView
   4    extends PhabricatorApplicationTransactionView {
   5  
   6    private $changesets;
   7    private $revision;
   8    private $rightDiff;
   9    private $leftDiff;
  10  
  11    public function setLeftDiff(DifferentialDiff $left_diff) {
  12      $this->leftDiff = $left_diff;
  13      return $this;
  14    }
  15  
  16    public function getLeftDiff() {
  17      return $this->leftDiff;
  18    }
  19  
  20    public function setRightDiff(DifferentialDiff $right_diff) {
  21      $this->rightDiff = $right_diff;
  22      return $this;
  23    }
  24  
  25    public function getRightDiff() {
  26      return $this->rightDiff;
  27    }
  28  
  29    public function setRevision(DifferentialRevision $revision) {
  30      $this->revision = $revision;
  31      return $this;
  32    }
  33  
  34    public function getRevision() {
  35      return $this->revision;
  36    }
  37  
  38    public function setChangesets(array $changesets) {
  39      assert_instances_of($changesets, 'DifferentialChangeset');
  40      $this->changesets = $changesets;
  41      return $this;
  42    }
  43  
  44    public function getChangesets() {
  45      return $this->changesets;
  46    }
  47  
  48    // TODO: There's a whole lot of code duplication between this and
  49    // PholioTransactionView to handle inlines. Merge this into the core? Some of
  50    // it can probably be shared, while other parts are trickier.
  51  
  52    protected function shouldGroupTransactions(
  53      PhabricatorApplicationTransaction $u,
  54      PhabricatorApplicationTransaction $v) {
  55  
  56      if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
  57        // Don't group transactions by different authors.
  58        return false;
  59      }
  60  
  61      if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
  62        // Don't group if transactions that happened more than 60s apart.
  63        return false;
  64      }
  65  
  66      switch ($u->getTransactionType()) {
  67        case PhabricatorTransactions::TYPE_COMMENT:
  68        case DifferentialTransaction::TYPE_INLINE:
  69          break;
  70        default:
  71          return false;
  72      }
  73  
  74      switch ($v->getTransactionType()) {
  75        case DifferentialTransaction::TYPE_INLINE:
  76          return true;
  77      }
  78  
  79      return parent::shouldGroupTransactions($u, $v);
  80    }
  81  
  82    protected function renderTransactionContent(
  83      PhabricatorApplicationTransaction $xaction) {
  84  
  85      $out = array();
  86  
  87      $type_inline = DifferentialTransaction::TYPE_INLINE;
  88  
  89      $group = $xaction->getTransactionGroup();
  90      if ($xaction->getTransactionType() == $type_inline) {
  91        array_unshift($group, $xaction);
  92      } else {
  93        $out[] = parent::renderTransactionContent($xaction);
  94      }
  95  
  96      if (!$group) {
  97        return $out;
  98      }
  99  
 100      $inlines = array();
 101      foreach ($group as $xaction) {
 102        switch ($xaction->getTransactionType()) {
 103          case DifferentialTransaction::TYPE_INLINE:
 104            $inlines[] = $xaction;
 105            break;
 106          default:
 107            throw new Exception('Unknown grouped transaction type!');
 108        }
 109      }
 110  
 111      if ($inlines) {
 112        $inline_view = new PhabricatorInlineSummaryView();
 113  
 114        $changesets = $this->getChangesets();
 115  
 116        $inline_groups = DifferentialTransactionComment::sortAndGroupInlines(
 117          $inlines,
 118          $changesets);
 119        foreach ($inline_groups as $changeset_id => $group) {
 120          $changeset = $changesets[$changeset_id];
 121          $items = array();
 122          foreach ($group as $inline) {
 123            $comment = $inline->getComment();
 124            $item = array(
 125              'id' => $comment->getID(),
 126              'line' => $comment->getLineNumber(),
 127              'length' => $comment->getLineLength(),
 128              'content' => parent::renderTransactionContent($inline),
 129            );
 130  
 131            $changeset_diff_id = $changeset->getDiffID();
 132            if ($comment->getIsNewFile()) {
 133              $visible_diff_id = $this->getRightDiff()->getID();
 134            } else {
 135              $visible_diff_id = $this->getLeftDiff()->getID();
 136            }
 137  
 138            // TODO: We still get one edge case wrong here, when we have a
 139            // versus diff and the file didn't exist in the old version. The
 140            // comment is visible because we show the left side of the target
 141            // diff when there's no corresponding file in the versus diff, but
 142            // we incorrectly link it off-page.
 143  
 144            $is_visible = ($changeset_diff_id == $visible_diff_id);
 145            if (!$is_visible) {
 146              $item['where'] = pht('(On Diff #%d)', $changeset_diff_id);
 147  
 148              $revision_id = $this->getRevision()->getID();
 149              $comment_id = $comment->getID();
 150  
 151              $item['href'] =
 152                '/D'.$revision_id.
 153                '?id='.$changeset_diff_id.
 154                '#inline-'.$comment_id;
 155            }
 156  
 157            $items[] = $item;
 158          }
 159          $inline_view->addCommentGroup(
 160            $changeset->getFilename(),
 161            $items);
 162        }
 163  
 164        $out[] = $inline_view;
 165      }
 166  
 167      return $out;
 168    }
 169  
 170  }


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