Dashboard.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Dashboard extends \Magento\Backend\Block\Template
  12. {
  13. /**
  14. * Location of the "Enable Chart" config param
  15. */
  16. const XML_PATH_ENABLE_CHARTS = 'admin/dashboard/enable_charts';
  17. /**
  18. * @var string
  19. */
  20. protected $_template = 'Magento_Backend::dashboard/index.phtml';
  21. /**
  22. * @return void
  23. */
  24. protected function _prepareLayout()
  25. {
  26. $this->addChild('lastOrders', \Magento\Backend\Block\Dashboard\Orders\Grid::class);
  27. $this->addChild('totals', \Magento\Backend\Block\Dashboard\Totals::class);
  28. $this->addChild('sales', \Magento\Backend\Block\Dashboard\Sales::class);
  29. $isChartEnabled = $this->_scopeConfig->getValue(
  30. self::XML_PATH_ENABLE_CHARTS,
  31. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  32. );
  33. if ($isChartEnabled) {
  34. $block = $this->getLayout()->createBlock(\Magento\Backend\Block\Dashboard\Diagrams::class);
  35. } else {
  36. $block = $this->getLayout()->createBlock(
  37. \Magento\Backend\Block\Template::class
  38. )->setTemplate(
  39. 'dashboard/graph/disabled.phtml'
  40. )->setConfigUrl(
  41. $this->getUrl(
  42. 'adminhtml/system_config/edit',
  43. ['section' => 'admin', '_fragment' => 'admin_dashboard-link']
  44. )
  45. );
  46. }
  47. $this->setChild('diagrams', $block);
  48. $this->addChild('grids', \Magento\Backend\Block\Dashboard\Grids::class);
  49. parent::_prepareLayout();
  50. }
  51. /**
  52. * @return string
  53. */
  54. public function getSwitchUrl()
  55. {
  56. if ($url = $this->getData('switch_url')) {
  57. return $url;
  58. }
  59. return $this->getUrl('adminhtml/*/*', ['_current' => true, 'period' => null]);
  60. }
  61. }