PHP Class Piwik\DataTable\Row

DataTable rows contain columns, metadata and a subtable ID. Columns and metadata are stored as an array of name => value mappings.
Inheritance: implements ArrayAccess, implements IteratorAggregate
Mostra file Open project: piwik/piwik Class Usage Examples

Public Properties

Property Type Description
$maxVisitsSummed @see sumRow - implementation detail
$subtableId

Public Methods

Method Description
__construct ( array $row = [] ) Constructor.
__destruct ( ) When destroyed, a row destroys its associated subtable if there is one.
__toString ( ) : string Applies a basic rendering to the Row and returns the output.
addColumn ( string $name, mixed $value ) Add a new column to the row. If the column already exists, throws an exception.
addColumns ( array $columns ) : void Add many columns to this row.
addMetadata ( string $name, mixed $value ) Add a new metadata to the row. If the metadata already exists, throws an exception.
compareElements ( mixed $elem1, mixed $elem2 ) : boolean Helper function to compare array elements
deleteColumn ( string $name ) : boolean Deletes the given column.
deleteMetadata ( boolean | string $name = false ) : boolean Deletes one metadata value or all metadata values.
export ( ) : array Used when archiving to serialize the Row's properties.
getColumn ( string $name ) : mixed | false Returns a column by name.
getColumns ( ) : array Returns the array containing all the columns.
getIdSubDataTable ( ) : integer | null Returns the ID of the subDataTable.
getMetadata ( string | null $name = null ) : mixed Returns the array of all metadata, or one requested metadata value.
getSubtable ( ) : DataTable | boolean Returns the associated subtable, if one exists. Returns false if none exists.
hasColumn ( string $name ) : boolean 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.
isEqual ( Row $row1, Row $row2 ) : boolean Helper function that tests if two rows are equal.
isSubtableLoaded ( ) : boolean Returns true if the subtable is currently loaded in memory via {@link Piwik\DataTable\Manager}.
isSummaryRow ( ) : boolean Returns true if this row is the summary row, false if otherwise. This function depends on the label of the row, and so, is not 100% accurate.
removeSubtable ( ) Removes the subtable reference.
renameColumn ( string $oldName, string $newName ) Renames a column.
setColumn ( string $name, mixed $value ) Set the value $value to the column called $name.
setColumns ( array $columns ) Set all the columns at once. Overwrites **all** previously set columns.
setMetadata ( string $name, mixed $value ) Set the value $value to the metadata called $name.
setNonLoadedSubtableId ( integer $subtableId )
setSubtable ( DataTable $subTable ) : DataTable Attaches a subtable to this row, overwriting the existing subtable, if any.
sumRow ( Row $rowToSum, boolean $enableCopyMetadata = true, array | boolean $aggregationOperations = false ) Sums the given $rowToSum columns values to the existing row column values.
sumRowMetadata ( Row $rowToSum, array $aggregationOperations = [] ) Sums the metadata in $rowToSum with the metadata in $this row.
sumSubtable ( DataTable $subTable ) Sums a DataTable to this row's subtable. If this row has no subtable a new one is created.

Protected Methods

Method Description
sumRowArray ( number | boolean $thisColumnValue, number | array $columnToSumValue ) : array | integer Helper function: sums 2 values
warnWhenSummingTwoStrings ( $thisColumnValue, $columnToSumValue )

Private Methods

Method Description
getColumnValuesMerged ( $operation, $thisColumnValue, $columnToSumValue, $thisRow, $rowToSum )
isSummableColumn ( $columnName )
warnIfSubtableAlreadyExists ( )

Method Details

__construct() public method

