BxBaseModNotificationsConfig.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 BxBaseModNotificationsConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_aObjects;
  15. protected $_aHandlerDescriptor;
  16. protected $_sHandlersMethod;
  17. protected $_aHandlers;
  18. protected $_aHandlersHidden;
  19. protected $_aPerPage;
  20. protected $_aHtmlIds;
  21. protected $_sAnimationEffect;
  22. protected $_iAnimationSpeed;
  23. protected $_aPrivacyViewDefault;
  24. function __construct($aModule)
  25. {
  26. parent::__construct($aModule);
  27. $this->_aPrefixes = array();
  28. $this->_aObjects = array(
  29. 'alert' => $this->_sName,
  30. 'privacy_view' => $this->_sName . '_privacy_view',
  31. 'conn_subscriptions' => 'sys_profiles_subscriptions'
  32. );
  33. $this->_aHandlerDescriptor = array();
  34. $this->_sHandlersMethod = '';
  35. $this->_aHandlersHidden = array();
  36. $this->_aHandlers = array();
  37. $this->_aJsClasses = array();
  38. $this->_aJsObjects = array();
  39. $this->_aPerPage = array();
  40. $this->_aHtmlIds = array();
  41. $this->_sAnimationEffect = 'fade';
  42. $this->_iAnimationSpeed = 'slow';
  43. $this->_aPrivacyViewDefault = array(
  44. 'object' => BX_DOL_PG_ALL,
  45. 'event' => BX_DOL_PG_ALL
  46. );
  47. }
  48. public function init(&$oDb)
  49. {
  50. $this->_oDb = &$oDb;
  51. $sOptionPrefix = $this->getPrefix('option');
  52. $aHandlers = $this->_oDb->getHandlers();
  53. foreach($aHandlers as $aHandler) {
  54. if($aHandler['type'] === BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT && !empty($aHandler['content'])) {
  55. $aContent = unserialize($aHandler['content']);
  56. if(is_array($aContent) && !empty($aContent))
  57. $aHandler = array_merge($aHandler, $aContent);
  58. }
  59. $this->_aHandlers[$aHandler['alert_unit'] . (!empty($aHandler['alert_action']) ? '_' . $aHandler['alert_action'] :'')] = $aHandler;
  60. }
  61. $sHideTimeline = getParam($sOptionPrefix . 'events_hide');
  62. if(!empty($sHideTimeline))
  63. $this->_aHandlersHidden = explode(',', $sHideTimeline);
  64. }
  65. public function getHandlerDescriptor()
  66. {
  67. return $this->_aHandlerDescriptor;
  68. }
  69. public function getHandlersMethod()
  70. {
  71. return $this->_sHandlersMethod;
  72. }
  73. public function getHandlersUnitTitle($sUnit)
  74. {
  75. $sKey = '_' . $sUnit;
  76. if(strcmp($sKey, _t($sKey)) === 0)
  77. $sKey = $this->getPrefix('language') . '_alert_module_' . $sUnit;
  78. return $sKey;
  79. }
  80. public function getHandlersActionTitle($sUnit, $sAction, $sType = '')
  81. {
  82. $sKeyMask = '_%s_alert_action_%s' . (!empty($sType) ? '_%s' : '');
  83. $sKey = sprintf($sKeyMask, $sUnit, $sAction, $sType);
  84. if(strcmp($sKey, _t($sKey)) === 0)
  85. $sKey = sprintf($sKeyMask, trim($this->getPrefix('language'), '_'), $sAction, $sType);
  86. return $sKey;
  87. }
  88. public function getHandler(&$aEvent)
  89. {
  90. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  91. if(!$this->isHandler($sHandler))
  92. return false;
  93. $aHandler = $this->getHandlers($sHandler);
  94. if(empty($aHandler['module_name']) || empty($aHandler['module_class']) || empty($aHandler['module_method']))
  95. return false;
  96. return $aHandler;
  97. }
  98. public function isHandler($sKey = '')
  99. {
  100. return isset($this->_aHandlers[$sKey]);
  101. }
  102. public function getHandlers($sKey = '')
  103. {
  104. if($sKey == '')
  105. return $this->_aHandlers;
  106. return isset($this->_aHandlers[$sKey]) ? $this->_aHandlers[$sKey] : '';
  107. }
  108. public function getHandlersHidden()
  109. {
  110. return $this->_aHandlersHidden;
  111. }
  112. public function getPrivacyObject($sKey = '')
  113. {
  114. if(!$this->isHandler($sKey))
  115. return false;
  116. $aHandler = $this->getHandlers($sKey);
  117. if(empty($aHandler) || !is_array($aHandler) || empty($aHandler['privacy']))
  118. return false;
  119. return BxDolPrivacy::getObjectInstance($aHandler['privacy']);
  120. }
  121. public function getPerPage($sType = 'default')
  122. {
  123. if(empty($sType))
  124. return $this->_aPerPage;
  125. return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
  126. }
  127. public function getHtmlIds($sType, $sKey = '')
  128. {
  129. if(empty($sKey))
  130. return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
  131. return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
  132. }
  133. public function getAnimationEffect()
  134. {
  135. return $this->_sAnimationEffect;
  136. }
  137. public function getAnimationSpeed()
  138. {
  139. return $this->_iAnimationSpeed;
  140. }
  141. public function getPrivacyViewDefault($sType)
  142. {
  143. return isset($this->_aPrivacyViewDefault[$sType]) ? (int)$this->_aPrivacyViewDefault[$sType] : (int)BX_DOL_PG_ALL;
  144. }
  145. }
  146. /** @} */