BxBaseModNotificationsStudioPage.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 BaseNotifications Base classes for Notifications like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModNotificationsStudioPage extends BxTemplStudioModule
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct($sModule, $mixedPageName, $sPage = "")
  16. {
  17. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  18. parent::__construct($sModule, $mixedPageName, $sPage);
  19. }
  20. public function checkAction()
  21. {
  22. $sAction = bx_get($this->sParamPrefix . '_action');
  23. if($sAction === false)
  24. return false;
  25. if(empty($this->aModule) || !is_array($this->aModule))
  26. return array('code' => 1, 'message' => _t('_sys_request_page_not_found_cpt'));
  27. $sAction = bx_process_input($sAction);
  28. $aResult = array('code' => 2, 'message' => _t('_adm_mod_err_cannot_process_action'));
  29. switch($sAction) {
  30. case 'reinit':
  31. $aConfig = BxDolInstallerUtils::getModuleConfig($this->_oModule->_aModule);
  32. if(empty($aConfig) || !is_array($aConfig))
  33. break;
  34. $oInstallerDb = bx_instance('BxDolStudioInstallerQuery');
  35. $aRelation = $oInstallerDb->getRelationsBy(array('type' => 'module', 'value' => $aConfig['name']));
  36. if(empty($aRelation))
  37. break;
  38. $aOperations = ['disable', 'enable'];
  39. foreach($aOperations as $sOperation) {
  40. if(empty($aRelation['on_' . $sOperation]))
  41. break 2;
  42. $sHandlersMethod = isset($aConfig['relation_handlers_method']) ? $aConfig['relation_handlers_method'] : '';
  43. $aModules = $oInstallerDb->getModulesBy(array('type' => 'all', 'active' => 1));
  44. foreach($aModules as $aModule) {
  45. $aModuleConfig = BxDolInstallerUtils::getModuleConfig($aModule);
  46. if(!empty($aModuleConfig['relations']) && is_array($aModuleConfig['relations']) && in_array($aConfig['name'], $aModuleConfig['relations']))
  47. bx_srv_ii($aConfig['name'], $aRelation['on_' . $sOperation], [$aModule['uri']]);
  48. else if($sHandlersMethod && bx_is_srv($aModule['name'], $sHandlersMethod) && (bx_srv('system', 'is_module_content', [$aModule['name']]) || bx_srv('system', 'is_module_context', [$aModule['name']])))
  49. bx_srv_ii($aConfig['name'], $aRelation['on_' . $sOperation], [$aModule['uri']]);
  50. }
  51. }
  52. $aResult = ['code' => 0, 'message' => _t('_adm_txt_modules_process_action_success')];
  53. break;
  54. default:
  55. $aResult = parent::checkAction();
  56. }
  57. return $aResult;
  58. }
  59. }
  60. /** @} */