BxAdsMenuView.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /**
  12. * View entry menu
  13. */
  14. class BxAdsMenuView extends BxBaseModTextMenuView
  15. {
  16. /**
  17. * Array with check_sum => JS_code pairs of all JS codes
  18. * which should be added to the page.
  19. */
  20. protected $_aJsCodes;
  21. public function __construct($aObject, $oTemplate = false)
  22. {
  23. $this->MODULE = 'bx_ads';
  24. parent::__construct($aObject, $oTemplate);
  25. $this->_aJsCodes = array();
  26. $this->addMarkers(array(
  27. 'js_object' => $this->_oModule->_oConfig->getJsObject('entry')
  28. ));
  29. }
  30. public function getCode ()
  31. {
  32. return parent::getCode() . $this->getJsCode();
  33. }
  34. public function getJsCode()
  35. {
  36. if(empty($this->_aJsCodes) || !is_array($this->_aJsCodes))
  37. return '';
  38. return implode('', $this->_aJsCodes);
  39. }
  40. protected function _isVisible ($a)
  41. {
  42. $CNF = &$this->_oModule->_oConfig->CNF;
  43. if(!parent::_isVisible($a))
  44. return false;
  45. $oPayment = BxDolPayments::getInstance();
  46. $bResult = false;
  47. switch ($a['name']) {
  48. case 'add-to-cart':
  49. if((float)$this->_aContentInfo[$CNF['FIELD_PRICE']] == 0 || (int)$this->_aContentInfo[$CNF['FIELD_QUANTITY']] <= 0)
  50. break;
  51. $aJs = $oPayment->getAddToCartJs($this->_aContentInfo[$CNF['FIELD_AUTHOR']], $this->MODULE, $this->_aContentInfo[$CNF['FIELD_ID']], 1, true);
  52. if(empty($aJs) || !is_array($aJs))
  53. break;
  54. list($sJsCode, $sJsMethod) = $aJs;
  55. $sJsCodeCheckSum = md5($sJsCode);
  56. if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
  57. $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
  58. $aCurrency = $this->_oModule->_oConfig->getCurrency();
  59. $bResult = true;
  60. $this->addMarkers(array(
  61. 'add_to_cart_title' => _t('_bx_market_menu_item_title_add_to_cart', $aCurrency['sign'], $this->_aContentInfo[$CNF['FIELD_PRICE']]),
  62. 'add_to_cart_onclick' => $sJsMethod
  63. ));
  64. break;
  65. case 'interested':
  66. $bResult = $this->_aContentInfo[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id();
  67. break;
  68. case 'make-offer':
  69. $bResult = $this->_oModule->isAllowedMakeOffer($this->_aContentInfo);
  70. break;
  71. case 'view-offers':
  72. $bResult = $this->_oModule->isAllowedViewOffers($this->_aContentInfo);
  73. break;
  74. default:
  75. $bResult = true;
  76. }
  77. return $bResult;
  78. }
  79. }
  80. /** @} */