BxBaseModNotificationsConfig.php 5.5 KB

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