3 final class FundInitiative
extends FundDAO
5 PhabricatorPolicyInterface
,
6 PhabricatorProjectInterface
,
7 PhabricatorApplicationTransactionInterface
,
8 PhabricatorSubscribableInterface
,
9 PhabricatorMentionableInterface
,
10 PhabricatorFlaggableInterface
,
11 PhabricatorTokenReceiverInterface
,
12 PhabricatorDestructibleInterface
,
13 PhabricatorFulltextInterface
,
14 PhabricatorFerretInterface
{
18 protected $merchantPHID;
19 protected $description;
21 protected $viewPolicy;
22 protected $editPolicy;
24 protected $totalAsCurrency;
26 private $projectPHIDs = self
::ATTACHABLE
;
28 const STATUS_OPEN
= 'open';
29 const STATUS_CLOSED
= 'closed';
31 public static function getStatusNameMap() {
33 self
::STATUS_OPEN
=> pht('Open'),
34 self
::STATUS_CLOSED
=> pht('Closed'),
38 public static function initializeNewInitiative(PhabricatorUser
$actor) {
39 $app = id(new PhabricatorApplicationQuery())
41 ->withClasses(array('PhabricatorFundApplication'))
44 $view_policy = $app->getPolicy(FundDefaultViewCapability
::CAPABILITY
);
46 return id(new FundInitiative())
47 ->setOwnerPHID($actor->getPHID())
48 ->setViewPolicy($view_policy)
49 ->setEditPolicy($actor->getPHID())
50 ->setStatus(self
::STATUS_OPEN
)
51 ->setTotalAsCurrency(PhortuneCurrency
::newEmptyCurrency());
54 protected function getConfiguration() {
56 self
::CONFIG_AUX_PHID
=> true,
57 self
::CONFIG_COLUMN_SCHEMA
=> array(
59 'description' => 'text',
62 'merchantPHID' => 'phid?',
63 'totalAsCurrency' => 'text64',
65 self
::CONFIG_APPLICATION_SERIALIZERS
=> array(
66 'totalAsCurrency' => new PhortuneCurrencySerializer(),
68 self
::CONFIG_KEY_SCHEMA
=> array(
69 'key_status' => array(
70 'columns' => array('status'),
73 'columns' => array('ownerPHID'),
76 ) + parent
::getConfiguration();
79 public function getPHIDType() {
80 return FundInitiativePHIDType
::TYPECONST
;
83 public function getMonogram() {
84 return 'I'.$this->getID();
87 public function getViewURI() {
88 return '/'.$this->getMonogram();
91 public function getProjectPHIDs() {
92 return $this->assertAttached($this->projectPHIDs
);
95 public function attachProjectPHIDs(array $phids) {
96 $this->projectPHIDs
= $phids;
100 public function isClosed() {
101 return ($this->getStatus() == self
::STATUS_CLOSED
);
105 /* -( PhabricatorPolicyInterface )----------------------------------------- */
108 public function getCapabilities() {
110 PhabricatorPolicyCapability
::CAN_VIEW
,
111 PhabricatorPolicyCapability
::CAN_EDIT
,
115 public function getPolicy($capability) {
116 switch ($capability) {
117 case PhabricatorPolicyCapability
::CAN_VIEW
:
118 return $this->getViewPolicy();
119 case PhabricatorPolicyCapability
::CAN_EDIT
:
120 return $this->getEditPolicy();
124 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
125 if ($viewer->getPHID() == $this->getOwnerPHID()) {
129 if ($capability == PhabricatorPolicyCapability
::CAN_VIEW
) {
130 $can_merchant = PhortuneMerchantQuery
::canViewersEditMerchants(
131 array($viewer->getPHID()),
132 array($this->getMerchantPHID()));
142 public function describeAutomaticCapability($capability) {
143 return pht('The owner of an initiative can always view and edit it.');
147 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
150 public function getApplicationTransactionEditor() {
151 return new FundInitiativeEditor();
154 public function getApplicationTransactionTemplate() {
155 return new FundInitiativeTransaction();
159 /* -( PhabricatorSubscribableInterface )----------------------------------- */
162 public function isAutomaticallySubscribed($phid) {
163 return ($phid == $this->getOwnerPHID());
167 /* -( PhabricatorTokenRecevierInterface )---------------------------------- */
170 public function getUsersToNotifyOfTokenGiven() {
172 $this->getOwnerPHID(),
177 /* -( PhabricatorDestructibleInterface )----------------------------------- */
180 public function destroyObjectPermanently(
181 PhabricatorDestructionEngine
$engine) {
183 $this->openTransaction();
185 $this->saveTransaction();
189 /* -( PhabricatorFulltextInterface )--------------------------------------- */
192 public function newFulltextEngine() {
193 return new FundInitiativeFulltextEngine();
197 /* -( PhabricatorFerretInterface )----------------------------------------- */
200 public function newFerretEngine() {
201 return new FundInitiativeFerretEngine();