BxBaseModGroupsGridPricesView.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. require_once('BxBaseModGroupsGridPrices.php');
  12. class BxBaseModGroupsGridPricesView extends BxBaseModGroupsGridPrices
  13. {
  14. protected $_oPayment;
  15. protected $_bTypeSingle;
  16. protected $_bTypeRecurring;
  17. protected $_iSeller;
  18. protected $_iClient;
  19. protected $_iClientRole;
  20. public function __construct ($aOptions, $oTemplate = false)
  21. {
  22. parent::__construct ($aOptions, $oTemplate);
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. $this->_oPayment = BxDolPayments::getInstance();
  25. $this->_iSeller = $this->_aGroupContentInfo[$CNF['FIELD_AUTHOR']];
  26. $this->_iClient = bx_get_logged_profile_id();
  27. $this->_iClientRole = $this->_oModule->getRole($this->_iGroupProfileId, $this->_iClient);
  28. $this->_bTypeSingle = $this->_oPayment->isAcceptingPayments($this->_iSeller, BX_PAYMENT_TYPE_SINGLE);
  29. $this->_bTypeRecurring = $this->_oPayment->isAcceptingPayments($this->_iSeller, BX_PAYMENT_TYPE_RECURRING);
  30. }
  31. public function performActionChoose()
  32. {
  33. $CNF = &$this->_oModule->_oConfig->CNF;
  34. $aIds = $this->_getIds();
  35. if($aIds === false)
  36. return echoJson(array());
  37. $aItem = $this->_oModule->_oDb->getPrices(array('type' => 'by_id', 'value' => $aIds[0]));
  38. if(!is_array($aItem) || empty($aItem) || (float)$aItem['price'] != 0)
  39. return echoJson(array());
  40. $aResult = array();
  41. if($this->_oModule->setRole($this->_iGroupProfileId, $this->_iClient, $aItem['role_id'], array('period' => $aItem['period'], 'period_unit' => $aItem['period_unit'])))
  42. $aResult = array('grid' => $this->getCode(false), 'blink' => $aItem['id'], 'msg' => _t($CNF['T']['msg_performed']));
  43. else
  44. $aResult = array('msg' => _t($CNF['T']['err_cannot_perform']));
  45. return echoJson($aResult);
  46. }
  47. public function getCode($isDisplayHeader = true)
  48. {
  49. return $this->_oPayment->getCartJs() . parent::getCode($isDisplayHeader);
  50. }
  51. protected function _getCellRoleId($mixedValue, $sKey, $aField, $aRow)
  52. {
  53. return parent::_getCellDefault($this->_aRoles[$mixedValue], $sKey, $aField, $aRow);
  54. }
  55. protected function _getActionChoose ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  56. {
  57. if((float)$aRow['price'] != 0 || $this->_oModule->getRole($this->_iGroupProfileId, $this->_iClient) === (int)$aRow['role_id'])
  58. return '';
  59. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  60. }
  61. protected function _getActionBuy ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  62. {
  63. $CNF = &$this->_oModule->_oConfig->CNF;
  64. if((float)$aRow['price'] == 0 || !$this->_bTypeSingle || $this->_bTypeRecurring)
  65. return '';
  66. $aJs = $this->_oPayment->getAddToCartJs($this->_iSeller, $this->_sModule, $aRow['id'], 1, true);
  67. if(!empty($aJs) && is_array($aJs)) {
  68. list($sJsCode, $sJsMethod) = $aJs;
  69. $a['attr'] = array(
  70. 'title' => bx_html_attribute(_t($CNF['T']['txt_buy_title'])),
  71. 'onclick' => $sJsMethod
  72. );
  73. }
  74. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  75. }
  76. protected function _getActionSubscribe ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. if((float)$aRow['price'] == 0 || !$this->_bTypeRecurring)
  80. return '';
  81. $aJs = $this->_oPayment->getSubscribeJs($this->_iSeller, '', $this->_sModule, $aRow['id'], 1);
  82. if(!empty($aJs) && is_array($aJs)) {
  83. list($sJsCode, $sJsMethod) = $aJs;
  84. $a['attr'] = array(
  85. 'title' => bx_html_attribute(_t($CNF['T']['txt_subscribe_title'])),
  86. 'onclick' => $sJsMethod
  87. );
  88. }
  89. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  90. }
  91. }
  92. /** @} */