BxAdsGridOffers.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAdsGridOffers extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. $this->_sModule = 'bx_ads';
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. if(!$oTemplate)
  20. $oTemplate = $this->_oModule->_oTemplate;
  21. parent::__construct ($aOptions, $oTemplate);
  22. $this->_sDefaultSortingOrder = 'DESC';
  23. if(($iContentId = bx_get('content_id')) !== false)
  24. $this->setContentId($iContentId);
  25. }
  26. public function setContentId($iContentId)
  27. {
  28. $this->_aQueryAppend['content_id'] = (int)$iContentId;
  29. }
  30. public function performActionAccept()
  31. {
  32. $iId = $this->_getId();
  33. if($iId && ($mixedResult = $this->_oModule->offerAccept($iId)) === true)
  34. $aResult = ['grid' => $this->getCode(false), 'blick' => $iId];
  35. else
  36. $aResult = ['msg' => $mixedResult !== false ? $mixedResult : _t('_bx_ads_txt_err_cannot_perform_action')];
  37. echoJson($aResult);
  38. }
  39. public function performActionDecline()
  40. {
  41. $iId = $this->_getId();
  42. if($iId && $this->_oModule->offerDecline($iId))
  43. $aResult = ['grid' => $this->getCode(false), 'blick' => $iId];
  44. else
  45. $aResult = ['msg' => _t('_bx_ads_txt_err_cannot_perform_action')];
  46. echoJson($aResult);
  47. }
  48. protected function _getCellAuthorId($mixedValue, $sKey, $aField, $aRow)
  49. {
  50. return parent::_getCellDefault($this->_oModule->_oTemplate->getProfileLink($mixedValue), $sKey, $aField, $aRow);
  51. }
  52. protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $aContentInfo = $this->_oModule->_oDb->getContentInfoById((int)$aRow[$CNF['FIELD_OFR_CONTENT']]);
  56. return parent::_getCellDefault(_t_format_currency_ext($mixedValue, [
  57. 'sign' => BxDolPayments::getInstance()->getCurrencySign((int)$aContentInfo[$CNF['FIELD_AUTHOR']])
  58. ]), $sKey, $aField, $aRow);
  59. }
  60. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  61. {
  62. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  63. }
  64. protected function _getCellStatus($mixedValue, $sKey, $aField, $aRow)
  65. {
  66. return parent::_getCellDefault(_t('_bx_ads_txt_offer_status_' . $mixedValue), $sKey, $aField, $aRow);
  67. }
  68. protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  69. {
  70. $CNF = &$this->_oModule->_oConfig->CNF;
  71. if($aRow[$CNF['FIELD_OFR_STATUS']] != BX_ADS_OFFER_STATUS_AWAITING)
  72. return '';
  73. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  74. }
  75. protected function _getActionDecline ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  76. {
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. if($aRow[$CNF['FIELD_OFR_STATUS']] != BX_ADS_OFFER_STATUS_AWAITING)
  79. return '';
  80. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  81. }
  82. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  83. {
  84. if(empty($this->_aQueryAppend['content_id']))
  85. return array();
  86. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `content_id`=?", $this->_aQueryAppend['content_id']);
  87. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  88. }
  89. protected function _getId()
  90. {
  91. $aIds = bx_get('ids');
  92. if(!empty($aIds) && is_array($aIds))
  93. return array_shift($aIds);
  94. if(($iId = bx_get('id')) !== false)
  95. return (int)$iId;
  96. return false;
  97. }
  98. }
  99. /** @} */