[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class FundBacker extends FundDAO 4 implements 5 PhabricatorPolicyInterface, 6 PhabricatorApplicationTransactionInterface { 7 8 protected $initiativePHID; 9 protected $backerPHID; 10 protected $amountAsCurrency; 11 protected $status; 12 protected $properties = array(); 13 14 private $initiative = self::ATTACHABLE; 15 16 const STATUS_NEW = 'new'; 17 const STATUS_IN_CART = 'in-cart'; 18 const STATUS_PURCHASED = 'purchased'; 19 20 public static function initializeNewBacker(PhabricatorUser $actor) { 21 return id(new FundBacker()) 22 ->setBackerPHID($actor->getPHID()) 23 ->setStatus(self::STATUS_NEW); 24 } 25 26 public function getConfiguration() { 27 return array( 28 self::CONFIG_AUX_PHID => true, 29 self::CONFIG_SERIALIZATION => array( 30 'properties' => self::SERIALIZATION_JSON, 31 ), 32 self::CONFIG_APPLICATION_SERIALIZERS => array( 33 'amountAsCurrency' => new PhortuneCurrencySerializer(), 34 ), 35 self::CONFIG_COLUMN_SCHEMA => array( 36 'status' => 'text32', 37 'amountAsCurrency' => 'text64', 38 ), 39 self::CONFIG_KEY_SCHEMA => array( 40 'key_initiative' => array( 41 'columns' => array('initiativePHID'), 42 ), 43 'key_backer' => array( 44 'columns' => array('backerPHID'), 45 ), 46 ), 47 ) + parent::getConfiguration(); 48 } 49 50 public function generatePHID() { 51 return PhabricatorPHID::generateNewPHID(FundBackerPHIDType::TYPECONST); 52 } 53 54 public function getProperty($key, $default = null) { 55 return idx($this->properties, $key, $default); 56 } 57 58 public function setProperty($key, $value) { 59 $this->properties[$key] = $value; 60 return $this; 61 } 62 63 public function getInitiative() { 64 return $this->assertAttached($this->initiative); 65 } 66 67 public function attachInitiative(FundInitiative $initiative = null) { 68 $this->initiative = $initiative; 69 return $this; 70 } 71 72 73 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 74 75 76 public function getCapabilities() { 77 return array( 78 PhabricatorPolicyCapability::CAN_VIEW, 79 ); 80 } 81 82 public function getPolicy($capability) { 83 switch ($capability) { 84 case PhabricatorPolicyCapability::CAN_VIEW: 85 // If we have the initiative, use the initiative's policy. 86 // Otherwise, return NOONE. This allows the backer to continue seeing 87 // a backer even if they're no longer allowed to see the initiative. 88 89 $initiative = $this->getInitiative(); 90 if ($initiative) { 91 return $initiative->getPolicy($capability); 92 } 93 return PhabricatorPolicies::POLICY_NOONE; 94 } 95 } 96 97 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 98 return ($viewer->getPHID() == $this->getBackerPHID()); 99 } 100 101 public function describeAutomaticCapability($capability) { 102 return pht('A backer can always see what they have backed.'); 103 } 104 105 106 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 107 108 109 public function getApplicationTransactionEditor() { 110 return new FundBackerEditor(); 111 } 112 113 public function getApplicationTransactionObject() { 114 return $this; 115 } 116 117 public function getApplicationTransactionTemplate() { 118 return new FundBackerTransaction(); 119 } 120 121 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |