1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Service; |
4
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Statistic\StatisticsValueObject; |
5
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Statistic\StatisticValueObject; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Willy Reiche |
9
|
|
|
* @since 2017-08-26 |
10
|
|
|
* @version 1.0 |
11
|
|
|
*/ |
12
|
|
|
class StatisticService |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param $statistics |
16
|
|
|
* |
17
|
|
|
* @return StatisticsValueObject |
18
|
|
|
*/ |
19
|
|
|
public function getStatistics($statistics) |
20
|
|
|
{ |
21
|
|
|
$categoryStatistics = []; |
22
|
|
|
if (isset($statistics->statistics)) { |
23
|
|
|
$categoryStatistics = $this->getCategoryStatistics($statistics->statistics); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$statisticsSubCategories = []; |
27
|
|
|
if (isset($statistics->subCategories)) { |
28
|
|
|
$statisticsSubCategories = $this->getStatisticsSubCategories($statistics->subCategories); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$statisticsValueObject = new StatisticsValueObject( |
32
|
|
|
$statistics->id, |
33
|
|
|
$statistics->name, |
34
|
|
|
$statisticsSubCategories, |
35
|
|
|
$categoryStatistics |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
return $statisticsValueObject; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $subCategories |
43
|
|
|
* |
44
|
|
|
* @return StatisticsValueObject[] |
45
|
|
|
*/ |
46
|
|
|
private function getStatisticsSubCategories($subCategories) |
47
|
|
|
{ |
48
|
|
|
$categories = []; |
49
|
|
|
foreach ($subCategories as $subCategory) { |
50
|
|
|
$categories[] = $this->getStatistics($subCategory); |
51
|
|
|
} |
52
|
|
|
return $categories; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $statistics |
57
|
|
|
* |
58
|
|
|
* @return StatisticValueObject[] |
59
|
|
|
*/ |
60
|
|
|
private function getCategoryStatistics($statistics) |
61
|
|
|
{ |
62
|
|
|
$categoryStatistics = []; |
63
|
|
|
foreach ($statistics as $statistic) { |
64
|
|
|
$highest = ""; |
65
|
|
|
if (isset($statistic->highest)) { |
66
|
|
|
$highest = $statistic->highest; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$categoryStatistics[] = new StatisticValueObject( |
70
|
|
|
$statistic->id, |
71
|
|
|
$statistic->name, |
72
|
|
|
$statistic->quantity, |
73
|
|
|
$statistic->lastUpdated, |
74
|
|
|
$statistic->money, |
75
|
|
|
$highest |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $categoryStatistics; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|