BxNtfsModule.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php use nspace\func;
  2. defined('BX_DOL') or die('hack attempt');
  3. /**
  4. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  6. *
  7. * @defgroup Notifications Notifications
  8. * @ingroup DolphinModules
  9. *
  10. * @{
  11. */
  12. bx_import('BxDolAcl');
  13. bx_import('BxBaseModNotificationsModule');
  14. define('BX_NTFS_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_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. $this->_echoResultJson(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($iStart = -1, $iPerPage = -1, $aModules = array())
  40. {
  41. $iOwnerId = $this->getUserId();
  42. if(!$iOwnerId)
  43. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  44. $aParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId, $iStart, $iPerPage, $aModules);
  45. $sContent = $this->_oTemplate->getViewBlock($aParams);
  46. $aParams['browse'] = 'first';
  47. $aEvent = $this->_oDb->getEvents($aParams);
  48. if(!empty($aEvent))
  49. $this->_oDb->markAsRead($iOwnerId, $aEvent['id']);
  50. return array('content' => $sContent);
  51. }
  52. public function serviceGetUnreadNotificationsNum($iOwnerId = 0)
  53. {
  54. if(!$iOwnerId)
  55. $iOwnerId = $this->getUserId();
  56. if(!$iOwnerId)
  57. return 0;
  58. $aParams = $this->_prepareParams(BX_NTFS_TYPE_DEFAULT, $iOwnerId);
  59. $aParams['new'] = 1;
  60. list($aEvent, $iCount) = $this->_oDb->getEvents($aParams, true);
  61. return $iCount;
  62. }
  63. /*
  64. * COMMON METHODS
  65. */
  66. public function onPost($iId)
  67. {
  68. //--- Event -> Post for Alerts Engine ---//
  69. bx_import('BxDolAlerts');
  70. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post', $iId);
  71. $oAlert->alert();
  72. //--- Event -> Post for Alerts Engine ---//
  73. }
  74. protected function _prepareParams($sType = '', $iOwnerId = 0, $iStart = -1, $iPerPage = -1, $aModules = array())
  75. {
  76. $aParams = array();
  77. $aParams['browse'] = 'list';
  78. $aParams['type'] = !empty($sType) ? $sType : BX_NTFS_TYPE_DEFAULT;
  79. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  80. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  81. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  82. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  83. $aParams['active'] = 1;
  84. return $aParams;
  85. }
  86. protected function _prepareParamsGet()
  87. {
  88. $aParams = array();
  89. $aParams['browse'] = 'list';
  90. $sType = bx_get('type');
  91. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_NTFS_TYPE_DEFAULT;
  92. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  93. $iStart = bx_get('start');
  94. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  95. $iPerPage = bx_get('per_page');
  96. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  97. $aModules = bx_get('modules');
  98. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  99. return $aParams;
  100. }
  101. }
  102. /** @} */