PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Http / Endpoints / Responses / Statistics / CountriesResponse.php

CountriesResponse.php in Metricool – Social media and site statistics 2.1.1, at app/Http/Endpoints/Responses/Statistics/CountriesResponse.php

39 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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