BxAnalyticsStudioMenu.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 Analytics Analytics
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * The Studio side menu in sections (Traffic, Behavior, Conversion...). Each section's items are
  13. * drawn by Studio's own menu object, so they look and behave like any Studio menu; this class
  14. * only adds the section headings around them.
  15. */
  16. class BxAnalyticsStudioMenu
  17. {
  18. protected $_oTemplate;
  19. protected $_aSections;
  20. /**
  21. * @param object $oTemplate the module template
  22. * @param array $aSections list of ['name' => section name, 'title' => heading or '', 'menu' => Studio menu object]
  23. */
  24. public function __construct($oTemplate, $aSections)
  25. {
  26. $this->_oTemplate = $oTemplate;
  27. $this->_aSections = $aSections;
  28. }
  29. public function getCode()
  30. {
  31. $aSections = [];
  32. foreach($this->_aSections as $aSection)
  33. $aSections[] = [
  34. 'name' => $aSection['name'],
  35. 'bx_if:title' => [
  36. 'condition' => $aSection['title'] !== '',
  37. 'content' => [
  38. 'name' => $aSection['name'],
  39. 'title' => $aSection['title'],
  40. ],
  41. ],
  42. 'attrs' => $aSection['title'] !== '' ? 'role="group" aria-labelledby="bx-analytics-std-menu-' . $aSection['name'] . '"' : '',
  43. 'menu' => $aSection['menu']->getCode(),
  44. ];
  45. return $this->_oTemplate->parseHtmlByName('studio_menu.html', [
  46. 'bx_repeat:sections' => $aSections,
  47. ]);
  48. }
  49. }
  50. /** @} */