forked from philip/YahooFantasySportsAPI
/
matchups.php
61 lines (45 loc) · 1.94 KB
/
matchups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require './inc/config.inc.php';
require './inc/header.php';
// @todo add proper error reporting
if ( empty( $_VARS['week_num'] ) || empty( $_VARS['league_key'] ) ) {
echo 'Error: A week number and league key is required for matchup information';
exit;
}
try {
$m = new YahooMessageArchiver( TRUE );
} catch ( OauthException $e ) {
echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
exit;
}
$query = "league/{$_VARS['league_key']}/scoreboard;week={$_VARS['week_num']}/matchups/teams/roster;week={$_VARS['week_num']}/players/stats;type=week;week={$_VARS['week_num']}";
// For single team
// $query = "team/{$team_key}/roster;week={$week_num}/players/stats;type=week;week={$week_num}
$minfo = $m->retrieve( $query );
// @todo fix questionable error handling
if ( empty( $minfo ) ) {
echo "FAIL";
exit;
}
echo '<h1>Matchup information for week ', $minfo->league->scoreboard->week, '</h1>';
// @todo remove this hack
// @todo show more info
foreach ($minfo->league->scoreboard->matchups->matchup as $key => $values) {
$team_name_0 = $values->teams->team[0]->name;
$team_name_1 = $values->teams->team[1]->name;
// @todo Assuming one manager for now
$team_nick_0 = $values->teams->team[0]->managers->manager->nickname;
$team_nick_1 = $values->teams->team[1]->managers->manager->nickname;
$team_score_0 = $values->teams->team[0]->team_points->total;
$team_score_1 = $values->teams->team[1]->team_points->total;
$team_proj_0 = $values->teams->team[0]->team_projected_points->total;
$team_proj_1 = $values->teams->team[1]->team_projected_points->total;
echo "<h3>$team_name_0 ($team_nick_0) versus $team_name_1 ($team_nick_1)</h3>";
echo "<p>$team_name_0 is projected for $team_proj_0 and so far has $team_score_0 points</p>";
echo "<p>$team_name_1 is projected for $team_proj_1 and so far has $team_score_1 points</p>";
}
// @todo add proper view instead of simple print_r
print '<pre>';
print_r( $minfo );
print '</pre>';
require './inc/footer.php';