Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReportsByDimension.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik\View;
  10. use Piwik\FrontController;
  11. use Piwik\Piwik;
  12. use Piwik\Url;
  13. use Piwik\View;
  14. /**
  15. * A facade that makes it easier to use the '_reportsByDimension.twig' template.
  16. *
  17. * This view will output HTML that displays a list of report names by category and
  18. * loads them by AJAX when clicked. The loaded report is displayed to the right
  19. * of the report listing.
  20. */
  21. class ReportsByDimension extends View
  22. {
  23. /**
  24. * Constructor.
  25. *
  26. * @param string $id
  27. */
  28. public function __construct($id)
  29. {
  30. parent::__construct('@CoreHome/ReportsByDimension/_reportsByDimension');
  31. $this->dimensionCategories = array();
  32. $this->id = $id;
  33. }
  34. /**
  35. * Adds a report to the list of reports to display.
  36. *
  37. * @param string $category The report's category. Can be a i18n token.
  38. * @param string $title The report's title. Can be a i18n token.
  39. * @param string $action The controller action used to load the report, ie, Referrers.getAll
  40. * @param array $params The list of query parameters to use when loading the report.
  41. * This list overrides query parameters currently in use. For example,
  42. * array('idSite' => 2, 'viewDataTable' => 'goalsTable')
  43. * would mean the goals report for site w/ ID=2 will always be loaded.
  44. */
  45. public function addReport($category, $title, $action, $params = array())
  46. {
  47. list($module, $action) = explode('.', $action);
  48. $params = array('module' => $module, 'action' => $action) + $params;
  49. $categories = $this->dimensionCategories;
  50. $categories[$category][] = array(
  51. 'title' => $title,
  52. 'params' => $params,
  53. 'url' => Url::getCurrentQueryStringWithParametersModified($params)
  54. );
  55. $this->dimensionCategories = $categories;
  56. }
  57. /**
  58. * Adds a set of reports to the list of reports to display.
  59. *
  60. * @param array $reports An array containing report information. The array requires
  61. * the 'category', 'title', 'action' and 'params' elements.
  62. * For information on what they should contain, @see addReport.
  63. */
  64. public function addReports($reports)
  65. {
  66. foreach ($reports as $report) {
  67. $this->addReport($report['category'], $report['title'], $report['action'], $report['params']);
  68. }
  69. }
  70. /**
  71. * @return string The ID specified in the constructor, usually the plugin name
  72. */
  73. public function getId()
  74. {
  75. return $this->id;
  76. }
  77. /**
  78. * Renders this view.
  79. *
  80. * @return string The rendered view.
  81. */
  82. public function render()
  83. {
  84. /**
  85. * Triggered before rendering {@link ReportsByDimension} views.
  86. *
  87. * Plugins can use this event to configure {@link ReportsByDimension} instances by
  88. * adding or removing reports to display.
  89. *
  90. * @param ReportsByDimension $this The view instance.
  91. */
  92. Piwik::postEvent('View.ReportsByDimension.render', array($this));
  93. $this->firstReport = "";
  94. // if there are reports & report categories added, render the first one so we can
  95. // display it initially
  96. $categories = $this->dimensionCategories;
  97. if (!empty($categories)) {
  98. $firstCategory = reset($categories);
  99. $firstReportInfo = reset($firstCategory);
  100. $oldGet = $_GET;
  101. $oldPost = $_POST;
  102. foreach ($firstReportInfo['params'] as $key => $value) {
  103. $_GET[$key] = $value;
  104. }
  105. $_POST = array();
  106. $module = $firstReportInfo['params']['module'];
  107. $action = $firstReportInfo['params']['action'];
  108. $this->firstReport = FrontController::getInstance()->fetchDispatch($module, $action);
  109. $_GET = $oldGet;
  110. $_POST = $oldPost;
  111. }
  112. return parent::render();
  113. }
  114. }