-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPages.php
More file actions
122 lines (106 loc) · 4.56 KB
/
Pages.php
File metadata and controls
122 lines (106 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\EventsEnhanced;
use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution;
use Piwik\Report\ReportWidgetFactory;
/**
* Pages helper for EventsEnhanced plugin
* Follows standard Matomo widget configuration patterns (similar to Goals/Pages.php)
*/
class Pages
{
private $factory;
private $dimensionType;
private $dimensionValue;
private $paramName;
public function __construct(ReportWidgetFactory $reportFactory)
{
$this->factory = $reportFactory;
$this->loadDimensionFromUrl();
}
/**
* Load dimension parameters from URL
*/
private function loadDimensionFromUrl()
{
$this->dimensionType = Common::getRequestVar('eventDimensionType', 'name', 'string');
$this->dimensionValue = Common::getRequestVar('eventDimensionValue', '', 'string');
$paramMap = [
'category' => 'eventCategory',
'action' => 'eventAction',
'name' => 'eventName',
];
$this->paramName = $paramMap[$this->dimensionType] ?? 'eventCategory';
// Try legacy parameter names
if (empty($this->dimensionValue)) {
$this->dimensionValue = Common::getRequestVar($this->paramName, '', 'string');
}
}
/**
* Create the event detail page widgets
*
* @return array Widget configurations
*/
public function createEventDetailPage()
{
$subcategory = 'EventsEnhanced_EventsDetails';
$widgets = [];
$params = [
'dimensionType' => $this->dimensionType,
'dimensionValue' => $this->dimensionValue,
$this->paramName => $this->dimensionValue,
];
// 1. Evolution Graph widget
$evolutionWidget = $this->factory->createWidget();
$evolutionWidget->setSubcategoryId($subcategory);
$evolutionWidget->setModule('EventsEnhanced');
$evolutionWidget->setAction('getEvolutionGraph');
$evolutionWidget->setName('');
$evolutionWidget->setOrder(5);
$evolutionWidget->forceViewDataTable(Evolution::ID);
$evolutionWidget->setIsNotWidgetizable();
$evolutionWidget->setParameters($params);
$widgets[] = $evolutionWidget;
// 2. Related dimension reports based on current dimension type
if ($this->dimensionType === 'category') {
// For category: show Actions and Names
$widgets[] = $this->createReportWidget($subcategory, 'getEventActionsForCategory', 'Events_EventActions', 10, ['eventCategory' => $this->dimensionValue]);
$widgets[] = $this->createReportWidget($subcategory, 'getEventNamesForCategory', 'Events_EventNames', 15, ['eventCategory' => $this->dimensionValue]);
} elseif ($this->dimensionType === 'action') {
// For action: show Categories and Names
$widgets[] = $this->createReportWidget($subcategory, 'getEventCategoriesForAction', 'Events_EventCategories', 10, ['eventAction' => $this->dimensionValue]);
$widgets[] = $this->createReportWidget($subcategory, 'getEventNamesForAction', 'Events_EventNames', 15, ['eventAction' => $this->dimensionValue]);
} else {
// For name: show Categories and Actions
$widgets[] = $this->createReportWidget($subcategory, 'getEventCategoriesForName', 'Events_EventCategories', 10, ['eventName' => $this->dimensionValue]);
$widgets[] = $this->createReportWidget($subcategory, 'getEventActionsForName', 'Events_EventActions', 15, ['eventName' => $this->dimensionValue]);
}
// 3. Page URLs widget
$widgets[] = $this->createReportWidget($subcategory, 'getPageUrlsForEvent', 'Actions_SubmenuPageUrls', 20, $params);
// 4. Page Titles widget
$widgets[] = $this->createReportWidget($subcategory, 'getPageTitlesForEvent', 'Actions_SubmenuPageTitles', 25, $params);
return $widgets;
}
/**
* Create a report widget config
*/
private function createReportWidget($subcategory, $action, $name, $order, $params)
{
$widget = $this->factory->createWidget();
$widget->setSubcategoryId($subcategory);
$widget->setModule('EventsEnhanced');
$widget->setAction($action);
$widget->setName($name);
$widget->setOrder($order);
$widget->setIsNotWidgetizable();
$widget->setParameters($params);
return $widget;
}
}