blob: 5b79a0c8bc1da79bccce4b1a3228742f46b55e6d (
plain)
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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\DataTable;
use Exception;
use Piwik\DataTable;
use Piwik\DataTable\Row;
/**
* A filter is applied instantly to a given DataTable and can
* - remove rows
* - change columns values (lowercase the strings, truncate, etc.)
* - add/remove columns or metadata (compute percentage values, add an 'icon' metadata based on the label, etc.)
* - add/remove/edit sub DataTable associated to some rows
* - whatever you can imagine
*
* The concept is very simple: the filter is given the DataTable
* and can do whatever is necessary on the data (in the filter() method).
*
* @package Piwik
* @subpackage DataTable
*/
abstract class Filter
{
/**
* @var bool
*/
protected $enableRecursive = false;
/**
* @throws Exception
* @param DataTable $table
*/
public function __construct($table)
{
if (!($table instanceof DataTable)) {
throw new Exception("The filter accepts only a DataTable object.");
}
}
/**
* Filters the given data table
*
* @param DataTable $table
*/
abstract public function filter($table);
/**
* Enables/Disables the recursive mode
*
* @param bool $bool
*/
public function enableRecursive($bool)
{
$this->enableRecursive = (bool)$bool;
}
/**
* Filters a subtable
*
* @param Row $row
* @return mixed
*/
public function filterSubTable(Row $row)
{
if (!$this->enableRecursive) {
return;
}
if ($row->isSubtableLoaded()) {
$subTable = Manager::getInstance()->getTable($row->getIdSubDataTable());
$this->filter($subTable);
}
}
}
|