Skip to content
Extraits de code Groupes Projets
Valider 82a36f16 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Refs #4200, documented ViewDataTable\Factory.

parent e18a6a22
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -204,9 +204,12 @@ abstract class Controller ...@@ -204,9 +204,12 @@ abstract class Controller
/** /**
* Convenience method that creates and renders a ViewDataTable for a API method. * Convenience method that creates and renders a ViewDataTable for a API method.
* *
* @param string $apiAction The name of the API action (eg, getResolution). * @param string $pluginName The name of the plugin (eg, `'UserSettings'`).
* @throws \Exception * @param string $apiAction The name of the API action (eg, `'getResolution'`).
* @return string * @param bool $fetch If `true`, the rendered string is returned, if `false` it is `echo`'d.
* @throws \Exception if `$pluginName` is not an existing plugin or if `$apiAction` is not an
* existing method of the plugin's API.
* @return string|void See `$fetch`.
*/ */
protected function renderReport($apiAction) protected function renderReport($apiAction)
{ {
......
...@@ -16,8 +16,45 @@ use Piwik\Piwik; ...@@ -16,8 +16,45 @@ use Piwik\Piwik;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
/** /**
* TODO * Provides a means of creating [ViewDataTable](#) instances by ID.
* *
* ### Examples
*
* **Creating a ViewDataTable for a report**
*
* // method in MyPlugin\Controller
* public function myReport()
* {
* $view = Factory::build('table', 'MyPlugin.myReport');
* $view->config->show_limit_control = true;
* $view->config->translations['myFancyMetric'] = "My Fancy Metric";
* echo $view->render();
* }
*
* **Displaying a report in another way**
*
* // method in MyPlugin\Controller
* // use the same data that's used in myReport() above, but transform it in some way before
* // displaying.
* public function myReportShownDifferently()
* {
* $view = Factory::build('table', 'MyPlugin.myReport', 'MyPlugin.myReportShownDifferently');
* $view->config->filters[] = array('MyMagicFilter', array('an arg', 'another arg'));
* echo $view->render();
* }
*
* **Force a report to be shown as a bar graph**
*
* // method in MyPlugin\Controller
* // force the myReport report to show as a bar graph if there is no viewDataTable query param,
* // even though it is configured to show as a table.
* public function myReportShownAsABarGraph()
* {
* $view = Factory::build('graphVerticalBar', 'MyPlugin.myReport', 'MyPlugin.myReportShownAsABarGraph',
* $forceDefault = true);
* echo $view->render();
* }
*
* @package Piwik * @package Piwik
* @subpackage ViewDataTable * @subpackage ViewDataTable
* *
...@@ -25,7 +62,6 @@ use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; ...@@ -25,7 +62,6 @@ use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
*/ */
class Factory class Factory
{ {
/** /**
* Cache for getDefaultTypeViewDataTable result. * Cache for getDefaultTypeViewDataTable result.
* *
...@@ -34,19 +70,28 @@ class Factory ...@@ -34,19 +70,28 @@ class Factory
private static $defaultViewTypes = null; private static $defaultViewTypes = null;
/** /**
* Returns a Piwik_ViewDataTable_* object. * Creates a [ViewDataTable](#) instance by ID. If the **viewDataTable** query parameter is set,
* By default it will return a ViewDataTable_Html * this parameter's value is used as the ID.
* If there is a viewDataTable parameter in the URL, a ViewDataTable of this 'viewDataTable' type will be returned. *
* If defaultType is specified and if there is no 'viewDataTable' in the URL, a ViewDataTable of this $defaultType will be returned. * See [ViewDataTable docs](#) to read about the ViewDataTable implementations that are packaged with Piwik.
* If force is set to true, a ViewDataTable of the $defaultType will be returned in all cases. *
* * @param string|null $defaultType A ViewDataTable ID representing the default ViewDataTable type to use. If
* @param string $defaultType Any of these: table, cloud, graphPie, graphVerticalBar, graphEvolution, sparkline, generateDataChart* * the **viewDataTable** query parameter is not found, this value is used as
* @param string|bool $apiAction * the ID of the ViewDataTable to create.
* @param string|bool $controllerAction *
* @param bool $forceDefault * If a visualization type is configured for the report being displayed, it
* * is used instead of the default type. (See [ViewDataTable.getDefaultType](#)).
* If nothing is configured for the report and `null` is supplied for this
* argument, **table** is used.
* @param string|false $apiAction The API method for the report that will be displayed, eg,
* `'UserSettings.getBrowser'`.
* @param string|false $controllerAction The controller name and action dedicated to displaying the report. This
* action is used when reloading reports or changing the report visualization.
* Defaulted to `$apiAction` if `false` is supplied.
* @param bool $forceDefault If true, then the visualization type that was configured for the report will be
* ignored and `$defaultType` will be used as the default.
* @throws \Exception * @throws \Exception
* @return \Piwik\Plugin\ViewDataTable|\Piwik\Plugin\Visualization|\Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline; * @return \Piwik\Plugin\ViewDataTable
*/ */
public static function build($defaultType = null, $apiAction = false, $controllerAction = false, $forceDefault = false) public static function build($defaultType = null, $apiAction = false, $controllerAction = false, $forceDefault = false)
{ {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter