BxBaseStudioMenu.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 BxBaseStudioMenu extends BxDolStudioMenu
  11. {
  12. protected $_bMenuSide;
  13. protected $_bInlineIcons;
  14. protected $_sIconBgUrl;
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. parent::__construct ($aObject, $oTemplate);
  18. $this->_bMenuSide = $this->_aObject['template'] == 'menu_side.html';
  19. $this->_bInlineIcons = in_array($this->_aObject['template'], array(
  20. 'menu_side.html',
  21. 'menu_top_toolbar.html',
  22. 'menu_launcher_browser.html',
  23. 'page_breadcrumb.html'
  24. ));
  25. $this->_sIconBgUrl = $this->_oTemplate->getIconUrl('mi-empty.svg');
  26. }
  27. public function setInlineIcons($bInlineIcons)
  28. {
  29. $this->_bInlineIcons = $bInlineIcons;
  30. }
  31. protected function _getMenuItem ($aItem)
  32. {
  33. $aItem = parent::_getMenuItem($aItem);
  34. if($aItem === false)
  35. return $aItem;
  36. $aItem['class'] = isset($aItem['class']) ? $aItem['class'] : '';
  37. if($this->_bInlineIcons && $aItem['bx_if:image']['condition'] && strpos($aItem['icon'], '.svg') !== false) {
  38. $aItem = array_merge($aItem, array(
  39. 'bx_if:image' => array (
  40. 'condition' => false,
  41. 'content' => array(),
  42. ),
  43. 'bx_if:image_inline' => array (
  44. 'condition' => true,
  45. 'content' => array(
  46. 'image' => file_get_contents($this->_oTemplate->getIconPath($aItem['icon']))
  47. ),
  48. ),
  49. ));
  50. }
  51. if($this->_bMenuSide) {
  52. $aItem['bx_if:show_icon'] = [
  53. 'condition' => $aItem['bx_if:icon']['condition'] || $aItem['bx_if:image']['condition'] || $aItem['bx_if:image_inline']['condition'],
  54. 'content' => []
  55. ];
  56. $aItem['bx_if:show_icon_bg'] = [
  57. 'condition' => isset($aItem['icon_bg']) && $aItem['icon_bg'] === true,
  58. 'content' => [
  59. 'icon_bg_url' => $this->_sIconBgUrl
  60. ]
  61. ];
  62. }
  63. return $aItem;
  64. }
  65. /**
  66. * Check if menu items is selected.
  67. * @param $a menu item array
  68. * @return boolean
  69. */
  70. protected function _isSelected ($a)
  71. {
  72. return isset($a['selected']) && $a['selected'] === true;
  73. }
  74. }
  75. /** @} */