Piwik\DataTable\
This is what a DataTable is composed of.
DataTable rows contain columns, metadata and a subtable ID. Columns and metadata are stored as an array of name => value mappings.
This class defines the following properties:
$maxVisitsSummed
$subtableId
The class defines the following methods:
__construct()
— Constructor.__toString()
— Applies a basic rendering to the Row and returns the output.deleteColumn()
— Deletes the given column.renameColumn()
— Renames a column.getColumn()
— Returns a column by name.getMetadata()
— Returns the array of all metadata, or one requested metadata value.hasColumn()
— Returns true if a column having the given name is already registered.getColumns()
— Returns the array containing all the columns.getIdSubDataTable()
— Returns the ID of the subDataTable.getSubtable()
— Returns the associated subtable, if one exists.sumSubtable()
— Sums a DataTable to this row's subtable.setSubtable()
— Attaches a subtable to this row, overwriting the existing subtable, if any.isSubtableLoaded()
— Returns true
if the subtable is currently loaded in memory via Piwik\DataTable\Manager.removeSubtable()
— Removes the subtable reference.setColumns()
— Set all the columns at once.setColumn()
— Set the value $value
to the column called $name
.setMetadata()
— Set the value $value
to the metadata called $name
.setAllMetadata()
— Sets all metadata at once.deleteMetadata()
— Deletes one metadata value or all metadata values.addColumn()
— Add a new column to the row.addColumns()
— Add many columns to this row.addMetadata()
— Add a new metadata to the row.sumRow()
— Sums the given $rowToSum
columns values to the existing row column values.sumRowMetadata()
— Sums the metadata in $rowToSum
with the metadata in $this
row.isSummaryRow()
— Returns true
if this row was added to a datatable as the summary row, false
if otherwise.setIsSummaryRow()
getComparisons()
— Returns the associated comparisons DataTable, if any.setComparisons()
— Associates the supplied table with this row as the comparisons table.isEqual()
— Helper function that tests if two rows are equal.__construct()
Constructor.
$row
(array
) —
An array with the following structure: array( Row::COLUMNS => array('label' => 'Matomo', 'column1' => 42, 'visits' => 657, 'time_spent' => 155744), Row::METADATA => array('logo' => 'test.png'), Row::DATATABLE_ASSOCIATED => $subtable // DataTable object // (but in the row only the ID will be stored) )__toString()
Applies a basic rendering to the Row and returns the output.
string
—
describing the row. Example:
"- 1 ['label' => 'piwik', 'nb_uniq_visitors' => 1685, 'nb_visits' => 1861] [] [idsubtable = 1375]"deleteColumn()
Deletes the given column.
It accepts the following parameter(s):
$name
(string
) —
The column name.Returns: bool
—
true
on success, false
if the column does not exist.
renameColumn()
Renames a column.
$oldName
(string
) —
The current name of the column.$newName
(string
) —
The new name of the column.getColumn()
Returns a column by name.
It accepts the following parameter(s):
$name
(string
) —
The column name.Returns: mixed
|false
—
The column value or false if it doesn't exist.
getMetadata()
Returns the array of all metadata, or one requested metadata value.
$name
(string
|null
) —
The name of the metadata to return or null to return all metadata.mixed
value.hasColumn()
Returns true if a column having the given name is already registered. The value will not be evaluated, it will just check whether a column exists independent of its value.
It accepts the following parameter(s):
$name
(string
) —It returns a bool
value.
getColumns()
Returns the array containing all the columns.
Returns: array
—
Example:
array(
'column1' => VALUE,
'label' => 'www.php.net'
'nb_visits' => 15894,
)
getIdSubDataTable()
Returns the ID of the subDataTable.
If there is no such a table, returns null.
int
|null
—getSubtable()
Returns the associated subtable, if one exists. Returns false
if none exists.
DataTable
|bool
—sumSubtable()
Sums a DataTable to this row's subtable. If this row has no subtable a new one is created.
See DataTable::addDataTable() to learn how DataTables are summed.
$subTable
(DataTable
) —
Table to sum to this row's subtable.setSubtable()
Attaches a subtable to this row, overwriting the existing subtable, if any.
It accepts the following parameter(s):
$subTable
(DataTable
) —
DataTable to associate to this row.Returns: DataTable
—
Returns $subTable
.
isSubtableLoaded()
Returns true
if the subtable is currently loaded in memory via Piwik\DataTable\Manager.
bool
value.removeSubtable()
Removes the subtable reference.
setColumns()
Set all the columns at once. Overwrites all previously set columns.
$columns
(array
) —
eg, array('label' => 'www.php.net', 'nb_visits' => 15894)
setColumn()
Set the value $value
to the column called $name
.
$name
(string
) —
name of the column to set.$value
(mixed
) —
value of the column to set.setMetadata()
Set the value $value
to the metadata called $name
.
$name
(string
) —
name of the metadata to set.$value
(mixed
) —
value of the metadata to set.setAllMetadata()
Sets all metadata at once.
$metadata
(array
) —
new metadata to setdeleteMetadata()
Deletes one metadata value or all metadata values.
It accepts the following parameter(s):
$name
(bool
|string
) —
Metadata name (omit to delete entire metadata).Returns: bool
—
true
on success, false
if the column didn't exist
addColumn()
Add a new column to the row. If the column already exists, throws an exception.
$name
(string
) —
name of the column to add.$value
(mixed
) —
value of the column to set or a PHP callable.Exception
— if the column already exists.addColumns()
Add many columns to this row.
$columns
(array
) —
Name/Value pairs, e.g., array('name' => $value , ...)
void
value.Exception
— if any column name does not exist.addMetadata()
Add a new metadata to the row. If the metadata already exists, throws an exception.
$name
(string
) —
name of the metadata to add.$value
(mixed
) —
value of the metadata to set.Exception
— if the metadata already exists.sumRow()
Sums the given $rowToSum
columns values to the existing row column values.
Only the int or float values will be summed. Label columns will be ignored even if they have a numeric value.
Columns in $rowToSum
that don't exist in $this
are added to $this
.
$rowToSum
(Row
) —
The row to sum to this row.$enableCopyMetadata
(bool
) —
Whether metadata should be copied or not.$aggregationOperations
(array
|bool
) —
for columns that should not be summed, determine which aggregation should be used (min, max). format: array('column name' => 'function name')
sumRowMetadata()
Sums the metadata in $rowToSum
with the metadata in $this
row.
It accepts the following parameter(s):
$rowToSum
(Row
) —
$aggregationOperations
(array
) —
It does not return anything or a mixed result.
isSummaryRow()
Returns true
if this row was added to a datatable as the summary row, false
if otherwise.
bool
value.setIsSummaryRow()
getComparisons()
Returns the associated comparisons DataTable, if any.
DataTable
|null
—setComparisons()
Associates the supplied table with this row as the comparisons table.
It accepts the following parameter(s):
$table
(DataTable
) —It does not return anything or a mixed result.
isEqual()
Helper function that tests if two rows are equal.
Two rows are equal if:
Column order is not important.