BxRemindersModule.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Reminders Reminders
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxRemindersModule extends BxBaseModGeneralModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. $this->_oConfig->init($this->_oDb);
  17. }
  18. public function actionMain()
  19. {
  20. return echoJson(array());
  21. }
  22. /**
  23. * Service methods
  24. */
  25. public function serviceGetOptionsSystemProfileId()
  26. {
  27. $aResult = array(
  28. array('key' => '', 'value' => _t('_Select_one'))
  29. );
  30. $oProfile = BxDolProfile::getInstance();
  31. $aAccIds = BxDolAccountQuery::getInstance()->getOperators();
  32. foreach($aAccIds as $iAccId) {
  33. $aPrfIds = BxDolAccount::getInstance($iAccId)->getProfilesIds();
  34. foreach($aPrfIds as $iPrfId) {
  35. $aResult[] = array(
  36. 'key' => $iPrfId,
  37. 'value' => $oProfile->getDisplayName($iPrfId)
  38. );
  39. }
  40. }
  41. return $aResult;
  42. }
  43. public function serviceGetBlockView($iProfileId = 0)
  44. {
  45. if(!isLogged())
  46. return '';
  47. if(!$iProfileId)
  48. $iProfileId = bx_get_logged_profile_id();
  49. return $this->_oTemplate->getBlockView($iProfileId);
  50. }
  51. public function serviceGetNotificationsData()
  52. {
  53. $sModule = $this->_aModule['name'];
  54. return array(
  55. 'handlers' => array(
  56. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => ''),
  57. ),
  58. 'settings' => array(
  59. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('personal')),
  60. ),
  61. 'alerts' => array(
  62. array('unit' => $sModule, 'action' => 'added'),
  63. )
  64. );
  65. }
  66. public function serviceGetNotificationsPost($aEvent)
  67. {
  68. $CNF = &$this->_oConfig->CNF;
  69. $aEntry = $this->_oDb->getEntry(array('type' => 'id', 'id' => $aEvent['object_id'], 'full' => true));
  70. if(empty($aEntry) || !is_array($aEntry))
  71. return array();
  72. $aReturn = array(
  73. 'entry_sample' => $CNF['T']['txt_sample_single'],
  74. 'entry_url' => bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $this->getEntryUrl($aEntry)), '{bx_url_root}'),
  75. 'lang_key' => $aEntry[$CNF['FIELD_TEXT']]
  76. );
  77. $aParams = unserialize($aEntry['params']);
  78. if(!empty($aParams) && is_array($aParams))
  79. $aReturn = array_merge($aReturn, $aParams);
  80. return $aReturn;
  81. }
  82. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  83. {
  84. return CHECK_ACTION_RESULT_ALLOWED;
  85. }
  86. /**
  87. * Permissions methods
  88. */
  89. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  90. {
  91. if(!$iProfileId)
  92. $iProfileId = $this->_iProfileId;
  93. if(empty($aDataEntry) || !is_array($aDataEntry))
  94. return _t('_sys_txt_not_found');
  95. $oProfile = BxDolProfile::getInstance($iProfileId);
  96. if(!$oProfile)
  97. return _t('_sys_txt_not_found');
  98. if(isAdmin($oProfile->getAccountId()))
  99. return CHECK_ACTION_RESULT_ALLOWED;
  100. $aCheckResult = checkActionModule($iProfileId, 'view', $this->getName(), $isPerformAction);
  101. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  102. return $aCheckResult[CHECK_ACTION_MESSAGE];
  103. return CHECK_ACTION_RESULT_ALLOWED;
  104. }
  105. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  106. {
  107. return _t('_sys_txt_access_denied');
  108. }
  109. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  110. {
  111. return _t('_sys_txt_access_denied');
  112. }
  113. /**
  114. * Auxiliary methods
  115. */
  116. public function getEntryUrl(&$aEntry)
  117. {
  118. $aParams = unserialize($aEntry['params']);
  119. $sResult = '';
  120. if(!empty($aEntry['link']))
  121. $sResult = bx_replace_markers($aEntry['link'], $aParams);
  122. else if(!empty($aParams['profile_link']))
  123. $sResult = $aParams['profile_link'];
  124. else if(!empty($aParams['profile_id']))
  125. $sResult = $oProfile->getUrl((int)$aParams['profile_id']);
  126. else
  127. $sResult = 'javascript:void(0)';
  128. return $sResult;
  129. }
  130. }
  131. /** @} */