2012-01-24 16:11:37 +01:00
|
|
|
<?php
|
|
|
|
|
2013-10-22 22:49:28 +02:00
|
|
|
final class PhabricatorProjectTransaction
|
2017-05-16 23:40:15 +02:00
|
|
|
extends PhabricatorModularTransaction {
|
2012-01-24 16:11:37 +01:00
|
|
|
|
2014-02-10 23:32:30 +01:00
|
|
|
// NOTE: This is deprecated, members are just a normal edge now.
|
|
|
|
const TYPE_MEMBERS = 'project:members';
|
2012-01-24 16:11:37 +01:00
|
|
|
|
2015-06-16 23:25:13 +02:00
|
|
|
const MAILTAG_METADATA = 'project-metadata';
|
|
|
|
const MAILTAG_MEMBERS = 'project-members';
|
|
|
|
const MAILTAG_WATCHERS = 'project-watchers';
|
|
|
|
const MAILTAG_OTHER = 'project-other';
|
2015-05-16 01:33:31 +02:00
|
|
|
|
2013-10-22 22:49:28 +02:00
|
|
|
public function getApplicationName() {
|
|
|
|
return 'project';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionType() {
|
2014-07-24 00:05:46 +02:00
|
|
|
return PhabricatorProjectProjectPHIDType::TYPECONST;
|
2012-01-24 16:11:37 +01:00
|
|
|
}
|
|
|
|
|
2017-10-24 14:57:15 +02:00
|
|
|
public function getApplicationTransactionCommentObject() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-05-16 23:40:15 +02:00
|
|
|
public function getBaseTransactionClass() {
|
|
|
|
return 'PhabricatorProjectTransactionType';
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:49:37 +02:00
|
|
|
public function getRequiredHandlePHIDs() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
$req_phids = array();
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2013-10-22 22:49:37 +02:00
|
|
|
$add = array_diff($new, $old);
|
|
|
|
$rem = array_diff($old, $new);
|
|
|
|
$req_phids = array_merge($add, $rem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
|
|
|
|
}
|
|
|
|
|
2016-02-29 01:28:43 +01:00
|
|
|
public function shouldHide() {
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case PhabricatorTransactions::TYPE_EDGE:
|
|
|
|
$edge_type = $this->getMetadataValue('edge:type');
|
|
|
|
switch ($edge_type) {
|
|
|
|
case PhabricatorProjectSilencedEdgeType::EDGECONST:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::shouldHide();
|
|
|
|
}
|
|
|
|
|
2016-02-12 15:19:26 +01:00
|
|
|
public function shouldHideForMail(array $xactions) {
|
|
|
|
switch ($this->getTransactionType()) {
|
2017-05-23 20:54:37 +02:00
|
|
|
case PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE:
|
2017-05-24 21:07:04 +02:00
|
|
|
case PhabricatorProjectSortTransaction::TRANSACTIONTYPE:
|
|
|
|
case PhabricatorProjectFilterTransaction::TRANSACTIONTYPE:
|
2017-05-24 21:46:49 +02:00
|
|
|
case PhabricatorProjectWorkboardBackgroundTransaction::TRANSACTIONTYPE:
|
2016-02-12 15:19:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-19 19:14:27 +01:00
|
|
|
|
2016-02-12 15:19:26 +01:00
|
|
|
return parent::shouldHideForMail($xactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon() {
|
2015-01-19 19:14:27 +01:00
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2015-01-19 19:14:27 +01:00
|
|
|
return 'fa-user';
|
|
|
|
}
|
|
|
|
return parent::getIcon();
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:49:37 +02:00
|
|
|
public function getTitle() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
2015-12-27 15:45:53 +01:00
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$author_handle = $this->renderHandleLink($author_phid);
|
2013-10-22 22:49:37 +02:00
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-12-27 15:45:53 +01:00
|
|
|
case PhabricatorTransactions::TYPE_CREATE:
|
|
|
|
return pht(
|
|
|
|
'%s created this project.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2013-10-22 22:49:37 +02:00
|
|
|
$add = array_diff($new, $old);
|
|
|
|
$rem = array_diff($old, $new);
|
|
|
|
|
|
|
|
if ($add && $rem) {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s changed project member(s), added %d: %s; removed %d: %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($add),
|
|
|
|
$this->renderHandleList($add),
|
|
|
|
count($rem),
|
|
|
|
$this->renderHandleList($rem));
|
|
|
|
} else if ($add) {
|
|
|
|
if (count($add) == 1 && (head($add) == $this->getAuthorPHID())) {
|
|
|
|
return pht(
|
|
|
|
'%s joined this project.',
|
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s added %d project member(s): %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($add),
|
|
|
|
$this->renderHandleList($add));
|
|
|
|
}
|
|
|
|
} else if ($rem) {
|
|
|
|
if (count($rem) == 1 && (head($rem) == $this->getAuthorPHID())) {
|
|
|
|
return pht(
|
|
|
|
'%s left this project.',
|
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s removed %d project member(s): %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($rem),
|
|
|
|
$this->renderHandleList($rem));
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 01:33:31 +02:00
|
|
|
break;
|
2013-10-22 22:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getTitle();
|
|
|
|
}
|
|
|
|
|
2015-05-16 01:33:31 +02:00
|
|
|
public function getMailTags() {
|
|
|
|
$tags = array();
|
|
|
|
switch ($this->getTransactionType()) {
|
2017-05-18 20:03:31 +02:00
|
|
|
case PhabricatorProjectNameTransaction::TRANSACTIONTYPE:
|
|
|
|
case PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE:
|
2017-05-19 00:14:02 +02:00
|
|
|
case PhabricatorProjectImageTransaction::TRANSACTIONTYPE:
|
2017-05-19 01:15:24 +02:00
|
|
|
case PhabricatorProjectIconTransaction::TRANSACTIONTYPE:
|
2017-05-19 01:32:04 +02:00
|
|
|
case PhabricatorProjectColorTransaction::TRANSACTIONTYPE:
|
2015-05-16 01:33:31 +02:00
|
|
|
$tags[] = self::MAILTAG_METADATA;
|
|
|
|
break;
|
|
|
|
case PhabricatorTransactions::TYPE_EDGE:
|
|
|
|
$type = $this->getMetadata('edge:type');
|
|
|
|
$type = head($type);
|
|
|
|
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
|
|
|
|
$type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
|
|
|
if ($type == $type_member) {
|
|
|
|
$tags[] = self::MAILTAG_MEMBERS;
|
|
|
|
} else if ($type == $type_watcher) {
|
|
|
|
$tags[] = self::MAILTAG_WATCHERS;
|
|
|
|
} else {
|
|
|
|
$tags[] = self::MAILTAG_OTHER;
|
|
|
|
}
|
|
|
|
break;
|
2017-05-18 20:24:59 +02:00
|
|
|
case PhabricatorProjectStatusTransaction::TRANSACTIONTYPE:
|
2017-05-21 00:34:07 +02:00
|
|
|
case PhabricatorProjectLockTransaction::TRANSACTIONTYPE:
|
2015-05-16 01:33:31 +02:00
|
|
|
default:
|
|
|
|
$tags[] = self::MAILTAG_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:11:37 +01:00
|
|
|
}
|