1
0

BxBaseStudioModule.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioModule extends BxDolStudioModule
  11. {
  12. protected $oHelper;
  13. protected $aMenuItems = array(
  14. BX_DOL_STUDIO_MOD_TYPE_SETTINGS => array('name' => BX_DOL_STUDIO_MOD_TYPE_SETTINGS, 'icon' => 'mi-cog.svg', 'icon_bg' => true, 'title' => '_adm_lmi_cpt_settings')
  15. );
  16. protected $sTmplNamePopupSettings;
  17. protected $sTmplNamePopupConfirmUninstall;
  18. function __construct($sModule, $mixedPageName, $sPage = "")
  19. {
  20. parent::__construct($sModule, $mixedPageName, $sPage);
  21. $this->oHelper = BxTemplStudioModules::getInstance();
  22. $this->sTmplNamePopupSettings = 'mod_popup_settings.html';
  23. $this->sTmplNamePopupConfirmUninstall = 'mod_popup_confirm_uninstall.html';
  24. }
  25. function getPageCss()
  26. {
  27. return array_merge(parent::getPageCss(), $this->oHelper->getCss());
  28. }
  29. function getPageJs()
  30. {
  31. return array_merge(parent::getPageJs(), $this->oHelper->getJs());
  32. }
  33. function getPageJsClass()
  34. {
  35. return $this->oHelper->getJsClass();
  36. }
  37. function getPageJsObject()
  38. {
  39. return $this->oHelper->getJsObject();
  40. }
  41. function getPageJsCode($aParams = array(), $mixedWrap = true)
  42. {
  43. return $this->oHelper->getJsCode($aParams, $mixedWrap);
  44. }
  45. function getPageCaption()
  46. {
  47. return BxDolStudioTemplate::getInstance()->parseHtmlByName('mod_page_caption.html', array(
  48. 'js_object' => $this->getPageJsObject(),
  49. 'content' => parent::getPageCaption(),
  50. 'js_code' => $this->getPageJsCode()
  51. ));
  52. }
  53. function getPageAttributes()
  54. {
  55. if($this->_bShowHeaderBreadcrumb && (int)$this->aModule['enabled'] == 0)
  56. return 'style="display:none"';
  57. return parent::getPageAttributes();
  58. }
  59. function getPageMenu($aMenu = array(), $aMarkers = array())
  60. {
  61. $sJsObject = $this->getPageJsObject();
  62. $aMenu = [];
  63. if((int)$this->aModule['enabled'] != 0)
  64. foreach($this->aMenuItems as $sName => $aItem)
  65. $aMenu[] = array_merge($aItem, [
  66. 'name' => $sName,
  67. 'link' => isset($aItem['link']) ? $aItem['link'] : bx_append_url_params($this->sManageUrl, ['page' => $sName]),
  68. 'title' => _t(!empty($aItem['title']) ? $aItem['title'] : $aItem['caption']),
  69. 'selected' => $sName == $this->sPage
  70. ]);
  71. return parent::getPageMenu($aMenu);
  72. }
  73. public function getPageCode($sPage = '', $bWrap = true)
  74. {
  75. if((int)$this->aModule['enabled'] == 0)
  76. return '';
  77. return parent::getPageCode($sPage, $bWrap);
  78. }
  79. protected function getSettings()
  80. {
  81. $oOptions = new BxTemplStudioOptions($this->sModule);
  82. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  83. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  84. return BxDolStudioTemplate::getInstance()->parseHtmlByName('module.html', array(
  85. 'content' => $oOptions->getCode(),
  86. ));
  87. }
  88. protected function getPopupSettings($sPage, $iWidgetId)
  89. {
  90. $sActions = $this->getPageActions($iWidgetId);
  91. if(empty($sActions))
  92. return '';
  93. $sPrefix = 'bx-std-mod-popup-settings';
  94. $sName = $sPrefix . '-' . $sPage;
  95. $sContent = BxDolStudioTemplate::getInstance()->parseHtmlByName($this->sTmplNamePopupSettings, array(
  96. 'content' => $sActions
  97. ));
  98. return BxTemplStudioFunctions::getInstance()->transBox($sName, array(
  99. 'wrapper_class' => $sPrefix . '-wrapper',
  100. 'content' => $sContent
  101. ));
  102. }
  103. /**
  104. * The page's context menu (see BxBaseStudioWidget::getPageContextMenu) in the popup wrapper the context menu script expects,
  105. * named after the page so a tile and a dock item of the same app share it.
  106. */
  107. protected function getPopupContextMenu($sPage, $iWidgetId)
  108. {
  109. $sMenu = $this->getPageContextMenu($iWidgetId);
  110. if(empty($sMenu))
  111. return '';
  112. return BxTemplStudioFunctions::getInstance()->transBox('bx-std-cmenu-' . $sPage, array(
  113. 'wrapper_class' => 'bx-std-context-wrapper',
  114. 'wrapper_role' => 'presentation',
  115. 'content' => $sMenu
  116. ), true);
  117. }
  118. protected function getPopupConfirmUninstall($iWidgetId, &$aModule)
  119. {
  120. $sJsObject = $this->getPageJsObject();
  121. $sName = 'bx-std-mod-popup-confirm';
  122. $sContent = BxDolStudioTemplate::getInstance()->parseHtmlByName($this->sTmplNamePopupConfirmUninstall, array(
  123. 'content' => _t('_adm_' . $this->sLangPrefix . '_cnf_uninstall', $aModule['title']),
  124. 'click' => $sJsObject . ".uninstall('" . $aModule['name'] . "', " . $iWidgetId . ", 1)"
  125. ));
  126. return BxTemplStudioFunctions::getInstance()->transBox($sName, $sContent);
  127. }
  128. }
  129. /** @} */