BxNtfsModule.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php use nspace\func;
  2. defined('BX_DOL') or die('hack attempt');
  3. /**
  4. * Copyright (c) UNA, Inc - https://una.io
  5. * MIT License - https://opensource.org/licenses/MIT
  6. *
  7. * @defgroup Notifications Notifications
  8. * @ingroup UnaModules
  9. *
  10. * @{
  11. */
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS', 'obj_own_and_con');
  14. define('BX_NTFS_TYPE_DEFAULT', BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS);
  15. class BxNtfsModule extends BxBaseModNotificationsModule
  16. {
  17. /**
  18. * Constructor
  19. */
  20. function __construct($aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iOwnerId = $this->getUserId();
  24. }
  25. /**
  26. * ACTION METHODS
  27. */
  28. function actionGetPosts()
  29. {
  30. $aParams = $this->_prepareParamsGet();
  31. $sEvents = $this->_oTemplate->getPosts($aParams);
  32. echoJson(array('events' => $sEvents));
  33. }
  34. /**
  35. * SERVICE METHODS
  36. *
  37. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  38. */
  39. public function serviceGetBlockView($sType = '', $iStart = -1, $iPerPage = -1, $aModules = array())
  40. {
  41. $aBrowseTypes = array(BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, BX_BASE_MOD_NTFS_TYPE_OBJECT_OWNER);
  42. if(empty($sType)) {
  43. $mixedType = bx_get('type');
  44. if($mixedType !== false && in_array($mixedType, $aBrowseTypes))
  45. $sType = $mixedType;
  46. if(empty($sType))
  47. $sType = BX_NTFS_TYPE_DEFAULT;
  48. }
  49. $iOwnerId = $this->getUserId();
  50. if(!$iOwnerId)
  51. return array('content' => MsgBox(_t('_bx_ntfs_txt_msg_no_results')));
  52. $aParams = $this->_prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $aModules);
  53. $sContent = $this->_oTemplate->getViewBlock($aParams);
  54. $aParams['browse'] = 'first';
  55. $aEvent = $this->_oDb->getEvents($aParams);
  56. if(!empty($aEvent))
  57. $this->_oDb->markAsRead($iOwnerId, $aEvent['id']);
  58. $sModule = $this->_oConfig->getName();
  59. $sJsObject = $this->_oConfig->getJsObject('view');
  60. return array('content' => $sContent);
  61. }
  62. public function serviceGetEventById($iId)
  63. {
  64. $aParams = array(
  65. 'browse' => 'id',
  66. 'value' => $iId,
  67. );
  68. return $this->_oDb->getEvents($aParams);
  69. }
  70. public function serviceGetUnreadNotificationsNum($iOwnerId = 0)
  71. {
  72. if(!$iOwnerId)
  73. $iOwnerId = $this->getUserId();
  74. if(!$iOwnerId)
  75. return 0;
  76. $aParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId);
  77. $aParams['new'] = 1;
  78. list($aEvent, $iCount) = $this->_oDb->getEvents($aParams, true);
  79. return $iCount;
  80. }
  81. public function serviceGetLiveUpdates($aMenuItemParent, $aMenuItemChild, $iCount = 0)
  82. {
  83. $iOwnerId = $this->getUserId();
  84. $iCountNew = $this->serviceGetUnreadNotificationsNum($iOwnerId);
  85. if($iCountNew == $iCount)
  86. return false;
  87. return array(
  88. 'count' => $iCountNew, // required
  89. 'method' => 'bx_menu_show_live_update(oData)', // required
  90. 'data' => array(
  91. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  92. 'content' => '{count}'
  93. )),
  94. 'mi_parent' => $aMenuItemParent,
  95. 'mi_child' => $aMenuItemChild
  96. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  97. );
  98. }
  99. /*
  100. * COMMON METHODS
  101. */
  102. public function setSubmenu($sSelected)
  103. {
  104. $oSubmenuSystem = BxDolMenu::getObjectInstance('sys_site_submenu');
  105. if(!$oSubmenuSystem)
  106. return;
  107. $CNF = &$this->_oConfig->CNF;
  108. $oSubmenuSystem->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU'], array (
  109. 'title' => _t('_bx_ntfs'),
  110. 'link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  111. 'icon' => '',
  112. ));
  113. $oSubmenuModule = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU']);
  114. if($oSubmenuModule)
  115. $oSubmenuModule->setSelected($this->_oConfig->getName(), $sSelected);
  116. }
  117. public function onPost($iId)
  118. {
  119. //--- Event -> Post for Alerts Engine ---//
  120. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post', $iId);
  121. $oAlert->alert();
  122. //--- Event -> Post for Alerts Engine ---//
  123. }
  124. protected function _prepareParams($sType = '', $iOwnerId = 0, $iStart = -1, $iPerPage = -1, $aModules = array())
  125. {
  126. $aParams = array();
  127. $aParams['browse'] = 'list';
  128. $aParams['type'] = !empty($sType) ? $sType : BX_NTFS_TYPE_DEFAULT;
  129. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  130. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  131. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  132. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  133. $aParams['active'] = 1;
  134. return $aParams;
  135. }
  136. protected function _prepareParamsGet()
  137. {
  138. $aParams = array();
  139. $aParams['browse'] = 'list';
  140. $sType = bx_get('type');
  141. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_NTFS_TYPE_DEFAULT;
  142. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  143. $iStart = bx_get('start');
  144. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  145. $iPerPage = bx_get('per_page');
  146. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  147. $aModules = bx_get('modules');
  148. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  149. $aParams['active'] = 1;
  150. return $aParams;
  151. }
  152. }
  153. /** @} */