Piwik\DataTable\Filter\

BeautifyTimeRangeLabels

A DataTable filter that replaces range labels whose values are in seconds with prettier, human-friendlier versions.

This filter customizes the behavior of the BeautifyRangeLabels filter so range values that are less than one minute are displayed in seconds but other ranges are displayed in minutes.

Basic usage

$dataTable->filter('BeautifyTimeRangeLabels', array("%1$s-%2$s min", "1 min", "%s min"));

Methods

The class defines the following methods:

  • __construct() — Constructor.
  • beautify() ash; Beautifies a range label and returns the pretty result. Inherited from BeautifyRangeLabels
  • 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.

Signature

  • It accepts the following parameter(s):
    • $table (DataTable) — The DataTable this filter will run over.
    • $labelSecondsPlural (string) — A string to use when beautifying range labels whose lower bound is between 0 and 60. Must be a format string that takes two numeric params.
    • $labelMinutesSingular (string) — A string to use when replacing a range that equals 60-60 (or 1 minute - 1 minute).
    • $labelMinutesPlural (string) — A string to use when replacing a range that spans multiple minutes. This must be a format string that takes one string parameter.

beautify()

Beautifies a range label and returns the pretty result.

See BeautifyRangeLabels.

Signature

  • 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.

If the lower bound of the range is less than 60 the pretty range label will be in seconds. Otherwise, it will be in minutes.

Signature

  • 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+.

If the lower bound of the range is less than 60 the pretty range label will be in seconds. Otherwise, it will be in minutes.

Signature

  • 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.

If the lower bound of the range is less than 60 the pretty range label will be in seconds. Otherwise, it will be in minutes.

Signature

  • 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.