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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Actions\Reports;
use Piwik\Common;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\Actions\Actions;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\API\Request;
abstract class Base extends \Piwik\Plugin\Report
{
protected function init()
{
$this->categoryId = 'General_Actions';
$this->processedMetrics = false;
$this->recursiveLabelSeparator = '/';
}
protected function addBaseDisplayProperties(ViewDataTable $view)
{
$view->config->datatable_js_type = 'ActionsDataTable';
$view->config->search_recursive = true;
$view->config->show_table_all_columns = false;
$view->requestConfig->filter_limit = Actions::ACTIONS_REPORT_ROWS_DISPLAY;
$view->config->show_all_views_icons = false;
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->show_embedded_subtable = true;
}
if (Request::shouldLoadExpanded()) {
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->show_expanded = true;
}
$view->config->filters[] = function ($dataTable) {
Actions::setDataTableRowLevels($dataTable);
};
}
$view->config->filters[] = function ($dataTable) use ($view) {
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->datatable_css_class = 'dataTableActions';
}
};
}
protected function addPageDisplayProperties(ViewDataTable $view)
{
$view->config->addTranslations(array(
'nb_hits' => Piwik::translate('General_ColumnPageviews'),
'nb_visits' => Piwik::translate('General_ColumnUniquePageviews')
));
$formatter = new Formatter();
// add avg_generation_time tooltip
$tooltipCallback = function ($hits, $min, $max) use ($formatter) {
if (!$hits) {
return false;
}
return Piwik::translate("Actions_AvgGenerationTimeTooltip", array(
$hits,
"<br />",
$formatter->getPrettyTimeFromSeconds($min, true),
$formatter->getPrettyTimeFromSeconds($max, true)
));
};
$view->config->filters[] = array('ColumnCallbackAddMetadata',
array(
array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'),
'avg_time_generation_tooltip',
$tooltipCallback
)
);
$this->addExcludeLowPopDisplayProperties($view);
}
protected function addExcludeLowPopDisplayProperties(ViewDataTable $view)
{
if (Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') {
if (Common::getRequestVar('flat', 0, 'int') === 1) {
$view->requestConfig->filter_excludelowpop = 'nb_hits';
} else {
$view->requestConfig->filter_excludelowpop = Metrics::INDEX_PAGE_NB_HITS;
}
$view->requestConfig->filter_excludelowpop_value = function () {
// computing minimum value to exclude (2 percent of the total number of actions)
$visitsInfo = \Piwik\Plugins\VisitsSummary\Controller::getVisitsSummary()->getFirstRow();
$nbActions = $visitsInfo->getColumn('nb_actions');
$nbActionsLowPopulationThreshold = floor(0.02 * $nbActions);
// we remove 1 to make sure some actions/downloads are displayed in the case we have a very few of them
// and each of them has 1 or 2 hits...
return min($visitsInfo->getColumn('max_actions') - 1, $nbActionsLowPopulationThreshold - 1);
};
}
}
}
|