| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup PaidLevels Paid Levels
- * @ingroup UnaModules
- *
- * @{
- */
- bx_import('BxDolAcl');
- define('BX_ACL_LICENSE_TYPE_SINGLE', 'single'); //--- one-time payment license
- define('BX_ACL_LICENSE_TYPE_RECURRING', 'recurring'); //--- recurring payment license
- class BxAclModule extends BxDolModule
- {
- /**
- * Constructor
- */
- function __construct($aModule)
- {
- parent::__construct($aModule);
- $this->_oConfig->init($this->_oDb);
- }
- /**
- * ACTION METHODS
- */
- /**
- * SERVICE METHODS
- */
- public function serviceGetBlockView()
- {
- $sGrid = $this->_oConfig->getGridObject('view');
- $oGrid = BxDolGrid::getObjectInstance($sGrid);
- if(!$oGrid)
- return '';
- return array(
- 'content' => $oGrid->getCode()
- );
- }
- public function serviceGetMembershipActions($iProfileId)
- {
- if($iProfileId != $this->getUserId())
- return '';
- return $this->_oTemplate->displayMembershipActions($iProfileId);
- }
- /**
- * Integration with Payment based modules.
- */
- public function serviceGetPaymentData()
- {
- return $this->_aModule;
- }
- public function serviceGetCartItem($iItemId)
- {
- $CNF = &$this->_oConfig->CNF;
- if(!$iItemId)
- return array();
- $aItem = $this->_oDb->getPrices(array('type' => 'by_id_full', 'value' => $iItemId));
- if(empty($aItem) || !is_array($aItem))
- return array();
- return array (
- 'id' => $aItem['id'],
- 'author_id' => $this->_oConfig->getOwner(),
- 'name' => $aItem['name'],
- 'title' => _t('_bx_acl_txt_cart_item_title', _t($aItem['level_name']), $aItem['period'], $aItem['period_unit']),
- 'description' => _t($aItem['level_description']),
- 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_VIEW']),
- 'price_single' => $aItem['price'],
- 'price_recurring' => $aItem['price'],
- );
- }
- public function serviceGetCartItems($iSellerId)
- {
- $CNF = &$this->_oConfig->CNF;
- $iSellerId = $this->_oConfig->getOwner();
- $aItems = $this->_oDb->getPrices(array('type' => 'all_full'));
- $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_VIEW']);
- $aResult = array();
- foreach($aItems as $aItem)
- $aResult[] = array(
- 'id' => $aItem['id'],
- 'author_id' => $iSellerId,
- 'name' => $aItem['name'],
- 'title' => _t('_bx_acl_txt_cart_item_title', _t($aItem['level_name']), $aItem['period'], $aItem['period_unit']),
- 'description' => _t($aItem['level_description']),
- 'url' => $sUrl,
- 'price_single' => $aItem['price'],
- 'price_recurring' => $aItem['price'],
- );
- return $aResult;
- }
- public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
- {
- return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_SINGLE);
- }
- public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
- {
- return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_RECURRING);
- }
- public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
- {
- return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_SINGLE);
- }
- public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
- {
- return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_RECURRING);
- }
- protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
- {
- $aItem = $this->serviceGetCartItem($iItemId);
- if(empty($aItem) || !is_array($aItem))
- return array();
- $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
- if(!BxDolAcl::getInstance()->setMembership($iClientId, $aItemInfo['level_id'], array('period' => $aItemInfo['period'], 'period_unit' => $aItemInfo['period_unit']), false, $sLicense))
- return array();
- return $aItem;
- }
- protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
- {
- $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
- if(empty($aItemInfo) || !is_array($aItemInfo))
- return false;
- return BxDolAcl::getInstance()->unsetMembership($iClientId, $aItemInfo['level_id'], $sLicense);
- }
- /**
- * COMMON METHODS
- */
- public function getUserId()
- {
- return isLogged() ? bx_get_logged_profile_id() : 0;
- }
- public function getUserInfo($iUserId = 0)
- {
- $oProfile = BxDolProfile::getInstance($iUserId);
- if (!$oProfile)
- $oProfile = BxDolProfileUndefined::getInstance();
- return array(
- $oProfile->getDisplayName(),
- $oProfile->getUrl(),
- $oProfile->getThumb(),
- $oProfile->getUnit()
- );
- }
- }
- /** @} */
|