-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.php
72 lines (62 loc) · 2.04 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
<?php
include 'bootstrap.php';
// Load data that we will need for the front page
$gameMapper = new \IBL\GameMapper($container['db_connection']);
$franchiseMapper = new \IBL\FranchiseMapper($container['db_connection']);
$rotationMapper = new \IBL\RotationMapper($container['db_connection']);
$scheduleMapper = new \IBL\ScheduleMapper($container['db_connection']);
$games = $gameMapper->findAll();
$franchises = $franchiseMapper->findAll();
$standings = new \IBL\Standings($games, $franchises);
$regularStandings = $standings->generateRegular();
$currentWeek = $gameMapper->getCurrentWeek();
$currentResults = $gameMapper->generateResults(
$gameMapper->findByWeek($currentWeek),
$franchises
);
/**
* If we don't have any rotations for the current week, make sure to grab
* rotations for the previous week
*/
$rotations = $rotationMapper->findByWeek($currentWeek);
$rotationWeek = $currentWeek;
if (count($rotations) == 0) {
$rotations = $rotationMapper->findByWeek($currentWeek - 1);
$rotationWeek = $currentWeek - 1;
}
$currentRotations = $rotationMapper->generateRotations(
$rotations,
$franchises
);
/**
* We need to use some intelligence in deciding what schedules we need to
* show. If we have less than half the results in, show the schedule
* from the previous week
*/
if (count($currentResults) < 12) {
$scheduleWeek = $currentWeek - 1;
} else {
$scheduleWeek = $currentWeek;
}
$franchiseMap = $franchiseMapper->generateMap(
$scheduleMapper->teamsTable
);
$rawSchedule = $scheduleMapper->findByWeek($scheduleWeek);
$currentSchedules = $scheduleMapper->generate(
$rawSchedule,
$franchiseMap
);
// Display the data
echo $twig->render(
'index.html',
array(
'currentWeek' => $currentWeek,
'currentResults' => $currentResults,
'currentRotations' => $currentRotations,
'currentSchedules' => $currentSchedules,
'franchises' => $franchises,
'rotationWeek' => $rotationWeek,
'scheduleWeek' => $scheduleWeek,
'standings' => $regularStandings,
)
);