Remove unused variables, add filter by event type, rewrite CSS class generation

This commit is contained in:
Vencislav Atanasov 2016-10-24 00:16:00 +03:00
parent a807406eb0
commit 48a0fa9c5f
2 changed files with 42 additions and 23 deletions

View File

@ -9,7 +9,7 @@ require $requirePath . 'load.php';
require $requirePath . 'parse.php'; require $requirePath . 'parse.php';
$sched_config = getSchedConfig(date('Y')); $sched_config = getSchedConfig(date('Y'));
$data = loadData($sched_config); $data = loadData($sched_config);
//$sched_config['filterEventType'] = 'workshop'; $sched_config['filterEventType'] = array_key_exists('event_type', $_GET) ? $_GET['event_type'] : null;
$content = parseData($sched_config, $data); $content = parseData($sched_config, $data);
?> ?>
<html> <html>

View File

@ -1,12 +1,5 @@
<?php <?php
function parseData($config, $data) { function parseData($config, $data) {
$time = 0;
$date = 0;
$lines = [];
$fulltalks = '';
$prev_event_id = 0;
$colspan = 1;
$languages = array( $languages = array(
'en' => array( 'en' => array(
'name' => 'English', 'name' => 'English',
@ -78,7 +71,12 @@ function parseData($config, $data) {
// Fill in the event ID for each time slot in each hall // Fill in the event ID for each time slot in each hall
$events = []; $events = [];
$filtered_type_id =
array_key_exists('filterEventType', $config) &&
array_key_exists($config['filterEventType'], $config['eventTypes']) ?
$config['eventTypes'][$config['filterEventType']] :
null;
foreach ($data['halls'] as $hall_id => $hall) { foreach ($data['halls'] as $hall_id => $hall) {
$hall_data = []; $hall_data = [];
@ -92,6 +90,12 @@ function parseData($config, $data) {
$slot['ends_at'] >= $timestamps[1] && $slot['ends_at'] >= $timestamps[1] &&
array_key_exists($slot['event_id'], $data['events']) array_key_exists($slot['event_id'], $data['events'])
) { ) {
if (!is_null($filtered_type_id)) {
if ($data['events'][$slot['event_id']]['event_type_id'] !== $filtered_type_id) {
continue;
}
}
$found = true; $found = true;
$hall_data[] = [ $hall_data[] = [
'event_id' => $slot['event_id'], 'event_id' => $slot['event_id'],
@ -196,6 +200,7 @@ function parseData($config, $data) {
$schedule .= '</tr></thead><tbody>'; $schedule .= '</tr></thead><tbody>';
$lastTs = 0; $lastTs = 0;
$fulltalks = '';
foreach ($events as $slot_index => $events_data) { foreach ($events as $slot_index => $events_data) {
$columns = []; $columns = [];
@ -225,32 +230,27 @@ function parseData($config, $data) {
$speakers = ''; $speakers = '';
if (count($event['participant_user_ids']) > 0) { if (count($event['participant_user_ids']) > 0) {
$spk = array(); $spk = [];
$speaker_name = array();
foreach ($event['participant_user_ids'] as $uid) { foreach ($event['participant_user_ids'] as $uid) {
if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) { if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) {
continue; continue;
} }
$name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name'];
$spk[$uid] = '<a class="vt-p" href="#' . $name . '">' . $name . '</a>'; $spk[] = '<a class="vt-p" href="#' . $name . '">' . $name . '</a>';
} }
$speakers = implode (', ', $spk); $speakers = implode (', ', $spk);
} }
if (in_array($event['track_id'], $config['hidden_language_tracks'])) {
$csslang = '';
} else {
$csslang = 'schedule-' . $event['language'];
}
$cssclass = &$data['tracks'][$event['track_id']]['css_class'];
$style = ' class="' . $cssclass . ' ' . $csslang . '"';
$content = '<a href="#lecture-' . $eid . '">' . htmlspecialchars($title) . '</a><br>' . $speakers; $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) */ // these are done by $eid, as otherwise we get some talks more than once (for example the lunch)
// TODO: fix this, it's broken
$fulltalks .= '<section id="lecture-' . $eid . '">'; $fulltalks .= '<section id="lecture-' . $eid . '">';
/* We don't want '()' when we don't have a speaker name */
// We don't want '()' when we don't have a speaker name
$fulltalk_spkr = strlen($speakers) > 0 ? (' (' . $speakers . ')') : ''; $fulltalk_spkr = strlen($speakers) > 0 ? (' (' . $speakers . ')') : '';
$fulltalks .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong></p>'; $fulltalks .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong></p>';
$fulltalks .= '<p>' . $event['abstract'] . '</p>'; $fulltalks .= '<p>' . $event['abstract'] . '</p>';
@ -265,8 +265,27 @@ function parseData($config, $data) {
} }
$rowspan = array_key_exists('rowspan', $event_info) ? (' rowspan="' . $event_info['rowspan'] . '"') : ''; $rowspan = array_key_exists('rowspan', $event_info) ? (' rowspan="' . $event_info['rowspan'] . '"') : '';
$columns[] = '<td' . $style . ($colspan > 1 ? ' colspan="' . $colspan . '"' : $rowspan) . '>' . $content . '</td>';
// CSS
$cssClasses = [];
if (!in_array($event['track_id'], $config['hidden_language_tracks'])) {
$cssClasses[] = 'schedule-' . $event['language'];
}
$cssClass = $data['tracks'][$event['track_id']]['css_class'];
if (strlen($cssClass) > 0) {
$cssClasses[] = $cssClass;
}
$cssClasses = count($cssClasses) > 0 ? (' class="' . implode(' ', $cssClasses) . '"') : '';
// Render cell
$columns[] = '<td' . ($colspan > 1 ? ' colspan="' . $colspan . '"' : $rowspan) . $cssClasses . '>' . $content . '</td>';
$lastEventId = $eid; $lastEventId = $eid;
unset($eid, $event);
} }
$schedule .= '<tr><td>'; $schedule .= '<tr><td>';