-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxonomy-seasons.php
201 lines (172 loc) · 8.5 KB
/
taxonomy-seasons.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
<?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>Season Archive (<?php global $wp_query; echo $wp_query->queried_object->name ?>)</h2>
<ul class='pageMenu'>
<?php if ( current_user_can('edit_post', get_the_id() ) ) { ?>
<li><a class='fa fa-plus-square fa-lg' 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 fa-lg' href='<?php echo str_replace ( 'http://', 'webcal://', site_url('/calendar.ics?of=fixtures'))?>'>iCal (fixtures)<a/></li>
<li><a class='fa fa-rss-square fa-lg' 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();
$results = array();
// Handle a lack of fixtures
if(! have_posts() ) : ?>
<p>Normally this page contains the details of all the upcoming fixtures for this season. It looks like the committee haven't uploaded them yet, try back later. Alternatively, check the <a href="#">fixture archive</a>.</p>
<?php endif;
// 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-page');
$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)
);
$fixtures[] = $fixture;
endwhile;
if( $fixtures ) : ?>
<section class="clearsection">
<h3>Fixture Results</h3>
<p>Results for this season are below. 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(
'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' => 'post',
'nopaging' => 'true', 'meta_query' => array (
'relation' => 'AND',
array(
'key' => 'fixture_id',
'compare' => 'EXISTS' ),
array(
'key' => 'fixture_id',
'compare' => '!=' ,
'value' => '0') )
));
// Loop over reports, 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())
);
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($fixtures as &$fixture) :
foreach($results as $result) :
if($fixture['id'] == $result['parent-fixture']) :
$fixture['their-score'] = $result['their-score'];
$fixture['our-score'] = $result['our-score'];
$fixture['edit-result-link'] = $result['edit-result-link'];
endif;
endforeach;
foreach($linked_posts as $linked_post) :
if($fixture['id'] == $linked_post['parent-fixture']) :
$fixture['linked_posts'][] = $linked_post;
$linked_post_on = true;
endif;
endforeach;
if(get_edit_post_link( $fixture['id'] ) ) $edit_col_on = true;
endforeach;
$fixtures = array_reverse( $fixtures );
?>
<table class='resultsTable center'>
<tbody>
<?php
foreach($fixtures as $fixture) :
$fixdate = $fixture['date'];
$opposing = $fixture['opposing'];
$oppurl = $fixture['teamurl'];
$fixture['edit-result-link'] = isset ( $fixture['edit-result-link'] )
? $fixture['edit-result-link']
: "<a href='/wp-admin/post-new.php?post_type=results&parent_post=".$fixture['id']."'>Result</a>";
?>
<tr>
<td class="datecol"><?php echo $fixdate; ?></td>
<td><?php echo ($fixture['homeaway'] == "Home") ? "Bristol Bisons RFC" : '<a href='.$fixture['teamurl'].'>'.$fixture['opposing'].'</a></td>' ?></td>
<?php if (isset ( $fixture['our-score'] ) && isset ( $fixture['their-score'] ) ) : ?>
<td class='resultsCell'><?php echo ($fixture['homeaway'] == "Home") ? $fixture['our-score'] : $fixture['their-score'] ?></td>
<td class='resultsCell'><?php echo ($fixture['homeaway'] == "Home") ? $fixture['their-score'] : $fixture['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 $fixture['edit-result-link'] ?></span></td>
<?php else : ?>
<td colspan="2">TBC</td>
<?php endif ?>
<?php endif ?>
<td><?php echo ($fixture['homeaway'] == "Home") ? '<a href='.$fixture['teamurl'].'>'.$fixture['opposing'].'</a></td>' : "Bristol Bisons RFC" ?></td>
<?php if ($linked_post_on) : ?>
<td<?php if ( ! isset ( $fixture['linked_posts'] ) ) echo " class='emptycell' " ?>>
<?php if ( isset ( $fixture['linked_posts'] ) ) : ?>
<ul>
<?php foreach ($fixture['linked_posts'] as $post ) : ?>
<li class='linked-posts-col'><span class='fa fa-file'><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 endif; ?>
</div>
</div>
</div>
<?php get_footer(); ?>