PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/ExampleUI/Controller.php

https://github.com/CodeYellowBV/piwik
PHP | 202 lines | 153 code | 40 blank | 9 comment | 5 complexity | 12c2743dcdbab03c82dd0e9ced36298a MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  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\Plugins\ExampleUI;
  10. use Piwik\Common;
  11. use Piwik\Notification;
  12. use Piwik\Piwik;
  13. use Piwik\View;
  14. use Piwik\ViewDataTable\Factory as ViewDataTableFactory;
  15. /**
  16. */
  17. class Controller extends \Piwik\Plugin\Controller
  18. {
  19. public function dataTables()
  20. {
  21. $controllerAction = $this->pluginName . '.' . __FUNCTION__;
  22. $apiAction = 'ExampleUI.getTemperatures';
  23. $view = ViewDataTableFactory::build('table', $apiAction, $controllerAction);
  24. $view->config->translations['value'] = 'Temperature in 째C';
  25. $view->config->translations['label'] = 'Hour of day';
  26. $view->requestConfig->filter_sort_column = 'label';
  27. $view->requestConfig->filter_sort_order = 'asc';
  28. $view->requestConfig->filter_limit = 24;
  29. $view->config->columns_to_display = array('label', 'value');
  30. $view->config->y_axis_unit = '째C'; // useful if the user requests the bar graph
  31. $view->config->show_exclude_low_population = false;
  32. $view->config->show_table_all_columns = false;
  33. $view->config->disable_row_evolution = true;
  34. $view->config->max_graph_elements = 24;
  35. $view->config->metrics_documentation = array('value' => 'Documentation for temperature metric');
  36. return $view->render();
  37. }
  38. public function evolutionGraph()
  39. {
  40. $view = new View('@ExampleUI/evolutiongraph');
  41. $this->setPeriodVariablesView($view);
  42. $view->evolutionGraph = $this->getEvolutionGraph(array(), array('server1', 'server2'));
  43. return $view->render();
  44. }
  45. public function notifications()
  46. {
  47. $notification = new Notification('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
  48. Notification\Manager::notify('ExampleUI_InfoSimple', $notification);
  49. $notification = new Notification('Neque porro quisquam est qui dolorem ipsum quia dolor sit amet.');
  50. $notification->title = 'Warning:';
  51. $notification->context = Notification::CONTEXT_WARNING;
  52. $notification->flags = null;
  53. Notification\Manager::notify('ExampleUI_warningWithClose', $notification);
  54. $notification = new Notification('Phasellus tincidunt arcu at justo faucibus, et lacinia est accumsan. ');
  55. $notification->title = 'Well done';
  56. $notification->context = Notification::CONTEXT_SUCCESS;
  57. $notification->type = Notification::TYPE_TOAST;
  58. Notification\Manager::notify('ExampleUI_successToast', $notification);
  59. $notification = new Notification('Phasellus tincidunt arcu at justo <a href="#">faucibus</a>, et lacinia est accumsan. ');
  60. $notification->raw = true;
  61. $notification->context = Notification::CONTEXT_ERROR;
  62. Notification\Manager::notify('ExampleUI_error', $notification);
  63. $view = new View('@ExampleUI/notifications');
  64. $this->setGeneralVariablesView($view);
  65. return $view->render();
  66. }
  67. public function getEvolutionGraph(array $columns = array(), array $defaultColumns = array())
  68. {
  69. if (empty($columns)) {
  70. $columns = Common::getRequestVar('columns', false);
  71. if (false !== $columns) {
  72. $columns = Piwik::getArrayFromApiParameter($columns);
  73. }
  74. }
  75. $view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
  76. $selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution');
  77. $view->requestConfig->filter_sort_column = 'label';
  78. if (empty($view->config->columns_to_display) && !empty($defaultColumns)) {
  79. $view->config->columns_to_display = $defaultColumns;
  80. }
  81. return $this->renderView($view);
  82. }
  83. public function barGraph()
  84. {
  85. $view = ViewDataTableFactory::build(
  86. 'graphVerticalBar', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.barGraph');
  87. $view->config->y_axis_unit = '째C';
  88. $view->config->show_footer = false;
  89. $view->config->translations['value'] = "Temperature";
  90. $view->config->selectable_columns = array("value");
  91. $view->config->max_graph_elements = 24;
  92. return $view->render();
  93. }
  94. public function pieGraph()
  95. {
  96. $view = ViewDataTableFactory::build(
  97. 'graphPie', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.pieGraph');
  98. $view->config->columns_to_display = array('value');
  99. $view->config->translations['value'] = "times the diameter of Earth";
  100. $view->config->show_footer_icons = false;
  101. $view->config->selectable_columns = array("value");
  102. $view->config->max_graph_elements = 10;
  103. return $view->render();
  104. }
  105. public function tagClouds()
  106. {
  107. $output = "<h2>Simple tag cloud</h2>";
  108. $output .= $this->echoSimpleTagClouds();
  109. $output .= "<br /><br /><h2>Advanced tag cloud: with logos and links</h2>
  110. <ul style='list-style-type:disc;margin-left:50px'>
  111. <li>The logo size is proportional to the value returned by the API</li>
  112. <li>The logo is linked to a specific URL</li>
  113. </ul><br /><br />";
  114. $output .= $this->echoAdvancedTagClouds();
  115. return $output;
  116. }
  117. public function echoSimpleTagClouds()
  118. {
  119. $view = ViewDataTableFactory::build(
  120. 'cloud', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.echoSimpleTagClouds');
  121. $view->config->columns_to_display = array('label', 'value');
  122. $view->config->translations['value'] = "times the diameter of Earth";
  123. $view->config->show_footer = false;
  124. return $view->render();
  125. }
  126. public function echoAdvancedTagClouds()
  127. {
  128. $view = ViewDataTableFactory::build(
  129. 'cloud', 'ExampleUI.getPlanetRatiosWithLogos', $controllerAction = 'ExampleUI.echoAdvancedTagClouds');
  130. $view->config->display_logo_instead_of_label = true;
  131. $view->config->columns_to_display = array('label', 'value');
  132. $view->config->translations['value'] = "times the diameter of Earth";
  133. return $view->render();
  134. }
  135. public function sparklines()
  136. {
  137. $view = new View('@ExampleUI/sparklines');
  138. $view->urlSparkline1 = $this->getUrlSparkline('generateSparkline', array('server' => 'server1', 'rand' => mt_rand()));
  139. $view->urlSparkline2 = $this->getUrlSparkline('generateSparkline', array('server' => 'server2', 'rand' => mt_rand()));
  140. return $view->render();
  141. }
  142. public function generateSparkline()
  143. {
  144. $view = ViewDataTableFactory::build(
  145. 'sparkline', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.generateSparkline');
  146. $serverRequested = Common::getRequestVar('server', false);
  147. if (false !== $serverRequested) {
  148. $view->config->columns_to_display = array($serverRequested);
  149. }
  150. return $view->render();
  151. }
  152. public function treemap()
  153. {
  154. $view = ViewDataTableFactory::build(
  155. 'infoviz-treemap', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.treemap');
  156. $view->config->translations['value'] = "Temperature";
  157. $view->config->columns_to_display = array("label", "value");
  158. $view->config->selectable_columns = array("value");
  159. $view->config->show_evolution_values = 0;
  160. return $view->render();
  161. }
  162. }