-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive-fixtures.php
350 lines (294 loc) · 15 KB
/
archive-fixtures.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
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
<?php get_header(); ?>
<div id="wrapper">
<div id="pagecol" class='ajaxcol'>
<div class='page'>
<?php if ( isset ( $GLOBALS['bisons_flash_message'] ) ) : ?>
<p id="flashmessage"><?php echo $GLOBALS['bisons_flash_message'] ?></p>
<?php endif ?>
<header>
<h2>Fixtures</h2>
<ul class='pageMenu'>
<?php if ( current_user_can('edit_post', get_the_id() ) ) { ?>
<li><a class='fa fa-plus-square' href='<?php echo $GLOBALS['blog_info']['url']; ?>/wp-admin/post-new.php?post_type=fixture'>Add</a></li>
<?php } ?>
<li><a class='fa fa-rss-square' href='<?php echo str_replace ( 'http://', 'webcal://', site_url('/calendar.ics?of=fixtures'))?>'>iCal (fixtures)<a/></li>
<li><a class='fa fa-rss-square' href='<?php echo str_replace ( 'http://', 'webcal://', site_url('/calendar.ics')) ?>'>iCal (all)</a></li>
</ul>
</header>
<?php
$cuid = get_current_user_id();
$fixtures = array();
$past_fixtures = array();
$future_fixtures = array();
$results = array();
// Handle a lack of fixtures
if(! have_posts() ) : ?>
<p>Details of this seasons fixtures have not been released yet. Check out results from previous seasons using the links below.</p>
<?php else :
// Loop over fixtures
while( have_posts()) : the_post();
// Reformat date and convert the date and time combined into a unix time
$unixdate = get_post_meta( get_the_id(), 'fixture-date', true );
$printdate = date( 'jS \o\f F Y' , $unixdate );
$time = get_post_meta( get_the_id(), 'fixture-kickoff-time', true );
$datetime = date( 'Y:m:d' , $unixdate ). ' '.$time.':00';
$datetimeunix = strtotime($datetime);
if ( get_post_meta(get_the_id(), 'fixture-home-away', true) == 'Home' )
{
$clubInfoSettings = get_option('club-info-settings');
$address = $clubInfoSettings['home-address'];
}
else
{
$address = get_post_meta( get_the_id(), 'fixture-address', true ) ? wpautop ( get_post_meta( get_the_id(), 'fixture-address', true ) ) : wpautop ( get_post_meta( get_post_meta( get_the_id(), 'fixture_team', true), 'homeaddress', true) );
}
// Prepare fixtures array
$fixture = array(
'id' => get_the_id(),
'date' => get_post_meta( get_the_id(), 'fixture-date', true ) ? $printdate : 'Date TBC',
'textdate' => get_post_meta( get_the_id(), 'text-date', true ),
'kickoff' => get_post_meta( get_the_id(), 'fixture-kickoff-time', true ) ? date("g:ia", strtotime(get_post_meta( get_the_id(), 'fixture-kickoff-time', true ) )) : 'TBC',
'playtime' => get_post_meta( get_the_id(), 'fixture-player-arrival-time', true ) ? date("g:ia", strtotime(get_post_meta( get_the_id(), 'fixture-player-arrival-time', true ))) : false,
'address' => $address,
'opposing' => get_post_meta( get_the_id(), 'fixture_team', true ) ? get_the_title( get_post_meta( get_the_id(), 'fixture_team', true ) ) : 'No Team' ,
'page' => get_permalink(),
'gmap' => get_post_meta( get_the_id(), 'fixture-gmap', true ) ? get_post_meta( get_the_id(), 'fixture-gmap', true ) : false,
'teamurl' => get_permalink( get_post_meta( get_the_id(), 'fixture_team', true) ),
'edit_link' => '<a class="editsmall" href="'.get_edit_post_link( get_the_id() ).'">Edit fixture</a>',
'homeaway' => get_post_meta(get_the_id(), 'fixture-home-away', true)
);
if( $datetimeunix > time() ) $future_fixtures[] = $fixture;
else $past_fixtures[] = $fixture;
// Otherwise push it into the $past_fixtures array
endwhile;
// Move the next fixture from the $future_fixtures array into its own variable
$first_fixture = $future_fixtures[0];
unset($future_fixtures[0]);
if( count($future_fixtures) > 0 ) $future_fixtures = array_values($future_fixtures);
// If there is a 'Next Event' show the relevant HTML
if( $first_fixture ) : ?>
<h3>Next Fixture</h3>
<p>Friends and family are always welcome at our matches. If there are any remaining fixtures or we have already played fixtures this season, scroll down the page to find the details and match results. </p>
<div class='metaBox fixture'>
<a itemprop="url" href="<?php echo $first_fixture['page'] ?>"><img src='<?php echo get_template_directory_uri() ?>/images/ball2.jpg' /></a>
<div class='eventMeta'>
<h4><?php if ( $first_fixture['textdate'] ) : echo $first_fixture['textdate']; ?><?php else : ?><time itemProp="startDate" datetime="<?php echo $first_fixture['isodate'] ?>"><?php echo $first_fixture['date']; ?></time><?php endif ?></h4>
<ul>
<?php if ( $first_fixture['homeaway'] == 'Home' ) : ?>
<li class="fa fa-star teamName">Bristol Bisons RFC (Home)</li>
<li>Vs</li>
<li class="fa fa-star teamName"><a href='<?php echo $first_fixture['teamurl'] ?>'><?php echo $first_fixture['opposing'] ?></a> (Away)</li>
<?php else : ?>
<li class="fa fa-star teamName"><a href='<?php echo $first_fixture['teamurl'] ?>'><?php echo $first_fixture['opposing'] ?></a> (Home)</li>
<li>Vs</li>
<li class="fa fa-star teamName">Bristol Bisons RFC (Away)</li>
<?php endif ?>
</ul>
<div class='clear'></div>
</div>
</div>
<?php else: ?>
<p>It looks like there isn't any more fixtures coming up this season, or the committee have not yet updated the website - try checking back later. In the meantime, checkout the results for the fixtures we have played so far below.</p>
<?php endif; ?>
</section>
<?php if( $future_fixtures ) : ?>
<section class="clearsection">
<h3>Upcoming Fixtures</h3>
<p>Below are the remaining upcoming fixtures for this season. Click on the fixture date for details of that fixture.</p>
<table class='center fixturestable'>
<tbody>
<?php foreach($future_fixtures as $future_fixture) : ?>
<tr>
<td class="datecol"><a href="<?php echo $future_fixture['page']; ?>"><?php echo $future_fixture['textdate'] ? $future_fixture['textdate'] : $future_fixture['date'] ?></a></td>
<td class="homeawaycol"><?php echo $future_fixture['homeaway'] ?></td>
<td><a href='<?php echo $future_fixture['teamurl'] ?>'><?php echo $future_fixture['opposing'] ?></a> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</section>
<?php endif; ?>
<?php if( $past_fixtures ) : ?>
<section class="clearsection">
<h3>Fixture Results</h3>
<p>Results for this season are below. Click on the match date to be taken to the individual results page which contains more details about that match such as match statistics. Please get in contact with us if you believe any fixture results to be wrong.</p>
<?php
// Create match results query
$getResultsQuery = new WP_Query(array(
'post_type' => 'results',
'nopaging' => 'true'
));
// Loop over results, store in an array
while($getResultsQuery->have_posts()) : $getResultsQuery->the_post();
$results[] = array(
'link' => get_the_permalink(),
'parent-fixture' => get_post_meta(get_the_id(), 'parent-fixture', true),
'their-score' => get_post_meta(get_the_id(), 'their-score', true),
'our-score' => get_post_meta(get_the_id(), 'our-score', true),
'edit-result-link' => "<a class='editsmall' href='".get_edit_post_link( get_the_id() )."'>Edit result</a>"
);
endwhile;
// Create match reports query;
$linked_posts_query = new WP_Query(array(
'post_type' => array ( 'post', 'photos' ),
'nopaging' => 'true', 'meta_query' => array (
'relation' => 'AND',
array(
'key' => 'fixture_id',
'compare' => 'EXISTS' ),
array(
'key' => 'fixture_id',
'compare' => '!=' ,
'value' => '0') )
));
// Loop over linked posts, store in an array
while($linked_posts_query->have_posts()) : $linked_posts_query->the_post();
$linked_posts[] = array(
'id' => get_the_id(),
'parent-fixture' => get_post_meta(get_the_id(), 'fixture_id', true),
'link' => get_permalink(get_the_id()),
'title' => get_the_title(get_the_id()),
'class' => ( get_post_type( get_the_id() ) == 'photos' ) ? 'fa fa-picture-o' : 'fa fa-file'
);
endwhile;
/* Loop through fixtures array and change the unix times back to a date string.
* Also if any of the results or reports parent_fixture matches the id, insert results/reports into the details of the old fixture
*/
$match_report_col_on = false;
$edit_col_on = false;
$linked_post_on = false;
foreach($past_fixtures as &$past_fixture) :
foreach($results as $result) :
if($past_fixture['id'] == $result['parent-fixture']) :
$past_fixture['result_link'] = $result['link'];
$past_fixture['their-score'] = $result['their-score'];
$past_fixture['our-score'] = $result['our-score'];
$past_fixture['edit-result-link'] = $result['edit-result-link'];
endif;
endforeach;
foreach($linked_posts as $linked_post) :
if($past_fixture['id'] == $linked_post['parent-fixture']) :
$past_fixture['linked_posts'][] = $linked_post;
$linked_post_on = true;
endif;
endforeach;
if(get_edit_post_link( $past_fixture['id'] ) ) $edit_col_on = true;
endforeach;
$past_fixtures = array_reverse( $past_fixtures );
?>
<table class='resultsTable center'>
<tbody>
<?php
foreach($past_fixtures as $past_fixture_print) :
$fixdate = $past_fixture_print['date'];
$opposing = $past_fixture_print['opposing'];
$oppurl = $past_fixture_print['teamurl'];
$past_fixture_print['edit-result-link'] = isset ( $past_fixture_print['edit-result-link'] )
? $past_fixture_print['edit-result-link']
: "<a href='/wp-admin/post-new.php?post_type=results&parent_post=".$past_fixture_print['id']."'>Result</a>";
?>
<tr>
<td class="datecol"><?php if ( isset ($past_fixture_print['result_link'] ) ) : ?><a href='<?php echo $past_fixture_print['result_link'] ?>'><?php echo $fixdate; ?></a><?php else : echo $fixdate; endif; ?></td>
<td><?php echo ($past_fixture_print['homeaway'] == "Home") ? "Bristol Bisons RFC" : team_link($opposing, $oppurl) ?></td>
<?php if (isset ( $past_fixture_print['our-score'] ) && isset ( $past_fixture_print['their-score'] ) ) : ?>
<td class='resultsCell'><?php echo ($past_fixture_print['homeaway'] == "Home") ? $past_fixture_print['our-score'] : $past_fixture_print['their-score'] ?></td>
<td class='resultsCell'><?php echo ($past_fixture_print['homeaway'] == "Home") ? $past_fixture_print['their-score'] : $past_fixture_print['our-score'] ?></td>
<?php else : ?>
<?php if ( current_user_can('edit_post', get_the_id() ) ) : ?>
<td colspan="2"><span class='fa fa-plus-square'><?php echo $past_fixture_print['edit-result-link'] ?></span></td>
<?php else : ?>
<td colspan="2">TBC</td>
<?php endif ?>
<?php endif ?>
<td><?php echo ($past_fixture_print['homeaway'] == "Home") ? team_link($opposing, $oppurl) : "Bristol Bisons RFC" ?></td>
<?php if ($linked_post_on) : ?>
<td<?php if ( ! isset ( $past_fixture_print['linked_posts'] ) ) echo " class='emptycell' " ?>>
<?php if ( isset ( $past_fixture_print['linked_posts'] ) ) : ?>
<ul>
<?php foreach ($past_fixture_print['linked_posts'] as $post ) : ?>
<li class='linked-posts-col'><span class='<?php echo $post['class'] ?>'><a href="<?php echo $post['link']; ?>"><?php echo $post['title']; ?></a></span></li>
<?php endforeach; ?>
</ul>
<?php endif ?>
</td>
<?php endif ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</tbody>
</table>
</section>
<?php $tries = get_stats_chart ( 'try_scored' ) ?>
<?php $MOTM = get_stats_chart ( 'MOTM' ) ?>
<?php $conversions = get_stats_chart ( 'conversion' ) ?>
<?php if ( $tries || $MOTM || $conversions ) : ?>
<h3>Statistics - Top 10s</h3>
<p>The following information is based directly on match event data recorded in the database. If you think you should be included below, please let me know specifically which match you scored a try/conversion/motm in and I will add you to the match result record.
<?php if ( $tries ) : ?>
<h4>Try Scorers</h4>
<table class="center">
<tbody>
<?php $position = 1; foreach ($tries as $user => $tries ) : ?>
<tr>
<td class='smallcol'><?php echo $position ?></td>
<td><?php if ( $url = get_profile_url ( $user ) ) echo "<a href='$url'>" ?><?php $user = get_userdata ( $user ); echo $user->display_name; ?><?php echo $url ? '</a>' : '' ?></td>
<td class='medcol'><?php echo $tries. ' ' . plural_word ( $tries, 'try', 'tries' ) ?></td>
</tr>
<?php $position++; endforeach ?>
</tbody>
</table>
<?php endif ?>
<?php if ( $MOTM ) : ?>
<h4>Men of the Match</h4>
<table class="center">
<tbody>
<?php $position = 1; foreach ($MOTM as $user => $motm ) : ?>
<tr>
<td class='smallcol'><?php echo $position ?></td>
<td><?php if ( $url = get_profile_url ( $user ) ) echo "<a href='$url'>" ?><?php $user = get_userdata ( $user ); echo $user->display_name; ?><?php echo $url ? '</a>' : '' ?></td>
<td class='medcol'><?php echo $motm. ' ' . plural_word ( $motm, 'match', 'matches' ) ?></td>
</tr>
<?php $position++; endforeach ?>
</tbody>
</table>
<?php endif ?>
<?php if ( $conversions ) : ?>
<h4>Conversions</h4>
<table class="center">
<tbody>
<?php $position = 1; foreach ($conversions as $user => $conversion ) : ?>
<tr>
<td class='smallcol'><?php echo $position ?></td>
<td><?php if ( $url = get_profile_url ( $user ) ) echo "<a href='$url'>" ?><?php $user = get_userdata ( $user ); echo $user->display_name; ?><?php echo $url ? '</a>' : '' ?></td>
<td class='medcol'><?php echo $conversion. ' ' . plural_word ( $conversion, 'conversion', 'conversions' ) ?></td>
</tr>
<?php $position++; endforeach ?>
</tbody>
</table>
<?php endif ?>
<?php endif ?>
<?php endif; ?>
<?php
endif;
$seasons = get_terms ( array ( 'seasons' ) );
if ( is_array( $seasons ) ) : ?>
<h3>Previous Seasons</h3>
<table>
<tbody>
<tr>
<?php for ($i = 0; $i < count($seasons); $i++ ) : ?>
<td><span class='fa-li fa fa-folder'></span><a href='<?php echo site_url('/seasons/' . $seasons[$i]->slug) ?>'><?php echo $seasons[$i]->name ?></a></td>
<?php if ($i % 2 && $i != count($seasons) -1) : ?>
</tr>
<tr>
<?php endif ?>
<?php endfor ?>
</tr>
</tbody>
</table>
<?php endif ?>
</div>
</div>
</div>
<?php get_footer(); ?>