BxBaseModNotificationsModule.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 BaseNotifications Base classes for Notifications like modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT', 'insert');
  12. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE', 'update');
  13. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE', 'delete');
  14. define('BX_BASE_MOD_NTFS_TYPE_OWNER', 'owner');
  15. define('BX_BASE_MOD_NTFS_TYPE_OBJECT_OWNER', 'object_owner');
  16. define('BX_BASE_MOD_NTFS_TYPE_CONNECTIONS', 'connections');
  17. define('BX_BASE_MOD_NTFS_TYPE_PUBLIC', 'public');
  18. /**
  19. * Base module class.
  20. */
  21. class BxBaseModNotificationsModule extends BxDolModule
  22. {
  23. public $_iOwnerId;
  24. function __construct(&$aModule)
  25. {
  26. parent::__construct($aModule);
  27. $this->_oConfig->init($this->_oDb);
  28. $this->_iOwnerId = 0;
  29. }
  30. public function serviceAddHandlers($sModuleUri)
  31. {
  32. $this->_updateModuleData('add_handlers', $sModuleUri);
  33. }
  34. public function serviceDeleteHandlers($sModuleUri)
  35. {
  36. $this->_updateModuleData('delete_handlers', $sModuleUri);
  37. }
  38. public function serviceDeleteModuleEvents($sModuleUri)
  39. {
  40. $this->_updateModuleData('delete_module_events', $sModuleUri);
  41. }
  42. function serviceGetActionsChecklist()
  43. {
  44. $sLangPrefix = $this->_oConfig->getPrefix('language');
  45. $aHandlers = $this->_oConfig->getHandlers();
  46. $aResults = array();
  47. foreach($aHandlers as $aHandler) {
  48. if($aHandler['type'] != BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT)
  49. continue;
  50. $aModule = array();
  51. if(!empty($aHandler['module_name']))
  52. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  53. if(empty($aModule))
  54. $aModule['title'] = _t($sLangPrefix . '_alert_module_' . $aHandler['alert_unit']);
  55. $sAction = !empty($aHandler['alert_action']) ? ' (' . _t($sLangPrefix . '_alert_action_' . $aHandler['alert_action']) . ')' : '';
  56. $aResults[$aHandler['id']] = $aModule['title'] . $sAction;
  57. }
  58. asort($aResults);
  59. return $aResults;
  60. }
  61. public function isAllowedView($bPerform = false)
  62. {
  63. return true;
  64. }
  65. public function getOwnerId()
  66. {
  67. return $this->_iOwnerId;
  68. }
  69. public function getUserId()
  70. {
  71. return isLogged() ? bx_get_logged_profile_id() : 0;
  72. }
  73. public function getUserIp()
  74. {
  75. return getVisitorIP();
  76. }
  77. public function getUserInfo($iUserId = 0)
  78. {
  79. $oProfile = BxDolProfile::getInstance($iUserId);
  80. if (!$oProfile)
  81. $oProfile = BxDolProfileUndefined::getInstance();
  82. return array(
  83. $oProfile->getDisplayName(),
  84. $oProfile->getUrl(),
  85. $oProfile->getThumb(),
  86. $oProfile->getUnit()
  87. );
  88. }
  89. protected function _updateModuleData($sAction, $sModuleUri)
  90. {
  91. $sMethod = $this->_oConfig->getHandlersMethod();
  92. $aModule = $this->_oDb->getModuleByUri($sModuleUri);
  93. if(!BxDolRequest::serviceExists($aModule, $sMethod))
  94. return;
  95. $aData = BxDolService::call($aModule['name'], $sMethod);
  96. if(empty($aData) || !is_array($aData))
  97. return;
  98. switch($sAction) {
  99. case 'add_handlers':
  100. $this->_oDb->insertData($aData);
  101. BxDolAlerts::cacheInvalidate();
  102. $this->_oDb->activateModuleEvents($aData, true);
  103. break;
  104. case 'delete_handlers':
  105. $this->_oDb->deleteData($aData);
  106. BxDolAlerts::cacheInvalidate();
  107. $this->_oDb->activateModuleEvents($aData, false);
  108. break;
  109. case 'delete_module_events':
  110. $this->_oDb->deleteModuleEvents($aData);
  111. break;
  112. }
  113. }
  114. }
  115. /** @} */