blob: 5ac99ce678af65364ba5ae78011d87d91540b04c (
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
|
<?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
*/
use Piwik\Piwik;
/**
* Add a new column to the table which is a percentage based on the value resulting
* from a callback function with the parameter being another column's value
*
* For example in the keywords table, we can create a "nb_visits_percentage" column
* from the "nb_visits" column that will be nb_visits / $totalValueUsedToComputePercentage
* You can also specify the precision of the percentage value to be displayed (defaults to 0, eg "11%")
*
* Usage:
* $nbVisits = Piwik_VisitsSummary_API::getInstance()->getVisits($idSite, $period, $date);
* $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('nb_visits', 'nb_visits_percentage', $nbVisits, 1));
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient
{
/**
* Formats the given value
*
* @param number $value
* @param number $divisor
* @return string
*/
protected function formatValue($value, $divisor)
{
return Piwik::getPercentageSafe($value, $divisor, $this->quotientPrecision) . '%';
}
}
|