BxBaseModPaymentGridTransactions.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 BxBaseModPaymentGridTransactions extends BxTemplGrid
  12. {
  13. protected $MODULE;
  14. protected $_oModule;
  15. protected $_sOrdersType;
  16. protected $_bSingleSeller;
  17. protected $_iSingleSeller;
  18. protected $_sJsObject;
  19. protected $_sLangsPrefix;
  20. protected $_sCurrencySign;
  21. public function __construct ($aOptions, $oTemplate = false)
  22. {
  23. parent::__construct ($aOptions, $oTemplate);
  24. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  25. $this->_bSingleSeller = $this->_oModule->_oConfig->isSingleSeller();
  26. $this->_iSingleSeller = 0;
  27. if($this->_bSingleSeller)
  28. $this->_iSingleSeller = $this->_oModule->_oConfig->getSiteAdmin();
  29. $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
  30. $this->_sCurrencySign = $this->_oModule->_oConfig->getDefaultCurrencySign();
  31. $this->_sDefaultSortingOrder = 'DESC';
  32. $iSellerId = bx_get('seller_id');
  33. if($iSellerId !== false) {
  34. $iSellerId = (int)$iSellerId;
  35. $this->_aQueryAppend['seller_id'] = $iSellerId;
  36. if(!$this->_bSingleSeller)
  37. $this->_sCurrencySign = $this->_oModule->getVendorCurrencySign($iSellerId);
  38. }
  39. $iClientId = bx_get('client_id');
  40. if($iClientId !== false)
  41. $this->_aQueryAppend['client_id'] = (int)$iClientId;
  42. }
  43. public function addQueryParam($sKey, $sValue)
  44. {
  45. if(empty($sKey) || !isset($sValue))
  46. return;
  47. $this->_aQueryAppend[$sKey] = $sValue;
  48. }
  49. public function performActionViewOrder()
  50. {
  51. $aIds = bx_get('ids');
  52. if((!$aIds || !is_array($aIds)) && !bx_is_api())
  53. return echoJson(array());
  54. $iId = (int)$aIds[0];
  55. if (bx_is_api()){
  56. $iId = bx_get('id');
  57. }
  58. $sKey = 'order_' . $this->_sOrdersType . '_view';
  59. $sId = $this->_oModule->_oConfig->getHtmlIds($this->_sOrdersType, $sKey);
  60. $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
  61. $sContent = $this->_oModule->getObjectOrders()->getOrder($this->_sOrdersType, $iId);
  62. if (bx_is_api()){
  63. return [bx_api_get_block('simple_list', $sContent)];
  64. }
  65. return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)));
  66. }
  67. protected function _getCellHeaderAuthorId ($sKey, $aField)
  68. {
  69. if(!$this->_bSingleSeller)
  70. return '';
  71. if($this->_aQueryAppend['seller_id'] != $this->_iSingleSeller)
  72. $aField['title'] = _t('_bx_payment_grid_column_title_ods_seller_id');
  73. return parent::_getCellHeaderDefault($sKey, $aField);
  74. }
  75. protected function _getCellClientId($mixedValue, $sKey, $aField, $aRow)
  76. {
  77. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  78. }
  79. protected function _getCellSellerId($mixedValue, $sKey, $aField, $aRow)
  80. {
  81. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  82. }
  83. protected function _getCellAuthorId($mixedValue, $sKey, $aField, $aRow)
  84. {
  85. if(!$this->_bSingleSeller)
  86. return '';
  87. if($this->_aQueryAppend['seller_id'] != $this->_iSingleSeller)
  88. $mixedValue = $aRow['seller_id'];
  89. $sResult = '';
  90. if(!empty($mixedValue) && is_numeric($mixedValue))
  91. $sResult = $this->_oModule->_oTemplate->displayProfileLink($mixedValue);
  92. return parent::_getCellDefault($sResult, $sKey, $aField, $aRow);
  93. }
  94. protected function _getCellItem($mixedValue, $sKey, $aField, $aRow)
  95. {
  96. $sTxtUnknown = _t('_uknown');
  97. if(empty($aRow['module_id']) || empty($aRow['item_id']))
  98. return parent::_getCellDefault($sTxtUnknown, $sKey, $aField, $aRow);
  99. $aItemInfo = $this->_oModule->callGetCartItem((int)$aRow['module_id'], array((int)$aRow['item_id'], isset($aRow['client_id']) ? (int)$aRow['client_id'] : 0));
  100. if(empty($aItemInfo) || !is_array($aItemInfo))
  101. return parent::_getCellDefault($sTxtUnknown, $sKey, $aField, $aRow);
  102. return parent::_getCellDefault($this->_oModule->_oTemplate->displayLink('link', array(
  103. 'href' => $aItemInfo['url'],
  104. 'title' => bx_html_attribute($aItemInfo['title']),
  105. 'content' => $aItemInfo['title']
  106. )), $sKey, $aField, $aRow);
  107. }
  108. protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
  109. {
  110. $sSign = '';
  111. if(!empty($aRow['currency']))
  112. $sSign = $this->_oModule->_oConfig->retrieveCurrencySign($aRow['currency']);
  113. else
  114. $sSign = !$this->_bSingleSeller ? $this->_oModule->getVendorCurrencySign((int)$aRow['seller_id']) : $this->_sCurrencySign;
  115. return parent::_getCellDefault(_t_format_currency_ext($mixedValue, ['sign' => $sSign]), $sKey, $aField, $aRow);
  116. }
  117. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  118. {
  119. return $this->_getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow);
  120. }
  121. protected function _getCellDefaultDate($mixedValue, $sKey, $aField, $aRow)
  122. {
  123. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  124. }
  125. protected function _getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow)
  126. {
  127. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE_TIME, true), $sKey, $aField, $aRow);
  128. }
  129. protected function _getFilterSelectAll($sName, $aParams = array())
  130. {
  131. $sJsObject = !empty($aParams['js_object']) ? $aParams['js_object'] : $this->_sJsObject;
  132. $sJsOnChange = !empty($aParams['js_onchange']) ? $aParams['js_onchange'] : 'onChangeFilter(this)';
  133. $aAttrs = array(
  134. 'id' => 'bx-grid-' . $sName . '-' . $this->_sObject,
  135. 'onChange' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.' . $sJsOnChange,
  136. 'onBlur' => 'javascript:' . $sJsObject . '.' . $sJsOnChange,
  137. );
  138. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  139. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  140. $aInput = array(
  141. 'type' => 'select',
  142. 'name' => $sName,
  143. 'tr_attrs' => array(
  144. 'class' => 'bx-grid-filter-' . $sName,
  145. ),
  146. 'attrs' => $aAttrs,
  147. 'value' => !empty($aParams['value']) ? $aParams['value'] : '',
  148. 'values' => !empty($aParams['values']) && is_array($aParams['values']) ? $aParams['values'] : array()
  149. );
  150. $oForm = new BxTemplFormView(array());
  151. return $oForm->genRow($aInput);
  152. }
  153. protected function _getSearchInput()
  154. {
  155. $aInput = array(
  156. 'type' => 'text',
  157. 'name' => 'keyword',
  158. 'attrs' => array(
  159. 'id' => 'bx-grid-search-' . $this->_sObject,
  160. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->_sJsObject . '.onChangeFilter(this)',
  161. 'placeholder' => bx_html_attribute(_t('_sys_grid_search'))
  162. )
  163. );
  164. $oForm = new BxTemplFormView(array());
  165. return $oForm->genRow($aInput);
  166. }
  167. }
  168. /** @} */