Fix for unset events

This commit is contained in:
Vencislav Atanasov 2023-10-16 21:21:55 +03:00
parent 4b072dc2df
commit b33da1563f
1 changed files with 59 additions and 59 deletions

View File

@ -13,8 +13,8 @@ function parseData($config, $data) {
'locale' => 'bg_BG.UTF8' 'locale' => 'bg_BG.UTF8'
) )
); );
if ($data === false) return false; if ($data === false) return false;
// We need to set these so we actually parse properly the dates. WP fucks up both. // We need to set these so we actually parse properly the dates. WP fucks up both.
date_default_timezone_set('Europe/Sofia'); date_default_timezone_set('Europe/Sofia');
@ -24,7 +24,7 @@ function parseData($config, $data) {
$data['slots'] = array_filter($data['slots'], function($slot) { $data['slots'] = array_filter($data['slots'], function($slot) {
return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']);
}); });
// Collect the slots for each hall, sort them in order of starting // Collect the slots for each hall, sort them in order of starting
$slots = []; $slots = [];
$timestamps = []; $timestamps = [];
@ -37,7 +37,7 @@ function parseData($config, $data) {
foreach ($data['halls'] as $hall_id => $hall) { foreach ($data['halls'] as $hall_id => $hall) {
$slots[$hall_id] = []; $slots[$hall_id] = [];
foreach ($data['slots'] as $slot_id => $slot) { foreach ($data['slots'] as $slot_id => $slot) {
if ($slot['hall_id'] !== $hall_id) { if ($slot['hall_id'] !== $hall_id) {
continue; continue;
@ -48,11 +48,11 @@ function parseData($config, $data) {
if ($etype !== $filtered_type_id && !is_null($filtered_type_id)) { if ($etype !== $filtered_type_id && !is_null($filtered_type_id)) {
continue; continue;
} }
if (!in_array($slot['starts_at'], $timestamps)) { if (!in_array($slot['starts_at'], $timestamps)) {
$timestamps[] = $slot['starts_at']; $timestamps[] = $slot['starts_at'];
} }
if (!in_array($slot['ends_at'], $timestamps)) { if (!in_array($slot['ends_at'], $timestamps)) {
$timestamps[] = $slot['ends_at']; $timestamps[] = $slot['ends_at'];
} }
@ -62,26 +62,26 @@ function parseData($config, $data) {
ksort($slots[$hall_id]); ksort($slots[$hall_id]);
if (empty($slots[$hall_id])) unset($slots[$hall_id]); if (empty($slots[$hall_id])) unset($slots[$hall_id]);
} }
sort($timestamps); sort($timestamps);
// Find all microslots (the smallest time unit) // Find all microslots (the smallest time unit)
$microslots = []; $microslots = [];
$lastTs = 0; $lastTs = 0;
$first = true; $first = true;
foreach ($timestamps as $ts) { foreach ($timestamps as $ts) {
if ($first) { if ($first) {
$lastTs = $ts; $lastTs = $ts;
$first = false; $first = false;
continue; continue;
} }
if (date('d.m', $lastTs) !== date('d.m', $ts)) { if (date('d.m', $lastTs) !== date('d.m', $ts)) {
$lastTs = $ts; $lastTs = $ts;
continue; continue;
} }
$microslots[] = [$lastTs, $ts]; $microslots[] = [$lastTs, $ts];
$lastTs = $ts; $lastTs = $ts;
} }
@ -90,10 +90,10 @@ function parseData($config, $data) {
foreach ($data['halls'] as $hall_id => $hall) { foreach ($data['halls'] as $hall_id => $hall) {
$hall_data = []; $hall_data = [];
foreach ($microslots as $timestamps) { foreach ($microslots as $timestamps) {
$found = false; $found = false;
foreach ($data['slots'] as $slot_id => $slot) { foreach ($data['slots'] as $slot_id => $slot) {
if ( if (
$slot['hall_id'] === $hall_id && $slot['hall_id'] === $hall_id &&
@ -106,7 +106,7 @@ function parseData($config, $data) {
continue; continue;
} }
} }
$found = true; $found = true;
$hall_data[] = [ $hall_data[] = [
'event_id' => $slot['event_id'], 'event_id' => $slot['event_id'],
@ -116,12 +116,12 @@ function parseData($config, $data) {
break; break;
} }
} }
if (!$found) { if (!$found) {
$hall_data[] = null; $hall_data[] = null;
} }
} }
$events[$hall_id] = $hall_data; $events[$hall_id] = $hall_data;
} }
// Remove halls with no events after filtering // Remove halls with no events after filtering
@ -146,25 +146,25 @@ function parseData($config, $data) {
foreach($events as $i => $val) { foreach($events as $i => $val) {
$hall_count = count($events[$i]); $hall_count = count($events[$i]);
$hasEvents = false; $hasEvents = false;
for ($j = 0; $j < $hall_count; ++$j) { for ($j = 0; $j < $hall_count; ++$j) {
if (!is_null($events[$i][$j]) && $events[$i][$j]['edge']) { if (!is_null($events[$i][$j]) && $events[$i][$j]['edge']) {
$hasEvents = true; $hasEvents = true;
continue 2; continue 2;
} }
} }
if (!$hasEvents) { if (!$hasEvents) {
unset($events[$i]); unset($events[$i]);
} }
} }
// Merge events longer than one slot // Merge events longer than one slot
$prevEventId = []; $prevEventId = [];
$prevEventSlot = []; $prevEventSlot = [];
$prevSlotIndex = 0; $prevSlotIndex = 0;
$first = true; $first = true;
foreach ($events as $slot_index => &$events_data) { foreach ($events as $slot_index => &$events_data) {
if ($first) { if ($first) {
$prevEventId = array_map(function($event_info) { $prevEventId = array_map(function($event_info) {
@ -175,46 +175,46 @@ function parseData($config, $data) {
$first = false; $first = false;
continue; continue;
} }
foreach ($events_data as $hall_index => &$event_info) { foreach ($events_data as $hall_index => &$event_info) {
if (is_null($event_info)) { if (is_null($event_info)) {
$prevEventId[$hall_index] = null; $prevEventId[$hall_index] = null;
$prevEventSlot[$hall_index] = null; $prevEventSlot[$hall_index] = null;
continue; continue;
} }
if ($event_info['event_id'] !== $prevEventId[$hall_index]) { if ($event_info['event_id'] !== $prevEventId[$hall_index]) {
$prevEventId[$hall_index] = $event_info['event_id']; $prevEventId[$hall_index] = $event_info['event_id'];
$prevEventSlot[$hall_index] = null; $prevEventSlot[$hall_index] = null;
continue; continue;
} }
// We have a long event // We have a long event
if (is_null($prevEventSlot[$hall_index])) { if (is_null($prevEventSlot[$hall_index])) {
$prevEventSlot[$hall_index] = $prevSlotIndex; $prevEventSlot[$hall_index] = $prevSlotIndex;
} }
$master_slot = &$events[$prevEventSlot[$hall_index]][$hall_index]; $master_slot = &$events[$prevEventSlot[$hall_index]][$hall_index];
if (!array_key_exists('rowspan', $master_slot)) { if (!array_key_exists('rowspan', $master_slot)) {
$master_slot['rowspan'] = 2; $master_slot['rowspan'] = 2;
} }
else { else {
++$master_slot['rowspan']; ++$master_slot['rowspan'];
} }
unset($master_slot); unset($master_slot);
$event_info = false; $event_info = false;
} }
unset($event_info); unset($event_info);
$prevSlotIndex = $slot_index; $prevSlotIndex = $slot_index;
} }
unset($events_data); unset($events_data);
// Build the HTML // Build the HTML
$schedule_body = ''; $schedule_body = '';
$lastTs = 0; $lastTs = 0;
@ -226,36 +226,36 @@ function parseData($config, $data) {
foreach ($events as $slot_index => $events_data) { foreach ($events as $slot_index => $events_data) {
$columns = []; $columns = [];
if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) {
$schedule_body .= '<tr><th colspan="' . (count($events_data) + 1) . '">' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '</th></tr>'; $schedule_body .= '<tr><th colspan="' . (count($events_data) + 1) . '">' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '</th></tr>';
} }
$lastTs = $microslots[$slot_index][0]; $lastTs = $microslots[$slot_index][0];
$lastEventId = 0; $lastEventId = 0;
$colspan = 1; $colspan = 1;
foreach ($events_data as $event_info) { foreach ($events_data as $event_info) {
if ($event_info === false) { if ($event_info === false) {
continue; continue;
} }
if (is_null($event_info['event_id'])) { if (is_null($event_info) || is_null($event_info['event_id'])) {
$columns[] = '<td>&nbsp;</td>'; $columns[] = '<td>&nbsp;</td>';
continue; continue;
} }
if (!in_array($event_info['hall_id'], $hall_ids)) { if (!in_array($event_info['hall_id'], $hall_ids)) {
$hall_ids[] = $event_info['hall_id']; $hall_ids[] = $event_info['hall_id'];
} }
$eid = &$event_info['event_id']; $eid = &$event_info['event_id'];
$event = &$data['events'][$eid]; $event = &$data['events'][$eid];
# var_dump($microslots[$slot_index]); # var_dump($microslots[$slot_index]);
$title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : ''); $title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : '');
$speakers = ''; $speakers = '';
if (count($event['participant_user_ids']) > 0) { if (count($event['participant_user_ids']) > 0) {
$spk = []; $spk = [];
@ -267,10 +267,10 @@ function parseData($config, $data) {
$name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name'];
$spk[] = '<a class="vt-p" href="#' . $name . '">' . $name . '</a>'; $spk[] = '<a class="vt-p" href="#' . $name . '">' . $name . '</a>';
} }
$speakers = implode (', ', $spk); $speakers = implode (', ', $spk);
} }
if ($microslots[$slot_index][0] < $now) { if ($microslots[$slot_index][0] < $now) {
// talk has already started. Provide feedback links // talk has already started. Provide feedback links
$fullfb = '<p align=right><strong><a href="https://cfp.openfest.org/events/' . $eid . '/feedback/new">'.pll__('Submit feedback').'</a></strong></p>'; $fullfb = '<p align=right><strong><a href="https://cfp.openfest.org/events/' . $eid . '/feedback/new">'.pll__('Submit feedback').'</a></strong></p>';
@ -284,7 +284,7 @@ function parseData($config, $data) {
if (!isset($known_events[$eid])) { if (!isset($known_events[$eid])) {
//if (!in_array($data['events'][$event_info['event_id']]['track_id'], $config['hidden_language_tracks']) && !isset($known_events[$eid])) { //if (!in_array($data['events'][$event_info['event_id']]['track_id'], $config['hidden_language_tracks']) && !isset($known_events[$eid])) {
$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>' . htmlentities($event['title']) . ' ' . $fulltalk_spkr . '</strong></p>'; $fulltalks .= '<p><strong>' . htmlentities($event['title']) . ' ' . $fulltalk_spkr . '</strong></p>';
@ -293,7 +293,7 @@ function parseData($config, $data) {
$fulltalks .= '<div class="separator"></div></section>'; $fulltalks .= '<div class="separator"></div></section>';
$known_events[$eid] = $eid; $known_events[$eid] = $eid;
} }
if ($eid === $lastEventId) { if ($eid === $lastEventId) {
array_pop($columns); array_pop($columns);
++$colspan; ++$colspan;
@ -303,50 +303,50 @@ 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'] . '"') : '';
// CSS // CSS
$cssClasses = []; $cssClasses = [];
if (!in_array($event['track_id'], $config['hidden_language_tracks'])) { if (!in_array($event['track_id'], $config['hidden_language_tracks'])) {
$cssClasses[] = 'schedule-' . $event['language']; $cssClasses[] = 'schedule-' . $event['language'];
} }
$cssClass = $data['tracks'][$event['track_id']]['css_class']; $cssClass = $data['tracks'][$event['track_id']]['css_class'];
if (strlen($cssClass) > 0) { if (strlen($cssClass) > 0) {
$cssClasses[] = $cssClass; $cssClasses[] = $cssClass;
} }
$cssClasses = count($cssClasses) > 0 ? (' class="' . implode(' ', $cssClasses) . '"') : ''; $cssClasses = count($cssClasses) > 0 ? (' class="' . implode(' ', $cssClasses) . '"') : '';
// Render cell // Render cell
$columns[] = '<td' . ($colspan > 1 ? ' colspan="' . $colspan . '"' : $rowspan) . $cssClasses . '>' . $content . $progfb . '</td>'; $columns[] = '<td' . ($colspan > 1 ? ' colspan="' . $colspan . '"' : $rowspan) . $cssClasses . '>' . $content . $progfb . '</td>';
$lastEventId = $eid; $lastEventId = $eid;
unset($eid, $event); unset($eid, $event);
} }
$schedule_body .= '<tr><td>'; $schedule_body .= '<tr><td>';
$schedule_body .= date('H:i', $microslots[$slot_index][0]) . ' - ' . date('H:i', $microslots[$slot_index][1]); $schedule_body .= date('H:i', $microslots[$slot_index][0]) . ' - ' . date('H:i', $microslots[$slot_index][1]);
$schedule_body .= '</td>'; $schedule_body .= '</td>';
$schedule_body .= implode('', $columns); $schedule_body .= implode('', $columns);
$schedule_body .= '</tr>'; $schedule_body .= '</tr>';
} }
$schedule = '<table cellpadding="0" cellspacing="0" style="text-align: center;" class="schedule"><thead><tr><th></th>'; $schedule = '<table cellpadding="0" cellspacing="0" style="text-align: center;" class="schedule"><thead><tr><th></th>';
foreach ($data['halls'] as $hall_id => $hall) { foreach ($data['halls'] as $hall_id => $hall) {
if (!in_array($hall_id, $hall_ids)) { if (!in_array($hall_id, $hall_ids)) {
continue; continue;
} }
$schedule .= '<th>' . $hall[$config['lang']] . '</th>'; $schedule .= '<th>' . $hall[$config['lang']] . '</th>';
} }
$schedule .= '</tr></thead><tbody>'; $schedule .= '</tr></thead><tbody>';
$schedule .= $schedule_body; $schedule .= $schedule_body;
$schedule .= '</tbody></table>'; $schedule .= '</tbody></table>';
// Create the legend // Create the legend
$legend = ''; $legend = '';
@ -360,7 +360,7 @@ function parseData($config, $data) {
foreach ($languages as $code => $lang) { foreach ($languages as $code => $lang) {
$legend .= '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>'; $legend .= '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>';
} }
// Speaker list // Speaker list
$gspk = '<div class="grid members">'; $gspk = '<div class="grid members">';
$fspk = ''; $fspk = '';
@ -388,16 +388,16 @@ function parseData($config, $data) {
$gspk .= '</a> </div>'; $gspk .= '</a> </div>';
$fspk .= '<div class="speaker" id="' . $name . '">'; $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 .= '<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 .= '<h3>' . $name . '</h3>';
$fspk .= '<div class="icons">'; $fspk .= '<div class="icons">';
foreach ($types as $type => $param) { foreach ($types as $type => $param) {
if (!empty($speaker[$type])) { if (!empty($speaker[$type])) {
$fspk .= '<a href="' . $param['url'] . $speaker[$type] . '"><i class="fa fa-' . $param['class'] . '"></i></a>'; $fspk .= '<a href="' . $param['url'] . $speaker[$type] . '"><i class="fa fa-' . $param['class'] . '"></i></a>';
} }
} }
$fspk .= '</div>'; $fspk .= '</div>';
$fspk .= '<p>' . htmlentities($speaker['biography']) . '</p>'; $fspk .= '<p>' . htmlentities($speaker['biography']) . '</p>';
$fspk .= '</div><div class="separator"></div>'; $fspk .= '</div><div class="separator"></div>';