| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Http\Endpoints\Responses\Statistics; |
| 6 |
|
| 7 |
use Locale; |
| 8 |
use Metricool\Http\Endpoints\Responses\DistributionResponse; |
| 9 |
use Metricool\Http\Metricool\DTOs\DistributionDTO; |
| 10 |
|
| 11 |
class CountriesResponse extends DistributionResponse |
| 12 |
{ |
| 13 |
/** |
| 14 |
* The columns for the country chart. Keys represent the property, |
| 15 |
* value is the label for this property |
| 16 |
* @see \Metricool\Support\Builders\StatsChartTableBuilder::setColumns() |
| 17 |
*/ |
| 18 |
public function getChartColumns(): array |
| 19 |
{ |
| 20 |
return [ |
| 21 |
'country' => __('Country', 'metricool'), |
| 22 |
'visitors' => __('Visitors', 'metricool'), |
| 23 |
'percentage' => __('Percentage', 'metricool'), |
| 24 |
]; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @inheritDoc |
| 29 |
*/ |
| 30 |
protected function parseSingleItem(DistributionDTO $item, int $total): object |
| 31 |
{ |
| 32 |
return (object) [ |
| 33 |
'country' => Locale::getDisplayRegion('-' . $item->value, get_user_locale()), |
| 34 |
'visitors' => $item->amount, |
| 35 |
'percentage' => $item->calculatePercentageFromTotal($total), |
| 36 |
]; |
| 37 |
} |
| 38 |
} |
| 39 |
|