PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Report / ReportWidgetFactory.php
matomo / app / core / Report Last commit date
ReportWidgetConfig.php 6 years ago ReportWidgetFactory.php 6 years ago
ReportWidgetFactory.php
119 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\Report;
10
11 use Piwik\Plugin\Report;
12 use Piwik\Widget\WidgetContainerConfig;
13
14 /**
15 * Report widget factory. This factory allows you to create widgets for a given report without having to re-specify
16 * redundant information like module, action, category, subcategory, order, ... When creating a widget from a report
17 * these values will be automatically specified so that ideally `$factory->createWidget()` is all one has to do in
18 * order to create a new widget.
19 *
20 * @api since Piwik 3.0.0
21 */
22 class ReportWidgetFactory
23 {
24 /**
25 * @var Report
26 */
27 private $report = null;
28
29 /**
30 * Generates a new report widget factory.
31 * @param Report $report A report instance, widgets will be created based on the data provided by this report.
32 */
33 public function __construct(Report $report)
34 {
35 $this->report = $report;
36 }
37
38 /**
39 * Creates a widget based on the specified report in {@link construct()}.
40 *
41 * It will automatically use the report's name, categoryId, subcategoryId (if specified),
42 * defaultViewDataTable, module, action, order and parameters in order to create the widget.
43 *
44 * @return ReportWidgetConfig
45 */
46 public function createWidget()
47 {
48 $widget = new ReportWidgetConfig();
49 $widget->setName($this->report->getName());
50 $widget->setCategoryId($this->report->getCategoryId());
51
52 if ($this->report->getDefaultTypeViewDataTable()) {
53 $widget->setDefaultViewDataTable($this->report->getDefaultTypeViewDataTable());
54 }
55
56 if ($this->report->getSubcategoryId()) {
57 $widget->setSubcategoryId($this->report->getSubcategoryId());
58 }
59
60 $widget->setModule($this->report->getModule());
61 $widget->setAction($this->report->getAction());
62
63 $orderThatListsReportsAtTheEndOfEachCategory = 100 + $this->report->getOrder();
64 $widget->setOrder($orderThatListsReportsAtTheEndOfEachCategory);
65
66 $parameters = $this->report->getParameters();
67 if (!empty($parameters)) {
68 $widget->setParameters($parameters);
69 }
70
71 return $widget;
72 }
73
74 /**
75 * Creates a new container widget based on the specified report in {@link construct()}.
76 *
77 * It will automatically use the report's categoryId, subcategoryId (if specified) and order in order to
78 * create the container.
79 *
80 * @param string $containerId eg 'Products' or 'Contents' see {Piwik\Widget\WidgetContainerConfig::setId()}.
81 * Other reports or widgets will be able to add more widgets to this container.
82 * This is useful when you want to show for example multiple related widgets
83 * together.
84 * @return WidgetContainerConfig
85 */
86 public function createContainerWidget($containerId)
87 {
88 $widget = new WidgetContainerConfig();
89 $widget->setCategoryId($this->report->getCategoryId());
90 $widget->setId($containerId);
91
92 if ($this->report->getSubcategoryId()) {
93 $widget->setSubcategoryId($this->report->getSubcategoryId());
94 }
95
96 $orderThatListsReportsAtTheEndOfEachCategory = 100 + $this->report->getOrder();
97 $widget->setOrder($orderThatListsReportsAtTheEndOfEachCategory);
98
99 return $widget;
100 }
101
102 /**
103 * Creates a custom widget that doesn't use a viewDataTable to render the report but instead a custom
104 * controller action. Make sure the specified `$action` exists in the plugin's controller. Otherwise
105 * behaves as {@link createWidget()}.
106 *
107 * @param string $action eg 'conversionReports' (requires a method `public function conversionReports()` in
108 * the plugin's controller).
109 * @return ReportWidgetConfig
110 */
111 public function createCustomWidget($action)
112 {
113 $widget = $this->createWidget();
114 $widget->setDefaultViewDataTable(null);
115 $widget->setAction($action);
116
117 return $widget;
118 }
119 }