Path: blob/master/src/applications/differential/storage/DifferentialTransactionComment.php
12256 views
<?php12final class DifferentialTransactionComment3extends PhabricatorApplicationTransactionComment4implements5PhabricatorInlineCommentInterface {67protected $revisionPHID;8protected $changesetID;9protected $isNewFile = 0;10protected $lineNumber = 0;11protected $lineLength = 0;12protected $fixedState;13protected $hasReplies = 0;14protected $replyToCommentPHID;15protected $attributes = array();1617private $replyToComment = self::ATTACHABLE;18private $isHidden = self::ATTACHABLE;19private $changeset = self::ATTACHABLE;20private $inlineContext = self::ATTACHABLE;2122public function getApplicationTransactionObject() {23return new DifferentialTransaction();24}2526public function attachReplyToComment(27DifferentialTransactionComment $comment = null) {28$this->replyToComment = $comment;29return $this;30}3132public function getReplyToComment() {33return $this->assertAttached($this->replyToComment);34}3536protected function getConfiguration() {37$config = parent::getConfiguration();3839$config[self::CONFIG_COLUMN_SCHEMA] = array(40'revisionPHID' => 'phid?',41'changesetID' => 'id?',42'isNewFile' => 'bool',43'lineNumber' => 'uint32',44'lineLength' => 'uint32',45'fixedState' => 'text12?',46'hasReplies' => 'bool',47'replyToCommentPHID' => 'phid?',48) + $config[self::CONFIG_COLUMN_SCHEMA];4950$config[self::CONFIG_KEY_SCHEMA] = array(51'key_draft' => array(52'columns' => array('authorPHID', 'transactionPHID'),53),54'key_changeset' => array(55'columns' => array('changesetID'),56),57'key_revision' => array(58'columns' => array('revisionPHID'),59),60) + $config[self::CONFIG_KEY_SCHEMA];6162$config[self::CONFIG_SERIALIZATION] = array(63'attributes' => self::SERIALIZATION_JSON,64) + idx($config, self::CONFIG_SERIALIZATION, array());6566return $config;67}6869public function shouldUseMarkupCache($field) {70// Only cache submitted comments.71return ($this->getTransactionPHID() != null);72}7374public static function sortAndGroupInlines(75array $inlines,76array $changesets) {77assert_instances_of($inlines, 'DifferentialTransaction');78assert_instances_of($changesets, 'DifferentialChangeset');7980$changesets = mpull($changesets, null, 'getID');81$changesets = msort($changesets, 'getFilename');8283// Group the changesets by file and reorder them by display order.84$inline_groups = array();85foreach ($inlines as $inline) {86$changeset_id = $inline->getComment()->getChangesetID();87$inline_groups[$changeset_id][] = $inline;88}89$inline_groups = array_select_keys($inline_groups, array_keys($changesets));9091foreach ($inline_groups as $changeset_id => $group) {92// Sort the group of inlines by line number.93$items = array();94foreach ($group as $inline) {95$comment = $inline->getComment();96$num = $comment->getLineNumber();97$len = $comment->getLineLength();98$id = $comment->getID();99100$items[] = array(101'inline' => $inline,102'sort' => sprintf('~%010d%010d%010d', $num, $len, $id),103);104}105106$items = isort($items, 'sort');107$items = ipull($items, 'inline');108$inline_groups[$changeset_id] = $items;109}110111return $inline_groups;112}113114public function getIsHidden() {115return $this->assertAttached($this->isHidden);116}117118public function attachIsHidden($hidden) {119$this->isHidden = $hidden;120return $this;121}122123public function getAttribute($key, $default = null) {124return idx($this->attributes, $key, $default);125}126127public function setAttribute($key, $value) {128$this->attributes[$key] = $value;129return $this;130}131132public function newInlineCommentObject() {133return DifferentialInlineComment::newFromModernComment($this);134}135136public function getInlineContext() {137return $this->assertAttached($this->inlineContext);138}139140public function attachInlineContext(141PhabricatorInlineCommentContext $context = null) {142$this->inlineContext = $context;143return $this;144}145146147public function isEmptyComment() {148if (!parent::isEmptyComment()) {149return false;150}151152return $this->newInlineCommentObject()153->getContentState()154->isEmptyContentState();155}156157158}159160161