3 final class PhortuneAccountEmail
6 PhabricatorApplicationTransactionInterface
,
7 PhabricatorPolicyInterface
,
8 PhabricatorExtendedPolicyInterface
{
10 protected $accountPHID;
11 protected $authorPHID;
14 protected $addressKey;
17 private $account = self
::ATTACHABLE
;
19 protected function getConfiguration() {
21 self
::CONFIG_AUX_PHID
=> true,
22 self
::CONFIG_COLUMN_SCHEMA
=> array(
23 'address' => 'sort128',
25 'addressKey' => 'text32',
26 'accessKey' => 'text32',
28 self
::CONFIG_KEY_SCHEMA
=> array(
29 'key_account' => array(
30 'columns' => array('accountPHID', 'address'),
33 'key_address' => array(
34 'columns' => array('addressKey'),
37 ) + parent
::getConfiguration();
40 public function getPHIDType() {
41 return PhortuneAccountEmailPHIDType
::TYPECONST
;
44 public static function initializeNewAddress(
45 PhortuneAccount
$account,
48 $address_key = Filesystem
::readRandomCharacters(16);
49 $access_key = Filesystem
::readRandomCharacters(16);
50 $default_status = PhortuneAccountEmailStatus
::getDefaultStatusConstant();
53 ->setAuthorPHID($author_phid)
54 ->setAccountPHID($account->getPHID())
55 ->setStatus($default_status)
56 ->attachAccount($account)
57 ->setAddressKey($address_key)
58 ->setAccessKey($access_key);
61 public function attachAccount(PhortuneAccount
$account) {
62 $this->account
= $account;
66 public function getAccount() {
67 return $this->assertAttached($this->account
);
70 public function getObjectName() {
71 return pht('Account Email %d', $this->getID());
74 public function getURI() {
76 '/phortune/account/%d/addresses/%d/',
77 $this->getAccount()->getID(),
81 public function getExternalURI() {
83 '/phortune/external/%s/%s/',
84 $this->getAddressKey(),
85 $this->getAccessKey());
88 public function getUnsubscribeURI() {
90 '/phortune/external/%s/%s/unsubscribe/',
91 $this->getAddressKey(),
92 $this->getAccessKey());
95 public function getExternalOrderURI(PhortuneCart
$cart) {
97 '/phortune/external/%s/%s/order/%d/',
98 $this->getAddressKey(),
99 $this->getAccessKey(),
103 public function getExternalOrderPrintURI(PhortuneCart
$cart) {
105 '/phortune/external/%s/%s/order/%d/print/',
106 $this->getAddressKey(),
107 $this->getAccessKey(),
112 /* -( PhabricatorPolicyInterface )----------------------------------------- */
115 public function getCapabilities() {
117 PhabricatorPolicyCapability
::CAN_VIEW
,
118 PhabricatorPolicyCapability
::CAN_EDIT
,
122 public function getPolicy($capability) {
123 return PhabricatorPolicies
::getMostOpenPolicy();
126 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
131 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
134 public function getExtendedPolicy($capability, PhabricatorUser
$viewer) {
136 array($this->getAccount(), $capability),
141 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
144 public function getApplicationTransactionEditor() {
145 return new PhortuneAccountEmailEditor();
148 public function getApplicationTransactionTemplate() {
149 return new PhortuneAccountEmailTransaction();