BxAdsAlertsResponse.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 BxAdsAlertsResponse extends BxBaseModTextAlertsResponse
  12. {
  13. public function __construct()
  14. {
  15. $this->MODULE = 'bx_ads';
  16. parent::__construct();
  17. }
  18. public function response($oAlert)
  19. {
  20. parent::response($oAlert);
  21. $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
  22. if(!method_exists($this, $sMethod))
  23. return;
  24. $this->$sMethod($oAlert);
  25. }
  26. protected function _processProfileApprove($oAlert)
  27. {
  28. $this->_processProfileChangeStatus($oAlert);
  29. }
  30. protected function _processProfileActivate($oAlert)
  31. {
  32. $this->_processProfileChangeStatus($oAlert);
  33. }
  34. protected function _processProfileDisapprove($oAlert)
  35. {
  36. $this->_processProfileChangeStatus($oAlert);
  37. }
  38. protected function _processProfileSuspend($oAlert)
  39. {
  40. $this->_processProfileChangeStatus($oAlert);
  41. }
  42. protected function _processProfileChangeStatus($oAlert)
  43. {
  44. $CNF = &$this->_oModule->_oConfig->CNF;
  45. $aEntries = $this->_oModule->_oDb->getEntriesBy([
  46. 'type' => 'author',
  47. 'author' => $oAlert->iObject
  48. ]);
  49. $aCategories = [];
  50. foreach($aEntries as $aEntry) {
  51. if($aEntry[$CNF['FIELD_STATUS']] != 'active' || $aEntry[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  52. continue;
  53. if(in_array($aEntry[$CNF['FIELD_CATEGORY']], $aCategories))
  54. continue;
  55. $aCategories[] = $aEntry[$CNF['FIELD_CATEGORY']];
  56. }
  57. if(!empty($aCategories))
  58. foreach($aCategories as $iCategoryId)
  59. $this->_oModule->serviceUpdateCategoriesStatsByCategory($iCategoryId);
  60. }
  61. protected function _processBxTimelineGetView($oAlert)
  62. {
  63. if(!$this->_oModule->_oConfig->isPromotion())
  64. return;
  65. $bDynamicMode = isset($oAlert->aExtras['params']['dynamic_mode']) && (bool)$oAlert->aExtras['params']['dynamic_mode'] === true;
  66. $sJs = $this->_oModule->_oTemplate->addJs(['main.js'], $bDynamicMode);
  67. $oAlert->aExtras['content_before'] .= ($bDynamicMode ? $sJs : '') . $this->_oModule->_oTemplate->getJsCode('main');
  68. }
  69. protected function _processBxTimelineGetExternalPost($oAlert)
  70. {
  71. if(!$this->_oModule->_oConfig->isPromotion())
  72. return;
  73. $aSegViewer = [];
  74. if(!empty($oAlert->aExtras['params']['viewer_id']) && ($oViewer = BxDolProfile::getInstance($oAlert->aExtras['params']['viewer_id'])) !== false && ($sViewerModule = $oViewer->getModule()) == 'bx_persons') {
  75. $aViewerInfo = bx_srv($sViewerModule, 'get_info', [$oViewer->getContentId(), false]);
  76. if(!empty($aViewerInfo) && is_array($aViewerInfo)) {
  77. if(!empty($aViewerInfo['gender']))
  78. $aSegViewer['gender'] = $aViewerInfo['gender'];
  79. if(!empty($aViewerInfo['birthday']))
  80. $aSegViewer['age'] = bx_birthday2age($aViewerInfo['birthday']);
  81. if(!empty($aViewerInfo['location'])) {
  82. $aLocation = unserialize($aViewerInfo['location']);
  83. if(!empty($aLocation['country']))
  84. $aSegViewer['country'] = $aLocation['country'];
  85. }
  86. if(!empty($aViewerInfo['tags']))
  87. $aSegViewer['tags'] = explode(',', $aViewerInfo['tags']);
  88. }
  89. }
  90. $aEntries = $this->_oModule->_oDb->getEntriesBy(['type' => 'promotion', 'seg_viewer' => $aSegViewer]);
  91. if(empty($aEntries) || !is_array($aEntries))
  92. return;
  93. $iId = $this->_oModule->_oConfig->getRandomWeightedItem($aEntries);
  94. $sModule = 'bx_timeline';
  95. $aEvent = bx_srv($sModule, 'get_events_by_descriptor', [$this->MODULE, 'added', $iId]);
  96. if(empty($aEvent) || !is_array($aEvent))
  97. return;
  98. $mixedEvent = bx_srv($sModule, 'get_post', [$aEvent, $oAlert->aExtras['params']]);
  99. if(empty($mixedEvent))
  100. return;
  101. $oAlert->aExtras['override_result'] = $mixedEvent;
  102. }
  103. }
  104. /** @} */