BxAclGridView.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 PaidLevels Paid Levels
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once('BxAclGridLevels.php');
  12. class BxAclGridView extends BxAclGridLevels
  13. {
  14. protected $_iOwner;
  15. protected $_oPayment;
  16. protected $_bTypeSingle;
  17. protected $_bTypeRecurring;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. parent::__construct ($aOptions, $oTemplate);
  21. $this->_iOwner = $this->_oModule->_oConfig->getOwner();
  22. $this->_oPayment = BxDolPayments::getInstance();
  23. $this->_bTypeSingle = $this->_oPayment->isAcceptingPayments($this->_iOwner, BX_PAYMENT_TYPE_SINGLE);
  24. $this->_bTypeRecurring = $this->_oPayment->isAcceptingPayments($this->_iOwner, BX_PAYMENT_TYPE_RECURRING);
  25. }
  26. public function performActionChoose()
  27. {
  28. $CNF = &$this->_oModule->_oConfig->CNF;
  29. $aIds = $this->_getIds();
  30. if($aIds === false)
  31. return echoJson(array());
  32. $aItem = $this->_oModule->_oDb->getPrices(array('type' => 'by_id', 'value' => $aIds[0]));
  33. if(!is_array($aItem) || empty($aItem) || (float)$aItem['price'] != 0)
  34. return echoJson(array());
  35. $aResult = array();
  36. $iUserId = bx_get_logged_profile_id();
  37. if(BxDolAcl::getInstance()->setMembership($iUserId, $aItem['level_id'], array('period' => $aItem['period'], 'period_unit' => $aItem['period_unit']), true))
  38. $aResult = array('grid' => $this->getCode(false), 'blink' => $aItem['id'], 'msg' => _t('_bx_acl_msg_performed'));
  39. else
  40. $aResult = array('msg' => _t('_bx_acl_err_cannot_perform'));
  41. return echoJson($aResult);
  42. }
  43. public function getCode($isDisplayHeader = true)
  44. {
  45. return $this->_oPayment->getCartJs() . parent::getCode($isDisplayHeader);
  46. }
  47. protected function _getCellLevelIcon($mixedValue, $sKey, $aField, $aRow)
  48. {
  49. $mixedValue = $this->_oModule->_oTemplate->displayLevelIcon($mixedValue);
  50. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  51. }
  52. protected function _getActionChoose ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  53. {
  54. if((float)$aRow['price'] != 0 || BxDolAcl::getInstance()->isMemberLevelInSet(array($aRow['level_id'])))
  55. return '';
  56. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  57. }
  58. protected function _getActionBuy ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  59. {
  60. if((float)$aRow['price'] == 0 || !$this->_bTypeSingle || $this->_bTypeRecurring)
  61. return '';
  62. $aJs = $this->_oPayment->getAddToCartJs($this->_iOwner, $this->MODULE, $aRow['id'], 1, true);
  63. if(!empty($aJs) && is_array($aJs)) {
  64. list($sJsCode, $sJsMethod) = $aJs;
  65. $a['attr'] = array(
  66. 'title' => bx_html_attribute(_t('_bx_acl_grid_action_buy_title')),
  67. 'onclick' => $sJsMethod
  68. );
  69. }
  70. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  71. }
  72. protected function _getActionSubscribe ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  73. {
  74. if((float)$aRow['price'] == 0 || !$this->_bTypeRecurring)
  75. return '';
  76. $aJs = $this->_oPayment->getSubscribeJs($this->_iOwner, '', $this->MODULE, $aRow['id'], 1);
  77. if(!empty($aJs) && is_array($aJs)) {
  78. list($sJsCode, $sJsMethod) = $aJs;
  79. $a['attr'] = array(
  80. 'title' => bx_html_attribute(_t('_bx_acl_grid_action_subscribe_title')),
  81. 'onclick' => $sJsMethod
  82. );
  83. }
  84. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  85. }
  86. }
  87. /** @} */