Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / fund / xaction / FundInitiativeBackerTransaction.php
blob72b4b1bd85c5389b81735f3082aa7e42437d472a
1 <?php
3 final class FundInitiativeBackerTransaction
4 extends FundInitiativeTransactionType {
6 const TRANSACTIONTYPE = 'fund:backer';
8 public function generateOldValue($object) {
9 return null;
12 public function applyInternalEffects($object, $value) {
13 $amount = $this->getMetadataValue(
14 FundInitiativeTransaction::PROPERTY_AMOUNT);
15 $amount = PhortuneCurrency::newFromString($amount);
16 $total = $object->getTotalAsCurrency()->add($amount);
17 $object->setTotalAsCurrency($total);
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'));
29 $subx = array();
30 $subx[] = id(new FundBackerTransaction())
31 ->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE)
32 ->setNewValue(FundBacker::STATUS_PURCHASED);
34 $content_source = $this->getEditor()->getContentSource();
36 $editor = id(new FundBackerEditor())
37 ->setActor($this->getActor())
38 ->setContentSource($content_source)
39 ->setContinueOnMissingFields(true)
40 ->setContinueOnNoEffect(true);
42 $editor->applyTransactions($backer, $subx);
45 public function getTitle() {
46 $amount = $this->getMetadataValue(
47 FundInitiativeTransaction::PROPERTY_AMOUNT);
48 $amount = PhortuneCurrency::newFromString($amount);
49 return pht(
50 '%s backed this initiative with %s.',
51 $this->renderAuthor(),
52 $amount->formatForDisplay());
55 public function getTitleForFeed() {
56 $amount = $this->getMetadataValue(
57 FundInitiativeTransaction::PROPERTY_AMOUNT);
58 $amount = PhortuneCurrency::newFromString($amount);
59 return pht(
60 '%s backed %s with %s.',
61 $this->renderAuthor(),
62 $this->renderObject(),
63 $amount->formatForDisplay());
66 public function getIcon() {
67 return 'fa-heart';
70 public function getColor() {
71 return 'red';