3 final class DifferentialTransactionView
4 extends PhabricatorApplicationTransactionView
{
6 private $changesets = array();
11 public function setLeftDiff(DifferentialDiff
$left_diff) {
12 $this->leftDiff
= $left_diff;
16 public function getLeftDiff() {
17 return $this->leftDiff
;
20 public function setRightDiff(DifferentialDiff
$right_diff) {
21 $this->rightDiff
= $right_diff;
25 public function getRightDiff() {
26 return $this->rightDiff
;
29 public function setRevision(DifferentialRevision
$revision) {
30 $this->revision
= $revision;
34 public function getRevision() {
35 return $this->revision
;
38 public function setChangesets(array $changesets) {
39 assert_instances_of($changesets, 'DifferentialChangeset');
40 $this->changesets
= $changesets;
44 public function getChangesets() {
45 return $this->changesets
;
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.
52 protected function shouldGroupTransactions(
53 PhabricatorApplicationTransaction
$u,
54 PhabricatorApplicationTransaction
$v) {
56 if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
57 // Don't group transactions by different authors.
61 if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
62 // Don't group if transactions that happened more than 60s apart.
66 switch ($u->getTransactionType()) {
67 case PhabricatorTransactions
::TYPE_COMMENT
:
68 case DifferentialTransaction
::TYPE_INLINE
:
74 switch ($v->getTransactionType()) {
75 case DifferentialTransaction
::TYPE_INLINE
:
79 return parent
::shouldGroupTransactions($u, $v);
82 protected function renderTransactionContent(
83 PhabricatorApplicationTransaction
$xaction) {
87 $type_inline = DifferentialTransaction
::TYPE_INLINE
;
89 $group = $xaction->getTransactionGroup();
90 if ($xaction->getTransactionType() == $type_inline) {
91 array_unshift($group, $xaction);
93 $out[] = parent
::renderTransactionContent($xaction);
96 // If we're rendering a preview, we show the inline comments in a separate
97 // section underneath the main transaction preview, so we skip rendering
98 // them in the preview body.
99 if ($this->getIsPreview()) {
108 foreach ($group as $xaction) {
109 switch ($xaction->getTransactionType()) {
110 case DifferentialTransaction
::TYPE_INLINE
:
111 $inlines[] = $xaction;
114 throw new Exception(pht('Unknown grouped transaction type!'));
119 $inline_view = new PhabricatorInlineSummaryView();
121 $changesets = $this->getChangesets();
123 $inline_groups = DifferentialTransactionComment
::sortAndGroupInlines(
126 foreach ($inline_groups as $changeset_id => $group) {
127 $changeset = $changesets[$changeset_id];
129 foreach ($group as $inline) {
130 $comment = $inline->getComment();
132 'id' => $comment->getID(),
133 'line' => $comment->getLineNumber(),
134 'length' => $comment->getLineLength(),
135 'content' => parent
::renderTransactionContent($inline),
138 $changeset_diff_id = $changeset->getDiffID();
139 if ($comment->getIsNewFile()) {
140 $visible_diff_id = $this->getRightDiff()->getID();
142 $visible_diff_id = $this->getLeftDiff()->getID();
145 // TODO: We still get one edge case wrong here, when we have a
146 // versus diff and the file didn't exist in the old version. The
147 // comment is visible because we show the left side of the target
148 // diff when there's no corresponding file in the versus diff, but
149 // we incorrectly link it off-page.
151 $is_visible = ($changeset_diff_id == $visible_diff_id);
153 $revision_id = $this->getRevision()->getID();
154 $comment_id = $comment->getID();
157 '?id='.$changeset_diff_id.
158 '#inline-'.$comment_id;
159 $item['where'] = pht('(On Diff #%d)', $changeset_diff_id);
164 $inline_view->addCommentGroup(
165 $changeset->getFilename(),
169 $out[] = $inline_view;