Path: blob/master/src/applications/differential/view/DifferentialTransactionView.php
12256 views
<?php12final class DifferentialTransactionView3extends PhabricatorApplicationTransactionView {45private $changesets = array();6private $revision;7private $rightDiff;8private $leftDiff;910public function setLeftDiff(DifferentialDiff $left_diff) {11$this->leftDiff = $left_diff;12return $this;13}1415public function getLeftDiff() {16return $this->leftDiff;17}1819public function setRightDiff(DifferentialDiff $right_diff) {20$this->rightDiff = $right_diff;21return $this;22}2324public function getRightDiff() {25return $this->rightDiff;26}2728public function setRevision(DifferentialRevision $revision) {29$this->revision = $revision;30return $this;31}3233public function getRevision() {34return $this->revision;35}3637public function setChangesets(array $changesets) {38assert_instances_of($changesets, 'DifferentialChangeset');39$this->changesets = $changesets;40return $this;41}4243public function getChangesets() {44return $this->changesets;45}4647// TODO: There's a whole lot of code duplication between this and48// PholioTransactionView to handle inlines. Merge this into the core? Some of49// it can probably be shared, while other parts are trickier.5051protected function shouldGroupTransactions(52PhabricatorApplicationTransaction $u,53PhabricatorApplicationTransaction $v) {5455if ($u->getAuthorPHID() != $v->getAuthorPHID()) {56// Don't group transactions by different authors.57return false;58}5960if (($v->getDateCreated() - $u->getDateCreated()) > 60) {61// Don't group if transactions that happened more than 60s apart.62return false;63}6465switch ($u->getTransactionType()) {66case PhabricatorTransactions::TYPE_COMMENT:67case DifferentialTransaction::TYPE_INLINE:68break;69default:70return false;71}7273switch ($v->getTransactionType()) {74case DifferentialTransaction::TYPE_INLINE:75return true;76}7778return parent::shouldGroupTransactions($u, $v);79}8081protected function renderTransactionContent(82PhabricatorApplicationTransaction $xaction) {8384$out = array();8586$type_inline = DifferentialTransaction::TYPE_INLINE;8788$group = $xaction->getTransactionGroup();89if ($xaction->getTransactionType() == $type_inline) {90array_unshift($group, $xaction);91} else {92$out[] = parent::renderTransactionContent($xaction);93}9495// If we're rendering a preview, we show the inline comments in a separate96// section underneath the main transaction preview, so we skip rendering97// them in the preview body.98if ($this->getIsPreview()) {99return $out;100}101102if (!$group) {103return $out;104}105106$inlines = array();107foreach ($group as $xaction) {108switch ($xaction->getTransactionType()) {109case DifferentialTransaction::TYPE_INLINE:110$inlines[] = $xaction;111break;112default:113throw new Exception(pht('Unknown grouped transaction type!'));114}115}116117if ($inlines) {118$inline_view = new PhabricatorInlineSummaryView();119120$changesets = $this->getChangesets();121122$inline_groups = DifferentialTransactionComment::sortAndGroupInlines(123$inlines,124$changesets);125foreach ($inline_groups as $changeset_id => $group) {126$changeset = $changesets[$changeset_id];127$items = array();128foreach ($group as $inline) {129$comment = $inline->getComment();130$item = array(131'id' => $comment->getID(),132'line' => $comment->getLineNumber(),133'length' => $comment->getLineLength(),134'content' => parent::renderTransactionContent($inline),135);136137$changeset_diff_id = $changeset->getDiffID();138if ($comment->getIsNewFile()) {139$visible_diff_id = $this->getRightDiff()->getID();140} else {141$visible_diff_id = $this->getLeftDiff()->getID();142}143144// TODO: We still get one edge case wrong here, when we have a145// versus diff and the file didn't exist in the old version. The146// comment is visible because we show the left side of the target147// diff when there's no corresponding file in the versus diff, but148// we incorrectly link it off-page.149150$is_visible = ($changeset_diff_id == $visible_diff_id);151if (!$is_visible) {152$revision_id = $this->getRevision()->getID();153$comment_id = $comment->getID();154$item['href'] =155'/D'.$revision_id.156'?id='.$changeset_diff_id.157'#inline-'.$comment_id;158$item['where'] = pht('(On Diff #%d)', $changeset_diff_id);159}160161$items[] = $item;162}163$inline_view->addCommentGroup(164$changeset->getFilename(),165$items);166}167168$out[] = $inline_view;169}170171return $out;172}173174}175176177