diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-07-03 03:54:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-10-06 18:25:13 +0300 |
commit | 9ba8f216fd7856ce5fef06bf82ecb8f8a2e7e630 (patch) | |
tree | 6ce07d18a85d00b39ab720abe042361c0775aead /plugins/Goals/Reports | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/Goals/Reports')
-rw-r--r-- | plugins/Goals/Reports/Base.php | 2 | ||||
-rw-r--r-- | plugins/Goals/Reports/Get.php | 111 |
2 files changed, 112 insertions, 1 deletions
diff --git a/plugins/Goals/Reports/Base.php b/plugins/Goals/Reports/Base.php index fd732035d3..3f9cb9c98a 100644 --- a/plugins/Goals/Reports/Base.php +++ b/plugins/Goals/Reports/Base.php @@ -18,7 +18,7 @@ abstract class Base extends \Piwik\Plugin\Report protected function init() { - $this->category = 'Goals_Goals'; + $this->categoryId = 'Goals_Goals'; } protected function addReportMetadataForEachGoal(&$availableReports, $infos, $goalNameFormatter) diff --git a/plugins/Goals/Reports/Get.php b/plugins/Goals/Reports/Get.php index bccecda146..66f167fb24 100644 --- a/plugins/Goals/Reports/Get.php +++ b/plugins/Goals/Reports/Get.php @@ -8,7 +8,20 @@ */ namespace Piwik\Plugins\Goals\Reports; +use Piwik\Common; +use Piwik\DataTable; +use Piwik\Metrics\Formatter; use Piwik\Piwik; +use Piwik\Plugin; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; +use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines; +use Piwik\Plugins\Goals\API; +use Piwik\Plugins\Goals\Goals; +use Piwik\Plugins\Goals\Pages; +use Piwik\Report\ReportWidgetFactory; +use Piwik\Site; +use Piwik\Widget\WidgetsList; class Get extends Base { @@ -25,6 +38,104 @@ class Get extends Base $this->parameters = null; } + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + $idSite = $this->getIdSite(); + $goals = API::getInstance()->getGoals($idSite); + $reports = Goals::getReportsWithGoalMetrics(); + + $page = new Pages($factory, $reports); + + $widgetsList->addWidgetConfigs($page->createGoalsOverviewPage($goals)); + + if ($this->isEcommerceEnabled($idSite)) { + $widgetsList->addWidgetConfigs($page->createEcommerceOverviewPage()); + $widgetsList->addWidgetConfigs($page->createEcommerceSalesPage()); + } + + foreach ($goals as $goal) { + $widgetsList->addWidgetConfigs($page->createGoalDetailPage($goal)); + } + } + + private function getIdSite() + { + return Common::getRequestVar('idSite', null, 'int'); + } + + private function isEcommerceEnabled($idSite) + { + if (!Plugin\Manager::getInstance()->isPluginActivated('Ecommerce')) { + return false; + } + + $site = new Site($idSite); + return $site->isEcommerceEnabled(); + } + + public function configureView(ViewDataTable $view) + { + if ($view->isViewDataTableId(Sparklines::ID)) { + /** @var Sparklines $view */ + $idSite = $this->getIdSite(); + $isEcommerceEnabled = $this->isEcommerceEnabled($idSite); + + $idGoal = Common::getRequestVar('idGoal', 0, 'int'); + + $formatter = new Formatter(); + $view->config->filters[] = function (DataTable $table) use ($formatter, $idSite) { + $firstRow = $table->getFirstRow(); + if ($firstRow) { + $revenue = $firstRow->getColumn('revenue'); + $firstRow->setColumn('revenue', $formatter->getPrettyMoney($revenue, $idSite)); + } + }; + + $view->config->addTranslations(array( + 'nb_visits' => Piwik::translate('VisitsSummary_NbVisitsDescription'), + 'nb_conversions' => Piwik::translate('Goals_ConversionsDescription'), + 'nb_visits_converted' => Piwik::translate('General_NVisits'), + 'conversion_rate' => Piwik::translate('Goals_OverallConversionRate'), + 'revenue' => Piwik::translate('Goals_OverallRevenue'), + )); + + $allowMultiple = Common::getRequestVar('allow_multiple', 0, 'int'); + + if ($allowMultiple) { + $view->config->addSparklineMetric(array('nb_conversions', 'nb_visits_converted'), $order = 10); + } else { + $view->config->addSparklineMetric(array('nb_conversions'), $order = 10); + } + + $view->config->addSparklineMetric(array('conversion_rate'), $order = 20); + + if (empty($idGoal)) { + // goals overview sparklines below evolution graph + + if ($isEcommerceEnabled) { + // this would be ideally done in Ecommerce plugin but then it is hard to keep same order + $view->config->addSparklineMetric(array('revenue'), $order = 30); + } + + } else { + $onlySummary = Common::getRequestVar('only_summary', 0, 'int'); + + if ($onlySummary) { + // in Goals Overview we list an overview for each goal.... + $view->config->addTranslation('conversion_rate', Piwik::translate('Goals_ConversionRate')); + + } elseif ($isEcommerceEnabled) { + // in Goals detail page... + $view->config->addSparklineMetric(array('revenue'), $order = 30); + } + } + } else if ($view->isViewDataTableId(Evolution::ID)) { + if (empty($view->config->columns_to_display)) { + $view->config->columns_to_display = array('nb_conversions'); + } + } + } + public function configureReportMetadata(&$availableReports, $infos) { if (!$this->isEnabled()) { |