BxBaseModPaymentGridTransactions.php 8.2 KB

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