BxBaseMenuToolbar.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseMenuToolbar extends BxTemplMenu
  14. {
  15. protected $_sUnitSize;
  16. public function __construct ($aObject, $oTemplate)
  17. {
  18. parent::__construct ($aObject, $oTemplate);
  19. $this->_sUnitSize = 'icon';
  20. }
  21. public function getMenuItems ()
  22. {
  23. $a = parent::getMenuItems ();
  24. if (!isLogged())
  25. return $a;
  26. foreach ($a as $k => $r) {
  27. if($r['name'] != 'account')
  28. continue;
  29. if($a[$k]['bx_if:image']['condition'] || $a[$k]['bx_if:icon-html']['condition'])
  30. break;
  31. $oProfile = BxDolProfile::getInstance(bx_get_logged_profile_id());
  32. $sUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => $this->_sUnitSize)));
  33. if(!empty($sUnit)) {
  34. $a[$k]['bx_if:icon']['condition'] = false;
  35. $a[$k]['bx_if:unit'] = array (
  36. 'condition' => true,
  37. 'content' => array('unit' => $sUnit),
  38. );
  39. break;
  40. }
  41. $sThumb = $oProfile->getThumb();
  42. if(!empty($sThumb)) {
  43. $a[$k]['bx_if:icon']['condition'] = false;
  44. $a[$k]['bx_if:image'] = array (
  45. 'condition' => true,
  46. 'content' => array('icon_url' => $sThumb),
  47. );
  48. break;
  49. }
  50. }
  51. return $a;
  52. }
  53. protected function _getMenuItem ($a)
  54. {
  55. $a = parent::_getMenuItem ($a);
  56. if($a === false)
  57. return $a;
  58. $a['bx_if:unit'] = array(
  59. 'condition' => false,
  60. 'content' => array()
  61. );
  62. if ('add-content' == $a['name'] || 'search' == $a['name'])
  63. $a['class_add'] .= ' bx-def-media-phone-hide';
  64. return $a;
  65. }
  66. protected function _getMenuAttrs ($aMenuItem)
  67. {
  68. $sAttrs = parent::_getMenuAttrs($aMenuItem);
  69. if($aMenuItem['name'] == 'apps')
  70. $sAttrs .= ' data-dropdown-toggle="sys-menu-apps"';
  71. return $sAttrs;
  72. }
  73. protected function _getTmplVarsAddon($mixedAddon, $aMenuItem)
  74. {
  75. $aAddon = parent::_getTmplVarsAddon($mixedAddon, $aMenuItem);
  76. $sAddonF = '';
  77. if(!empty($aAddon['addon']))
  78. $sAddonF = $this->_oTemplate->parseHtmlByTemplateName('menu_item_addon', array(
  79. 'content' => $aAddon['addon']
  80. ));
  81. return array(
  82. 'addon' => $aAddon['addon'],
  83. 'addonf' => $sAddonF
  84. );
  85. }
  86. }
  87. /** @} */