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
Afficher le fichier Open project: piwik/piwik Class Usage Examples

Méthodes publiques

Свойство Type Description
$maxVisitsSummed @see sumRow - implementation detail
$subtableId

Méthodes publiques

Méthode 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.

Méthodes protégées

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

Private Methods

Méthode Description
getColumnValuesMerged ( $operation, $thisColumnValue, $columnToSumValue, $thisRow, $rowToSum )
isSummableColumn ( $columnName )
warnIfSubtableAlreadyExists ( )

Method Details

__construct() public méthode

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 méthode

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

__toString() public méthode

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

addColumn() public méthode

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 méthode

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

addMetadata() public méthode

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 méthode

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

deleteColumn() public méthode

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

deleteMetadata() public méthode

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).
Résultat boolean `true` on success, `false` if the column didn't exist

export() public méthode

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

getColumn() public méthode

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

getColumns() public méthode

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

getIdSubDataTable() public méthode

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

getMetadata() public méthode

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.
Résultat mixed

getSubtable() public méthode

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

hasColumn() public méthode

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
Résultat boolean

isEqual() public static méthode

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
Résultat boolean

isSubtableLoaded() public méthode

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

isSummaryRow() public méthode

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
Résultat boolean

removeSubtable() public méthode

Removes the subtable reference.
public removeSubtable ( )

renameColumn() public méthode

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 méthode

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 méthode

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 méthode

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 méthode

public setNonLoadedSubtableId ( integer $subtableId )
$subtableId integer

setSubtable() public méthode

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.
Résultat Piwik\DataTable Returns `$subTable`.

sumRow() public méthode

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 méthode

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

sumRowMetadata() public méthode

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

sumSubtable() public méthode

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 méthode

protected warnWhenSummingTwoStrings ( $thisColumnValue, $columnToSumValue )

Property Details

$maxVisitsSummed public_oe property

@see sumRow - implementation detail
public $maxVisitsSummed

$subtableId public_oe property

public $subtableId