Path: blob/master/src/applications/fund/storage/FundInitiative.php
12256 views
<?php12final class FundInitiative extends FundDAO3implements4PhabricatorPolicyInterface,5PhabricatorProjectInterface,6PhabricatorApplicationTransactionInterface,7PhabricatorSubscribableInterface,8PhabricatorMentionableInterface,9PhabricatorFlaggableInterface,10PhabricatorTokenReceiverInterface,11PhabricatorDestructibleInterface,12PhabricatorFulltextInterface,13PhabricatorFerretInterface {1415protected $name;16protected $ownerPHID;17protected $merchantPHID;18protected $description;19protected $risks;20protected $viewPolicy;21protected $editPolicy;22protected $status;23protected $totalAsCurrency;2425private $projectPHIDs = self::ATTACHABLE;2627const STATUS_OPEN = 'open';28const STATUS_CLOSED = 'closed';2930public static function getStatusNameMap() {31return array(32self::STATUS_OPEN => pht('Open'),33self::STATUS_CLOSED => pht('Closed'),34);35}3637public static function initializeNewInitiative(PhabricatorUser $actor) {38$app = id(new PhabricatorApplicationQuery())39->setViewer($actor)40->withClasses(array('PhabricatorFundApplication'))41->executeOne();4243$view_policy = $app->getPolicy(FundDefaultViewCapability::CAPABILITY);4445return id(new FundInitiative())46->setOwnerPHID($actor->getPHID())47->setViewPolicy($view_policy)48->setEditPolicy($actor->getPHID())49->setStatus(self::STATUS_OPEN)50->setTotalAsCurrency(PhortuneCurrency::newEmptyCurrency());51}5253protected function getConfiguration() {54return array(55self::CONFIG_AUX_PHID => true,56self::CONFIG_COLUMN_SCHEMA => array(57'name' => 'text255',58'description' => 'text',59'risks' => 'text',60'status' => 'text32',61'merchantPHID' => 'phid?',62'totalAsCurrency' => 'text64',63),64self::CONFIG_APPLICATION_SERIALIZERS => array(65'totalAsCurrency' => new PhortuneCurrencySerializer(),66),67self::CONFIG_KEY_SCHEMA => array(68'key_status' => array(69'columns' => array('status'),70),71'key_owner' => array(72'columns' => array('ownerPHID'),73),74),75) + parent::getConfiguration();76}7778public function getPHIDType() {79return FundInitiativePHIDType::TYPECONST;80}8182public function getMonogram() {83return 'I'.$this->getID();84}8586public function getViewURI() {87return '/'.$this->getMonogram();88}8990public function getProjectPHIDs() {91return $this->assertAttached($this->projectPHIDs);92}9394public function attachProjectPHIDs(array $phids) {95$this->projectPHIDs = $phids;96return $this;97}9899public function isClosed() {100return ($this->getStatus() == self::STATUS_CLOSED);101}102103104/* -( PhabricatorPolicyInterface )----------------------------------------- */105106107public function getCapabilities() {108return array(109PhabricatorPolicyCapability::CAN_VIEW,110PhabricatorPolicyCapability::CAN_EDIT,111);112}113114public function getPolicy($capability) {115switch ($capability) {116case PhabricatorPolicyCapability::CAN_VIEW:117return $this->getViewPolicy();118case PhabricatorPolicyCapability::CAN_EDIT:119return $this->getEditPolicy();120}121}122123public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {124if ($viewer->getPHID() == $this->getOwnerPHID()) {125return true;126}127128if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {129$can_merchant = PhortuneMerchantQuery::canViewersEditMerchants(130array($viewer->getPHID()),131array($this->getMerchantPHID()));132133if ($can_merchant) {134return true;135}136}137138return false;139}140141public function describeAutomaticCapability($capability) {142return pht('The owner of an initiative can always view and edit it.');143}144145146/* -( PhabricatorApplicationTransactionInterface )------------------------- */147148149public function getApplicationTransactionEditor() {150return new FundInitiativeEditor();151}152153public function getApplicationTransactionTemplate() {154return new FundInitiativeTransaction();155}156157158/* -( PhabricatorSubscribableInterface )----------------------------------- */159160161public function isAutomaticallySubscribed($phid) {162return ($phid == $this->getOwnerPHID());163}164165166/* -( PhabricatorTokenRecevierInterface )---------------------------------- */167168169public function getUsersToNotifyOfTokenGiven() {170return array(171$this->getOwnerPHID(),172);173}174175176/* -( PhabricatorDestructibleInterface )----------------------------------- */177178179public function destroyObjectPermanently(180PhabricatorDestructionEngine $engine) {181182$this->openTransaction();183$this->delete();184$this->saveTransaction();185}186187188/* -( PhabricatorFulltextInterface )--------------------------------------- */189190191public function newFulltextEngine() {192return new FundInitiativeFulltextEngine();193}194195196/* -( PhabricatorFerretInterface )----------------------------------------- */197198199public function newFerretEngine() {200return new FundInitiativeFerretEngine();201}202203}204205206