Piwik\DataTable\Filter\
A DataTable filter that replaces range label columns with prettier, human-friendlier versions.
When reports that summarize data over a set of ranges (such as the reports in the VisitorInterest plugin) are archived, they are archived with labels that read as: '$min-$max' or '$min+'. These labels have no units and can look like '1-1'.
This filter can be used to clean up and add units to those range labels. To do this, you supply a string to use when the range specifies only one unit (ie '1-1') and another format string when the range specifies more than one unit (ie '2-2', '3-5' or '6+').
This filter can be extended to vary exactly how ranges are prettified based on the range values found in the DataTable. To see an example of this, take a look at the BeautifyTimeRangeLabels filter.
Basic usage example
$dataTable->queueFilter('BeautifyRangeLabels', array("1 visit", "%s visits"));
The class defines the following methods:
__construct()
— Constructor.filter()
ash; See ColumnCallbackReplace. Inherited from ColumnCallbackReplace
enableRecursive()
ash; Enables/Disables recursive filtering. Inherited from BaseFilter
filterSubTable()
ash; Filters a row's subtable, if one exists and is loaded in memory. Inherited from BaseFilter
beautify()
— Beautifies a range label and returns the pretty result.getSingleUnitLabel()
— Beautifies and returns a range label whose range spans over one unit, ie 1-1, 2-2 or 3-3.getRangeLabel()
— Beautifies and returns a range label whose range is bounded and spans over more than one unit, ie 1-5, 5-10 but NOT 11+.getUnboundedLabel()
— Beautifies and returns a range label whose range is unbounded, ie 5+, 10+, etc.__construct()
Constructor.
It accepts the following parameter(s):
$table
(DataTable
) —
$labelSingular
(string
) —
The string to use when the range being beautified is equal to '1-1 units', eg "1 visit"
.
$labelPlural
(string
) —
The string to use when the range being beautified references more than one unit. This must be a format string that takes one string parameter, eg, "%s visits"
.filter()
It accepts the following parameter(s):
$table
(DataTable
) —It does not return anything or a mixed result.
enableRecursive()
Enables/Disables recursive filtering. Whether this property is actually used is up to the derived BaseFilter class.
It accepts the following parameter(s):
$enable
(bool
) —It does not return anything or a mixed result.
filterSubTable()
Filters a row's subtable, if one exists and is loaded in memory.
$row
(Row
) —
The row whose subtable should be filter.beautify()
Beautifies a range label and returns the pretty result. See BeautifyRangeLabels.
It accepts the following parameter(s):
$value
(string
) —
The range string. This must be in either a '$min-$max' format a '$min+' format.Returns: string
—
The pretty range label.
getSingleUnitLabel()
Beautifies and returns a range label whose range spans over one unit, ie 1-1, 2-2 or 3-3.
This function can be overridden in derived types to customize beautifcation behavior based on the range values.
It accepts the following parameter(s):
$oldLabel
(string
) —
The original label value.$lowerBound
(int
) —
The lower bound of the range.Returns: string
—
The pretty range label.
getRangeLabel()
Beautifies and returns a range label whose range is bounded and spans over more than one unit, ie 1-5, 5-10 but NOT 11+.
This function can be overridden in derived types to customize beautifcation behavior based on the range values.
It accepts the following parameter(s):
$oldLabel
(string
) —
The original label value.$lowerBound
(int
) —
The lower bound of the range.$upperBound
(int
) —
The upper bound of the range.Returns: string
—
The pretty range label.
getUnboundedLabel()
Beautifies and returns a range label whose range is unbounded, ie 5+, 10+, etc.
This function can be overridden in derived types to customize beautifcation behavior based on the range values.
It accepts the following parameter(s):
$oldLabel
(string
) —
The original label value.$lowerBound
(int
) —
The lower bound of the range.Returns: string
—
The pretty range label.