Piwik\Plugins\Insights\Model::getMetricTotalValue PHP Method

getMetricTotalValue() public method

public getMetricTotalValue ( DataTable $currentReport, $metric )
$currentReport Piwik\DataTable
    public function getMetricTotalValue(DataTable $currentReport, $metric)
    {
        $totals = $currentReport->getMetadata('totals');
        if (!empty($totals[$metric])) {
            $totalValue = (int) $totals[$metric];
        } else {
            $totalValue = 0;
        }
        return $totalValue;
    }

Usage Example

Example #1
0
 public function test_getMetricTotalValue_shouldReturnZeroIfMetricHasNoTotal()
 {
     $table = new DataTable();
     $table->setMetadata('totals', array('nb_visits' => '17'));
     $total = $this->model->getMetricTotalValue($table, 'unknown_metric');
     $this->assertEquals(0, $total);
 }