BxTimelineResponse.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModNotificationsResponse');
  12. class BxTimelineResponse extends BxBaseModNotificationsResponse
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. bx_import('BxDolModule');
  18. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  19. }
  20. /**
  21. * Overwtire the method of parent class.
  22. *
  23. * @param BxDolAlerts $oAlert an instance of alert.
  24. */
  25. public function response($oAlert)
  26. {
  27. if(is_array($oAlert->aExtras) && isset($oAlert->aExtras['from_wall']) && (int)$oAlert->aExtras['from_wall'] == 1)
  28. $this->_responseInner($oAlert);
  29. else
  30. $this->_responseOuter($oAlert);
  31. }
  32. protected function _responseOuter($oAlert)
  33. {
  34. $iPrivacyView = $this->_getPrivacyView($oAlert->aExtras);
  35. if($iPrivacyView == BX_DOL_PG_HIDDEN)
  36. return;
  37. $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
  38. switch($aHandler['type']) {
  39. case BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT:
  40. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  41. $iId = $this->_oModule->_oDb->insertEvent(array(
  42. 'owner_id' => $oAlert->iSender,
  43. 'type' => $oAlert->sUnit,
  44. 'action' => $oAlert->sAction,
  45. 'object_id' => $oAlert->iObject,
  46. 'object_privacy_view' => $iPrivacyView,
  47. 'content' => $sContent,
  48. 'title' => '',
  49. 'description' => ''
  50. ));
  51. if(!empty($iId))
  52. $this->_oModule->onPost($iId);
  53. //TODO: Remove the call and the function itself if GROUPING feature won't be used.
  54. $this->_oModule->_oDb->updateSimilarObject($iId, $oAlert);
  55. break;
  56. case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
  57. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  58. $this->_oModule->_oDb->updateEvent(array('object_privacy_view' => $iPrivacyView, 'content' => $sContent), array('type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
  59. break;
  60. case BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE:
  61. if($oAlert->sUnit == 'profile' && $oAlert->sAction == 'delete') {
  62. $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'owner_id', 'value' => $oAlert->iObject));
  63. foreach($aEvents as $aEvent)
  64. $this->_oModule->deleteEvent($aEvent);
  65. $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'common_by_object', 'value' => $oAlert->iObject));
  66. foreach($aEvents as $aEvent)
  67. $this->_oModule->deleteEvent($aEvent);
  68. break;
  69. }
  70. $aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'descriptor', 'type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
  71. $this->_oModule->deleteEvent($aEvent);
  72. break;
  73. }
  74. }
  75. //TODO: Remove if it's not used.
  76. protected function _responseInner($oAlert)
  77. {
  78. $this->_oModule->_iOwnerId = (int)$oAlert->aExtras['owner_id'];
  79. $sMedia = strtolower(str_replace('bx_', '', $oAlert->sUnit));
  80. $aMediaInfo = $this->_oModule->_oTemplate->getCommonMedia($sMedia, $oAlert->iObject);
  81. $iId = $this->_oModule->_oDb->insertEvent(array(
  82. 'owner_id' => $this->_oModule->_iOwnerId,
  83. 'type' => $this->_oModule->_oConfig->getPrefix('common_post') . $sMedia,
  84. 'action' => '',
  85. 'object_id' => $this->_oModule->_getUserId(),
  86. 'object_privacy_view' => $this->_getPrivacyView($oAlert->aExtras),
  87. 'content' => serialize(array(
  88. 'type' => $sMedia,
  89. 'id' => $oAlert->iObject,
  90. )),
  91. 'title' => bx_process_input($aMediaInfo['title']),
  92. 'description' => bx_process_input($aMediaInfo['description'])
  93. ));
  94. if(!empty($iId))
  95. $this->_oModule->onPost($iId);
  96. echo $this->_oModule->_oTemplate->_wrapInTagJsCode("parent." . $this->_oModule->_sJsPostObject . "._getPost(null, " . $iId . ");");
  97. }
  98. }
  99. /** @} */