2012-12-11 14:00:21 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @concrete-extensible
|
|
|
|
*/
|
|
|
|
class PhabricatorApplicationTransactionFeedStory
|
|
|
|
extends PhabricatorFeedStory {
|
|
|
|
|
|
|
|
public function getPrimaryObjectPHID() {
|
|
|
|
return $this->getValue('objectPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredObjectPHIDs() {
|
2013-11-05 09:03:59 -08:00
|
|
|
return $this->getValue('transactionPHIDs');
|
2012-12-11 14:00:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredHandlePHIDs() {
|
|
|
|
$phids = array();
|
2013-11-05 09:03:59 -08:00
|
|
|
$phids[] = $this->getValue('objectPHID');
|
|
|
|
foreach ($this->getValue('transactionPHIDs') as $xaction_phid) {
|
|
|
|
$xaction = $this->getObject($xaction_phid);
|
|
|
|
foreach ($xaction->getRequiredHandlePHIDs() as $handle_phid) {
|
|
|
|
$phids[] = $handle_phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $phids;
|
2012-12-11 14:00:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPrimaryTransactionPHID() {
|
|
|
|
return head($this->getValue('transactionPHIDs'));
|
|
|
|
}
|
|
|
|
|
2014-08-02 00:06:56 -07:00
|
|
|
public function getPrimaryTransaction() {
|
2012-12-11 14:00:21 -08:00
|
|
|
return $this->getObject($this->getPrimaryTransactionPHID());
|
|
|
|
}
|
|
|
|
|
2014-08-26 14:36:35 -07:00
|
|
|
public function getFieldStoryMarkupFields() {
|
|
|
|
$xaction_phids = $this->getValue('transactionPHIDs');
|
|
|
|
|
|
|
|
$fields = array();
|
|
|
|
foreach ($xaction_phids as $xaction_phid) {
|
|
|
|
$xaction = $this->getObject($xaction_phid);
|
|
|
|
foreach ($xaction->getMarkupFieldsForFeed($this) as $field) {
|
|
|
|
$fields[] = $field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
$xaction_phids = $this->getValue('transactionPHIDs');
|
|
|
|
|
|
|
|
foreach ($xaction_phids as $xaction_phid) {
|
|
|
|
$xaction = $this->getObject($xaction_phid);
|
|
|
|
foreach ($xaction->getMarkupFieldsForFeed($this) as $xaction_field) {
|
|
|
|
if ($xaction_field == $field) {
|
|
|
|
return $xaction->getMarkupTextForFeed($this, $field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-12-11 14:00:21 -08:00
|
|
|
public function renderView() {
|
2013-07-12 17:04:02 -07:00
|
|
|
$view = $this->newStoryView();
|
2012-12-11 14:00:21 -08:00
|
|
|
|
2013-05-26 07:54:29 -07:00
|
|
|
$handle = $this->getHandle($this->getPrimaryObjectPHID());
|
|
|
|
$view->setHref($handle->getURI());
|
|
|
|
|
2015-01-25 14:14:41 -08:00
|
|
|
$type = phid_get_type($handle->getPHID());
|
|
|
|
$phid_types = PhabricatorPHIDType::getAllTypes();
|
|
|
|
$icon = null;
|
|
|
|
if (!empty($phid_types[$type])) {
|
|
|
|
$phid_type = $phid_types[$type];
|
|
|
|
$class = $phid_type->getPHIDTypeApplicationClass();
|
|
|
|
if ($class) {
|
|
|
|
$application = PhabricatorApplication::getByClass($class);
|
2016-01-28 08:40:22 -08:00
|
|
|
$icon = $application->getIcon();
|
2015-01-25 14:14:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->setAppIcon($icon);
|
2012-12-11 14:00:21 -08:00
|
|
|
|
|
|
|
$xaction_phids = $this->getValue('transactionPHIDs');
|
2013-11-05 09:03:59 -08:00
|
|
|
$xaction = $this->getPrimaryTransaction();
|
2012-12-11 14:00:21 -08:00
|
|
|
|
|
|
|
$xaction->setHandles($this->getHandles());
|
2015-01-02 08:45:43 -08:00
|
|
|
$view->setTitle($xaction->getTitleForFeed());
|
2013-11-05 09:03:59 -08:00
|
|
|
|
|
|
|
foreach ($xaction_phids as $xaction_phid) {
|
|
|
|
$secondary_xaction = $this->getObject($xaction_phid);
|
|
|
|
$secondary_xaction->setHandles($this->getHandles());
|
|
|
|
|
|
|
|
$body = $secondary_xaction->getBodyForFeed($this);
|
|
|
|
if (nonempty($body)) {
|
|
|
|
$view->appendChild($body);
|
|
|
|
}
|
2013-08-05 10:10:33 -07:00
|
|
|
}
|
2012-12-11 14:00:21 -08:00
|
|
|
|
2016-04-20 14:24:24 -07:00
|
|
|
$author_phid = $xaction->getAuthorPHID();
|
|
|
|
$author_handle = $this->getHandle($author_phid);
|
|
|
|
$author_image = $author_handle->getImageURI();
|
|
|
|
|
|
|
|
if ($author_image) {
|
|
|
|
$view->setImage($author_image);
|
|
|
|
} else {
|
|
|
|
$view->setAuthorIcon($author_handle->getIcon());
|
|
|
|
}
|
2013-05-26 07:54:29 -07:00
|
|
|
|
2012-12-11 14:00:21 -08:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-02-15 17:10:51 -08:00
|
|
|
public function renderText() {
|
2014-04-10 13:46:02 -07:00
|
|
|
$xaction = $this->getPrimaryTransaction();
|
|
|
|
$old_target = $xaction->getRenderingTarget();
|
|
|
|
$new_target = PhabricatorApplicationTransaction::TARGET_TEXT;
|
|
|
|
$xaction->setRenderingTarget($new_target);
|
2014-04-17 15:57:18 -07:00
|
|
|
$xaction->setHandles($this->getHandles());
|
2015-01-02 08:45:43 -08:00
|
|
|
$text = $xaction->getTitleForFeed();
|
2014-04-10 13:46:02 -07:00
|
|
|
$xaction->setRenderingTarget($old_target);
|
|
|
|
return $text;
|
2013-02-15 17:10:51 -08:00
|
|
|
}
|
|
|
|
|
2015-06-22 13:11:37 -07:00
|
|
|
public function renderTextBody() {
|
|
|
|
$all_bodies = '';
|
|
|
|
$new_target = PhabricatorApplicationTransaction::TARGET_TEXT;
|
|
|
|
$xaction_phids = $this->getValue('transactionPHIDs');
|
|
|
|
foreach ($xaction_phids as $xaction_phid) {
|
|
|
|
$secondary_xaction = $this->getObject($xaction_phid);
|
|
|
|
$old_target = $secondary_xaction->getRenderingTarget();
|
|
|
|
$secondary_xaction->setRenderingTarget($new_target);
|
|
|
|
$secondary_xaction->setHandles($this->getHandles());
|
|
|
|
|
|
|
|
$body = $secondary_xaction->getBodyForMail();
|
|
|
|
if (nonempty($body)) {
|
|
|
|
$all_bodies .= $body."\n";
|
|
|
|
}
|
|
|
|
$secondary_xaction->setRenderingTarget($old_target);
|
|
|
|
}
|
|
|
|
return trim($all_bodies);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getImageURI() {
|
|
|
|
$author_phid = $this->getPrimaryTransaction()->getAuthorPHID();
|
|
|
|
return $this->getHandle($author_phid)->getImageURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
$handle = $this->getHandle($this->getPrimaryObjectPHID());
|
|
|
|
return PhabricatorEnv::getProductionURI($handle->getURI());
|
|
|
|
}
|
|
|
|
|
2014-10-01 07:09:34 -07:00
|
|
|
public function renderAsTextForDoorkeeper(
|
|
|
|
DoorkeeperFeedStoryPublisher $publisher) {
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xaction_phids = $this->getValue('transactionPHIDs');
|
|
|
|
foreach ($xaction_phids as $xaction_phid) {
|
2014-10-13 16:45:58 -07:00
|
|
|
$xaction = $this->getObject($xaction_phid);
|
|
|
|
$xaction->setHandles($this->getHandles());
|
|
|
|
$xactions[] = $xaction;
|
2014-10-01 07:09:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$primary = $this->getPrimaryTransaction();
|
|
|
|
return $primary->renderAsTextForDoorkeeper($publisher, $this, $xactions);
|
|
|
|
}
|
|
|
|
|
2012-12-11 14:00:21 -08:00
|
|
|
}
|