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/Events | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/Events')
-rw-r--r-- | plugins/Events/Categories/EventsSubcategory.php | 19 | ||||
-rw-r--r-- | plugins/Events/Controller.php | 104 | ||||
-rw-r--r-- | plugins/Events/Events.php | 3 | ||||
-rw-r--r-- | plugins/Events/Menu.php | 21 | ||||
-rw-r--r-- | plugins/Events/Reports/Base.php | 20 | ||||
-rw-r--r-- | plugins/Events/Reports/GetAction.php | 1 | ||||
-rw-r--r-- | plugins/Events/Reports/GetActionFromCategoryId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Reports/GetActionFromNameId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Reports/GetCategory.php | 1 | ||||
-rw-r--r-- | plugins/Events/Reports/GetCategoryFromActionId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Reports/GetCategoryFromNameId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Reports/GetName.php | 1 | ||||
-rw-r--r-- | plugins/Events/Reports/GetNameFromActionId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Reports/GetNameFromCategoryId.php | 2 | ||||
-rw-r--r-- | plugins/Events/Widgets/EventsByDimension.php | 22 | ||||
-rw-r--r-- | plugins/Events/templates/index.twig | 2 |
16 files changed, 65 insertions, 141 deletions
diff --git a/plugins/Events/Categories/EventsSubcategory.php b/plugins/Events/Categories/EventsSubcategory.php new file mode 100644 index 0000000000..e969029e13 --- /dev/null +++ b/plugins/Events/Categories/EventsSubcategory.php @@ -0,0 +1,19 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\Events\Categories; + +use Piwik\Category\Subcategory; + +class EventsSubcategory extends Subcategory +{ + protected $categoryId = 'General_Actions'; + protected $id = 'Events_Events'; + protected $order = 40; + +} diff --git a/plugins/Events/Controller.php b/plugins/Events/Controller.php deleted file mode 100644 index 3429443b88..0000000000 --- a/plugins/Events/Controller.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\Events; - -use Piwik\View; - -/** - * Events controller - * - */ -class Controller extends \Piwik\Plugin\Controller -{ - public function index() - { - $view = new View('@Events/index'); - $view->leftMenuReports = $this->getLeftMenuReports(); - return $view->render(); - } - - private function getLeftMenuReports() - { - $reports = new View\ReportsByDimension('Events'); - foreach(Events::getLabelTranslations() as $apiAction => $translations) { - // 'getCategory' is the API method, but we are loading 'indexCategory' which displays <h2> - $count = 1; - $controllerAction = str_replace("get", "index", $apiAction, $count); - $params = array( - 'secondaryDimension' => API::getInstance()->getDefaultSecondaryDimension($apiAction) - ); - $reports->addReport('Events_TopEvents', $translations[0], 'Events.' . $controllerAction, $params); - } - return $reports->render(); - } - - public function indexCategory() - { - return $this->indexEvent(__FUNCTION__); - } - - public function indexAction() - { - return $this->indexEvent(__FUNCTION__); - } - - public function indexName() - { - return $this->indexEvent(__FUNCTION__); - } - - public function getActionFromCategoryId() - { - return $this->renderReport(__FUNCTION__); - } - - public function getNameFromCategoryId() - { - return $this->renderReport(__FUNCTION__); - } - - public function getCategoryFromActionId() - { - return $this->renderReport(__FUNCTION__); - } - - public function getNameFromActionId() - { - return $this->renderReport(__FUNCTION__); - } - - public function getActionFromNameId() - { - return $this->renderReport(__FUNCTION__); - } - - public function getCategoryFromNameId() - { - return $this->renderReport(__FUNCTION__); - } - - protected function indexEvent($controllerMethod) - { - $count = 1; - $apiMethod = str_replace('index', 'get', $controllerMethod, $count); - $events = new Events; - $title = $events->getReportTitleTranslation($apiMethod); - - if (method_exists($this, $apiMethod)) { - $content = $this->$apiMethod(); - } else { - $content = $this->renderReport($apiMethod); - } - - return View::singleReport( - $title, - $content - ); - } -} diff --git a/plugins/Events/Events.php b/plugins/Events/Events.php index ba3e96465d..f09e1a9925 100644 --- a/plugins/Events/Events.php +++ b/plugins/Events/Events.php @@ -12,6 +12,7 @@ use Piwik\Common; use Piwik\Piwik; use Piwik\Plugin\Report; use Piwik\Plugin\ViewDataTable; +use Piwik\Plugin\Reports; class Events extends \Piwik\Plugin { @@ -154,7 +155,7 @@ class Events extends \Piwik\Plugin $this->addRelatedReports($view, $secondaryDimension); $this->addTooltipEventValue($view); - $subtableReport = Report::factory('Events', $view->config->subtable_controller_action); + $subtableReport = Reports::factory('Events', $view->config->subtable_controller_action); $view->config->pivot_by_dimension = $subtableReport->getDimension()->getId(); $view->config->pivot_by_column = 'nb_events'; } diff --git a/plugins/Events/Menu.php b/plugins/Events/Menu.php deleted file mode 100644 index 440a35978e..0000000000 --- a/plugins/Events/Menu.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\Events; - -use Piwik\Menu\MenuReporting; - -/** - */ -class Menu extends \Piwik\Plugin\Menu -{ - public function configureReportingMenu(MenuReporting $menu) - { - $menu->addActionsItem('Events_Events', $this->urlForAction('index'), 30); - } -} diff --git a/plugins/Events/Reports/Base.php b/plugins/Events/Reports/Base.php index 4430b31407..a43ba0dbfa 100644 --- a/plugins/Events/Reports/Base.php +++ b/plugins/Events/Reports/Base.php @@ -10,19 +10,31 @@ namespace Piwik\Plugins\Events\Reports; use Piwik\Plugins\Events\API; use Piwik\Plugins\Events\Columns\Metrics\AverageEventValue; +use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; abstract class Base extends \Piwik\Plugin\Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'General_Actions'; + $this->subcategoryId = 'Events_Events'; + $this->processedMetrics = array( new AverageEventValue() ); + } - $this->widgetParams = array( - 'secondaryDimension' => API::getInstance()->getDefaultSecondaryDimension($this->action) - ); + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + if (!$this->isSubtableReport) { + $widget = $factory->createWidget()->setParameters(array( + 'secondaryDimension' => API::getInstance()->getDefaultSecondaryDimension($this->action) + )); + + $widgetsList->addToContainerWidget('Events', $widget); + } } + } diff --git a/plugins/Events/Reports/GetAction.php b/plugins/Events/Reports/GetAction.php index 84f750e264..bbdadd7ed4 100644 --- a/plugins/Events/Reports/GetAction.php +++ b/plugins/Events/Reports/GetAction.php @@ -27,6 +27,5 @@ class GetAction extends Base $this->actionToLoadSubTables = 'getNameFromActionId'; } $this->order = 1; - $this->widgetTitle = 'Events_EventActions'; } } diff --git a/plugins/Events/Reports/GetActionFromCategoryId.php b/plugins/Events/Reports/GetActionFromCategoryId.php index e5de6af9ca..9c355d4de1 100644 --- a/plugins/Events/Reports/GetActionFromCategoryId.php +++ b/plugins/Events/Reports/GetActionFromCategoryId.php @@ -19,7 +19,7 @@ class GetActionFromCategoryId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventAction(); $this->name = Piwik::translate('Events_EventActions'); diff --git a/plugins/Events/Reports/GetActionFromNameId.php b/plugins/Events/Reports/GetActionFromNameId.php index 55bd628459..1da175e47b 100644 --- a/plugins/Events/Reports/GetActionFromNameId.php +++ b/plugins/Events/Reports/GetActionFromNameId.php @@ -19,7 +19,7 @@ class GetActionFromNameId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventAction(); $this->name = Piwik::translate('Events_EventActions'); diff --git a/plugins/Events/Reports/GetCategory.php b/plugins/Events/Reports/GetCategory.php index be867705ea..2049868e7c 100644 --- a/plugins/Events/Reports/GetCategory.php +++ b/plugins/Events/Reports/GetCategory.php @@ -27,6 +27,5 @@ class GetCategory extends Base $this->actionToLoadSubTables = 'getActionFromCategoryId'; } $this->order = 0; - $this->widgetTitle = 'Events_EventCategories'; } } diff --git a/plugins/Events/Reports/GetCategoryFromActionId.php b/plugins/Events/Reports/GetCategoryFromActionId.php index 51f5f6918d..47e62c9260 100644 --- a/plugins/Events/Reports/GetCategoryFromActionId.php +++ b/plugins/Events/Reports/GetCategoryFromActionId.php @@ -19,7 +19,7 @@ class GetCategoryFromActionId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventCategory(); $this->name = Piwik::translate('Events_EventCategories'); diff --git a/plugins/Events/Reports/GetCategoryFromNameId.php b/plugins/Events/Reports/GetCategoryFromNameId.php index 4806c97d0f..0eef6b5f32 100644 --- a/plugins/Events/Reports/GetCategoryFromNameId.php +++ b/plugins/Events/Reports/GetCategoryFromNameId.php @@ -19,7 +19,7 @@ class GetCategoryFromNameId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventCategory(); $this->name = Piwik::translate('Events_EventCategories'); diff --git a/plugins/Events/Reports/GetName.php b/plugins/Events/Reports/GetName.php index aa21f968be..08d97b6ac4 100644 --- a/plugins/Events/Reports/GetName.php +++ b/plugins/Events/Reports/GetName.php @@ -27,6 +27,5 @@ class GetName extends Base $this->actionToLoadSubTables = 'getActionFromNameId'; } $this->order = 2; - $this->widgetTitle = 'Events_EventNames'; } } diff --git a/plugins/Events/Reports/GetNameFromActionId.php b/plugins/Events/Reports/GetNameFromActionId.php index 7b4899b672..4c0325a706 100644 --- a/plugins/Events/Reports/GetNameFromActionId.php +++ b/plugins/Events/Reports/GetNameFromActionId.php @@ -19,7 +19,7 @@ class GetNameFromActionId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventName(); $this->name = Piwik::translate('Events_Names'); diff --git a/plugins/Events/Reports/GetNameFromCategoryId.php b/plugins/Events/Reports/GetNameFromCategoryId.php index d1f43f7931..6e28ccf1e9 100644 --- a/plugins/Events/Reports/GetNameFromCategoryId.php +++ b/plugins/Events/Reports/GetNameFromCategoryId.php @@ -19,7 +19,7 @@ class GetNameFromCategoryId extends Report { protected function init() { - $this->category = 'Events_Events'; + $this->categoryId = 'Events_Events'; $this->processedMetrics = false; $this->dimension = new EventName(); $this->name = Piwik::translate('Events_EventNames'); diff --git a/plugins/Events/Widgets/EventsByDimension.php b/plugins/Events/Widgets/EventsByDimension.php new file mode 100644 index 0000000000..ef04e0d761 --- /dev/null +++ b/plugins/Events/Widgets/EventsByDimension.php @@ -0,0 +1,22 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\Events\Widgets; + +use Piwik\Plugins\CoreHome\CoreHome; +use Piwik\Translation\Translator; +use Piwik\Widget\WidgetContainerConfig; + +class EventsByDimension extends WidgetContainerConfig +{ + protected $layout = CoreHome::WIDGET_CONTAINER_LAYOUT_BY_DIMENSION; + protected $id = 'Events'; + protected $categoryId = 'General_Actions'; + protected $subcategoryId = 'Events_Events'; + +} diff --git a/plugins/Events/templates/index.twig b/plugins/Events/templates/index.twig deleted file mode 100644 index a12afb651a..0000000000 --- a/plugins/Events/templates/index.twig +++ /dev/null @@ -1,2 +0,0 @@ -{{ leftMenuReports|raw }} - |