Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fund/storage/FundBacker.php
12256 views
1
<?php
2
3
final class FundBacker extends FundDAO
4
implements
5
PhabricatorPolicyInterface,
6
PhabricatorApplicationTransactionInterface {
7
8
protected $initiativePHID;
9
protected $backerPHID;
10
protected $amountAsCurrency;
11
protected $status;
12
protected $properties = array();
13
14
private $initiative = self::ATTACHABLE;
15
16
const STATUS_NEW = 'new';
17
const STATUS_IN_CART = 'in-cart';
18
const STATUS_PURCHASED = 'purchased';
19
20
public static function initializeNewBacker(PhabricatorUser $actor) {
21
return id(new FundBacker())
22
->setBackerPHID($actor->getPHID())
23
->setStatus(self::STATUS_NEW);
24
}
25
26
protected function getConfiguration() {
27
return array(
28
self::CONFIG_AUX_PHID => true,
29
self::CONFIG_SERIALIZATION => array(
30
'properties' => self::SERIALIZATION_JSON,
31
),
32
self::CONFIG_APPLICATION_SERIALIZERS => array(
33
'amountAsCurrency' => new PhortuneCurrencySerializer(),
34
),
35
self::CONFIG_COLUMN_SCHEMA => array(
36
'status' => 'text32',
37
'amountAsCurrency' => 'text64',
38
),
39
self::CONFIG_KEY_SCHEMA => array(
40
'key_initiative' => array(
41
'columns' => array('initiativePHID'),
42
),
43
'key_backer' => array(
44
'columns' => array('backerPHID'),
45
),
46
),
47
) + parent::getConfiguration();
48
}
49
50
public function generatePHID() {
51
return PhabricatorPHID::generateNewPHID(FundBackerPHIDType::TYPECONST);
52
}
53
54
public function getProperty($key, $default = null) {
55
return idx($this->properties, $key, $default);
56
}
57
58
public function setProperty($key, $value) {
59
$this->properties[$key] = $value;
60
return $this;
61
}
62
63
public function getInitiative() {
64
return $this->assertAttached($this->initiative);
65
}
66
67
public function attachInitiative(FundInitiative $initiative = null) {
68
$this->initiative = $initiative;
69
return $this;
70
}
71
72
73
/* -( PhabricatorPolicyInterface )----------------------------------------- */
74
75
76
public function getCapabilities() {
77
return array(
78
PhabricatorPolicyCapability::CAN_VIEW,
79
PhabricatorPolicyCapability::CAN_EDIT,
80
);
81
}
82
83
public function getPolicy($capability) {
84
switch ($capability) {
85
case PhabricatorPolicyCapability::CAN_VIEW:
86
// If we have the initiative, use the initiative's policy.
87
// Otherwise, return NOONE. This allows the backer to continue seeing
88
// a backer even if they're no longer allowed to see the initiative.
89
90
$initiative = $this->getInitiative();
91
if ($initiative) {
92
return $initiative->getPolicy($capability);
93
}
94
return PhabricatorPolicies::POLICY_NOONE;
95
case PhabricatorPolicyCapability::CAN_EDIT:
96
return PhabricatorPolicies::POLICY_NOONE;
97
}
98
}
99
100
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
101
return ($viewer->getPHID() == $this->getBackerPHID());
102
}
103
104
public function describeAutomaticCapability($capability) {
105
return pht('A backer can always see what they have backed.');
106
}
107
108
109
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
110
111
112
public function getApplicationTransactionEditor() {
113
return new FundBackerEditor();
114
}
115
116
public function getApplicationTransactionTemplate() {
117
return new FundBackerTransaction();
118
}
119
120
}
121
122