BxBaseModGroupsConfig.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Groups Groups
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolInformer');
  12. class BxBaseModGroupsConfig extends BxBaseModProfileConfig
  13. {
  14. protected $_aHtmlIds;
  15. protected $_bUseCoverAsThumb;
  16. protected $_aCurrency;
  17. function __construct($aModule)
  18. {
  19. parent::__construct($aModule);
  20. $this->_aMenuItems2MethodsActions = array (
  21. 'join-group-profile' => 'checkAllowedFanAdd',
  22. 'profile-fan-add' => 'checkAllowedFanAdd',
  23. 'profile-fan-remove' => 'checkAllowedFanRemove',
  24. 'profile-subscribe-add' => 'checkAllowedSubscribeAdd',
  25. 'profile-subscribe-remove' => 'checkAllowedSubscribeRemove',
  26. 'profile-actions-more' => 'checkAllowedViewMoreMenu',
  27. 'convos-compose' => 'checkAllowedCompose',
  28. );
  29. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  30. $this->_aHtmlIds = array(
  31. 'popup_price' => $sHtmlPrefix . '-popup-price'
  32. );
  33. $this->_bUseCoverAsThumb = $this->_initUseCoverAsThumb();
  34. $oPayments = BxDolPayments::getInstance();
  35. $this->_aCurrency = array(
  36. 'code' => $oPayments->getOption('default_currency_code'),
  37. 'sign' => $oPayments->getOption('default_currency_sign')
  38. );
  39. }
  40. public function getHtmlIds($sKey = '')
  41. {
  42. if(empty($sKey))
  43. return $this->_aHtmlIds;
  44. return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
  45. }
  46. public function getCurrency($iAuthorId = 0)
  47. {
  48. if(!$iAuthorId)
  49. return $this->_aCurrency;
  50. $aCurrency = BxDolPayments::getInstance()->getCurrencyInfo($iAuthorId);
  51. return !empty($aCurrency) && is_array($aCurrency) ? $aCurrency : $this->_aCurrency;
  52. }
  53. public function isFans()
  54. {
  55. return true;
  56. }
  57. public function isAdmins()
  58. {
  59. return $this->isFans() && !empty($this->CNF['TABLE_ADMINS']);
  60. }
  61. public function isPaidJoin()
  62. {
  63. return isset($this->CNF['PARAM_PAID_JOIN_ENABLED']) && $this->CNF['PARAM_PAID_JOIN_ENABLED'] === true;
  64. }
  65. public function isInternalNotifications()
  66. {
  67. return !isset($this->CNF['PARAM_USE_IN']) || getParam($this->CNF['PARAM_USE_IN']) == 'on';
  68. }
  69. public function isUseCoverAsThumb()
  70. {
  71. return $this->_bUseCoverAsThumb;
  72. }
  73. public function getRolesPurchasable()
  74. {
  75. $aRoles = parent::getRoles();
  76. $aResult = [];
  77. foreach($aRoles as $iValue => $sTitle)
  78. if(!in_array($iValue, [BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR, BX_BASE_MOD_GROUPS_ROLE_MODERATOR]))
  79. $aResult[$iValue] = $sTitle;
  80. return $aResult;
  81. }
  82. public function getPriceName($sName)
  83. {
  84. return uriGenerate($sName, $this->CNF['TABLE_PRICES'], $this->CNF['FIELD_PRICE_NAME'], ['lowercase' => false]);
  85. }
  86. public function getPriceTitle($iAuthorId, $aPrice)
  87. {
  88. $aCurrency = $this->getCurrency($iAuthorId);
  89. $sPrice = _t_format_currency_ext($aPrice['price'], ['sign' => $aCurrency['sign']]);
  90. $sResult = '';
  91. if(!empty($aPrice['period']) && !empty($aPrice['period_unit'])) {
  92. $bPeriods = (int)$aPrice['period'] > 1;
  93. $sDuration = ($bPeriods ? $aPrice['period'] . ' ' : '') . _t('_duration_' . $aPrice['period_unit'] . ($bPeriods ? '_pl' : ''));
  94. $sResult = _t('_price_recurring', $sPrice, $sDuration);
  95. }
  96. else
  97. $sResult = _t('_price_single', $sPrice);
  98. return $sResult;
  99. }
  100. protected function _initUseCoverAsThumb()
  101. {
  102. if(($sKey = 'PARAM_USE_COVER_AS_THUMB') && !empty($this->CNF[$sKey]))
  103. return getParam($this->CNF[$sKey]) == 'on';
  104. if(($sParam = $this->_sName . '_use_cover_as_thumb') && ($mixedValue = getParam($sParam)) !== false)
  105. return $mixedValue == 'on';
  106. return true;
  107. }
  108. }
  109. /** @} */