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

ColumnCallbackAddColumnPercentage.php « Filter « DataTable « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 056c1294400194cc397abc3a396d22cce6f69d8f (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
<?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\Piwik;

/**
 * Calculates a percentage value for each row of a {@link DataTable} and adds the result
 * to each row.
 *
 * See {@link ColumnCallbackAddColumnQuotient} for more information.
 *
 * **Basic usage example**
 *
 *     $nbVisits = // ... get the visits for a period ...
 *     $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('nb_visits', 'nb_visits_percentage', $nbVisits, 1));
 *
 * @api
 */
class ColumnCallbackAddColumnPercentage extends ColumnCallbackAddColumnQuotient
{
    /**
     * Formats the given value as a percentage.
     *
     * @param number $value
     * @param number $divisor
     * @return string
     */
    protected function formatValue($value, $divisor)
    {
        return Piwik::getPercentageSafe($value, $divisor, $this->quotientPrecision) . '%';
    }
}