Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / phortune / storage / PhortuneProduct.php
blob18fc553e8745cfb044f856f5835c34da8a981868
1 <?php
3 /**
4 * A product is something users can purchase.
5 */
6 final class PhortuneProduct extends PhortuneDAO
7 implements PhabricatorPolicyInterface {
9 protected $productClassKey;
10 protected $productClass;
11 protected $productRefKey;
12 protected $productRef;
13 protected $metadata = array();
15 private $implementation = self::ATTACHABLE;
17 protected function getConfiguration() {
18 return array(
19 self::CONFIG_AUX_PHID => true,
20 self::CONFIG_SERIALIZATION => array(
21 'metadata' => self::SERIALIZATION_JSON,
23 self::CONFIG_COLUMN_SCHEMA => array(
24 'productClassKey' => 'bytes12',
25 'productClass' => 'text128',
26 'productRefKey' => 'bytes12',
27 'productRef' => 'text128',
29 self::CONFIG_KEY_SCHEMA => array(
30 'key_product' => array(
31 'columns' => array('productClassKey', 'productRefKey'),
32 'unique' => true,
35 ) + parent::getConfiguration();
38 public function generatePHID() {
39 return PhabricatorPHID::generateNewPHID(
40 PhortuneProductPHIDType::TYPECONST);
43 public static function initializeNewProduct() {
44 return id(new PhortuneProduct());
47 public function attachImplementation(PhortuneProductImplementation $impl) {
48 $this->implementation = $impl;
51 public function getImplementation() {
52 return $this->assertAttached($this->implementation);
55 public function save() {
56 $this->productClassKey = PhabricatorHash::digestForIndex(
57 $this->productClass);
59 $this->productRefKey = PhabricatorHash::digestForIndex(
60 $this->productRef);
62 return parent::save();
65 public function getPriceAsCurrency() {
66 return $this->getImplementation()->getPriceAsCurrency($this);
69 public function getProductName() {
70 return $this->getImplementation()->getName($this);
73 public function getPurchaseName(PhortunePurchase $purchase) {
74 return $this->getImplementation()->getPurchaseName($this, $purchase);
77 public function didPurchaseProduct(PhortunePurchase $purchase) {
78 return $this->getImplementation()->didPurchaseProduct($this, $purchase);
81 public function didRefundProduct(
82 PhortunePurchase $purchase,
83 PhortuneCurrency $amount) {
84 return $this->getImplementation()->didRefundProduct(
85 $this,
86 $purchase,
87 $amount);
90 public function getPurchaseURI(PhortunePurchase $purchase) {
91 return $this->getImplementation()->getPurchaseURI(
92 $this,
93 $purchase);
96 /* -( PhabricatorPolicyInterface )----------------------------------------- */
99 public function getCapabilities() {
100 return array(
101 PhabricatorPolicyCapability::CAN_VIEW,
105 public function getPolicy($capability) {
106 return PhabricatorPolicies::POLICY_USER;
109 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
110 return false;