Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/DataTable/Row/DataTableSummaryRow.php')
-rw-r--r--core/DataTable/Row/DataTableSummaryRow.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/core/DataTable/Row/DataTableSummaryRow.php b/core/DataTable/Row/DataTableSummaryRow.php
new file mode 100644
index 0000000000..f4203d9489
--- /dev/null
+++ b/core/DataTable/Row/DataTableSummaryRow.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+namespace Piwik\DataTable\Row;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Row;
+
+/**
+ * This class creates a row from a given DataTable.
+ * The row contains
+ * - 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
+ *
+ * @package Piwik
+ * @subpackage DataTable
+ */
+class DataTableSummaryRow extends Row
+{
+ /**
+ * @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->getColumnAggregationOperations());
+ }
+ }
+}