Path: blob/master/src/applications/fund/storage/FundBacker.php
12256 views
<?php12final class FundBacker extends FundDAO3implements4PhabricatorPolicyInterface,5PhabricatorApplicationTransactionInterface {67protected $initiativePHID;8protected $backerPHID;9protected $amountAsCurrency;10protected $status;11protected $properties = array();1213private $initiative = self::ATTACHABLE;1415const STATUS_NEW = 'new';16const STATUS_IN_CART = 'in-cart';17const STATUS_PURCHASED = 'purchased';1819public static function initializeNewBacker(PhabricatorUser $actor) {20return id(new FundBacker())21->setBackerPHID($actor->getPHID())22->setStatus(self::STATUS_NEW);23}2425protected function getConfiguration() {26return array(27self::CONFIG_AUX_PHID => true,28self::CONFIG_SERIALIZATION => array(29'properties' => self::SERIALIZATION_JSON,30),31self::CONFIG_APPLICATION_SERIALIZERS => array(32'amountAsCurrency' => new PhortuneCurrencySerializer(),33),34self::CONFIG_COLUMN_SCHEMA => array(35'status' => 'text32',36'amountAsCurrency' => 'text64',37),38self::CONFIG_KEY_SCHEMA => array(39'key_initiative' => array(40'columns' => array('initiativePHID'),41),42'key_backer' => array(43'columns' => array('backerPHID'),44),45),46) + parent::getConfiguration();47}4849public function generatePHID() {50return PhabricatorPHID::generateNewPHID(FundBackerPHIDType::TYPECONST);51}5253public function getProperty($key, $default = null) {54return idx($this->properties, $key, $default);55}5657public function setProperty($key, $value) {58$this->properties[$key] = $value;59return $this;60}6162public function getInitiative() {63return $this->assertAttached($this->initiative);64}6566public function attachInitiative(FundInitiative $initiative = null) {67$this->initiative = $initiative;68return $this;69}707172/* -( PhabricatorPolicyInterface )----------------------------------------- */737475public function getCapabilities() {76return array(77PhabricatorPolicyCapability::CAN_VIEW,78PhabricatorPolicyCapability::CAN_EDIT,79);80}8182public function getPolicy($capability) {83switch ($capability) {84case PhabricatorPolicyCapability::CAN_VIEW:85// If we have the initiative, use the initiative's policy.86// Otherwise, return NOONE. This allows the backer to continue seeing87// a backer even if they're no longer allowed to see the initiative.8889$initiative = $this->getInitiative();90if ($initiative) {91return $initiative->getPolicy($capability);92}93return PhabricatorPolicies::POLICY_NOONE;94case PhabricatorPolicyCapability::CAN_EDIT:95return PhabricatorPolicies::POLICY_NOONE;96}97}9899public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {100return ($viewer->getPHID() == $this->getBackerPHID());101}102103public function describeAutomaticCapability($capability) {104return pht('A backer can always see what they have backed.');105}106107108/* -( PhabricatorApplicationTransactionInterface )------------------------- */109110111public function getApplicationTransactionEditor() {112return new FundBackerEditor();113}114115public function getApplicationTransactionTemplate() {116return new FundBackerTransaction();117}118119}120121122