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