Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / fund / storage / FundInitiative.php
blob7503083c237de3f6aa84330c14e40bc7a424d9f4
1 <?php
3 final class FundInitiative extends FundDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorProjectInterface,
7 PhabricatorApplicationTransactionInterface,
8 PhabricatorSubscribableInterface,
9 PhabricatorMentionableInterface,
10 PhabricatorFlaggableInterface,
11 PhabricatorTokenReceiverInterface,
12 PhabricatorDestructibleInterface,
13 PhabricatorFulltextInterface,
14 PhabricatorFerretInterface {
16 protected $name;
17 protected $ownerPHID;
18 protected $merchantPHID;
19 protected $description;
20 protected $risks;
21 protected $viewPolicy;
22 protected $editPolicy;
23 protected $status;
24 protected $totalAsCurrency;
26 private $projectPHIDs = self::ATTACHABLE;
28 const STATUS_OPEN = 'open';
29 const STATUS_CLOSED = 'closed';
31 public static function getStatusNameMap() {
32 return array(
33 self::STATUS_OPEN => pht('Open'),
34 self::STATUS_CLOSED => pht('Closed'),
38 public static function initializeNewInitiative(PhabricatorUser $actor) {
39 $app = id(new PhabricatorApplicationQuery())
40 ->setViewer($actor)
41 ->withClasses(array('PhabricatorFundApplication'))
42 ->executeOne();
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() {
55 return array(
56 self::CONFIG_AUX_PHID => true,
57 self::CONFIG_COLUMN_SCHEMA => array(
58 'name' => 'text255',
59 'description' => 'text',
60 'risks' => 'text',
61 'status' => 'text32',
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'),
72 'key_owner' => array(
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;
97 return $this;
100 public function isClosed() {
101 return ($this->getStatus() == self::STATUS_CLOSED);
105 /* -( PhabricatorPolicyInterface )----------------------------------------- */
108 public function getCapabilities() {
109 return array(
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()) {
126 return true;
129 if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
130 $can_merchant = PhortuneMerchantQuery::canViewersEditMerchants(
131 array($viewer->getPHID()),
132 array($this->getMerchantPHID()));
134 if ($can_merchant) {
135 return true;
139 return false;
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() {
171 return array(
172 $this->getOwnerPHID(),
177 /* -( PhabricatorDestructibleInterface )----------------------------------- */
180 public function destroyObjectPermanently(
181 PhabricatorDestructionEngine $engine) {
183 $this->openTransaction();
184 $this->delete();
185 $this->saveTransaction();
189 /* -( PhabricatorFulltextInterface )--------------------------------------- */
192 public function newFulltextEngine() {
193 return new FundInitiativeFulltextEngine();
197 /* -( PhabricatorFerretInterface )----------------------------------------- */
200 public function newFerretEngine() {
201 return new FundInitiativeFerretEngine();