Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fund/xaction/FundInitiativeRefundTransaction.php
12256 views
1
<?php
2
3
final class FundInitiativeRefundTransaction
4
extends FundInitiativeTransactionType {
5
6
const TRANSACTIONTYPE = 'fund:refund';
7
8
public function generateOldValue($object) {
9
return null;
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$amount = $this->getMetadataValue(
14
FundInitiativeTransaction::PROPERTY_AMOUNT);
15
$amount = PhortuneCurrency::newFromString($amount);
16
$total = $object->getTotalAsCurrency()->subtract($amount);
17
$object->setTotalAsCurrency($total);
18
}
19
20
public function applyExternalEffects($object, $value) {
21
$backer = id(new FundBackerQuery())
22
->setViewer($this->getActor())
23
->withPHIDs(array($value))
24
->executeOne();
25
if (!$backer) {
26
throw new Exception(pht('Unable to load %s!', 'FundBacker'));
27
}
28
29
$subx = array();
30
$amount = $this->getMetadataValue(
31
FundInitiativeTransaction::PROPERTY_AMOUNT);
32
$subx[] = id(new FundBackerTransaction())
33
->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE)
34
->setNewValue($amount);
35
36
$content_source = $this->getEditor()->getContentSource();
37
38
$editor = id(new FundBackerEditor())
39
->setActor($this->getActor())
40
->setContentSource($content_source)
41
->setContinueOnMissingFields(true)
42
->setContinueOnNoEffect(true);
43
44
$editor->applyTransactions($backer, $subx);
45
}
46
47
public function getTitle() {
48
$amount = $this->getMetadataValue(
49
FundInitiativeTransaction::PROPERTY_AMOUNT);
50
$amount = PhortuneCurrency::newFromString($amount);
51
$backer_phid = $this->getMetadataValue(
52
FundInitiativeTransaction::PROPERTY_BACKER);
53
54
return pht(
55
'%s refunded %s to %s.',
56
$this->renderAuthor(),
57
$amount->formatForDisplay(),
58
$this->renderHandle($backer_phid));
59
}
60
61
public function getTitleForFeed() {
62
$amount = $this->getMetadataValue(
63
FundInitiativeTransaction::PROPERTY_AMOUNT);
64
$amount = PhortuneCurrency::newFromString($amount);
65
$backer_phid = $this->getMetadataValue(
66
FundInitiativeTransaction::PROPERTY_BACKER);
67
68
return pht(
69
'%s refunded %s to %s for %s.',
70
$this->renderAuthor(),
71
$amount->formatForDisplay(),
72
$this->renderHandle($backer_phid),
73
$this->renderObject());
74
}
75
76
77
}
78
79