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

AddSummaryRow.php « Filter « DataTable « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 09f6725db0d22be6219ef40022c689dbabb67ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\DataTable\Filter;

use Piwik\DataTable\BaseFilter;
use Piwik\DataTable;
use Piwik\DataTable\Row\DataTableSummaryRow;

/**
 * Adds a summary row to {@link DataTable}s that contains the sum of all other table rows.
 *
 * **Basic usage example**
 * 
 *     $dataTable->filter('AddSummaryRow');
 * 
 *     // use a human readable label for the summary row (instead of '-1')
 *     $dataTable->filter('AddSummaryRow', array($labelSummaryRow = Piwik::translate('General_Total')));
 * 
 * @api
 */
class AddSummaryRow extends BaseFilter
{
    /**
     * Constructor.
     *
     * @param DataTable $table The table that will be filtered.
     * @param int $labelSummaryRow The value of the label column for the new row.
     */
    public function __construct($table, $labelSummaryRow = DataTable::LABEL_SUMMARY_ROW)
    {
        parent::__construct($table);
        $this->labelSummaryRow = $labelSummaryRow;
    }

    /**
     * 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);
    }
}