PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.1 5.12.0 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 2 years ago ReportWidgetFactory.php 2 years ago
ReportWidgetFactory.php
106 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Report;
11
12 use Piwik\Plugin\Report;
13 use Piwik\Widget\WidgetContainerConfig;
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 * Generates a new report widget factory.
30 * @param Report $report A report instance, widgets will be created based on the data provided by this report.
31 */
32 public function __construct(Report $report)
33 {
34 $this->report = $report;
35 }
36 /**
37 * Creates a widget based on the specified report in {@link construct()}.
38 *
39 * It will automatically use the report's name, categoryId, subcategoryId (if specified),
40 * defaultViewDataTable, module, action, order and parameters in order to create the widget.
41 *
42 * @return ReportWidgetConfig
43 */
44 public function createWidget()
45 {
46 $widget = new \Piwik\Report\ReportWidgetConfig();
47 $widget->setName($this->report->getName());
48 $widget->setCategoryId($this->report->getCategoryId());
49 if ($this->report->getDefaultTypeViewDataTable()) {
50 $widget->setDefaultViewDataTable($this->report->getDefaultTypeViewDataTable());
51 }
52 if ($this->report->getSubcategoryId()) {
53 $widget->setSubcategoryId($this->report->getSubcategoryId());
54 }
55 $widget->setModule($this->report->getModule());
56 $widget->setAction($this->report->getAction());
57 $orderThatListsReportsAtTheEndOfEachCategory = 100 + $this->report->getOrder();
58 $widget->setOrder($orderThatListsReportsAtTheEndOfEachCategory);
59 $parameters = $this->report->getParameters();
60 if (!empty($parameters)) {
61 $widget->setParameters($parameters);
62 }
63 return $widget;
64 }
65 /**
66 * Creates a new container widget based on the specified report in {@link construct()}.
67 *
68 * It will automatically use the report's categoryId, subcategoryId (if specified) and order in order to
69 * create the container.
70 *
71 * @param string $containerId eg 'Products' or 'Contents' see {Piwik\Widget\WidgetContainerConfig::setId()}.
72 * Other reports or widgets will be able to add more widgets to this container.
73 * This is useful when you want to show for example multiple related widgets
74 * together.
75 * @return WidgetContainerConfig
76 */
77 public function createContainerWidget($containerId)
78 {
79 $widget = new WidgetContainerConfig();
80 $widget->setCategoryId($this->report->getCategoryId());
81 $widget->setId($containerId);
82 if ($this->report->getSubcategoryId()) {
83 $widget->setSubcategoryId($this->report->getSubcategoryId());
84 }
85 $orderThatListsReportsAtTheEndOfEachCategory = 100 + $this->report->getOrder();
86 $widget->setOrder($orderThatListsReportsAtTheEndOfEachCategory);
87 return $widget;
88 }
89 /**
90 * Creates a custom widget that doesn't use a viewDataTable to render the report but instead a custom
91 * controller action. Make sure the specified `$action` exists in the plugin's controller. Otherwise
92 * behaves as {@link createWidget()}.
93 *
94 * @param string $action eg 'conversionReports' (requires a method `public function conversionReports()` in
95 * the plugin's controller).
96 * @return ReportWidgetConfig
97 */
98 public function createCustomWidget($action)
99 {
100 $widget = $this->createWidget();
101 $widget->setDefaultViewDataTable(null);
102 $widget->setAction($action);
103 return $widget;
104 }
105 }
106