BxTimelineResponse.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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('BxDolAlerts');
  12. class BxTimelineResponse extends BxDolAlertsResponse
  13. {
  14. protected $_oModule;
  15. /**
  16. * Constructor
  17. * @param BxTimelineModule $oModule - an instance of current module
  18. */
  19. public function __construct($oModule)
  20. {
  21. parent::__construct();
  22. $this->_oModule = $oModule;
  23. }
  24. /**
  25. * Overwtire the method of parent class.
  26. *
  27. * @param BxDolAlerts $oAlert an instance of alert.
  28. */
  29. public function response($oAlert)
  30. {
  31. if(is_array($oAlert->aExtras) && isset($oAlert->aExtras['from_wall']) && (int)$oAlert->aExtras['from_wall'] == 1)
  32. $this->_responseInner($oAlert);
  33. else
  34. $this->_responseOuter($oAlert);
  35. }
  36. protected function _responseOuter($oAlert)
  37. {
  38. $iPrivacyView = $this->_getPrivacyView($oAlert->aExtras);
  39. if($iPrivacyView == BX_DOL_PG_HIDDEN)
  40. return;
  41. $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
  42. switch($aHandler['type']) {
  43. case BX_TIMELINE_HANDLER_TYPE_INSERT:
  44. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  45. $iId = $this->_oModule->_oDb->insertEvent(array(
  46. 'owner_id' => $oAlert->iSender,
  47. 'type' => $oAlert->sUnit,
  48. 'action' => $oAlert->sAction,
  49. 'object_id' => $oAlert->iObject,
  50. 'object_privacy_view' => $iPrivacyView,
  51. 'content' => $sContent,
  52. 'title' => '',
  53. 'description' => ''
  54. ));
  55. if(!empty($iId))
  56. $this->_oModule->onPost($iId);
  57. //TODO: Remove the call and the function itself if GROUPING feature won't be used.
  58. $this->_oModule->_oDb->updateSimilarObject($iId, $oAlert);
  59. break;
  60. case BX_TIMELINE_HANDLER_TYPE_UPDATE:
  61. $sContent = !empty($oAlert->aExtras) && is_array($oAlert->aExtras) ? serialize(bx_process_input($oAlert->aExtras)) : '';
  62. $this->_oModule->_oDb->updateEvent(array('object_privacy_view' => $iPrivacyView, 'content' => $sContent), array('type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
  63. break;
  64. case BX_TIMELINE_HANDLER_TYPE_DELETE:
  65. $this->_oModule->_oDb->deleteEvent(array('type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
  66. break;
  67. }
  68. }
  69. //TODO: Remove if it's not used.
  70. protected function _responseInner($oAlert)
  71. {
  72. $this->_oModule->_iOwnerId = (int)$oAlert->aExtras['owner_id'];
  73. $sMedia = strtolower(str_replace('bx_', '', $oAlert->sUnit));
  74. $aMediaInfo = $this->_oModule->_oTemplate->getCommonMedia($sMedia, $oAlert->iObject);
  75. $iId = $this->_oModule->_oDb->insertEvent(array(
  76. 'owner_id' => $this->_oModule->_iOwnerId,
  77. 'type' => $this->_oModule->_oConfig->getPrefix('common_post') . $sMedia,
  78. 'action' => '',
  79. 'object_id' => $this->_oModule->_getUserId(),
  80. 'object_privacy_view' => $this->_getPrivacyView($oAlert->aExtras),
  81. 'content' => serialize(array(
  82. 'type' => $sMedia,
  83. 'id' => $oAlert->iObject,
  84. )),
  85. 'title' => bx_process_input($aMediaInfo['title']),
  86. 'description' => bx_process_input($aMediaInfo['description'])
  87. ));
  88. if(!empty($iId))
  89. $this->_oModule->onPost($iId);
  90. echo $this->_oModule->_oTemplate->_wrapInTagJsCode("parent." . $this->_oModule->_sJsPostObject . "._getPost(null, " . $iId . ");");
  91. }
  92. protected function _getPrivacyView($aExtras)
  93. {
  94. return is_array($aExtras) && isset($aExtras['privacy_view']) ? (int)$aExtras['privacy_view'] : $this->_oModule->_oConfig->getPrivacyViewDefault();
  95. }
  96. }
  97. /** @} */