Piwik\DataTable\Row::sumRowMetadata PHP Method

sumRowMetadata() public method

Sums the metadata in $rowToSum with the metadata in $this row.
public sumRowMetadata ( Row $rowToSum, array $aggregationOperations = [] )
$rowToSum Row
$aggregationOperations array
    public function sumRowMetadata($rowToSum, $aggregationOperations = array())
    {
        if (!empty($rowToSum->metadata) && !$this->isSummaryRow()) {
            $aggregatedMetadata = array();
            if (is_array($aggregationOperations)) {
                // we need to aggregate value before value is overwritten by maybe another row
                foreach ($aggregationOperations as $columnn => $operation) {
                    $thisMetadata = $this->getMetadata($columnn);
                    $sumMetadata = $rowToSum->getMetadata($columnn);
                    if ($thisMetadata === false && $sumMetadata === false) {
                        continue;
                    }
                    $aggregatedMetadata[$columnn] = $this->getColumnValuesMerged($operation, $thisMetadata, $sumMetadata, $this, $rowToSum);
                }
            }
            // We shall update metadata, and keep the metadata with the _most visits or pageviews_, rather than first or last seen
            $visits = max($rowToSum->getColumn(Metrics::INDEX_PAGE_NB_HITS) || $rowToSum->getColumn(Metrics::INDEX_NB_VISITS), $rowToSum->getColumn('nb_actions') || $rowToSum->getColumn('nb_visits'));
            if ($visits && $visits > $this->maxVisitsSummed || empty($this->metadata)) {
                $this->maxVisitsSummed = $visits;
                $this->metadata = $rowToSum->metadata;
            }
            foreach ($aggregatedMetadata as $column => $value) {
                // we need to make sure aggregated value is used, and not metadata from $rowToSum
                $this->setMetadata($column, $value);
            }
        }
    }

Usage Example

Beispiel #1
0
 public function test_sumRowMetadata_uniquearraymergeShouldUseArrayFromThisRow_IfNoMetadataForOtherRowSpecified()
 {
     $row = $this->getTestRowWithNoSubDataTable();
     $arrayValue = array(array('test' => 3, 'value' => 3), array('test' => 2, 'value' => 2));
     $this->row->setMetadata('my_array', $arrayValue);
     $aggregations = array('my_array' => 'uniquearraymerge');
     $this->row->sumRowMetadata($row, $aggregations);
     $this->assertSame(array('my_array' => $arrayValue), $this->row->getMetadata());
 }
All Usage Examples Of Piwik\DataTable\Row::sumRowMetadata