Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fund/phortune/FundBackerCart.php
12256 views
1
<?php
2
3
final class FundBackerCart extends PhortuneCartImplementation {
4
5
private $initiativePHID;
6
private $initiative;
7
8
public function setInitiativePHID($initiative_phid) {
9
$this->initiativePHID = $initiative_phid;
10
return $this;
11
}
12
13
public function getInitiativePHID() {
14
return $this->initiativePHID;
15
}
16
17
public function setInitiative(FundInitiative $initiative) {
18
$this->initiative = $initiative;
19
return $this;
20
}
21
22
public function getInitiative() {
23
return $this->initiative;
24
}
25
26
public function getName(PhortuneCart $cart) {
27
return pht('Fund Initiative');
28
}
29
30
public function willCreateCart(
31
PhabricatorUser $viewer,
32
PhortuneCart $cart) {
33
34
$initiative = $this->getInitiative();
35
if (!$initiative) {
36
throw new PhutilInvalidStateException('setInitiative');
37
}
38
39
$cart->setMetadataValue('initiativePHID', $initiative->getPHID());
40
}
41
42
public function loadImplementationsForCarts(
43
PhabricatorUser $viewer,
44
array $carts) {
45
46
$phids = array();
47
foreach ($carts as $cart) {
48
$phids[] = $cart->getMetadataValue('initiativePHID');
49
}
50
51
$initiatives = id(new FundInitiativeQuery())
52
->setViewer($viewer)
53
->withPHIDs($phids)
54
->execute();
55
$initiatives = mpull($initiatives, null, 'getPHID');
56
57
$objects = array();
58
foreach ($carts as $key => $cart) {
59
$initiative_phid = $cart->getMetadataValue('initiativePHID');
60
61
$object = id(new FundBackerCart())
62
->setInitiativePHID($initiative_phid);
63
64
$initiative = idx($initiatives, $initiative_phid);
65
if ($initiative) {
66
$object->setInitiative($initiative);
67
}
68
69
$objects[$key] = $object;
70
}
71
72
return $objects;
73
}
74
75
public function getCancelURI(PhortuneCart $cart) {
76
return '/'.$this->getInitiative()->getMonogram();
77
}
78
79
public function getDoneURI(PhortuneCart $cart) {
80
return '/'.$this->getInitiative()->getMonogram();
81
}
82
83
public function getDoneActionName(PhortuneCart $cart) {
84
return pht('Return to Initiative');
85
}
86
87
}
88
89