BxBaseModNotificationsConfig.php 6.9 KB

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