BxNtfsModule.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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('BxBaseModNotificationsModule');
  12. define('BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS', 'obj_own_and_con');
  13. define('BX_NTFS_TYPE_DEFAULT', BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS);
  14. /**
  15. * STYPE - Setting Type:
  16. * 1. personal - related to you;
  17. * 2. follow_member - related to members you follow;
  18. * 3. follow_context - related to contexts you follow;
  19. * 4. other - others.
  20. */
  21. define('BX_NTFS_STYPE_PERSONAL', 'personal');
  22. define('BX_NTFS_STYPE_FOLLOW_MEMBER', 'follow_member');
  23. define('BX_NTFS_STYPE_FOLLOW_CONTEXT', 'follow_context');
  24. define('BX_NTFS_STYPE_OTHER', 'other');
  25. /**
  26. * SLTMODE - Silent mode:
  27. * It is needed for alert sending module to tell that the alert should be ignored
  28. * with Notifications module completely or partially. Available values:
  29. * 1. disabled (global, value = 0) - all notifications are available;
  30. * 2. absolute (global, value = 1) - alert isn't registered which means that there is no notifications at all;
  31. * 3. absolute (for Notifications only, value = 11) - the same as global absolute.
  32. * 3. on-site only (value = 12) - alert is registered. It means that on-site notification is available while the others are disabled.
  33. * 4. on-site + email (value = 13) - alert is registered (on-site) and notification via 'email' is enabled.
  34. * 5. on-site + push (value = 14) - alert is registered (on-site) and notification via 'push' is enabled.
  35. *
  36. * @see BxNtfsResponse::response - 'silent_mode' parameter in Alerts Extras array.
  37. */
  38. define('BX_NTFS_SLTMODE_ABSOLUTE', 11);
  39. define('BX_NTFS_SLTMODE_SITE', 12);
  40. define('BX_NTFS_SLTMODE_SITE_EMAIL', 13);
  41. define('BX_NTFS_SLTMODE_SITE_PUSH', 14);
  42. class BxNtfsModule extends BxBaseModNotificationsModule
  43. {
  44. /**
  45. * Constructor
  46. */
  47. function __construct($aModule)
  48. {
  49. parent::__construct($aModule);
  50. $this->_iOwnerId = $this->getUserId();
  51. }
  52. /**
  53. * ACTION METHODS
  54. */
  55. function actionMarkAsClicked()
  56. {
  57. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  58. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  59. if(empty($aEvent) || !is_array($aEvent))
  60. return echoJson(['code' => 1]);
  61. $aParams = $this->_prepareParamsGet();
  62. if($this->_oDb->markAsClicked($aParams['viewer_id'], $iId) === false)
  63. return echoJson(['code' => 2]);
  64. echoJson([
  65. 'code' => 0,
  66. 'id' => $iId
  67. ]);
  68. }
  69. function actionGetPosts()
  70. {
  71. $aParams = $this->_prepareParamsGet();
  72. if(empty($aParams['owner_id']) || (int)$aParams['owner_id'] != $this->_iOwnerId)
  73. return echoJson([]);
  74. echoJson([
  75. 'events' => $this->_oTemplate->getPosts($aParams)
  76. ]);
  77. }
  78. /**
  79. * SERVICE METHODS
  80. */
  81. public function serviceGetSafeServices()
  82. {
  83. return [
  84. 'GetBlockView' => '',
  85. 'GetData' => '',
  86. ];
  87. }
  88. /**
  89. * @page service Service Calls
  90. * @section bx_notifications Invitations
  91. * @subsection bx_notifications-other Other
  92. * @subsubsection bx_notifications-get_include get_include
  93. *
  94. * @code bx_srv('bx_notifications', 'get_include', [...]); @endcode
  95. *
  96. * Get all necessary CSS and JS files to include in a page.
  97. *
  98. * @return string with all necessary CSS and JS files.
  99. *
  100. * @see BxInvModule::serviceGetInclude
  101. */
  102. /**
  103. * @ref bx_notifications-get_include "get_include"
  104. */
  105. public function serviceGetInclude($bIncludeCss = true, $mixedIncludeJs = false)
  106. {
  107. return $this->_oTemplate->getInclude($bIncludeCss, $mixedIncludeJs);
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_notifications Notifications
  112. * @subsection bx_notifications-page_blocks Page Blocks
  113. * @subsubsection bx_notifications-get_block_settings get_block_settings
  114. *
  115. * @code bx_srv('bx_notifications', 'get_block_settings', [...]); @endcode
  116. *
  117. * Get Settings block for a separate page.
  118. *
  119. * @return a string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  120. *
  121. * @see BxNtfsModule::serviceGetBlockSettings
  122. */
  123. /**
  124. * @ref bx_notifications-get_block_settings "get_block_settings"
  125. */
  126. public function serviceGetBlockSettings($sDeliveryType = '', $aParams = array())
  127. {
  128. if(!isLogged())
  129. return '';
  130. if(empty($sDeliveryType) && bx_get('delivery') !== false)
  131. $sDeliveryType = bx_process_input(bx_get('delivery'));
  132. if(empty($sDeliveryType))
  133. $sDeliveryType = BX_BASE_MOD_NTFS_DTYPE_SITE;
  134. $iUserId = bx_get_logged_profile_id();
  135. if(!empty($aParams['user_id']))
  136. $iUserId = (int)$aParams['user_id'];
  137. else
  138. $aParams['user_id'] = $iUserId;
  139. $this->_oDb->initSettingUser($iUserId);
  140. return array(
  141. 'content' => $this->getBlockSettings($sDeliveryType, $aParams),
  142. );
  143. }
  144. /**
  145. * @page service Service Calls
  146. * @section bx_notifications Notifications
  147. * @subsection bx_notifications-page_blocks Page Blocks
  148. * @subsubsection bx_notifications-get_data get_data
  149. *
  150. * @code bx_srv('bx_notifications', 'get_data', [...]); @endcode
  151. *
  152. * Get data for app
  153. *
  154. * @return an array .
  155. *
  156. * @see BxNtfsModule::serviceGetData
  157. */
  158. /**
  159. * @ref bx_notifications-get_data "get_data"
  160. * @api @ref bx_notifications-get_data "get_data"
  161. */
  162. public function serviceGetData($aParams)
  163. {
  164. if(is_string($aParams)){
  165. $aParams = json_decode($aParams, true);
  166. }
  167. return $this->serviceGetBlockView($aParams['params']['type'], $aParams['params']['start'], $aParams['params']['per_page'], $aParams['params']['modules']);
  168. }
  169. /**
  170. * @page service Service Calls
  171. * @section bx_notifications Notifications
  172. * @subsection bx_notifications-page_blocks Page Blocks
  173. * @subsubsection bx_notifications-get_block_view get_block_view
  174. *
  175. * @code bx_srv('bx_notifications', 'get_block_view', [...]); @endcode
  176. *
  177. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  178. *
  179. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  180. *
  181. * @see BxNtfsModule::serviceGetBlockView
  182. */
  183. /**
  184. * @ref bx_notifications-get_block_view "get_block_view"
  185. */
  186. public function serviceGetBlockView($sType = '', $iStart = -1, $iPerPage = -1, $aModules = [])
  187. {
  188. $aBrowseTypes = [BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, BX_BASE_MOD_NTFS_TYPE_OBJECT_OWNER];
  189. if(empty($sType)) {
  190. $mixedType = bx_get('type');
  191. if($mixedType !== false && in_array($mixedType, $aBrowseTypes))
  192. $sType = $mixedType;
  193. if(empty($sType))
  194. $sType = BX_NTFS_TYPE_DEFAULT;
  195. }
  196. $iOwnerId = $this->getUserId();
  197. if(!$iOwnerId)
  198. return ['content' => MsgBox(_t('_bx_ntfs_txt_msg_no_results'))];
  199. $aParams = $this->_prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $aModules);
  200. if(bx_is_api()) {
  201. $aParams['start_from_item'] = true;
  202. $aContent = $this->_oTemplate->getPosts($aParams);
  203. $iContent = count($aContent);
  204. if($iContent > $aParams['per_page'])
  205. $aContent = array_slice($aContent, 0, -($iContent - $aParams['per_page']));
  206. $aParams['start'] = end($aContent)['id'];
  207. return [bx_api_get_block('browse', [
  208. 'unit' => 'notifications',
  209. 'request_url' => '/api.php?r=bx_notifications/get_data/&params[]=',
  210. 'params' => $aParams,
  211. 'id' => $iOwnerId,
  212. 'data' => $aContent]),
  213. ];
  214. }
  215. $sContent = $this->_oTemplate->getViewBlock($aParams);
  216. $aParams['browse'] = 'first';
  217. $aEvent = $this->_oDb->getEvents($aParams);
  218. if(!empty($aEvent))
  219. $this->_oDb->markAsRead($iOwnerId, $aEvent['id']);
  220. return ['content' => $sContent];
  221. }
  222. /**
  223. * @page service Service Calls
  224. * @section bx_notifications Notifications
  225. * @subsection bx_notifications-browsing Browsing
  226. * @subsubsection bx_notifications-get_event_by_id get_event_by_id
  227. *
  228. * @code bx_srv('bx_notifications', 'get_event_by_id', [...]); @endcode
  229. *
  230. * Get event's data by event ID.
  231. *
  232. * @return an array with event's data.
  233. *
  234. * @see BxNtfsModule::serviceGetEventById
  235. */
  236. /**
  237. * @ref bx_notifications-get_event_by_id "get_event_by_id"
  238. */
  239. public function serviceGetEventById($iId)
  240. {
  241. $aParams = array(
  242. 'browse' => 'id',
  243. 'value' => $iId,
  244. );
  245. return $this->_oDb->getEvents($aParams);
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_notifications Notifications
  250. * @subsection bx_notifications-other Other
  251. * @subsubsection bx_notifications-get_notifications get_notifications
  252. *
  253. * @code bx_srv('bx_notifications', 'get_notifications', [...]); @endcode
  254. *
  255. * Get notifications by params.
  256. *
  257. * @return array with notifications.
  258. *
  259. * @see BxNtfsModule::serviceGetNotifications
  260. */
  261. /**
  262. * @ref bx_notifications-get_notifications "get_notifications"
  263. */
  264. public function serviceGetNotifications($iOwnerId = 0, $aBrowseParams = array())
  265. {
  266. if(!$iOwnerId)
  267. $iOwnerId = $this->getUserId();
  268. if(!$iOwnerId)
  269. return 0;
  270. $aParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId);
  271. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  272. $aParams = array_merge($aParams, $aBrowseParams);
  273. $aEvents = $this->_oDb->getEvents($aParams);
  274. if($this->_oConfig->isEventsGrouped())
  275. $this->groupEvents($aEvents);
  276. // returns parsed content for React Jot
  277. if (!is_array($aBrowseParams) && $aBrowseParams === 'return_parsed_content')
  278. foreach ($aEvents as &$aContent)
  279. $this->_oTemplate->getPost($aContent, array('return_parsed_content'));
  280. return $aEvents;
  281. }
  282. /**
  283. * @page service Service Calls
  284. * @section bx_notifications Notifications
  285. * @subsection bx_notifications-other Other
  286. * @subsubsection bx_notifications-get_unread_notifications get_unread_notifications
  287. *
  288. * @code bx_srv('bx_notifications', 'get_unread_notifications', [...]); @endcode
  289. *
  290. * Get unread notifications.
  291. *
  292. * @return array with unread notifications.
  293. *
  294. * @see BxNtfsModule::serviceGetUnreadNotifications
  295. */
  296. /**
  297. * @ref bx_notifications-get_unread_notifications "get_unread_notifications"
  298. */
  299. public function serviceGetUnreadNotifications($iOwnerId = 0)
  300. {
  301. return $this->serviceGetNotifications($iOwnerId, array('new' => 1));
  302. }
  303. /**
  304. * @page service Service Calls
  305. * @section bx_notifications Notifications
  306. * @subsection bx_notifications-other Other
  307. * @subsubsection bx_notifications-get_unread_notifications_num get_unread_notifications_num
  308. *
  309. * @code bx_srv('bx_notifications', 'get_unread_notifications_num', [...]); @endcode
  310. *
  311. * Get number of unread notifications.
  312. *
  313. * @return integer value with number of unread notifications.
  314. *
  315. * @see BxNtfsModule::serviceGetUnreadNotificationsNum
  316. */
  317. /**
  318. * @ref bx_notifications-get_unread_notifications_num "get_unread_notifications_num"
  319. */
  320. public function serviceGetUnreadNotificationsNum($iOwnerId = 0)
  321. {
  322. if(!$iOwnerId)
  323. $iOwnerId = $this->getUserId();
  324. if(!$iOwnerId)
  325. return 0;
  326. $sModule = $this->_oConfig->getName();
  327. $aBrowseParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId, 0, PHP_INT_MAX);
  328. $sParamCheck = 'perform_privacy_check';
  329. $sParamCheckFor = 'perform_privacy_check_for';
  330. $iEvents = 0;
  331. if($this->_oConfig->isEventsGrouped()) {
  332. $aEvents = $this->_oDb->getEvents($aBrowseParams);
  333. $this->groupEvents($aEvents);
  334. $iCount = 0;
  335. $iLastRead = $this->_oDb->getLastRead((int)$aBrowseParams['owner_id']);
  336. foreach($aEvents as $aEvent)
  337. if($aEvent['id'] > $iLastRead)
  338. $iCount++;
  339. $aEvents = array_slice($aEvents, 0, $iCount);
  340. }
  341. else {
  342. $aBrowseParams = array_merge($aBrowseParams, [
  343. 'new' => 1,
  344. ]);
  345. $aEvents = $this->_oDb->getEvents($aBrowseParams);
  346. }
  347. foreach($aEvents as $aEvent) {
  348. if(isset($aBrowseParams[$sParamCheck]) && $aBrowseParams[$sParamCheck] !== true)
  349. continue;
  350. $iViewerId = !empty($aBrowseParams[$sParamCheckFor]) ? (int)$aBrowseParams[$sParamCheckFor] : 0;
  351. $oPrivacyInt = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  352. if(!$oPrivacyInt->check($aEvent['id'], $iViewerId))
  353. continue;
  354. $oPrivacyExt = $this->_oConfig->getPrivacyObject($aEvent['type'] . '_' . $aEvent['action']);
  355. if($oPrivacyExt !== false && !$oPrivacyExt->check($aEvent['id'], $iViewerId))
  356. continue;
  357. $sSrvModule = $this->_oConfig->getContentModule($aEvent);
  358. $sSrvMethod = 'check_allowed_with_content_for_profile';
  359. if($sSrvModule && BxDolRequest::serviceExists($sSrvModule, $sSrvMethod) && BxDolService::call($sSrvModule, $sSrvMethod, array('view', $this->_oConfig->getContentObjectId($aEvent), $iViewerId)) !== CHECK_ACTION_RESULT_ALLOWED)
  360. continue;
  361. $bEventCanceled = false;
  362. bx_alert($sModule, 'is_notification', 0, 0, [
  363. 'event' => &$aEvent,
  364. 'event_canceled' => &$bEventCanceled,
  365. 'browse_params' => $aBrowseParams
  366. ]);
  367. if($bEventCanceled)
  368. continue;
  369. $iEvents++;
  370. }
  371. return $iEvents;
  372. }
  373. /**
  374. * @page service Service Calls
  375. * @section bx_notifications Notifications
  376. * @subsection bx_notifications-other Other
  377. * @subsubsection bx_notifications-get_live_updates get_live_updates
  378. *
  379. * @code bx_srv('bx_notifications', 'get_live_updates', [...]); @endcode
  380. *
  381. * Get data for Live Updates system.
  382. *
  383. * @return an array with special format.
  384. *
  385. * @see BxNtfsModule::serviceGetLiveUpdates
  386. */
  387. /**
  388. * @ref bx_notifications-get_live_updates "get_live_updates"
  389. */
  390. public function serviceGetLiveUpdates($aMenuItemParent, $aMenuItemChild, $iCount = 0)
  391. {
  392. $iOwnerId = $this->getUserId();
  393. $iCountNew = $this->serviceGetUnreadNotificationsNum($iOwnerId);
  394. if($iCountNew == $iCount)
  395. return false;
  396. return array(
  397. 'count' => $iCountNew, // required
  398. 'method' => 'bx_menu_show_live_update(oData)', // required
  399. 'data' => array(
  400. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  401. 'content' => '{count}'
  402. )),
  403. 'mi_parent' => $aMenuItemParent,
  404. 'mi_child' => $aMenuItemChild
  405. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  406. );
  407. }
  408. /*
  409. * COMMON METHODS
  410. */
  411. public function getBlockSettings($sDeliveryType, $aParams = array())
  412. {
  413. return $this->_oTemplate->getSettingsBlock($sDeliveryType, $aParams);
  414. }
  415. public function setSubmenu($sSelected)
  416. {
  417. $oSubmenuSystem = BxDolMenu::getObjectInstance('sys_site_submenu');
  418. if(!$oSubmenuSystem)
  419. return;
  420. $CNF = &$this->_oConfig->CNF;
  421. $oSubmenuSystem->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU'], array (
  422. 'title' => _t('_bx_ntfs'),
  423. 'link' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME'])),
  424. 'icon' => '',
  425. ));
  426. $oSubmenuModule = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU']);
  427. if($oSubmenuModule)
  428. $oSubmenuModule->setSelected($this->_oConfig->getName(), $sSelected);
  429. }
  430. public function onPost($iId)
  431. {
  432. //--- Event -> Post for Alerts Engine ---//
  433. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post', $iId);
  434. $oAlert->alert();
  435. //--- Event -> Post for Alerts Engine ---//
  436. }
  437. public function enableSettingsLike($iId, $bValue, $bAdministration = false)
  438. {
  439. $aSetting = $this->_oDb->getSetting(array(
  440. 'by' => $bAdministration ? 'id' : 'tsu_id',
  441. 'id' => (int)$iId
  442. ));
  443. if(empty($aSetting) || !is_array($aSetting))
  444. return false;
  445. $aSettingsIds = $this->_oDb->getSetting(array(
  446. 'by' => 'group_type_delivery',
  447. 'group' => $aSetting['group'],
  448. 'delivery' => $aSetting['delivery'],
  449. 'type' => $aSetting['type'],
  450. 'active' => !$bAdministration
  451. ));
  452. if(empty($aSettingsIds) || !is_array($aSettingsIds))
  453. return false;
  454. $iUserId = bx_get_logged_profile_id();
  455. $mixedResult = false;
  456. if($bAdministration)
  457. $mixedResult = $this->_oDb->activateSettingById($bValue, $aSettingsIds);
  458. else
  459. $mixedResult = $this->_oDb->activateSettingByIdUser($bValue, $iUserId, $aSettingsIds);
  460. return $mixedResult;
  461. }
  462. public function _changeSettingsValueLike($iId, $sField, $mixedValue, $bAdministration = false)
  463. {
  464. $aSetting = $this->_oDb->getSetting(array(
  465. 'by' => $bAdministration ? 'id' : 'tsu_id',
  466. 'id' => (int)$iId
  467. ));
  468. if(empty($aSetting) || !is_array($aSetting))
  469. return false;
  470. $aSettingsIds = $this->_oDb->getSetting(array(
  471. 'by' => 'group_type_delivery',
  472. 'group' => $aSetting['group'],
  473. 'delivery' => $aSetting['delivery'],
  474. 'type' => $aSetting['type'],
  475. 'active' => !$bAdministration
  476. ));
  477. if(empty($aSettingsIds) || !is_array($aSettingsIds))
  478. return false;
  479. $iUserId = bx_get_logged_profile_id();
  480. $mixedResult = false;
  481. if($bAdministration)
  482. $mixedResult = $this->_oDb->changeSettingById($sField, $mixedValue, $aSettingsIds);
  483. else
  484. $mixedResult = $this->_oDb->changeSettingByIdUser($sField, $mixedValue, $iUserId, $aSettingsIds);
  485. return $mixedResult;
  486. }
  487. public function sendNotificationEmail($iProfile, $aNotification)
  488. {
  489. if(!$iProfile)
  490. return false;
  491. $aSettings = &$aNotification['settings'];
  492. $sTemplate = !empty($aSettings['template']) ? $aSettings['template'] : 'bx_notifications_new_event';
  493. $aTemplateMarkers = array('content' => $aNotification['content']);
  494. if(!empty($aSettings['markers']) && is_array($aSettings['markers']))
  495. $aTemplateMarkers = array_merge($aTemplateMarkers, $aSettings['markers']);
  496. $aTemplate = null;
  497. bx_alert($this->_aModule['name'], 'before_parse_email_template', 0, 0, array('profile_id' => $iProfile, 'template' => $sTemplate, 'markers' => $aTemplateMarkers, 'notification' => $aNotification, 'override_result' => &$aTemplate));
  498. if(is_null($aTemplate))
  499. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sTemplate, $aTemplateMarkers, 0, $iProfile);
  500. if(!$aTemplate)
  501. return false;
  502. $sEmail = BxDolProfileQuery::getInstance()->getEmailById($iProfile);
  503. $sSubject = !empty($aSettings['subject']) ? $aSettings['subject'] : $aTemplate['Subject'];
  504. return sendMail($sEmail, $sSubject, $aTemplate['Body'], 0, array(), BX_EMAIL_NOTIFY, 'html', false, array(), true);
  505. }
  506. public function sendNotificationPush($iProfile, $aNotification)
  507. {
  508. if(!$iProfile)
  509. return false;
  510. $aContent = &$aNotification['content'];
  511. $aSettings = &$aNotification['settings'];
  512. $sSubject = !empty($aSettings['subject']) ? $aSettings['subject'] : _t('_bx_ntfs_push_new_event_subject', getParam('site_title'));
  513. bx_alert($this->_aModule['name'], 'before_send_notification_push', 0, 0, array('profile_id' => $iProfile, 'content' => &$aContent, 'setting' => &$aSettings, 'subject' => &$sSubject));
  514. return BxDolPush::getInstance()->send($iProfile, array(
  515. 'contents' => array(
  516. 'en' => $aContent['message']
  517. ),
  518. 'headings' => array(
  519. 'en' => $sSubject
  520. ),
  521. 'url' => $aContent['url'],
  522. 'icon' => $aContent['icon']
  523. ), true);
  524. }
  525. public function groupEvents(&$aEvents)
  526. {
  527. //--- Check for Visual Grouping
  528. $aGroups = [];
  529. foreach($aEvents as $iIndex => $aEvent) {
  530. if(empty($aEvent['source']))
  531. continue;
  532. $sSource = $aEvent['source'];
  533. if(!isset($aGroups[$sSource]))
  534. $aGroups[$sSource] = [];
  535. $aGroups[$sSource][$iIndex] = $aEvent['priority'];
  536. }
  537. //--- Perform Visual Grouping
  538. foreach($aGroups as $sSource => $aGroup) {
  539. if(!is_array($aGroup) || count($aGroup) < 2)
  540. continue;
  541. arsort($aGroup);
  542. $iPriorityMax = reset($aGroup);
  543. foreach($aGroup as $iIndex => $iPriority)
  544. if($iPriority != $iPriorityMax)
  545. unset($aEvents[$iIndex]);
  546. }
  547. }
  548. /*
  549. * INTERNAL METHODS
  550. */
  551. protected function _prepareParams($sType = '', $iOwnerId = 0, $iStart = -1, $iPerPage = -1, $aModules = [])
  552. {
  553. $iUserId = $this->getUserId();
  554. $iOwnerId = (int)$iOwnerId != 0 ? $iOwnerId : $iUserId;
  555. $aParams = [
  556. 'browse' => 'list',
  557. 'type' => !empty($sType) ? $sType : BX_NTFS_TYPE_DEFAULT,
  558. 'owner_id' => $iOwnerId,
  559. 'start' => (int)$iStart > 0 ? $iStart : 0,
  560. 'start_from_item' => false,
  561. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  562. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : [],
  563. 'last_read' => $this->_oDb->getLastRead($iOwnerId),
  564. 'viewer_id' => $iUserId,
  565. 'active' => 1
  566. ];
  567. return $aParams;
  568. }
  569. protected function _prepareParamsGet()
  570. {
  571. $aParams = [];
  572. $aParams['browse'] = 'list';
  573. $sType = bx_get('type');
  574. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_NTFS_TYPE_DEFAULT;
  575. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  576. $iStart = bx_get('start');
  577. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  578. $aParams['start_from_item'] = false;
  579. $iPerPage = bx_get('per_page');
  580. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  581. $aModules = bx_get('modules');
  582. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : [];
  583. $iViewerId = $this->getUserId();
  584. if(($aParams['viewer_id'] = bx_get('viewer_id')) !== false)
  585. $aParams['viewer_id'] = bx_process_input($aParams['viewer_id'], BX_DATA_INT);
  586. if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
  587. $aParams['viewer_id'] = $iViewerId;
  588. $aParams['active'] = 1;
  589. return $aParams;
  590. }
  591. }
  592. /** @} */