BxBaseStudioWidgets.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 BxBaseStudioWidgets extends BxDolStudioWidgets
  11. {
  12. public function __construct($mixedPageName)
  13. {
  14. parent::__construct($mixedPageName);
  15. }
  16. public function getPageMenu($aMenu = array(), $aMarkers = array())
  17. {
  18. $aTypes = parent::getPageTypes();
  19. $iAccountId = getLoggedId();
  20. $oUtils = BxDolStudioRolesUtils::getInstance();
  21. $aMenuItems = array();
  22. foreach($aTypes as $sName => $aType) {
  23. if(!$oUtils->isActionAllowed('use ' . $sName, $iAccountId))
  24. continue;
  25. $aTypeData = unserialize($aType['Data']);
  26. $aMenuItems[] = array(
  27. 'name' => $sName,
  28. 'title' => _t($aType['LKey']),
  29. 'link' => bx_append_url_params($this->sPageUrl, array(
  30. 'type' => $sName
  31. )),
  32. 'icon' => !empty($aTypeData['icon']) ? $aTypeData['icon'] : '',
  33. 'selected' => $sName == $this->_sType
  34. );
  35. }
  36. return parent::getPageMenu($aMenuItems);
  37. }
  38. public function getPageCode()
  39. {
  40. $sResult = parent::getPageCode();
  41. if($sResult === false)
  42. return false;
  43. if(!$this->bPageMultiple)
  44. return $this->wrapWidgets($this->aPage['name'], $this->getWidgets($this->aPage['name'], $this->aWidgets));
  45. $sContent = "";
  46. foreach($this->aWidgets as $sPage => $aWidgets)
  47. $sContent .= $this->wrapWidgets($sPage, $this->getWidgets($sPage, $aWidgets), $sPage != $this->sPageSelected);
  48. return $sContent;
  49. }
  50. public function getPageCaption()
  51. {
  52. if(empty($this->aPage) || !is_array($this->aPage))
  53. return '';
  54. //--- Menu Right ---//
  55. $aItemsRight = array(
  56. 'template' => 'menu_top_toolbar.html',
  57. 'menu_items' => array(
  58. 'site' => array(
  59. 'name' => 'site',
  60. 'icon' => 'tmi-site.svg',
  61. 'link' => '{url_root}',
  62. 'title' => '_adm_tmi_cpt_site'
  63. ),
  64. 'tour' => array(
  65. 'name' => 'tour',
  66. 'icon' => 'tmi-help.svg',
  67. 'link' => 'javascript:void(0);',
  68. 'onclick' => 'glTour.start()',
  69. 'title' => '_adm_tmi_cpt_tour'
  70. ),
  71. 'account' => array(
  72. 'name' => 'account',
  73. 'icon' => 'tmi-account.svg',
  74. 'link' => 'javascript:void(0);',
  75. 'onclick' => 'bx_menu_popup(\'sys_studio_account_popup\', this);',
  76. 'title' => '_adm_tmi_cpt_account'
  77. )
  78. )
  79. );
  80. $oTopMenu = BxTemplStudioMenuTop::getInstance();
  81. $oTopMenu->setContent(BX_DOL_STUDIO_MT_RIGHT, $aItemsRight);
  82. return '';
  83. }
  84. protected function wrapWidgets($sName, $sContent, $bHidden = false)
  85. {
  86. return BxDolStudioTemplate::getInstance()->parseHtmlByName('widgets_page.html', array(
  87. 'page' => $sName,
  88. 'bx_if:page_hidden' => array(
  89. 'condition' => $bHidden,
  90. 'content' => array()
  91. ),
  92. 'content' => $sContent
  93. ));
  94. }
  95. protected function getWidgets($sPage, $aWidgets)
  96. {
  97. $oFunction = BxTemplStudioFunctions::getInstance();
  98. $aTmplVars = array();
  99. foreach($aWidgets as $aWidget) {
  100. $sWidget = $oFunction->getWidget($aWidget, $this->aWidgetsNotices);
  101. if(empty($sWidget))
  102. continue;
  103. $aTmplVars[] = array(
  104. 'widget' => $sWidget,
  105. );
  106. }
  107. return BxDolStudioTemplate::getInstance()->parseHtmlByName('widgets.html', array(
  108. 'bx_repeat:widgets' => $aTmplVars
  109. ));
  110. }
  111. }
  112. /** @} */