-
Notifications
You must be signed in to change notification settings - Fork 0
/
bracket_recaps.module
113 lines (100 loc) · 3.54 KB
/
bracket_recaps.module
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
<?php
/**
* @file
* Module file for bracket_recaps_module.
*/
/**
* Implements hook_help().
*/
function bracket_recaps_help($path, $arg) {
switch ($path) {
case 'bracket_recaps/simple':
// Help text for the simple page registered for this path.
return t('This is help text for the bracket recaps.');
case 'admin/help#bracket_recaps':
// Help text for the admin section, using the module name in the path.
return t("This is help text created in the bracket recap's second case.");
}
}
/**
* Implements hook_permission().
*/
function bracket_recaps_permission() {
return array(
'access simple page' => array(
'title' => t('Access bracket recaps'),
'description' => t('Allow users to access bracket recaps'),
),
);
}
/**
* Implements hook_menu().
*/
function bracket_recaps_menu() {
// This is the minimum information you can provide for a menu item. This menu
// item will be created in the default menu, usually Navigation.
$items['athletics/mens-soccer/tournament/recaps'] = array(
'title' => 'MCCC Tournament Recaps',
'page callback' => 'bracket_recaps_simple',
'access callback' => TRUE,
'expanded' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Constructs a simple page.
*
* Our menu maps this function to the path 'athletics/mens-soccer/tournament/recaps'.
*/
function bracket_recaps_simple() {
// Text for our table's header row
$table_header = array(
'Date',
'Time',
'Team',
'Score',
'Goal Scorers',
);
// Load the bracket that you want here. We'll change this to a config
// setting sometime soon.
$bracket = bracket_api_load_bracket(621);
// This needs to exist so that we can look into the last row, and it
// won't throw any errors at us.
$rows = array();
// Get each round in the bracket
foreach (element_children($bracket->round) as $rid) {
// Get each match in the round
foreach (element_children($bracket->round[$rid]->match) as $mid) {
// Make sure that two competitors already exist for the match
// Otherwise, we'll not show this match in the table.
if (!empty($bracket->round[$rid]->match[$mid]->cname[1]) &&
!empty($bracket->round[$rid]->match[$mid]->cname[2]) ) {
// Get each competitor in the match
foreach (element_children($bracket->round[$rid]->match[$mid]->compid) as $cid) {
// Save the previous row to compare against
$prev_row = end($rows);
reset($rows);
$rows[] = array(
// We don't want date/time to be the same row-after-row
// This will display the date/time once for each match
'Date' => ($prev_row['Date'] === t($bracket->round[$rid]->match[$mid]->comment[1])) ? null : t($bracket->round[$rid]->match[$mid]->comment[1]),
'Time' => ($prev_row['Time'] === t($bracket->round[$rid]->match[$mid]->comment[2])) ? null : t($bracket->round[$rid]->match[$mid]->comment[2]),
'Team' => t($bracket->round[$rid]->match[$mid]->cname[$cid]),
'Score' => t($bracket->round[$rid]->match[$mid]->score[$cid]),
// We're keeping the goal scorers within the competitor
// comment. So, we grab that here.
'Goal Scorers' => t($bracket->round[$rid]->match[$mid]->comp_comment[$cid]),
);
}
}
}
}
// Render out the array as a table.
$render_array['bracket_recaps_simple'] = array(
'#theme' => 'table',
'#header' => $table_header,
'#rows' => $rows,
);
return $render_array;
}