├── .coveralls.yml
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── api-key.php
├── api-key.php.enc
├── composer.json
├── data
├── 686
│ └── abilities.json
├── abilities.json
├── heroes.json
├── items.json
├── lobbies.json
├── mods.json
└── regions.json
├── db_latest.sql
├── images
├── empty.png
├── map
│ ├── dota-map-6.82.jpg
│ ├── dota-map-6.86.jpg
│ ├── dota_map.jpg
│ ├── racks_dire.png
│ ├── racks_radiant.png
│ ├── tower.png
│ ├── tower_dire.png
│ └── tower_radiant.png
└── stats.png
├── includes
├── Api.php
├── Data
│ ├── Abilities.php
│ ├── Data.php
│ ├── Heroes.php
│ ├── HeroesData.php
│ ├── Items.php
│ ├── Lobbies.php
│ ├── Mods.php
│ └── Regions.php
├── Mappers
│ ├── HeroesMapper.php
│ ├── ItemsMapper.php
│ ├── ItemsMapperDb.php
│ ├── ItemsMapperWeb.php
│ ├── LeagueMapper.php
│ ├── LeaguePrizePoolMapper.php
│ ├── LeaguePrizePoolMapperDb.php
│ ├── LeaguePrizePoolMapperWeb.php
│ ├── LeaguesMapper.php
│ ├── LeaguesMapperDb.php
│ ├── LeaguesMapperWeb.php
│ ├── LiveMatchMapperDb.php
│ ├── MatchMapper.php
│ ├── MatchMapperDb.php
│ ├── MatchMapperWeb.php
│ ├── MatchesMapper.php
│ ├── MatchesMapperDb.php
│ ├── MatchesMapperWeb.php
│ ├── PlayerMapperDb.php
│ ├── PlayersMapperDb.php
│ ├── PlayersMapperWeb.php
│ ├── TeamsMapper.php
│ ├── TeamsMapperDb.php
│ ├── TeamsMapperWeb.php
│ └── UgcMapperWeb.php
├── Models
│ ├── Item.php
│ ├── League.php
│ ├── LiveMatch.php
│ ├── LiveSlot.php
│ ├── Match.php
│ ├── Player.php
│ ├── Slot.php
│ ├── StatObject.php
│ └── Team.php
└── Utils
│ ├── Db.php
│ ├── Map.php
│ └── Request.php
├── phpunit.xml.dist
├── tests
└── includes
│ ├── Data
│ ├── AbilitiesTest.php
│ └── ItemsTest.php
│ ├── Mappers
│ ├── HeroesMapperTest.php
│ ├── ItemsMapperDbTest.php
│ ├── ItemsMapperWebTest.php
│ ├── LeagueMapperTest.php
│ ├── LeaguePrizePoolMapperDbTest.php
│ ├── LeaguePrizePoolMapperWebTest.php
│ ├── LeaguesMapperDbTest.php
│ ├── LeaguesMapperWebTest.php
│ ├── MatchMapperDbTest.php
│ ├── MatchMapperWebTest.php
│ ├── MatchesMapperDbTest.php
│ ├── MatchesMapperWebTest.php
│ ├── PlayerMapperDbTest.php
│ ├── PlayersMapperDbTest.php
│ ├── PlayersMapperWebTest.php
│ ├── TeamsMapperDbTest.php
│ ├── TeamsMapperWebTest.php
│ └── UgcMapperWebTest.php
│ └── Models
│ └── MatchTest.php
└── tests_config.php
/.coveralls.yml:
--------------------------------------------------------------------------------
1 | # for php-coveralls
2 | src_dir: includes
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .idea/*
3 | /vendor
4 | composer.lock
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 | php:
3 | - 5.3
4 | - 5.4
5 | - 5.5
6 | - 5.6
7 | - 7.0
8 | - hhvm
9 | cache:
10 | directories:
11 | - vendor
12 | before_install:
13 | - openssl aes-256-cbc -K $encrypted_ec75b5db0746_key -iv $encrypted_ec75b5db0746_iv
14 | -in api-key.php.enc -out api-key.php -d
15 | before_script:
16 | - curl -s http://getcomposer.org/installer | php
17 | - php composer.phar self-update
18 | - php composer.phar install --dev --no-interaction --prefer-source
19 | script:
20 | - mkdir -p build/logs
21 | - mkdir -p build/cov
22 | - php vendor/bin/phpcs --config-set show_warnings 0
23 | - php vendor/bin/phpcs ./includes --standard=PSR1 --encoding=utf-8
24 | - php vendor/bin/phpcs ./includes --standard=PSR2 --encoding=utf-8
25 | - php vendor/bin/phpunit -c phpunit.xml.dist
26 | after_script:
27 | - php vendor/bin/coveralls
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 kronusme
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #DotA2-Api
2 |
3 | [](https://travis-ci.org/kronusme/dota2-api)
4 | [](https://coveralls.io/r/kronusme/dota2-api?branch=master)
5 | [](https://packagist.org/packages/kronusme/dota2-api)
6 | [](https://packagist.org/packages/kronusme/dota2-api)
7 | [](https://www.versioneye.com/user/projects/5469ed86a760ce7bc8000027)
8 | [](https://codeclimate.com/github/kronusme/dota2-api)
9 |
10 | ### About
11 |
12 | 1. **What is it?**
13 | This is PHP code for processing DotA 2 API-requests.
14 |
15 | 2. **What can it do?**
16 | It can get match-list for some criteria, get match-info for single match, get steam-profile info for users.
17 | AND save all this data in MySQL database. For more information see - "How to use it".
18 |
19 | 3. **What I need to work with it?**
20 | First of all you need web-server with **PHP 5.3+** ( **PDO** and **cURL** should be enabled) and **MySQL 5**. Then look at install section.
21 |
22 | ### Install
23 |
24 | 1. Install via [Composer](http://getcomposer.org/):
25 | ````json
26 | {
27 | "require": {
28 | "kronusme/dota2-api": "2.2.1"
29 | }
30 | }
31 | ````
32 |
33 | 2. Connect to your mysql-server with any tool (phpmyadmin, heidisql etc) and execute code from the file **db_latest.sql**.
34 |
35 | 3. Initialize Dota2-Api like this:
36 | ````php
37 | require_once 'vendor/autoload.php';
38 |
39 | use Dota2Api\Api;
40 |
41 | Api::init('YOUR_API_KEY', array('localhost', 'root', 'password', 'db_name', 'table_prefix_'));
42 | ````
43 |
44 | ### Requests
45 | | Type | URL |
46 | |------------------------------|----------------------------------------------------------------------------------|
47 | | **Supported** | |
48 | | GetMatchHistory | https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/v001/ |
49 | | GetMatchDetails | https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/v001/ |
50 | | GetPlayerSummaries | https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/ |
51 | | GetLeagueListing | https://api.steampowered.com/IDOTA2Match_570/GetLeagueListing/v0001/ |
52 | | GetLiveLeagueGames | https://api.steampowered.com/IDOTA2Match_570/GetLiveLeagueGames/v0001/ |
53 | | GetTeamInfoByTeamID | https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v001/ |
54 | | GetHeroes | https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/ |
55 | | GetTournamentPrizePool | https://api.steampowered.com/IEconDOTA2_570/GetTournamentPrizePool/v1/ |
56 | | GetGameItems | https://api.steampowered.com/IEconDOTA2_570/GetGameItems/v0001/ |
57 | | **Unsupported** | |
58 | | EconomySchema | https://api.steampowered.com/IEconItems_570/GetSchema/v0001/ |
59 | | GetMatchHistoryBySequenceNum | https://api.steampowered.com/IDOTA2Match_570/GetMatchHistoryBySequenceNum/v0001/ |
60 |
61 | ### How to use it
62 |
63 | #### IMPORTANT!
64 | Before parsing and saving leagues matches to your DB, make sure that you've saved leagues to the DB (using `leaguesMapperWeb`!
65 | If you try to save some "public" matches, you should REMOVE `foreign key` for field `leagueid` in the table `matches`!
66 |
67 | #### Load some match-info
68 | ```php
69 | load();
72 | ```
73 | $match - it's an object with all match data including slots info, ability-upgrades (if provided) and pick, bans (if cm-mode).
74 |
75 | #### Save match-info in the database
76 | ```php
77 | load();
80 | $saver = new Dota2Api\Mappers\MatchMapperDb();
81 | $saver->save($match);
82 | ```
83 | matchMapperDb will check if match with $match->get('match_id') exists in the db and select method for save (insert or update).
84 |
85 |
86 | #### Work with match-object
87 | ```php
88 | load();
91 | echo $match->get('match_id');
92 | echo $match->get('start_time');
93 | echo $match->get('game_mode');
94 | $slots = $match->getAllSlots();
95 | foreach($slots as $slot) {
96 | echo $slot->get('last_hits');
97 | }
98 | print_r($match->getDataArray());
99 | print_r($match->getSlot(0)->getDataArray());
100 | ```
101 |
102 | #### I want get last 25 matches with some player
103 | ````php
104 | setAccountId(93712171);
107 | $matchesShortInfo = $matchesMapperWeb->load();
108 | foreach ($matchesShortInfo as $key=>$matchShortInfo) {
109 | $matchMapper = new Dota2Api\Mappers\MatchMapperWeb($key);
110 | $match = $matchMapper->load();
111 | if ($match) {
112 | $mm = new Dota2Api\Mappers\MatchMapperDb();
113 | $mm->save($match);
114 | }
115 | }
116 | ````
117 |
118 | #### Get player info
119 | ````php
120 | addId('76561198067833250')->addId('76561198058587506')->load();
123 | foreach($playersInfo as $playerInfo) {
124 | echo $playerInfo->get('realname');
125 | echo '
';
126 | echo ''.$playerInfo->get('personaname').'\'s steam profile';
127 | }
128 | print_r($playersInfo);
129 | ````
130 | Player's id you can get via Player::convertId('xxxxx') method (xxxxx - its DotA ID).
131 |
132 | #### Get team info
133 | ````php
134 | setTeamId(2)->setTeamsRequested(2)->load();
137 | foreach($teams as $team) {
138 | echo $team->get('name');
139 | echo $team->get('rating');
140 | echo $team->get('country_code');
141 | print_r($team->getAllLeaguesIds());
142 | }
143 | ````
144 |
145 | #### Get current heroes list
146 | ````php
147 | load();
150 | print_r($heroes);
151 | ````
152 | $heroes - array with numeric indexes (heroes ids)
153 |
154 | #### Get current items list
155 | ````php
156 | load();
159 | print_r($itemsInfo);
160 | foreach($itemsInfo as $item) {
161 | echo $item->get('id');
162 | echo $item->get('name');
163 | echo $item->get('cost');
164 | echo $item->get('secret_shop');
165 | echo $item->get('side_shop');
166 | echo $item->get('recipe');
167 | echo $item->get('localized_name');
168 | }
169 | ````
170 |
171 | #### Save received from web items list to db
172 | ````php
173 | load();
176 | $itemsMapperDb = new itemsMapperDb();
177 | $itemsMapperDb->save($items);
178 | ````
179 |
180 | #### Get current items list from db
181 | ````php
182 | load();
185 | print_r($itemsInfo);
186 | foreach($itemsInfo as $item) {
187 | echo $item->get('id');
188 | echo $item->get('name');
189 | echo $item->get('cost');
190 | echo $item->get('secret_shop');
191 | echo $item->get('side_shop');
192 | echo $item->get('recipe');
193 | echo $item->get('localized_name');
194 | }
195 | ````
196 |
197 | #### Get leagues list
198 | ````php
199 | load();
202 | foreach($leagues as $league) {
203 | echo $league->get('description');
204 | if ($league->get('tournament_url')) {
205 | echo $league->get('tournament_url');
206 | }
207 | }
208 | ````
209 | $leagues - array with numeric indexes (leagues ids)
210 |
211 | #### Get leagues prize pool
212 | ````php
213 | $leaguePrizePoolMapperWeb = new Dota2Api\Mappers\LeaguePrizePoolMapperWeb();
214 | $leaguePrizePoolMapperWeb->setLeagueId(600);
215 | $prizePoolInfo = $leaguePrizePoolMapperWeb->load();
216 | print_r($prizePoolInfo);
217 | echo $prizePoolInfo['prize_pool'];
218 | echo $prizePoolInfo['league_id'];
219 | echo $prizePoolInfo['status']; // may be undefined
220 | ````
221 |
222 | ````php
223 | $prizePoolMapperDb = new Dota2Api\Mappers\LeaguePrizePoolMapperDb();
224 | $pp = $prizePoolMapperDb->setLeagueId(600)->load();
225 | foreach($pp as $date=>$prize_pool) {
226 | echo $date.' - $ '.number_format($prize_pool, 2);
227 | }
228 | ````
229 |
230 | #### Get live leagues matches
231 | ````php
232 | load();
235 | print_r($games);
236 | ````
237 | $games - array of live_match objects
238 |
239 | #### Get matches from local db
240 | ````php
241 | setLeagueId(29)->setMatchesRequested(1);
244 | $matchesInfo = $matchesMapperDb->load();
245 | print_r($matchesInfo);
246 | ````
247 |
248 | #### Delete match(es) from local db
249 | ````php
250 | delete(array(151341579, 151401247));
253 |
254 | $mm = new Dota2Api\Mappers\MatchMapperDb();
255 | $mm->delete(151341579);
256 | ````
257 |
258 | #### Get info about abilities, heroes, items, games mods, lobby types etc
259 | ````php
260 | parse();
263 | $abilities->getDataById(5172); // return array for ability with id 5172 (BeastMaster Inner Beast)
264 | // same, because there are no thumbs for abilities
265 | $abilities->getImgUrlById(5172, false);
266 | $abilities->getImgUrlById(5172);
267 |
268 | $heroes = new Dota2Api\Data\Heroes();
269 | $heroes->parse();
270 | $heroes->getDataById(97); // get info about Magnus
271 | $heroes->getImgUrlById(97, false); // large image
272 | $heroes->getImgUrlById(97); // thumb
273 |
274 | $items = new Dota2Api\Data\Items();
275 | $items->parse();
276 | $items->getDataById(149); // get info about Crystalis
277 | $items->getImgUrlById(149, false); // large image
278 | $items->getImgUrlById(149); // thumb
279 |
280 | $mods = new Dota2Api\Data\Mods();
281 | $mods->parse();
282 | $mods->getFieldById(1, 'name'); // returns 'All Pick'
283 |
284 | $lobbies = new Dota2Api\Data\Lobbies();
285 | $lobbies->parse();
286 | $lobbies->getFieldById(2, 'name'); // returns 'Tournament'
287 |
288 | $regions = new Dota2Api\Data\Regions();
289 | $regions->parse();
290 | $regions->getFieldById(132, 'name'); // returns 'Europe West'
291 | ````
292 |
293 | #### Get map with barracks and towers
294 | ````php
295 | load();
298 | $map = new Dota2Api\Utils\Map($match->get('tower_status_radiant'), $match->get('tower_status_dire'), $match->get('barracks_status_radiant'), $match->get('barracks_status_dire'));
299 | $canvas = $map->getImage();
300 | header('Content-Type: image/jpg');
301 | imagejpeg($canvas);
302 | imagedestroy($canvas);
303 | ````
304 |
305 | #### Get info about players from db
306 | ````php
307 | addId('76561198020176880')->addId('76561197998200662')->load();
310 | print_r($players_info);
311 | ````
312 | or for just getting one player, you can also use
313 | ````php
314 | setSteamid('76561198020176880');
317 | print_r($playerMapperDb->load());
318 | ````
319 |
320 | #### Save info about players into db
321 | ````php
322 | addId('76561198020176880')->addId('76561197998200662')->load();
326 |
327 | //save players into db
328 | $playerMapperDb = new Dota2Api\Mappers\PlayerMapperDb();
329 | foreach($players as $p) {
330 | $playerMapperDb->save($p);
331 | }
332 | ````
333 |
334 | #### Work with UGC Objects
335 | ````php
336 | load();
339 | $ugcMapperWeb = new Dota2Api\Mappers\UgcMapperWeb($game->get('radiant_logo'));
340 | $logoData = $ugcMapperWeb->load();
341 | var_dump($logoData);
342 | echo $logoData->url;
343 | ````
344 |
345 | ### Thanks
346 |
347 | 1. Valve for DotA 2 and Web API.
348 |
349 | 2. [MuppetMaster42](http://dev.dota2.com/member.php?u=5137), for http://dev.dota2.com/showthread.php?t=58317.
350 |
351 | 3. Players, who don't hide their own statistic.
352 |
353 | 4. dev.dota2 community.
354 |
--------------------------------------------------------------------------------
/api-key.php:
--------------------------------------------------------------------------------
1 | 5.2"
49 | },
50 | "require-dev": {
51 | "phpunit/phpunit": "4.4.*",
52 | "phpunit/dbunit": ">=1.2",
53 | "satooshi/php-coveralls": "~1.0",
54 | "squizlabs/php_codesniffer": "2.*",
55 | "sebastianbergmann/phpcov": "1.1.0"
56 | }
57 | }
--------------------------------------------------------------------------------
/data/686/abilities.json:
--------------------------------------------------------------------------------
1 | {
2 | "abilities": [
3 | {
4 | "name": "death_prophet_spirit_siphon",
5 | "id": "5685"
6 | },
7 | {
8 | "name": "doom_bringer_infernal_blade",
9 | "id": "5341"
10 | },
11 | {
12 | "name": "faceless_void_time_dilation",
13 | "id": "5691"
14 | },
15 | {
16 | "name": "lone_druid_savage_roar",
17 | "id": "5414"
18 | },
19 | {
20 | "name": "silencer_arcane_curse",
21 | "id": "5377"
22 | },
23 | {
24 | "name": "riki_cloak_and_dagger",
25 | "id": "5144"
26 | },
27 | {
28 | "name": "riki_tricks_of_the_trade",
29 | "id": "5145"
30 | },
31 | {
32 | "name": "arc_warden_flux",
33 | "id": "5677"
34 | },
35 | {
36 | "name": "arc_warden_magnetic_field",
37 | "id": "5678"
38 | },
39 | {
40 | "name": "arc_warden_spark_wraith",
41 | "id": "5679"
42 | },
43 | {
44 | "name": "arc_warden_tempest_double",
45 | "id": "5683"
46 | }
47 | ]
48 | }
--------------------------------------------------------------------------------
/data/heroes.json:
--------------------------------------------------------------------------------
1 | {
2 | "heroes": [
3 | {
4 | "name": "antimage",
5 | "id": 1,
6 | "localized_name": "Anti-Mage"
7 | },
8 | {
9 | "name": "axe",
10 | "id": 2,
11 | "localized_name": "Axe"
12 | },
13 | {
14 | "name": "bane",
15 | "id": 3,
16 | "localized_name": "Bane"
17 | },
18 | {
19 | "name": "bloodseeker",
20 | "id": 4,
21 | "localized_name": "Bloodseeker"
22 | },
23 | {
24 | "name": "crystal_maiden",
25 | "id": 5,
26 | "localized_name": "Crystal Maiden"
27 | },
28 | {
29 | "name": "drow_ranger",
30 | "id": 6,
31 | "localized_name": "Drow Ranger"
32 | },
33 | {
34 | "name": "earthshaker",
35 | "id": 7,
36 | "localized_name": "Earthshaker"
37 | },
38 | {
39 | "name": "juggernaut",
40 | "id": 8,
41 | "localized_name": "Juggernaut"
42 | },
43 | {
44 | "name": "mirana",
45 | "id": 9,
46 | "localized_name": "Mirana"
47 | },
48 | {
49 | "name": "nevermore",
50 | "id": 11,
51 | "localized_name": "Shadow Fiend"
52 | },
53 | {
54 | "name": "morphling",
55 | "id": 10,
56 | "localized_name": "Morphling"
57 | },
58 | {
59 | "name": "phantom_lancer",
60 | "id": 12,
61 | "localized_name": "Phantom Lancer"
62 | },
63 | {
64 | "name": "puck",
65 | "id": 13,
66 | "localized_name": "Puck"
67 | },
68 | {
69 | "name": "pudge",
70 | "id": 14,
71 | "localized_name": "Pudge"
72 | },
73 | {
74 | "name": "razor",
75 | "id": 15,
76 | "localized_name": "Razor"
77 | },
78 | {
79 | "name": "sand_king",
80 | "id": 16,
81 | "localized_name": "Sand King"
82 | },
83 | {
84 | "name": "storm_spirit",
85 | "id": 17,
86 | "localized_name": "Storm Spirit"
87 | },
88 | {
89 | "name": "sven",
90 | "id": 18,
91 | "localized_name": "Sven"
92 | },
93 | {
94 | "name": "tiny",
95 | "id": 19,
96 | "localized_name": "Tiny"
97 | },
98 | {
99 | "name": "vengefulspirit",
100 | "id": 20,
101 | "localized_name": "Vengeful Spirit"
102 | },
103 | {
104 | "name": "windrunner",
105 | "id": 21,
106 | "localized_name": "Windranger"
107 | },
108 | {
109 | "name": "zuus",
110 | "id": 22,
111 | "localized_name": "Zeus"
112 | },
113 | {
114 | "name": "kunkka",
115 | "id": 23,
116 | "localized_name": "Kunkka"
117 | },
118 | {
119 | "name": "lina",
120 | "id": 25,
121 | "localized_name": "Lina"
122 | },
123 | {
124 | "name": "lich",
125 | "id": 31,
126 | "localized_name": "Lich"
127 | },
128 | {
129 | "name": "lion",
130 | "id": 26,
131 | "localized_name": "Lion"
132 | },
133 | {
134 | "name": "shadow_shaman",
135 | "id": 27,
136 | "localized_name": "Shadow Shaman"
137 | },
138 | {
139 | "name": "slardar",
140 | "id": 28,
141 | "localized_name": "Slardar"
142 | },
143 | {
144 | "name": "tidehunter",
145 | "id": 29,
146 | "localized_name": "Tidehunter"
147 | },
148 | {
149 | "name": "witch_doctor",
150 | "id": 30,
151 | "localized_name": "Witch Doctor"
152 | },
153 | {
154 | "name": "riki",
155 | "id": 32,
156 | "localized_name": "Riki"
157 | },
158 | {
159 | "name": "enigma",
160 | "id": 33,
161 | "localized_name": "Enigma"
162 | },
163 | {
164 | "name": "tinker",
165 | "id": 34,
166 | "localized_name": "Tinker"
167 | },
168 | {
169 | "name": "sniper",
170 | "id": 35,
171 | "localized_name": "Sniper"
172 | },
173 | {
174 | "name": "necrolyte",
175 | "id": 36,
176 | "localized_name": "Necrophos"
177 | },
178 | {
179 | "name": "warlock",
180 | "id": 37,
181 | "localized_name": "Warlock"
182 | },
183 | {
184 | "name": "beastmaster",
185 | "id": 38,
186 | "localized_name": "Beastmaster"
187 | },
188 | {
189 | "name": "queenofpain",
190 | "id": 39,
191 | "localized_name": "Queen of Pain"
192 | },
193 | {
194 | "name": "venomancer",
195 | "id": 40,
196 | "localized_name": "Venomancer"
197 | },
198 | {
199 | "name": "faceless_void",
200 | "id": 41,
201 | "localized_name": "Faceless Void"
202 | },
203 | {
204 | "name": "skeleton_king",
205 | "id": 42,
206 | "localized_name": "Skeleton King"
207 | },
208 | {
209 | "name": "death_prophet",
210 | "id": 43,
211 | "localized_name": "Death Prophet"
212 | },
213 | {
214 | "name": "phantom_assassin",
215 | "id": 44,
216 | "localized_name": "Phantom Assassin"
217 | },
218 | {
219 | "name": "pugna",
220 | "id": 45,
221 | "localized_name": "Pugna"
222 | },
223 | {
224 | "name": "templar_assassin",
225 | "id": 46,
226 | "localized_name": "Templar Assassin"
227 | },
228 | {
229 | "name": "viper",
230 | "id": 47,
231 | "localized_name": "Viper"
232 | },
233 | {
234 | "name": "luna",
235 | "id": 48,
236 | "localized_name": "Luna"
237 | },
238 | {
239 | "name": "dragon_knight",
240 | "id": 49,
241 | "localized_name": "Dragon Knight"
242 | },
243 | {
244 | "name": "dazzle",
245 | "id": 50,
246 | "localized_name": "Dazzle"
247 | },
248 | {
249 | "name": "rattletrap",
250 | "id": 51,
251 | "localized_name": "Clockwerk"
252 | },
253 | {
254 | "name": "leshrac",
255 | "id": 52,
256 | "localized_name": "Leshrac"
257 | },
258 | {
259 | "name": "furion",
260 | "id": 53,
261 | "localized_name": "Nature's Prophet"
262 | },
263 | {
264 | "name": "life_stealer",
265 | "id": 54,
266 | "localized_name": "Lifestealer"
267 | },
268 | {
269 | "name": "dark_seer",
270 | "id": 55,
271 | "localized_name": "Dark Seer"
272 | },
273 | {
274 | "name": "clinkz",
275 | "id": 56,
276 | "localized_name": "Clinkz"
277 | },
278 | {
279 | "name": "omniknight",
280 | "id": 57,
281 | "localized_name": "Omniknight"
282 | },
283 | {
284 | "name": "enchantress",
285 | "id": 58,
286 | "localized_name": "Enchantress"
287 | },
288 | {
289 | "name": "huskar",
290 | "id": 59,
291 | "localized_name": "Huskar"
292 | },
293 | {
294 | "name": "night_stalker",
295 | "id": 60,
296 | "localized_name": "Night Stalker"
297 | },
298 | {
299 | "name": "broodmother",
300 | "id": 61,
301 | "localized_name": "Broodmother"
302 | },
303 | {
304 | "name": "bounty_hunter",
305 | "id": 62,
306 | "localized_name": "Bounty Hunter"
307 | },
308 | {
309 | "name": "weaver",
310 | "id": 63,
311 | "localized_name": "Weaver"
312 | },
313 | {
314 | "name": "jakiro",
315 | "id": 64,
316 | "localized_name": "Jakiro"
317 | },
318 | {
319 | "name": "batrider",
320 | "id": 65,
321 | "localized_name": "Batrider"
322 | },
323 | {
324 | "name": "chen",
325 | "id": 66,
326 | "localized_name": "Chen"
327 | },
328 | {
329 | "name": "spectre",
330 | "id": 67,
331 | "localized_name": "Spectre"
332 | },
333 | {
334 | "name": "doom_bringer",
335 | "id": 69,
336 | "localized_name": "Doom"
337 | },
338 | {
339 | "name": "ancient_apparition",
340 | "id": 68,
341 | "localized_name": "Ancient Apparition"
342 | },
343 | {
344 | "name": "ursa",
345 | "id": 70,
346 | "localized_name": "Ursa"
347 | },
348 | {
349 | "name": "spirit_breaker",
350 | "id": 71,
351 | "localized_name": "Spirit Breaker"
352 | },
353 | {
354 | "name": "gyrocopter",
355 | "id": 72,
356 | "localized_name": "Gyrocopter"
357 | },
358 | {
359 | "name": "alchemist",
360 | "id": 73,
361 | "localized_name": "Alchemist"
362 | },
363 | {
364 | "name": "invoker",
365 | "id": 74,
366 | "localized_name": "Invoker"
367 | },
368 | {
369 | "name": "silencer",
370 | "id": 75,
371 | "localized_name": "Silencer"
372 | },
373 | {
374 | "name": "obsidian_destroyer",
375 | "id": 76,
376 | "localized_name": "Outworld Devourer"
377 | },
378 | {
379 | "name": "lycan",
380 | "id": 77,
381 | "localized_name": "Lycanthrope"
382 | },
383 | {
384 | "name": "brewmaster",
385 | "id": 78,
386 | "localized_name": "Brewmaster"
387 | },
388 | {
389 | "name": "shadow_demon",
390 | "id": 79,
391 | "localized_name": "Shadow Demon"
392 | },
393 | {
394 | "name": "lone_druid",
395 | "id": 80,
396 | "localized_name": "Lone Druid"
397 | },
398 | {
399 | "name": "chaos_knight",
400 | "id": 81,
401 | "localized_name": "Chaos Knight"
402 | },
403 | {
404 | "name": "meepo",
405 | "id": 82,
406 | "localized_name": "Meepo"
407 | },
408 | {
409 | "name": "treant",
410 | "id": 83,
411 | "localized_name": "Treant Protector"
412 | },
413 | {
414 | "name": "ogre_magi",
415 | "id": 84,
416 | "localized_name": "Ogre Magi"
417 | },
418 | {
419 | "name": "undying",
420 | "id": 85,
421 | "localized_name": "Undying"
422 | },
423 | {
424 | "name": "rubick",
425 | "id": 86,
426 | "localized_name": "Rubick"
427 | },
428 | {
429 | "name": "disruptor",
430 | "id": 87,
431 | "localized_name": "Disruptor"
432 | },
433 | {
434 | "name": "nyx_assassin",
435 | "id": 88,
436 | "localized_name": "Nyx Assassin"
437 | },
438 | {
439 | "name": "naga_siren",
440 | "id": 89,
441 | "localized_name": "Naga Siren"
442 | },
443 | {
444 | "name": "keeper_of_the_light",
445 | "id": 90,
446 | "localized_name": "Keeper of the Light"
447 | },
448 | {
449 | "name": "wisp",
450 | "id": 91,
451 | "localized_name": "Wisp"
452 | },
453 | {
454 | "name": "visage",
455 | "id": 92,
456 | "localized_name": "Visage"
457 | },
458 | {
459 | "name": "slark",
460 | "id": 93,
461 | "localized_name": "Slark"
462 | },
463 | {
464 | "name": "medusa",
465 | "id": 94,
466 | "localized_name": "Medusa"
467 | },
468 | {
469 | "name": "troll_warlord",
470 | "id": 95,
471 | "localized_name": "Troll Warlord"
472 | },
473 | {
474 | "name": "centaur",
475 | "id": 96,
476 | "localized_name": "Centaur Warrunner"
477 | },
478 | {
479 | "name": "magnataur",
480 | "id": 97,
481 | "localized_name": "Magnus"
482 | },
483 | {
484 | "name": "shredder",
485 | "id": 98,
486 | "localized_name": "Timbersaw"
487 | },
488 | {
489 | "name": "bristleback",
490 | "id": 99,
491 | "localized_name": "Bristleback"
492 | },
493 | {
494 | "name": "tusk",
495 | "id": 100,
496 | "localized_name": "Tusk"
497 | },
498 | {
499 | "name": "skywrath_mage",
500 | "id": 101,
501 | "localized_name": "Skywrath Mage"
502 | },
503 | {
504 | "name": "abaddon",
505 | "id": 102,
506 | "localized_name": "Abaddon"
507 | },
508 | {
509 | "name": "elder_titan",
510 | "id": 103,
511 | "localized_name": "Elder Titan"
512 | },
513 | {
514 | "name": "legion_commander",
515 | "id": 104,
516 | "localized_name": "Legion Commander"
517 | },
518 | {
519 | "name": "ember_spirit",
520 | "id": 106,
521 | "localized_name": "Ember Spirit"
522 | },
523 | {
524 | "name": "earth_spirit",
525 | "id": 107,
526 | "localized_name": "Earth Spirit"
527 | },
528 | {
529 | "name": "abyssal_underlord",
530 | "id": 108,
531 | "localized_name": "Abyssal Underlord"
532 | },
533 | {
534 | "name": "terrorblade",
535 | "id": 109,
536 | "localized_name": "Terrorblade"
537 | },
538 | {
539 | "name": "phoenix",
540 | "id": 110,
541 | "localized_name": "Phoenix"
542 | },
543 | {
544 | "name": "techies",
545 | "id": 105,
546 | "localized_name": "Techies"
547 | },
548 | {
549 | "name": "oracle",
550 | "id": 111,
551 | "localized_name": "Oracle"
552 | },
553 | {
554 | "name": "winter_wyvern",
555 | "id": 112,
556 | "localized_name": "Winter Wyvern"
557 | },
558 | {
559 | "name": "arc_warden",
560 | "id": 113,
561 | "localized_name": "Arc Warden"
562 | }
563 | ]
564 | }
565 |
--------------------------------------------------------------------------------
/data/lobbies.json:
--------------------------------------------------------------------------------
1 | {
2 | "lobbies" : [
3 | {
4 | "id" : -1,
5 | "name" : "Invalid"
6 | },
7 | {
8 | "id" : 0,
9 | "name" : "Public matchmaking"
10 | },
11 | {
12 | "id" : 1,
13 | "name" : "Practice"
14 | },
15 | {
16 | "id" : 2,
17 | "name" : "Tournament"
18 | },
19 | {
20 | "id" : 3,
21 | "name" : "Tutorial"
22 | },
23 | {
24 | "id" : 4,
25 | "name" : "Co-op with bots"
26 | },
27 | {
28 | "id" : 5,
29 | "name" : "Team match"
30 | },
31 | {
32 | "id" : 6,
33 | "name" : "Solo Queue"
34 | },
35 | {
36 | "id" : 7,
37 | "name" : "Ranked"
38 | },
39 | {
40 | "id" : 8,
41 | "name" : "Solo Mid 1vs1"
42 | }
43 | ]
44 | }
45 |
--------------------------------------------------------------------------------
/data/mods.json:
--------------------------------------------------------------------------------
1 | {
2 | "mods": [
3 | {
4 | "id" : 0,
5 | "name" : "Unknown"
6 | },
7 | {
8 | "id" : 1,
9 | "name" : "All Pick"
10 | },
11 | {
12 | "id" : 2,
13 | "name" : "Captains Mode"
14 | },
15 | {
16 | "id" : 3,
17 | "name" : "Random Draft"
18 | },
19 | {
20 | "id" : 4,
21 | "name" : "Single Draft"
22 | },
23 | {
24 | "id" : 5,
25 | "name" : "All Random"
26 | },
27 | {
28 | "id" : 6,
29 | "name" : "?? INTRO/DEATH ??"
30 | },
31 | {
32 | "id" : 7,
33 | "name" : "The Diretide"
34 | },
35 | {
36 | "id" : 8,
37 | "name" : "Reverse Captains Mode"
38 | },
39 | {
40 | "id" : 9,
41 | "name" : "Greeviling"
42 | },
43 | {
44 | "id" : 10,
45 | "name": "Tutorial"
46 | },
47 | {
48 | "id" : 11,
49 | "name" : "Mid Only"
50 | },
51 | {
52 | "id" : 12,
53 | "name" : "Least Played"
54 | },
55 | {
56 | "id" : 13,
57 | "name" : "New Player Pool"
58 | },
59 | {
60 | "id" : 14,
61 | "name" : "Compendium Matchmaking"
62 | },
63 | {
64 | "id": 15,
65 | "name": "Custom"
66 | },
67 | {
68 | "id": 16,
69 | "name": "Captains Draft"
70 | },
71 | {
72 | "id": 17,
73 | "name": "Balanced Draft"
74 | },
75 | {
76 | "id": 18,
77 | "name": "Ability Draft"
78 | },
79 | {
80 | "id": 19,
81 | "name": "?? Event ??"
82 | },
83 | {
84 | "id": 20,
85 | "name": "All Random Death Match"
86 | },
87 | {
88 | "id": 21,
89 | "name": "1vs1 Solo Mid"
90 | },
91 | {
92 | "id": 22,
93 | "name": "Ranked All Pick"
94 | }
95 | ]
96 | }
97 |
--------------------------------------------------------------------------------
/data/regions.json:
--------------------------------------------------------------------------------
1 | {
2 | "regions": [
3 | {
4 | "id" : 111,
5 | "name" : "US West"
6 | },
7 | {
8 | "id" : 112,
9 | "name" : "US West"
10 | },
11 | {
12 | "id" : 113,
13 | "name" : "US West"
14 | },
15 | {
16 | "id" : 114,
17 | "name" : "US West"
18 | },
19 | {
20 | "id" : 121,
21 | "name" : "US East"
22 | },
23 | {
24 | "id" : 122,
25 | "name" : "US East"
26 | },
27 | {
28 | "id" : 123,
29 | "name" : "US East"
30 | },
31 | {
32 | "id" : 124,
33 | "name" : "US East"
34 | },
35 | {
36 | "id" : 131,
37 | "name" : "Europe West"
38 | },
39 | {
40 | "id" : 132,
41 | "name" : "Europe West"
42 | },
43 | {
44 | "id" : 133,
45 | "name" : "Europe West"
46 | },
47 | {
48 | "id" : 134,
49 | "name" : "Europe West"
50 | },
51 | {
52 | "id" : 135,
53 | "name" : "Europe West"
54 | },
55 | {
56 | "id" : 136,
57 | "name" : "Europe West"
58 | },
59 | {
60 | "id" : 137,
61 | "name" : "Europe West"
62 | },
63 | {
64 | "id" : 138,
65 | "name" : "Europe West"
66 | },
67 | {
68 | "id" : 142 ,
69 | "name" : "South Korea"
70 | },
71 | {
72 | "id" : 143,
73 | "name" : "South Korea"
74 | },
75 | {
76 | "id" : 144,
77 | "name" : "South Korea"
78 | },
79 | {
80 | "id" : 145,
81 | "name" : "South Korea"
82 | },
83 | {
84 | "id" : 151 ,
85 | "name" : "Southeast Asia"
86 | },
87 | {
88 | "id" : 152,
89 | "name" : "Southeast Asia"
90 | },
91 | {
92 | "id" : 153,
93 | "name" : "Southeast Asia"
94 | },
95 | {
96 | "id" : 154,
97 | "name" : "Southeast Asia"
98 | },
99 | {
100 | "id" : 155,
101 | "name" : "Southeast Asia"
102 | },
103 | {
104 | "id" : 156,
105 | "name" : "Southeast Asia"
106 | },
107 | {
108 | "id" : 161,
109 | "name" : "China"
110 | },
111 | {
112 | "id" : 163,
113 | "name" : "China"
114 | },
115 | {
116 | "id" : 171,
117 | "name": "Australia"
118 | },
119 | {
120 | "id" : 181,
121 | "name" : "Russia"
122 | },
123 | {
124 | "id" : 182,
125 | "name" : "Russia"
126 | },
127 | {
128 | "id" : 183,
129 | "name" : "Russia"
130 | },
131 | {
132 | "id" : 184,
133 | "name" : "Russia"
134 | },
135 | {
136 | "id" : 185,
137 | "name" : "Russia"
138 | },
139 | {
140 | "id" : 186,
141 | "name" : "Russia"
142 | },
143 | {
144 | "id" : 187,
145 | "name" : "Russia"
146 | },
147 | {
148 | "id" : 188,
149 | "name" : "Russia"
150 | },
151 | {
152 | "id" : 191,
153 | "name" : "Europe East"
154 | },
155 | {
156 | "id" : 192,
157 | "name" : "Europe East"
158 | },
159 | {
160 | "id" : 200,
161 | "name" : "South America"
162 | },
163 | {
164 | "id" : 202,
165 | "name" : "South America"
166 | },
167 | {
168 | "id" : 203,
169 | "name" : "South America"
170 | },
171 | {
172 | "id" : 204,
173 | "name" : "South America"
174 | },
175 | {
176 | "id" : 211,
177 | "name" : "South Africa"
178 | },
179 | {
180 | "id" : 212,
181 | "name" : "South Africa"
182 | },
183 | {
184 | "id" : 213,
185 | "name" : "South Africa"
186 | },
187 | {
188 | "id" : 221,
189 | "name" : "China"
190 | },
191 | {
192 | "id" : 222,
193 | "name" : "China"
194 | },
195 | {
196 | "id" : 223,
197 | "name" : "China"
198 | },
199 | {
200 | "id" : 224,
201 | "name" : "China"
202 | },
203 | {
204 | "id" : 225,
205 | "name" : "China"
206 | },
207 | {
208 | "id" : 227,
209 | "name" : "China"
210 | },
211 | {
212 | "id" : 231,
213 | "name" : "China"
214 | },
215 | {
216 | "id" : 241,
217 | "name" : "Chile"
218 | },
219 | {
220 | "id" : 242,
221 | "name" : "Chile"
222 | },
223 | {
224 | "id" : 251,
225 | "name" : "Peru"
226 | },
227 | {
228 | "id" : 261,
229 | "name" : "India"
230 | }
231 | ]
232 | }
233 |
--------------------------------------------------------------------------------
/images/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/empty.png
--------------------------------------------------------------------------------
/images/map/dota-map-6.82.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/dota-map-6.82.jpg
--------------------------------------------------------------------------------
/images/map/dota-map-6.86.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/dota-map-6.86.jpg
--------------------------------------------------------------------------------
/images/map/dota_map.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/dota_map.jpg
--------------------------------------------------------------------------------
/images/map/racks_dire.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/racks_dire.png
--------------------------------------------------------------------------------
/images/map/racks_radiant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/racks_radiant.png
--------------------------------------------------------------------------------
/images/map/tower.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/tower.png
--------------------------------------------------------------------------------
/images/map/tower_dire.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/tower_dire.png
--------------------------------------------------------------------------------
/images/map/tower_radiant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/map/tower_radiant.png
--------------------------------------------------------------------------------
/images/stats.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kronusme/dota2-api/bbc512369ccb1490804d0e4ed13f5b58f20ca004/images/stats.png
--------------------------------------------------------------------------------
/includes/Api.php:
--------------------------------------------------------------------------------
1 | connectPDO($autoselect_db);
14 | Request::$apiKey = (string)$api_key;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/includes/Data/Abilities.php:
--------------------------------------------------------------------------------
1 |
11 | * $abilities = new Dota2Api\Data\Abilities();
12 | * $abilities->parse();
13 | * $abilities->getDataById(5172); // return array for ability with id 5172 (BeastMaster Inner Beast)
14 | * // same, because there are no thumbs for abilities
15 | * $abilities->getImgUrlById(5172, false);
16 | * $abilities->getImgUrlById(5172);
17 | *
18 | */
19 | class Abilities extends HeroesData
20 | {
21 | /**
22 | * Stats ability identifier
23 | */
24 | const STATS_ABILITY_ID = 5002;
25 |
26 | public function __construct()
27 | {
28 | $this->setFilename('abilities.json');
29 | $this->setField('abilities');
30 | // no small images for abilities :(
31 | $this->_suffixes['thumb'] = 'lg';
32 | }
33 |
34 | public function getImgUrlById($id, $thumb = true)
35 | {
36 | return ($id !== self::STATS_ABILITY_ID) ? parent::getImgUrlById($id, $thumb) : 'images/stats.png';
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/includes/Data/Data.php:
--------------------------------------------------------------------------------
1 | array, id=>array, ...)
25 | * @var array
26 | */
27 | protected $_data = array();
28 |
29 | /**
30 | * Field name in the JSON file
31 | * @var string
32 | */
33 | protected $_field;
34 |
35 | /**
36 | * Suffixes for images names
37 | * @var array
38 | */
39 | protected $_suffixes = array('thumb' => 'eg', 'large' => 'lg');
40 |
41 | /**
42 | * @param string $field
43 | * @return data
44 | */
45 | public function setField($field)
46 | {
47 | $this->_field = (string)$field;
48 | return $this;
49 | }
50 |
51 | /**
52 | * @return string
53 | */
54 | public function getField()
55 | {
56 | return $this->_field;
57 | }
58 |
59 | /**
60 | * @param array $data
61 | * @return data
62 | */
63 | public function setData(array $data)
64 | {
65 | $this->_data = $data;
66 | return $this;
67 | }
68 |
69 | /**
70 | * @return array
71 | */
72 | public function getData()
73 | {
74 | return $this->_data;
75 | }
76 |
77 | /**
78 | * @param string $filename
79 | * @return data
80 | */
81 | public function setFilename($filename)
82 | {
83 | $this->_filename = (string)$filename;
84 | return $this;
85 | }
86 |
87 | /**
88 | * @return string
89 | */
90 | public function getFilename()
91 | {
92 | return $this->_filename;
93 | }
94 |
95 | /**
96 | * Parse JSON file
97 | * @param string $parseTo
98 | */
99 | public function parse($parseTo = '')
100 | {
101 | $parseTo = str_replace('.', '', $parseTo); // allow to use '6.86' and '686'
102 | $p = __DIR__ . '/../../' . self::PATH . '/';
103 | $fullpath = $p . $this->_filename;
104 | $initData = $this->_parseJsonFile($fullpath);
105 | if ($parseTo) {
106 | $subdirs = scandir($p);
107 | sort($subdirs);
108 | foreach ($subdirs as $sdir) {
109 | $subdir = $p . $sdir;
110 | if (!is_dir($subdir) || $sdir === '.' || $sdir === '..') {
111 | continue;
112 | }
113 | if ($sdir > $parseTo) {
114 | break;
115 | }
116 | $path = $subdir . '/' . $this->_filename;
117 | if (file_exists($path)) {
118 | $patchData = $this->_parseJsonFile($path);
119 | $initData = $this->_mergeById($initData, $patchData);
120 | }
121 | }
122 | }
123 | $this->_data = $initData;
124 | }
125 |
126 | protected function _mergeById($arr1, $arr2)
127 | {
128 | foreach ($arr2 as $k => $row) {
129 | $arr1[$k] = $row;
130 | }
131 | return $arr1;
132 | }
133 |
134 | protected function _parseJsonFile($fullpath)
135 | {
136 | $return = array();
137 | if (file_exists($fullpath)) {
138 | $content = file_get_contents($fullpath);
139 | $data = json_decode($content);
140 | $field = $this->getField();
141 | if ($field && $data->$field) {
142 | foreach ($data->$field as $obj) {
143 | $obj_array = (array)$obj;
144 | $return[$obj_array['id']] = $obj_array;
145 | }
146 | }
147 | }
148 | return $return;
149 | }
150 |
151 | /**
152 | * Get array of data by its id (data should be parsed before)
153 | *
154 | * @param int $id
155 | * @return array|null
156 | */
157 | public function getDataById($id)
158 | {
159 | $id = (int)$id;
160 | return array_key_exists($id, $this->_data) ? $this->_data[$id] : null;
161 | }
162 |
163 | /**
164 | * Get some field ($field_name) value in the data with id = $id
165 | * @param int $id
166 | * @param string $field_name
167 | * @return mixed|null
168 | */
169 | public function getFieldById($id, $field_name)
170 | {
171 | $data = $this->getDataById($id);
172 | if (null !== $data) {
173 | $field_name = (string)$field_name;
174 | if (array_key_exists($field_name, $data)) {
175 | return $data[$field_name];
176 | }
177 | }
178 | return null;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/includes/Data/Heroes.php:
--------------------------------------------------------------------------------
1 |
11 | * $heroes = new Dota2Api\Data\Heroes();
12 | * $heroes->parse();
13 | * $heroes-getDataById(97); // get info about Magnus
14 | * $heroes->getImgUrlById(97, false); // large image
15 | * $heroes->getImgUrlById(97); // thumb
16 | *
17 | */
18 | class Heroes extends HeroesData
19 | {
20 | public function __construct()
21 | {
22 | $this->setFilename('heroes.json');
23 | $this->setField('heroes');
24 | //$this->_suffixes['thumb'] = 'sb';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/includes/Data/HeroesData.php:
--------------------------------------------------------------------------------
1 | getDataById($id);
18 | if (null === $data) {
19 | return '';
20 | } else {
21 | $suffix = $thumb ? $this->_suffixes['thumb'] : $this->_suffixes['large'];
22 | return 'http://media.steampowered.com/apps/dota2/images/' . $this->_field . '/' . $data['name'] . '_' . $suffix . '.png';
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/includes/Data/Items.php:
--------------------------------------------------------------------------------
1 |
11 | * $items = new Dota2Api\Data\Items();
12 | * $items->parse();
13 | * $items-getDataById(149); // get info about Crystalis
14 | * $items->getImgUrlById(149, false); // large image
15 | * $items->getImgUrlById(149); // thumb
16 | *
17 | */
18 | class Items extends HeroesData
19 | {
20 | /**
21 | * Empty slot has id = 0
22 | */
23 | const EMPTY_ID = 0;
24 |
25 | /**
26 | * Some items where replaced in 6.84-patch
27 | * Example:
28 | * before 6.84 - mystery_hook was 217
29 | * 6.84+ - mystery_hook is 1001
30 | * @var array (old item id => new item id)
31 | */
32 | protected $_conflictsMap = array(
33 | 217 => 1001,
34 | 218 => 1002,
35 | 219 => 1003,
36 | 220 => 1004,
37 | 221 => 1005,
38 | 226 => 1006,
39 | 228 => 1007,
40 | 235 => 1008,
41 | 227 => 1009,
42 | 229 => 1010,
43 | 230 => 1011,
44 | 231 => 1012,
45 | 232 => 1013,
46 | 233 => 1014,
47 | 234 => 1015,
48 | 236 => 1016,
49 | 237 => 1017,
50 | 238 => 1018,
51 | 239 => 1019,
52 | 240 => 1020
53 | );
54 |
55 | public function __construct()
56 | {
57 | $this->setFilename('items.json');
58 | $this->setField('items');
59 | }
60 |
61 | public function getImgUrlById($id, $thumb = true, $isConflict = false)
62 | {
63 | $id = (int)$id;
64 | if ($isConflict) {
65 | $id = array_key_exists($id, $this->_conflictsMap) ? $this->_conflictsMap[$id] : $id;
66 | }
67 | return parent::getImgUrlById($id, $thumb);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/includes/Data/Lobbies.php:
--------------------------------------------------------------------------------
1 |
11 | * $lobbies = new Dota2Api\Data\Lobbies();
12 | * $lobbies->parse();
13 | * $lobbies->getFieldById(2, 'name'); // returns 'Tournament'
14 | *
15 | */
16 | class Lobbies extends Data
17 | {
18 | public function __construct()
19 | {
20 | $this->_filename = 'lobbies.json';
21 | $this->_field = 'lobbies';
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/includes/Data/Mods.php:
--------------------------------------------------------------------------------
1 |
11 | * $mods = new Dota2Api\Data\Mods();
12 | * $mods->parse();
13 | * $mods->getFieldById(1, 'name'); // returns 'All Pick'
14 | *
15 | */
16 | class Mods extends Data
17 | {
18 | public function __construct()
19 | {
20 | $this->_filename = 'mods.json';
21 | $this->_field = 'mods';
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/includes/Data/Regions.php:
--------------------------------------------------------------------------------
1 |
11 | * $regions = new Dota2Api\Data\Regions();
12 | * $regions->parse();
13 | * $regions->getFieldById(132, 'name'); // returns 'Europe West'
14 | *
15 | */
16 | class Regions extends Data
17 | {
18 | public function __construct()
19 | {
20 | $this->_filename = 'regions.json';
21 | $this->_field = 'regions';
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/includes/Mappers/HeroesMapper.php:
--------------------------------------------------------------------------------
1 |
13 | * $heroesMapper = new Dota2Api\Mappers\HeroesMapper();
14 | * $heroes = $heroesMapper->load();
15 | * print_r($heroes);
16 | *
17 | */
18 | class HeroesMapper
19 | {
20 | /**
21 | * Request url
22 | */
23 | const HEROES_STEAM_URL = 'https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/';
24 |
25 | /**
26 | * @return array
27 | */
28 | public function load()
29 | {
30 | $request = new Request(
31 | self::HEROES_STEAM_URL,
32 | array()
33 | );
34 | $response = $request->send();
35 | if (null === $response) {
36 | return null;
37 | }
38 | $heroes_info = (array)($response->heroes);
39 | $heroes_info = $heroes_info['hero'];
40 | $heroes = array();
41 | foreach ($heroes_info as $hero_info) {
42 | $info = (array)$hero_info;
43 | $heroes[$info['id']] = $info;
44 | }
45 | return $heroes;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/includes/Mappers/ItemsMapper.php:
--------------------------------------------------------------------------------
1 |
13 | * $itemsMapperDb = new Dota2Api\Mappers\ItemsMapperDb();
14 | * $itemsInfo = $itemsMapperDb->load();
15 | * print_r($itemsInfo);
16 | * foreach($itemsInfo as $item) {
17 | * echo $item->get('id');
18 | * echo $item->get('name');
19 | * echo $item->get('cost');
20 | * echo $item->get('secret_shop');
21 | * echo $item->get('side_shop');
22 | * echo $item->get('recipe');
23 | * echo $item->get('localized_name');
24 | * }
25 | *
26 | */
27 | class ItemsMapperDb extends ItemsMapper
28 | {
29 |
30 | /**
31 | * @return Item[]
32 | */
33 | public function load()
34 | {
35 | $db = Db::obtain();
36 | $items = array();
37 | $itemsInfo = $db->fetchArrayPDO('SELECT * FROM ' . Db::realTablename('items'));
38 | foreach ($itemsInfo as $itemInfo) {
39 | $item = new Item();
40 | $item->setArray($itemInfo);
41 | $items[$itemInfo['id']] = $item;
42 | }
43 | return $items;
44 | }
45 |
46 | /**
47 | * @param Item[] $data list of items
48 | */
49 | public function save(array $data)
50 | {
51 | $db = Db::obtain();
52 | $dataToInsert = array();
53 | foreach ($data as $item) {
54 | array_push($dataToInsert, $item->getDataArray());
55 | }
56 | $db->insertManyPDO(
57 | Db::realTablename('items'),
58 | array('id', 'name', 'cost', 'secret_shop', 'side_shop', 'recipe', 'localized_name'),
59 | $dataToInsert,
60 | true
61 | );
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/includes/Mappers/ItemsMapperWeb.php:
--------------------------------------------------------------------------------
1 |
13 | * $itemsMapperWeb = new Dota2Api\Mappers\ItemsMapperWeb();
14 | * $itemsInfo = $itemsMapperWeb->load();
15 | * print_r($itemsInfo);
16 | * foreach($itemsInfo as $item) {
17 | * echo $item->get('id');
18 | * echo $item->get('name');
19 | * echo $item->get('cost');
20 | * echo $item->get('secret_shop');
21 | * echo $item->get('side_shop');
22 | * echo $item->get('recipe');
23 | * echo $item->get('localized_name');
24 | * }
25 | *
26 | */
27 | class ItemsMapperWeb extends ItemsMapper
28 | {
29 |
30 | /**
31 | * Request url
32 | */
33 | const ITEMS_STEAM_URL = 'https://api.steampowered.com/IEconDOTA2_570/GetGameItems/v0001/';
34 |
35 | /**
36 | * @return Item[]
37 | */
38 | public function load()
39 | {
40 | $request = new Request(
41 | self::ITEMS_STEAM_URL,
42 | array()
43 | );
44 | $response = $request->send();
45 | if (null === $response) {
46 | return null;
47 | }
48 | $itemsInfo = (array)($response->items);
49 | $itemsInfo = $itemsInfo['item'];
50 | $items = array();
51 | foreach ($itemsInfo as $itemInfo) {
52 | $info = (array)$itemInfo;
53 | array_walk($info, function (&$v) {
54 | $v = (string)$v;
55 | });
56 | $item = new item();
57 | $item->setArray($info);
58 | $items[$info['id']] = $item;
59 | }
60 | return $items;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/includes/Mappers/LeagueMapper.php:
--------------------------------------------------------------------------------
1 |
15 | * $leagueMapper = new Dota2Api\Mappers\LeagueMapper(22); // set league id (can be get via leaguesMapper)
16 | * $games = $leagueMapper->load();
17 | * print_r($games);
18 | *
19 | */
20 | class LeagueMapper
21 | {
22 | /**
23 | *
24 | */
25 | const LEAGUE_STEAM_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetLiveLeagueGames/v0001/';
26 | /**
27 | * @var int
28 | */
29 | protected $_leagueId;
30 |
31 | /**
32 | * @param int $leagueId
33 | * @return LeagueMapper
34 | */
35 | public function setLeagueId($leagueId)
36 | {
37 | $this->_leagueId = (int)$leagueId;
38 | return $this;
39 | }
40 |
41 | /**
42 | * @return int
43 | */
44 | public function getLeagueId()
45 | {
46 | return $this->_leagueId;
47 | }
48 |
49 | /**
50 | * @param int $leagueId
51 | */
52 | public function __construct($leagueId = null)
53 | {
54 | if (null !== $leagueId) {
55 | $this->setLeagueId($leagueId);
56 | }
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public function load()
63 | {
64 | $leagueId = $this->getLeagueId();
65 | $requestData = $leagueId ? array('league_id' => $leagueId) : array();
66 | $request = new Request(
67 | self::LEAGUE_STEAM_URL,
68 | $requestData
69 | );
70 | $leagueLiveMatches = $request->send();
71 | return null === $leagueLiveMatches ? null : $this->parseLoadedMatches($leagueLiveMatches);
72 | }
73 |
74 | /**
75 | * @param $leagueLiveMatches
76 | * @return LiveMatch[]
77 | */
78 | protected function parseLoadedMatches($leagueLiveMatches)
79 | {
80 | $leagueLiveMatches = $leagueLiveMatches->games;
81 | $liveMatches = array();
82 | if (null === $leagueLiveMatches->game) {
83 | return array();
84 | }
85 | foreach ($leagueLiveMatches->game as $game) {
86 | $liveMatch = new LiveMatch();
87 | foreach ($game->players->player as $player) {
88 | $data = (array)$player;
89 | $data['match_id'] = $game->match_id;
90 | switch ($player->team) {
91 | case 0:
92 | $liveMatch->addRadiantPlayer($data);
93 | break;
94 | case 1:
95 | $liveMatch->addDirePlayer($data);
96 | break;
97 | case 2:
98 | $liveMatch->addBroadcaster($data);
99 | break;
100 | case 4:
101 | $liveMatch->addUnassigned($data);
102 | break;
103 | }
104 | }
105 | $a_game = (array)$game;
106 | $a_game['stage_name'] = strval($a_game['stage_name']);
107 | $a_game['leagueid'] = $a_game['league_id'];
108 | unset($a_game['league_id']);
109 | $picks_bans = array();
110 | $teams = array('radiant', 'dire');
111 | foreach ($teams as $team) {
112 | if (array_key_exists($team . '_team', $a_game)) {
113 | $a_game[$team . '_team_id'] = (string)$a_game[$team . '_team']->team_id;
114 | $a_game[$team . '_name'] = (string)$a_game[$team . '_team']->team_name;
115 | $a_game[$team . '_logo'] = (string)$a_game[$team . '_team']->team_logo;
116 | $a_game[$team . '_team_complete'] = ($a_game[$team . '_team']->complete === 'false') ? 0 : 1;
117 | }
118 | }
119 | $liveMatch->setArray($a_game);
120 | if (array_key_exists('scoreboard', $a_game)) {
121 | $scoreboard = $a_game['scoreboard'];
122 | $a_board = (array)$scoreboard;
123 | $liveMatch->set('duration', intval($a_board['duration']));
124 | $liveMatch->set('roshan_respawn_timer', intval($a_board['roshan_respawn_timer']));
125 |
126 | if ($scoreboard->radiant) {
127 | $this->parseScoreboard($liveMatch, $scoreboard, 'radiant');
128 | }
129 | if ($scoreboard->dire) {
130 | $this->parseScoreboard($liveMatch, $scoreboard, 'dire');
131 | }
132 | }
133 | $liveMatch->setAllPickBans($picks_bans);
134 | $liveMatches[$liveMatch->get('match_id')] = $liveMatch;
135 | }
136 | return $liveMatches;
137 | }
138 |
139 | /**
140 | * @param LiveMatch $liveMatch
141 | * @param Object $scoreboard
142 | * @param string $teamSide
143 | * @return LiveMatch
144 | */
145 | private function parseScoreboard(&$liveMatch, $scoreboard, $teamSide)
146 | {
147 | $team = $scoreboard->{$teamSide};
148 | $liveMatch->set($teamSide.'_score', strval($team->score));
149 | $liveMatch->set('tower_status_' . $teamSide, strval($team->tower_state));
150 | $liveMatch->set('barracks_status_' . $teamSide, strval($team->barracks_state));
151 | if ($team->players) {
152 | foreach ($team->players->player as $player) {
153 | $liveSlot = new LiveSlot();
154 | $slotData = (array)$player;
155 | for ($i = 0; $i <= 5; $i++) {
156 | if (!array_key_exists('item_'.$i, $slotData) && array_key_exists('item'.$i, $slotData)) {
157 | $slotData['item_'.$i] = $slotData['item'.$i];
158 | unset($slotData['item'.$i]);
159 | }
160 | }
161 | $liveSlot->setArray($slotData);
162 | $liveSlot->set('match_id', $liveMatch->get('match_id'));
163 | $liveSlot->set('player_slot', $this->getPlayerSlot($player->player_slot, $teamSide));
164 | $liveMatch->addSlot($liveSlot);
165 | }
166 | }
167 | $fl = $team === 'radiant' ? 0 : 1;
168 | if ($team->picks) {
169 | foreach ($team->picks->pick as $pick) {
170 | $liveMatch->addPickBan($this->getPickBanItem(true, $fl, 0, $pick->hero_id));
171 | }
172 | }
173 | if ($team->bans) {
174 | foreach ($team->bans->ban as $ban) {
175 | $liveMatch->addPickBan($this->getPickBanItem(false, $fl, 0, $ban->hero_id));
176 | }
177 | }
178 | return $liveMatch;
179 | }
180 |
181 | private function getPlayerSlot($val, $teamSide)
182 | {
183 | $val = intval($val);
184 | return $teamSide === 'radiant' ? $val - 1 : $val + 127;
185 | }
186 |
187 | /**
188 | * @param boolean $isPick
189 | * @param 0|1 $team
190 | * @param integer $order
191 | * @param integer|string $heroId
192 | * @return array
193 | */
194 | private function getPickBanItem($isPick, $team, $order, $heroId)
195 | {
196 | return array(
197 | 'is_pick' => $isPick,
198 | 'team' => $team,
199 | 'order' => $order,
200 | 'hero_id' => strval($heroId)
201 | );
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/includes/Mappers/LeaguePrizePoolMapper.php:
--------------------------------------------------------------------------------
1 | _leagueId = (int)$leagueId;
30 | return $this;
31 | }
32 |
33 | /**
34 | * @return int
35 | */
36 | public function getLeagueId()
37 | {
38 | return $this->_leagueId;
39 | }
40 |
41 | /**
42 | * @param int $prizePool
43 | * @return LeaguePrizePoolMapper
44 | */
45 | public function setPrizePool($prizePool)
46 | {
47 | $this->_prizePool = (int)$prizePool;
48 | return $this;
49 | }
50 |
51 | /**
52 | * @return int
53 | */
54 | public function getPrizePool()
55 | {
56 | return $this->_prizePool;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/includes/Mappers/LeaguePrizePoolMapperDb.php:
--------------------------------------------------------------------------------
1 |
12 | * $prizePoolMapperDb = new Dota2Api\Mappers\LeaguePrizePoolMapperDb();
13 | * $pp = $prizePoolMapperDb->setLeagueId(600)->load();
14 | * foreach($pp as $date=>$prizePool) {
15 | * echo $date.' - $ '.number_format($prizePool, 2).'
';
16 | * }
17 | *
18 | */
19 | class LeaguePrizePoolMapperDb extends LeaguePrizePoolMapper
20 | {
21 |
22 | public function load()
23 | {
24 | $leagueid = $this->getLeagueId();
25 | if (null === $leagueid) {
26 | return array();
27 | }
28 | $db = Db::obtain();
29 | $checks = array();
30 | $result = $db->fetchArrayPDO(
31 | 'SELECT * FROM ' . Db::realTablename('league_prize_pools') . ' WHERE league_id = ' . $leagueid,
32 | array()
33 | );
34 | foreach ($result as $r) {
35 | $checks[$r['date']] = $r['prize_pool'];
36 | }
37 |
38 | return $checks;
39 | }
40 |
41 | public function save()
42 | {
43 | $leagueid = $this->getLeagueId();
44 | $prizePool = $this->getPrizePool();
45 | if (null === $prizePool || null === $leagueid) {
46 | return;
47 | }
48 | $db = Db::obtain();
49 | $data = array('league_id' => $leagueid, 'prize_pool' => $prizePool);
50 | $db->insertPDO(Db::realTablename('league_prize_pools'), $data);
51 | echo $db->getError();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/includes/Mappers/LeaguePrizePoolMapperWeb.php:
--------------------------------------------------------------------------------
1 |
12 | * $leaguePrizePoolMapperWeb = new Dota2Api\Mappers\LeaguePrizePoolMapperWeb();
13 | * $leaguePrizePoolMapperWeb->setLeagueId(600);
14 | * $prizePoolInfo = $leaguePrizePoolMapperWeb->load();
15 | * print_r($prizePoolInfo);
16 | * echo $prizePoolInfo['prize_pool'];
17 | * echo $prizePoolInfo['league_id'];
18 | * echo $prizePoolInfo['status']; // may be undefined
19 | *
20 | */
21 | class LeaguePrizePoolMapperWeb extends LeaguePrizePoolMapper
22 | {
23 |
24 | /**
25 | * Request url
26 | */
27 | const LEAGUES_PRIZE_POOL_STEAM_URL = 'http://api.steampowered.com/IEconDOTA2_570/GetTournamentPrizePool/v1/';
28 |
29 | /**
30 | * @param int $leagueId
31 | */
32 | public function __construct($leagueId = null)
33 | {
34 | if (null !== $leagueId) {
35 | $this->setLeagueId($leagueId);
36 | }
37 | }
38 |
39 | public function load()
40 | {
41 | $request = new Request(
42 | self::LEAGUES_PRIZE_POOL_STEAM_URL,
43 | array('leagueid' => $this->getLeagueId())
44 | );
45 | $prizePool = $request->send();
46 | if (null === $prizePool) {
47 | return null;
48 | }
49 | return (array)$prizePool;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/includes/Mappers/LeaguesMapper.php:
--------------------------------------------------------------------------------
1 | fetchArrayPDO('SELECT * FROM ' . Db::realTablename('leagues'). ' '. $addSql);
22 | $leagues = array();
23 | foreach ($data as $row) {
24 | $league = new League();
25 | $league->setArray($row);
26 | $leagues[$row['leagueid']] = $league;
27 | }
28 | return $leagues;
29 | }
30 |
31 | public function delete($ids)
32 | {
33 | if (!$ids) {
34 | return;
35 | }
36 | if (!is_array($ids)) {
37 | $ids = array($ids);
38 | }
39 | $ids_str = implode(',', $ids);
40 | $db = Db::obtain();
41 | $db->exec('DELETE FROM ' . Db::realTablename('leagues') . ' WHERE leagueid IN (' . $ids_str . ')');
42 | }
43 |
44 | /**
45 | * @param League $league
46 | * @param bool $autoUpdate if true - update league info if league exists in the DB
47 | */
48 | public function save(League $league, $autoUpdate = true)
49 | {
50 | if (self::leagueExists($league->get('leagueid'))) {
51 | if ($autoUpdate) {
52 | $this->update($league);
53 | }
54 | } else {
55 | $this->insert($league);
56 | }
57 | }
58 |
59 | /**
60 | * @param League $league
61 | */
62 | public function insert(League $league)
63 | {
64 | $db = Db::obtain();
65 | $db->insertPDO(Db::realTablename('leagues'), $league->getDataArray());
66 | }
67 |
68 | /**
69 | * @param League $league
70 | */
71 | public function update(League $league)
72 | {
73 | $db = Db::obtain();
74 | $db->updatePDO(
75 | Db::realTablename('leagues'),
76 | $league->getDataArray(),
77 | array('leagueid' => $league->get('leagueid'))
78 | );
79 | }
80 |
81 | public static function leagueExists($leagueid)
82 | {
83 | $leagueid = (int)$leagueid;
84 | $db = Db::obtain();
85 | $r = $db->queryFirstPDO(
86 | 'SELECT leagueid FROM ' . Db::realTablename('leagues') . ' WHERE leagueid = ?',
87 | array($leagueid)
88 | );
89 | return ((bool)$r);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/includes/Mappers/LeaguesMapperWeb.php:
--------------------------------------------------------------------------------
1 |
14 | * $leaguesMapperWeb = new Dota2Api\Mappers\LeaguesMapperWeb();
15 | * $leagues = $leaguesMapperWeb->load();
16 | * foreach($leagues as $league) {
17 | * echo $league->get('description');
18 | * if ($league->get('tournament_url')) {
19 | * echo $league->get('tournament_url');
20 | * }
21 | * }
22 | *
23 | */
24 | class LeaguesMapperWeb extends LeaguesMapper
25 | {
26 | /**
27 | *
28 | */
29 | const LEAGUES_STEAM_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetLeagueListing/v0001/';
30 |
31 | /**
32 | * @return League[]
33 | */
34 | public function load()
35 | {
36 | $request = new Request(
37 | self::LEAGUES_STEAM_URL,
38 | array()
39 | );
40 | $response = $request->send();
41 | if (null === $response) {
42 | return null;
43 | }
44 | $leaguesInfo = (array)($response->leagues);
45 | $leaguesInfo = $leaguesInfo['league'];
46 | $leagues = array();
47 | foreach ($leaguesInfo as $leagueInfo) {
48 | $info = (array)$leagueInfo;
49 | array_walk($info, function (&$v) {
50 | $v = (string)$v;
51 | });
52 | $league = new League();
53 | $league->setArray($info);
54 | $leagues[$info['leagueid']] = $league;
55 | }
56 | return $leagues;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/includes/Mappers/LiveMatchMapperDb.php:
--------------------------------------------------------------------------------
1 | matchesTable) . ' WHERE match_id=?';
31 | $queryForSlots = 'SELECT * FROM ' . Db::realTablename($this->slotsTable) . ' WHERE match_id=?';
32 | $queryForBroadcasters = 'SELECT * FROM ' . Db::realTablename('broadcasters') . ' WHERE match_id=?';
33 | $broadcasters = $db->fetchArrayPDO($queryForBroadcasters, array($liveMatchId));
34 | $matchInfo = $db->fetchArrayPdo($queryForMatch, array($liveMatchId));
35 | $liveMatchStamps = array();
36 | foreach ($matchInfo as $mTime) {
37 | $id = $mTime['id'];
38 | $match = new LiveMatch();
39 | $match->setArray($mTime);
40 | foreach ($broadcasters as $broadcaster) {
41 | $match->addBroadcaster($broadcaster);
42 | }
43 | $liveMatchStamps[$id] = $match;
44 | }
45 | $match = new LiveMatch();
46 | if (!$matchInfo) {
47 | return $match;
48 | }
49 | $match->setArray($matchInfo);
50 | $slots = $db->fetchArrayPDO($queryForSlots, array($liveMatchId));
51 | foreach ($slots as $s) {
52 | $slot = new LiveSlot();
53 | $slot->setArray($s);
54 | $liveMatchStamps[$s['live_match_id']]->addSlot($slot);
55 | }
56 | return $liveMatchStamps;
57 | }
58 |
59 | /**
60 | * @param LiveMatch $liveMatch
61 | */
62 | public function save($liveMatch)
63 | {
64 | $this->insert($liveMatch);
65 | }
66 |
67 | /**
68 | * @param LiveMatch $liveMatch
69 | */
70 | public function insert($liveMatch)
71 | {
72 | $db = Db::obtain();
73 | $slots = $liveMatch->getAllSlots();
74 | $liveMatchId = $db->insertPDO(Db::realTablename($this->matchesTable), $liveMatch->getDataArray());
75 | if ($liveMatchId === false) {
76 | return;
77 | }
78 | foreach ($slots as $slot) {
79 | $dataToSave = $slot->getDataArray();
80 | $dataToSave['live_match_id'] = $liveMatchId;
81 | $db->insertPDO(Db::realTablename($this->slotsTable), $dataToSave);
82 | }
83 | $broadcasters = $liveMatch->get('broadcasters');
84 | if (count($broadcasters)) {
85 | $dataToSave = array();
86 | foreach ($broadcasters as $b) {
87 | array_push($dataToSave, array($b['match_id'], $b['account_id'], $b['name']));
88 | }
89 | $db->insertManyPDO('broadcasters', array('match_id', 'account_id', 'name'), $dataToSave);
90 | }
91 | }
92 |
93 | /**
94 | * No `update` for LiveMatch - only `insert`
95 | *
96 | * @param \Dota2Api\Models\LiveMatch $liveMatch
97 | */
98 | public function update($liveMatch)
99 | {
100 | $this->insert($liveMatch);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchMapper.php:
--------------------------------------------------------------------------------
1 | _match_id = $matchId;
25 | }
26 | return $this;
27 | }
28 |
29 | /**
30 | * @return int
31 | */
32 | public function getMatchId()
33 | {
34 | return $this->_match_id;
35 | }
36 |
37 | /**
38 | * @param int $matchId
39 | */
40 | public function __construct($matchId = null)
41 | {
42 | if (null !== $matchId) {
43 | $this->setMatchId($matchId);
44 | }
45 | }
46 |
47 | /**
48 | * Load info by match_id
49 | * @return mixed
50 | */
51 | abstract public function load();
52 | }
53 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchMapperDb.php:
--------------------------------------------------------------------------------
1 |
16 | * $mm = new Dota2Api\Mappers\MatchMapperDb(111093969);
17 | * $match = $mm->load();
18 | * echo $match->get('match_id');
19 | * echo $match->get('start_time');
20 | * echo $match->get('game_mode');
21 | * $slots = $match->getAllSlots();
22 | * foreach($slots as $slot) {
23 | * echo $slot->get('last_hits');
24 | * }
25 | * print_r($match->getDataArray());
26 | * print_r($match->getSlot(0)->getDataArray());
27 | * $mm->save($match);
28 | * $mm->delete(111093969);
29 | *
30 | */
31 | class MatchMapperDb extends MatchMapper
32 | {
33 |
34 | /**
35 | * @var string
36 | */
37 | protected $matchesTable = 'matches';
38 | /**
39 | * @var string
40 | */
41 | protected $slotsTable = 'slots';
42 |
43 | /**
44 | * @param int $matchId
45 | * @return Match
46 | */
47 | public function load($matchId = null)
48 | {
49 | if (null !== $matchId) {
50 | $this->setMatchId($matchId);
51 | }
52 | $db = Db::obtain();
53 | $queryForMatch = 'SELECT * FROM ' . Db::realTablename($this->matchesTable) . ' WHERE match_id=?';
54 | $queryForSlots = 'SELECT * FROM ' . Db::realTablename($this->slotsTable) . ' WHERE match_id=?';
55 | $matchInfo = $db->queryFirstPDO($queryForMatch, array($this->getMatchId()));
56 | $match = new Match();
57 | if (!$matchInfo) {
58 | return $match;
59 | }
60 | $match->setArray($matchInfo);
61 | $slots = $db->fetchArrayPDO($queryForSlots, array($this->getMatchId()));
62 | $slotIds = '';
63 | foreach ($slots as $slot) {
64 | $slotIds .= $slot['id'] . ',';
65 | }
66 | $queryForAbilityUpgrades = 'SELECT * FROM ' . Db::realTablename('ability_upgrades') . ' WHERE slot_id IN (' . rtrim(
67 | $slotIds,
68 | ','
69 | ) . ')';
70 | $abilityUpgrade = $db->fetchArrayPDO($queryForAbilityUpgrades);
71 | $abilityUpgradeFormatted = array();
72 | foreach ($abilityUpgrade as $a) {
73 | if (!array_key_exists($a['slot_id'], $abilityUpgradeFormatted)) {
74 | $abilityUpgradeFormatted[$a['slot_id']] = array();
75 | }
76 | array_push($abilityUpgradeFormatted[$a['slot_id']], $a);
77 | }
78 | $queryForAdditionalUnits = 'SELECT * FROM ' . Db::realTablename('additional_units') . ' WHERE slot_id IN (' . rtrim(
79 | $slotIds,
80 | ','
81 | ) . ')';
82 | $additionalUnits = $db->fetchArrayPDO($queryForAdditionalUnits);
83 | $additionalUnitsFormatted = array();
84 | foreach ($additionalUnits as $additionalUnit) {
85 | if (!array_key_exists($additionalUnit['slot_id'], $additionalUnitsFormatted)) {
86 | $additionalUnitsFormatted[$additionalUnit['slot_id']] = array();
87 | }
88 | array_push($additionalUnitsFormatted[$additionalUnit['slot_id']], $additionalUnit);
89 | }
90 | foreach ($slots as $s) {
91 | $slot = new Slot();
92 | $slot->setArray($s);
93 | if (array_key_exists($slot->get('id'), $abilityUpgradeFormatted)) {
94 | $slot->setAbilitiesUpgrade($abilityUpgradeFormatted[$slot->get('id')]);
95 | }
96 | if (array_key_exists($slot->get('id'), $additionalUnitsFormatted)) {
97 | $slot->setAdditionalUnitItems($additionalUnitsFormatted[$slot->get('id')]);
98 | }
99 | $match->addSlot($slot);
100 | }
101 | if ($match->get('game_mode') == match::CAPTAINS_MODE) {
102 | $queryForPicksBans = 'SELECT `is_pick`, `hero_id`, `team`, `order` FROM ' . Db::realTablename('picks_bans') . ' WHERE match_id = ? ORDER BY `order`';
103 | $picks_bans = $db->fetchArrayPDO($queryForPicksBans, array($match->get('match_id')));
104 | $match->setAllPickBans($picks_bans);
105 | }
106 | return $match;
107 | }
108 |
109 | /**
110 | * @param match $match
111 | * @param bool $autoUpdate if true - update match info if match exists in the DB
112 | */
113 | public function save(Match $match, $autoUpdate = true)
114 | {
115 | if (self::matchExists($match->get('match_id'))) {
116 | if ($autoUpdate) {
117 | $this->update($match);
118 | }
119 | } else {
120 | $this->insert($match);
121 | }
122 | }
123 |
124 | /**
125 | * @param $match
126 | */
127 | public function insert(Match $match)
128 | {
129 | $db = Db::obtain();
130 | $slots = $match->getAllSlots();
131 | if ($match->get('radiant_team_id')) {
132 | $db->insertPDO(Db::realTablename('teams'), array(
133 | 'id' => $match->get('radiant_team_id'),
134 | 'name' => $match->get('radiant_name')
135 | ));
136 | }
137 |
138 | if ($match->get('dire_team_id')) {
139 | $db->insertPDO(Db::realTablename('teams'), array(
140 | 'id' => $match->get('dire_team_id'),
141 | 'name' => $match->get('dire_name')
142 | ));
143 | }
144 |
145 | // save common match info
146 | $db->insertPDO(Db::realTablename($this->matchesTable), $match->getDataArray());
147 | // save accounts
148 | foreach ($slots as $slot) {
149 | if ((int)$slot->get('account_id') !== Player::ANONYMOUS) {
150 | $db->insertPDO(Db::realTablename('users'), array(
151 | 'account_id' => $slot->get('account_id'),
152 | 'steamid' => Player::convertId($slot->get('account_id'))
153 | ));
154 | }
155 | }
156 | // save slots
157 | foreach ($slots as $slot) {
158 | $slotId = $db->insertPDO(Db::realTablename($this->slotsTable), $slot->getDataArray());
159 | // save abilities upgrade
160 | $aU = $slot->getAbilitiesUpgrade();
161 | if (count($aU) > 0) {
162 | $keys = array();
163 | $data = array();
164 | foreach ($aU as $ability) {
165 | $keys = array_keys($ability); // yes, it will be reassigned many times
166 | $data1 = array_values($ability);
167 | array_unshift($data1, $slotId);
168 | array_push($data, $data1);
169 | }
170 | reset($aU);
171 | array_unshift($keys, 'slot_id');
172 | $db->insertManyPDO(Db::realTablename('ability_upgrades'), $keys, $data);
173 | }
174 | $additionalUnit = $slot->getAdditionalUnitItems();
175 | if (count($additionalUnit) > 0) {
176 | $additionalUnit['slot_id'] = $slotId;
177 | $db->insertPDO(Db::realTablename('additional_units'), $additionalUnit);
178 | }
179 | }
180 | if ((int)$match->get('game_mode') === match::CAPTAINS_MODE) {
181 | $picksBans = $match->getAllPicksBans();
182 | $data = array();
183 | foreach ($picksBans as $pickBan) {
184 | $data1 = array();
185 | array_push($data1, $match->get('match_id'));
186 | array_push($data1, $pickBan['is_pick']);
187 | array_push($data1, $pickBan['hero_id']);
188 | array_push($data1, $pickBan['team']);
189 | array_push($data1, $pickBan['order']);
190 | array_push($data, $data1);
191 | }
192 | $db->insertManyPDO(
193 | Db::realTablename('picks_bans'),
194 | array('match_id', 'is_pick', 'hero_id', 'team', 'order'),
195 | $data
196 | );
197 | }
198 | }
199 |
200 | /**
201 | * @param Match $match
202 | * @param bool $lazy if false - update all data, if true - only possible updated data
203 | */
204 | public function update(Match $match, $lazy = true)
205 | {
206 | $db = Db::obtain();
207 | $slots = $match->getAllSlots();
208 | // update common match info
209 | $db->updatePDO(
210 | Db::realTablename($this->matchesTable),
211 | $match->getDataArray(),
212 | array('match_id' => $match->get('match_id'))
213 | );
214 | foreach ($slots as $slot) {
215 | // update accounts
216 | $db->updatePDO(Db::realTablename('users'), array(
217 | 'account_id' => $slot->get('account_id'),
218 | 'steamid' => Player::convertId($slot->get('account_id'))
219 | ), array('account_id' => $slot->get('account_id')));
220 | // update slots
221 | if (!$lazy) {
222 | $db->updatePDO(
223 | Db::realTablename($this->slotsTable),
224 | $slot->getDataArray(),
225 | array('match_id' => $slot->get('match_id'), 'player_slot' => $slot->get('player_slot'))
226 | );
227 | }
228 | }
229 | }
230 |
231 | /**
232 | * @param int $matchId
233 | */
234 | public function delete($matchId)
235 | {
236 | if (!self::matchExists($matchId)) {
237 | return;
238 | }
239 | $db = Db::obtain();
240 | $slots = $db->fetchArrayPDO(
241 | 'SELECT id FROM ' . Db::realTablename($this->slotsTable) . ' WHERE match_id = ?',
242 | array($matchId)
243 | );
244 | $slotsFormatted = array();
245 | foreach ($slots as $slot) {
246 | array_push($slotsFormatted, $slot['id']);
247 | }
248 | if (count($slotsFormatted)) {
249 | $slots_str = implode(',', $slotsFormatted);
250 | $db->exec('DELETE FROM ' . Db::realTablename('ability_upgrades') . ' WHERE slot_id IN (' . $slots_str . ')');
251 | $db->exec('DELETE FROM ' . Db::realTablename('additional_units') . ' WHERE slot_id IN (' . $slots_str . ')');
252 | $db->exec('DELETE FROM ' . Db::realTablename($this->slotsTable) . ' WHERE id IN (' . $slots_str . ')');
253 | }
254 | $db->deletePDO(Db::realTablename('picks_bans'), array('match_id' => $matchId), 0);
255 | $db->deletePDO(Db::realTablename($this->matchesTable), array('match_id' => $matchId));
256 | }
257 |
258 | /**
259 | * Delete match data from db
260 | *
261 | * @param int $matchId
262 | * @return bool
263 | */
264 | public static function matchExists($matchId)
265 | {
266 | $db = Db::obtain();
267 | $r = $db->queryFirstPDO(
268 | 'SELECT match_id FROM ' . Db::realTablename('matches') . ' WHERE match_id = ?',
269 | array($matchId)
270 | );
271 | return ((bool)$r);
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchMapperWeb.php:
--------------------------------------------------------------------------------
1 |
15 | * $mm = new Dota2Api\Mappers\MatchMapperWeb(121995119);
16 | * $match = $mm->load();
17 | * echo $match->get('match_id');
18 | * echo $match->get('start_time');
19 | * echo $match->get('game_mode');
20 | * $slots = $match->getAllSlots();
21 | * foreach($slots as $slot) {
22 | * echo $slot->get('last_hits');
23 | * }
24 | * print_r($match->getDataArray());
25 | * print_r($match->getSlot(0)->getDataArray());
26 | *
27 | */
28 | class MatchMapperWeb extends MatchMapper
29 | {
30 | const STEAM_MATCH_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/';
31 |
32 | public function __construct($matchId)
33 | {
34 | parent::__construct($matchId);
35 | }
36 |
37 | /**
38 | * Load match info by match_id
39 | */
40 | public function load()
41 | {
42 | $request = new request(self::STEAM_MATCH_URL, array('match_id' => $this->getMatchId()));
43 | $matchInfo = $request->send();
44 | if (null === $matchInfo) {
45 | return null;
46 | }
47 | $match = new Match();
48 | $players = array();
49 | foreach ($matchInfo->players->player as $key => $player) {
50 | $players[] = $player;
51 | }
52 | $data = (array)$matchInfo;
53 | unset($data['players']);
54 | $data['start_time'] = date('Y-m-d H:i:s', $data['start_time']);
55 | $data['radiant_win'] = ($data['radiant_win'] === 'true') ? '1' : '0';
56 | $match->setArray($data);
57 | // slots info
58 | foreach ($players as $player) {
59 | $data = (array)$player;
60 | $data['match_id'] = $this->getMatchId();
61 | $slot = new Slot();
62 | $slot->setArray($data);
63 | // additional_units
64 | if (array_key_exists('additional_units', $data)) {
65 | $slot->setAdditionalUnitItems((array)($data['additional_units']->unit));
66 | }
67 | // abilities
68 | if (array_key_exists('ability_upgrades', $data)) {
69 | $d = (array)$data['ability_upgrades'];
70 | $abilitiesUpgrade = $d['ability'];
71 | if (!is_array($abilitiesUpgrade)) {
72 | $abilitiesUpgrade = array($abilitiesUpgrade);
73 | }
74 | foreach ($abilitiesUpgrade as $k => $v) {
75 | $abilitiesUpgrade[$k] = (array)$abilitiesUpgrade[$k];
76 | }
77 | $slot->setAbilitiesUpgrade($abilitiesUpgrade);
78 | }
79 | $match->addSlot($slot);
80 | }
81 | if (isset($matchInfo->picks_bans)) {
82 | $picksBans = (array)$matchInfo->picks_bans;
83 | foreach ($picksBans['pick_ban'] as $k => $v) {
84 | $picksBans['pick_ban'][$k] = (array)$v;
85 | $picksBans['pick_ban'][$k]['is_pick'] = filter_var($picksBans['pick_ban'][$k]['is_pick'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
86 | }
87 | $match->setAllPickBans($picksBans['pick_ban']);
88 | }
89 | return $match;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchesMapper.php:
--------------------------------------------------------------------------------
1 | _player_name = (string)$name;
91 | return $this;
92 | }
93 |
94 | /**
95 | * @return string | null
96 | */
97 | public function getPlayerName()
98 | {
99 | return $this->_player_name;
100 | }
101 |
102 | /**
103 | * @param int $heroId
104 | * @return MatchesMapper
105 | */
106 | public function setHeroId($heroId)
107 | {
108 | $this->_hero_id = (int)$heroId;
109 | return $this;
110 | }
111 |
112 | /**
113 | * @return int
114 | */
115 | public function getHeroId()
116 | {
117 | return $this->_hero_id;
118 | }
119 |
120 | /**
121 | * @param int $skill
122 | * @return MatchesMapper
123 | */
124 | public function setSkill($skill)
125 | {
126 | $skill = (int)$skill;
127 | if ($skill >= 0 && $skill <= 3) {
128 | $this->_skill = $skill;
129 | }
130 | return $this;
131 | }
132 |
133 | /**
134 | * @return int
135 | */
136 | public function getSkill()
137 | {
138 | return $this->_skill;
139 | }
140 |
141 | /**
142 | * @param int $timestamp
143 | * @return MatchesMapper
144 | */
145 | public function setDateMax($timestamp)
146 | {
147 | $timestamp = (int)$timestamp;
148 | if ($timestamp >= 0 && $timestamp < 2147483647) {
149 | $this->_date_max = $timestamp;
150 | }
151 | return $this;
152 | }
153 |
154 | /**
155 | * @return int
156 | */
157 | public function getDateMax()
158 | {
159 | return $this->_date_max;
160 | }
161 |
162 | /**
163 | * @param int $timestamp
164 | * @return MatchesMapper
165 | */
166 | public function setDateMin($timestamp)
167 | {
168 | $timestamp = (int)$timestamp;
169 | if ($timestamp >= 0 && $timestamp < 2147483647) {
170 | $this->_date_min = $timestamp;
171 | }
172 | return $this;
173 | }
174 |
175 | /**
176 | * @return int
177 | */
178 | public function getDateMin()
179 | {
180 | return $this->_date_min;
181 | }
182 |
183 | /**
184 | * @param int $accountId
185 | * @return MatchesMapper
186 | */
187 | public function setAccountId($accountId)
188 | {
189 | $this->_account_id = (int)$accountId;
190 | return $this;
191 | }
192 |
193 | /**
194 | * @return int
195 | */
196 | public function getAccountId()
197 | {
198 | return $this->_account_id;
199 | }
200 |
201 | /**
202 | * @param int $leagueId
203 | * @return MatchesMapper
204 | */
205 | public function setLeagueId($leagueId)
206 | {
207 | $this->_league_id = (int)$leagueId;
208 | return $this;
209 | }
210 |
211 | /**
212 | * @return int
213 | */
214 | public function getLeagueId()
215 | {
216 | return $this->_league_id;
217 | }
218 |
219 | /**
220 | * @param int $matchId
221 | * @return MatchesMapper
222 | */
223 | public function setStartAtMatchId($matchId)
224 | {
225 | $this->_start_at_match_id = $matchId;
226 | return $this;
227 | }
228 |
229 | /**
230 | * @return int
231 | */
232 | public function getStartAtMatchId()
233 | {
234 | return $this->_start_at_match_id;
235 | }
236 |
237 | /**
238 | * @param int $matchesRequested
239 | * @return MatchesMapper
240 | */
241 | public function setMatchesRequested($matchesRequested)
242 | {
243 | $matchesRequested = (int)$matchesRequested;
244 | if ($matchesRequested > 0 && $matchesRequested <= 100) {
245 | $this->_matches_requested = $matchesRequested;
246 | }
247 | return $this;
248 | }
249 |
250 | /**
251 | * @return int
252 | */
253 | public function getMatchesRequested()
254 | {
255 | return $this->_matches_requested;
256 | }
257 |
258 | /**
259 | * @param string $tournamentGamesOnly
260 | * @return MatchesMapper
261 | */
262 | public function setTournamentGamesOnly($tournamentGamesOnly)
263 | {
264 | $tournamentGamesOnly = ($tournamentGamesOnly === true) ? 'true' : 'false';
265 | $this->_tournament_games_only = $tournamentGamesOnly;
266 | return $this;
267 | }
268 |
269 | /**
270 | * @return string
271 | */
272 | public function getTournamentGamesOnly()
273 | {
274 | return $this->_tournament_games_only;
275 | }
276 |
277 | /**
278 | * @param int $gameMode
279 | * @return MatchesMapper
280 | */
281 | public function setGameMode($gameMode)
282 | {
283 | $gameMode = (int)$gameMode;
284 | $this->_game_mode = $gameMode;
285 | return $this;
286 | }
287 |
288 | /**
289 | * @return string
290 | */
291 | public function getGameMode()
292 | {
293 | return $this->_game_mode;
294 | }
295 | }
296 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchesMapperDb.php:
--------------------------------------------------------------------------------
1 |
15 | * $matchesMapperDb = new Dota2Api\Mappers\MatchesMapperDb();
16 | * $matchesMapperDb->setLeagueId(29)->setMatchesRequested(1);
17 | * $matchesInfo = $matchesMapperDb->load();
18 | * $matchesMapperDb->delete(array(12345, 54321));
19 | * print_r($matchesInfo);
20 | *
21 | */
22 | class MatchesMapperDb extends MatchesMapper
23 | {
24 |
25 | private $_team_id;
26 |
27 | /**
28 | * @param int $teamId
29 | * @return MatchesMapperDb
30 | */
31 | public function setTeamId($teamId)
32 | {
33 | $this->_team_id = (int)$teamId;
34 | return $this;
35 | }
36 |
37 | /**
38 | * @return int | null
39 | */
40 | public function getTeamId()
41 | {
42 | return $this->_team_id;
43 | }
44 |
45 | /**
46 | *
47 | */
48 | public function __construct()
49 | {
50 | }
51 |
52 | /**
53 | * Load matches from db
54 | *
55 | * Possible filters: league_id, hero_id, account_id, start_at_match_id
56 | * Also matches_requested used as LIMIT
57 | * @return Match[]
58 | */
59 | public function load()
60 | {
61 | $matchesInfo = $this->_getMatchesIdsFromMatches();
62 | $matchesIds = array();
63 | foreach ($matchesInfo as $matchInfo) {
64 | array_push($matchesIds, $matchInfo['match_id']);
65 | }
66 | if (count($matchesIds) === 0) {
67 | return array();
68 | }
69 | $slotsInfo = $this->_loadSlotsInfo($matchesIds);
70 | $picksBansFormattedInfo = $this->_loadPicksBansInfo($matchesIds);
71 |
72 | $slotsIds = array();
73 | foreach ($slotsInfo as $slotInfo) {
74 | array_push($slotsIds, $slotInfo['id']);
75 | }
76 |
77 | $abilitiesUpgradeFormattedInfo = $this->_loadAbilityUpgradesInfo($slotsIds);
78 | $additionalUnitsFormattedInfo = $this->_loadAdditionalUnitsInfo($slotsIds);
79 |
80 | // we load all matches info and now need to make proper match objects
81 | $matches = array();
82 | foreach ($matchesInfo as $matchInfo) {
83 | $match = new Match();
84 | $match->setArray($matchInfo);
85 | $slots_count = 0;
86 | foreach ($slotsInfo as $slotInfo) {
87 | if ($slots_count > 9) {
88 | // match can't has more than 10 slots
89 | break;
90 | }
91 | if ($slotInfo['match_id'] == $match->get('match_id')) {
92 | $slot = new slot();
93 | $slot->setArray($slotInfo);
94 | if (array_key_exists($slot->get('id'), $abilitiesUpgradeFormattedInfo)) {
95 | $slot->setAbilitiesUpgrade($abilitiesUpgradeFormattedInfo[$slot->get('id')]);
96 | }
97 | if (array_key_exists($slot->get('id'), $additionalUnitsFormattedInfo)) {
98 | $slot->setAdditionalUnitItems($additionalUnitsFormattedInfo[$slot->get('id')]);
99 | }
100 | $match->addSlot($slot);
101 | $slots_count++;
102 | }
103 | }
104 | if (array_key_exists($match->get('match_id'), $picksBansFormattedInfo)) {
105 | $match->setAllPickBans($picksBansFormattedInfo[$match->get('match_id')]);
106 | }
107 | $matches[$match->get('match_id')] = $match;
108 | }
109 | return $matches;
110 | }
111 |
112 | /**
113 | * Delete matches info from db
114 | * @param array $ids
115 | */
116 | public function delete(array $ids)
117 | {
118 | if (!count($ids)) {
119 | return;
120 | }
121 | $ids_str = implode(',', $ids);
122 | $db = Db::obtain();
123 | $slots = $db->fetchArrayPDO(
124 | 'SELECT id FROM ' . Db::realTablename('slots') . ' WHERE match_id IN (' . $ids_str . ')',
125 | array()
126 | );
127 | $slotsFormatted = array();
128 | foreach ($slots as $slot) {
129 | array_push($slotsFormatted, $slot['id']);
130 | }
131 | if (count($slotsFormatted)) {
132 | $slots_str = implode(',', $slotsFormatted);
133 | $db->exec('DELETE FROM ' . Db::realTablename('ability_upgrades') . ' WHERE slot_id IN (' . $slots_str . ')');
134 | $db->exec('DELETE FROM ' . Db::realTablename('additional_units') . ' WHERE slot_id IN (' . $slots_str . ')');
135 | $db->exec('DELETE FROM ' . Db::realTablename('slots') . ' WHERE id IN (' . $slots_str . ')');
136 | }
137 | $db->exec('DELETE FROM ' . Db::realTablename('picks_bans') . ' WHERE match_id IN (' . $ids_str . ')');
138 | $db->exec('DELETE FROM ' . Db::realTablename('matches') . ' WHERE match_id IN (' . $ids_str . ')');
139 | }
140 |
141 | /**
142 | * Load data about slots from "slots" table.
143 | * Array of the matches ids used as filter
144 | *
145 | * @param array $matchesIds
146 | * @return array
147 | */
148 | private function _loadSlotsInfo(array $matchesIds)
149 | {
150 | $db = Db::obtain();
151 | $slots_query = 'SELECT * FROM ' . Db::realTablename('slots') . ' WHERE match_id IN (' . implode(
152 | ',',
153 | $matchesIds
154 | ) . ')';
155 | return $db->fetchArrayPDO($slots_query, array());
156 | }
157 |
158 | /**
159 | * Load data about picks and bans from "picks_bans" table.
160 | * Array of the matches ids used as filter.
161 | * Data is formatted like
162 | *
163 | * Array (
164 | * [match_id] => Array (
165 | * [0] => Array(
166 | * [id] => int
167 | * [match_id] => match_id
168 | * [is_pick] => 0/1
169 | * [hero_id] => hero_id
170 | * [team] => 0/1
171 | * [order] => 0/1
172 | * )
173 | * ...
174 | * )
175 | * ...
176 | * )
177 | *
178 | * @param array $matchesIds
179 | * @return array
180 | */
181 | private function _loadPicksBansInfo(array $matchesIds)
182 | {
183 | $db = Db::obtain();
184 | $picksBansQuery = 'SELECT * FROM ' . Db::realTablename('picks_bans') . ' WHERE match_id IN (' . implode(
185 | ',',
186 | $matchesIds
187 | ) . ')';
188 | $picksBansInfo = $db->fetchArrayPDO($picksBansQuery, array());
189 | // reformat picks_bans array
190 | $picksBansFormattedInfo = array();
191 | foreach ($picksBansInfo as $pickBanInfo) {
192 | if (!array_key_exists($pickBanInfo['match_id'], $picksBansFormattedInfo)) {
193 | $picksBansFormattedInfo[$pickBanInfo['match_id']] = array();
194 | }
195 | array_push($picksBansFormattedInfo[$pickBanInfo['match_id']], $pickBanInfo);
196 | }
197 | return $picksBansFormattedInfo;
198 | }
199 |
200 | /**
201 | * Load data about ability upgrades from "ability_upgrades" table.
202 | * Array of the slots ids used as filter.
203 | * Data is formatted like
204 | *
205 | * Array (
206 | * [slot_id] => Array (
207 | * [0] => Array (
208 | * [slot_id] => slot_id
209 | * [ability] => ability identifier
210 | * [time] => timestamp from the match start time
211 | * [level] => hero level
212 | * )
213 | * ...
214 | * )
215 | * ...
216 | * )
217 | *
218 | * @param array $slotsIds
219 | * @return array
220 | */
221 | private function _loadAbilityUpgradesInfo(array $slotsIds)
222 | {
223 | $db = Db::obtain();
224 | $abilitiesUpgradeQuery = 'SELECT * FROM ' . Db::realTablename('ability_upgrades') . ' WHERE slot_id IN (' . implode(
225 | ',',
226 | $slotsIds
227 | ) . ') ORDER BY slot_id, level ASC';
228 | $abilitiesUpgradeInfo = $db->fetchArrayPDO($abilitiesUpgradeQuery, array());
229 |
230 | // reformat abilities upgrades array
231 | $abilitiesUpgradeFormattedInfo = array();
232 | foreach ($abilitiesUpgradeInfo as $abilityUpgradeInfo) {
233 | if (!array_key_exists($abilityUpgradeInfo['slot_id'], $abilitiesUpgradeFormattedInfo)) {
234 | $abilitiesUpgradeFormattedInfo[$abilityUpgradeInfo['slot_id']] = array();
235 | }
236 | array_push($abilitiesUpgradeFormattedInfo[$abilityUpgradeInfo['slot_id']], $abilityUpgradeInfo);
237 | }
238 | return $abilitiesUpgradeFormattedInfo;
239 | }
240 |
241 | /**
242 | * Load data about additional units from "additional_units" table.
243 | * Array of the slots ids used as filter.
244 | * Data is formatted like
245 | *
246 | * Array (
247 | * [slot_id] => Array (
248 | * [slot_id] => slot_id
249 | * [unitname] => spirit_bear (example)
250 | * [item_0] => item_id
251 | * [item_1] => item_id
252 | * [item_2] => item_id
253 | * [item_3] => item_id
254 | * [item_4] => item_id
255 | * [item_5] => item_id
256 | * )
257 | * ...
258 | * )
259 | *
260 | * @param array $slotsIds
261 | * @return array
262 | */
263 | private function _loadAdditionalUnitsInfo(array $slotsIds)
264 | {
265 | $db = Db::obtain();
266 | $additionalUnitsQuery = 'SELECT * FROM ' . Db::realTablename('additional_units') . ' WHERE slot_id IN (' . implode(
267 | ',',
268 | $slotsIds
269 | ) . ')';
270 | $additionalUnitsInfo = $db->fetchArrayPDO($additionalUnitsQuery, array());
271 | $additionalUnitsFormattedInfo = array();
272 | foreach ($additionalUnitsInfo as $additionalUnitInfo) {
273 | if (!array_key_exists($additionalUnitInfo['slot_id'], $additionalUnitsFormattedInfo)) {
274 | $additionalUnitsFormattedInfo[$additionalUnitInfo['slot_id']] = array();
275 | }
276 | $additionalUnitsFormattedInfo[$additionalUnitInfo['slot_id']] = $additionalUnitInfo;
277 | }
278 | return $additionalUnitsFormattedInfo;
279 | }
280 |
281 | /**
282 | * Get info about matches from the "matches" table
283 | * Use matches ids from slots table as additional filter
284 | * @return array
285 | */
286 | private function _getMatchesIdsFromMatches()
287 | {
288 | $_matchesIdsFromSlots = $this->_getMatchesIdsFromSlots();
289 | $db = Db::obtain();
290 | // basic matches data
291 | $matchesQuery = 'SELECT * FROM ' . Db::realTablename('matches') . '';
292 | $where = '';
293 | $data = array();
294 |
295 | if (null !== $this->getLeagueId()) {
296 | $where .= 'leagueid = ? AND ';
297 | array_push($data, $this->getLeagueId());
298 | }
299 |
300 | if (null !== $this->getTeamId()) {
301 | $where .= '(radiant_team_id = ? OR dire_team_id = ?) AND ';
302 | array_push($data, $this->getTeamId());
303 | array_push($data, $this->getTeamId());
304 | }
305 |
306 | if (count($_matchesIdsFromSlots)) {
307 | $where .= 'match_id IN (' . implode(',', $_matchesIdsFromSlots) . ') AND ';
308 | }
309 |
310 | if (null !== $this->getStartAtMatchId()) {
311 | $where .= 'match_id > ? AND ';
312 | array_push($data, $this->getStartAtMatchId());
313 | }
314 |
315 | if (trim($where) !== '') {
316 | $matchesQuery .= ' WHERE ' . substr($where, 0, strlen($where) - 4);
317 | }
318 |
319 | $matchesQuery .= ' ORDER BY start_time DESC';
320 |
321 | if (null !== $this->getMatchesRequested()) {
322 | $matchesQuery .= ' LIMIT ?';
323 | array_push($data, $this->getMatchesRequested());
324 | }
325 |
326 | $matchesInfo = $db->fetchArrayPDO($matchesQuery, $data);
327 | // no one match found
328 | if (count($matchesInfo) === 0) {
329 | return array();
330 | }
331 | return $matchesInfo;
332 | }
333 |
334 | /**
335 | * Get matches ids with provided hero_id or account_id (query for "slots" table)
336 | * @return array
337 | */
338 | private function _getMatchesIdsFromSlots()
339 | {
340 | $db = Db::obtain();
341 | $forSlots = 'SELECT match_id ' . Db::realTablename('FROM slots') . '';
342 | $whereForSlots = '';
343 | $dataForSlots = array();
344 |
345 | if (null !== $this->getHeroId()) {
346 | $whereForSlots .= 'hero_id = ? AND ';
347 | array_push($dataForSlots, $this->getHeroId());
348 | }
349 | if (null !== $this->getAccountId()) {
350 | $whereForSlots .= 'account_id = ? AND ';
351 | array_push($dataForSlots, $this->getAccountId());
352 | }
353 |
354 | if (trim($whereForSlots) !== '') {
355 | $forSlots .= ' WHERE ' . substr($whereForSlots, 0, strlen($whereForSlots) - 4);
356 | }
357 | $matchesIds = $db->fetchArrayPDO($forSlots, $dataForSlots);
358 | $ret = array();
359 | foreach ($matchesIds as $val) {
360 | array_push($ret, $val['match_id']);
361 | }
362 | return $ret;
363 | }
364 | }
365 |
--------------------------------------------------------------------------------
/includes/Mappers/MatchesMapperWeb.php:
--------------------------------------------------------------------------------
1 |
15 | * $matchesMapperWeb = new Dota2Api\Mappers\MatchesMapperWeb();
16 | * $matchesMapperWeb->setAccountId(93712171);
17 | * $matchesShortInfo = $matchesMapperWeb->load();
18 | * foreach ($matchesShortInfo as $key=>$matchShortInfo) {
19 | * $matchMapper = new MatchMapperWeb($key);
20 | * $match = $matchMapper->load();
21 | * if ($match) {
22 | * $mm = new Dota2Api\Mappers\MatchMapperDb();
23 | * $mm->save($match);
24 | * }
25 | * }
26 | *
27 | */
28 | class MatchesMapperWeb extends MatchesMapper
29 | {
30 | /**
31 | * Request url
32 | */
33 | const STEAM_MATCHES_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/';
34 |
35 | /**
36 | * The total number of matches available for retrieval
37 | * @var int
38 | */
39 | protected $_total_results;
40 |
41 | /**
42 | * The remaining results to be retrieved
43 | * @var int
44 | */
45 | protected $_results_remaining;
46 |
47 | /**
48 | * @return int
49 | */
50 | public function getTotalMatches()
51 | {
52 | return $this->_total_results;
53 | }
54 |
55 | /**
56 | * @return int
57 | */
58 | public function getResultsRemaining()
59 | {
60 | return $this->_results_remaining;
61 | }
62 |
63 | /**
64 | * @return array
65 | */
66 | private function _getDataArray()
67 | {
68 | $data = get_object_vars($this);
69 | $ret = array();
70 | foreach ($data as $key => $value) {
71 | if ($key !== '_total_results' && null !== $value && !is_array($value)) {
72 | $ret[ltrim($key, '_')] = $value;
73 | }
74 | }
75 | return $ret;
76 | }
77 |
78 | /**
79 | * @return array
80 | */
81 | public function load()
82 | {
83 | $request = new Request(self::STEAM_MATCHES_URL, $this->_getDataArray());
84 | $xml = $request->send();
85 | if (null === $xml) {
86 | return null;
87 | }
88 | $matches = array();
89 | if (isset($xml->matches)) {
90 | $this->_total_results = $xml->total_results;
91 | $this->_results_remaining = $xml->results_remaining;
92 | foreach ($xml->matches as /* @var $m_matches array */ $m_matches) {
93 | foreach ($m_matches as $m) {
94 | $match = new Match();
95 | $match->setArray((array)$m);
96 | foreach ($m->players as /* @var $players array */ $players) {
97 | foreach ($players as $player) {
98 | $slot = new Slot();
99 | $slot->setArray((array)$player);
100 | $match->addSlot($slot);
101 | }
102 | }
103 | $matches[$match->get('match_id')] = $match;
104 | }
105 | }
106 | }
107 | return $matches;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/includes/Mappers/PlayerMapperDb.php:
--------------------------------------------------------------------------------
1 | _steam_id = (string)$id;
23 | }
24 |
25 | public function getSteamid()
26 | {
27 | return $this->_steam_id;
28 | }
29 |
30 | /**
31 | * @param number|string $id or null
32 | * @return Player
33 | */
34 | public function load($id = null)
35 | {
36 | if (null !== $id) {
37 | $this->_steam_id = (string)$id;
38 | }
39 | $player = new Player();
40 |
41 | if (empty($this->_steam_id)) {
42 | return $player;
43 | }
44 |
45 | $db = Db::obtain();
46 | $result = $db->queryFirstPDO(
47 | 'SELECT * FROM ' . Db::realTablename('users') . ' WHERE steamid = ?',
48 | array($this->getSteamid())
49 | );
50 | $player->setArray($result);
51 | return $player;
52 | }
53 |
54 | /**
55 | * Determines whether the player should be inserted or updated in the db
56 | * @param Player $player
57 | */
58 | public function save(Player $player)
59 | {
60 | if (self::playerExists($player->get('steamid'))) {
61 | $this->update($player);
62 | } else {
63 | $this->insert($player);
64 | }
65 | }
66 |
67 | public function insert(Player $player)
68 | {
69 | Db::obtain()->insertPDO(Db::realTablename('users'), $this->prepareDataToSave($player));
70 | }
71 |
72 | public function update(Player $player)
73 | {
74 | Db::obtain()->updatePDO(Db::realTablename('users'), $this->prepareDataToSave($player), array('steamid' => $player->get('steamid')));
75 | }
76 |
77 | protected function prepareDataToSave(Player $player)
78 | {
79 | $account_id = $player->get('account_id');
80 | $data = $player->getDataArray();
81 | if (!$account_id) {
82 | $data = array('account_id' => Player::convertId($player->get('steamid')));
83 | $data = array_merge($data, $player->getDataArray());
84 | }
85 | return $data;
86 | }
87 |
88 | /**
89 | * @param string $id
90 | * @return bool
91 | */
92 | public static function playerExists($id = null)
93 | {
94 | if (null === $id) {
95 | return false;
96 | }
97 |
98 | $db = Db::obtain();
99 | $result = $db->queryFirstPDO(
100 | 'SELECT steamid FROM ' . Db::realTablename('users') . ' WHERE steamid = ?',
101 | array($id)
102 | );
103 | return $result['steamid'] === (string)$id;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/includes/Mappers/PlayersMapperDb.php:
--------------------------------------------------------------------------------
1 | _ids, true)) {
26 | array_push($this->_ids, $id);
27 | }
28 |
29 | return $this;
30 | }
31 |
32 | public function removeId($id)
33 | {
34 | $id = (string)$id;
35 | foreach ($this->_ids as $k => $v) {
36 | if ($v === $id) {
37 | unset($this->_ids[$k]);
38 | }
39 | }
40 | return $this;
41 | }
42 |
43 | /**
44 | * Removes all ids
45 | * @return PlayersMapperDb
46 | */
47 | public function removeIds()
48 | {
49 | $this->_ids = array();
50 | return $this;
51 | }
52 |
53 | /**
54 | * @return array
55 | */
56 | public function getIds()
57 | {
58 | return $this->_ids;
59 | }
60 |
61 | /**
62 | * @return string
63 | */
64 | public function getIdsString()
65 | {
66 | return implode(',', $this->getIds());
67 | }
68 |
69 | /**
70 | * Default Constructor
71 | */
72 | public function __construct()
73 | {
74 | }
75 |
76 | public function load()
77 | {
78 | $db = Db::obtain();
79 | $players = array();
80 | $ids = $this->getIdsString();
81 | if (count($this->_ids) === 0) {
82 | return array();
83 | }
84 | $result = $db->fetchArrayPDO(
85 | 'SELECT * FROM ' . Db::realTablename('users') . ' WHERE steamid IN (' . $ids . ')',
86 | array()
87 | );
88 | foreach ($result as $r) {
89 | $player = new Player();
90 | $player->setArray((array)$r);
91 | $players[$player->get('steamid')] = $player;
92 | }
93 |
94 | return $players;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/includes/Mappers/PlayersMapperWeb.php:
--------------------------------------------------------------------------------
1 |
13 | * $playersMapperWeb = new Dota2Api\Mappers\PlayersMapperWeb();
14 | * $playersInfo = $playersMapperWeb->addId('76561198067833250')->addId('76561198058587506')->load();
15 | * foreach($playersInfo as $playerInfo) {
16 | * echo $playerInfo->get('realname');
17 | * echo '
';
18 | * echo ''.$playerInfo->get('personaname').'\'s steam profile';
19 | * }
20 | * print_r($playersInfo);
21 | *
22 | */
23 | class PlayersMapperWeb
24 | {
25 | /**
26 | *
27 | */
28 | const PLAYER_STEAM_URL = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/';
29 | /**
30 | * @var array
31 | */
32 | private $_ids = array();
33 |
34 | /**
35 | * @param $id
36 | * @return PlayersMapperWeb
37 | */
38 | public function addId($id)
39 | {
40 | $id = (string)$id;
41 | if (!in_array($id, $this->_ids, true)) {
42 | array_push($this->_ids, $id);
43 | }
44 | return $this;
45 | }
46 |
47 | /**
48 | * @param $id
49 | * @return PlayersMapperWeb
50 | */
51 | public function removeId($id)
52 | {
53 | $id = (string)$id;
54 | foreach ($this->_ids as $k => $v) {
55 | if ($v === $id) {
56 | unset($this->_ids[$k]);
57 | }
58 | }
59 | return $this;
60 | }
61 |
62 | /**
63 | * @return PlayersMapperWeb
64 | */
65 | public function removeIds()
66 | {
67 | $this->_ids = array();
68 | return $this;
69 | }
70 |
71 | /**
72 | * @return array
73 | */
74 | public function getIds()
75 | {
76 | return $this->_ids;
77 | }
78 |
79 | /**
80 | * @return string
81 | */
82 | public function getIdsString()
83 | {
84 | return implode(',', $this->getIds());
85 | }
86 |
87 | /**
88 | * @return Player[]
89 | */
90 | public function load()
91 | {
92 | $request = new Request(self::PLAYER_STEAM_URL, array('steamids' => $this->getIdsString()));
93 | $playersInfo = $request->send();
94 | if (null === $playersInfo) {
95 | return null;
96 | }
97 | $players = array();
98 | foreach ($playersInfo->players[0] as $playerInfo) {
99 | $player = new Player();
100 | $player->setArray((array)$playerInfo);
101 | $player->set('account_id', Player::convertId($player->get('steamid')));
102 | $players[$player->get('steamid')] = $player;
103 | }
104 | return $players;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/includes/Mappers/TeamsMapper.php:
--------------------------------------------------------------------------------
1 | _teamId;
27 | }
28 |
29 | /**
30 | * @param int $teamId
31 | * @return TeamsMapper
32 | */
33 | public function setTeamId($teamId)
34 | {
35 | $teamId = (int)$teamId;
36 | if ($teamId > 0) {
37 | $this->_teamId = $teamId;
38 | }
39 | return $this;
40 | }
41 |
42 | /**
43 | * @return int
44 | */
45 | public function getTeamsRequested()
46 | {
47 | return $this->_teamsRequested;
48 | }
49 |
50 | /**
51 | * @param int $teamRequested
52 | * @return TeamsMapper
53 | */
54 | public function setTeamsRequested($teamRequested)
55 | {
56 | $teamRequested = (int)$teamRequested;
57 | if ($teamRequested >= 1) {
58 | $this->_teamsRequested = $teamRequested;
59 | }
60 | return $this;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/includes/Mappers/TeamsMapperDb.php:
--------------------------------------------------------------------------------
1 |
14 | * $teamsMapperDb = new Dota2Api\Mappers\TeamsMapperDb();
15 | * $teams = $teamsMapperDb->load();
16 | * foreach($teams as $team) {
17 | * echo $team->get('name');
18 | * }
19 | *
20 | */
21 | class TeamsMapperDb extends TeamsMapper
22 | {
23 | /**
24 | *
25 | */
26 | const TEAMS_STEAM_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v001/';
27 |
28 | /**
29 | * @return null|Team[]
30 | */
31 | public function load($tid)
32 | {
33 | $addSql = '';
34 | if (!is_null($tid)) {
35 | if (is_array($tid)) {
36 | $addSql = ' WHERE id IN (' . implode(',', $tid) . ')';
37 | } else {
38 | $addSql = ' WHERE id = ' . intval($tid);
39 | }
40 | }
41 | $db = Db::obtain();
42 | $result = $db->fetchArrayPDO('SELECT * FROM ' . Db::realTablename('teams') . ' ' . $addSql);
43 | if ($result === false) {
44 | return null;
45 | }
46 | $teams = array();
47 | foreach ($result as $row) {
48 | $tid = $row['id'];
49 | $team = new Team();
50 | $team->setArray($row);
51 | $team->set('team_id', $tid);
52 | $teams[$tid] = $team;
53 | }
54 | return $teams;
55 | }
56 |
57 | /**
58 | * @param Team $team
59 | * @return bool|integer
60 | */
61 | public function save($team)
62 | {
63 | $db = Db::obtain();
64 | return $db->insertPDO(Db::realTablename('teams'), array('id' => $team->get('team_id'), 'name' => $team->get('name')));
65 | }
66 |
67 | /**
68 | * @param integer[] $ids
69 | */
70 | public function delete($ids)
71 | {
72 | $db = Db::obtain();
73 | $ids = is_array($ids) ? $ids : array($ids);
74 | if (!count($ids)) {
75 | return;
76 | }
77 | $db->exec('DELETE FROM ' . Db::realTablename('teams') . ' WHERE id IN (' . implode(',', $ids) . ')');
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/includes/Mappers/TeamsMapperWeb.php:
--------------------------------------------------------------------------------
1 |
14 | * $teamsMapperWeb = new Dota2Api\Mappers\TeamsMapperWeb();
15 | * $teams = $teamsMapperWeb->setTeamId(2)->setTeamsRequested(2)->load();
16 | * foreach($teams as $team) {
17 | * echo $team->get('name');
18 | * echo $team->get('rating');
19 | * echo $team->get('country_code');
20 | * print_r($team->getAllLeaguesIds());
21 | * }
22 | *
23 | */
24 | class TeamsMapperWeb extends TeamsMapper
25 | {
26 | /**
27 | *
28 | */
29 | const TEAMS_STEAM_URL = 'https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v001/';
30 |
31 | /**
32 | * @return team[]
33 | */
34 | public function load()
35 | {
36 | $request = new Request(
37 | self::TEAMS_STEAM_URL,
38 | array(
39 | 'start_at_team_id' => $this->getTeamId(),
40 | 'teams_requested' => $this->getTeamsRequested()
41 | )
42 | );
43 | $teamsInfo = $request->send();
44 | if (null === $teamsInfo) {
45 | return null;
46 | }
47 | $teams = array();
48 | if (isset($teamsInfo->teams)) {
49 | $teamsInfo = (array)$teamsInfo->teams;
50 | $teamsInfo = $teamsInfo['team'];
51 | if (is_array($teamsInfo)) {
52 | foreach ($teamsInfo as $teamInfo) {
53 | $team = $this->getTeam($teamInfo);
54 | $teams[$team->get('team_id')] = $team;
55 | }
56 | return $teams;
57 | } else {
58 | $team = $this->getTeam($teamsInfo);
59 | $teams[$team->get('team_id')] = $team;
60 | return $teams;
61 | }
62 | }
63 | return null;
64 | }
65 |
66 | /**
67 | * Map one team
68 | * @param Object $t
69 | * @return Team team
70 | */
71 | protected function getTeam($t)
72 | {
73 | $teamInfo = (array)$t;
74 | $team = new Team();
75 | $fields = array_keys($teamInfo);
76 | foreach ($fields as $field) {
77 | // I hope, that API-response will be changed and players_ids, leagues_ids will become arrays
78 | if (preg_match('/^player_\d+_account_id$/', $field)) {
79 | $team->addPlayerId($teamInfo[$field]);
80 | continue;
81 | }
82 | if (preg_match('/^league_id_\d+$/', $field)) {
83 | $team->addLeagueId($teamInfo[$field]);
84 | continue;
85 | }
86 | $team->set($field, (string)$teamInfo[$field]);
87 | }
88 | return $team;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/includes/Mappers/UgcMapperWeb.php:
--------------------------------------------------------------------------------
1 |
12 | * $matchMapperWeb = new Dota2Api\Mappers\MatchMapperWeb(37633163);
13 | * $game = $matchMapperWeb->load();
14 | * $ugcMapperWeb = new Dota2Api\Mappers\UgcMapperWeb($game->get('radiant_logo'));
15 | * $logo_data = $ugcMapperWeb->load();
16 | * var_dump($logoData);
17 | * echo $logoData->url;
18 | *
19 | */
20 | class UgcMapperWeb
21 | {
22 |
23 | /**
24 | * Request url
25 | * @var string
26 | */
27 | const STEAM_UGC_URL = 'http://api.steampowered.com/ISteamRemoteStorage/GetUGCFileDetails/v1/';
28 |
29 | /**
30 | * @var int
31 | */
32 | private $_ugcid;
33 |
34 | public function __construct($ugcid = null)
35 | {
36 | $this->_ugcid = $ugcid;
37 | }
38 |
39 | /**
40 | * @param int $ugcid
41 | * @return object | null
42 | */
43 | public function load($ugcid = null)
44 | {
45 | if (null !== $ugcid) {
46 | $this->_ugcid = $ugcid;
47 | }
48 | $request = new Request(
49 | self::STEAM_UGC_URL,
50 | array('appid' => 570, 'ugcid' => $this->_ugcid)
51 | );
52 | return $request->send();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/includes/Models/Item.php:
--------------------------------------------------------------------------------
1 | _broadcasters[$broadcaster['account_id']] = $broadcaster;
97 | return $this;
98 | }
99 |
100 | /**
101 | * @param array $unassigned
102 | * @return LiveMatch
103 | */
104 | public function addUnassigned(array $unassigned)
105 | {
106 | $this->_unassigned[$unassigned['account_id']] = $unassigned;
107 | return $this;
108 | }
109 |
110 | /**
111 | * @param array $player_info
112 | * @return LiveMatch
113 | */
114 | public function addRadiantPlayer(array $player_info)
115 | {
116 | $this->_radiant_team[$player_info['account_id']] = $player_info;
117 | return $this;
118 | }
119 |
120 | /**
121 | * @param array $player_info
122 | * @return LiveMatch
123 | */
124 | public function addDirePlayer(array $player_info)
125 | {
126 | $this->_dire_team[$player_info['account_id']] = $player_info;
127 | return $this;
128 | }
129 |
130 | public function getDataArray()
131 | {
132 | $data = get_object_vars($this);
133 | $ret = array();
134 | foreach ($data as $key => $value) {
135 | if (!is_array($value) && !is_null($value)) {
136 | $ret[ltrim($key, '_')] = $value;
137 | }
138 | }
139 | return $ret;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/includes/Models/LiveSlot.php:
--------------------------------------------------------------------------------
1 | $value) {
37 | if (!is_array($value) && !is_null($value)) {
38 | $ret[ltrim($key, '_')] = $value;
39 | }
40 | }
41 | return $ret;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/includes/Models/Match.php:
--------------------------------------------------------------------------------
1 | _slots[$slot->get('player_slot')] = $slot;
197 | return $this;
198 | }
199 |
200 | /**
201 | * Get Slot by its index (0-4 for radiant, 128-132 for dire - as it is in the field player_slot)
202 | * @param int $index
203 | * @return Slot | null
204 | */
205 | public function getSlot($index)
206 | {
207 | $index = (int)$index;
208 | return array_key_exists($index, $this->_slots) ? $this->_slots[$index] : null;
209 | }
210 |
211 | /**
212 | * Return array of all Slots
213 | * @return Slot[]
214 | */
215 | public function getAllSlots()
216 | {
217 | return $this->_slots;
218 | }
219 |
220 | /**
221 | * Return array of all slots divided by team (5 for radiant, 5 for dire)
222 | * @return Slot[][]
223 | */
224 | public function getAllSlotsDivided()
225 | {
226 | $return = array('radiant' => array(), 'dire' => array());
227 | foreach ($this->_slots as $slot) {
228 | $team = 'radiant';
229 | if ($slot->get('player_slot') > 5) {
230 | $team = 'dire';
231 | }
232 | array_push($return[$team], $slot);
233 | }
234 | return $return;
235 | }
236 |
237 | /**
238 | * Return array of all picks and bans
239 | * @return array
240 | */
241 | public function getAllPicksBans()
242 | {
243 | return $this->_picks_bans;
244 | }
245 |
246 | /**
247 | * Return array of all picks and bans divided by team (and then by bans and picks)
248 | * @return array
249 | */
250 | public function getAllPicksBansDivided()
251 | {
252 | $return = array(
253 | 'radiant' => array(
254 | 'bans' => array(),
255 | 'picks' => array()
256 | ),
257 | 'dire' => array(
258 | 'bans' => array(),
259 | 'picks' => array()
260 | )
261 | );
262 | foreach ($this->_picks_bans as $pick_ban) {
263 | $team = 'radiant';
264 | $state = 'picks';
265 | if ($pick_ban['team']) {
266 | $team = 'dire';
267 | }
268 | if (!$pick_ban['is_pick']) {
269 | $state = 'bans';
270 | }
271 | array_push($return[$team][$state], $pick_ban);
272 | }
273 | return $return;
274 | }
275 |
276 | /**
277 | * Set whole array of picks, bans.
278 | * Used in mappers
279 | *
280 | * @param array $data
281 | * @return Match
282 | */
283 | public function setAllPickBans(array $data)
284 | {
285 | $this->_picks_bans = $data;
286 | return $this;
287 | }
288 |
289 | /**
290 | * @param array $data
291 | * @return Match
292 | */
293 | public function addPickBan($data)
294 | {
295 | array_push($this->_picks_bans, $data);
296 | return $this;
297 | }
298 |
299 | /**
300 | * Set list of slots for current match
301 | *
302 | * @param Slot[] $slots
303 | * @return Match
304 | */
305 | public function setAllSlots(array $slots)
306 | {
307 | $this->_slots = $slots;
308 | return $this;
309 | }
310 | }
311 |
--------------------------------------------------------------------------------
/includes/Models/Player.php:
--------------------------------------------------------------------------------
1 | _abilities_upgrade = $data;
161 | return $this;
162 | }
163 |
164 | /**
165 | * Return array of ability upgrades
166 | * @return array
167 | */
168 | public function getAbilitiesUpgrade()
169 | {
170 | return $this->_abilities_upgrade;
171 | }
172 |
173 | /**
174 | * Set array of additional unit items ids
175 | * @param array $data
176 | * @return slot
177 | */
178 | public function setAdditionalUnitItems(array $data)
179 | {
180 | $this->_additional_unit_items = $data;
181 | return $this;
182 | }
183 |
184 | /**
185 | * Get array of additional unit items ids
186 | * @return array
187 | */
188 | public function getAdditionalUnitItems()
189 | {
190 | return $this->_additional_unit_items;
191 | }
192 |
193 | /**
194 | * Remove item from additional unit items
195 | * @param int $item_id
196 | * @return slot
197 | */
198 | public function removeAdditionalUnitItem($item_id)
199 | {
200 | foreach ($this->_additional_unit_items as $k => $id) {
201 | if ($id === $item_id) {
202 | unset($this->_additional_unit_items[$k]);
203 | break;
204 | }
205 | }
206 | return $this;
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/includes/Models/StatObject.php:
--------------------------------------------------------------------------------
1 | $name : null;
22 | }
23 |
24 | /**
25 | * Set field value (if field isn't array)
26 | * @param string $name
27 | * @param mixed $value
28 | * @return StatObject
29 | */
30 | public function set($name, $value)
31 | {
32 | $name = '_' . (string)$name;
33 | if (property_exists($this, $name) && (!is_array($this->$name))) {
34 | $this->$name = $value;
35 | }
36 | return $this;
37 | }
38 |
39 | /**
40 | * Set not-array fields
41 | * @param array $data
42 | * @return StatObject
43 | */
44 | public function setArray(array $data)
45 | {
46 | foreach ($data as $name => $value) {
47 | $this->set($name, $value);
48 | }
49 | return $this;
50 | }
51 |
52 | /**
53 | * Return all not-array fields as assoc array
54 | * @return array
55 | */
56 | public function getDataArray()
57 | {
58 | $data = get_object_vars($this);
59 | $ret = array();
60 | foreach ($data as $key => $value) {
61 | if (!is_array($value)) {
62 | $ret[ltrim($key, '_')] = $value;
63 | }
64 | }
65 | return $ret;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/includes/Models/Team.php:
--------------------------------------------------------------------------------
1 | _players_ids;
84 | }
85 |
86 | /**
87 | * @param array $ids
88 | * @return team
89 | */
90 | public function setAllPlayersIds(array $ids)
91 | {
92 | foreach ($ids as $id) {
93 | $this->addPlayerId($id);
94 | }
95 | return $this;
96 | }
97 |
98 | /**
99 | * @param int $index
100 | * @return int|null
101 | */
102 | public function getPlayerId($index)
103 | {
104 | $index = (int)$index;
105 | return array_key_exists($index, $this->_players_ids) ? $this->_players_ids[$index] : null;
106 | }
107 |
108 | /**
109 | * @param int $player_id
110 | * @return team
111 | */
112 | public function addPlayerId($player_id)
113 | {
114 | $player_id = (int)$player_id;
115 | array_push($this->_players_ids, $player_id);
116 | return $this;
117 | }
118 |
119 | /**
120 | * @return array
121 | */
122 | public function getAllLeaguesIds()
123 | {
124 | return $this->_leagues_ids;
125 | }
126 |
127 | /**
128 | * @param array $leagues
129 | * @return team
130 | */
131 | public function setAllLeaguesIds(array $leagues)
132 | {
133 | foreach ($leagues as $id) {
134 | $this->addLeagueId($id);
135 | }
136 | return $this;
137 | }
138 |
139 | /**
140 | * @param int $index
141 | * @return int|null
142 | */
143 | public function getLeaguesId($index)
144 | {
145 | $index = (int)$index;
146 | return array_key_exists($index, $this->_leagues_ids) ? $this->_leagues_ids[$index] : null;
147 | }
148 |
149 | /**
150 | * @param int $league_id
151 | * @return team
152 | */
153 | public function addLeagueId($league_id)
154 | {
155 | $league_id = (int)$league_id;
156 | array_push($this->_leagues_ids, $league_id);
157 | return $this;
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/includes/Utils/Map.php:
--------------------------------------------------------------------------------
1 |
12 | * $matchMapperWeb = new Dota2Api\Utils\MatchMapperWeb(123456789);
13 | * $match = $matchMapperWeb->load();
14 | * $map = new map($match->get('tower_status_radiant'), $match->get('tower_status_dire'), $match->get('barracks_status_radiant'), $match->get('barracks_status_dire'));
15 | *
16 | * $canvas = $map->getImage();
17 | *
18 | * header('Content-Type: image/jpg');
19 | * imagejpeg($canvas);
20 | * imagedestroy($canvas);
21 | *
22 | */
23 | class Map
24 | {
25 |
26 | private static $radiantTowersPositions = array(
27 | array(130, 795), // t4 top
28 | array(150, 810), // t4 bot
29 |
30 | array(250, 870), // t3 bot
31 | array(480, 870), // t2 bot
32 | array(820, 870), // t1 bot
33 |
34 | array(205, 745), // t3 mid
35 | array(270, 660), // t2 mid
36 | array(410, 580), // t1 mid
37 |
38 | array(80, 700), // t3 top
39 | array(115, 520), // t2 top
40 | array(115, 383) // t1 top
41 | );
42 |
43 | private static $radiantBarracksPositions = array(
44 | array(220, 890), // BOT RANGED
45 | array(220, 850), // BOT MELEE
46 | array(165, 760), // MID RANGED
47 | array(195, 780), // MID MELEE
48 | array(60, 730), // TOP RANGED
49 | array(100, 730) // TOP MELEE
50 | );
51 |
52 | private static $direTowersPositions = array(
53 | array(830, 180), // t4 top
54 | array(860, 205), // t4 bot
55 |
56 | array(895, 310), // t3 bot
57 | array(910, 490), // t2 bot
58 | array(875, 597), // t1 bot
59 |
60 | array(760, 265), // t3 mid
61 | array(640, 350), // t2 mid
62 | array(560, 470), // t1 mid
63 |
64 | array(725, 130), // t3 top
65 | array(450, 100), // t2 top
66 | array(180, 100) // t1 top
67 | );
68 |
69 | private static $direBarracksPositions = array(
70 | array(870, 285), // BOT RANGED
71 | array(920, 285), // BOT MELEE
72 | array(775, 235), // MID RANGED
73 | array(800, 255), // MID MELEE
74 | array(750, 110), // TOP RANGED
75 | array(750, 150) // TOP MELEE
76 | );
77 |
78 | /**
79 | * @var string
80 | */
81 | private $_folder;
82 | /**
83 | * @var resource
84 | */
85 | private $_canvas;
86 | /**
87 | * @var string
88 | */
89 | private $_towerStatusRadiant;
90 | /**
91 | * @var string
92 | */
93 | private $_towerStatusDire;
94 | /**
95 | * @var string
96 | */
97 | private $_barracksStatusRadiant;
98 | /**
99 | * @var string
100 | */
101 | private $_barracksStatusDire;
102 |
103 | public function __construct(
104 | $towerStatusRadiant,
105 | $towerStatusDire,
106 | $barracksStatusRadiant,
107 | $barracksStatusDire
108 | ) {
109 | $this->_towerStatusRadiant = sprintf('%011b', $towerStatusRadiant);
110 | $this->_towerStatusDire = sprintf('%011b', $towerStatusDire);
111 | $this->_barracksStatusRadiant = substr(sprintf('%011b', $barracksStatusRadiant), 5);
112 | $this->_barracksStatusDire = substr(sprintf('%011b', $barracksStatusDire), 5);
113 | $this->_folder = 'images' . DIRECTORY_SEPARATOR . 'map' . DIRECTORY_SEPARATOR;
114 | }
115 |
116 | public function getImage()
117 | {
118 | $path = __DIR__ . '/../../' . $this->_folder;
119 | $this->_canvas = imagecreatefromjpeg($path . 'dota_map.jpg');
120 | if ($this->_canvas === false) {
121 | return null;
122 | }
123 | $towerDire = $this->_loadPng($path . 'tower_dire.png');
124 | $towerRadiant = $this->_loadPng($path . 'tower_radiant.png');
125 | $barracksDire = $this->_loadPng($path . 'racks_dire.png');
126 | $barracksRadiant = $this->_loadPng($path . 'racks_radiant.png');
127 | // Radiant
128 | for ($i = 0; $i < count(self::$radiantTowersPositions); $i++) {
129 | if ($this->_towerStatusRadiant[$i]) {
130 | $this->_drawIcon($towerRadiant, self::$radiantTowersPositions[$i]);
131 | }
132 | }
133 | for ($i = 0; $i < count(self::$radiantBarracksPositions); $i++) {
134 | if ($this->_barracksStatusRadiant[$i]) {
135 | $this->_drawIcon($barracksRadiant, self::$radiantBarracksPositions[$i]);
136 | }
137 | }
138 | // Dire
139 | for ($i = 0; $i < count(self::$direTowersPositions); $i++) {
140 | if ($this->_towerStatusDire[$i]) {
141 | $this->_drawIcon($towerDire, self::$direTowersPositions[$i]);
142 | }
143 | }
144 | for ($i = 0; $i < count(self::$direBarracksPositions); $i++) {
145 | if ($this->_barracksStatusDire[$i]) {
146 | $this->_drawIcon($barracksDire, self::$direBarracksPositions[$i]);
147 | }
148 | }
149 | return $this->_canvas;
150 | }
151 |
152 | /**
153 | * Put image to the canvas
154 | *
155 | * @param resource $icon image
156 | * @param array $coordinates where put it
157 | * @return null
158 | */
159 | private function _drawIcon($icon, $coordinates)
160 | {
161 | imagecopyresampled($this->_canvas, $icon, $coordinates[0], $coordinates[1], 0, 0, 32, 32, 32, 32);
162 | }
163 |
164 | /**
165 | * Load png image (like tower or barrack icon)
166 | *
167 | * @param string $file
168 | * @return null|resource
169 | */
170 | private function _loadPng($file)
171 | {
172 | $pic = imagecreatefrompng($file);
173 | if ($pic === false) {
174 | return null;
175 | }
176 | // make sure the images can be properly drawn together
177 | imagealphablending($pic, false);
178 | imagesavealpha($pic, true);
179 | return $pic;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/includes/Utils/Request.php:
--------------------------------------------------------------------------------
1 | _url;
37 | }
38 |
39 | /**
40 | * Set url
41 | * @param string $url
42 | * @return request
43 | */
44 | public function setUrl($url)
45 | {
46 | $this->_url = (string)$url;
47 | return $this;
48 | }
49 |
50 | /**
51 | * Get all request parameters
52 | * @return array
53 | */
54 | public function getAllParams()
55 | {
56 | return $this->_params;
57 | }
58 |
59 | /**
60 | * Get request parameter by its name
61 | * @param string $name
62 | * @return string | null
63 | */
64 | public function getParameter($name)
65 | {
66 | $name = (string)$name;
67 | return array_key_exists($name, $this->_params) ? $this->_params[$name] : null;
68 | }
69 |
70 | /**
71 | * Set parameter by its name and value
72 | * @param string $name
73 | * @param string $value
74 | * @return request
75 | */
76 | public function setParameter($name, $value)
77 | {
78 | $name = (string)$name;
79 | $value = (string)$value;
80 | $this->_params[$name] = $value;
81 | return $this;
82 | }
83 |
84 | /**
85 | * Set array of parameters. New values will rewrite older
86 | * @param array $params
87 | * @return request
88 | */
89 | public function setParameters(array $params)
90 | {
91 | $this->_params = $params + $this->_params;
92 | return $this;
93 | }
94 |
95 | /**
96 | * @param string $url
97 | * @param array $params
98 | */
99 | public function __construct($url, array $params)
100 | {
101 | $this->_url = $url;
102 | $this->_params = $params;
103 | }
104 |
105 | /**
106 | * Send request to Valve's servers
107 | * @access public
108 | * @return SimpleXMLElement | null
109 | */
110 | public function send()
111 | {
112 | $ch = curl_init();
113 | $url = $this->_url;
114 | $d = '';
115 | $this->_params['format'] = 'xml';
116 | $this->_params['key'] = self::$apiKey;
117 | // The language to retrieve results in (see http://en.wikipedia.org/wiki/ISO_639-1 for the language codes (first
118 | // two characters) and http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for the country codes (last two characters))
119 | $this->_params['language'] = 'en_us';
120 | foreach ($this->_params as $key => $value) {
121 | $d .= $key . '=' . $value . '&';
122 | }
123 | $d = rtrim($d, '&');
124 | $url .= '?' . $d;
125 |
126 | curl_setopt($ch, CURLOPT_URL, $url);
127 | curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
128 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
129 | // Ignore SSL warnings and questions
130 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
131 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
132 |
133 | $r = curl_exec($ch);
134 | curl_close($ch);
135 | libxml_use_internal_errors(true);
136 | try {
137 | $r = new SimpleXMLElement($r);
138 | } catch (Exception $e) {
139 | return null;
140 | }
141 | return $r;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 | ./tests
15 |
16 |
17 |
18 | ./includes
19 |
20 | ./includes/Utils/Db.php
21 | ./includes/Utils/Map.php
22 | ./includes/Mappers/LeagueMapper.php
23 | ./vendor
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/tests/includes/Data/AbilitiesTest.php:
--------------------------------------------------------------------------------
1 | abilities = new Abilities();
16 | $this->abilities->parse();
17 | }
18 |
19 | public function testGetDataById()
20 | {
21 | $data = $this->abilities->getDataById(5172);
22 | $this->assertEquals(5172, $data['id']);
23 | $this->assertEquals('beastmaster_inner_beast', $data['name']);
24 | }
25 |
26 | public function testGetImgUrlById()
27 | {
28 | $url = $this->abilities->getImgUrlById(5172);
29 | $this->assertEquals('http://media.steampowered.com/apps/dota2/images/abilities/beastmaster_inner_beast_lg.png',
30 | $url);
31 |
32 | $url = $this->abilities->getImgUrlById(5002);
33 | $this->assertEquals('images/stats.png', $url);
34 | }
35 |
36 | public function testParse()
37 | {
38 | $abilities = new Abilities();
39 | $abilities->parse('6.86');
40 | $url = $abilities->getImgUrlById(5341);
41 | $this->assertEquals('http://media.steampowered.com/apps/dota2/images/abilities/doom_bringer_infernal_blade_lg.png',
42 | $url);
43 | }
44 | }
--------------------------------------------------------------------------------
/tests/includes/Data/ItemsTest.php:
--------------------------------------------------------------------------------
1 | items = new Items();
16 | $this->items->parse();
17 | }
18 |
19 | public function testGetImgUrlById()
20 | {
21 | $url = $this->items->getImgUrlById(220, true, true);
22 | $this->assertContains('mystery_toss', $url);
23 |
24 | $url = $this->items->getImgUrlById(220, true, false);
25 | $this->assertContains('travel_boots_2', $url);
26 | }
27 | }
--------------------------------------------------------------------------------
/tests/includes/Mappers/HeroesMapperTest.php:
--------------------------------------------------------------------------------
1 | load();
11 | $this->assertGreaterThan(100, count($heroes));
12 | foreach ($heroes as $id => $hero) {
13 | $this->assertTrue(is_string($hero['name']) && '' !== $hero['name']);
14 | $this->assertTrue(is_string($hero['localized_name']) && '' !== $hero['localized_name']);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/ItemsMapperDbTest.php:
--------------------------------------------------------------------------------
1 | load();
14 | foreach ($items as $item) {
15 | $this->assertTrue($item instanceof Item);
16 | $this->assertTrue('' !== $item->get('localized_name'));
17 | $this->assertTrue('' !== $item->get('name'));
18 | }
19 |
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/tests/includes/Mappers/ItemsMapperWebTest.php:
--------------------------------------------------------------------------------
1 | load();
11 | $this->assertGreaterThan(200, count($items));
12 | foreach ($items as $id => $item) {
13 | $this->assertTrue(is_string($item->get('name')) && '' !== $item->get('name'));
14 | $this->assertTrue(is_string($item->get('localized_name')) && '' !== $item->get('localized_name'));
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/LeagueMapperTest.php:
--------------------------------------------------------------------------------
1 | load();
11 | if (count($matches) === 0) {
12 | $this->markTestSkipped('There are no matches currently');
13 | } else {
14 | $match = array_pop($matches);
15 | $slots = $match->getAllSlots();
16 | if (count($slots) > 0) {
17 | $this->assertCount(10, $slots);
18 | $this->assertInstanceOf('Dota2Api\Models\LiveMatch', $match);
19 | $slot_ids = array();
20 | $needed_slot_ids = array(0, 1, 2, 3, 4, 128, 129, 130, 131, 132);
21 | foreach ($slots as $slot) {
22 | $this->assertInstanceOf('Dota2Api\Models\LiveSlot', $slot);
23 | array_push($slot_ids, $slot->get('player_slot'));
24 | }
25 | sort($slot_ids);
26 | $this->assertArraySubset($slot_ids, $needed_slot_ids);
27 | $this->assertArraySubset($needed_slot_ids, $slot_ids);
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/LeaguePrizePoolMapperDbTest.php:
--------------------------------------------------------------------------------
1 | exec('DELETE FROM ' . Db::realTablename('league_prize_pools') . '');
18 | $leaguesMapperWeb = new LeaguesMapperWeb();
19 | $leagues = $leaguesMapperWeb->load();
20 | $leaguesMapperDb = new LeaguesMapperDb();
21 | $leaguesMapperDb->save($leagues[600]);
22 | }
23 |
24 | public static function tearDownAfterClass()
25 | {
26 | Db::obtain()->exec('DELETE FROM league_prize_pools');
27 | Db::obtain()->exec('DELETE FROM leagues');
28 | }
29 |
30 | public function testSaveLoad()
31 | {
32 | $leaguePrizePoolMapperWeb = new LeaguePrizePoolMapperWeb();
33 | $leaguePrizePoolMapperWeb->setLeagueId($this->leagueId);
34 | $prizePoolInfo = $leaguePrizePoolMapperWeb->load();
35 |
36 | $leaguePrizePoolMapperDb = new LeaguePrizePoolMapperDb();
37 | $leaguePrizePoolMapperDb->setLeagueId($this->leagueId)->setPrizePool($prizePoolInfo['prize_pool']);
38 | $leaguePrizePoolMapperDb->save();
39 |
40 | $rows = $leaguePrizePoolMapperDb->load();
41 | $this->assertEquals(1, count($rows));
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/LeaguePrizePoolMapperWebTest.php:
--------------------------------------------------------------------------------
1 | setLeagueId(600);
11 | $prizePoolInfo = $leaguePrizePoolMapperWeb->load();
12 | $this->assertTrue((int)$prizePoolInfo['prize_pool'] >= 0);
13 | $this->assertEquals('600', (string)$prizePoolInfo['league_id']);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/LeaguesMapperDbTest.php:
--------------------------------------------------------------------------------
1 | load();
14 | $mapperDb->save($leagues[600]);
15 | $leaguesFromDb = $mapperDb->load();
16 | $this->assertEquals(1, count($leaguesFromDb));
17 | $mapperDb->save($leagues[65000]);
18 | $leaguesFromDb = $mapperDb->load();
19 | $this->assertEquals(2, count($leaguesFromDb));
20 | $mapperDb->save($leagues[4664]);
21 | $leaguesFromDb = $mapperDb->load(600);
22 | $this->assertEquals(1, count($leaguesFromDb));
23 | $leaguesFromDb = $mapperDb->load(array(600, 65000));
24 | $this->assertEquals(2, count($leaguesFromDb));
25 | $leaguesFromDb = $mapperDb->load(array(600, 4664 ,65000));
26 | $this->assertEquals(3, count($leaguesFromDb));
27 | }
28 |
29 | protected function tearDown()
30 | {
31 | Db::obtain()->exec('DELETE FROM league_prize_pools');
32 | Db::obtain()->exec('DELETE FROM leagues');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/LeaguesMapperWebTest.php:
--------------------------------------------------------------------------------
1 | load();
11 | $this->assertInternalType('array', $leagues);
12 | $this->assertGreaterThan(0, count($leagues));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/MatchMapperDbTest.php:
--------------------------------------------------------------------------------
1 | load();
19 | $leaguesMapperDb = new LeaguesMapperDb();
20 | $leaguesMapperDb->save($leagues[4395]);
21 | }
22 |
23 | public static function tearDownBeforeClass()
24 | {
25 | $db = Db::obtain();
26 | $db->exec('DELETE FROM picks_bans');
27 | $db->exec('DELETE FROM ability_upgrades');
28 | $db->exec('DELETE FROM additional_units');
29 | $db->exec('DELETE FROM slots');
30 | $db->exec('DELETE FROM matches');
31 | $db->exec('DELETE FROM leagues');
32 | }
33 |
34 | public function testLoad()
35 | {
36 |
37 | $expectedMatchInfo = array(
38 | 'game_mode' => '2',
39 | 'radiant_win' => '1',
40 | 'first_blood_time' => '77',
41 | 'leagueid' => '4395',
42 | 'duration' => '1301'
43 | );
44 |
45 | $mapperWeb = new MatchMapperWeb($this->matchId);
46 | $match = $mapperWeb->load();
47 | while (!$match) {
48 | $match = $mapperWeb->load();
49 | }
50 | $mapperDb = new MatchMapperDb();
51 | $mapperDb->save($match);
52 | $match = $mapperDb->load($this->matchId);
53 |
54 | $this->assertInstanceOf('Dota2Api\Models\Match', $match);
55 | foreach ($expectedMatchInfo as $k => $v) {
56 | $this->assertEquals($v, $match->get($k));
57 | }
58 | $expectedSlotsInfo = array(
59 | 0 => array(
60 | 'ability_upgrades' => 15,
61 | 'level' => 15
62 | ),
63 | 1 => array(
64 | 'ability_upgrades' => 11,
65 | 'level' => 11
66 | ),
67 | 2 => array(
68 | 'ability_upgrades' => 8,
69 | 'level' => 8
70 | ),
71 | 3 => array(
72 | 'ability_upgrades' => 11,
73 | 'level' => 11
74 | ),
75 | 4 => array(
76 | 'ability_upgrades' => 14,
77 | 'level' => 14
78 | ),
79 | 128 => array(
80 | 'ability_upgrades' => 9,
81 | 'level' => 9
82 | ),
83 | 129 => array(
84 | 'ability_upgrades' => 10,
85 | 'level' => 10
86 | ),
87 | 130 => array(
88 | 'ability_upgrades' => 13,
89 | 'level' => 13
90 | ),
91 | 131 => array(
92 | 'ability_upgrades' => 8,
93 | 'level' => 10
94 | ),
95 | 132 => array(
96 | 'ability_upgrades' => 13,
97 | 'level' => 13
98 | )
99 | );
100 | $slots = $match->getAllSlots();
101 | foreach ($expectedSlotsInfo as $slotId => $slot) {
102 | $this->assertTrue($slots[$slotId]->get('account_id') !== Player::ANONYMOUS);
103 | $this->assertEquals($slot['level'], (int)$slots[$slotId]->get('level'));
104 | $this->assertEquals($slot['ability_upgrades'], count($slots[$slotId]->getAbilitiesUpgrade()));
105 | }
106 |
107 | $picksBans = $match->getAllPicksBans();
108 | $this->assertInternalType('array', $picksBans);
109 | $this->assertGreaterThan(0, count($picksBans));
110 | $fl = true;
111 | foreach ($picksBans as $r) {
112 | if (!in_array($r['is_pick'], array('1', '0'), true)) {
113 | $fl = false;
114 | }
115 | }
116 | $this->assertTrue($fl);
117 |
118 | }
119 |
120 | public function testUpdate()
121 | {
122 | $mapperDb = new MatchMapperDb();
123 | $match = $mapperDb->load($this->matchId);
124 | $match->set('first_blood_time', 0);
125 | $slots = $match->getAllSlots();
126 | $slots[0]->set('hero_id', '1');
127 | $match->setAllSlots($slots);
128 | $mapperDb->update($match, false);
129 |
130 | $match = $mapperDb->load($this->matchId);
131 |
132 | $this->assertEquals(0, $match->get('first_blood_time'));
133 | $slots = $match->getAllSlots();
134 | $this->assertEquals(1, $slots[0]->get('hero_id'));
135 |
136 | }
137 |
138 | public function testDelete()
139 | {
140 | $mapperDb = new MatchMapperDb();
141 | $match = $mapperDb->load($this->matchId);
142 | $mapperDb->save($match);
143 |
144 | $mapperDb->delete($match->get('match_id'));
145 |
146 | $match = $mapperDb->load($this->matchId);
147 | $this->assertNull($match->get('match_id'));
148 | }
149 |
150 | }
151 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/MatchMapperWebTest.php:
--------------------------------------------------------------------------------
1 | '2',
13 | 'radiant_win' => '1',
14 | 'first_blood_time' => '77',
15 | 'leagueid' => '4395',
16 | 'duration' => '1301'
17 | );
18 | $mapper = new MatchMapperWeb($matchId);
19 | $match = $mapper->load();
20 | while (!$match) {
21 | $match = $mapper->load();
22 | }
23 | $this->assertInstanceOf('Dota2Api\Models\Match', $match);
24 | foreach ($expectedMatchInfo as $k => $v) {
25 | $this->assertEquals($match->get($k), $v);
26 | }
27 |
28 | $expectedSlotsInfo = array(
29 | 0 => array(
30 | 'ability_upgrades' => 15,
31 | 'level' => 15
32 | ),
33 | 1 => array(
34 | 'ability_upgrades' => 11,
35 | 'level' => 11
36 | ),
37 | 2 => array(
38 | 'ability_upgrades' => 8,
39 | 'level' => 8
40 | ),
41 | 3 => array(
42 | 'ability_upgrades' => 11,
43 | 'level' => 11
44 | ),
45 | 4 => array(
46 | 'ability_upgrades' => 14,
47 | 'level' => 14
48 | ),
49 | 128 => array(
50 | 'ability_upgrades' => 9,
51 | 'level' => 9
52 | ),
53 | 129 => array(
54 | 'ability_upgrades' => 10,
55 | 'level' => 10
56 | ),
57 | 130 => array(
58 | 'ability_upgrades' => 13,
59 | 'level' => 13
60 | ),
61 | 131 => array(
62 | 'ability_upgrades' => 8,
63 | 'level' => 10
64 | ),
65 | 132 => array(
66 | 'ability_upgrades' => 13,
67 | 'level' => 13
68 | )
69 | );
70 | $slots = $match->getAllSlots();
71 | foreach ($expectedSlotsInfo as $slotId => $slot) {
72 | $this->assertTrue($slots[$slotId]->get('account_id') !== Player::ANONYMOUS);
73 | $this->assertEquals($slot['level'], (int)$slots[$slotId]->get('level'));
74 | $this->assertEquals($slot['ability_upgrades'], count($slots[$slotId]->getAbilitiesUpgrade()));
75 | }
76 |
77 | $picksBans = $match->getAllPicksBans();
78 | $this->assertInternalType('array', $picksBans);
79 | $this->assertGreaterThan(0, count($picksBans));
80 | $fl = true;
81 | foreach ($picksBans as $r) {
82 | if (!in_array($r['is_pick'], array('1', '0'), true)) {
83 | $fl = false;
84 | }
85 | }
86 | $this->assertTrue($fl);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/MatchesMapperDbTest.php:
--------------------------------------------------------------------------------
1 | exec('DELETE FROM picks_bans');
20 | $db->exec('DELETE FROM ability_upgrades');
21 | $db->exec('DELETE FROM additional_units');
22 | $db->exec('DELETE FROM slots');
23 | $db->exec('DELETE FROM matches');
24 | }
25 |
26 | public function setUp()
27 | {
28 |
29 | $leaguesMapperWeb = new LeaguesMapperWeb();
30 | $leagues = $leaguesMapperWeb->load();
31 | $leaguesMapperDb = new LeaguesMapperDb();
32 | $leaguesMapperDb->save($leagues[$this->leagueId]);
33 |
34 | $matchMapperWeb = new MatchMapperWeb($this->matchId);
35 | $match = $matchMapperWeb->load();
36 | while (!$match) {
37 | $match = $matchMapperWeb->load();
38 | }
39 | $matchMapperDb = new MatchMapperDb();
40 | $matchMapperDb->save($match);
41 | }
42 |
43 | public function testLoad()
44 | {
45 |
46 | $matchesMapperDb = new MatchesMapperDb();
47 | $matchesMapperDb->setLeagueId($this->leagueId)->setMatchesRequested(1);
48 | $matches = $matchesMapperDb->load();
49 | /* @var $match \Dota2Api\Models\Match */
50 | $match = array_pop($matches);
51 |
52 | $this->assertEquals($match->get('match_id'), $this->matchId);
53 | $this->assertEquals($match->get('game_mode'), 2);
54 | $this->assertEquals($match->get('tower_status_radiant'), 1846);
55 | $this->assertEquals($match->get('tower_status_dire'), 1572);
56 | $this->assertEquals($match->get('radiant_win'), 1);
57 | $this->assertEquals($match->get('duration'), 2348);
58 | $this->assertEquals($match->get('first_blood_time'), 538);
59 | $this->assertStringStartsWith('2015-08-09', $match->get('start_time'));
60 | $this->assertEquals($match->get('barracks_status_radiant'), 63);
61 | $this->assertEquals($match->get('barracks_status_dire'), 15);
62 | $this->assertEquals($match->get('lobby_type'), 1);
63 | $this->assertEquals($match->get('human_players'), 10);
64 | $this->assertEquals($match->get('leagueid'), $this->leagueId);
65 | $this->assertEquals($match->get('cluster'), 111);
66 | $this->assertEquals($match->get('radiant_name'), 'Evil Geniuses');
67 | $this->assertEquals($match->get('radiant_team_id'), 39);
68 | $this->assertEquals($match->get('dire_name'), 'CDEC Gaming');
69 | $this->assertEquals($match->get('dire_team_id'), 1520578);
70 |
71 | $slots = $match->getAllSlots();
72 |
73 | $this->assertEquals(count($slots), 10);
74 | $slot = $slots[0];
75 | $this->assertEquals($slot->get('match_id'), $this->matchId);
76 | $this->assertEquals($slot->get('account_id'), 86727555);
77 | $this->assertEquals($slot->get('hero_id'), 68);
78 | $this->assertEquals($slot->get('player_slot'), 0);
79 | $this->assertEquals($slot->get('item_0'), 214);
80 | $this->assertEquals($slot->get('item_1'), 254);
81 | $this->assertEquals($slot->get('item_2'), 92);
82 | $this->assertEquals($slot->get('item_3'), 23);
83 | $this->assertEquals($slot->get('item_4'), 0);
84 | $this->assertEquals($slot->get('item_5'), 36);
85 | $this->assertEquals($slot->get('kills'), 2);
86 | $this->assertEquals($slot->get('deaths'), 2);
87 | $this->assertEquals($slot->get('assists'), 13);
88 | $this->assertEquals($slot->get('leaver_status'), 0);
89 | $this->assertEquals($slot->get('gold'), 2428);
90 | $this->assertEquals($slot->get('last_hits'), 49);
91 | $this->assertEquals($slot->get('denies'), 3);
92 | $this->assertEquals($slot->get('gold_per_min'), 264);
93 | $this->assertEquals($slot->get('xp_per_min'), 337);
94 | $this->assertEquals($slot->get('gold_spent'), 8185);
95 | $this->assertEquals($slot->get('hero_damage'), 4527);
96 | $this->assertEquals($slot->get('tower_damage'), 501);
97 | $this->assertEquals($slot->get('hero_healing'), 569);
98 | $this->assertEquals($slot->get('level'), 15);
99 |
100 | $getAllPicksBans = $match->getAllPicksBans();
101 |
102 | $this->assertEquals(count($getAllPicksBans), 20);
103 |
104 | }
105 |
106 | public function testDelete()
107 | {
108 |
109 | $additionalMatchId = 1697737102;
110 | $matchMapperWeb = new MatchMapperWeb($additionalMatchId);
111 | $match = $matchMapperWeb->load();
112 | while(!$match) {
113 | $match = $matchMapperWeb->load();
114 | }
115 | $matchMapperDb = new MatchMapperDb();
116 | $matchMapperDb->save($match);
117 |
118 | $matchesMapperDb = new MatchesMapperDb();
119 | $matchesMapperDb->delete(array($additionalMatchId, $this->matchId));
120 |
121 | $db = Db::obtain();
122 | $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM matches')));
123 | $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM slots')));
124 | $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM additional_units')));
125 | $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM ability_upgrades')));
126 | $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM picks_bans')));
127 |
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/MatchesMapperWebTest.php:
--------------------------------------------------------------------------------
1 | setLeagueId($leagueid);
13 | $matches = $mapper->load();
14 | $this->assertEquals((int)$mapper->getTotalMatches(), $expectedMatchesCount);
15 | $this->assertContainsOnlyInstancesOf('Dota2Api\Models\Match', $matches);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/PlayerMapperDbTest.php:
--------------------------------------------------------------------------------
1 | exec('DELETE FROM users');
22 | }
23 |
24 | public static function tearDownAfterClass()
25 | {
26 | $db = Db::obtain();
27 | $db->exec('DELETE FROM users');
28 | }
29 |
30 | public function setUp()
31 | {
32 | $mapperWeb = new PlayersMapperWeb();
33 | $mapperWeb->addId(Player::convertId($this->playerId));
34 | $d = $mapperWeb->load();
35 | $this->player = array_pop($d);
36 | }
37 |
38 | public function testSave()
39 | {
40 | $mapperDb = new PlayerMapperDb();
41 | $mapperDb->save($this->player);
42 | $db = Db::obtain();
43 | $r = $db->fetchArrayPDO('SELECT * FROM users');
44 | $this->assertEquals(1, count($r));
45 | }
46 |
47 | public function testUpdate()
48 | {
49 | $this->player->set('personaname', 'test');
50 | $mapperDb = new PlayerMapperDb();
51 | $mapperDb->save($this->player);
52 | $db = Db::obtain();
53 | $r = $db->fetchArrayPDO('SELECT * FROM users');
54 | $player = array_pop($r);
55 | $this->assertEquals('test', $player['personaname']);
56 | }
57 |
58 | public function testLoad()
59 | {
60 | $mapperDb = new PlayerMapperDb();
61 | $player = $mapperDb->load(Player::convertId((string)$this->playerId));
62 | $this->assertEquals('test', $player->get('personaname'));
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/tests/includes/Mappers/PlayersMapperDbTest.php:
--------------------------------------------------------------------------------
1 | load();
22 | $leaguesMapperDb = new LeaguesMapperDb();
23 | $leaguesMapperDb->save($leagues[2733]);
24 |
25 | $matchMapperWeb = new MatchMapperWeb(1697818230);
26 | $match = $matchMapperWeb->load();
27 | while (!$match) {
28 | $match = $matchMapperWeb->load();
29 | }
30 | $matchMapperDb = new MatchMapperDb();
31 | $matchMapperDb->save($match);
32 | }
33 |
34 | public static function tearDownBeforeClass()
35 | {
36 | $db = Db::obtain();
37 | $db->exec('DELETE FROM picks_bans');
38 | $db->exec('DELETE FROM ability_upgrades');
39 | $db->exec('DELETE FROM additional_units');
40 | $db->exec('DELETE FROM slots');
41 | $db->exec('DELETE FROM matches');
42 | $db->exec('DELETE FROM leagues');
43 | }
44 |
45 | public function setUp()
46 | {
47 | $this->mapper = new PlayersMapperDb();
48 | }
49 |
50 | public function testAddId()
51 | {
52 | $this->assertEquals(array(), $this->mapper->getIds());
53 | $this->mapper->addId(1);
54 | $this->assertEquals(array(1), $this->mapper->getIds());
55 | }
56 |
57 | public function testRemoveId()
58 | {
59 | $this->mapper->addId(1)->addId(2);
60 | $this->mapper->removeId(2);
61 | $this->assertEquals(array(1), $this->mapper->getIds());
62 | }
63 |
64 | public function testRemoveIds()
65 | {
66 | $this->mapper->addId(1);
67 | $this->mapper->removeIds();
68 | $this->assertEquals(array(), $this->mapper->getIds());
69 | }
70 |
71 | public function testGetIdsString()
72 | {
73 | $this->mapper->addId(1)->addId(2);
74 | $this->assertEquals('1,2', $this->mapper->getIdsString());
75 | }
76 |
77 | public function testLoad()
78 | {
79 | $players = $this->mapper->load();
80 | $this->assertEquals(array(), $players);
81 |
82 | $this->mapper->addId(Player::convertId(86727555))->addId(Player::convertId(111620041));
83 | $players = $this->mapper->load();
84 | $this->assertTrue($players[Player::convertId(86727555)] instanceof Player);
85 | $this->assertTrue($players[Player::convertId(111620041)] instanceof Player);
86 | }
87 |
88 | }
--------------------------------------------------------------------------------
/tests/includes/Mappers/PlayersMapperWebTest.php:
--------------------------------------------------------------------------------
1 | addId('76561198067833250')->addId('76561198058587506')->load();
11 |
12 | $this->assertEquals(count($playersInfo), 2);
13 |
14 | $this->assertEquals('76561198067833250', (string)$playersInfo['76561198067833250']->get('steamid'));
15 | $this->assertEquals('76561198058587506', (string)$playersInfo['76561198058587506']->get('steamid'));
16 |
17 | $this->assertContains('/steamcommunity/public/images/avatars/', $playersInfo['76561198067833250']->get('avatar'));
18 | $this->assertContains('/steamcommunity/public/images/avatars/', $playersInfo['76561198058587506']->get('avatar'));
19 |
20 | $this->assertStringStartsWith('http://steamcommunity.com/',
21 | $playersInfo['76561198067833250']->get('profileurl'));
22 | $this->assertStringStartsWith('http://steamcommunity.com/',
23 | $playersInfo['76561198058587506']->get('profileurl'));
24 | }
25 |
26 | public function testRemoveId()
27 | {
28 | $playersMapperWeb = new PlayersMapperWeb();
29 | $playersMapperWeb->addId(1)->addId(2)->addId(3);
30 | $this->assertEquals(array(1, 2, 3), array_values($playersMapperWeb->getIds()));
31 | $playersMapperWeb->removeId(2);
32 | $this->assertEquals(array(1, 3), array_values($playersMapperWeb->getIds()));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/TeamsMapperDbTest.php:
--------------------------------------------------------------------------------
1 | mapper = new TeamsMapperDb();
16 | $mapperWeb = new TeamsMapperWeb();
17 | $mapperWeb->setTeamId(36)->setTeamsRequested(1);
18 | $teams = $mapperWeb->load();
19 |
20 | $this->assertEquals(count($teams), 1);
21 | $team = array_pop($teams);
22 | $team->set('team_id', 36);
23 | $this->mapper->save($team);
24 | }
25 |
26 | public function testLoad()
27 | {
28 | $teams = $this->mapper->load(36);
29 | $this->assertEquals(count($teams), 1);
30 | $team = $teams[36];
31 | $this->assertEquals($team->get('name'), 'Natus Vincere');
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/TeamsMapperWebTest.php:
--------------------------------------------------------------------------------
1 | markTestSkipped('Teams API end-point doesn\'t return team_id for teams');
15 | $this->mapper = new TeamsMapperWeb();
16 | }
17 |
18 | public function testLoad()
19 | {
20 |
21 | $this->mapper->setTeamId(36)->setTeamsRequested(1);
22 | $teams = $this->mapper->load();
23 |
24 | $this->assertEquals(count($teams), 1);
25 | $team = array_pop($teams);
26 | $this->assertEquals((int)$team->get('team_id'), 36);
27 | $this->assertEquals($team->get('name'), 'Natus Vincere');
28 | $this->assertEquals($team->get('tag'), 'Na`Vi');
29 | $this->assertEquals($team->get('country_code'), 'ua');
30 | $this->assertGreaterThan(0, count($team->getAllPlayersIds()));
31 | $this->assertGreaterThan(0, count($team->getAllLeaguesIds()));
32 | }
33 |
34 | public function testLoadMultiple()
35 | {
36 |
37 | $this->mapper->setTeamId(36)->setTeamsRequested(2);
38 | $teams = $this->mapper->load();
39 | $this->assertEquals(count($teams), 2);
40 |
41 | $team = array_pop($teams);
42 | $this->assertEquals((int)$team->get('team_id'), 39);
43 | $this->assertEquals($team->get('name'), 'Evil Geniuses');
44 | $this->assertEquals($team->get('tag'), 'EG');
45 | $this->assertEquals($team->get('country_code'), 'us');
46 | $this->assertGreaterThan(0, count($team->getAllPlayersIds()));
47 | $this->assertGreaterThan(0, count($team->getAllLeaguesIds()));
48 |
49 | $team = array_pop($teams);
50 | $this->assertEquals((int)$team->get('team_id'), 36);
51 | $this->assertEquals($team->get('name'), 'Natus Vincere');
52 | $this->assertEquals($team->get('tag'), 'Na`Vi');
53 | $this->assertEquals($team->get('country_code'), 'ua');
54 | $this->assertGreaterThan(0, count($team->getAllPlayersIds()));
55 | $this->assertGreaterThan(0, count($team->getAllLeaguesIds()));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/includes/Mappers/UgcMapperWebTest.php:
--------------------------------------------------------------------------------
1 | load();
13 | while (!$game) {
14 | $game = $matchMapperWeb->load();
15 | }
16 | $ugcMapperWeb = new UgcMapperWeb($game->get('dire_logo'));
17 | $logo_data = $ugcMapperWeb->load();
18 | $this->assertNotNull($logo_data);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/tests/includes/Models/MatchTest.php:
--------------------------------------------------------------------------------
1 | matchId);
19 | $this->match = $matchMapperWeb->load();
20 | while (!$this->match) {
21 | $this->match = $matchMapperWeb->load();
22 | }
23 | }
24 |
25 | public function testGetSlot()
26 | {
27 | $slot = $this->match->getSlot(0);
28 |
29 | $this->assertEquals(68, $slot->get('hero_id'));
30 | $this->assertEquals(15, $slot->get('level'));
31 | $this->assertEquals(2, $slot->get('kills'));
32 | $this->assertEquals(2, $slot->get('deaths'));
33 | $this->assertEquals(13, $slot->get('assists'));
34 | $this->assertEquals(49, $slot->get('last_hits'));
35 | $this->assertEquals(3, $slot->get('denies'));
36 | $this->assertEquals(264, $slot->get('gold_per_min'));
37 | $this->assertEquals(337, $slot->get('xp_per_min'));
38 | $this->assertEquals(501, $slot->get('tower_damage'));
39 | $this->assertEquals(4527, $slot->get('hero_damage'));
40 | $this->assertEquals(569, $slot->get('hero_healing'));
41 | $this->assertEquals(214, $slot->get('item_0'));
42 | $this->assertEquals(254, $slot->get('item_1'));
43 | $this->assertEquals(92, $slot->get('item_2'));
44 | $this->assertEquals(23, $slot->get('item_3'));
45 | $this->assertEquals(0, $slot->get('item_4'));
46 | $this->assertEquals(36, $slot->get('item_5'));
47 | }
48 |
49 | public function testGetAllSlotsDivided()
50 | {
51 | $slots = $this->match->getAllSlotsDivided();
52 |
53 | /* @var $slots Dota2Api\Models\Slot[][] */
54 |
55 | $this->assertEquals(5, count($slots['radiant']));
56 | $this->assertEquals(5, count($slots['dire']));
57 |
58 | $this->assertEquals(86727555, $slots['radiant'][0]->get('account_id'));
59 | $this->assertEquals(111620041, $slots['radiant'][1]->get('account_id'));
60 | $this->assertEquals(87276347, $slots['radiant'][2]->get('account_id'));
61 | $this->assertEquals(40547474, $slots['radiant'][3]->get('account_id'));
62 | $this->assertEquals(87177591, $slots['radiant'][4]->get('account_id'));
63 |
64 | $this->assertEquals(140153524, $slots['dire'][0]->get('account_id'));
65 | $this->assertEquals(131237305, $slots['dire'][1]->get('account_id'));
66 | $this->assertEquals(142750189, $slots['dire'][2]->get('account_id'));
67 | $this->assertEquals(101375717, $slots['dire'][3]->get('account_id'));
68 | $this->assertEquals(130416036, $slots['dire'][4]->get('account_id'));
69 | }
70 |
71 | public function testGetAllPicksBansDivided()
72 | {
73 | $picksBans = $this->match->getAllPicksBansDivided();
74 | $expectedDividedPicksBans = array(
75 | 'radiant' => array(
76 | 'bans' => array(
77 | array(
78 | 'is_pick' => '0',
79 | 'hero_id' => '62',
80 | 'team' => '0',
81 | 'order' => '0',
82 | ),
83 | array(
84 | 'is_pick' => '0',
85 | 'hero_id' => '100',
86 | 'team' => '0',
87 | 'order' => '2',
88 | ),
89 | array(
90 | 'is_pick' => '0',
91 | 'hero_id' => '106',
92 | 'team' => '0',
93 | 'order' => '8',
94 | ),
95 | array(
96 | 'is_pick' => '0',
97 | 'hero_id' => '92',
98 | 'team' => '0',
99 | 'order' => '10',
100 | ),
101 | array(
102 | 'is_pick' => '0',
103 | 'hero_id' => '50',
104 | 'team' => '0',
105 | 'order' => '17',
106 | ),
107 | ),
108 | 'picks' => array(
109 | array(
110 | 'is_pick' => '1',
111 | 'hero_id' => '72',
112 | 'team' => '0',
113 | 'order' => '4',
114 | ),
115 | array(
116 | 'is_pick' => '1',
117 | 'hero_id' => '89',
118 | 'team' => '0',
119 | 'order' => '7',
120 | ),
121 | array(
122 | 'is_pick' => '1',
123 | 'hero_id' => '17',
124 | 'team' => '0',
125 | 'order' => '13',
126 | ),
127 | array(
128 | 'is_pick' => '1',
129 | 'hero_id' => '7',
130 | 'team' => '0',
131 | 'order' => '15',
132 | ),
133 | array(
134 | 'is_pick' => '1',
135 | 'hero_id' => '68',
136 | 'team' => '0',
137 | 'order' => '19',
138 | ),
139 | ),
140 | ),
141 | 'dire' => array(
142 | 'bans' => array(
143 | array(
144 | 'is_pick' => '0',
145 | 'hero_id' => '52',
146 | 'team' => '1',
147 | 'order' => '1',
148 | ),
149 | array(
150 | 'is_pick' => '0',
151 | 'hero_id' => '105',
152 | 'team' => '1',
153 | 'order' => '3',
154 | ),
155 | array(
156 | 'is_pick' => '0',
157 | 'hero_id' => '55',
158 | 'team' => '1',
159 | 'order' => '9',
160 | ),
161 | array(
162 | 'is_pick' => '0',
163 | 'hero_id' => '11',
164 | 'team' => '1',
165 | 'order' => '11',
166 | ),
167 | array(
168 | 'is_pick' => '0',
169 | 'hero_id' => '5',
170 | 'team' => '1',
171 | 'order' => '16',
172 | ),
173 | ),
174 | 'picks' => array(
175 | array(
176 | 'is_pick' => '1',
177 | 'hero_id' => '51',
178 | 'team' => '1',
179 | 'order' => '5',
180 | ),
181 | array(
182 | 'is_pick' => '1',
183 | 'hero_id' => '25',
184 | 'team' => '1',
185 | 'order' => '6',
186 | ),
187 | array(
188 | 'is_pick' => '1',
189 | 'hero_id' => '112',
190 | 'team' => '1',
191 | 'order' => '12',
192 | ),
193 | array(
194 | 'is_pick' => '1',
195 | 'hero_id' => '12',
196 | 'team' => '1',
197 | 'order' => '14',
198 | ),
199 | array(
200 | 'is_pick' => '1',
201 | 'hero_id' => '49',
202 | 'team' => '1',
203 | 'order' => '18',
204 | ),
205 | ),
206 | ),
207 | );
208 | $this->assertEquals($expectedDividedPicksBans, $picksBans);
209 | }
210 |
211 | }
--------------------------------------------------------------------------------
/tests_config.php:
--------------------------------------------------------------------------------
1 | exec('CREATE DATABASE '.$db_name);
14 | Db::clean();
15 | $db = Db::obtain('localhost', 'root', '', 'dota2_api_test_db', '');
16 | $db->connectPDO();
17 | $db->exec(file_get_contents('db_latest.sql'));
18 |
19 | register_shutdown_function(function() {
20 | $db = Db::obtain();
21 | $db->exec('DROP DATABASE dota2_api_test_db');
22 | });
--------------------------------------------------------------------------------