Constructor.
public __construct ( array $row = [] )
$row array An array with the following structure: array( Row::COLUMNS => array('label' => 'Piwik', '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) )

__destruct() public method

When destroyed, a row destroys its associated subtable if there is one.
public __destruct ( )

__toString() public method

Applies a basic rendering to the Row and returns the output.
public __toString ( ) : string
return string describing the row. Example: "- 1 ['label' => 'piwik', 'nb_uniq_visitors' => 1685, 'nb_visits' => 1861] [] [idsubtable = 1375]"

addColumn() public method

Add a new column to the row. If the column already exists, throws an exception.
public addColumn ( string $name, mixed $value )
$name string name of the column to add.
$value mixed value of the column to set or a PHP callable.

addColumns() public method

Add many columns to this row.
public addColumns ( array $columns ) : void
$columns array Name/Value pairs, e.g., `array('name' => $value , ...)`
return void

addMetadata() public method

Add a new metadata to the row. If the metadata already exists, throws an exception.
public addMetadata ( string $name, mixed $value )
$name string name of the metadata to add.
$value mixed value of the metadata to set.

compareElements() public static method

Helper function to compare array elements
public static compareElements ( mixed $elem1, mixed $elem2 ) : boolean
$elem1 mixed
$elem2 mixed
return boolean

deleteColumn() public method

Deletes the given column.
public deleteColumn ( string $name ) : boolean
$name string The column name.
return boolean `true` on success, `false` if the column does not exist.

deleteMetadata() public method

Deletes one metadata value or all metadata values.
public deleteMetadata ( boolean | string $name = false ) : boolean
$name boolean | string Metadata name (omit to delete entire metadata).
return boolean `true` on success, `false` if the column didn't exist

export() public method

Used when archiving to serialize the Row's properties.
public export ( ) : array
return array

getColumn() public method

Returns a column by name.
public getColumn ( string $name ) : mixed | false
$name string The column name.
return mixed | false The column value or false if it doesn't exist.

getColumns() public method

Returns the array containing all the columns.
public getColumns ( ) : array
return array Example: array( 'column1' => VALUE, 'label' => 'www.php.net' 'nb_visits' => 15894, )

getIdSubDataTable() public method

If there is no such a table, returns null.
public getIdSubDataTable ( ) : integer | null
return integer | null

getMetadata() public method

Returns the array of all metadata, or one requested metadata value.
public getMetadata ( string | null $name = null ) : mixed
$name string | null The name of the metadata to return or null to return all metadata.
return mixed

getSubtable() public method

Returns the associated subtable, if one exists. Returns false if none exists.
public getSubtable ( ) : DataTable | boolean
return Piwik\DataTable | boolean

hasColumn() public method

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.
public hasColumn ( string $name ) : boolean
$name string
return boolean

isEqual() public static method

Two rows are equal if: - they have exactly the same columns / metadata - they have a subDataTable associated, then we check that both of them are the same. Column order is not important.
public static isEqual ( Row $row1, Row $row2 ) : boolean
$row1 Row first to compare
$row2 Row second to compare
return boolean

isSubtableLoaded() public method

Returns true if the subtable is currently loaded in memory via {@link Piwik\DataTable\Manager}.
public isSubtableLoaded ( ) : boolean
return boolean

isSummaryRow() public method

Returns true if this row is the summary row, false if otherwise. This function depends on the label of the row, and so, is not 100% accurate.
public isSummaryRow ( ) : boolean
return boolean

removeSubtable() public method

Removes the subtable reference.
public removeSubtable ( )

renameColumn() public method

Renames a column.
public renameColumn ( string $oldName, string $newName )
$oldName string The current name of the column.
$newName string The new name of the column.

setColumn() public method

Set the value $value to the column called $name.
public setColumn ( string $name, mixed $value )
$name string name of the column to set.
$value mixed value of the column to set.

setColumns() public method

Set all the columns at once. Overwrites **all** previously set columns.
public setColumns ( array $columns )
$columns array eg, `array('label' => 'www.php.net', 'nb_visits' => 15894)`

setMetadata() public method

Set the value $value to the metadata called $name.
public setMetadata ( string $name, mixed $value )
$name string name of the metadata to set.
$value mixed value of the metadata to set.

setNonLoadedSubtableId() public method

public setNonLoadedSubtableId ( integer $subtableId )
$subtableId integer

setSubtable() public method

Attaches a subtable to this row, overwriting the existing subtable, if any.
public setSubtable ( DataTable $subTable ) : DataTable
$subTable Piwik\DataTable DataTable to associate to this row.
return Piwik\DataTable Returns `$subTable`.

sumRow() public method

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.
public sumRow ( Row $rowToSum, boolean $enableCopyMetadata = true, array | boolean $aggregationOperations = false )
$rowToSum Row The row to sum to this row.
$enableCopyMetadata boolean Whether metadata should be copied or not.
$aggregationOperations array | boolean for columns that should not be summed, determine which aggregation should be used (min, max). format: `array('column name' => 'function name')`

sumRowArray() protected method

Helper function: sums 2 values
protected sumRowArray ( number | boolean $thisColumnValue, number | array $columnToSumValue ) : array | integer
$thisColumnValue number | boolean
$columnToSumValue number | array
return array | integer

sumRowMetadata() public method

Sums the metadata in $rowToSum with the metadata in $this row.
public sumRowMetadata ( Row $rowToSum, array $aggregationOperations = [] )
$rowToSum Row
$aggregationOperations array

sumSubtable() public method

See {@link Piwik\DataTable::addDataTable()} to learn how DataTables are summed.
public sumSubtable ( DataTable $subTable )
$subTable Piwik\DataTable Table to sum to this row's subtable.

warnWhenSummingTwoStrings() protected method

protected warnWhenSummingTwoStrings ( $thisColumnValue, $columnToSumValue )

Property Details

$maxVisitsSummed public_oe property

@see sumRow - implementation detail
public $maxVisitsSummed

$subtableId public_oe property

public $subtableId