1
0

BxBaseModGroupsConfig.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = [
  21. 'join-group-profile' => 'checkAllowedFanAdd',
  22. 'profile-fans' => 'checkAllowedFans',
  23. 'profile-fan-add' => 'checkAllowedFanAdd',
  24. 'profile-fan-remove' => 'checkAllowedFanRemove',
  25. 'profile-subscriptions' => 'checkAllowedSubscriptions',
  26. 'profile-subscribe-add' => 'checkAllowedSubscribeAdd',
  27. 'profile-subscribe-remove' => 'checkAllowedSubscribeRemove',
  28. 'profile-actions-more' => 'checkAllowedViewMoreMenu',
  29. 'convos-compose' => 'checkAllowedCompose',
  30. ];
  31. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  32. $this->_aHtmlIds = [
  33. 'popup_price' => $sHtmlPrefix . '-popup-price',
  34. 'timeline_card_recommendations' => $sHtmlPrefix . '-recommendations'
  35. ];
  36. $this->_bUseCoverAsThumb = $this->_initUseCoverAsThumb();
  37. $oPayments = BxDolPayments::getInstance();
  38. $this->_aCurrency = [
  39. 'code' => $oPayments->getOption('default_currency_code'),
  40. 'sign' => $oPayments->getOption('default_currency_sign')
  41. ];
  42. }
  43. public function getHtmlIds($sKey = '')
  44. {
  45. if(empty($sKey))
  46. return $this->_aHtmlIds;
  47. return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
  48. }
  49. public function getCurrency($iAuthorId = 0)
  50. {
  51. if(!$iAuthorId)
  52. return $this->_aCurrency;
  53. $aCurrency = BxDolPayments::getInstance()->getCurrencyInfo($iAuthorId);
  54. return !empty($aCurrency) && is_array($aCurrency) ? $aCurrency : $this->_aCurrency;
  55. }
  56. public function isFans()
  57. {
  58. return true;
  59. }
  60. public function isAdmins()
  61. {
  62. return $this->isFans() && !empty($this->CNF['TABLE_ADMINS']);
  63. }
  64. public function isPaidJoin()
  65. {
  66. return isset($this->CNF['PARAM_PAID_JOIN_ENABLED']) && $this->CNF['PARAM_PAID_JOIN_ENABLED'] === true;
  67. }
  68. public function isInternalNotifications()
  69. {
  70. return !isset($this->CNF['PARAM_USE_IN']) || getParam($this->CNF['PARAM_USE_IN']) == 'on';
  71. }
  72. public function isUseCoverAsThumb()
  73. {
  74. return $this->_bUseCoverAsThumb;
  75. }
  76. public function getRolesPurchasable()
  77. {
  78. $aRoles = parent::getRoles();
  79. $aResult = [];
  80. foreach($aRoles as $iValue => $sTitle)
  81. if(!in_array($iValue, [BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR, BX_BASE_MOD_GROUPS_ROLE_MODERATOR]))
  82. $aResult[$iValue] = $sTitle;
  83. return $aResult;
  84. }
  85. public function getPriceName($sName)
  86. {
  87. return uriGenerate($sName, $this->CNF['TABLE_PRICES'], $this->CNF['FIELD_PRICE_NAME'], ['lowercase' => false]);
  88. }
  89. public function getPriceTitle($iAuthorId, $aPrice)
  90. {
  91. $aCurrency = $this->getCurrency($iAuthorId);
  92. $sPrice = _t_format_currency_ext($aPrice['price'], ['sign' => $aCurrency['sign']]);
  93. $sResult = '';
  94. if(!empty($aPrice['period']) && !empty($aPrice['period_unit'])) {
  95. $bPeriods = (int)$aPrice['period'] > 1;
  96. $sDuration = ($bPeriods ? $aPrice['period'] . ' ' : '') . _t('_duration_' . $aPrice['period_unit'] . ($bPeriods ? '_pl' : ''));
  97. $sResult = _t('_price_recurring', $sPrice, $sDuration);
  98. }
  99. else
  100. $sResult = _t('_price_single', $sPrice);
  101. return $sResult;
  102. }
  103. protected function _initUseCoverAsThumb()
  104. {
  105. if(($sKey = 'PARAM_USE_COVER_AS_THUMB') && !empty($this->CNF[$sKey]))
  106. return getParam($this->CNF[$sKey]) == 'on';
  107. if(($sParam = $this->_sName . '_use_cover_as_thumb') && ($mixedValue = getParam($sParam)) !== false)
  108. return $mixedValue == 'on';
  109. return true;
  110. }
  111. }
  112. /** @} */