1
0

BxBaseModNotificationsModule.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxDolModule');
  12. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT', 'insert');
  13. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE', 'update');
  14. define('BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE', 'delete');
  15. define('BX_BASE_MOD_NTFS_TYPE_OWNER', '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 getUserId()
  66. {
  67. return isLogged() ? bx_get_logged_profile_id() : 0;
  68. }
  69. public function getUserIp()
  70. {
  71. return getVisitorIP();
  72. }
  73. public function getUserInfo($iUserId = 0)
  74. {
  75. bx_import('BxDolProfile');
  76. $oProfile = BxDolProfile::getInstance($iUserId);
  77. if (!$oProfile) {
  78. bx_import('BxDolProfileUndefined');
  79. $oProfile = BxDolProfileUndefined::getInstance();
  80. }
  81. return array(
  82. $oProfile->getDisplayName(),
  83. $oProfile->getUrl(),
  84. $oProfile->getThumb(),
  85. $oProfile->getUnit()
  86. );
  87. }
  88. protected function _updateModuleData($sAction, $sModuleUri)
  89. {
  90. $sMethod = $this->_oConfig->getHandlersMethod();
  91. $aModule = $this->_oDb->getModuleByUri($sModuleUri);
  92. if(!BxDolRequest::serviceExists($aModule, $sMethod))
  93. return;
  94. $aData = BxDolService::call($aModule['name'], $sMethod);
  95. if(empty($aData) || !is_array($aData))
  96. return;
  97. switch($sAction) {
  98. case 'add_handlers':
  99. $this->_oDb->insertData($aData);
  100. BxDolAlerts::cacheInvalidate();
  101. $this->_oDb->activateModuleEvents($aData, true);
  102. break;
  103. case 'delete_handlers':
  104. $this->_oDb->deleteData($aData);
  105. BxDolAlerts::cacheInvalidate();
  106. $this->_oDb->activateModuleEvents($aData, false);
  107. break;
  108. case 'delete_module_events':
  109. $this->_oDb->deleteModuleEvents($aData);
  110. break;
  111. }
  112. }
  113. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false)
  114. {
  115. header('Content-type: text/html; charset=utf-8');
  116. $s = json_encode($a);
  117. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  118. $s = '<textarea>' . $s . '</textarea>';
  119. echo $s;
  120. }
  121. }
  122. /** @} */