BxReputationAlertsResponse.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @defdroup Reputation Reputation
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxReputationAlertsResponse extends BxBaseModNotificationsResponse
  12. {
  13. public function __construct()
  14. {
  15. $this->_sModule = 'bx_reputation';
  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 $this->$sMethod($oAlert);
  24. /**
  25. * @hooks
  26. * @hookdef hook-bx_reputation-before_register_alert 'bx_reputation', 'before_register_alert' - hook to override alert (hook) before processing
  27. * - $unit_name - equals `bx_reputation`
  28. * - $action - equals `before_register_alert`
  29. * - $object_id - not used
  30. * - $sender_id - not used
  31. * - $extra_params - array of additional params with the following array keys:
  32. * - `unit` - [string] alert (hook) unit
  33. * - `action` - [string] alert (hook) action
  34. * - `alert` - [array] by ref, an instance of alert (hook), @see BxDolAlerts, can be overridden in hook processing
  35. * @hook @ref hook-bx_reputation-before_register_alert
  36. */
  37. bx_alert($this->_oModule->getName(), 'before_register_alert', 0, 0, [
  38. 'unit' => $oAlert->sUnit,
  39. 'action' => $oAlert->sAction,
  40. 'alert' => &$oAlert,
  41. ]);
  42. $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
  43. if(empty($aHandler) || !is_array($aHandler))
  44. return;
  45. $iOwnerId = $oAlert->iSender;
  46. $iObjectOwnerId = $this->_getObjectOwnerId($oAlert->aExtras);
  47. if(($iPoints = (int)$aHandler['points_active']) != 0)
  48. $this->_oModule->_oDb->insertProfile($iOwnerId, $iPoints);
  49. if(($iPoints = (int)$aHandler['points_passive']) != 0 && $iOwnerId != $iObjectOwnerId)
  50. $this->_oModule->_oDb->insertProfile($iObjectOwnerId, $iPoints);
  51. }
  52. protected function _processProfileDelete($oAlert)
  53. {
  54. $this->_oModule->_oDb->deleteProfile($oAlert->iObject);
  55. }
  56. }
  57. /** @} */