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