diff options
Diffstat (limited to 'plugins/ExampleUI')
-rw-r--r-- | plugins/ExampleUI/Controller.php | 29 | ||||
-rw-r--r-- | plugins/ExampleUI/CustomDataTable.php | 44 |
2 files changed, 52 insertions, 21 deletions
diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index fa6c7d39b2..6f7c769d5f 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -23,28 +23,15 @@ class Controller extends \Piwik\Controller { public function dataTables() { - $view = ViewDataTable::factory('table', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.dataTables'); - - $view->translations['value'] = "Temperature in °C"; - $view->translations['label'] = "Hour of day"; - $view->filter_sort_column = 'label'; - $view->filter_sort_order = 'asc'; - $view->filter_limit = 24; - $view->y_axis_unit = '°C'; // useful if the user requests the bar graph - $view->show_exclude_low_population = false; - $view->show_table_all_columns = false; - $view->visualization_properties->setForVisualization( - 'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\HtmlTable', - 'disable_row_evolution', - true - ); - $view->visualization_properties->setForVisualization( - 'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\JqplotGraph', - 'max_graph_elements', - 24 - ); + $controllerAction = $this->pluginName . '.' . __FUNCTION__; + $apiAction = 'ExampleUI.getTemperatures'; - echo $view->render(); + /** + * this is an example how you can make a custom visualization reusable. + */ + $table = new CustomDataTable(); + + echo $table->render('Temperature in °C', 'Hour of day', $apiAction, $controllerAction); } public function evolutionGraph() diff --git a/plugins/ExampleUI/CustomDataTable.php b/plugins/ExampleUI/CustomDataTable.php new file mode 100644 index 0000000000..d130495a96 --- /dev/null +++ b/plugins/ExampleUI/CustomDataTable.php @@ -0,0 +1,44 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package ExampleUI + */ + +namespace Piwik\Plugins\ExampleUI; + +use Piwik\ViewDataTable; + +class CustomDataTable +{ + public function render($value, $label, $apiAction, $controllerAction) + { + $view = ViewDataTable::factory('exampleui-customtable', $apiAction, $controllerAction); + + $view->translations['value'] = $value; + $view->translations['label'] = $label; + $view->filter_sort_column = 'label'; + $view->filter_sort_order = 'asc'; + $view->filter_limit = 24; + $view->y_axis_unit = '°C'; // useful if the user requests the bar graph + $view->show_exclude_low_population = false; + $view->show_table_all_columns = false; + $view->visualization_properties->setForVisualization( + 'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\HtmlTable', + 'disable_row_evolution', + true + ); + $view->visualization_properties->setForVisualization( + 'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\JqplotGraph', + 'max_graph_elements', + 24 + ); + + return $view->render(); + } + +}
\ No newline at end of file |