BxNtfsConfig.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 Notifications Notifications
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolPrivacy');
  12. class BxNtfsConfig extends BxBaseModNotificationsConfig
  13. {
  14. protected $_iOwnerNameMaxLen;
  15. protected $_iContentMaxLen;
  16. protected $_iPushMaxLen;
  17. protected $_aHandlersHiddenEmail;
  18. protected $_aHandlersHiddenPush;
  19. /**
  20. * Group settings by action. Enabled by default.
  21. */
  22. protected $_bSettingsGrouped;
  23. protected $_aSettingsTypes;
  24. protected $_aModulesProfiles;
  25. protected $_aModulesContexts;
  26. protected $_iDeliveryTimeout;
  27. protected $_iProcessedEvent;
  28. /**
  29. * Constructor
  30. */
  31. public function __construct($aModule)
  32. {
  33. parent::__construct($aModule);
  34. $this->CNF = array (
  35. // page URIs
  36. 'URL_HOME' => 'page.php?i=notifications-view',
  37. // some params
  38. 'PARAM_QUEUE_ADD_THRESHOLD' => 0,
  39. // objects
  40. 'OBJECT_MENU_SUBMENU' => 'bx_notifications_submenu', // main module submenu
  41. 'OBJECT_MENU_SETTINGS' => 'bx_notifications_settings', // settings submenu
  42. 'OBJECT_GRID_SETTINGS_ADMINISTRATION' => 'bx_notifications_settings_administration',
  43. 'OBJECT_GRID_SETTINGS_COMMON' => 'bx_notifications_settings_common',
  44. // some language keys
  45. 'T' => array(
  46. 'setting_personal' => '_bx_ntfs_setting_type_personal',
  47. 'setting_follow_member' => '_bx_ntfs_setting_type_follow_member',
  48. 'setting_follow_context' => '_bx_ntfs_setting_type_follow_context',
  49. 'setting_other' => '_bx_ntfs_setting_type_other',
  50. )
  51. );
  52. $this->_aPrefixes = array(
  53. 'style' => 'bx-ntfs',
  54. 'language' => '_bx_ntfs',
  55. 'option' => 'bx_notifications_'
  56. );
  57. $this->_iOwnerNameMaxLen = 21;
  58. $this->_iContentMaxLen = 32;
  59. $this->_iPushMaxLen = 190;
  60. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '');
  61. $this->_sHandlersMethod = 'get_notifications_data';
  62. $this->_aHandlersHiddenEmail = array();
  63. $this->_aHandlersHiddenPush = array();
  64. $this->_bSettingsGrouped = true;
  65. $this->_aSettingsTypes = array(
  66. BX_NTFS_STYPE_PERSONAL,
  67. BX_NTFS_STYPE_FOLLOW_MEMBER,
  68. BX_NTFS_STYPE_FOLLOW_CONTEXT,
  69. //BX_NTFS_STYPE_OTHER //TODO: May be it can be removed, because there is no events(alerts) for this type.
  70. );
  71. $this->_aModulesProfiles = false;
  72. $this->_aModulesContexts = false;
  73. $this->_aJsClasses = array(
  74. 'main' => 'BxNtfsMain',
  75. 'view' => 'BxNtfsView',
  76. );
  77. $this->_aJsObjects = array(
  78. 'main' => 'oBxNtfsMain',
  79. 'view' => 'oBxNtfsView',
  80. );
  81. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  82. $this->_aHtmlIds = array(
  83. 'view' => array(
  84. 'block' => $sHtmlPrefix,
  85. 'events' => $sHtmlPrefix . '-events',
  86. 'event' => $sHtmlPrefix . '-event-'
  87. )
  88. );
  89. }
  90. public function init(&$oDb)
  91. {
  92. parent::init($oDb);
  93. $sOptionPrefix = $this->getPrefix('option');
  94. $this->_aPerPage = array(
  95. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  96. 'preview' => (int)getParam($sOptionPrefix . 'events_per_preview')
  97. );
  98. $this->_bSettingsGrouped = getParam($sOptionPrefix . 'enable_group_settings') == 'on';
  99. $aSettings = array(
  100. 'site' => '',
  101. 'email' => 'Email',
  102. 'push' => 'Push'
  103. );
  104. foreach($aSettings as $sSetting => $sVariable) {
  105. $sHideTimeline = getParam($sOptionPrefix . 'events_hide_' . $sSetting);
  106. if(!empty($sHideTimeline))
  107. $this->{'_aHandlersHidden' . $sVariable} = explode(',', $sHideTimeline);
  108. }
  109. $this->_iDeliveryTimeout = (int)getParam($sOptionPrefix . 'delivery_timeout');
  110. $this->_iProcessedEvent = (int)getParam($sOptionPrefix . 'processed_event');
  111. }
  112. public function getOwnerNameMaxLen()
  113. {
  114. return $this->_iOwnerNameMaxLen;
  115. }
  116. public function getContentMaxLen()
  117. {
  118. return $this->_iContentMaxLen;
  119. }
  120. public function getPushMaxLen()
  121. {
  122. return $this->_iPushMaxLen;
  123. }
  124. public function getHandlersHidden($sType = '')
  125. {
  126. if(!in_array($sType, array('', 'email', 'push')))
  127. return array();
  128. return $this->{'_aHandlersHidden' . ucfirst($sType)};
  129. }
  130. public function isSettingsGrouped()
  131. {
  132. return $this->_bSettingsGrouped;
  133. }
  134. public function getSettingsTypes()
  135. {
  136. return $this->_aSettingsTypes;
  137. }
  138. public function getDeliveryTimeout()
  139. {
  140. return $this->_iDeliveryTimeout;
  141. }
  142. public function getProcessedEvent()
  143. {
  144. return $this->_iProcessedEvent;
  145. }
  146. public function setProcessedEvent($iEvent)
  147. {
  148. $this->_iProcessedEvent = $iEvent;
  149. setParam($this->getPrefix('option') . 'processed_event', $iEvent);
  150. }
  151. /**
  152. * Ancillary functions
  153. */
  154. public function getViewUrl()
  155. {
  156. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=notifications-view');
  157. }
  158. public function getContentModule(&$aEvent)
  159. {
  160. $sModule = $aEvent['type'];
  161. if($this->_oDb->isEnabledByName($sModule))
  162. return $sModule;
  163. $sModule = str_replace(array('_media', '_reactions'), array('', ''), $sModule);
  164. if($this->_oDb->isEnabledByName($sModule))
  165. return $sModule;
  166. return '';
  167. }
  168. public function getContentObjectId(&$aEvent)
  169. {
  170. return !empty($aEvent['content']['object_id']) ? (int)$aEvent['content']['object_id'] : (int)$aEvent['object_id'];
  171. }
  172. public function getProfileBasedModules()
  173. {
  174. if ($this->_aModulesProfiles !== false && $this->_aModulesContexts !== false)
  175. return array($this->_aModulesProfiles, $this->_aModulesContexts);
  176. if (getParam('sys_db_cache_enable')) {
  177. $oDb = BxDolDb::getInstance();
  178. $oCache = $oDb->getDbCacheObject();
  179. $sCacheKey = $oDb->genDbCacheKey('bx_ntfs_profile_based_modules');
  180. $aData = $oCache->getData($sCacheKey);
  181. if (null === $aData) {
  182. $aData = $this->_getProfileBasedModulesData();
  183. $oCache->setData ($sCacheKey, $aData);
  184. }
  185. }
  186. else {
  187. $aData = $this->_getProfileBasedModulesData();
  188. }
  189. return $aData;
  190. }
  191. protected function _getProfileBasedModulesData()
  192. {
  193. $this->_aModulesProfiles = [];
  194. $this->_aModulesContexts = [];
  195. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules']);
  196. foreach($aModules as $aModule) {
  197. if(!bx_is_srv($aModule['name'], 'act_as_profile'))
  198. continue;
  199. if(bx_srv($aModule['name'], 'act_as_profile'))
  200. $this->_aModulesProfiles[] = $aModule['name'];
  201. else
  202. $this->_aModulesContexts[] = $aModule['name'];
  203. }
  204. return [$this->_aModulesProfiles, $this->_aModulesContexts];
  205. }
  206. }
  207. /** @} */