Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/storage/PhrictionTransaction.php
<?php | <?php | ||||
final class PhrictionTransaction | final class PhrictionTransaction | ||||
extends PhabricatorApplicationTransaction { | extends PhabricatorApplicationTransaction { | ||||
const TYPE_TITLE = 'title'; | const TYPE_TITLE = 'title'; | ||||
const TYPE_CONTENT = 'content'; | const TYPE_CONTENT = 'content'; | ||||
const TYPE_DELETE = 'delete'; | |||||
const TYPE_MOVE_TO = 'move-to'; | |||||
const TYPE_MOVE_AWAY = 'move-away'; | |||||
const MAILTAG_TITLE = 'phriction-title'; | const MAILTAG_TITLE = 'phriction-title'; | ||||
const MAILTAG_CONTENT = 'phriction-content'; | const MAILTAG_CONTENT = 'phriction-content'; | ||||
const MAILTAG_DELETE = 'phriction-delete'; | |||||
public function getApplicationName() { | public function getApplicationName() { | ||||
return 'phriction'; | return 'phriction'; | ||||
} | } | ||||
public function getApplicationTransactionType() { | public function getApplicationTransactionType() { | ||||
return PhrictionDocumentPHIDType::TYPECONST; | return PhrictionDocumentPHIDType::TYPECONST; | ||||
} | } | ||||
public function getApplicationTransactionCommentObject() { | public function getApplicationTransactionCommentObject() { | ||||
return new PhrictionTransactionComment(); | return new PhrictionTransactionComment(); | ||||
} | } | ||||
public function getRequiredHandlePHIDs() { | |||||
$phids = parent::getRequiredHandlePHIDs(); | |||||
$new = $this->getNewValue(); | |||||
switch ($this->getTransactionType()) { | |||||
case self::TYPE_MOVE_TO: | |||||
case self::TYPE_MOVE_AWAY: | |||||
$phids[] = $new['phid']; | |||||
break; | |||||
} | |||||
return $phids; | |||||
} | |||||
public function getRemarkupBlocks() { | public function getRemarkupBlocks() { | ||||
$blocks = parent::getRemarkupBlocks(); | $blocks = parent::getRemarkupBlocks(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
$blocks[] = $this->getNewValue(); | $blocks[] = $this->getNewValue(); | ||||
break; | break; | ||||
} | } | ||||
Show All 10 Lines | switch ($this->getTransactionType()) { | ||||
return false; | return false; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return parent::shouldHide(); | return parent::shouldHide(); | ||||
} | } | ||||
public function shouldHideForMail(array $xactions) { | |||||
switch ($this->getTransactionType()) { | |||||
case self::TYPE_MOVE_TO: | |||||
case self::TYPE_MOVE_AWAY: | |||||
return true; | |||||
} | |||||
return parent::shouldHideForMail($xactions); | |||||
} | |||||
public function shouldHideForFeed() { | |||||
switch ($this->getTransactionType()) { | |||||
case self::TYPE_MOVE_TO: | |||||
case self::TYPE_MOVE_AWAY: | |||||
return true; | |||||
} | |||||
return parent::shouldHideForFeed(); | |||||
} | |||||
public function getActionStrength() { | public function getActionStrength() { | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
return 1.4; | return 1.4; | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return 1.3; | return 1.3; | ||||
case self::TYPE_DELETE: | |||||
return 1.2; | |||||
case self::TYPE_MOVE_TO: | |||||
case self::TYPE_MOVE_AWAY: | |||||
return 1.0; | |||||
} | } | ||||
return parent::getActionStrength(); | return parent::getActionStrength(); | ||||
} | } | ||||
public function getActionName() { | public function getActionName() { | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
$new = $this->getNewValue(); | $new = $this->getNewValue(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
if ($old === null) { | if ($old === null) { | ||||
return pht('Created'); | return pht('Created'); | ||||
} | } | ||||
return pht('Retitled'); | return pht('Retitled'); | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return pht('Edited'); | return pht('Edited'); | ||||
case self::TYPE_DELETE: | |||||
return pht('Deleted'); | |||||
case self::TYPE_MOVE_TO: | |||||
return pht('Moved'); | |||||
case self::TYPE_MOVE_AWAY: | |||||
return pht('Moved Away'); | |||||
} | } | ||||
return parent::getActionName(); | return parent::getActionName(); | ||||
} | } | ||||
public function getIcon() { | public function getIcon() { | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
$new = $this->getNewValue(); | $new = $this->getNewValue(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return 'fa-pencil'; | return 'fa-pencil'; | ||||
case self::TYPE_DELETE: | |||||
return 'fa-times'; | |||||
case self::TYPE_MOVE_TO: | |||||
case self::TYPE_MOVE_AWAY: | |||||
return 'fa-arrows'; | |||||
} | } | ||||
return parent::getIcon(); | return parent::getIcon(); | ||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
$author_phid = $this->getAuthorPHID(); | $author_phid = $this->getAuthorPHID(); | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
$new = $this->getNewValue(); | $new = $this->getNewValue(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
if ($old === null) { | if ($old === null) { | ||||
return pht( | return pht( | ||||
'%s created this document.', | '%s created this document.', | ||||
$this->renderHandleLink($author_phid)); | $this->renderHandleLink($author_phid)); | ||||
} | } | ||||
return pht( | return pht( | ||||
'%s changed the title from "%s" to "%s".', | '%s changed the title from "%s" to "%s".', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$old, | $old, | ||||
$new); | $new); | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return pht( | return pht( | ||||
'%s edited the document content.', | '%s edited the document content.', | ||||
$this->renderHandleLink($author_phid)); | $this->renderHandleLink($author_phid)); | ||||
case self::TYPE_DELETE: | |||||
return pht( | |||||
'%s deleted this document.', | |||||
$this->renderHandleLink($author_phid)); | |||||
case self::TYPE_MOVE_TO: | |||||
return pht( | |||||
'%s moved this document from %s', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($new['phid'])); | |||||
case self::TYPE_MOVE_AWAY: | |||||
return pht( | |||||
'%s moved this document to %s', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($new['phid'])); | |||||
} | } | ||||
return parent::getTitle(); | return parent::getTitle(); | ||||
} | } | ||||
public function getTitleForFeed(PhabricatorFeedStory $story) { | public function getTitleForFeed(PhabricatorFeedStory $story) { | ||||
$author_phid = $this->getAuthorPHID(); | $author_phid = $this->getAuthorPHID(); | ||||
$object_phid = $this->getObjectPHID(); | $object_phid = $this->getObjectPHID(); | ||||
Show All 18 Lines | switch ($this->getTransactionType()) { | ||||
$new); | $new); | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return pht( | return pht( | ||||
'%s edited the content of %s.', | '%s edited the content of %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
case self::TYPE_DELETE: | |||||
return pht( | |||||
'%s deleted %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($object_phid)); | |||||
} | } | ||||
return parent::getTitleForFeed($story); | return parent::getTitleForFeed($story); | ||||
} | } | ||||
public function hasChangeDetails() { | public function hasChangeDetails() { | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
return true; | return true; | ||||
Show All 12 Lines | public function getMailTags() { | ||||
$tags = array(); | $tags = array(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
$tags[] = self::MAILTAG_TITLE; | $tags[] = self::MAILTAG_TITLE; | ||||
break; | break; | ||||
case self::TYPE_CONTENT: | case self::TYPE_CONTENT: | ||||
$tags[] = self::MAILTAG_CONTENT; | $tags[] = self::MAILTAG_CONTENT; | ||||
break; | break; | ||||
case self::TYPE_DELETE: | |||||
$tags[] = self::MAILTAG_DELETE; | |||||
break; | |||||
} | } | ||||
return $tags; | return $tags; | ||||
} | } | ||||
} | } |