BxBaseModNotificationsResponse.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 BaseNotifications Base classes for Notifications like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModNotificationsResponse extends BxDolAlertsResponse
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. }
  20. /**
  21. * Note. Check priority is IMPORTANT!
  22. * Don't swap the checks without a REAL need.
  23. */
  24. protected function _getObjectOwnerId($aExtras)
  25. {
  26. if(!is_array($aExtras))
  27. return 0;
  28. if(isset($aExtras['parent_author_id']))
  29. return (int)$aExtras['parent_author_id'];
  30. if(isset($aExtras['object_author_id']))
  31. return (int)$aExtras['object_author_id'];
  32. return 0;
  33. }
  34. protected function _getObjectPrivacyView($aExtras)
  35. {
  36. return $this->_oModule->getObjectPrivacyView($aExtras);
  37. }
  38. protected function _getObjectCf($aExtras)
  39. {
  40. return $this->_oModule->getObjectCf($aExtras);
  41. }
  42. /**
  43. * Note. Check priority is NOT IMPORTANT!
  44. */
  45. protected function _getSubObjectId($aExtras)
  46. {
  47. if(!is_array($aExtras))
  48. return 0;
  49. if(isset($aExtras['comment_id']))
  50. return (int)$aExtras['comment_id'];
  51. if(isset($aExtras['vote_id']))
  52. return (int)$aExtras['vote_id'];
  53. if(isset($aExtras['score_id']))
  54. return (int)$aExtras['score_id'];
  55. if(isset($aExtras['repost_id']))
  56. return (int)$aExtras['repost_id'];
  57. if(isset($aExtras['timeline_post_id']))
  58. return (int)$aExtras['timeline_post_id'];
  59. if(isset($aExtras['performer_id']))
  60. return (int)$aExtras['performer_id'];
  61. if(isset($aExtras['subobject_id']))
  62. return (int)$aExtras['subobject_id'];
  63. if(isset($aExtras['subobjects_ids']))
  64. return is_array($aExtras['subobjects_ids']) ? $aExtras['subobjects_ids'] : array($aExtras['subobjects_ids']);
  65. return 0;
  66. }
  67. protected function _getEventUpdate(&$oAlert, &$aHandler)
  68. {
  69. $aHandlers = $this->_oModule->_oDb->getHandlers([
  70. 'type' => 'by_group_key_type',
  71. 'group' => $aHandler['group']
  72. ]);
  73. return $this->_oModule->_oDb->getEvents([
  74. 'browse' => 'descriptor',
  75. 'type' => $oAlert->sUnit,
  76. 'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
  77. 'object_id' => $oAlert->iObject
  78. ]);
  79. }
  80. }
  81. /** @} */