BxBaseStudioMenu.php 2.7 KB

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