BxBaseModPaymentGridTransactions.php 8.5 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. $iId = 0;
  56. if(($aIds = bx_get('ids')) !== false && is_array($aIds))
  57. $iId = (int)$aIds[0];
  58. else if(($iId = bx_get('id')) !== false)
  59. $iId = (int)$iId;
  60. if(!$iId)
  61. return $this->_bIsApi ? [] : echoJson([]);
  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. return $this->_bIsApi ? [bx_api_get_block('simple_list', $sContent)] : echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)]);
  67. }
  68. protected function _getCellHeaderAuthorId ($sKey, $aField)
  69. {
  70. if(!$this->_bSingleSeller)
  71. return '';
  72. if($this->_aQueryAppend['seller_id'] != $this->_iSingleSeller)
  73. $aField['title'] = _t('_bx_payment_grid_column_title_ods_seller_id');
  74. return parent::_getCellHeaderDefault($sKey, $aField);
  75. }
  76. protected function _getCellClientId($mixedValue, $sKey, $aField, $aRow)
  77. {
  78. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  79. }
  80. protected function _getCellSellerId($mixedValue, $sKey, $aField, $aRow)
  81. {
  82. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  83. }
  84. protected function _getCellAuthorId($mixedValue, $sKey, $aField, $aRow)
  85. {
  86. if(!$this->_bSingleSeller)
  87. return '';
  88. if($this->_aQueryAppend['seller_id'] != $this->_iSingleSeller)
  89. $mixedValue = $aRow['seller_id'];
  90. $sResult = '';
  91. if(!empty($mixedValue) && is_numeric($mixedValue))
  92. $sResult = $this->_oModule->_oTemplate->displayProfileLink($mixedValue);
  93. return parent::_getCellDefault($sResult, $sKey, $aField, $aRow);
  94. }
  95. protected function _getCellItem($mixedValue, $sKey, $aField, $aRow)
  96. {
  97. $sTxtUnknown = _t('_uknown');
  98. if(empty($aRow['module_id']) || empty($aRow['item_id']))
  99. return parent::_getCellDefault($sTxtUnknown, $sKey, $aField, $aRow);
  100. $aItemInfo = $this->_oModule->callGetCartItem((int)$aRow['module_id'], array((int)$aRow['item_id'], isset($aRow['client_id']) ? (int)$aRow['client_id'] : 0));
  101. if(empty($aItemInfo) || !is_array($aItemInfo))
  102. return parent::_getCellDefault($sTxtUnknown, $sKey, $aField, $aRow);
  103. return parent::_getCellDefault($this->_oModule->_oTemplate->displayLink('link', array(
  104. 'href' => $aItemInfo['url'],
  105. 'title' => bx_html_attribute($aItemInfo['title']),
  106. 'content' => $aItemInfo['title']
  107. )), $sKey, $aField, $aRow);
  108. }
  109. protected function _getCellItems($mixedValue, $sKey, $aField, $aRow)
  110. {
  111. $aInfo = $this->_oModule->getObjectCart()->getInfo(BX_PAYMENT_TYPE_RECURRING, $aRow['client_id'], $aRow['seller_id'], $mixedValue);
  112. $mixedValue = [];
  113. if(($sK = 'items') && !empty($aInfo[$sK]) && is_array($aInfo[$sK]))
  114. foreach($aInfo[$sK] as $aItem)
  115. if($this->_bIsApi)
  116. $mixedValue[] = $aItem['title'];
  117. else
  118. $mixedValue[] = $this->_oTemplate->parseLink($aItem['url'], $aItem['title']);
  119. return parent::_getCellDefault(implode(', ', $mixedValue), $sKey, $aField, $aRow);
  120. }
  121. protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
  122. {
  123. if(bx_is_api()) {
  124. $sCode = '';
  125. if(empty($aRow['currency']))
  126. $sCode = !$this->_bSingleSeller ? $this->_oModule->getVendorCurrencyCode((int)$aRow['seller_id']) : $this->_sCurrencyCode;
  127. else
  128. $sCode = $aRow['currency'];
  129. return ['type' => 'text', 'value' => $mixedValue . ' ' . $sCode];
  130. }
  131. $sSign = '';
  132. if(!empty($aRow['currency']))
  133. $sSign = $this->_oModule->_oConfig->retrieveCurrencySign($aRow['currency']);
  134. else
  135. $sSign = !$this->_bSingleSeller ? $this->_oModule->getVendorCurrencySign((int)$aRow['seller_id']) : $this->_sCurrencySign;
  136. return parent::_getCellDefault(_t_format_currency_ext($mixedValue, ['sign' => $sSign]), $sKey, $aField, $aRow);
  137. }
  138. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  139. {
  140. return $this->_getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow);
  141. }
  142. protected function _getCellDefaultDate($mixedValue, $sKey, $aField, $aRow)
  143. {
  144. if(bx_is_api())
  145. return ['type' => 'time', 'data' => $mixedValue];
  146. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  147. }
  148. protected function _getCellDefaultDateTime($mixedValue, $sKey, $aField, $aRow)
  149. {
  150. if(bx_is_api())
  151. return ['type' => 'time', 'data' => $mixedValue];
  152. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE_TIME, true), $sKey, $aField, $aRow);
  153. }
  154. protected function _getFilterOnChange()
  155. {
  156. return $this->_sJsObject . '.onChangeFilter(this)';
  157. }
  158. protected function _getFilterSelectAll($sName, $aParams = array())
  159. {
  160. $sJsObject = !empty($aParams['js_object']) ? $aParams['js_object'] : $this->_sJsObject;
  161. $sJsOnChange = !empty($aParams['js_onchange']) ? $aParams['js_onchange'] : 'onChangeFilter(this)';
  162. $aAttrs = array(
  163. 'id' => 'bx-grid-' . $sName . '-' . $this->_sObject,
  164. 'onChange' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.' . $sJsOnChange,
  165. 'onBlur' => 'javascript:' . $sJsObject . '.' . $sJsOnChange,
  166. );
  167. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  168. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  169. $aInput = array(
  170. 'type' => 'select',
  171. 'name' => $sName,
  172. 'tr_attrs' => array(
  173. 'class' => 'bx-grid-filter-' . $sName,
  174. ),
  175. 'attrs' => $aAttrs,
  176. 'value' => !empty($aParams['value']) ? $aParams['value'] : '',
  177. 'values' => !empty($aParams['values']) && is_array($aParams['values']) ? $aParams['values'] : array()
  178. );
  179. $oForm = new BxTemplFormView(array());
  180. return $oForm->genRow($aInput);
  181. }
  182. }
  183. /** @} */