|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Domain\Igdb\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use VideoGamesRecords\CoreBundle\Repository\GameRepository; |
|
8
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Game; |
|
9
|
|
|
use VideoGamesRecords\IgdbBundle\Entity\Game as IgdbGame; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Database-based mapping between VGR Games and IGDB Games |
|
13
|
|
|
* Uses the ManyToOne relation in the Game entity to store mappings |
|
14
|
|
|
*/ |
|
15
|
|
|
class GameMapping |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct( |
|
18
|
|
|
private readonly GameRepository $gameRepository |
|
19
|
|
|
) { |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Get IGDB Game entity from VGR Game ID |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getIgdbGame(int $vgrGameId): ?IgdbGame |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->gameRepository->findIgdbGame($vgrGameId); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get IGDB Game ID from VGR Game ID |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getIgdbId(int $vgrGameId): ?int |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->gameRepository->findIgdbId($vgrGameId); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get VGR Game entity from IGDB Game entity |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getVgrGame(IgdbGame $igdbGame): ?Game |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->gameRepository->findVgrGameByIgdbGame($igdbGame); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get VGR Game ID from IGDB Game ID |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getVgrId(int $igdbGameId): ?int |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->gameRepository->findVgrIdByIgdbId($igdbGameId); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Check if VGR Game has IGDB mapping |
|
56
|
|
|
*/ |
|
57
|
|
|
public function hasMapping(int $vgrGameId): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getIgdbId($vgrGameId) !== null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get all VGR Game IDs that have IGDB mappings |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getMappedVgrIds(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->gameRepository->findVgrIdsWithIgdbMapping(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get all IGDB Game IDs that are mapped from VGR |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getMappedIgdbIds(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->gameRepository->findMappedIgdbIds(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Set IGDB Game entity for a VGR Game |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setMappingEntity(int $vgrGameId, ?IgdbGame $igdbGame): bool |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->gameRepository->updateIgdbGame($vgrGameId, $igdbGame); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Set IGDB ID for a VGR Game (compatibility method) |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setMapping(int $vgrGameId, ?int $igdbGameId): bool |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->gameRepository->updateIgdbId($vgrGameId, $igdbGameId); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Remove IGDB mapping for a VGR Game |
|
96
|
|
|
*/ |
|
97
|
|
|
public function removeMapping(int $vgrGameId): bool |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->setMapping($vgrGameId, null); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get mapping statistics |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getStats(): array |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->gameRepository->getIgdbMappingStats(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Batch update mappings |
|
112
|
|
|
*/ |
|
113
|
|
|
public function batchUpdateMappings(array $mappings): int |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->gameRepository->batchUpdateIgdbMappings($mappings); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|