BxNtfsModule.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_DEFAULT', BX_BASE_MOD_NTFS_TYPE_CONNECTIONS);
  14. class BxNtfsModule extends BxBaseModNotificationsModule
  15. {
  16. /**
  17. * Constructor
  18. */
  19. function __construct($aModule)
  20. {
  21. parent::__construct($aModule);
  22. $this->_iOwnerId = $this->getUserId();
  23. }
  24. /**
  25. * ACTION METHODS
  26. */
  27. function actionGetPosts()
  28. {
  29. $aParams = $this->_prepareParamsGet();
  30. $sEvents = $this->_oTemplate->getPosts($aParams);
  31. echoJson(array('events' => $sEvents));
  32. }
  33. /**
  34. * SERVICE METHODS
  35. *
  36. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  37. */
  38. public function serviceGetBlockView($sType = '', $iStart = -1, $iPerPage = -1, $aModules = array())
  39. {
  40. $aBrowseTypes = array(BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, BX_BASE_MOD_NTFS_TYPE_OBJECT_OWNER);
  41. if(empty($sType)) {
  42. $mType = bx_get('type');
  43. if($mType !== false && in_array($mType, $aBrowseTypes))
  44. $sType = $mType;
  45. if(empty($sType))
  46. $sType = BX_NTFS_TYPE_DEFAULT;
  47. }
  48. $iOwnerId = $this->getUserId();
  49. if(!$iOwnerId)
  50. return array('content' => MsgBox(_t('_bx_ntfs_txt_msg_no_results')));
  51. $aParams = $this->_prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $aModules);
  52. $sContent = $this->_oTemplate->getViewBlock($aParams);
  53. $aParams['browse'] = 'first';
  54. $aEvent = $this->_oDb->getEvents($aParams);
  55. if(!empty($aEvent))
  56. $this->_oDb->markAsRead($iOwnerId, $aEvent['id']);
  57. $sModule = $this->_oConfig->getName();
  58. $sJsObject = $this->_oConfig->getJsObject('view');
  59. $aMenu = array();
  60. foreach($aBrowseTypes as $sBrowseType)
  61. $aMenu[] = array(
  62. 'id' => $sModule . '-' . $sBrowseType,
  63. 'name' => $sModule . '-' . $sBrowseType,
  64. 'class' => '',
  65. 'title' => '_bx_ntfs_menu_item_title_' . $sBrowseType,
  66. 'target' => '_self',
  67. 'onclick' => 'javascript:' . $sJsObject . '.changeType(this, \'' . $sBrowseType . '\');'
  68. );
  69. $oMenu = new BxTemplMenuInteractive(array(
  70. 'template' => 'menu_interactive_vertical.html',
  71. 'menu_id' => $sModule . '-browse-types',
  72. 'menu_items' => $aMenu
  73. ), $this->_oTemplate);
  74. $oMenu->setSelected($sModule, $sModule . '-' . $sType);
  75. return array('content' => $sContent, 'menu' => $oMenu);
  76. }
  77. public function serviceGetEventById($iId)
  78. {
  79. $aParams = array(
  80. 'browse' => 'id',
  81. 'value' => $iId,
  82. );
  83. return $this->_oDb->getEvents($aParams);
  84. }
  85. public function serviceGetUnreadNotificationsNum($iOwnerId = 0)
  86. {
  87. if(!$iOwnerId)
  88. $iOwnerId = $this->getUserId();
  89. if(!$iOwnerId)
  90. return 0;
  91. $aParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId);
  92. $aParams['new'] = 1;
  93. list($aEvent, $iCount) = $this->_oDb->getEvents($aParams, true);
  94. return $iCount;
  95. }
  96. /*
  97. * COMMON METHODS
  98. */
  99. public function setSubmenu($sSelected)
  100. {
  101. $oSubmenuSystem = BxDolMenu::getObjectInstance('sys_site_submenu');
  102. if(!$oSubmenuSystem)
  103. return;
  104. $CNF = &$this->_oConfig->CNF;
  105. $oSubmenuSystem->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU'], array (
  106. 'title' => _t('_bx_ntfs'),
  107. 'link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  108. 'icon' => '',
  109. ));
  110. $oSubmenuModule = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU']);
  111. if($oSubmenuModule)
  112. $oSubmenuModule->setSelected($this->_oConfig->getName(), $sSelected);
  113. }
  114. public function onPost($iId)
  115. {
  116. //--- Event -> Post for Alerts Engine ---//
  117. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post', $iId);
  118. $oAlert->alert();
  119. //--- Event -> Post for Alerts Engine ---//
  120. }
  121. protected function _prepareParams($sType = '', $iOwnerId = 0, $iStart = -1, $iPerPage = -1, $aModules = array())
  122. {
  123. $aParams = array();
  124. $aParams['browse'] = 'list';
  125. $aParams['type'] = !empty($sType) ? $sType : BX_NTFS_TYPE_DEFAULT;
  126. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  127. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  128. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  129. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  130. $aParams['active'] = 1;
  131. return $aParams;
  132. }
  133. protected function _prepareParamsGet()
  134. {
  135. $aParams = array();
  136. $aParams['browse'] = 'list';
  137. $sType = bx_get('type');
  138. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_NTFS_TYPE_DEFAULT;
  139. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  140. $iStart = bx_get('start');
  141. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  142. $iPerPage = bx_get('per_page');
  143. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  144. $aModules = bx_get('modules');
  145. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  146. $aParams['active'] = 1;
  147. return $aParams;
  148. }
  149. }
  150. /** @} */