BxAnalyticsStudioPage.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * Studio page of the module: every report section in a side menu grouped like the reports
  13. * themselves (traffic, behavior, conversion, revenue, health, community, explore), then setup
  14. * and settings. A section shows the same block services the site's page builder offers, with
  15. * the filter bar on top, so a report looks and counts the same in Studio and on any page.
  16. */
  17. class BxAnalyticsStudioPage extends BxTemplStudioModule
  18. {
  19. protected $_sModule;
  20. protected $_oModule;
  21. protected $sPageDefault = 'overview';
  22. /**
  23. * Section => [page => Lucide glyph]. The empty section has no heading.
  24. */
  25. protected $_aSections = [
  26. '' => ['overview' => 'chart-line'],
  27. 'traffic' => ['realtime' => 'zap', 'pages' => 'file-text', 'sources' => 'share-2', 'audience' => 'users', 'map' => 'earth', 'bots' => 'bot'],
  28. 'behavior' => ['sessions' => 'history', 'users' => 'user', 'events' => 'mouse-pointer-click'],
  29. 'conversion' => ['goals' => 'target', 'funnels' => 'funnel', 'journeys' => 'route', 'retention' => 'repeat'],
  30. 'revenue' => ['revenue' => 'circle-dollar-sign', 'subscriptions' => 'refresh-cw', 'sales' => 'shopping-cart', 'credits' => 'coins'],
  31. 'health' => ['errors' => 'triangle-alert', 'performance' => 'gauge'],
  32. 'community' => ['content' => 'layers'],
  33. 'explore' => ['query' => 'database', 'api' => 'code', 'dashboards' => 'layout-dashboard'],
  34. 'configure' => ['setup' => 'plug', 'settings' => 'settings'],
  35. ];
  36. public function __construct($sModule, $mixedPageName, $sPage = "")
  37. {
  38. $this->_sModule = 'bx_analytics';
  39. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  40. parent::__construct($sModule, $mixedPageName, $sPage);
  41. $aSettings = $this->aMenuItems[BX_DOL_STUDIO_MOD_TYPE_SETTINGS];
  42. $this->aMenuItems = [];
  43. foreach($this->_aSections as $aPages)
  44. foreach($aPages as $sPage => $sIcon)
  45. $this->aMenuItems[$sPage] = $sPage == BX_DOL_STUDIO_MOD_TYPE_SETTINGS ? $aSettings : [
  46. 'name' => $sPage,
  47. 'icon' => '',
  48. 'lucide' => $sIcon,
  49. 'title' => '_bx_analytics_lmi_cpt_' . $sPage,
  50. ];
  51. }
  52. /**
  53. * The side menu in sections, each drawn by Studio's own menu object.
  54. */
  55. protected function getPageMenuObject($aMenu = [], $aMarkers = [])
  56. {
  57. $this->_oModule->_oTemplate->addStudioCss(['studio.css']);
  58. bx_import('StudioMenu', $this->_oModule->_aModule);
  59. bx_import('StudioMenuItems', $this->_oModule->_aModule);
  60. $aByName = [];
  61. foreach($aMenu as $aItem)
  62. $aByName[$aItem['name']] = $aItem;
  63. $aSections = [];
  64. foreach($this->_aSections as $sSection => $aPages) {
  65. $aItems = [];
  66. foreach(array_keys($aPages) as $sPage)
  67. if(isset($aByName[$sPage]))
  68. $aItems[] = $aByName[$sPage];
  69. if(empty($aItems))
  70. continue;
  71. $oMenu = new BxAnalyticsStudioMenuItems(['template' => 'menu_side.html', 'menu_items' => $aItems]);
  72. if(!empty($aMarkers))
  73. $oMenu->addMarkers($aMarkers);
  74. $oMenu->setInlineIcons($this->bPageMenuIconsInline);
  75. $aSections[] = [
  76. 'name' => $sSection !== '' ? $sSection : 'main',
  77. 'title' => $sSection !== '' ? _t('_bx_analytics_section_' . $sSection) : '',
  78. 'menu' => $oMenu,
  79. ];
  80. }
  81. return new BxAnalyticsStudioMenu($this->_oModule->_oTemplate, $aSections);
  82. }
  83. /**
  84. * Report sections: the page name is the section the module renders.
  85. */
  86. public function getPageCode($sPage = '', $bWrap = true)
  87. {
  88. if(empty($sPage))
  89. $sPage = $this->sPage;
  90. if($sPage != BX_DOL_STUDIO_MOD_TYPE_SETTINGS && isset($this->aMenuItems[$sPage]) && !method_exists($this, 'get' . bx_gen_method_name($sPage))) {
  91. $sResult = parent::getPageCode('', $bWrap);
  92. if($sResult === false)
  93. return false;
  94. $this->_oModule->_oTemplate->setStudio(true);
  95. return $this->getBlockCode(['content' => $this->_oModule->getStudioSection($sPage)]) . $sResult;
  96. }
  97. return parent::getPageCode($sPage, $bWrap);
  98. }
  99. protected function getContent()
  100. {
  101. $this->_oModule->_oTemplate->setStudio(true);
  102. return $this->_oModule->serviceGetCanvas();
  103. }
  104. }
  105. /** @} */