Newer
Older
mattpiwik
a validé
<?php
/**
* Piwik - Open source web analytics
mattpiwik
a validé
* @link http://piwik.org
mattpiwik
a validé
*/
namespace Piwik\DataTable\Row;
use Piwik\DataTable\Manager;
use Piwik\DataTable;
use Piwik\DataTable\Row;
mattpiwik
a validé
/**
* This class creates a row from a given DataTable.
* The row contains
mattpiwik
a validé
* - for each numeric column, the returned "summary" column is the sum of all the subRows
* - for every other column, it is ignored and will not be in the "summary row"
* @see \DataTable\Row::sumRow() for more information on the algorithm
* @subpackage DataTable
mattpiwik
a validé
*/
class DataTableSummaryRow extends Row
mattpiwik
a validé
{
* @param DataTable $subTable
*/
function __construct($subTable = null)
{
parent::__construct();
if ($subTable !== null) {
$this->sumTable($subTable);
}
}
/**
* Reset this row to an empty one and sum the associated subTable again.
*/
public function recalculate()
{
$id = $this->getIdSubDataTable();
if ($id !== null) {
$subTable = Manager::getInstance()->getTable($id);
$this->sumTable($subTable);
}
}
/**
* Sums a tables row with this one.
*
* @param DataTable $table
*/
private function sumTable($table)
{
foreach ($table->getRows() as $row) {
$this->sumRow($row, $enableCopyMetadata = false, $table->metadata[DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME]);