[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 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 14 protected $name; 15 protected $ownerPHID; 16 protected $merchantPHID; 17 protected $description; 18 protected $risks; 19 protected $viewPolicy; 20 protected $editPolicy; 21 protected $status; 22 protected $totalAsCurrency; 23 protected $mailKey; 24 25 private $projectPHIDs = self::ATTACHABLE; 26 27 const STATUS_OPEN = 'open'; 28 const STATUS_CLOSED = 'closed'; 29 30 public static function getStatusNameMap() { 31 return array( 32 self::STATUS_OPEN => pht('Open'), 33 self::STATUS_CLOSED => pht('Closed'), 34 ); 35 } 36 37 public static function initializeNewInitiative(PhabricatorUser $actor) { 38 $app = id(new PhabricatorApplicationQuery()) 39 ->setViewer($actor) 40 ->withClasses(array('PhabricatorFundApplication')) 41 ->executeOne(); 42 43 $view_policy = $app->getPolicy(FundDefaultViewCapability::CAPABILITY); 44 45 return 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 } 52 53 public function getConfiguration() { 54 return array( 55 self::CONFIG_AUX_PHID => true, 56 self::CONFIG_COLUMN_SCHEMA => array( 57 'name' => 'text255', 58 'description' => 'text', 59 'risks' => 'text', 60 'status' => 'text32', 61 'merchantPHID' => 'phid?', 62 'totalAsCurrency' => 'text64', 63 'mailKey' => 'bytes20', 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 generatePHID() { 80 return PhabricatorPHID::generateNewPHID(FundInitiativePHIDType::TYPECONST); 81 } 82 83 public function getMonogram() { 84 return 'I'.$this->getID(); 85 } 86 87 public function getProjectPHIDs() { 88 return $this->assertAttached($this->projectPHIDs); 89 } 90 91 public function attachProjectPHIDs(array $phids) { 92 $this->projectPHIDs = $phids; 93 return $this; 94 } 95 96 public function isClosed() { 97 return ($this->getStatus() == self::STATUS_CLOSED); 98 } 99 100 public function save() { 101 if (!$this->mailKey) { 102 $this->mailKey = Filesystem::readRandomCharacters(20); 103 } 104 return parent::save(); 105 } 106 107 108 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 109 110 111 public function getCapabilities() { 112 return array( 113 PhabricatorPolicyCapability::CAN_VIEW, 114 PhabricatorPolicyCapability::CAN_EDIT, 115 ); 116 } 117 118 public function getPolicy($capability) { 119 switch ($capability) { 120 case PhabricatorPolicyCapability::CAN_VIEW: 121 return $this->getViewPolicy(); 122 case PhabricatorPolicyCapability::CAN_EDIT: 123 return $this->getEditPolicy(); 124 } 125 } 126 127 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 128 return ($viewer->getPHID() == $this->getOwnerPHID()); 129 } 130 131 public function describeAutomaticCapability($capability) { 132 return pht( 133 'The owner of an initiative can always view and edit it.'); 134 } 135 136 137 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 138 139 140 public function getApplicationTransactionEditor() { 141 return new FundInitiativeEditor(); 142 } 143 144 public function getApplicationTransactionObject() { 145 return $this; 146 } 147 148 public function getApplicationTransactionTemplate() { 149 return new FundInitiativeTransaction(); 150 } 151 152 153 /* -( PhabricatorSubscribableInterface )----------------------------------- */ 154 155 156 public function isAutomaticallySubscribed($phid) { 157 return ($phid == $this->getOwnerPHID()); 158 } 159 160 public function shouldShowSubscribersProperty() { 161 return true; 162 } 163 164 public function shouldAllowSubscription($phid) { 165 return true; 166 } 167 168 169 /* -( PhabricatorTokenRecevierInterface )---------------------------------- */ 170 171 172 public function getUsersToNotifyOfTokenGiven() { 173 return array( 174 $this->getOwnerPHID(), 175 ); 176 } 177 178 179 /* -( PhabricatorDestructibleInterface )----------------------------------- */ 180 181 182 public function destroyObjectPermanently( 183 PhabricatorDestructionEngine $engine) { 184 185 $this->openTransaction(); 186 $this->delete(); 187 $this->saveTransaction(); 188 } 189 190 }
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 |