diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index c997969b1be..bd83dea97bf 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -36,6 +36,7 @@ * } * * + * @see Piwik_ViewDataTable_Properties for core DataTable display properties. * @see factory() for all the available output (cloud tags, html table, pie chart, vertical bar chart) * @package Piwik * @subpackage Piwik_ViewDataTable @@ -112,7 +113,6 @@ abstract class Piwik_ViewDataTable */ protected $view = null; - /** * Default constructor. */ @@ -173,6 +173,37 @@ public function __construct() } } + /** + * Gets a view property by reference. + * + * @param string $name A valid view property name. @see Piwik_ViewDataTable_Properties for all + * valid view properties. + * @return mixed + * @throws Exception if the property name is invalid. + */ + public function &__get($name) + { + Piwik_ViewDataTable_Properties::checkValidPropertyName($name); + + return $this->viewProperties[$name]; + } + + /** + * Sets a view property. + * + * @param string $name A valid view property name. @see Piwik_ViewDataTable_Properties for all + * valid view properties. + * @param mixed $value + * @return mixed Returns $value. + * @throws Exception if the property name is invalid. + */ + public function __set($name, $value) + { + Piwik_ViewDataTable_Properties::checkValidPropertyName($name); + + return $this->viewProperties[$name] = $value; + } + /** * Method to be implemented by the ViewDataTable_*. * This method should create and initialize a $this->view object @see Piwik_View_Interface @@ -196,16 +227,21 @@ abstract protected function getViewDataTableId(); * If force is set to true, a ViewDataTable of the $defaultType will be returned in all cases. * * @param string $defaultType Any of these: table, cloud, graphPie, graphVerticalBar, graphEvolution, sparkline, generateDataChart* - * @param string|bool $action + * @param string|bool $apiAction + * @param string|bool $controllerAction * @return Piwik_ViewDataTable */ - static public function factory($defaultType = null, $action = false) + static public function factory($defaultType = null, $apiAction = false, $controllerAction = false) { - if ($action !== false) { - $defaultProperties = self::getDefaultPropertiesForReport($action); + if ($apiAction !== false) { + $defaultProperties = self::getDefaultPropertiesForReport($apiAction); if (isset($defaultProperties['default_view_type'])) { $defaultType = $defaultProperties['default_view_type']; } + + if ($controllerAction === false) { + $controllerAction = $apiAction; + } } if ($defaultType === null) { @@ -248,15 +284,15 @@ static public function factory($defaultType = null, $action = false) break; } - if ($action !== false) { - list($plugin, $controllerAction) = explode('.', $action); + if ($apiAction !== false) { + list($plugin, $controllerAction) = explode('.', $controllerAction); $subtableAction = $controllerAction; if (isset($defaultProperties['subtable_action'])) { $subtableAction = $defaultProperties['subtable_action']; } - $result->init($plugin, $controllerAction, $action, $subtableAction, $defaultProperties); + $result->init($plugin, $controllerAction, $apiAction, $subtableAction, $defaultProperties); } return $result; @@ -1583,7 +1619,7 @@ private function getBaseReportUrl($module, $action, $queryParams = array()) * @param bool $fetch If true, the result is returned, if false it is echo'd. * @return string|null See $fetch. */ - static public function render($pluginName, $apiAction, $fetch = true) + static public function renderReport($pluginName, $apiAction, $fetch = true) { $apiClassName = 'Piwik_'.$pluginName.'_API'; if (!method_exists($apiClassName::getInstance(), $apiAction)) { @@ -1591,8 +1627,7 @@ static public function render($pluginName, $apiAction, $fetch = true) } $view = self::factory(null, $pluginName.'.'.$apiAction); - $view->main(); - $rendered = $view->getView()->render(); + $rendered = $view->render(); if ($fetch) { return $rendered; @@ -1600,6 +1635,17 @@ static public function render($pluginName, $apiAction, $fetch = true) echo $rendered; } } + + /** + * Convenience function. Calls main() & renders the view that gets built. + * + * @return string The result of rendering. + */ + public function render() + { + $this->main(); + return $this->getView()->render(); + } /** * Returns whether the DataTable result will have to be expanded for the @@ -1624,7 +1670,7 @@ public static function shouldLoadExpanded() * @param array|string $columnsToCheckFor eg, array('nb_visits', 'nb_uniq_visitors') * @return bool */ - private function dataTableColumnsContains($columns, $columnsToCheckFor) + protected function dataTableColumnsContains($columns, $columnsToCheckFor) { if (!is_array($columnsToCheckFor)) { $columnsToCheckFor = array($columnsToCheckFor); @@ -1659,7 +1705,7 @@ protected function buildView($visualization, $template = false) $view->visualization = $visualization; - if (!$this->isDataAvailable) { + if (!$this->dataTable === null) { $view->dataTable = null; } else { $view->dataTable = $this->dataTable; diff --git a/core/ViewDataTable/Cloud.php b/core/ViewDataTable/Cloud.php index 02fed10119d..28127ca281e 100644 --- a/core/ViewDataTable/Cloud.php +++ b/core/ViewDataTable/Cloud.php @@ -49,11 +49,12 @@ public function main() } $this->mainAlreadyExecuted = true; - $this->isDataAvailable = true; try { $this->loadDataTableFromAPI(); } catch (Exception $e) { - $this->isDataAvailable = false; + Piwik::log("Failed to get data from API: " . $e->getMessage()); + + $this->loadingError = array('message' => $e->getMessage()); } $this->checkStandardDataTable(); diff --git a/core/ViewDataTable/GenerateGraphHTML.php b/core/ViewDataTable/GenerateGraphHTML.php index 24ff479624a..2114eb38fa0 100644 --- a/core/ViewDataTable/GenerateGraphHTML.php +++ b/core/ViewDataTable/GenerateGraphHTML.php @@ -221,7 +221,6 @@ public function main() // will be done on the table before the labels are enhanced (see ReplaceColumnNames) $this->disableQueuedFilters(); - $this->isDataAvailable = true; try { $this->loadDataTableFromAPI(); } catch (Piwik_Access_NoAccessException $e) { @@ -229,7 +228,6 @@ public function main() } catch (Exception $e) { Piwik::log("Failed to get data from API: " . $e->getMessage()); - $this->isDataAvailable = false; $this->loadingError = array('message' => $e->getMessage()); } diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php index bc4cc034579..2830ab5cb51 100644 --- a/core/ViewDataTable/HtmlTable.php +++ b/core/ViewDataTable/HtmlTable.php @@ -64,7 +64,6 @@ public function main() } $this->mainAlreadyExecuted = true; - $this->isDataAvailable = true; try { $this->loadDataTableFromAPI(); } catch (Piwik_Access_NoAccessException $e) { @@ -72,7 +71,6 @@ public function main() } catch (Exception $e) { Piwik::log("Failed to get data from API: " . $e->getMessage()); - $this->isDataAvailable = false; $this->loadingError = array('message' => $e->getMessage()); } diff --git a/core/ViewDataTable/HtmlTable/AllColumns.php b/core/ViewDataTable/HtmlTable/AllColumns.php index 9b1a1f77d31..3426ef4af3c 100644 --- a/core/ViewDataTable/HtmlTable/AllColumns.php +++ b/core/ViewDataTable/HtmlTable/AllColumns.php @@ -38,9 +38,8 @@ protected function postDataTableLoadedFromAPI() $valid = parent::postDataTableLoadedFromAPI(); if (!$valid) return false; - Piwik_Controller::setPeriodVariablesView($this); $columnUniqueVisitors = false; - if ($this->period == 'day') { + if ($this->dataTableColumnsContains($this->dataTable->getColumns(), 'nb_uniq_visitors')) { $columnUniqueVisitors = 'nb_uniq_visitors'; } diff --git a/core/ViewDataTable/HtmlTable/Goals.php b/core/ViewDataTable/HtmlTable/Goals.php index 3ca37b6c20d..618ed20edd5 100644 --- a/core/ViewDataTable/HtmlTable/Goals.php +++ b/core/ViewDataTable/HtmlTable/Goals.php @@ -15,6 +15,9 @@ */ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable { + private $processOnlyIdGoal = null; + private $isEcommerce = false; + protected function getViewDataTableId() { return 'tableGoals'; diff --git a/core/ViewDataTable/Properties.php b/core/ViewDataTable/Properties.php new file mode 100644 index 00000000000..1a899f37b1d --- /dev/null +++ b/core/ViewDataTable/Properties.php @@ -0,0 +1,141 @@ +getConstants()); + } + + return $propertiesCache; + } + + /** + * Checks if a property is a valid ViewDataTable property, and if not, throws an exception. + * + * @param string $name The property name. + * @throws Exception + */ + public static function checkValidPropertyName($name) + { + $properties = self::getAllProperties(); + if (!isset($properties[$name])) { + throw new Exception("Invalid ViewDataTable display property '$name'. Is this a visualization property? " + . "If so, set it with \$view->visualization_properties->$name = ..."); + } + } +} \ No newline at end of file diff --git a/core/ViewDataTable/Sparkline.php b/core/ViewDataTable/Sparkline.php index 062a9267b2d..c49759cd1f1 100644 --- a/core/ViewDataTable/Sparkline.php +++ b/core/ViewDataTable/Sparkline.php @@ -43,10 +43,8 @@ public function main() $_GET['period'] = $period; $values = $this->getValuesFromDataTable($this->dataTable); - $this->isDataAvailable = true; if (empty($values)) { $values = array_fill(0, 30, 0); - $this->isDataAvailable = false; } $graph = new Piwik_Visualization_Sparkline(); diff --git a/plugins/Actions/Controller.php b/plugins/Actions/Controller.php index f7597825e56..578ca3bf2a4 100644 --- a/plugins/Actions/Controller.php +++ b/plugins/Actions/Controller.php @@ -84,66 +84,66 @@ public function indexOutlinks($fetch = false) public function getPageUrls($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getEntryPageUrls($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getExitPageUrls($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSiteSearchKeywords($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSiteSearchNoResultKeywords($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSiteSearchCategories($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getPageUrlsFollowingSiteSearch($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getPageTitlesFollowingSiteSearch($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getPageTitles($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getEntryPageTitles($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getExitPageTitles($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getDownloads($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOutlinks($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/CustomVariables/Controller.php b/plugins/CustomVariables/Controller.php index 83b83fb7799..ae7fcaad8cf 100644 --- a/plugins/CustomVariables/Controller.php +++ b/plugins/CustomVariables/Controller.php @@ -23,12 +23,12 @@ public function index($fetch = false) public function getCustomVariables($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getCustomVariablesValuesFromNameId($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php index 430b2126efc..e5109ee5774 100644 --- a/plugins/DBStats/Controller.php +++ b/plugins/DBStats/Controller.php @@ -53,7 +53,7 @@ public function index() public function getDatabaseUsageSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -67,7 +67,7 @@ public function getDatabaseUsageSummary($fetch = false) public function getTrackerDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -81,7 +81,7 @@ public function getTrackerDataSummary($fetch = false) public function getMetricDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -95,7 +95,7 @@ public function getMetricDataSummary($fetch = false) public function getMetricDataSummaryByYear($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -109,7 +109,7 @@ public function getMetricDataSummaryByYear($fetch = false) public function getReportDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -123,7 +123,7 @@ public function getReportDataSummary($fetch = false) public function getReportDataSummaryByYear($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -139,7 +139,7 @@ public function getReportDataSummaryByYear($fetch = false) public function getIndividualReportsSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -155,7 +155,7 @@ public function getIndividualReportsSummary($fetch = false) public function getIndividualMetricsSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -172,6 +172,6 @@ public function getIndividualMetricsSummary($fetch = false) public function getAdminDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/DevicesDetection/Controller.php b/plugins/DevicesDetection/Controller.php index 94584e60b9c..fffae636b80 100644 --- a/plugins/DevicesDetection/Controller.php +++ b/plugins/DevicesDetection/Controller.php @@ -25,37 +25,37 @@ public function index($fetch = false) public function getType($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrand($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getModel($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOsFamilies($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOsVersions($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserFamilies($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserVersions($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index 1535c07220c..7e4f02d630e 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -14,61 +14,61 @@ */ class Piwik_ExampleUI_Controller extends Piwik_Controller { - function dataTables() + public function dataTables() { - $view = Piwik_ViewDataTable::factory('table'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures'); - $view->setColumnTranslation('value', "Temperature in °C"); - $view->setColumnTranslation('label', "Hour of day"); - $view->setSortedColumn('label', 'asc'); - $view->setGraphLimit(24); - $view->setLimit(24); - $view->disableExcludeLowPopulation(); - $view->disableShowAllColumns(); - $view->disableRowEvolution(); - $view->setAxisYUnit('°C'); // useful if the user requests the bar graph - return $this->renderView($view); + $view = Piwik_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->graph_limit = 24; + $view->filter_limit = 24; + $view->show_exclude_low_population = false; + $view->show_table_all_columns = false; + $view->disable_row_evolution = true; + $view->y_axis_unit = '°C'; // useful if the user requests the bar graph + echo $view->render(); } - function evolutionGraph() + public function evolutionGraph() { echo "

Evolution of server temperatures over the last few days

"; $this->echoEvolutionGraph(); } - function echoEvolutionGraph() + public function echoEvolutionGraph() { - $view = Piwik_ViewDataTable::factory('graphEvolution'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution'); - $view->setColumnTranslation('server1', "Temperature server piwik.org"); - $view->setColumnTranslation('server2', "Temperature server dev.piwik.org"); - $view->setAxisYUnit('°C'); // useful if the user requests the bar graph - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphEvolution', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.echoEvolutionGraph'); + $view->translations['server1'] = "Temperature server piwik.org"; + $view->translations['server2'] = "Temperature server dev.piwik.org"; + $view->y_axis_unit = '°C'; // useful if the user requests the bar graph + echo $view->render(); } - function barGraph() + public function barGraph() { - $view = Piwik_ViewDataTable::factory('graphVerticalBar'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures'); - $view->setColumnTranslation('value', "Temperature"); - $view->setAxisYUnit('°C'); - $view->setGraphLimit(24); - $view->disableFooter(); - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphVerticalBar', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.barGraph'); + $view->translations['value'] = "Temperature"; + $view->y_axis_unit = '°C'; + $view->graph_limit = 24; + $view->show_footer = false; + echo $view->render(); } - function pieGraph() + public function pieGraph() { - $view = Piwik_ViewDataTable::factory('graphPie'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios'); - $view->setColumnsToDisplay('value'); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $view->setGraphLimit(10); - $view->disableFooterIcons(); - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphPie', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.pieGraph'); + $view->columns_to_display = array('value'); + $view->translations['value'] = "times the diameter of Earth"; + $view->graph_limit = 10; + $view->show_footer_icons = false; + echo $view->render(); } - function tagClouds() + public function tagClouds() { echo "

Simple tag cloud

"; $this->echoSimpleTagClouds(); @@ -81,28 +81,27 @@ function tagClouds() $this->echoAdvancedTagClouds(); } - function echoSimpleTagClouds() + public function echoSimpleTagClouds() { - $view = Piwik_ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios'); - $view->setColumnsToDisplay(array('label', 'value')); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $view->disableFooter(); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'cloud', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.echoSimpleTagClouds'); + $view->columns_to_display = array('label', 'value'); + $view->translations['value'] = "times the diameter of Earth"; + $view->show_footer = false; + echo $view->render(); } - function echoAdvancedTagClouds() + public function echoAdvancedTagClouds() { - $view = Piwik_ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatiosWithLogos'); - $view->setDisplayLogoInTagCloud(true); - $view->disableFooterExceptExportIcons(); - $view->setColumnsToDisplay(array('label', 'value')); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'cloud', 'ExampleUI.getPlanetRatiosWithLogos', $controllerAction = 'ExampleUI.echoAdvancedTagClouds'); + $view->display_logo_instead_of_label = true; + $view->columns_to_display = array('label', 'value'); + $view->translations['value'] = "times the diameter of Earth"; + echo $view->render(); } - function sparklines() + public function sparklines() { $view = new Piwik_View('@ExampleUI/sparklines'); $view->urlSparkline1 = $this->getUrlSparkline('generateSparkline', array('server' => 'server1', 'rand' => mt_rand())); @@ -110,13 +109,17 @@ function sparklines() echo $view->render(); } - function generateSparkline() + public function generateSparkline() { - $serverRequested = Piwik_Common::getRequestVar('server', ''); - $view = Piwik_ViewDataTable::factory('sparkline'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution'); - $view->setColumnsToDisplay($serverRequested); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'sparkline', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.generateSparkline'); + + $serverRequested = Piwik_Common::getRequestVar('server', false); + if ($serverRequested !== false) { + $view->columns_to_display = array($serverRequested); + } + + echo $view->render(); } // Example use diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index 9396b5f0b24..cf02a7430c9 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -450,26 +450,26 @@ private function getGoalReportsByDimensionTable($conversions, $ecommerce = false public function getItemsSku($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getItemsName($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getItemsCategory($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getVisitsUntilConversion($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getDaysToConversion($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php index 2c7b9c036ee..06a9570e67d 100644 --- a/plugins/Live/Controller.php +++ b/plugins/Live/Controller.php @@ -84,7 +84,7 @@ public function indexVisitorLog() public function getLastVisitsDetails($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** diff --git a/plugins/Provider/Controller.php b/plugins/Provider/Controller.php index cd06ea0f007..4644a9294f2 100644 --- a/plugins/Provider/Controller.php +++ b/plugins/Provider/Controller.php @@ -22,7 +22,7 @@ class Piwik_Provider_Controller extends Piwik_Controller */ public function getProvider($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/Referers/Controller.php b/plugins/Referers/Controller.php index 6193b54d637..4d1ac181f21 100644 --- a/plugins/Referers/Controller.php +++ b/plugins/Referers/Controller.php @@ -128,7 +128,7 @@ public function getSearchEnginesAndKeywords() public function getRefererType($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -141,27 +141,27 @@ public function getRefererType($fetch = false) */ public function getAll($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getKeywords($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSearchEnginesFromKeywordId($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSearchEngines($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getKeywordsFromSearchEngineId($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function indexWebsites($fetch = false) @@ -178,17 +178,17 @@ public function indexWebsites($fetch = false) public function getWebsites($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getSocials($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getUrlsForSocial($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function indexCampaigns($fetch = false) @@ -200,17 +200,17 @@ public function indexCampaigns($fetch = false) public function getCampaigns($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getKeywordsFromCampaignId($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getUrlsFromWebsiteId($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } protected function getReferersVisitorsByType($date = false) diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php index 12b43b77be3..d5a456c668a 100644 --- a/plugins/UserCountry/Controller.php +++ b/plugins/UserCountry/Controller.php @@ -312,12 +312,12 @@ public function getLocationUsingProvider() public function getCountry($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getContinent($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -328,7 +328,7 @@ public function getContinent($fetch = false) */ public function getRegion($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -339,7 +339,7 @@ public function getRegion($fetch = false) */ public function getCity($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getNumberOfDistinctCountries($fetch = false) diff --git a/plugins/UserSettings/Controller.php b/plugins/UserSettings/Controller.php index 515eacf118d..506938c19cc 100644 --- a/plugins/UserSettings/Controller.php +++ b/plugins/UserSettings/Controller.php @@ -33,56 +33,56 @@ public function index() public function getResolution($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getConfiguration($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOS($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOSFamily($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getMobileVsDesktop($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserVersion($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowser($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserType($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getWideScreen($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getPlugin($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getLanguage($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/VisitTime/Controller.php b/plugins/VisitTime/Controller.php index 600262625cc..89f6c0050d0 100644 --- a/plugins/VisitTime/Controller.php +++ b/plugins/VisitTime/Controller.php @@ -25,16 +25,16 @@ public function index() public function getVisitInformationPerServerTime($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getVisitInformationPerLocalTime($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getByDayOfWeek($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 11cebd6c413..c325250873c 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -178,12 +178,16 @@ public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) private static function getDateRangeForFooterMessage() { // get query params - $idSite = Piwik_Common::getRequestVar('idSite'); - $date = Piwik_Common::getRequestVar('date'); - $period = Piwik_Common::getRequestVar('period'); + $idSite = Piwik_Common::getRequestVar('idSite', false); + $date = Piwik_Common::getRequestVar('date', false); + $period = Piwik_Common::getRequestVar('period', false); // create a period instance - $oPeriod = Piwik_Period::makePeriodFromQueryParams(Piwik_Site::getTimezoneFor($idSite), $period, $date); + try { + $oPeriod = Piwik_Period::makePeriodFromQueryParams(Piwik_Site::getTimezoneFor($idSite), $period, $date); + } catch (Exception $ex) { + return ''; // if query params are incorrect, forget about the footer message + } // set the footer message using the period start & end date $start = $oPeriod->getDateStart()->toString(); diff --git a/plugins/VisitorInterest/Controller.php b/plugins/VisitorInterest/Controller.php index 588b98b7fc0..ac20678a035 100644 --- a/plugins/VisitorInterest/Controller.php +++ b/plugins/VisitorInterest/Controller.php @@ -26,12 +26,12 @@ public function index() public function getNumberOfVisitsPerVisitDuration($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getNumberOfVisitsPerPage($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -43,7 +43,7 @@ public function getNumberOfVisitsPerPage($fetch = false) */ public function getNumberOfVisitsByVisitCount($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -55,6 +55,6 @@ public function getNumberOfVisitsByVisitCount($fetch = false) */ public function getNumberOfVisitsByDaysSinceLast($fetch = false) { - return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } }