|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Domain\Igdb\Service; |
|
6
|
|
|
|
|
7
|
|
|
use VideoGamesRecords\CoreBundle\Domain\Igdb\Mapping\PlatformMapping; |
|
8
|
|
|
use VideoGamesRecords\CoreBundle\Domain\Igdb\Mapping\GameMapping; |
|
9
|
|
|
use VideoGamesRecords\CoreBundle\Domain\Igdb\Mapping\GenreMapping; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Central service for all IGDB mappings |
|
13
|
|
|
*/ |
|
14
|
|
|
class IgdbMappingService |
|
15
|
|
|
{ |
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private readonly GameMapping $gameMapping |
|
18
|
|
|
) { |
|
19
|
|
|
} |
|
20
|
|
|
/** |
|
21
|
|
|
* Platform mapping methods |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getPlatformIgdbId(int $vgrPlatformId): ?int |
|
24
|
|
|
{ |
|
25
|
|
|
return PlatformMapping::getIgdbId($vgrPlatformId); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getPlatformVgrId(int $igdbPlatformId): ?int |
|
29
|
|
|
{ |
|
30
|
|
|
return PlatformMapping::getVgrId($igdbPlatformId); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function hasPlatformMapping(int $vgrPlatformId): bool |
|
34
|
|
|
{ |
|
35
|
|
|
return PlatformMapping::hasMapping($vgrPlatformId); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Game mapping methods (database-based) |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getGameIgdbId(int $vgrGameId): ?int |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->gameMapping->getIgdbId($vgrGameId); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getGameVgrId(int $igdbGameId): ?int |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->gameMapping->getVgrId($igdbGameId); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function hasGameMapping(int $vgrGameId): bool |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->gameMapping->hasMapping($vgrGameId); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setGameMapping(int $vgrGameId, ?int $igdbGameId): bool |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->gameMapping->setMapping($vgrGameId, $igdbGameId); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function removeGameMapping(int $vgrGameId): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->gameMapping->removeMapping($vgrGameId); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Genre mapping methods |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getGenreIgdbId(int $vgrGenreId): ?int |
|
70
|
|
|
{ |
|
71
|
|
|
return GenreMapping::getIgdbId($vgrGenreId); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getGenreVgrId(int $igdbGenreId): ?int |
|
75
|
|
|
{ |
|
76
|
|
|
return GenreMapping::getVgrId($igdbGenreId); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function hasGenreMapping(int $vgrGenreId): bool |
|
80
|
|
|
{ |
|
81
|
|
|
return GenreMapping::hasMapping($vgrGenreId); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get mapping statistics for all entity types |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getAllMappingStats(): array |
|
88
|
|
|
{ |
|
89
|
|
|
return [ |
|
90
|
|
|
'platform' => PlatformMapping::getStats(), |
|
91
|
|
|
'game' => $this->gameMapping->getStats(), |
|
92
|
|
|
'genre' => GenreMapping::getStats(), |
|
93
|
|
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Batch convert multiple entity types from VGR to IGDB |
|
98
|
|
|
*/ |
|
99
|
|
|
public function convertBatchVgrToIgdb(array $data): array |
|
100
|
|
|
{ |
|
101
|
|
|
$result = []; |
|
102
|
|
|
|
|
103
|
|
|
if (isset($data['platforms'])) { |
|
104
|
|
|
$result['platforms'] = []; |
|
105
|
|
|
foreach ($data['platforms'] as $vgrId) { |
|
106
|
|
|
$igdbId = $this->getPlatformIgdbId($vgrId); |
|
107
|
|
|
if ($igdbId !== null) { |
|
108
|
|
|
$result['platforms'][$vgrId] = $igdbId; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (isset($data['games'])) { |
|
114
|
|
|
$result['games'] = []; |
|
115
|
|
|
foreach ($data['games'] as $vgrId) { |
|
116
|
|
|
$igdbId = $this->getGameIgdbId($vgrId); |
|
117
|
|
|
if ($igdbId !== null) { |
|
118
|
|
|
$result['games'][$vgrId] = $igdbId; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if (isset($data['genres'])) { |
|
124
|
|
|
$result['genres'] = []; |
|
125
|
|
|
foreach ($data['genres'] as $vgrId) { |
|
126
|
|
|
$igdbId = $this->getGenreIgdbId($vgrId); |
|
127
|
|
|
if ($igdbId !== null) { |
|
128
|
|
|
$result['genres'][$vgrId] = $igdbId; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $result; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|