Open Argosth opened 7 months ago
I don't think this tool has an iterator for exact match.
You could probably edit the current iterator, but you will loose the current behavior then.
I think changing the return to something like this should work for you:
return (strtolower($this->current()->name()) == strtolower($this->titleName));
Please note that this will only return exact matches now. So if a game have the name "Resident Evil™" so will you not find it by searching for "Resident Evil". It's also quite common for some games to have the name trophies in it, like "Resident Evil Trophies", which will also not be found if you search for "Resident Evil".
And as I said, this change will remove the current behavior. If you want both you have the create a new iterator and function, maybe "withExactName()" or something like that.
It might just be easier to change your own code to loop through the results for what you're looking for. It won't probably be that many games.
$user = $Client->users()->find('4352824381498132139');
$searchTerm = 'RESIDENT EVIL';
foreach ($user->trophyTitles()->withName($searchTerm) as $game) {
if (strtolower($game->name()) == strtolower($searchTerm)) {
// Do your thing
}
}
Again, you will still have to look out for ™ and Trophies and other strange things in names.
I don't think this tool has an iterator for exact match.
You could probably edit the current iterator, but you will loose the current behavior then.
I think changing the return to something like this should work for you:
return (strtolower($this->current()->name()) == strtolower($this->titleName));
Please note that this will only return exact matches now. So if a game have the name "Resident Evil™" so will you not find it by searching for "Resident Evil". It's also quite common for some games to have the name trophies in it, like "Resident Evil Trophies", which will also not be found if you search for "Resident Evil".
And as I said, this change will remove the current behavior. If you want both you have the create a new iterator and function, maybe "withExactName()" or something like that.
It might just be easier to change your own code to loop through the results for what you're looking for. It won't probably be that many games.
$user = $Client->users()->find('4352824381498132139'); $searchTerm = 'RESIDENT EVIL'; foreach ($user->trophyTitles()->withName($searchTerm) as $game) { if (strtolower($game->name()) == strtolower($searchTerm)) { // Do your thing } }
Again, you will still have to look out for ™ and Trophies and other strange things in names.
Thank you very much, I will look for other options too, ty mate :)
One more question @Ragowit, would you know how to determine the size or the games that a player has from $user->trophyTitles() without having to loop through the entire foreach? I need to know the number of games a player has, and the only way I have found is by iterating through the entire loop and adding it to a counter.
The API returns the total number of games. I'm uncertain if this number includes hidden games or not.
I'm also uncertain from the top of my head which function it was you should use, it's one of these two:
$user->trophyTitles()->count();
$user->trophyTitles()->getTotalResults();
The API returns the total number of games. I'm uncertain if this number includes hidden games or not.
I'm also uncertain from the top of my head which function it was you should use, it's one of these two:
$user->trophyTitles()->count();
$user->trophyTitles()->getTotalResults();
@Ragowit I tried the two options but nothing, and I'm looking into TrophyTitles Factory and there is no an option to determine the object size I think.
I was looking at https://github.com/Tustin/psn-php/blob/master/src/Iterator/TrophyTitlesIterator.php which inherits from https://github.com/Tustin/psn-php/blob/master/src/Iterator/AbstractApiIterator.php that has count() and getTotalResults(). Should be there if I understand the code right.
Hey @Ragowit do you know if there is a way to find titleId
from a given npCommunicationId
? I was able to do the opposite, but not this one...
For example: trophy/v1/users/${account_id}/trophyTitles
brings all games including PS3 games with npCommunicationId
, and no titleId
.
But to fetch game details (such as media) I need titleId
to use this endpoint: gamelist/v2/users/${account_id}/titles/${title_id}
No, I don't know of such a way.
Hello, I would like to know if the API has the possibility to search for a specific game of a user since the given method of the API by name is not exact when searching for a game and may return several:
I want it to return only the game Resident Evil, and not all that contain Resident Evil in their name, any ideas or solutions?
@Ragowit any idea about this?
Thank you very much.