-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccb8champ.inc
370 lines (310 loc) · 11.6 KB
/
ccb8champ.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
* @file
* This file contains the required functions for the ccb8champ bracket design
*
* This design consists of 8 competitors in a modified double elimination bracket
*
* @author Jim Bullington <jimb@jrbcs.com>
* @author Elliot Voris <elliotfriend@gmail.com>
*/
/**
* Create a bracket tree in the given node object
*
* @param $node
* the node object
*/
function ccb8champ_create(&$node) {
// set match id option
$node->options['show_match_id'] = TRUE;
// add competitors
bracket_design_create_competitors($node, 8);
// add winner rounds
bracket_design_create_winner_rounds($node);
// add championship results
bracket_design_create_championship_results($node);
// add loser rounds
bracket_design_create_loser_rounds($node, TRUE);
// add loser results
$node->round[6]->match[1]->winner_match = 0;
$node->round[6]->match[1]->winner_compid = 0;
$node->round[6]->match[1]->winner_result = 3;
$node->round[6]->match[1]->loser_result = 4;
$node->round[5]->match[1]->winner_result = 5;
$node->result[3] = new Bracket_Result();
$node->result[3]->comment = '3rd Place';
$node->result[4] = new Bracket_Result();
$node->result[4]->comment = '4th Place';
$node->result[5] = new Bracket_Result();
$node->result[5]->comment = '5th Place';
// name the rounds
$node->round[1]->name = t('Quarterfinals');
$node->round[2]->name = t('Semifinals');
$node->round[3]->name = t('Final');
for ($i=4; $i<=6; $i++) {
$node->round[$i]->name = t('Loser Rnd') . ' ' . ($i-3);
}
}
/**
* Produce a png image for the requested bracket object
*
* @param $b
* the bracket object
* @return
* the png image
*/
function ccb8champ_image($node) {
global $_bracket_image_font;
global $_bracket_image_font_bold;
global $_bracket_image_font_xlarge;
global $_bracket_image_font_large;
global $_bracket_image_font_norm;
global $_bracket_image_font_small;
global $_bracket_image_font_xsmall;
global $_bracket_image_bg_color;
global $_bracket_image_fg_color;
// setup positions and spacing
$top = 100;
$left = 310;
$width = 100;
$height = 50;
$spacing = $height * 2.0;
// spacing between top and bottom brackets
$tb = $spacing * 4.25;
// setup image
$iwidth = 700;
$iheight = 600;
$img = imagecreatetruecolor($iwidth, $iheight);
// allocate colors
bracket_image_setup_colors($node, $img);
// setup fonts
bracket_image_setup_fonts($node);
// fill in background
imagefill($img, 0, 0, $_bracket_image_bg_color);
// font sizes
$_bracket_image_font_xlarge = 14;
$_bracket_image_font_large = 12;
$_bracket_image_font_norm = 10;
$_bracket_image_font_small = 8;
$_bracket_image_font_xsmall = 7;
// font height
$bbox = imagettfbbox($_bracket_image_font_norm, 0, $_bracket_image_font, 'Q');
$h = $bbox[1] - $bbox[7];
$w = 10;
// quarters
bracket_image_drawbracketset($img, $node, $left, $top, $width, $height, $spacing, 1, 1, 4, 'L', TRUE);
// semis
$l = $left + $width;
$hh = $spacing;
$sp = $spacing * 2;
// new top - add half prev height
$t = $top + ($height / 2);
bracket_image_drawbracketset($img, $node, $l, $t, $width, $hh, $sp, 2, 1, 2, 'L', TRUE);
// final
$l += $width;
$t += ($hh / 2);
$hh = $sp;
$sp = $sp * 2;
bracket_image_drawbracketset($img, $node, $l, $t, $width, $hh, $sp, 3, 1, 1, 'L', TRUE);
// winner and runner-up
$l += $width;
$t += ($hh / 3);
imageline($img, $l, $t, $l+$width, $t, $_bracket_image_fg_color);
bracket_image_imagetextalign($img, $_bracket_image_font_large, $l, $t-2, $width, $node->result[1]->cname, $_bracket_image_fg_color, 'C');
bracket_image_imagetextalign($img, $_bracket_image_font_norm, $l, $t+$h+1, $width, $node->result[1]->comment, $_bracket_image_fg_color, 'C');
$t += ($hh / 3);
imageline($img, $l, $t, $l+$width, $t, $_bracket_image_fg_color);
bracket_image_imagetextalign($img, $_bracket_image_font_large, $l, $t-2, $width, $node->result[2]->cname, $_bracket_image_fg_color, 'C');
bracket_image_imagetextalign($img, $_bracket_image_font_norm, $l, $t+$h+1, $width, $node->result[2]->comment, $_bracket_image_fg_color, 'C');
// loser rounds
$lrnd = bracket_round_first_loser_round($node);
$t = $top + ($height / 2);
$hh = $spacing;
$sp = $spacing * 2;
// loser round 1
bracket_image_drawbracketset($img, $node, $left, $t, $width, $hh, $sp, $lrnd, 1, 2, 'R', TRUE);
// loser round 2
$l = $left - $width;
// determine if last match winner goes to top of bottom slot
$t += ($hh / 2);
$hh = $sp;
$sp = $sp * 2;
bracket_image_drawbracketset($img, $node, $l, $t, $width, $hh, $sp, $lrnd+1, 1, 1, 'R', TRUE);
// 5th place
$l -= ($width * 2);
$t += ($hh / 2);
imageline($img, $l, $t, $l+$width, $t, $_bracket_image_fg_color);
bracket_image_imagetextalign($img, $_bracket_image_font_large, $l, $t-2, $width, $node->result[5]->cname, $_bracket_image_fg_color, 'C');
bracket_image_imagetextalign($img, $_bracket_image_font_norm, $l, $t+$h+1, $width, $node->result[5]->comment, $_bracket_image_fg_color, 'C');
// loser round 3
$l += ($width * 5);
$t = $t + ($height * 4);
$hh = $spacing / 2;
$sp = $spacing * 4;
bracket_image_drawbracketset($img, $node, $l, $t, $width, $hh, $sp, $lrnd+2, 1, 1, 'L', TRUE);
// 3rd and 4th place
$l += $width;
$t += ($hh / 2);
imageline($img, $l, $t, $l+$width, $t, $_bracket_image_fg_color);
bracket_image_imagetextalign($img, $_bracket_image_font_large, $l, $t-2, $width, $node->result[3]->cname, $_bracket_image_fg_color, 'C');
bracket_image_imagetextalign($img, $_bracket_image_font_norm, $l, $t+$h+1, $width, $node->result[3]->comment, $_bracket_image_fg_color, 'C');
//imageline($img, $l, $t, $l+$width, $t, $_bracket_image_fg_color);
//bracket_image_imagetextalign($img, $_bracket_image_font_large, $l, $t-2, $width, $node->result[4]->cname, $_bracket_image_fg_color, 'C');
//bracket_image_imagetextalign($img, $_bracket_image_font_norm, $l, $t+$h+1, $width, $node->result[4]->comment, $_bracket_image_fg_color, 'C');
// bracket title
bracket_image_imagetextalign($img, $_bracket_image_font_xlarge, $iwidth / 2 - (400 / 2), 15, 400, $node->title, $_bracket_image_fg_color, 'C');
// bracket subtitle
bracket_image_imagetextalign($img, $_bracket_image_font_norm, $iwidth / 2 - (400 / 2), 30, 400, $node->subtitle, $_bracket_image_fg_color, 'C');
// bracket comments
bracket_image_imagetextwordwrap($img, $_bracket_image_font_small, $iwidth / 2 - (400 / 2), 60, 400, $node->comments, $_bracket_image_fg_color, 'C');
// bracket footnote
bracket_image_imagetextwordwrap($img, $_bracket_image_font_small, $left, $iheight-($h * 3), $iwidth-($left), $node->footer, $_bracket_image_fg_color, 'L');
// bracket logo
if ($node->logopath != '') {
bracket_image_insert_image($img, $node->logopath, 50, 450, 200);
}
// sponsor logo
if ($node->sponsorlogopath != '') {
bracket_image_insert_image($img, $node->sponsorlogopath, $iwidth/2, $iheight-100, 75, TRUE);
}
// generate the png image stream
$png = bracket_image_output_png($img);
// done with the image
imagedestroy($img);
// return the image
return $png;
}
/**
* Produce a pdf document for the requested bracket object
*
* @param $b
* the bracket object
* @return
* the pdf document
*/
function ccb8champ_pdf($node) {
global $_bracket_pdf_font_name;
global $_bracket_pdf_font_xlarge;
global $_bracket_pdf_font_large;
global $_bracket_pdf_font_norm;
global $_bracket_pdf_font_small;
global $_bracket_pdf_font_xsmall;
// setup pdf
$pdf = new PDF('L', 'in', 'letter');
$pdf->setAutoPageBreak(FALSE);
$iwidth = 11.0;
$iheight = 8.5;
// positions and spacing
$top = 1.5;
$left = 1.5;
$width = 1.25;
$height = 0.75;
$spacing = $height * 2;
$pdf->setMargins($top, $left);
// spacing between top and bottom brackets
$tb = $spacing * 4.25;
// set pdf colors
bracket_pdf_setup_colors($node, $pdf);
// set pdf font
bracket_pdf_setup_font($node, $pdf);
// set font sizes
$_bracket_pdf_font_norm = 8;
$_bracket_pdf_font_small = 7;
$pdf->setFont($_bracket_pdf_font_name, '', $_bracket_pdf_font_norm);
// start pdf
$pdf->addPage();
// quarters
$left = 4.75;
bracket_pdf_drawbracketset($pdf, $node, $left, $top, $width, $height, $spacing, 1, 1, 4, 'L', TRUE);
// semis
$l = $left + $width;
$t = $top + ($height / 2);
$hh = $spacing;
$sp = $spacing * 2;
bracket_pdf_drawbracketset($pdf, $node, $l, $t, $width, $hh, $sp, 2, 1, 2, 'L', TRUE);
// final
$l += $width;
$t += ($hh / 2);
$hh = $sp;
$sp = $sp * 2;
bracket_pdf_drawbracketset($pdf, $node, $l, $t, $width, $hh, $sp, 3, 1, 1, 'L', TRUE);
// winner and runner-up
$l += $width;
$t += ($hh / 3);
$pdf->setFont($_bracket_pdf_font_name, 'B', $_bracket_pdf_font_large);
$pdf->line($l, $t, $l+$width, $t);
$pdf->setXY($l, $t-0.125);
$pdf->cell($width, 0.125, $node->result[1]->cname, 0, 0, 'C');
$pdf->setXY($l, $t+0.0625);
$pdf->cell($width, 0.125, $node->result[1]->comment, 0, 0, 'C');
$t += ($hh / 3);
$pdf->line($l, $t, $l+$width, $t);
$pdf->setXY($l, $t-0.125);
$pdf->cell($width, 0.125, $node->result[2]->cname, 0, 0, 'C');
$pdf->setXY($l, $t+0.0625);
$pdf->cell($width, 0.125, $node->result[2]->comment, 0, 0, 'C');
// loser rounds
$lrnd = bracket_round_first_loser_round($node);
$t = $top + ($height / 2);
$hh = $spacing;
$sp = $spacing * 2;
// loser round 1
bracket_pdf_drawbracketset($pdf, $node, $left, $t, $width, $hh, $sp, $lrnd, 1, 2, 'R', TRUE);
// loser round 2
$t += ($hh / 2);
$hh = $sp;
$sp += $sp * 2;
$l = $left - $width;
bracket_pdf_drawbracketset($pdf, $node, $l, $t, $width, $hh, $sp, $lrnd+1, 1, 1, 'R', TRUE);
// 5th place
$l -= $width * 2;
$t += ($hh / 2);
$pdf->setFont($_bracket_pdf_font_name, 'B', $_bracket_pdf_font_large);
$pdf->line($l, $t, $l+$width, $t);
$pdf->setXY($l, $t-0.125);
$pdf->cell($width, 0.125, $node->result[5]->cname, 0, 0, 'C');
$pdf->setXY($l, $t+0.0625);
$pdf->cell($width, 0.125, $node->result[5]->comment, 0, 0, 'C');
// loser round 3
$l += ($width * 5);
$t = $t + ($height * 4);
$hh = $spacing / 2;
$sp = $spacing * 6;
bracket_pdf_drawbracketset($pdf, $node, $l, $t, $width, $hh, $sp, $lrnd+2, 1, 1, 'L', TRUE);
// 3rd and 4th place
$l += $width;
$t += ($hh / 2);
$pdf->setFont($_bracket_pdf_font_name, 'B', $_bracket_pdf_font_large);
$pdf->line($l, $t, $l+$width, $t);
$pdf->setXY($l, $t-0.125);
$pdf->cell($width, 0.125, $node->result[3]->cname, 0, 0, 'C');
$pdf->setXY($l, $t+0.0625);
$pdf->cell($width, 0.125, $node->result[3]->comment, 0, 0, 'C');
// bracket title
$left = 1.5;
$pdf->setFont($_bracket_pdf_font_name, 'BI', $_bracket_pdf_font_xlarge);
$pdf->setXY($left, 0.5);
$pdf->multicell($iwidth - ($left * 2) , 0.25, $node->title, 0, 'C');
// bracket subtitle
$pdf->setFont($_bracket_pdf_font_name, 'BI', $_bracket_pdf_font_large);
$pdf->setXY($left, 0.75);
$pdf->multicell($iwidth - ($left * 2), 0.125, $node->subtitle, 0, 'C');
// bracket comments
$pdf->setFont($_bracket_pdf_font_name, '', $_bracket_pdf_font_norm);
$pdf->setXY($left, 1);
$pdf->multicell($iwidth - ($left * 2), 0.125, $node->comments, 0, 'C');
// bracket footnote
$pdf->setFont($_bracket_pdf_font_name, '', $_bracket_pdf_font_small);
$pdf->setXY(($left * 3), $iheight - 0.5);
$pdf->multicell($iwidth - ($left * 4), 0.125, $node->footer, 0, 'L');
// bracket logo
if ($node->logopath != '') {
bracket_pdf_insert_image($pdf, $node->logopath, 2.0, 6.75, 2.0);
}
// sponsor logo
if ($node->sponsorlogopath != '') {
bracket_pdf_insert_image($pdf, $node->sponsorlogopath, 4.25, 9.5, 0.75);
}
// return pdf as a string
return $pdf->output('', 'S');
}