BxBaseModPaymentGridOrders.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentGridOrders extends BxTemplGrid
  12. {
  13. protected $MODULE;
  14. protected $_oModule;
  15. protected $_sOrdersType;
  16. protected $_sJsObject;
  17. protected $_sLangsPrefix;
  18. protected $_sCurrencySign;
  19. public function __construct ($aOptions, $oTemplate = false)
  20. {
  21. parent::__construct ($aOptions, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  23. $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
  24. $this->_sCurrencySign = $this->_oModule->_oConfig->getDefaultCurrencySign();
  25. $this->_sDefaultSortingOrder = 'DESC';
  26. $iSellerId = bx_get('seller_id');
  27. if($iSellerId !== false)
  28. $this->_aQueryAppend['seller_id'] = (int)$iSellerId;
  29. $iClientId = bx_get('client_id');
  30. if($iClientId !== false)
  31. $this->_aQueryAppend['client_id'] = (int)$iClientId;
  32. }
  33. public function addQueryParam($sKey, $sValue)
  34. {
  35. if(empty($sKey) || !isset($sValue))
  36. return;
  37. $this->_aQueryAppend[$sKey] = $sValue;
  38. }
  39. public function performActionViewOrder()
  40. {
  41. $aIds = bx_get('ids');
  42. if(!$aIds || !is_array($aIds))
  43. return echoJson(array());
  44. $iId = (int)$aIds[0];
  45. $sKey = 'order_' . $this->_sOrdersType . '_view';
  46. $sId = $this->_oModule->_oConfig->getHtmlIds($this->_sOrdersType, $sKey);
  47. $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
  48. $sContent = $this->_oModule->getObjectOrders()->getOrder($this->_sOrdersType, $iId);
  49. return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)));
  50. }
  51. public function performActionCancel()
  52. {
  53. $aIds = bx_get('ids');
  54. if(!$aIds || !is_array($aIds))
  55. return echoJson(array());
  56. $oOrders = $this->_oModule->getObjectOrders();
  57. $iAffected = 0;
  58. $aAffected = array();
  59. foreach($aIds as $iId)
  60. if($oOrders->cancel($this->_sOrdersType, $iId)) {
  61. $aAffected[] = $iId;
  62. $iAffected++;
  63. }
  64. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aAffected) : array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
  65. }
  66. protected function _getCellClientId($mixedValue, $sKey, $aField, $aRow)
  67. {
  68. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  69. }
  70. protected function _getCellSellerId($mixedValue, $sKey, $aField, $aRow)
  71. {
  72. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  73. }
  74. protected function _getCellItem($mixedValue, $sKey, $aField, $aRow)
  75. {
  76. $sTxtUnknown = _t('_uknown');
  77. if(empty($aRow['module_id']) || empty($aRow['item_id']))
  78. return $sTxtUnknown;
  79. $aItemInfo = $this->_oModule->callGetCartItem((int)$aRow['module_id'], array((int)$aRow['item_id']));
  80. if(empty($aItemInfo) || !is_array($aItemInfo))
  81. return $sTxtUnknown;
  82. return parent::_getCellDefault($this->_oModule->_oTemplate->displayLink('link', array(
  83. 'href' => $aItemInfo['url'],
  84. 'title' => bx_html_attribute($aItemInfo['title']),
  85. 'content' => $aItemInfo['title']
  86. )), $sKey, $aField, $aRow);
  87. }
  88. protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
  89. {
  90. return parent::_getCellDefault($this->_sCurrencySign . $mixedValue, $sKey, $aField, $aRow);
  91. }
  92. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  93. {
  94. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  95. }
  96. protected function _getFilterSelectAll($sName, $aParams = array())
  97. {
  98. $sJsObject = !empty($aParams['js_object']) ? $aParams['js_object'] : $this->_sJsObject;
  99. $sJsOnChange = !empty($aParams['js_onchange']) ? $aParams['js_onchange'] : 'onChangeFilter(this)';
  100. $aAttrs = array(
  101. 'id' => 'bx-grid-' . $sName . '-' . $this->_sObject,
  102. 'onChange' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.' . $sJsOnChange,
  103. 'onBlur' => 'javascript:' . $sJsObject . '.' . $sJsOnChange,
  104. );
  105. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  106. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  107. $aInput = array(
  108. 'type' => 'select',
  109. 'name' => $sName,
  110. 'tr_attrs' => array(
  111. 'class' => 'bx-grid-filter-' . $sName,
  112. ),
  113. 'attrs' => $aAttrs,
  114. 'value' => !empty($aParams['value']) ? $aParams['value'] : '',
  115. 'values' => !empty($aParams['values']) && is_array($aParams['values']) ? $aParams['values'] : array()
  116. );
  117. $oForm = new BxTemplFormView(array());
  118. return $oForm->genRow($aInput);
  119. }
  120. protected function _getSearchInput()
  121. {
  122. $aInput = array(
  123. 'type' => 'text',
  124. 'name' => 'keyword',
  125. 'attrs' => array(
  126. 'id' => 'bx-grid-search-' . $this->_sObject,
  127. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->_sJsObject . '.onChangeFilter(this)',
  128. 'placeholder' => bx_html_attribute(_t('_sys_grid_search'))
  129. )
  130. );
  131. $oForm = new BxTemplStudioFormView(array());
  132. return $oForm->genRow($aInput);
  133. }
  134. }
  135. /** @} */