[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/storage/ -> PhortuneProduct.php (source)

   1  <?php
   2  
   3  /**
   4   * A product is something users can purchase.
   5   */
   6  final class PhortuneProduct extends PhortuneDAO
   7    implements PhabricatorPolicyInterface {
   8  
   9    protected $productClassKey;
  10    protected $productClass;
  11    protected $productRefKey;
  12    protected $productRef;
  13    protected $metadata = array();
  14  
  15    private $implementation = self::ATTACHABLE;
  16  
  17    public function getConfiguration() {
  18      return array(
  19        self::CONFIG_AUX_PHID => true,
  20        self::CONFIG_SERIALIZATION => array(
  21          'metadata' => self::SERIALIZATION_JSON,
  22        ),
  23        self::CONFIG_COLUMN_SCHEMA => array(
  24          'productClassKey' => 'bytes12',
  25          'productClass' => 'text128',
  26          'productRefKey' => 'bytes12',
  27          'productRef' => 'text128',
  28        ),
  29        self::CONFIG_KEY_SCHEMA => array(
  30          'key_product' => array(
  31            'columns' => array('productClassKey', 'productRefKey'),
  32            'unique' => true,
  33          ),
  34        ),
  35      ) + parent::getConfiguration();
  36    }
  37  
  38    public function generatePHID() {
  39      return PhabricatorPHID::generateNewPHID(
  40        PhortuneProductPHIDType::TYPECONST);
  41    }
  42  
  43    public static function initializeNewProduct() {
  44      return id(new PhortuneProduct());
  45    }
  46  
  47    public function attachImplementation(PhortuneProductImplementation $impl) {
  48      $this->implementation = $impl;
  49    }
  50  
  51    public function getImplementation() {
  52      return $this->assertAttached($this->implementation);
  53    }
  54  
  55    public function save() {
  56      $this->productClassKey = PhabricatorHash::digestForIndex(
  57        $this->productClass);
  58  
  59      $this->productRefKey = PhabricatorHash::digestForIndex(
  60        $this->productRef);
  61  
  62      return parent::save();
  63    }
  64  
  65    public function getPriceAsCurrency() {
  66      return $this->getImplementation()->getPriceAsCurrency($this);
  67    }
  68  
  69    public function getProductName() {
  70      return $this->getImplementation()->getName($this);
  71    }
  72  
  73    public function getPurchaseName(PhortunePurchase $purchase) {
  74      return $this->getImplementation()->getPurchaseName($this, $purchase);
  75    }
  76  
  77    public function didPurchaseProduct(PhortunePurchase $purchase) {
  78      return $this->getImplementation()->didPurchaseProduct($this, $purchase);
  79    }
  80  
  81    public function didRefundProduct(
  82      PhortunePurchase $purchase,
  83      PhortuneCurrency $amount) {
  84      return $this->getImplementation()->didRefundProduct(
  85        $this,
  86        $purchase,
  87        $amount);
  88    }
  89  
  90  
  91  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  92  
  93  
  94    public function getCapabilities() {
  95      return array(
  96        PhabricatorPolicyCapability::CAN_VIEW,
  97      );
  98    }
  99  
 100    public function getPolicy($capability) {
 101      return PhabricatorPolicies::POLICY_USER;
 102    }
 103  
 104    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 105      return false;
 106    }
 107  
 108    public function describeAutomaticCapability($capability) {
 109      return null;
 110    }
 111  
 112  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1