BxBaseModGroupsGridPrices.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsGridPrices extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sParamsDivider = '#-#';
  16. protected $_iGroupProfileId;
  17. protected $_iGroupContentId;
  18. protected $_aGroupContentInfo;
  19. protected $_aRoles;
  20. protected $_aPeriodUnits;
  21. public function __construct ($aOptions, $oTemplate = false)
  22. {
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. parent::__construct ($aOptions, $oTemplate);
  25. $CNF = $this->_oModule->_oConfig->CNF;
  26. $this->_aRoles = $this->_oModule->_oConfig->getRolesPurchasable();
  27. $this->_aPeriodUnits = BxDolForm::getDataItems($CNF['OBJECT_PRE_LIST_PERIOD_UNITS']);
  28. $this->_iGroupProfileId = 0;
  29. $this->_iGroupContentId = 0;
  30. $this->_aGroupContentInfo = array();
  31. if(($iGroupProfileId = bx_get('profile_id')) !== false)
  32. $this->setProfileId($iGroupProfileId);
  33. }
  34. public function setProfileId($iProfileId)
  35. {
  36. $this->_iGroupProfileId = (int)$iProfileId;
  37. $this->_aQueryAppend['profile_id'] = $this->_iGroupProfileId;
  38. $oGroupProfile = BxDolProfile::getInstance($this->_iGroupProfileId);
  39. if($oGroupProfile) {
  40. $this->_iGroupContentId = (int)$oGroupProfile->getContentId();
  41. $this->_aGroupContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iGroupContentId);
  42. }
  43. }
  44. protected function _getCellPeriod($mixedValue, $sKey, $aField, $aRow)
  45. {
  46. $CNF = $this->_oModule->_oConfig->CNF;
  47. if(!$this->_bIsApi) {
  48. if((int)$mixedValue == 0)
  49. $mixedValue = _t('_lifetime');
  50. else
  51. $mixedValue = _t($CNF['T']['txt_n_unit'], $mixedValue, _t($this->_aPeriodUnits[$aRow['period_unit']]));
  52. }
  53. else
  54. $mixedValue = ['type' => 'period', 'period' => $mixedValue, 'unit' => $aRow['period_unit']];
  55. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  56. }
  57. protected function _getCellPrice($mixedValue, $sKey, $aField, $aRow)
  58. {
  59. $CNF = $this->_oModule->_oConfig->CNF;
  60. $aCurrency = $this->_oModule->_oConfig->getCurrency($this->_aGroupContentInfo[$CNF['FIELD_AUTHOR']]);
  61. if(!$this->_bIsApi) {
  62. if((float)$mixedValue != 0)
  63. $mixedValue = html_entity_decode($aCurrency['sign']) . $mixedValue;
  64. else
  65. $mixedValue = _t('_free');
  66. }
  67. else
  68. $mixedValue = ['type' => 'price', 'value' => $mixedValue, 'currency' => $aCurrency['code']];
  69. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  70. }
  71. protected function _roleIdI2S($iValue)
  72. {
  73. return $this->_oModule->_oConfig->roleIdI2S($iValue);
  74. }
  75. protected function _roleIdS2I($sValue)
  76. {
  77. return $this->_oModule->_oConfig->roleIdS2I($sValue);
  78. }
  79. protected function _getIds()
  80. {
  81. $aIds = bx_get('ids');
  82. if(!$aIds || !is_array($aIds)) {
  83. $iId = (int)bx_get('id');
  84. if(!$iId)
  85. return false;
  86. $aIds = array($iId);
  87. }
  88. return $aIds;
  89. }
  90. }
  91. /** @} */