The previous posts were about work with matches. Their data contains some values that refer to another instances. This are identifiers for league, players and teams. Now we’ll have a look at teams.
Fields radiant_team_id
and dire_team_id
in Dota2Api\Models\Match
instances are identifiers for teams in the match. They may be null
if players didn’t set teams. They might forget about it or they used to play for different teams. There are another two fields called radiant_name
and dire_name
that contain team names (may be null
as well). Looking at data organization, these two fields are redundant, because their value can be found with another API. However, it’s a good idea to give team names with match data to reduce API-requests.
Let’s see, where can we get teams data and how to save them to the local DB. There is a class Dota2Api\Mappers\TeamsMapperWeb
to load teams from the API:
$teamsMapperWeb = new Dota2Api\Mappers\TeamsMapperWeb(); $teamsMapperWeb->setTeamId(36); $teamsMapperWeb->setTeamsRequested(1); $teams = $teamsMapperWeb->load(); |
We set that we want to load one team with id 36 (Natus Vincere):
$navi = array_pop($teams); $navi->get('name'); // 'Natus Vincere' $navi->get('tag'); // 'Na`Vi' |
Now it is a problem with API. It doesn’t return field team_id
for teams. So, you should set it yourself:
$navi->set('team_id', 36); |
There is a lot of data about team in the API i.e. name, tag, creation time, country code, current roster, number of matches played with it, list of the tournaments where this team have played. dota2-api saves only name
and team_id
fields to the DB. Why this two only? Team’s name is more known rather than team’s tag. Creation time (basically, it’s time registered in the Dota2 client) is not very useful. Country code is not useful as well because players may be from around the world. Current roster may be found in the latest matches with team. Tournaments list for team can be received if you load all leagues matches.
There is a class Dota2Api\Mappers\TeamsMapperDb
for working with teams in the local DB:
$teamsMapperDb = new Dota2Api\Mappers\TeamsMapperDb(); if (!$navi->get('team_id')) { $navi->set('team_id', 36); } $teamsMapperDb->save($navi); |
Load team info from the DB:
$teams = $teamsMapperDb->load(); // all teams in the DB $teams = $teamsMapperDb->load(36); // one team $teams = $teamsMapperDb->load(array(36, 111474)); // two teams |
You can delete teams from the DB using delete
method:
$teamsMapperDb->delete(36); // delete one team $teamsMapperDb->delete(array(36, 111474)); // delete two teams |
That’s all about teams.
Add comment