-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpbenelux_schedule_widget.php
346 lines (323 loc) · 12.2 KB
/
phpbenelux_schedule_widget.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
<?php
/*
Plugin Name: PHPBenelux Schedule
Version: 1.0
Plugin URI: http://phpbenelux.eu
Description: Schedule plugin
Author: Martin de Keijzer
Author URI: http://phpbenelux.eu/
*/
add_action( 'widgets_init', 'phpbenelux_schedule_widget_init' );
add_action( 'wp_enqueue_scripts','enqueue_phpbenelux_schedule_styles');
function phpbenelux_schedule_widget_init() {
register_widget( 'phpbenelux_schedule_widget' );
}
function enqueue_phpbenelux_schedule_styles() {
wp_enqueue_style('related-styles', plugins_url('/schedule.css', __FILE__));
}
class phpbenelux_schedule_widget extends WP_Widget
{
const FRIDAY = 24;
const SATURDAY = 25;
const START_KEYNOTE = 1579869000;
/**
* @var array
*/
protected $schedule;
/**
* phpbenelux_schedule_widget constructor
*/
public function __construct()
{
$widget_details = array(
'classname' => 'phpbenelux_schedule_widget',
'description' => 'Shows the schedule for PHPBenelux Conference'
);
parent::__construct( 'phpbenelux_schedule_widget', 'PHPBenelux schedule Widget', $widget_details );
}
/**
* @param array $instance
*
* @return void
*/
public function form($instance) {
// Backend Form
}
/**
* @param array $args
* @param array $instance
*
* @throws Exception
*/
public function widget($args, $instance) {
?>
<p>Jump to:</p>
<div class="row jumplist">
<div class="col-md-4"><a class="btn btn-info" href="#tutorials">Friday Tutorials</a></div>
<div class="col-md-4"><a class="btn btn-info" href="#friday-afternoon">Friday Conference</a></div>
<div class="col-md-4"><a class="btn btn-info" href="#saturday">Saturday Conference</a></div>
</div>
<div class="row">
<div class="col-xs-12"> </div>
</div>
<div class="schedule">
<header class="post-heading clearfix">
<h2 class="date-inner">Friday</h2>
<div class="post-title-wrapper">
<h3 class="post-title">Morning tutorials (tutorial tickets only)</h3></div>
</header>
<a id="tutorials"> </a>
<p>For the tutorial rooms you'll be given directions upon registration.</p>
<?php
$this->renderTutorials();
?>
<div class="row">
<div class="col-xs-2 with-border">12:30 - 13:00</div>
<div class="col-xs-10 text-center with-border"><h5><a href="#">Tutorial lunch</a></h5></div>
</div>
<div class="row">
<div class="col-xs-12"> </div>
</div>
<header class="post-heading clearfix">
<h2 class="date-inner">Friday</h2>
<div class="post-title-wrapper">
<h3 class="post-title">Afternoon conference</h3></div>
</header>
<a id="friday-afternoon"> </a>
<div class="row hidden-xs">
<div class="col-xs-2 with-border"> </div>
<div class="col-xs-10 text-center with-border"><h3>Auditorium</h3></div>
</div>
<div class="row">
<div class="col-xs-2 with-border">13:20 - 13:30</div>
<div class="col-xs-10 text-center with-border"><h5><a href="#">Welcome & Introduction</a></h5></div>
</div>
<div class="row">
<div class="col-xs-2 with-border">13:30 - 14:30</div>
<div class="col-xs-10 text-center with-border">
<?php $this->renderKeynote(); ?>
</div>
</div>
<div class="row">
<div class="col-xs-12"> </div>
</div>
<div class="row hidden-xs">
<div class="col-xs-2 col-xs-2-5 with-border"> </div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track A<br> (Beethoven)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track B<br> (Permeke)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track C<br> (Rubens)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Uncon<br> (Van Gogh)</h3></div>
</div>
<?php
$this->renderTalks(self::FRIDAY);
?>
<div class="row">
<div class="col-xs-12"> </div>
</div>
<header class="post-heading clearfix">
<h2 class="date-inner">Saturday</h2>
<div class="post-title-wrapper">
<h3 class="post-title">Conference</h3></div>
</header>
<a id="saturday"> </a>
<div class="row hidden-xs">
<div class="col-xs-2 col-xs-2-5 with-border hidden-xs"> </div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track A<br> (Beethoven)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track B<br> (Permeke)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Track C<br> (Rubens)</h3></div>
<div class="col-xs-2 col-xs-2-5 with-border"><h3>Uncon<br> (Van Gogh)</h3></div>
</div>
<?php
$this->renderTalks(self::SATURDAY);
?>
</div>
<?php
}
/**
* Render the keynote session
*/
protected function renderKeynote()
{
$args = array(
'numberposts' => -1,
'post_type' => 'sessions',
'meta_key' => 'session_type',
'meta_value' => 'keynote',
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
/** @var array $speakers */
$speakers = get_field('speakers');
?>
<h5><a href="<?php echo get_the_permalink()?>">
<?php echo the_title(); ?>
</a></h5>
<?php
if ($speakers) {
foreach ($speakers as $speaker) {
?><a href="<?php echo get_the_permalink($speaker->ID); ?>"><?php echo get_the_title( $speaker->ID ); ?></a><?php
}
}
}
} else {
echo 'To be announced soon...';
}
wp_reset_query();
}
/**
* Render the tutorial sessions
*/
protected function renderTutorials()
{
$args = array(
'numberposts' => -1,
'post_type' => 'sessions',
'meta_key' => 'session_type',
'meta_value' => 'tutorial',
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) {
$postCounter = 0;
while ($the_query->have_posts()) {
if ($postCounter % 4 === 0) {
if ($postCounter !== 0) {
echo '</div>';
}
?>
<div class="row">
<div class="col-xs-2 col-xs-2-5 with-border">
09:00 - 12:30
</div>
<?php
}
$the_query->the_post();
/** @var array $speakers */
$speakers = get_field('speakers');
?>
<div class="col-xs-2 col-xs-2-5 with-border">
<h5><a href="<?php echo get_the_permalink()?>"><?php echo the_title(); ?></a></h5>
<?php
if ($speakers) {
foreach ($speakers as $speaker) {
?><a href="<?php echo get_the_permalink($speaker->ID); ?>"><?php
echo get_the_title( $speaker->ID );
?></a><?php
}
}
?>
</div>
<?php
$postCounter++;
}
?></div><?php
}
wp_reset_query();
wp_reset_postdata();
}
/**
* Render the talks for a certain day
*
* @param int $dayToShow
*
* @throws Exception
*/
protected function renderTalks($dayToShow)
{
if ($this->schedule === null) {
$this->loadSchedule();
}
/** @var array $todaysSchedule */
$todaysSchedule = $this->schedule[$dayToShow];
ksort($todaysSchedule);
/** @var array $timeSlot */
foreach ($todaysSchedule as $timeSlot) {
ksort($timeSlot);
$firstItem = reset($timeSlot);
if ((int) $firstItem['start'] <= self::START_KEYNOTE) {
continue;
}
$startTime = new \DateTime();
$startTime->setTimestamp($firstItem['start']);
$endTime = new \DateTime();
$endTime->setTimestamp($firstItem['end']);
$cssSessionClass = '';
$cssTimeClass = '';
if (count($timeSlot) > 1) {
$cssSessionClass = 'col-xs-2 col-xs-2-5';
$cssTimeClass = $cssSessionClass;
}
if (count($timeSlot) === 1) {
$cssSessionClass = 'col-xs-10 text-center';
$cssTimeClass = 'col-xs-2';
}
?>
<div class="row">
<div class="<?php echo $cssTimeClass; ?> with-border"><?php echo $startTime->format('H:i') ?> - <?php echo $endTime->format('H:i') ?></div>
<?php foreach ($timeSlot as $session) { ?>
<div class="<?php echo $cssSessionClass; ?> with-border">
<h5><a href="<?php echo $session['link']; ?>"><?php echo $session['title']; ?></a></h5>
<?php
/** @var array $speakers */
$speakers = $session['speakers'];
foreach ($speakers as $speaker) { ?>
<a href="<?php echo $speaker['link']; ?>"><?php echo $speaker['name']; ?></a>
<?php } ?>
</div>
<?php } ?>
</div>
<?php
}
}
protected function loadSchedule()
{
$speakers = array();
$schedule = array(
self::FRIDAY => array(),
self::SATURDAY => array(),
);
$args = array(
'posts_per_page' => 5000,
'post_type' => 'sessions',
'meta_query' => array(
'key' => 'session_type',
'value' => array( 'talk', 'social' ),
'compare' => 'IN',
)
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
$start = get_field('start');
$room = get_field('room');
$startDate = new \DateTime();
$startDate->setTimestamp($start);
$day = $startDate->format('d');
/** @var array $registeredSpeakers */
$registeredSpeakers = get_field('speakers');
if ($registeredSpeakers) {
foreach ($registeredSpeakers as $speaker) {
$speakers[] = array(
'name' => get_the_title($speaker->ID),
'link' => get_the_permalink($speaker->ID),
);
}
}
$schedule[(int) $day][$start][$room] = array(
'post_id' => get_the_ID(),
'start' => get_field('start'),
'end' => get_field('end'),
'title' => get_the_title(),
'link' => get_the_permalink(),
'speakers' => $speakers,
);
$speakers = array();
}
}
$this->schedule = $schedule;
wp_reset_query();
wp_reset_postdata();
}
}