initfest/schedule/parse.php

267 lines
7.2 KiB
PHP
Raw Normal View History

<?php
function parseData($config, $data) {
$time = 0;
$date = 0;
$lines = [];
$fulltalks = '';
$prev_event_id = 0;
$colspan = 1;
$languages = array(
'en' => array(
'name' => 'English',
'locale' => 'en_US.UTF8'
),
'bg' => array(
'name' => 'Български',
'locale' => 'bg_BG.UTF8'
)
);
2016-10-22 19:09:03 +03:00
// We need to set these so we actually parse properly the dates. WP fucks up both.
date_default_timezone_set('Europe/Sofia');
setlocale(LC_TIME, $languages[$config['lang']]['locale']);
// Filter out invalid slots
2016-10-22 03:30:31 +03:00
$data['slots'] = array_filter($data['slots'], function($slot) {
return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']);
});
2016-10-22 19:09:03 +03:00
// Collect the events for each hall, sort them in order of starting
$events = [];
2016-10-22 19:09:03 +03:00
$microslots = [];
foreach ($data['halls'] as $hall_id => $hall) {
$events[$hall_id] = [];
foreach ($data['slots'] as $slot_id => $slot) {
if ($slot['hall_id'] !== $hall_id) {
continue;
}
2016-10-22 17:22:04 +03:00
if (!in_array($slot['starts_at'], $microslots)) {
$microslots[] = $slot['starts_at'];
}
2016-10-22 17:22:04 +03:00
if (!in_array($slot['ends_at'], $microslots)) {
$microslots[] = $slot['ends_at'];
}
$events[$hall_id][$slot['starts_at']] = $slot;
}
ksort($events[$hall_id]);
}
2016-10-22 17:22:04 +03:00
sort($microslots);
2016-10-22 19:09:03 +03:00
// Find all microslots (the smallest time unit)
$intervals = [];
$lastTs = 0;
$first = true;
2016-10-22 19:09:03 +03:00
foreach ($microslots as $ts) {
if ($first) {
$lastTs = $ts;
$first = false;
continue;
}
2016-10-22 19:09:03 +03:00
if (date('d.m', $lastTs) !== date('d.m', $ts)) {
$lastTs = $ts;
continue;
}
$intervals[] = [$lastTs, $ts];
$lastTs = $ts;
}
2016-10-22 19:09:03 +03:00
// Fill in the event ID for each time slot in each hall
$slot_list = [];
foreach ($data['halls'] as $hall_id => $hall) {
$hall_data = [];
foreach ($intervals as $timestamps) {
$found = false;
foreach ($data['slots'] as $slot_id => $slot) {
if (
$slot['hall_id'] === $hall_id &&
$slot['starts_at'] <= $timestamps[0] &&
$slot['ends_at'] >= $timestamps[1]
) {
$found = true;
$hall_data[] = [
'event_id' => $slot['event_id'],
'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1],
];
break;
}
}
if (!$found) {
$hall_data[] = null;
}
}
2016-10-22 19:09:03 +03:00
$slot_list[] = $hall_data;
}
2016-10-22 19:09:03 +03:00
// Transpose the matrix
// rows->halls, cols->timeslots ===> rows->timeslots, cols->halls
$slot_list = array_map(null, ...$slot_list);
// Build the HTML
$schedule = '<table border="1"><thead><tr><th></th>';
2016-10-22 19:09:03 +03:00
foreach ($data['halls'] as $hall_id => $hall) {
$schedule .= '<th>' . $hall['bg'] . '</th>';
}
2016-10-22 19:09:03 +03:00
$schedule .= '</tr></thead><tbody>';
2016-10-22 17:22:04 +03:00
$lastTs = 0;
2016-10-22 19:09:03 +03:00
foreach ($slot_list as $slot_index => $events) {
$columns = [];
$hasEvents = false;
2016-10-22 17:22:04 +03:00
if (date('d.m', $intervals[$slot_index][0]) !== date('d.m', $lastTs)) {
2016-10-22 19:09:03 +03:00
$schedule .= '<tr><th colspan="' . (count($events) + 1) . '">' . strftime('%d %B - %A', $intervals[$slot_index][0]) . '</th></tr>';
2016-10-22 17:22:04 +03:00
}
$lastTs = $intervals[$slot_index][0];
$lastEventId = 0;
2016-10-22 19:09:03 +03:00
$colspan = 1;
2016-10-22 17:22:04 +03:00
2016-10-22 19:09:03 +03:00
foreach ($events as $hall_index => $hall_data) {
if (is_null($hall_data['event_id']) || !array_key_exists($hall_data['event_id'], $data['events'])) {
$columns[] = '<td>&nbsp;</td>';
continue;
}
2016-10-22 19:09:03 +03:00
if ($hall_data['edge']) {
$hasEvents = true;
}
2016-10-22 17:22:04 +03:00
2016-10-22 19:09:03 +03:00
$eid = &$hall_data['event_id'];
$event = &$data['events'][$eid];
$title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : '');
$speakers = '';
if (count($event['participant_user_ids']) > 0) {
$spk = array();
$speaker_name = array();
foreach ($event['participant_user_ids'] as $uid) {
2016-10-22 19:09:03 +03:00
if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) {
continue;
}
2016-10-22 19:09:03 +03:00
$name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name'];
$spk[$uid] = '<a class="vt-p" href="#' . $name . '">' . $name . '</a>';
}
$speakers = implode (', ', $spk);
}
2016-10-22 19:09:03 +03:00
if (in_array($event['track_id'], $config['hidden_language_tracks'])) {
$csslang = '';
2016-10-22 19:09:03 +03:00
} else {
$csslang = 'schedule-' . $event['language'];
}
2016-10-22 19:09:03 +03:00
$cssclass = &$data['tracks'][$event['track_id']]['css_class'];
$style = ' class="' . $cssclass . ' ' . $csslang . '"';
2016-10-22 19:09:03 +03:00
$content = '<a href="#lecture-' . $eid . '">' . htmlspecialchars($title) . '</a><br>' . $speakers;
/* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */
$fulltalks .= '<section id="lecture-' . $eid . '">';
/* We don't want '()' when we don't have a speaker name */
2016-10-22 19:09:03 +03:00
$fulltalk_spkr = strlen($speakers) > 0 ? (' (' . $speakers . ')') : '';
$fulltalks .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong></p>';
$fulltalks .= '<p>' . $event['abstract'] . '</p>';
$fulltalks .= '<div class="separator"></div></section>';
2016-10-22 19:09:03 +03:00
/*
if ($eid === $lastEventId) {
array_pop($columns);
++$colspan;
}
else {
$colspan = 1;
}
2016-10-22 19:09:03 +03:00
*/
$columns[] = '<td' . $style . ($colspan > 1 ? ' colspan="' . $colspan . '"' : '') . '>' . $content . '</td>';
$lastEventId = $eid;
}
2016-10-22 19:09:03 +03:00
if (!$hasEvents) {
continue;
}
$schedule .= '<tr><td>';
$schedule .= strftime('%H:%M', $intervals[$slot_index][0]) . ' - ' . strftime('%H:%M', $intervals[$slot_index][1]);
$schedule .= '</td>';
$schedule .= implode('', $columns);
$schedule .= '</tr>';
}
2016-10-22 19:09:03 +03:00
$schedule .= '</tbody></table>';
// Create the legend
$legend = '';
foreach($data['tracks'] as $track) {
$legend .= '<tr><td class="' . $track['css_class'] . '">' . $track['name'][$config['lang']] . '</td></tr>';
}
foreach ($languages as $code => $lang) {
$legend .= '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>';
}
2016-10-22 19:09:03 +03:00
// Speaker list
$gspk = '<div class="grid members">';
$fspk = '';
$types = [
'twitter' => [
'class' => 'twitter',
'url' => 'https://twitter.com/',
],
'github' => [
'class' => 'github',
'url' => 'https://github.com/',
],
'email' => [
'class' => 'envelope',
'url' => 'mailto:',
],
];
foreach ($data['speakers'] as $speaker) {
$name = $speaker['first_name'] . ' ' . $speaker['last_name'];
$gspk .= '<div class="member col4">';
$gspk .= '<a href="#' . $name . '">';
$gspk .= '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'] . '" class="attachment-100x100 wp-post-image" alt="' . $name . '" />';
$gspk .= '</a> </div>';
$fspk .= '<div class="speaker" id="' . $name . '">';
$fspk .= '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'] . '" class="attachment-100x100 wp-post-image" alt="' . $name . '" />';
$fspk .= '<h3>' . $name . '</h3>';
$fspk .= '<div class="icons">';
foreach ($types as $type => $param) {
if (!empty($speaker[$type])) {
$fspk .= '<a href="' . $param['url'] . $speaker[$type] . '"><i class="fa fa-' . $param['class'] . '"></i></a>';
}
}
$fspk .= '</div>';
$fspk .= '<p>' . $speaker['biography'] . '</p>';
$fspk .= '</div><div class="separator"></div>';
}
$gspk .= '</div>';
2016-10-22 19:09:03 +03:00
return compact('schedule', 'fulltalks', 'gspk', 'fspk', 'legend');
}