BxBaseModNotificationsConfig.php 6.8 KB

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