Tustin / psn-php

A PHP wrapper for the PSN API
https://tustin.dev/psn-php/
MIT License
354 stars 73 forks source link

Attempt to get DLC names, but empty string given. #258

Closed yduke closed 1 month ago

yduke commented 1 month ago

For some games with DLCs and have trophies in each DLCs, I have tried to get each DLC names, for example:

Nioh 2

So, I've tried:

$games = $user->trophyTitles();
foreach ($games as $k => $game) {
    foreach ($game->trophyGroups() as $trophyGroup) {
        $groupId= $trophyGroup->id();      // this works, returns DLC IDs like default, 001, 002 ....
        $dlcName= $trophyGroup->name();   // this will always be an empty strig:'';
        var_dump($dlcName);
    }
}

https://github.com/Tustin/psn-php/blob/b4ecb23e16a39815237bd884f50950a777e882e7/src/Model/Trophy/TrophyGroup.php#L48-L54

The name of DLC ($trophyGroup->name() ) will always be an empty string, I've tried to var_dump each whole $trophyGroup, not found the DLC name in there, the trophyGroupId is there though, given "default", "001", "002" ....ext.

Is there any other way to get DLC name(s) for a game (trohyTitle) ? Thank you for any help.

Ragowit commented 1 month ago

You are looking through the games (trophy titles) from a user, these will only have the id and associated user data related to said game.

You'll have to lookup the game itself to get things like DLC names.

// Get "groups" (game ("default") and DLCs ("001, 002, 003..."))
foreach ($client->trophies($trophyTitle->npCommunicationId(), $trophyTitle->serviceName())->trophyGroups() as $trophyGroup) {
    $groupId = $trophyGroup->id();
    $groupName = $trophyGroup->name();
    $groupDetail = $trophyGroup->detail();
}
yduke commented 1 month ago

Thank you! It works! This issue has troubled me for several days. You are absolutely right about it. Cheers!