-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournament_64.pages.inc
218 lines (182 loc) · 5.77 KB
/
tournament_64.pages.inc
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* @file
* Tournament 64 page views
*
*/
function tour64_bracket($teams, $winners, $sections, $league_winners = NULL) {
$build = array();
$build[] = array(
'#markup' => '<div id="bracket" class="tour64-bracket-block">',
);
if (!empty($league_winners)) {
$tour64_won = _tour64_fill_won($league_winners, $winners);
}
for ($i = 1; $i <= 32; $i++) {
$round_1_left_teams[] = array('name' => $teams[$i]['name']);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_1_left_teams,
'#tour64_round' => 1,
'#tour64_side' => 'left',
);
for ($i = 1; $i <= 16; $i++) {
$round_2_left_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_2_left_teams,
'#tour64_round' => 2,
'#tour64_side' => 'left',
);
for ($i = 33; $i <= 40; $i++) {
$round_3_left_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_3_left_teams,
'#tour64_round' => 3,
'#tour64_side' => 'left'
);
for ($i = 49; $i <= 52; $i++) {
$round_4_left_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_4_left_teams,
'#tour64_round' => 4,
'#tour64_side' => 'left',
);
for ($i = 57; $i <= 58; $i++) {
$round_5_left_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_5_left_teams,
'#tour64_round' => 5,
'#tour64_side' => 'left'
);
for ($i = 61; $i <= 63; $i++) {
$round_6_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_6_teams,
'#tour64_round' => 6,
'#tour64_side' => 'centre',
'#tour64_extras' => array('Finals', NULL, 'Champion'),
);
for ($i = 59; $i <= 60; $i++) {
$round_5_right_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_5_right_teams,
'#tour64_round' => 5,
'#tour64_side' => 'right',
);
for ($i = 53; $i <= 56; $i++) {
$round_4_right_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_4_right_teams,
'#tour64_round' => 4,
'#tour64_side' => 'right',
);
for ($i = 41; $i <= 48; $i++) {
$round_3_right_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_3_right_teams,
'#tour64_round' => 3,
'#tour64_side' => 'right',
);
for ($i = 17; $i <= 32; $i++) {
$round_2_right_teams[] = array(
'name' => !empty($winners[$i]) ? $teams[$winners[$i]]['name'] : NULL,
'won' => isset($tour64_won[$i]) ? $tour64_won[$i] : NULL,
);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_2_right_teams,
'#tour64_round' => 2,
'#tour64_side' => 'right',
);
for ($i = 33; $i <= 64; $i++) {
$round_1_right_teams[] = array('name' => $teams[$i]['name']);
}
$build[] = array(
'#theme' => 'tour64_bracket',
'#tour64_teams' => $round_1_right_teams,
'#tour64_round' => 1,
'#tour64_side' => 'right',
);
$build[] = array(
'#markup' => '</div>',
);
return $build;
}
function tour64_entity_view($entity_type, $entity_id) {
drupal_set_title(entity_label($entity_type, $entity_id));
return entity_view($entity_type, array(entity_id($entity_type, $entity_id) => $entity_id), 'full');
}
function tour64_entry_bracket($entity) {
$league_entity = entity_load('tour64_leagues', array($entity->league_id));
$league_entity = reset($league_entity);
return tour64_bracket($league_entity->teams, $entity->winners, $league_entity->sections, $league_entity->winners);
}
function tour64_league_bracket($entity) {
return tour64_bracket($entity->teams, $entity->winners, $entity->sections);
}
/**
* style winners and losers
*
*/
function _tour64_fill_won($league_winners, $entry_winners) {
$tour64_won = array();
$teams_lost = tour64_teams_lost($league_winners);
// check if this pick is a winner or loser and format accordingly
for ($game_number = 1; $game_number <= 63; $game_number++) {
// if no winner for this game yet, check to see if team lost in previous rounds
if (empty($league_winners[$game_number])) {
if (in_array($entry_winners[$game_number], $teams_lost)) {
$tour64_won[$game_number] = FALSE;
} else {
$tour64_won[$game_number] = NULL;
}
} elseif ($league_winners[$game_number] == $entry_winners[$game_number]) {
$tour64_won[$game_number] = TRUE;
} else {
$tour64_won[$game_number] = FALSE;
}
}
return $tour64_won;
}