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.

94 lines
3.7 KiB
PHTML

2 years ago
<?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<62>seln
2 years ago
$game = Http::withHeaders(config('services.igdb'))->withBody(
"fields *,age_ratings.*, age_ratings.*, 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}\";",
2 years ago
"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);
$rating_ids = [];
foreach ($game['age_ratings'] as $rating){
array_push($rating_ids, $rating['rating']);
}
$game['age_ratings'] = $rating_ids;
abort_if(!$game, 404);
#dd($game);
return $game;
}
2 years ago
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<74>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];
}
}