BxTimelineResponse.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineResponse extends BxBaseModNotificationsResponse
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  17. }
  18. /**
  19. * Overwtire the method of parent class.
  20. *
  21. * @param BxDolAlerts $oAlert an instance of alert.
  22. */
  23. public function response($oAlert)
  24. {
  25. $iObjectPrivacyView = $this->_getObjectPrivacyView($oAlert->aExtras);
  26. if($iObjectPrivacyView == BX_DOL_PG_HIDDEN)
  27. return;
  28. $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
  29. switch($aHandler['type']) {
  30. case BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT:
  31. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  32. $iId = $this->_oModule->_oDb->insertEvent(array(
  33. 'owner_id' => $oAlert->iSender,
  34. 'type' => $oAlert->sUnit,
  35. 'action' => $oAlert->sAction,
  36. 'object_id' => $oAlert->iObject,
  37. 'object_privacy_view' => $iObjectPrivacyView,
  38. 'content' => $sContent,
  39. 'title' => '',
  40. 'description' => ''
  41. ));
  42. if(!empty($iId))
  43. $this->_oModule->onPost($iId);
  44. //TODO: Remove the call and the function itself if GROUPING feature won't be used.
  45. $this->_oModule->_oDb->updateSimilarObject($iId, $oAlert);
  46. break;
  47. case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
  48. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  49. $this->_oModule->_oDb->updateEvent(array('object_privacy_view' => $iObjectPrivacyView, 'content' => $sContent), array('type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
  50. break;
  51. case BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE:
  52. if($oAlert->sUnit == 'profile' && $oAlert->sAction == 'delete') {
  53. $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'owner_id', 'value' => $oAlert->iObject));
  54. foreach($aEvents as $aEvent)
  55. $this->_oModule->deleteEvent($aEvent);
  56. if(isset($oAlert->aExtras['delete_with_content']) && $oAlert->aExtras['delete_with_content']) {
  57. $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'common_by_object', 'value' => $oAlert->iObject));
  58. foreach($aEvents as $aEvent)
  59. $this->_oModule->deleteEvent($aEvent);
  60. }
  61. break;
  62. }
  63. $aHandlers = $this->_oModule->_oDb->getHandlers(array('type' => 'by_group_key_type', 'group' => $aHandler['group']));
  64. $aEvent = $this->_oModule->_oDb->getEvents(array(
  65. 'browse' => 'descriptor',
  66. 'type' => $oAlert->sUnit,
  67. 'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
  68. 'object_id' => $oAlert->iObject
  69. ));
  70. $this->_oModule->deleteEvent($aEvent);
  71. break;
  72. }
  73. }
  74. }
  75. /** @} */