BxBaseModPaymentGridOrders.php 7.8 KB

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