Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phortune / storage / PhortuneAccountEmail.php
blob50c8e900258ee8d3c00bb4991c36d0c2fd029d7a
1 <?php
3 final class PhortuneAccountEmail
4 extends PhortuneDAO
5 implements
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorPolicyInterface,
8 PhabricatorExtendedPolicyInterface {
10 protected $accountPHID;
11 protected $authorPHID;
12 protected $address;
13 protected $status;
14 protected $addressKey;
15 protected $accessKey;
17 private $account = self::ATTACHABLE;
19 protected function getConfiguration() {
20 return array(
21 self::CONFIG_AUX_PHID => true,
22 self::CONFIG_COLUMN_SCHEMA => array(
23 'address' => 'sort128',
24 'status' => 'text32',
25 'addressKey' => 'text32',
26 'accessKey' => 'text32',
28 self::CONFIG_KEY_SCHEMA => array(
29 'key_account' => array(
30 'columns' => array('accountPHID', 'address'),
31 'unique' => true,
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,
46 $author_phid) {
48 $address_key = Filesystem::readRandomCharacters(16);
49 $access_key = Filesystem::readRandomCharacters(16);
50 $default_status = PhortuneAccountEmailStatus::getDefaultStatusConstant();
52 return id(new self())
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;
63 return $this;
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() {
75 return urisprintf(
76 '/phortune/account/%d/addresses/%d/',
77 $this->getAccount()->getID(),
78 $this->getID());
81 public function getExternalURI() {
82 return urisprintf(
83 '/phortune/external/%s/%s/',
84 $this->getAddressKey(),
85 $this->getAccessKey());
88 public function getUnsubscribeURI() {
89 return urisprintf(
90 '/phortune/external/%s/%s/unsubscribe/',
91 $this->getAddressKey(),
92 $this->getAccessKey());
95 public function getExternalOrderURI(PhortuneCart $cart) {
96 return urisprintf(
97 '/phortune/external/%s/%s/order/%d/',
98 $this->getAddressKey(),
99 $this->getAccessKey(),
100 $cart->getID());
103 public function getExternalOrderPrintURI(PhortuneCart $cart) {
104 return urisprintf(
105 '/phortune/external/%s/%s/order/%d/print/',
106 $this->getAddressKey(),
107 $this->getAccessKey(),
108 $cart->getID());
112 /* -( PhabricatorPolicyInterface )----------------------------------------- */
115 public function getCapabilities() {
116 return array(
117 PhabricatorPolicyCapability::CAN_VIEW,
118 PhabricatorPolicyCapability::CAN_EDIT,
122 public function getPolicy($capability) {
123 return PhabricatorPolicies::getMostOpenPolicy();
126 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
127 return false;
131 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
134 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
135 return array(
136 array($this->getAccount(), $capability),
141 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
144 public function getApplicationTransactionEditor() {
145 return new PhortuneAccountEmailEditor();
148 public function getApplicationTransactionTemplate() {
149 return new PhortuneAccountEmailTransaction();