-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-concert.php
261 lines (239 loc) · 11.2 KB
/
archive-concert.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
<?php
get_header();
// If there is a year query, e.g. '?y=2012', get it and use it as a variable, else set it to the current year
if (get_query_var('y')) {
if (filter_var(get_query_var('y'), FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range' => 9999,))) !== false) {
$yearquery = get_query_var('y');
}
} else {
// Set correct year query from current date when no query_var present
if (date('m') > 8) {
$yearquery = date('Y') - 1;
} else {
$yearquery = date('Y') - 2;
}
}
// Set season date variables
$seasonstart = $yearquery . '0901';
$seasonend = ($yearquery + 1) . '0831';
$season = array($seasonstart,$seasonend);
// Set pretty season range
// Format 'YYYY–YY' unless turn of century, in which case 'YYYY–YYYY'
if (($yearquery % 100) == 99) {
$seasontitle = $yearquery . '–' . ($yearquery + 1);
} else {
$seasontitle = $yearquery . '–' . str_pad((($yearquery + 1) % 100), 2, '0', STR_PAD_LEFT);
}
// Alter main query for displaying concerts in the loop
query_posts(
array(
'numberposts' => -1,
'post_type' => 'concert',
'meta_key' => 'dtstart',
'orderby' => 'dtstart',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'dtstart',
'value' => $season,
'compare' => 'BETWEEN'
)
)
)
);
// Get archived colloquia
$colloquia = event_query(array(
'post_type' => 'colloquium',
'order' => 'ASC',
'after' => $seasonstart,
'before' => $seasonend,
));
// Get archived miscellaneous events
$miscevents = event_query(array(
'post_type' => 'miscevent',
'order' => 'ASC',
'after' => $seasonstart,
'before' => $seasonend,
));
//
// Let’s start building a select menu
//
$seed = 1984;
if (date('m') > 8) {
$now = date('Y') + 1;
} else {
$now = date('Y');
}
$years = range($seed, $now);
$menuitems = array();
foreach ($years as $year) {
// Set query variables for each year
$querystart = $year . '0901';
$queryend = ($year + 1) . '0831';
// Get archived concerts
$concertcheck = event_query(array(
'maxposts' => 1,
'post_type' => 'concert',
'order' => 'ASC',
'after' => $querystart,
'before' => $queryend,
));
// Get archived colloquia
$colloquiumcheck = event_query(array(
'maxposts' => 1,
'post_type' => 'colloquium',
'order' => 'ASC',
'after' => $querystart,
'before' => $queryend,
));
// Get archived miscellaneous events
$misceventscheck = event_query(array(
'maxposts' => 1,
'post_type' => 'miscevent',
'order' => 'ASC',
'after' => $querystart,
'before' => $queryend,
));
if ($concertcheck || $colloquiumcheck || $misceventscheck) {
$menuitems = array_merge($menuitems, array($year));
}
} // endforeach years checker
$flippedmenuitems = (array_flip($menuitems));
$currentindex = isset($flippedmenuitems[$yearquery]) ? $flippedmenuitems[$yearquery] : null;
$previousyear = isset($menuitems[($currentindex - 1)]) ? $menuitems[($currentindex - 1)] : null;
$nextyear = isset($menuitems[($currentindex + 1)]) ? $menuitems[($currentindex + 1)] : null;
// Check queries to see if it is for a season starting more than a year in the future. N.B. The *next* season will return as false.
echo '<article id="events" class="section--events p-section clearfix">';
if ($seasonstart > date('Ymd', strtotime(date('Ymd', time()) . ' + 365 day'))) {
// What should happen if someone wants to see into the future?
echo '<h2>Archives</h2><p>Welcome to the future! It looks like you’re looking for events in the ' . $seasontitle . ' season, but unfortunately this is neither a time machine nor a crystal ball. Why not <a href="' . get_post_type_archive_link('concert') . '">check out what’s happening right now</a>?</p>';
} elseif ($seasonstart < 19840900) {
// What should happen if it is before HGNM was founded?
echo '<h2>Archives</h2><p>' . $yearquery . '? Harvard Group for New Music wasn’t founded until 1984, so there’s nothing to see for this date. Why not <a href="' . get_post_type_archive_link('concert') . '">check out what’s happening right now</a>?</p>';
} elseif ($seasonstart > date('Ymd') && !have_posts()) {
// What should happen if it is the *next* season but there are no posts
echo '<h2>Archives: ' . $seasontitle . '</h2>'; ?>
<p>We’re busy planning for next season, but the details aren’t available yet. Check back soon and in the meantime, why not <a href="<?php echo get_post_type_archive_link('colloquium') ?>">check out what’s happening right now</a>?</p></p>
<?php
} elseif (!have_posts() && !$colloquia && !$miscevents) {
// What should happen there are no posts
echo '<h2>Archives: ' . $seasontitle . '</h2>'; ?>
<p>Whoops, looks like we don’t have any events for this season. Why not <a href="<?php echo get_post_type_archive_link('colloquium') ?>">check out what’s happening right now</a>?</p></p>
<?php
} else {
// OK, now we’re talking. Check if posts exist?
// Display archive header and navigation
?>
<header class="archive-header">
<h2>Archives<br /><?php echo $seasontitle ?></h2>
<nav id="archive-nav" class="archive-nav clearfix">
<?php if ($previousyear) : ?>
<a href="<?php echo get_post_type_archive_link('concert') . $previousyear . '/'; ?>" class="left">
<?= component('icon', array('type' => 'left-arrow-bold')) ?>
<span class="text">Older Archive</span>
</a>
<?php endif; ?>
<?php if ($nextyear) : ?>
<a href="<?php echo get_post_type_archive_link('concert') . $nextyear . '/'; ?>" class="right">
<span class="text">Newer Archive</span>
<?= component('icon', array('type' => 'right-arrow-bold')) ?>
</a>
<?php endif; ?>
</nav>
</header>
<?php
// Display archived concerts for $yearquery season
if (have_posts()) : ?>
<section class="concerts <?php if (!$colloquia) {
echo 'solo';
} ?>">
<h3 class="sans-sc-h3">Concerts</h3>
<ul>
<?php while (have_posts()) {
the_post();
echo component('concert_list_item', array( "id" => get_the_ID() ));
} ?>
</ul>
</section><?php else: ?>
<?php endif;
// Display archived colloquia for $yearquery season
if ($colloquia) : ?><section class="colloquia <?php if (!have_posts()) {
echo 'solo';
} ?>">
<h3 class="sans-sc-h3">Colloquia</h3>
<?= component('colloquium_list', array("colloquia" => $colloquia)) ?>
</section>
<?php endif;
// Display archived miscellaneous events for $yearquery season
if ($miscevents): ?>
<section class="miscevents">
<h3 class="sans-sc-h3">Other Events</h3>
<ul>
<?php foreach ($miscevents as $miscevent): ?>
<li class="vevent clearfix">
<h4 class="dtstart">
<?php
$dtstart = DateTime::createFromFormat('d/m/Y', get_field('dtstart', $miscevent->ID));
$dtend = DateTime::createFromFormat('d/m/Y', get_field('dtend', $miscevent->ID));
echo '<time class="value-title" datetime="' . $dtstart->format('Y-m-d\TH:i:sO') . '" title="' . $dtstart->format('Y-m-d\TH:i:sO') . '">';
if (get_field('dtend', $miscevent->ID)) :
if ($dtstart->format('n') == $dtend->format('n')) :
echo $dtstart->format('n/j') . '–' . $dtend->format('j'); else :
echo $dtstart->format('n/j') . '–' . $dtend->format('n/j');
endif; ?>
<?php else : ?>
<?php echo $dtstart->format('n/j'); ?>
<?php endif; ?>
</time>
</h4>
<span class="summary"><a href="<?php echo get_permalink($miscevent->ID) ?>" class="url"><?php echo get_the_title($miscevent->ID); ?></a></span>
</li>
<?php endforeach; ?>
</ul>
</section>
<?php endif;
$concerts_with_media = event_query(array(
'post_type' => 'concert',
'has_av' => true,
'after' => $seasonstart,
'before' => $seasonend
));
if (!empty($concerts_with_media)) {
$media_items = array();
foreach ($concerts_with_media as $post) {
while (have_rows('programme')) {
the_row();
$media_item = component('embed_card', array(
'post' => $post
));
if ($media_item) {
$media_items[] = $media_item;
}
}
}
if (!empty($media_items)) {
echo '<section><h3 class="sans-sc-h3">Music</h3>';
echo component('responsive_card_list', array('cards' => $media_items));
echo '</section>';
}
}
if ($menuitems) {
echo '<footer id="years-nav" class="years-nav"><h3>Explore Seasons</h3><ul>';
foreach ($menuitems as $item) {
if (($item % 100) == 99) {
$menulabel = $item . '–' . ($item + 1);
} else {
$menulabel = $item . '–' . str_pad((($item + 1) % 100), 2, '0', STR_PAD_LEFT);
}
echo '<li';
if ($item == $yearquery) {
echo ' class="current"';
}
echo '><a href="' . get_post_type_archive_link('concert') . $item . '/">' . $menulabel . '</a></li>';
}
echo '</ul></footer>';
}
}
echo '</article>';
get_footer();
?>