diff --git a/app/Http/Controllers/IGDBController.php b/app/Http/Controllers/IGDBController.php index 49d599c..b31bb64 100644 --- a/app/Http/Controllers/IGDBController.php +++ b/app/Http/Controllers/IGDBController.php @@ -10,10 +10,10 @@ 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 + 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, 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; + "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') @@ -25,36 +25,64 @@ class IGDBController extends Controller return $game[0]; } - public static function getPreparedGameDetails(string $slug) - { + public static function getPreparedGameDetails(string $slug){ $game = IGDBController::getGameDetails($slug); # Prep Age Rating Icons - $game['age_ratings'] = IGDBController::prepAgeRatings($game['age_ratings']); + if (isset($game['age_ratings'])){ + $game['age_ratings'] = IGDBController::prepAgeRatings($game['age_ratings']); + } # Prep alternative names - $game['alternative_names'] = IGDBController::prepAltName($game['alternative_names']); + if (isset($game['alternative_names'])){ + $game['alternative_names'] = IGDBController::prepAltName($game['alternative_names']); + } # Prep category - $game['category'] = IGDBController::prepCategory($game['category']); + if (isset($game['category'])){ + $game['category'] = IGDBController::prepCategory($game['category']); + } # Prep collection - $game['collection'] = IGDBController::prepCollection($game['collection']); + if (isset($game['collection'])){ + $game['collection'] = IGDBController::prepCollection($game['collection']); + } # Prep cover_url - $game['cover'] = IGDBController::prepCover($game['cover']['url']); + if (isset($game['cover'])){ + $game['cover'] = IGDBController::prepCover($game['cover']['url']); + } # Prep Genre - $genre_names = []; - foreach ($game['genres'] as $genre){ - array_push($genre_names, $genre['name']); + if (isset($game['genres'])){ + $game['genres'] = IGDBController::prepGenre($game['genres']); } - $game['genres'] = $genre_names; # Prep involved Companies - $game['involved_companies'] = IGDBController::prepInvolvedCompanies($game['involved_companies']); - - # TODO complete Preper Functions + 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 - # Prep summary - # Prep tags + 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); @@ -75,8 +103,7 @@ class IGDBController extends Controller return $response; } - public static function searchGameBySlug(string $slug) - { + 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; @@ -91,8 +118,7 @@ class IGDBController extends Controller return $game[0]; } - public static function getAgeRatingData() - { + 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 @@ -278,6 +304,13 @@ class IGDBController extends Controller $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){ @@ -285,4 +318,91 @@ class IGDBController extends Controller } 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; + } }