You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
18 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class IGDBController extends Controller
{
public static function getGameDetails(string $slug){
// TODO Weiter bauen und weiter Details für Link aufbröseln
$game = Http::withHeaders(config('services.igdb'))->withBody(
"fields *,age_ratings.*,aggregated_rating, age_ratings.*, alternative_names.*, name, collection.*, cover.url, first_release_date, total_rating_count, platforms.abbreviation, rating, rating_count, slug, involved_companies.company.name, keywords.*, genres.name, aggregated_rating, summary, websites.*, videos.*, screenshots.*, release_dates.*, similar_games.*, similar_games.cover.url, similar_games.platforms.abbreviation, themes.*;
where slug=\"{$slug}\";",
"text/plain"
)->post('https://api.igdb.com/v4/games')
->json();
abort_if(!$game, 404);
#dd($game);
return $game[0];
}
public static function getPreparedGameDetails(string $slug){
$game = IGDBController::getGameDetails($slug);
# Prep Age Rating Icons
if (isset($game['age_ratings'])){
$game['age_ratings'] = IGDBController::prepAgeRatings($game['age_ratings']);
}
# Prep alternative names
if (isset($game['alternative_names'])){
$game['alternative_names'] = IGDBController::prepAltName($game['alternative_names']);
}
# Prep category
if (isset($game['category'])){
$game['category'] = IGDBController::prepCategory($game['category']);
}
# Prep collection
if (isset($game['collection'])){
$game['collection'] = IGDBController::prepCollection($game['collection']);
}
# Prep cover_url
if (isset($game['cover'])){
$game['cover'] = IGDBController::prepCover($game['cover']['url']);
}
# Prep Genre
if (isset($game['genres'])){
$game['genres'] = IGDBController::prepGenre($game['genres']);
}
# Prep involved Companies
if (isset($game['involved_companies'])){
$game['involved_companies'] = IGDBController::prepInvolvedCompanies($game['involved_companies']);
}
# Prep keywords
if (isset($game['keywords'])){
$game['keywords'] = IGDBController::prepKeywords($game['keywords']);
}
# Prep platforms
if (isset($game['platforms'])){
$game['platforms'] = IGDBController::prepPlatforms($game['platforms']);
}
# Prep release dates
if (isset($game['release_dates'])){
$game['release_dates'] = IGDBController::prepReleaseDates($game['release_dates']);
}
# Prep screenshots
if (isset($game['screenshots'])){
$game['screenshots'] = IGDBController::prepScreenshots($game['screenshots']);
}
# Prep tags // TODO Check because complex Tag-number conversion
#$game['tags'] = IGDBController::prepTags($game['tags']);
# Prep themes
if (isset($game['themes'])){
$game['themes'] = IGDBController::prepThemes($game['themes']);
}
# Prep websites
if (isset($game['websites'])){
$game['websites'] = IGDBController::prepWebsites($game['websites']);
}
abort_if(!$game, 404);
#dd($game);
return $game;
}
public static function searchGameByName(string $name) {
$response = Http::withHeaders(config('services.igdb'))
->withBody(
"search \"{$name}\"; fields *, name, cover.url, first_release_date, total_rating_count, platforms.abbreviation, rating, rating_count, slug, involved_companies.company.name, genres.name, aggregated_rating, summary, websites.*, videos.*, screenshots.*, similar_games.*, similar_games.cover.url, similar_games.platforms.abbreviation;",
"text/plain"
)
->post('https://api.igdb.com/v4/games')
->json();
return $response;
}
public static function searchGameBySlug(string $slug){
$game_list = Http::withHeaders(config('services.igdb'))->withBody(
"fields *, name, cover.url, first_release_date, total_rating_count, platforms.abbreviation, rating, rating_count, slug, involved_companies.company.name, genres.name, aggregated_rating, summary, websites.*, videos.*, screenshots.*, similar_games.*, similar_games.cover.url, similar_games.platforms.abbreviation;
where slug=\"{$slug}\";",
"text/plain"
)->post('https://api.igdb.com/v4/games')
->json();
abort_if(!$game, 404);
#dd($game);
return $game[0];
}
public static function getAgeRatingData(){
/* *Note* Nullable (einige Felder sind nicht bei allen Einträgen gesetzt)
field type description
category Category Enum The organization that has issued a specific rating
checksum uuid Hash of the object
content_descriptions Array of Age Rating Content Description IDs
rating Rating Enum The title of an age rating
rating_cover_url String The url for the image of a age rating
synopsis String A free text motivating a rating
*/
$game_list = Http::withHeaders(config('services.igdb'))->withBody(
"fields *, content_descriptions.* , rating_cover_url ;",
"text/plain"
)->post('https://api.igdb.com/v4/age_ratings')
->json();
abort_if(!$game, 404);
#dd($game);
return $game[0];
}
public static function getAgeRatingIcon ($rating_id){
$icon_url = "";
switch ($rating_id) {
case "1": # PEGI 3
$icon_url = "https://www.igdb.com/assets/pegi/PEGI_3-477c57b0d607627660e0ee86f4e39bad95233170528b028b21688faaba6a455b.png";
case "2": # PEGI 7
$icon_url = "https://www.igdb.com/assets/pegi/PEGI_7-fc2907b8d2f83bccc55070468cb0d4e90f1dd98a6a987cb53ed908e6eda31451.png";
case "3": # PEGI 12
$icon_url = "https://www.igdb.com/assets/pegi/PEGI_12-5c83ad44ed32a4c9bd40019d9817ba2ef69d2081db831285c64bfe08002a79ae.png";
case "4": # PEGI 16
$icon_url = "https://www.igdb.com/assets/pegi/PEGI_16-177256b4d01a59019d708199d71ccdc9721680ca8165c452b3eecff8bf47b61c.png";
case "5": # PEGI 18
$icon_url = "https://www.igdb.com/assets/pegi/PEGI_18-1efef95fe494465b999ef3d607f28e684a30341a0a9270a071fc559ee09577fc.png";
case "6": # RP
$icon_url = "https://www.igdb.com/assets/esrb/esrb_rp-2b9f914da8685eb905a3cb874e497ce9848db879a65e43444c6998fc28852c9b.png";
case "7": # Early Child (EC)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_ec-c2202019bef0475ea95d5ffdbfd882f595912e4a6cbea9204132fa73a0804076.png";
case "8": # Everyone (E)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_e-3ff51fae393dfcf5decdd4daa462372f28e3d78b417906e64d3d65ff08179838.png";
case "9": # Everyone (E10)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_e10-2b4600f85680e68b6e65b050e150754607669cd2602a224c5d9198ecbf0a860f.png";
case "10": # Teen (T)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_t-addf8c69e4e93438b2a4cf046972279b7f9a6448929fbb0b0b7b7c28a0e60a24.png";
case "11": # Mature (M)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_m-5472ffae8a4488c825e55818f41312dcc04401e45302246d3d19b0a08014de96.png";
case "12": # Adults Only (AO)
$icon_url = "https://www.igdb.com/assets/esrb/esrb_ao-53b8347d8123bf6cab401d0aa7e4f22aa88e25cb6b032be1813f967313bab2c5.png";
case "13": # CERO_A
$icon_url = "https://www.igdb.com/assets/cero/CERO-A-7b18f77081ddbbf98d1695f72730d009da4fca31e35f340359b64764b297c41e.png";
case "14": # CERO_B
$icon_url = "https://www.igdb.com/assets/cero/CERO-B-55bcb867080e544aa4472bcb21eecce372f092fd0fe907b8ea73288361e94a10.png";
case "15": # CERO_C
$icon_url = "https://www.igdb.com/assets/cero/CERO-C-b62841527ba6465a361601c16b4572676bdccfeb5f50caf1dc852ac8adcadcd2.png";
case "16": # CERO_D
$icon_url = "https://www.igdb.com/assets/cero/CERO-D-9d528564f72e69ca9d78219370542cc1884a85b094091357183c0a8b2c00f051.png";
case "17": # CERO_Z
$icon_url = "https://www.igdb.com/assets/cero/CERO-Z-9c14d02eb02f2ae8aba21882d95d1ee7591ab972efeb1083e326bbbb2eb04177.png";
case "18": # USK_0
$icon_url = "https://www.igdb.com/assets/usk/USK-0-4f098f12737c231fbd56afca87c028d8c3c9581bc15a7865b9677d606bd69103.png";
case "19": # USK_6
$icon_url = "https://www.igdb.com/assets/usk/USK-6-d0af52754e00b7161d4592b17ab94003ae26f4160e58c365a6d9c0cdee9e3dc9.png";
case "20": # USK_12
$icon_url = "https://www.igdb.com/assets/usk/USK-12-b06a58c13f5f5bb93f938013ab77cdb3163f62eb91b8ad4cb116c7a7733dc94f.png";
case "21": # USK_16
$icon_url = "https://www.igdb.com/assets/usk/USK-16-3e1175aef83f8c046901f355cfac04d7cb775f00347c428786ece66b2100c78c.png";
case "22": # USK_18
$icon_url = "https://www.igdb.com/assets/usk/USK-18-c75d4bb544f4a98e7f903683e0ab28b8b0e02146fa3c478ab5bbde4e7ee71ef5.png";
case "23": # GRAC_ALL
$icon_url = "https://www.igdb.com/assets/grac/GRAC-all-ea3b2809bf3dc6d6bf65af25c6c7a2736a644c2feb896afaec2ba5d60aad7ad8.png";
case "24": # GRAC_Twelve
$icon_url = "https://www.igdb.com/assets/grac/GRAC-12-8739f938b93dabc915737e4302a6a530b001d56e0da105aa677d3f266997a91c.png";
case "25": # GRAC_Fifteen
$icon_url = "https://www.igdb.com/assets/grac/GRAC-15-0f69666a48c254a680f2c51808b9831d311a3cbf14727c1fdb8332a9ce01b15a.png";
case "26": # GRAC_Eighteen
$icon_url = "https://www.igdb.com/assets/grac/GRAC-18-17047dba082572bfefdb159b14bd2a65c3323473938cade2746e65ad01a091fa.png";
case "27": # GRAC_TESTING
$icon_url = "https://www.igdb.com/assets/grac/GRAC-testing-fdb410e25ef5237353a2f8d98127ff3ef5aec2e4317da7c844fc426ba47462b9.png";
case "28": # CLASS_IND_L
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-L-0574985f80873413e495027fd5e71a30b589ef6801a3cf05d898c593ad694459.png";
case "29": # CLASS_IND_Ten
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-10-b2c0a0ce9872f295080bc85bfb96dee3643237b557f62b5051646ccbc9292e4f.png";
case "30": # CLASS_IND_Twelve
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-12-ae5d972b5ca5159c9dd5b4295d96f9dc8991a6cc863e5d1572900076420d211a.png";
case "31": # CLASS_IND_Fourteen
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-14-2f728c71718d4f6e2b03523e172dbc6fec3adf24a9c517fb607832262b090a62.png";
case "32": # CLASS_IND_Sixteen
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-16-72b2d94aee82d6552c2cda8e7e7f742f16621e832ef21b30eb8da2e99683abf7.png";
case "33": # CLASS_IND_Eighteen
$icon_url = "https://www.igdb.com/assets/class_ind/ClassInd-18-8cfef0946bb2ec76b7462a8626d3ac57212f48bd4f9d65b6845f0aedeb055de3.png";
case "34": # ACB_G
$icon_url = "https://www.igdb.com/assets/acb/ACB-G-1e1a8ffce64eb9f1103803e82ba597f2dfba9071a15645ac0055f0ecf4b1d3a3.png";
case "35": # ACB_PG
$icon_url = "https://www.igdb.com/assets/acb/ACB-PG-e3994b0735b7dc5796d232fa422b50e069aed98a63a5694bac301c11d16ea56f.png";
case "36": # ACB_M
$icon_url = "https://www.igdb.com/assets/acb/ACB-M-051441e5b1ccde43b84a2124fbbcbeb4d23624389d265914fd9bef4079a3fd63.png";
case "37": # ACB_MA15
$icon_url = "https://www.igdb.com/assets/acb/ACB-MA15-60f3d60093cb113bedb1224b2469a5a1cf23651bf53fb46dae4319091c0cd192.png";
case "38": # ACB_R18
$icon_url = "https://www.igdb.com/assets/acb/ACB-R18-08f8e4b9f19e35932a9d2bc1ecd9d3cdca50de35e11380308e1982caa16c5934.png";
case "39": # ACB_RC
$icon_url = "https://www.igdb.com/assets/acb/ACB-RC-430420e914f169913dc375ed88c8d67dfab2d2786841241c9ea253e180c643b9.png";
}
return $icon_url;
}
# Prep Functions
public static function prepAgeRatings ($ratings){
$rating_urls = [];
foreach ($ratings as $rating){
$cur_url = IGDBController::getAgeRatingIcon($rating['rating']);
array_push($rating_urls, $cur_url);
}
return $rating_urls;
}
public static function prepAltName ($altNames){
$prep_alt_names = [];
foreach ($altNames as $name_data){
array_push($prep_alt_names, $name_data['name']);
}
return $prep_alt_names;
}
public static function prepCategory ($category){
$formatedCategory = $category;
switch ($formatedCategory) {
case 0 :
$formatedCategory = "main_game";
break;
case 1 :
$formatedCategory = "dlc_addon";
break;
case 2 :
$formatedCategory = "expansion";
break;
case 3 :
$formatedCategory = "bundle";
break;
case 4 :
$formatedCategory = "standalone_expansion";
break;
case 5 :
$formatedCategory = "mod";
break;
case 6 :
$formatedCategory = "episode";
break;
case 7 :
$formatedCategory = "season";
break;
case 8 :
$formatedCategory = "remake";
break;
case 9 :
$formatedCategory = "remaster";
break;
case 10 :
$formatedCategory = "expanded_game";
break;
case 11 :
$formatedCategory = "port";
break;
case 12 :
$formatedCategory = "fork";
break;
case 13 :
$formatedCategory = "pack";
break;
case 14 :
$formatedCategory = "update";
break;
default :
$formatedCategory = "undefined";
break;
}
return $formatedCategory;
}
public static function prepCollection($collection_data){
$collection_name = ['name' => $collection_data['name'], 'slug' => $collection_data['slug']];
return $collection_name;
}
public static function prepCover($cover_url){
$prep_cover = Str::replaceFirst('thumb', 'cover_big', $cover_url);
return $prep_cover;
}
public static function prepGenre($genres){
$genre_names = [];
foreach ($genres as $genre){
array_push($genre_names, $genre['name']);
}
return $genre_names;
}
public static function prepInvolvedCompanies ($companies_data){
$companies_names = [];
foreach ($companies_data as $name_data){
array_push($companies_names, $name_data['company']['name']);
}
return $companies_names;
}
public static function prepKeywords ($keywords){
$prep_keywords = [];
foreach ($keywords as $keyword_data){
array_push($prep_keywords, $keyword_data['name']);
}
return $prep_keywords;
}
public static function prepPlatforms ($platforms){
$prep_platforms = [];
foreach ($platforms as $platform_data){
array_push($prep_platforms, $platform_data['abbreviation']);
}
return $prep_platforms;
}
public static function prepReleaseDates ($rel_dates){
$prep_dates = [];
foreach ($rel_dates as $index => $rel_date_data){
$region = $rel_date_data['region'];
switch($region){
case 1: # Europe
$region = 'europe';
break;
case 2: # north_america
$region = 'north_america';
break;
case 3: # australia
$region = 'australia';
break;
case 4: # new_zealand
$region = 'new_zealand';
break;
case 5: # japan
$region = 'japan';
break;
case 6: # china
$region = 'china';
break;
case 7: # asia
$region = 'asia';
break;
case 8: # worldwide
$region = 'worldwide';
break;
case 9: # korea
$region = 'korea';
break;
case 10: # brazil
$region = 'brazil';
break;
}
array_push($prep_dates,['date' => $rel_date_data['date'], 'region' => $region ]);
}
return $prep_dates;
}
public static function prepScreenshots ($screenshots){
$prep_screens = [];
foreach ($screenshots as $screenshot_data){
array_push($prep_screens,
[
'height' => $screenshot_data['height'],
'width' => $screenshot_data['width'],
'url' => Str::replaceFirst('thumb', 'screenshot_big', $screenshot_data['url'])
]);
}
return $prep_screens;
}
public static function prepTags($tags){
$prep_tags = [];
foreach ($tags as $tag_data){
}
return $prep_tags;
}
public static function prepThemes($themes){
$prep_themes = [];
foreach ($themes as $theme_data){
array_push($prep_themes,$theme_data['name']);
}
return $prep_themes;
}
public static function prepWebsites($websites){
$prep_sites = [];
foreach ($websites as $website_data){
array_push($prep_sites,$website_data['url']);
}
return $prep_sites;
}
}