From 9c87d24b787e8a1bcfc2907ed92097896a345a35 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 2 Jun 2023 23:13:11 +0200 Subject: [PATCH] Add DataPreper Functions --- app/Http/Controllers/IGDBController.php | 115 ++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/IGDBController.php b/app/Http/Controllers/IGDBController.php index 1b86f30..49d599c 100644 --- a/app/Http/Controllers/IGDBController.php +++ b/app/Http/Controllers/IGDBController.php @@ -13,7 +13,7 @@ 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.*, age_ratings.*, alternative_names.*, 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; + "fields *,age_ratings.*, age_ratings.*, alternative_names.*, name, collection.*, 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') @@ -28,20 +28,33 @@ class IGDBController extends Controller public static function getPreparedGameDetails(string $slug) { $game = IGDBController::getGameDetails($slug); - $rating_urls = []; - # Prep Age Rating Icons - foreach ($game['age_ratings'] as $rating){ - $cur_url = IGDBController::getAgeRatingIcon($rating['rating']); - array_push($rating_urls, $cur_url); - } - $game['age_ratings'] = $rating_ids; + # Prep Age Rating Icons + $game['age_ratings'] = IGDBController::prepAgeRatings($game['age_ratings']); + # Prep alternative names + $game['alternative_names'] = IGDBController::prepAltName($game['alternative_names']); + # Prep category + $game['category'] = IGDBController::prepCategory($game['category']); + # Prep collection + $game['collection'] = IGDBController::prepCollection($game['collection']); + # Prep cover_url + $game['cover'] = IGDBController::prepCover($game['cover']['url']); # Prep Genre $genre_names = []; foreach ($game['genres'] as $genre){ array_push($genre_names, $genre['name']); } $game['genres'] = $genre_names; + # Prep involved Companies + $game['involved_companies'] = IGDBController::prepInvolvedCompanies($game['involved_companies']); + + # TODO complete Preper Functions + # Prep platforms + # Prep release dates + # Prep summary + # Prep tags + # Prep themes + # Prep websites abort_if(!$game, 404); #dd($game); @@ -186,4 +199,90 @@ class IGDBController extends Controller } 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 prepInvolvedCompanies ($companies_data){ + $companies_names = []; + foreach ($companies_data as $name_data){ + array_push($companies_names, $name_data['company']['name']); + } + return $companies_names; + } }