BxPaymentGridSbsAdministration.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentGridSbsAdministration extends BxBaseModPaymentGridTransactions
  12. {
  13. protected $_iNow;
  14. protected $_sManageType;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. $this->MODULE = 'bx_payment';
  18. parent::__construct ($aOptions, $oTemplate);
  19. $this->_iNow = time();
  20. $this->_sOrdersType = BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION;
  21. $this->_sManageType = 'administration';
  22. }
  23. public function performActionCancel()
  24. {
  25. $aIds = bx_get('ids');
  26. if(!$aIds || !is_array($aIds))
  27. return echoJson(array());
  28. $oSubscriptions = $this->_oModule->getObjectSubscriptions();
  29. $iAffected = 0;
  30. $aAffected = array();
  31. foreach($aIds as $iId)
  32. if($oSubscriptions->cancel($iId)) {
  33. $aAffected[] = $iId;
  34. $iAffected++;
  35. }
  36. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aAffected) : array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
  37. }
  38. protected function _getCellProvider($mixedValue, $sKey, $aField, $aRow)
  39. {
  40. return parent::_getCellDefault(_t('_bx_payment_txt_name_' . $mixedValue), $sKey, $aField, $aRow);
  41. }
  42. protected function _getCellSubscriptionId($mixedValue, $sKey, $aField, $aRow)
  43. {
  44. $aItems = $this->_oModule->_oConfig->descriptorsM2A($aRow['items']);
  45. if(!is_array($aItems) || count($aItems) != 1)
  46. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  47. $aItem = array_shift($aItems);
  48. $aInfo = BxDolService::call((int)$aItem['module_id'], 'get_payment_data');
  49. if(!empty($aInfo['url_browse_order_' . $this->_sManageType]))
  50. $mixedValue = $this->_oModule->_oTemplate->displayLink('link', array(
  51. 'href' => bx_replace_markers($aInfo['url_browse_order_' . $this->_sManageType], array(
  52. 'order' => $mixedValue
  53. )),
  54. 'title' => bx_html_attribute($mixedValue),
  55. 'content' => $mixedValue
  56. ));
  57. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  58. }
  59. protected function _getCellDateAdd($mixedValue, $sKey, $aField, $aRow)
  60. {
  61. return $this->_getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow);
  62. }
  63. protected function _getCellDateNext($mixedValue, $sKey, $aField, $aRow)
  64. {
  65. if(empty($mixedValue))
  66. return parent::_getCellDefault(_t('_never'), $sKey, $aField, $aRow);
  67. else if(is_numeric($mixedValue) && (int)$mixedValue < $this->_iNow)
  68. return parent::_getCellDefault(_t('_uknown'), $sKey, $aField, $aRow);
  69. return $this->_getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow);
  70. }
  71. protected function _getCellStatus($mixedValue, $sKey, $aField, $aRow)
  72. {
  73. return parent::_getCellDefault(_t('_bx_payment_txt_status_' . $mixedValue), $sKey, $aField, $aRow);
  74. }
  75. protected function _addJsCss()
  76. {
  77. parent::_addJsCss();
  78. $this->_oTemplate->addJsTranslation(array(
  79. '_bx_payment_form_input_err',
  80. '_bx_payment_msg_confirm_cancelation',
  81. '_bx_payment_txt_unsubscribe_yes',
  82. '_bx_payment_txt_unsubscribe_no'
  83. ));
  84. }
  85. protected function _delete ($mixedId)
  86. {
  87. $aSubscription = $this->_oModule->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $mixedId));
  88. if(empty($aSubscription) || !is_array($aSubscription))
  89. return false;
  90. return $this->_oModule->_oDb->deleteSubscription($aSubscription['id'], 'delete');
  91. }
  92. }
  93. /** @} */