@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 204 lines 5.1 kB view raw
1<?php 2 3final 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 { 15 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; 25 26 private $projectPHIDs = self::ATTACHABLE; 27 28 const STATUS_OPEN = 'open'; 29 const STATUS_CLOSED = 'closed'; 30 31 public static function getStatusNameMap() { 32 return array( 33 self::STATUS_OPEN => pht('Open'), 34 self::STATUS_CLOSED => pht('Closed'), 35 ); 36 } 37 38 public static function initializeNewInitiative(PhabricatorUser $actor) { 39 $app = id(new PhabricatorApplicationQuery()) 40 ->setViewer($actor) 41 ->withClasses(array(PhabricatorFundApplication::class)) 42 ->executeOne(); 43 44 $view_policy = $app->getPolicy(FundDefaultViewCapability::CAPABILITY); 45 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()); 52 } 53 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', 64 ), 65 self::CONFIG_APPLICATION_SERIALIZERS => array( 66 'totalAsCurrency' => new PhortuneCurrencySerializer(), 67 ), 68 self::CONFIG_KEY_SCHEMA => array( 69 'key_status' => array( 70 'columns' => array('status'), 71 ), 72 'key_owner' => array( 73 'columns' => array('ownerPHID'), 74 ), 75 ), 76 ) + parent::getConfiguration(); 77 } 78 79 public function getPHIDType() { 80 return FundInitiativePHIDType::TYPECONST; 81 } 82 83 public function getMonogram() { 84 return 'I'.$this->getID(); 85 } 86 87 public function getViewURI() { 88 return '/'.$this->getMonogram(); 89 } 90 91 public function getProjectPHIDs() { 92 return $this->assertAttached($this->projectPHIDs); 93 } 94 95 public function attachProjectPHIDs(array $phids) { 96 $this->projectPHIDs = $phids; 97 return $this; 98 } 99 100 public function isClosed() { 101 return ($this->getStatus() == self::STATUS_CLOSED); 102 } 103 104 105/* -( PhabricatorPolicyInterface )----------------------------------------- */ 106 107 108 public function getCapabilities() { 109 return array( 110 PhabricatorPolicyCapability::CAN_VIEW, 111 PhabricatorPolicyCapability::CAN_EDIT, 112 ); 113 } 114 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(); 121 } 122 } 123 124 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 125 if ($viewer->getPHID() == $this->getOwnerPHID()) { 126 return true; 127 } 128 129 if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { 130 $can_merchant = PhortuneMerchantQuery::canViewersEditMerchants( 131 array($viewer->getPHID()), 132 array($this->getMerchantPHID())); 133 134 if ($can_merchant) { 135 return true; 136 } 137 } 138 139 return false; 140 } 141 142 public function describeAutomaticCapability($capability) { 143 return pht('The owner of an initiative can always view and edit it.'); 144 } 145 146 147/* -( PhabricatorApplicationTransactionInterface )------------------------- */ 148 149 150 public function getApplicationTransactionEditor() { 151 return new FundInitiativeEditor(); 152 } 153 154 public function getApplicationTransactionTemplate() { 155 return new FundInitiativeTransaction(); 156 } 157 158 159/* -( PhabricatorSubscribableInterface )----------------------------------- */ 160 161 162 public function isAutomaticallySubscribed($phid) { 163 return ($phid == $this->getOwnerPHID()); 164 } 165 166 167/* -( PhabricatorTokenRecevierInterface )---------------------------------- */ 168 169 170 public function getUsersToNotifyOfTokenGiven() { 171 return array( 172 $this->getOwnerPHID(), 173 ); 174 } 175 176 177/* -( PhabricatorDestructibleInterface )----------------------------------- */ 178 179 180 public function destroyObjectPermanently( 181 PhabricatorDestructionEngine $engine) { 182 183 $this->openTransaction(); 184 $this->delete(); 185 $this->saveTransaction(); 186 } 187 188 189/* -( PhabricatorFulltextInterface )--------------------------------------- */ 190 191 192 public function newFulltextEngine() { 193 return new FundInitiativeFulltextEngine(); 194 } 195 196 197/* -( PhabricatorFerretInterface )----------------------------------------- */ 198 199 200 public function newFerretEngine() { 201 return new FundInitiativeFerretEngine(); 202 } 203 204}