2013-07-14 16:02:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSlowvoteTransaction
|
|
|
|
extends PhabricatorApplicationTransaction {
|
|
|
|
|
2013-07-15 10:50:38 -07:00
|
|
|
const TYPE_QUESTION = 'vote:question';
|
2013-07-14 16:02:04 -07:00
|
|
|
const TYPE_DESCRIPTION = 'vote:description';
|
2013-07-15 10:50:38 -07:00
|
|
|
const TYPE_RESPONSES = 'vote:responses';
|
|
|
|
const TYPE_SHUFFLE = 'vote:shuffle';
|
2014-04-24 12:00:31 -07:00
|
|
|
const TYPE_CLOSE = 'vote:close';
|
2013-07-14 16:02:04 -07:00
|
|
|
|
2015-08-01 15:41:08 -07:00
|
|
|
const MAILTAG_DETAILS = 'vote:details';
|
|
|
|
const MAILTAG_RESPONSES = 'vote:responses';
|
|
|
|
const MAILTAG_OTHER = 'vote:vote';
|
|
|
|
|
2013-07-14 16:02:04 -07:00
|
|
|
public function getApplicationName() {
|
|
|
|
return 'slowvote';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionType() {
|
2014-07-24 08:05:46 +10:00
|
|
|
return PhabricatorSlowvotePollPHIDType::TYPECONST;
|
2013-07-14 16:02:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionCommentObject() {
|
2013-07-15 04:20:10 -07:00
|
|
|
return new PhabricatorSlowvoteTransactionComment();
|
2013-07-14 16:02:04 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 10:50:38 -07:00
|
|
|
public function shouldHide() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_DESCRIPTION:
|
|
|
|
case self::TYPE_RESPONSES:
|
|
|
|
case self::TYPE_SHUFFLE:
|
|
|
|
case self::TYPE_CLOSE:
|
2013-07-15 10:50:38 -07:00
|
|
|
return ($old === null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::shouldHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle() {
|
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_QUESTION:
|
2013-07-15 10:50:38 -07:00
|
|
|
if ($old === null) {
|
|
|
|
return pht(
|
|
|
|
'%s created this poll.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s changed the poll question from "%s" to "%s".',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$old,
|
|
|
|
$new);
|
|
|
|
}
|
|
|
|
break;
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_DESCRIPTION:
|
2013-07-15 10:50:38 -07:00
|
|
|
return pht(
|
|
|
|
'%s updated the description for this poll.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_RESPONSES:
|
2013-07-15 10:50:38 -07:00
|
|
|
// TODO: This could be more detailed
|
|
|
|
return pht(
|
|
|
|
'%s changed who can see the responses.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_SHUFFLE:
|
2013-07-15 10:50:38 -07:00
|
|
|
if ($new) {
|
|
|
|
return pht(
|
|
|
|
'%s made poll responses appear in a random order.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s made poll responses appear in a fixed order.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
}
|
2014-04-24 12:00:31 -07:00
|
|
|
break;
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_CLOSE:
|
2014-04-24 12:00:31 -07:00
|
|
|
if ($new) {
|
|
|
|
return pht(
|
|
|
|
'%s closed this poll.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s reopened this poll.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
}
|
|
|
|
|
2013-07-15 10:50:38 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getTitle();
|
|
|
|
}
|
|
|
|
|
2015-08-01 15:41:08 -07:00
|
|
|
public function getTitleForFeed() {
|
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$object_phid = $this->getObjectPHID();
|
|
|
|
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
$type = $this->getTransactionType();
|
|
|
|
switch ($type) {
|
|
|
|
case self::TYPE_QUESTION:
|
|
|
|
if ($old === null) {
|
|
|
|
return pht(
|
|
|
|
'%s created %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s renamed %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case self::TYPE_DESCRIPTION:
|
|
|
|
if ($old === null) {
|
|
|
|
return pht(
|
|
|
|
'%s set the description of %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s edited the description of %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case self::TYPE_RESPONSES:
|
|
|
|
// TODO: This could be more detailed
|
|
|
|
return pht(
|
|
|
|
'%s changed who can see the responses of %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
|
|
|
|
case self::TYPE_SHUFFLE:
|
|
|
|
if ($new) {
|
|
|
|
return pht(
|
|
|
|
'%s made %s responses appear in a random order.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s made %s responses appear in a fixed order.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
}
|
|
|
|
case self::TYPE_CLOSE:
|
|
|
|
if ($new) {
|
|
|
|
return pht(
|
|
|
|
'%s closed %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s reopened %s.',
|
|
|
|
$this->renderHandleLink($author_phid),
|
|
|
|
$this->renderHandleLink($object_phid));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getTitleForFeed();
|
|
|
|
}
|
|
|
|
|
2013-07-15 10:50:38 -07:00
|
|
|
public function getIcon() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_QUESTION:
|
2014-04-22 08:25:54 -07:00
|
|
|
if ($old === null) {
|
|
|
|
return 'fa-plus';
|
|
|
|
} else {
|
|
|
|
return 'fa-pencil';
|
|
|
|
}
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_DESCRIPTION:
|
|
|
|
case self::TYPE_RESPONSES:
|
2014-04-22 08:25:54 -07:00
|
|
|
return 'fa-pencil';
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_SHUFFLE:
|
2014-04-22 08:25:54 -07:00
|
|
|
return 'fa-refresh';
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_CLOSE:
|
2014-04-24 12:00:31 -07:00
|
|
|
if ($new) {
|
|
|
|
return 'fa-ban';
|
|
|
|
} else {
|
|
|
|
return 'fa-pencil';
|
|
|
|
}
|
2013-07-15 10:50:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getColor() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_QUESTION:
|
|
|
|
case self::TYPE_DESCRIPTION:
|
|
|
|
case self::TYPE_RESPONSES:
|
|
|
|
case self::TYPE_SHUFFLE:
|
|
|
|
case self::TYPE_CLOSE:
|
2013-07-15 10:50:38 -07:00
|
|
|
return PhabricatorTransactions::COLOR_BLUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getColor();
|
|
|
|
}
|
|
|
|
|
2013-07-15 11:07:37 -07:00
|
|
|
public function hasChangeDetails() {
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-14 06:50:28 +10:00
|
|
|
case self::TYPE_DESCRIPTION:
|
2013-07-15 11:07:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parent::hasChangeDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderChangeDetails(PhabricatorUser $viewer) {
|
2015-01-12 07:20:20 -08:00
|
|
|
return $this->renderTextCorpusChangeDetails(
|
|
|
|
$viewer,
|
|
|
|
$this->getOldValue(),
|
|
|
|
$this->getNewValue());
|
2013-07-15 11:07:37 -07:00
|
|
|
}
|
|
|
|
|
2015-08-01 15:41:08 -07:00
|
|
|
public function getMailTags() {
|
|
|
|
$tags = parent::getMailTags();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case self::TYPE_QUESTION:
|
|
|
|
case self::TYPE_DESCRIPTION:
|
|
|
|
case self::TYPE_SHUFFLE:
|
|
|
|
case self::TYPE_CLOSE:
|
|
|
|
$tags[] = self::MAILTAG_DETAILS;
|
|
|
|
break;
|
|
|
|
case self::TYPE_RESPONSES:
|
|
|
|
$tags[] = self::MAILTAG_RESPONSES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$tags[] = self::MAILTAG_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2013-07-15 11:07:37 -07:00
|
|
|
|
2013-07-14 16:02:04 -07:00
|
|
|
}
|