_Note: A DataTable can have only one summary row._
public addSummaryRow ( |
||
$row | ||
return | Returns `$row`. |
public function test_filter_shouldIgnoreSummaryRow() { $row = $this->buildRow(array('label' => 'other')); $this->table->addSummaryRow($row); $this->table->filter($this->filter, array('UTC', 'day', 'today')); $this->assertFalse($row->getMetadata('segmentValue')); }
public function test_filter_ShouldIgnoreSummaryRow() { $summaryRow = $this->buildRow(array('label' => 'my test')); $this->table->addSummaryRow($summaryRow); $this->table->filter($this->filter); $this->assertFalse($summaryRow->getMetadata('segmentValue')); }
public function test_filter_IfMultipleSegmentsAreGiven_ShouldIgnoreASummaryRow() { $summaryRow = $this->buildRow(array('label' => 'part1 part2')); $this->table->addSummaryRow($summaryRow); $this->table->filter($this->filter, array(array('seg1', 'seg2'), $delimiter = ' ')); $this->assertFalse($summaryRow->getMetadata('segment')); }
/** * See {@link Limit}. * * @param DataTable $table */ public function filter($table) { $table->setMetadata(DataTable::TOTAL_ROWS_BEFORE_LIMIT_METADATA_NAME, $table->getRowsCount()); if ($this->keepSummaryRow) { $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW); } // we delete from 0 to offset if ($this->offset > 0) { $table->deleteRowsOffset(0, $this->offset); } // at this point the array has offset less elements. We delete from limit to the end if ($this->limit >= 0) { $table->deleteRowsOffset($this->limit); } if ($this->keepSummaryRow && !empty($summaryRow)) { $table->addSummaryRow($summaryRow); } }
/** * Executes the filter. See {@link AddSummaryRow}. * * @param DataTable $table */ public function filter($table) { $row = new DataTableSummaryRow($table); $row->setColumn('label', $this->labelSummaryRow); $table->addSummaryRow($row); }
/** * Returns a new DataTable in which the rows of this table are replaced with the aggregatated rows of all its subtables. * * @param string|bool $labelColumn If supplied the label of the parent row will be added to * a new column in each subtable row. * * If set to, `'label'` each subtable row's label will be prepended * w/ the parent row's label. So `'child_label'` becomes * `'parent_label - child_label'`. * @param bool $useMetadataColumn If true and if `$labelColumn` is supplied, the parent row's * label will be added as metadata and not a new column. * @return \Piwik\DataTable */ public function mergeSubtables($labelColumn = false, $useMetadataColumn = false) { $result = new DataTable(); $result->setAllTableMetadata($this->getAllTableMetadata()); foreach ($this->getRowsWithoutSummaryRow() as $row) { $subtable = $row->getSubtable(); if ($subtable !== false) { $parentLabel = $row->getColumn('label'); // add a copy of each subtable row to the new datatable foreach ($subtable->getRows() as $id => $subRow) { $copy = clone $subRow; // if the summary row, add it to the existing summary row (or add a new one) if ($id == self::ID_SUMMARY_ROW) { $existing = $result->getRowFromId(self::ID_SUMMARY_ROW); if ($existing === false) { $result->addSummaryRow($copy); } else { $existing->sumRow($copy, $copyMeta = true, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME)); } } else { if ($labelColumn !== false) { // if we're modifying the subtable's rows' label column, then we make // sure to prepend the existing label w/ the parent row's label. otherwise // we're just adding the parent row's label as a new column/metadata. $newLabel = $parentLabel; if ($labelColumn == 'label') { $newLabel .= ' - ' . $copy->getColumn('label'); } // modify the child row's label or add new column/metadata if ($useMetadataColumn) { $copy->setMetadata($labelColumn, $newLabel); } else { $copy->setColumn($labelColumn, $newLabel); } } $result->addRow($copy); } } } } return $result; }
/** * @param DataTable $table */ private function addSummaryRow($table) { if ($table->getRowsCount() <= $this->truncateAfter + 1) { return; } $table->filter('Sort', array($this->columnToSortByBeforeTruncating, 'desc', $naturalSort = true, $recursiveSort = false)); $rows = array_values($table->getRows()); $count = $table->getRowsCount(); $newRow = new Row(array(Row::COLUMNS => array('label' => DataTable::LABEL_SUMMARY_ROW))); $aggregationOps = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME); for ($i = $this->truncateAfter; $i < $count; $i++) { if (!isset($rows[$i])) { // case when the last row is a summary row, it is not indexed by $cout but by DataTable::ID_SUMMARY_ROW $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW); //FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442 if ($summaryRow) { $newRow->sumRow($summaryRow, $enableCopyMetadata = false, $aggregationOps); } } else { $newRow->sumRow($rows[$i], $enableCopyMetadata = false, $aggregationOps); } } $table->filter('Limit', array(0, $this->truncateAfter)); $table->addSummaryRow($newRow); unset($rows); }