From b6b02e48b09b83fcd869d5c1c5ef5c7f7b90b8c1 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 19:47:05 +0300 Subject: [PATCH 01/18] Revert to the initial version of schedule --- schedule/.gitignore | 2 -- schedule/load.php | 18 ++++++++---------- schedule/parse.php | 34 ++++++---------------------------- 3 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 schedule/.gitignore diff --git a/schedule/.gitignore b/schedule/.gitignore deleted file mode 100644 index f3917d2..0000000 --- a/schedule/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -cache -cache.json diff --git a/schedule/load.php b/schedule/load.php index 9c2c971..fc9c8af 100644 --- a/schedule/load.php +++ b/schedule/load.php @@ -1,7 +1,7 @@ 'events.json', @@ -12,15 +12,14 @@ $filenames = [ 'slots' => 'slots.json', ]; - $data = []; foreach ($filenames as $name => $filename) { - $curl = new SmartCurl($base_url, 'cache' . DIRECTORY_SEPARATOR .$CF['confid']); + $curl = new SmartCurl($base_url); $json = $curl->getUrl($filename); if ($json === false) { - echo 'get failed: ', $filename, ' ', $base_url, PHP_EOL; + echo 'get failed: ', $filename, PHP_EOL; exit; } @@ -32,13 +31,12 @@ foreach ($filenames as $name => $filename) { } $add = true; + switch ($name) { case 'halls': - $ret = array(); - foreach($decoded as $id => $hall) { - if (in_array($id, $CF['allowedhallids'])) $ret[$id] = $hall['name']; - } - $decoded = $ret; + $decoded = array_map(function($el) { + return $el['name']; + }, $decoded); break; case 'slots': $decoded = array_map(function($el) { @@ -65,6 +63,6 @@ uasort($data['slots'], function($a, $b) { return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); }); -//array_pop($data['halls']); +array_pop($data['halls']); return $data; diff --git a/schedule/parse.php b/schedule/parse.php index 6ab9345..4ef5deb 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -9,11 +9,7 @@ $data = require __DIR__ . DIRECTORY_SEPARATOR . 'load.php'; -/* no idea why do I have to write this, doesn't seem to exist in the system */ - -$languages = array('en' => array('name' => 'English', 'locale' => 'en_US.UTF8'), 'bg' => array ('name' => 'Български', 'locale' => 'bg_BG.UTF8')); - -$cut_len = 70; +$cut_len = 50; $cfp_url = 'http://cfp.openfest.org'; $time = 0; $date = 0; @@ -25,20 +21,13 @@ $hall_ids = array_keys($data['halls']); $first_hall_id = min($hall_ids); $last_hall_id = max($hall_ids); -/* 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[$CF['lang']]['locale']); - foreach ($data['slots'] as $slot_id => $slot) { - if (! in_array($slot['hall_id'], $CF['allowedhallids'])) continue; $slotTime = $slot['starts_at']; $slotDate = date('d', $slotTime); if ($slotDate !== $date) { - /* this seems to be the easiest way to localize the date */ - $localdate = strftime('%d %B - %A' ,$slotTime); $lines[] = ''; - $lines[] = '' . $localdate . ''; + $lines[] = '' . date('d F - l', $slotTime) . ''; $lines[] = ' '; $lines[] = ''; @@ -63,7 +52,7 @@ foreach ($data['slots'] as $slot_id => $slot) { $lines[] = 'TBA'; } else { - $title = mb_substr($event['title'], 0, $cut_len) . (mb_strlen($event['title']) > $cut_len ? '...' : ''); + $title = mb_substr($event['title'], 0, $cut_len) . (strlen($event['title']) > $cut_len ? '...' : ''); $speakers = ''; if (count($event['participant_user_ids']) > 0) { @@ -78,7 +67,7 @@ foreach ($data['slots'] as $slot_id => $slot) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -103,7 +92,7 @@ foreach ($data['slots'] as $slot_id => $slot) { $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . ''; $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; - $fulltalks[$eid] .= '
'; + $fulltalks[$eid] .= '
'; if ($slot['event_id'] === $prev_event_id) { array_pop($lines); @@ -119,16 +108,6 @@ foreach ($data['slots'] as $slot_id => $slot) { } $lines[] = ''; -/* create the legend */ - -$legend = []; - -foreach($data['tracks'] as $track) { - $legend[] = '' . $track['name'][$CF['lang']] . ''; -} -foreach ($languages as $l => $n) { - $legend[] = '' . $n['name'] . ''; -} $gspk = []; $fspk = []; @@ -159,11 +138,10 @@ foreach ($data['speakers'] as $speaker) { $fspk[] = ''; } } - $fspk[] = ''; $fspk[] = '

' . $speaker['biography'] . '

'; $fspk[] = '
'; } $gspk[] = ''; -return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend')); +return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk')); From 25379fab151613a8ee6e4507d611af455724577e Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 20:03:05 +0300 Subject: [PATCH 02/18] Add gitignore for cache --- schedule/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 schedule/.gitignore diff --git a/schedule/.gitignore b/schedule/.gitignore new file mode 100644 index 0000000..f3917d2 --- /dev/null +++ b/schedule/.gitignore @@ -0,0 +1,2 @@ +cache +cache.json From 4eddfb2d5ad587f484ea7652d664590cd9aba57f Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 20:23:37 +0300 Subject: [PATCH 03/18] Skip slots without matching event ID --- schedule/parse.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/schedule/parse.php b/schedule/parse.php index 4ef5deb..b0de0a0 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -46,6 +46,11 @@ foreach ($data['slots'] as $slot_id => $slot) { } $eid = &$slot['event_id']; + + if (!array_key_exists($eid, $data['events'])) { + continue; + } + $event = &$data['events'][$eid]; if (is_null($eid)) { From 159cd14a5ef3aa9bc7d7e4a9a4cbeefe3c233f8a Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 20:30:50 +0300 Subject: [PATCH 04/18] Fix html of the test page --- schedule/index.php | 104 ++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/schedule/index.php b/schedule/index.php index 32fc571..43ca62a 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -1,49 +1,55 @@ - - -Test schedule - - - -
-
-
- - - - - - - - - - - - -
 
-
- + + + Test schedule + + + + +
+
+		
+ + + + + + + + + + + + +
 
+
+ + + From 117c405747ff3dd78b1ff18cd13aea1729fb4004 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 20:43:36 +0300 Subject: [PATCH 05/18] Fix closing tags, add placeholder for speaker URL --- schedule/parse.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index b0de0a0..e61ce4d 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -72,7 +72,7 @@ foreach ($data['slots'] as $slot_id => $slot) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -95,9 +95,9 @@ foreach ($data['slots'] as $slot_id => $slot) { $fulltalks[$eid] .= '
'; /* We don't want '()' when we don't have a speaker name */ $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; - $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . ''; + $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; - $fulltalks[$eid] .= '
'; + $fulltalks[$eid] .= '
'; if ($slot['event_id'] === $prev_event_id) { array_pop($lines); @@ -143,6 +143,7 @@ foreach ($data['speakers'] as $speaker) { $fspk[] = ''; } } + $fspk[] = ''; $fspk[] = '

' . $speaker['biography'] . '

'; $fspk[] = '
'; } From bdd3caa101e8908f0b5d5f849b30264f291f86f4 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 20:46:27 +0300 Subject: [PATCH 06/18] Increate cut length from 50 to 70, use multibyte strlen --- schedule/parse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index e61ce4d..78d05dd 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -9,7 +9,7 @@ $data = require __DIR__ . DIRECTORY_SEPARATOR . 'load.php'; -$cut_len = 50; +$cut_len = 70; $cfp_url = 'http://cfp.openfest.org'; $time = 0; $date = 0; @@ -57,7 +57,7 @@ foreach ($data['slots'] as $slot_id => $slot) { $lines[] = 'TBA'; } else { - $title = mb_substr($event['title'], 0, $cut_len) . (strlen($event['title']) > $cut_len ? '...' : ''); + $title = mb_substr($event['title'], 0, $cut_len) . (mb_strlen($event['title']) > $cut_len ? '...' : ''); $speakers = ''; if (count($event['participant_user_ids']) > 0) { From 33ecff552c0c3b6076c10489fcc9524be3ec6772 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 21:01:19 +0300 Subject: [PATCH 07/18] Add legend, fix issues with the locale --- schedule/index.php | 13 +++++++++++-- schedule/parse.php | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/schedule/index.php b/schedule/index.php index 43ca62a..6b9875c 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -2,7 +2,7 @@ error_reporting(~0); ini_set('display_errors', 1); -$lang = 'bg'; +define('SCHED_LANG', 'bg'); ?> @@ -23,7 +23,7 @@ $content = require __DIR__ . DIRECTORY_SEPARATOR . 'parse.php'; - + @@ -38,6 +38,15 @@ foreach ($content['lines'] as $line) {
+ + + + +
array( + 'name' => 'English', + 'locale' => 'en_US.UTF8' + ), + 'bg' => array( + 'name' => 'Български', + 'locale' => 'bg_BG.UTF8' + ) +); + +/* 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[SCHED_LANG]['locale']); + foreach ($data['slots'] as $slot_id => $slot) { $slotTime = $slot['starts_at']; $slotDate = date('d', $slotTime); if ($slotDate !== $date) { $lines[] = ''; - $lines[] = '' . date('d F - l', $slotTime) . ''; + $lines[] = '' . strftime('%d %B - %A', $slotTime) . ''; $lines[] = ' '; $lines[] = ''; @@ -114,6 +133,17 @@ foreach ($data['slots'] as $slot_id => $slot) { $lines[] = ''; +/* create the legend */ +$legend = []; + +foreach($data['tracks'] as $track) { + $legend[] = '' . $track['name'][SCHED_LANG] . ''; +} + +foreach ($languages as $code => $lang) { + $legend[] = '' . $lang['name'] . ''; +} + $gspk = []; $fspk = []; $types = []; @@ -150,4 +180,4 @@ foreach ($data['speakers'] as $speaker) { $gspk[] = ''; -return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk')); +return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend')); From ca4f0e0f73870445a1184d505578780c93adfc2a Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 21:13:25 +0300 Subject: [PATCH 08/18] Filter allowed hall ids --- schedule/load.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/schedule/load.php b/schedule/load.php index fc9c8af..c6311d1 100644 --- a/schedule/load.php +++ b/schedule/load.php @@ -12,6 +12,17 @@ $filenames = [ 'slots' => 'slots.json', ]; +if (empty($allowedhallids)) { + $allowedhallids = array(6, 7, 8); +} + +function compareKeys($a, $b, $key) { + $valA = &$a[$key]; + $valB = &$b[$key]; + + return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0); +} + $data = []; foreach ($filenames as $name => $filename) { @@ -52,17 +63,12 @@ foreach ($filenames as $name => $filename) { $data[$name] = $decoded; } -function compareKeys($a, $b, $key) { - $valA = &$a[$key]; - $valB = &$b[$key]; - - return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0); -} - uasort($data['slots'], function($a, $b) { return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); }); -array_pop($data['halls']); +$data['halls'] = array_filter($data['halls'], function($key) use ($allowedhallids) { + return in_array($key, $allowedhallids); +}, ARRAY_FILTER_USE_KEY); return $data; From 0857039fc5de619bd84a747b2b3c17024aa8e07c Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 21:50:09 +0300 Subject: [PATCH 09/18] Split code to functions, add basic config --- schedule/config.php | 17 +++ schedule/index.php | 18 ++- schedule/load.php | 118 +++++++-------- schedule/parse.php | 353 +++++++++++++++++++++----------------------- 4 files changed, 254 insertions(+), 252 deletions(-) create mode 100644 schedule/config.php diff --git a/schedule/config.php b/schedule/config.php new file mode 100644 index 0000000..d0ab77b --- /dev/null +++ b/schedule/config.php @@ -0,0 +1,17 @@ + 'bg', + 'cfp_url' => 'https://cfp.openfest.org', + 'cut_len' => 70, + ]; + + $config = [ + 2015 => [ + 'allowedHallIds' => [6, 7, 8], + + ], + ]; + + return array_merge($globalConfig, $config[$year]); +} diff --git a/schedule/index.php b/schedule/index.php index 6b9875c..ba026a3 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -2,7 +2,14 @@ error_reporting(~0); ini_set('display_errors', 1); -define('SCHED_LANG', 'bg'); +$requirePath = __DIR__ . DIRECTORY_SEPARATOR; +require $requirePath . 'class.SmartCurl.php'; +require $requirePath . 'config.php'; +require $requirePath . 'load.php'; +require $requirePath . 'parse.php'; +$sched_config = getSchedConfig(); +$data = loadData($sched_config); +$content = parseData($sched_config, $data); ?> @@ -11,19 +18,14 @@ define('SCHED_LANG', 'bg'); -
-
-		
- + diff --git a/schedule/load.php b/schedule/load.php index c6311d1..2466763 100644 --- a/schedule/load.php +++ b/schedule/load.php @@ -1,21 +1,4 @@ 'events.json', - 'speakers' => 'speakers.json', - 'tracks' => 'tracks.json', - 'event_types' => 'event_types.json', - 'halls' => 'halls.json', - 'slots' => 'slots.json', -]; - -if (empty($allowedhallids)) { - $allowedhallids = array(6, 7, 8); -} - function compareKeys($a, $b, $key) { $valA = &$a[$key]; $valB = &$b[$key]; @@ -23,52 +6,65 @@ function compareKeys($a, $b, $key) { return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0); } -$data = []; +function loadData($config) { + $base_url = $config['cfp_url'] . '/api/conferences/2/'; -foreach ($filenames as $name => $filename) { - $curl = new SmartCurl($base_url); - $json = $curl->getUrl($filename); + $filenames = [ + 'events' => 'events.json', + 'speakers' => 'speakers.json', + 'tracks' => 'tracks.json', + 'event_types' => 'event_types.json', + 'halls' => 'halls.json', + 'slots' => 'slots.json', + ]; - if ($json === false) { - echo 'get failed: ', $filename, PHP_EOL; - exit; - } - - $decoded = json_decode($json, true); + $data = []; - if ($decoded === false) { - echo 'decode failed: ', $filename, PHP_EOL; - exit; + foreach ($filenames as $name => $filename) { + $curl = new SmartCurl($base_url); + $json = $curl->getUrl($filename); + + if ($json === false) { + echo 'get failed: ', $filename, PHP_EOL; + exit; + } + + $decoded = json_decode($json, true); + + if ($decoded === false) { + echo 'decode failed: ', $filename, PHP_EOL; + exit; + } + + $add = true; + + switch ($name) { + case 'halls': + $decoded = array_map(function($el) { + return $el['name']; + }, $decoded); + break; + case 'slots': + $decoded = array_map(function($el) { + foreach (['starts_at', 'ends_at'] as $key) { + $el[$key] = strtotime($el[$key]); + } + + return $el; + }, $decoded); + break; + } + + $data[$name] = $decoded; } - - $add = true; - - switch ($name) { - case 'halls': - $decoded = array_map(function($el) { - return $el['name']; - }, $decoded); - break; - case 'slots': - $decoded = array_map(function($el) { - foreach (['starts_at', 'ends_at'] as $key) { - $el[$key] = strtotime($el[$key]); - } - - return $el; - }, $decoded); - break; - } - - $data[$name] = $decoded; + + uasort($data['slots'], function($a, $b) { + return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); + }); + + $data['halls'] = array_filter($data['halls'], function($key) use ($config) { + return in_array($key, $config['allowedHallIds']); + }, ARRAY_FILTER_USE_KEY); + + return $data; } - -uasort($data['slots'], function($a, $b) { - return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); -}); - -$data['halls'] = array_filter($data['halls'], function($key) use ($allowedhallids) { - return in_array($key, $allowedhallids); -}, ARRAY_FILTER_USE_KEY); - -return $data; diff --git a/schedule/parse.php b/schedule/parse.php index 3acd021..f195336 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -1,183 +1,170 @@ - array( - 'name' => 'English', - 'locale' => 'en_US.UTF8' - ), - 'bg' => array( - 'name' => 'Български', - 'locale' => 'bg_BG.UTF8' - ) -); - -/* 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[SCHED_LANG]['locale']); - -foreach ($data['slots'] as $slot_id => $slot) { - $slotTime = $slot['starts_at']; - $slotDate = date('d', $slotTime); - - if ($slotDate !== $date) { - $lines[] = ''; - $lines[] = ''; - $lines[] = ''; - $lines[] = ''; - - $date = $slotDate; - } - - if ($slotTime !== $time) { - if ($time !== 0) { - $lines[] = ''; - } - - $lines[] = ''; - $lines[] = ''; - - $time = $slotTime; - } - - $eid = &$slot['event_id']; - - if (!array_key_exists($eid, $data['events'])) { - continue; - } - - $event = &$data['events'][$eid]; - - if (is_null($eid)) { - $lines[] = ''; - } - else { - $title = mb_substr($event['title'], 0, $cut_len) . (mb_strlen($event['title']) > $cut_len ? '...' : ''); - $speakers = ''; - - if (count($event['participant_user_ids']) > 0) { - $speakers = json_encode($event['participant_user_ids']) . '
'; - - $spk = array(); - $speaker_name = array(); - foreach ($event['participant_user_ids'] as $uid) { - /* The check for uid==4 is for us not to show the "Opefest Team" as a presenter for lunches, etc. */ - if ($uid == 4 || empty ($data['speakers'][$uid])) { - continue; - } else { - /* TODO: fix the URL */ - $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; - } - } - $speakers = implode (', ', $spk); - } - - - /* Hack, we don't want language for the misc track. This is the same for all years. */ - if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { - $csslang = "schedule-".$event['language']; - } else { - $csslang = ""; - } - $cssclass = &$data['tracks'][$event['track_id']]['css_class']; - $style = ' class="' . $cssclass . ' ' . $csslang . '"'; - $content = '' . htmlspecialchars($title) . '
' . $speakers; - - - /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ - $fulltalks[$eid] = ''; - $fulltalks[$eid] .= '
'; - /* We don't want '()' when we don't have a speaker name */ - $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; - $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; - $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; - $fulltalks[$eid] .= '
'; - - if ($slot['event_id'] === $prev_event_id) { - array_pop($lines); - $lines[] = '' . $content . ''; - } - else { - $lines[] = '' . $content . ''; - $colspan = 1; - } - } - - $prev_event_id = $slot['event_id']; -} - -$lines[] = ''; - -/* create the legend */ -$legend = []; - -foreach($data['tracks'] as $track) { - $legend[] = ''; -} - -foreach ($languages as $code => $lang) { - $legend[] = ''; -} - -$gspk = []; -$fspk = []; -$types = []; -$types['twitter']['url']='https://twitter.com/'; -$types['twitter']['class']='fa fa-twitter'; -$types['github']['url']='https://github.com/'; -$types['github']['class']='fa fa-github'; -$types['email']['url']='mailto:'; -$types['email']['class']='fa fa-envelope'; - -$gspk[] = '
'; - -foreach ($data['speakers'] as $speaker) { - $name = $speaker['first_name'] . ' ' . $speaker['last_name']; - - $gspk[] = ''; - - $fspk[] = '
'; - $fspk[] = '' . $name .''; - $fspk[] = '

' . $name . '

'; - $fspk[] = '
'; - foreach ($types as $type => $parm) { - if (!empty($speaker[$type])) { - $fspk[] = ''; - } - } - $fspk[] = '
'; - $fspk[] = '

' . $speaker['biography'] . '

'; - $fspk[] = '
'; -} - -$gspk[] = '
'; - -return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend')); + array( + 'name' => 'English', + 'locale' => 'en_US.UTF8' + ), + 'bg' => array( + 'name' => 'Български', + 'locale' => 'bg_BG.UTF8' + ) + ); + + /* 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']); + + foreach ($data['slots'] as $slot_id => $slot) { + if (!in_array($slot['hall_id'], $config['allowedHallIds'])) { + continue; + } + + $slotTime = $slot['starts_at']; + $slotDate = date('d', $slotTime); + + if ($slotDate !== $date) { + $lines[] = ''; + $lines[] = ''; + $lines[] = ''; + $lines[] = ''; + + $date = $slotDate; + } + + if ($slotTime !== $time) { + if ($time !== 0) { + $lines[] = ''; + } + + $lines[] = ''; + $lines[] = ''; + + $time = $slotTime; + } + + $eid = &$slot['event_id']; + + if (!array_key_exists($eid, $data['events'])) { + continue; + } + + $event = &$data['events'][$eid]; + + if (is_null($eid)) { + $lines[] = ''; + } + else { + $title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : ''); + $speakers = ''; + + if (count($event['participant_user_ids']) > 0) { + $speakers = json_encode($event['participant_user_ids']) . '
'; + + $spk = array(); + $speaker_name = array(); + foreach ($event['participant_user_ids'] as $uid) { + /* The check for uid==4 is for us not to show the "Opefest Team" as a presenter for lunches, etc. */ + if ($uid == 4 || empty ($data['speakers'][$uid])) { + continue; + } else { + /* TODO: fix the URL */ + $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; + $spk[$uid] = '' . $name . ''; + } + } + $speakers = implode (', ', $spk); + } + + + /* Hack, we don't want language for the misc track. This is the same for all years. */ + if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { + $csslang = "schedule-".$event['language']; + } else { + $csslang = ""; + } + $cssclass = &$data['tracks'][$event['track_id']]['css_class']; + $style = ' class="' . $cssclass . ' ' . $csslang . '"'; + $content = '' . htmlspecialchars($title) . '
' . $speakers; + + + /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ + $fulltalks[$eid] = ''; + $fulltalks[$eid] .= '
'; + /* We don't want '()' when we don't have a speaker name */ + $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; + $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; + $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; + $fulltalks[$eid] .= '
'; + + if ($slot['event_id'] === $prev_event_id) { + array_pop($lines); + $lines[] = '' . $content . ''; + } + else { + $lines[] = '' . $content . ''; + $colspan = 1; + } + } + + $prev_event_id = $slot['event_id']; + } + + $lines[] = ''; + + /* create the legend */ + $legend = []; + + foreach($data['tracks'] as $track) { + $legend[] = ''; + } + + foreach ($languages as $code => $lang) { + $legend[] = ''; + } + + $gspk = []; + $fspk = []; + $types = []; + $types['twitter']['url']='https://twitter.com/'; + $types['twitter']['class']='fa fa-twitter'; + $types['github']['url']='https://github.com/'; + $types['github']['class']='fa fa-github'; + $types['email']['url']='mailto:'; + $types['email']['class']='fa fa-envelope'; + + $gspk[] = '
'; + + foreach ($data['speakers'] as $speaker) { + $name = $speaker['first_name'] . ' ' . $speaker['last_name']; + + $gspk[] = ''; + + $fspk[] = '
'; + $fspk[] = '' . $name .''; + $fspk[] = '

' . $name . '

'; + $fspk[] = '
'; + foreach ($types as $type => $parm) { + if (!empty($speaker[$type])) { + $fspk[] = ''; + } + } + $fspk[] = '
'; + $fspk[] = '

' . $speaker['biography'] . '

'; + $fspk[] = '
'; + } + + $gspk[] = '
'; + + return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); +} From 439d778f15806642ac5d2dd5595a9dc373753cc1 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Wed, 19 Oct 2016 21:49:50 +0300 Subject: [PATCH 10/18] Add support for showing different conferences (2014-2016), simplify some of the HTML code generation --- schedule/class.SmartCurl.php | 13 ++---- schedule/config.php | 23 ++++++++-- schedule/index.php | 18 ++------ schedule/load.php | 12 ++--- schedule/parse.php | 86 ++++++++++++++++++------------------ 5 files changed, 74 insertions(+), 78 deletions(-) diff --git a/schedule/class.SmartCurl.php b/schedule/class.SmartCurl.php index b963a31..6ebda1c 100644 --- a/schedule/class.SmartCurl.php +++ b/schedule/class.SmartCurl.php @@ -71,17 +71,16 @@ class SmartCurl { } if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) { - throw new Exception('set url failed'); + throw new Exception('set url failed: ' . $url); } - $cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename; - + $cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . str_replace('/', '@', $filename); $etag = array_key_exists($url, static::$etags) && file_exists($cache_file) ? static::$etags[$url] : null; if (curl_setopt($this->ch, CURLOPT_HTTPHEADER, [ 'If-None-Match:' . (is_null($etag) ? '' : ' ' . $etag), ]) === false) { - throw new Exception('set etag failed'); + throw new Exception('set etag failed: ' . $url); } $response = curl_exec($this->ch); @@ -123,12 +122,6 @@ class SmartCurl { $body = substr($response, $header_size); if ($http_code === 200) { - $dirname = dirname($filename); - - if ($dirname !== '.') { - mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $dirname, 0777, true); - } - file_put_contents($cache_file, $body); } diff --git a/schedule/config.php b/schedule/config.php index d0ab77b..3cdc9ee 100644 --- a/schedule/config.php +++ b/schedule/config.php @@ -5,11 +5,28 @@ function getSchedConfig($year = 2015) { 'cfp_url' => 'https://cfp.openfest.org', 'cut_len' => 70, ]; - + $config = [ + 2014 => [ + 'conferenceId' => 1, + 'eventTypes' => [ + 'lecture' => 1, + 'workshop' => 2, + ], + ], 2015 => [ - 'allowedHallIds' => [6, 7, 8], - + 'conferenceId' => 2, + 'eventTypes' => [ + 'lecture' => 3, + 'workshop' => 4, + ], + ], + 2016 => [ + 'conferenceId' => 3, + 'eventTypes' => [ + 'lecture' => 5, + 'workshop' => 6, + ], ], ]; diff --git a/schedule/index.php b/schedule/index.php index ba026a3..a8739d9 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -43,24 +43,14 @@ foreach ($content['lines'] as $line) {
 
' . strftime('%d %B - %A', $slotTime) . ' 
' . date('H:i', $slot['starts_at']) . ' - ' . date('H:i', $slot['ends_at']) . 'TBA
' . $track['name'][SCHED_LANG] . '
' . $lang['name'] . '
' . strftime('%d %B - %A', $slotTime) . ' 
' . date('H:i', $slot['starts_at']) . ' - ' . date('H:i', $slot['ends_at']) . 'TBA
' . $track['name'][$config['lang']] . '
' . $lang['name'] . '
diff --git a/schedule/load.php b/schedule/load.php index 2466763..a33769a 100644 --- a/schedule/load.php +++ b/schedule/load.php @@ -7,8 +7,6 @@ function compareKeys($a, $b, $key) { } function loadData($config) { - $base_url = $config['cfp_url'] . '/api/conferences/2/'; - $filenames = [ 'events' => 'events.json', 'speakers' => 'speakers.json', @@ -19,10 +17,10 @@ function loadData($config) { ]; $data = []; - + $curl = new SmartCurl($config['cfp_url'] . '/api/conferences/'); + foreach ($filenames as $name => $filename) { - $curl = new SmartCurl($base_url); - $json = $curl->getUrl($filename); + $json = $curl->getUrl($config['conferenceId'] . '/' . $filename); if ($json === false) { echo 'get failed: ', $filename, PHP_EOL; @@ -62,9 +60,5 @@ function loadData($config) { return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); }); - $data['halls'] = array_filter($data['halls'], function($key) use ($config) { - return in_array($key, $config['allowedHallIds']); - }, ARRAY_FILTER_USE_KEY); - return $data; } diff --git a/schedule/parse.php b/schedule/parse.php index f195336..6ded92b 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -3,7 +3,7 @@ function parseData($config, $data) { $time = 0; $date = 0; $lines = []; - $fulltalks = []; + $fulltalks = ''; $prev_event_id = 0; $colspan = 1; @@ -22,11 +22,7 @@ function parseData($config, $data) { date_default_timezone_set('Europe/Sofia'); setlocale(LC_TIME, $languages[$config['lang']]['locale']); - foreach ($data['slots'] as $slot_id => $slot) { - if (!in_array($slot['hall_id'], $config['allowedHallIds'])) { - continue; - } - + foreach ($data['slots'] as $slot) { $slotTime = $slot['starts_at']; $slotDate = date('d', $slotTime); @@ -77,7 +73,7 @@ function parseData($config, $data) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -86,9 +82,9 @@ function parseData($config, $data) { /* Hack, we don't want language for the misc track. This is the same for all years. */ if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { - $csslang = "schedule-".$event['language']; + $csslang = 'schedule-' . $event['language']; } else { - $csslang = ""; + $csslang = ''; } $cssclass = &$data['tracks'][$event['track_id']]['css_class']; $style = ' class="' . $cssclass . ' ' . $csslang . '"'; @@ -96,13 +92,12 @@ function parseData($config, $data) { /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ - $fulltalks[$eid] = ''; - $fulltalks[$eid] .= '
'; + $fulltalks .= '
'; /* We don't want '()' when we don't have a speaker name */ $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; - $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; - $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; - $fulltalks[$eid] .= '
'; + $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; + $fulltalks .= '

' . $event['abstract'] . '

'; + $fulltalks .= '
'; if ($slot['event_id'] === $prev_event_id) { array_pop($lines); @@ -120,51 +115,58 @@ function parseData($config, $data) { $lines[] = ''; /* create the legend */ - $legend = []; + $legend = ''; foreach($data['tracks'] as $track) { - $legend[] = '' . $track['name'][$config['lang']] . ''; + $legend .= '' . $track['name'][$config['lang']] . ''; } foreach ($languages as $code => $lang) { - $legend[] = '' . $lang['name'] . ''; + $legend .= '' . $lang['name'] . ''; } - $gspk = []; - $fspk = []; - $types = []; - $types['twitter']['url']='https://twitter.com/'; - $types['twitter']['class']='fa fa-twitter'; - $types['github']['url']='https://github.com/'; - $types['github']['class']='fa fa-github'; - $types['email']['url']='mailto:'; - $types['email']['class']='fa fa-envelope'; - - $gspk[] = '
'; + $gspk = '
'; + $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[] = ''; + $gspk .= ''; - $fspk[] = '
'; - $fspk[] = '' . $name .''; - $fspk[] = '

' . $name . '

'; - $fspk[] = '
'; - foreach ($types as $type => $parm) { + $fspk .= '
'; + $fspk .= '' . $name .''; + $fspk .= '

' . $name . '

'; + $fspk .= '
'; + + foreach ($types as $type => $param) { if (!empty($speaker[$type])) { - $fspk[] = ''; + $fspk .= ''; } } - $fspk[] = '
'; - $fspk[] = '

' . $speaker['biography'] . '

'; - $fspk[] = '
'; + + $fspk .= '
'; + $fspk .= '

' . $speaker['biography'] . '

'; + $fspk .= '
'; } - $gspk[] = '
'; + $gspk .= '
'; return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); } From da5810e68b1042af7f207eaaa93bc513abce88c4 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sat, 22 Oct 2016 03:23:29 +0300 Subject: [PATCH 11/18] [WIP] Properly format the schedule, fix minor bugs/whitespace --- schedule/class.SmartCurl.php | 2 +- schedule/index.php | 3 +- schedule/parse.php | 161 ++++++++++++++++++++++++++++++++++- 3 files changed, 161 insertions(+), 5 deletions(-) diff --git a/schedule/class.SmartCurl.php b/schedule/class.SmartCurl.php index 6ebda1c..278446a 100644 --- a/schedule/class.SmartCurl.php +++ b/schedule/class.SmartCurl.php @@ -12,7 +12,7 @@ class SmartCurl { } if (!file_exists($this->cache_dir)) { - mkdir($this->cache_dir); + mkdir($this->cache_dir, 0777, true); } $this->cache_index = $this->cache_dir . '.json'; diff --git a/schedule/index.php b/schedule/index.php index a8739d9..e0116a1 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -7,8 +7,9 @@ require $requirePath . 'class.SmartCurl.php'; require $requirePath . 'config.php'; require $requirePath . 'load.php'; require $requirePath . 'parse.php'; -$sched_config = getSchedConfig(); +$sched_config = getSchedConfig(date('Y')); $data = loadData($sched_config); +//$sched_config['filterEventType'] = 'workshop'; $content = parseData($sched_config, $data); ?> diff --git a/schedule/parse.php b/schedule/parse.php index 6ded92b..87d6f40 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -17,6 +17,152 @@ function parseData($config, $data) { 'locale' => 'bg_BG.UTF8' ) ); + + // PATCH WHILE CLARION RETURNS WRONG DATA + $data['slots'][188]['ends_at'] = strtotime('2016-11-06T13:15:00.000+02:00'); + + $moments = []; + + $data['slots'] = array_map(function($slot) { + $slot['start'] = date('d.m H:i', $slot['starts_at']); + $slot['end'] = date('d.m H:i', $slot['ends_at']); + return $slot; + }, $data['slots']); + + $events = []; + + foreach ($data['halls'] as $hall_id => $hall) { + $events[$hall_id] = []; + + foreach ($data['slots'] as $slot_id => $slot) { + if ($slot['hall_id'] !== $hall_id) { + continue; + } + + if (!in_array($slot['starts_at'], $moments)) { + $moments[] = $slot['starts_at']; + } + + if (!in_array($slot['ends_at'], $moments)) { + $moments[] = $slot['ends_at']; + } + + $events[$hall_id][$slot['starts_at']] = $slot; + } + + ksort($events[$hall_id]); + } + + sort($moments); + + $times = []; + + foreach ($moments as $moment) { + $times[$moment] = date('d.m H:i', $moment); + } + + $intervals = []; + $lastTs = 0; + $last = ''; + $first = true; + + foreach ($times as $ts => $time) { + if ($first) { + $last = $time; + $lastTs = $ts; + $first = false; + continue; + } + + if (date('d.m.Y', $lastTs) !== date('d.m.Y', $ts)) { + //echo PHP_EOL; + + $last = $time; + $lastTs = $ts; + continue; + } + + //echo count($intervals), '. ', $last, ' - ', $time, PHP_EOL; + $intervals[] = [$lastTs, $ts]; + + $lastTs = $ts; + $last = $time; + } + + $schedule = []; + $hall_ids = array_keys($data['halls']); + + 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; + } + } + + $schedule[] = $hall_data; + } + + $schedule = array_map(null, ...$schedule); + $table = ''; + + foreach ($hall_ids as $hall_id) { + $table .= ''; + } + + $table .= ''; + + foreach ($schedule as $slot_index => $events) { + $columns = []; + $hasEvents = false; + + foreach ($events as $hall_index => $event) { + if (is_null($event['event_id'])) { + $columns[] = ''; + continue; + } + + if ($event['edge']) { + $hasEvents = true; + } + + $columns[] = ''; + } + + if (!$hasEvents) { + continue; + } + + $table .= ''; + $table .= implode('', $columns); + $table .= ''; + } + + $table .= '
' . $data['halls'][$hall_id]['bg'] . '
 ' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ')
'; + $table .= date('H:i', $intervals[$slot_index][0]) . ' - ' . date('H:i', $intervals[$slot_index][1]); + $table .= '
'; + + echo $table; + //var_dump($schedule); + exit; /* We need to set these so we actually parse properly the dates. WP fucks up both. */ date_default_timezone_set('Europe/Sofia'); @@ -54,6 +200,15 @@ function parseData($config, $data) { $event = &$data['events'][$eid]; + if ( + array_key_exists('filterEventType', $config) && + array_key_exists($config['filterEventType'], $config['eventTypes']) + ) { + if ($config['eventTypes'][$config['filterEventType']] !== $event['event_type_id']) { + continue; + } + } + if (is_null($eid)) { $lines[] = 'TBA'; } @@ -73,7 +228,7 @@ function parseData($config, $data) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -147,11 +302,11 @@ function parseData($config, $data) { $gspk .= ''; $fspk .= '
'; - $fspk .= '' . $name .''; + $fspk .= '' . $name . ''; $fspk .= '

' . $name . '

'; $fspk .= '
'; From 3b74bc00534252a870ccb123062f8524667477ad Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sat, 22 Oct 2016 03:30:31 +0300 Subject: [PATCH 12/18] Fix rendering of schedule for 2015 --- schedule/parse.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 87d6f40..3f7d5d1 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -23,6 +23,10 @@ function parseData($config, $data) { $moments = []; + $data['slots'] = array_filter($data['slots'], function($slot) { + return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); + }); + $data['slots'] = array_map(function($slot) { $slot['start'] = date('d.m H:i', $slot['starts_at']); $slot['end'] = date('d.m H:i', $slot['ends_at']); @@ -135,7 +139,7 @@ function parseData($config, $data) { $hasEvents = false; foreach ($events as $hall_index => $event) { - if (is_null($event['event_id'])) { + if (is_null($event['event_id']) || !array_key_exists($event['event_id'], $data['events'])) { $columns[] = ' '; continue; } @@ -143,7 +147,7 @@ function parseData($config, $data) { if ($event['edge']) { $hasEvents = true; } - + $columns[] = '' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ')'; } From 69058e8fab84d8b0eb1d889d67b1b6f48b8b0e0f Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sat, 22 Oct 2016 17:22:04 +0300 Subject: [PATCH 13/18] Merge event slots horizontally --- schedule/parse.php | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 3f7d5d1..bb080f2 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -18,10 +18,7 @@ function parseData($config, $data) { ) ); - // PATCH WHILE CLARION RETURNS WRONG DATA - $data['slots'][188]['ends_at'] = strtotime('2016-11-06T13:15:00.000+02:00'); - - $moments = []; + $microslots = []; $data['slots'] = array_filter($data['slots'], function($slot) { return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); @@ -43,12 +40,12 @@ function parseData($config, $data) { continue; } - if (!in_array($slot['starts_at'], $moments)) { - $moments[] = $slot['starts_at']; + if (!in_array($slot['starts_at'], $microslots)) { + $microslots[] = $slot['starts_at']; } - if (!in_array($slot['ends_at'], $moments)) { - $moments[] = $slot['ends_at']; + if (!in_array($slot['ends_at'], $microslots)) { + $microslots[] = $slot['ends_at']; } $events[$hall_id][$slot['starts_at']] = $slot; @@ -57,12 +54,12 @@ function parseData($config, $data) { ksort($events[$hall_id]); } - sort($moments); + sort($microslots); $times = []; - foreach ($moments as $moment) { - $times[$moment] = date('d.m H:i', $moment); + foreach ($microslots as $microslot) { + $times[$microslot] = date('d.m H:i', $microslot); } $intervals = []; @@ -133,11 +130,19 @@ function parseData($config, $data) { } $table .= ''; + $lastTs = 0; foreach ($schedule as $slot_index => $events) { $columns = []; $hasEvents = false; + if (date('d.m', $intervals[$slot_index][0]) !== date('d.m', $lastTs)) { + $table .= '' . date('d.m', $intervals[$slot_index][0]) . ''; + } + + $lastTs = $intervals[$slot_index][0]; + $lastEventId = 0; + foreach ($events as $hall_index => $event) { if (is_null($event['event_id']) || !array_key_exists($event['event_id'], $data['events'])) { $columns[] = ' '; @@ -147,8 +152,19 @@ function parseData($config, $data) { if ($event['edge']) { $hasEvents = true; } + + if ($lastEventId === $event['event_id']) { + $lastColumn = array_pop($columns); + $lastColumn = preg_replace_callback('//', function($matches) { + $colspan = array_key_exists(1, $matches) ? intval($matches[1]) + 1 : 2; + return ''; + }, $lastColumn); + $columns[] = $lastColumn; + continue; + } $columns[] = '' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ')'; + $lastEventId = $event['event_id']; } if (!$hasEvents) { From 06080c62494e72339733b1b4989b8b374421aae1 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sat, 22 Oct 2016 19:09:03 +0300 Subject: [PATCH 14/18] Use the proper styles --- schedule/config.php | 6 +- schedule/index.php | 20 +--- schedule/parse.php | 251 +++++++++++++++----------------------------- 3 files changed, 91 insertions(+), 186 deletions(-) diff --git a/schedule/config.php b/schedule/config.php index 3cdc9ee..9149f4d 100644 --- a/schedule/config.php +++ b/schedule/config.php @@ -4,8 +4,10 @@ function getSchedConfig($year = 2015) { 'lang' => 'bg', 'cfp_url' => 'https://cfp.openfest.org', 'cut_len' => 70, + 'hidden_speakers' => [4], + 'hidden_language_tracks' => [], ]; - + $config = [ 2014 => [ 'conferenceId' => 1, @@ -20,6 +22,7 @@ function getSchedConfig($year = 2015) { 'lecture' => 3, 'workshop' => 4, ], + 'hidden_language_tracks' => [16], ], 2016 => [ 'conferenceId' => 3, @@ -27,6 +30,7 @@ function getSchedConfig($year = 2015) { 'lecture' => 5, 'workshop' => 6, ], + 'hidden_language_tracks' => [25], ], ]; diff --git a/schedule/index.php b/schedule/index.php index e0116a1..06c8171 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -19,27 +19,9 @@ $content = parseData($sched_config, $data); - - - - - - - - - - - -
 
diff --git a/schedule/parse.php b/schedule/parse.php index bb080f2..30d8342 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -18,19 +18,18 @@ function parseData($config, $data) { ) ); - $microslots = []; - + // 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 $data['slots'] = array_filter($data['slots'], function($slot) { return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); }); - $data['slots'] = array_map(function($slot) { - $slot['start'] = date('d.m H:i', $slot['starts_at']); - $slot['end'] = date('d.m H:i', $slot['ends_at']); - return $slot; - }, $data['slots']); - + // Collect the events for each hall, sort them in order of starting $events = []; + $microslots = []; foreach ($data['halls'] as $hall_id => $hall) { $events[$hall_id] = []; @@ -56,42 +55,29 @@ function parseData($config, $data) { sort($microslots); - $times = []; - - foreach ($microslots as $microslot) { - $times[$microslot] = date('d.m H:i', $microslot); - } - + // Find all microslots (the smallest time unit) $intervals = []; $lastTs = 0; - $last = ''; $first = true; - foreach ($times as $ts => $time) { + foreach ($microslots as $ts) { if ($first) { - $last = $time; $lastTs = $ts; $first = false; continue; } - if (date('d.m.Y', $lastTs) !== date('d.m.Y', $ts)) { - //echo PHP_EOL; - - $last = $time; + if (date('d.m', $lastTs) !== date('d.m', $ts)) { $lastTs = $ts; continue; } - //echo count($intervals), '. ', $last, ' - ', $time, PHP_EOL; $intervals[] = [$lastTs, $ts]; - $lastTs = $ts; - $last = $time; } - $schedule = []; - $hall_ids = array_keys($data['halls']); + // Fill in the event ID for each time slot in each hall + $slot_list = []; foreach ($data['halls'] as $hall_id => $hall) { $hall_data = []; @@ -119,177 +105,109 @@ function parseData($config, $data) { } } - $schedule[] = $hall_data; + $slot_list[] = $hall_data; } - $schedule = array_map(null, ...$schedule); - $table = '
'; + // Transpose the matrix + // rows->halls, cols->timeslots ===> rows->timeslots, cols->halls + $slot_list = array_map(null, ...$slot_list); - foreach ($hall_ids as $hall_id) { - $table .= ''; + // Build the HTML + $schedule = '
' . $data['halls'][$hall_id]['bg'] . '
'; + + foreach ($data['halls'] as $hall_id => $hall) { + $schedule .= ''; } - $table .= ''; + $schedule .= ''; $lastTs = 0; - foreach ($schedule as $slot_index => $events) { + foreach ($slot_list as $slot_index => $events) { $columns = []; $hasEvents = false; if (date('d.m', $intervals[$slot_index][0]) !== date('d.m', $lastTs)) { - $table .= ''; + $schedule .= ''; } $lastTs = $intervals[$slot_index][0]; $lastEventId = 0; + $colspan = 1; - foreach ($events as $hall_index => $event) { - if (is_null($event['event_id']) || !array_key_exists($event['event_id'], $data['events'])) { + foreach ($events as $hall_index => $hall_data) { + if (is_null($hall_data['event_id']) || !array_key_exists($hall_data['event_id'], $data['events'])) { $columns[] = ''; continue; } - if ($event['edge']) { + if ($hall_data['edge']) { $hasEvents = true; } - if ($lastEventId === $event['event_id']) { - $lastColumn = array_pop($columns); - $lastColumn = preg_replace_callback('//', function($matches) { - $colspan = array_key_exists(1, $matches) ? intval($matches[1]) + 1 : 2; - return ''; - $lastEventId = $event['event_id']; + $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) { + if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) { + continue; + } + + $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; + $spk[$uid] = '' . $name . ''; + } + $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 = '' . htmlspecialchars($title) . '
' . $speakers; + + /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ + $fulltalks .= '
'; + /* We don't want '()' when we don't have a speaker name */ + $fulltalk_spkr = strlen($speakers) > 0 ? (' (' . $speakers . ')') : ''; + $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; + $fulltalks .= '

' . $event['abstract'] . '

'; + $fulltalks .= '
'; +/* + if ($eid === $lastEventId) { + array_pop($columns); + ++$colspan; + } + else { + $colspan = 1; + } +*/ + $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : '') . '>' . $content . ''; + $lastEventId = $eid; } if (!$hasEvents) { continue; } - $table .= ''; - $table .= implode('', $columns); - $table .= ''; + $schedule .= ''; + $schedule .= implode('', $columns); + $schedule .= ''; } - $table .= '
' . $hall['bg'] . '
' . date('d.m', $intervals[$slot_index][0]) . '
' . strftime('%d %B - %A', $intervals[$slot_index][0]) . '
 '; - }, $lastColumn); - $columns[] = $lastColumn; - continue; - } + $eid = &$hall_data['event_id']; + $event = &$data['events'][$eid]; - $columns[] = '' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ')
'; - $table .= date('H:i', $intervals[$slot_index][0]) . ' - ' . date('H:i', $intervals[$slot_index][1]); - $table .= '
'; + $schedule .= strftime('%H:%M', $intervals[$slot_index][0]) . ' - ' . strftime('%H:%M', $intervals[$slot_index][1]); + $schedule .= '
'; + $schedule .= ''; - echo $table; - //var_dump($schedule); - exit; - - /* 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']); - - foreach ($data['slots'] as $slot) { - $slotTime = $slot['starts_at']; - $slotDate = date('d', $slotTime); - - if ($slotDate !== $date) { - $lines[] = ''; - $lines[] = '' . strftime('%d %B - %A', $slotTime) . ''; - $lines[] = ' '; - $lines[] = ''; - - $date = $slotDate; - } - - if ($slotTime !== $time) { - if ($time !== 0) { - $lines[] = ''; - } - - $lines[] = ''; - $lines[] = '' . date('H:i', $slot['starts_at']) . ' - ' . date('H:i', $slot['ends_at']) . ''; - - $time = $slotTime; - } - - $eid = &$slot['event_id']; - - if (!array_key_exists($eid, $data['events'])) { - continue; - } - - $event = &$data['events'][$eid]; - - if ( - array_key_exists('filterEventType', $config) && - array_key_exists($config['filterEventType'], $config['eventTypes']) - ) { - if ($config['eventTypes'][$config['filterEventType']] !== $event['event_type_id']) { - continue; - } - } - - if (is_null($eid)) { - $lines[] = 'TBA'; - } - else { - $title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : ''); - $speakers = ''; - - if (count($event['participant_user_ids']) > 0) { - $speakers = json_encode($event['participant_user_ids']) . '
'; - - $spk = array(); - $speaker_name = array(); - foreach ($event['participant_user_ids'] as $uid) { - /* The check for uid==4 is for us not to show the "Opefest Team" as a presenter for lunches, etc. */ - if ($uid == 4 || empty ($data['speakers'][$uid])) { - continue; - } else { - /* TODO: fix the URL */ - $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; - } - } - $speakers = implode (', ', $spk); - } - - - /* Hack, we don't want language for the misc track. This is the same for all years. */ - if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { - $csslang = 'schedule-' . $event['language']; - } else { - $csslang = ''; - } - $cssclass = &$data['tracks'][$event['track_id']]['css_class']; - $style = ' class="' . $cssclass . ' ' . $csslang . '"'; - $content = '' . htmlspecialchars($title) . '
' . $speakers; - - - /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ - $fulltalks .= '
'; - /* We don't want '()' when we don't have a speaker name */ - $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; - $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; - $fulltalks .= '

' . $event['abstract'] . '

'; - $fulltalks .= '
'; - - if ($slot['event_id'] === $prev_event_id) { - array_pop($lines); - $lines[] = '' . $content . ''; - } - else { - $lines[] = '' . $content . ''; - $colspan = 1; - } - } - - $prev_event_id = $slot['event_id']; - } - - $lines[] = ''; - - /* create the legend */ + // Create the legend $legend = ''; foreach($data['tracks'] as $track) { @@ -299,7 +217,8 @@ function parseData($config, $data) { foreach ($languages as $code => $lang) { $legend .= '' . $lang['name'] . ''; } - + + // Speaker list $gspk = '
'; $fspk = ''; $types = [ @@ -343,5 +262,5 @@ function parseData($config, $data) { $gspk .= '
'; - return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); + return compact('schedule', 'fulltalks', 'gspk', 'fspk', 'legend'); } From e18f6d1eb7ddd09889758dcb38f145656b80fe52 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 23 Oct 2016 00:44:27 +0300 Subject: [PATCH 15/18] Enable horizontal merging of slots --- schedule/parse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 30d8342..6bcdc11 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -181,7 +181,7 @@ function parseData($config, $data) { $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; $fulltalks .= '

' . $event['abstract'] . '

'; $fulltalks .= '
'; -/* + if ($eid === $lastEventId) { array_pop($columns); ++$colspan; @@ -189,7 +189,7 @@ function parseData($config, $data) { else { $colspan = 1; } -*/ + $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : '') . '>' . $content . ''; $lastEventId = $eid; } From a807406eb05f9a3bedd13a6e68fc74215fb82049 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 23 Oct 2016 23:16:13 +0300 Subject: [PATCH 16/18] Rename variables, add vertical merging of slots --- schedule/parse.php | 149 +++++++++++++++++++++++++++++++++------------ 1 file changed, 110 insertions(+), 39 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 6bcdc11..16b3571 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -27,40 +27,40 @@ function parseData($config, $data) { return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); }); - // Collect the events for each hall, sort them in order of starting - $events = []; - $microslots = []; + // Collect the slots for each hall, sort them in order of starting + $slots = []; + $timestamps = []; foreach ($data['halls'] as $hall_id => $hall) { - $events[$hall_id] = []; + $slots[$hall_id] = []; foreach ($data['slots'] as $slot_id => $slot) { if ($slot['hall_id'] !== $hall_id) { continue; } - if (!in_array($slot['starts_at'], $microslots)) { - $microslots[] = $slot['starts_at']; + if (!in_array($slot['starts_at'], $timestamps)) { + $timestamps[] = $slot['starts_at']; } - if (!in_array($slot['ends_at'], $microslots)) { - $microslots[] = $slot['ends_at']; + if (!in_array($slot['ends_at'], $timestamps)) { + $timestamps[] = $slot['ends_at']; } - - $events[$hall_id][$slot['starts_at']] = $slot; + + $slots[$hall_id][$slot['starts_at']] = $slot; } - ksort($events[$hall_id]); + ksort($slots[$hall_id]); } - sort($microslots); + sort($timestamps); // Find all microslots (the smallest time unit) - $intervals = []; + $microslots = []; $lastTs = 0; $first = true; - foreach ($microslots as $ts) { + foreach ($timestamps as $ts) { if ($first) { $lastTs = $ts; $first = false; @@ -72,24 +72,25 @@ function parseData($config, $data) { continue; } - $intervals[] = [$lastTs, $ts]; + $microslots[] = [$lastTs, $ts]; $lastTs = $ts; } // Fill in the event ID for each time slot in each hall - $slot_list = []; + $events = []; foreach ($data['halls'] as $hall_id => $hall) { $hall_data = []; - foreach ($intervals as $timestamps) { + foreach ($microslots 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] + $slot['ends_at'] >= $timestamps[1] && + array_key_exists($slot['event_id'], $data['events']) ) { $found = true; $hall_data[] = [ @@ -105,12 +106,86 @@ function parseData($config, $data) { } } - $slot_list[] = $hall_data; + $events[] = $hall_data; } - + // Transpose the matrix // rows->halls, cols->timeslots ===> rows->timeslots, cols->halls - $slot_list = array_map(null, ...$slot_list); + $events = array_map(null, ...$events); + + // Filter empty slots + $count = count($events); + for ($i = 0; $i < $count; ++$i) { + $hall_count = count($events[$i]); + $hasEvents = false; + + for ($j = 0; $j < $hall_count; ++$j) { + if (!is_null($events[$i][$j]) && $events[$i][$j]['edge']) { + $hasEvents = true; + continue 2; + } + } + + if (!$hasEvents) { + unset($events[$i]); + } + } + + // Merge events longer than one slot + $prevEventId = []; + $prevEventSlot = []; + $prevSlotIndex = 0; + $first = true; + + foreach ($events as $slot_index => &$events_data) { + if ($first) { + $prevEventId = array_map(function($event_info) { + return is_null($event_info) ? null : $event_info['event_id']; + }, $events_data); + $prevEventSlot = array_fill(0, count($events_data), null); + $prevSlotIndex = $slot_index; + $first = false; + continue; + } + + foreach ($events_data as $hall_index => &$event_info) { + if (is_null($event_info)) { + $prevEventId[$hall_index] = null; + $prevEventSlot[$hall_index] = null; + continue; + } + + if ($event_info['event_id'] !== $prevEventId[$hall_index]) { + $prevEventId[$hall_index] = $event_info['event_id']; + $prevEventSlot[$hall_index] = null; + continue; + } + + // We have a long event + if (is_null($prevEventSlot[$hall_index])) { + $prevEventSlot[$hall_index] = $prevSlotIndex; + } + + $master_slot = &$events[$prevEventSlot[$hall_index]][$hall_index]; + + if (!array_key_exists('rowspan', $master_slot)) { + $master_slot['rowspan'] = 2; + } + else { + ++$master_slot['rowspan']; + } + + unset($master_slot); + + $event_info = false; + } + + unset($event_info); + + $prevSlotIndex = $slot_index; + } + + unset($events_data); // Build the HTML $schedule = ''; @@ -122,29 +197,28 @@ function parseData($config, $data) { $schedule .= ''; $lastTs = 0; - foreach ($slot_list as $slot_index => $events) { + foreach ($events as $slot_index => $events_data) { $columns = []; - $hasEvents = false; - if (date('d.m', $intervals[$slot_index][0]) !== date('d.m', $lastTs)) { - $schedule .= ''; + if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { + $schedule .= ''; } - $lastTs = $intervals[$slot_index][0]; + $lastTs = $microslots[$slot_index][0]; $lastEventId = 0; $colspan = 1; - foreach ($events as $hall_index => $hall_data) { - if (is_null($hall_data['event_id']) || !array_key_exists($hall_data['event_id'], $data['events'])) { + foreach ($events_data as $hall_index => $event_info) { + if ($event_info === false) { + continue; + } + + if (is_null($event_info['event_id'])) { $columns[] = ''; continue; } - if ($hall_data['edge']) { - $hasEvents = true; - } - - $eid = &$hall_data['event_id']; + $eid = &$event_info['event_id']; $event = &$data['events'][$eid]; $title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : ''); @@ -190,16 +264,13 @@ function parseData($config, $data) { $colspan = 1; } - $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : '') . '>' . $content . ''; + $rowspan = array_key_exists('rowspan', $event_info) ? (' rowspan="' . $event_info['rowspan'] . '"') : ''; + $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : $rowspan) . '>' . $content . ''; $lastEventId = $eid; } - if (!$hasEvents) { - continue; - } - $schedule .= ''; $schedule .= implode('', $columns); $schedule .= ''; From 48a0fa9c5fe1120aeed715c42b50caaaf14c27d6 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 24 Oct 2016 00:16:00 +0300 Subject: [PATCH 17/18] Remove unused variables, add filter by event type, rewrite CSS class generation --- schedule/index.php | 2 +- schedule/parse.php | 63 ++++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/schedule/index.php b/schedule/index.php index 06c8171..b6e78da 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -9,7 +9,7 @@ require $requirePath . 'load.php'; require $requirePath . 'parse.php'; $sched_config = getSchedConfig(date('Y')); $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); ?> diff --git a/schedule/parse.php b/schedule/parse.php index 16b3571..3bca53c 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -1,12 +1,5 @@ array( 'name' => 'English', @@ -78,7 +71,12 @@ function parseData($config, $data) { // Fill in the event ID for each time slot in each hall $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) { $hall_data = []; @@ -92,6 +90,12 @@ function parseData($config, $data) { $slot['ends_at'] >= $timestamps[1] && 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; $hall_data[] = [ 'event_id' => $slot['event_id'], @@ -196,6 +200,7 @@ function parseData($config, $data) { $schedule .= ''; $lastTs = 0; + $fulltalks = ''; foreach ($events as $slot_index => $events_data) { $columns = []; @@ -225,32 +230,27 @@ function parseData($config, $data) { $speakers = ''; if (count($event['participant_user_ids']) > 0) { - $spk = array(); - $speaker_name = array(); + $spk = []; + foreach ($event['participant_user_ids'] as $uid) { if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) { continue; } $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[] = '' . $name . ''; } + $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 = '' . htmlspecialchars($title) . '
' . $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 .= '
'; - /* 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 . ')') : ''; $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; $fulltalks .= '

' . $event['abstract'] . '

'; @@ -265,8 +265,27 @@ function parseData($config, $data) { } $rowspan = array_key_exists('rowspan', $event_info) ? (' rowspan="' . $event_info['rowspan'] . '"') : ''; - $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : $rowspan) . '>' . $content . ''; + + // 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[] = ' 1 ? ' colspan="' . $colspan . '"' : $rowspan) . $cssClasses . '>' . $content . ''; + $lastEventId = $eid; + unset($eid, $event); } $schedule .= '
' . strftime('%d %B - %A', $intervals[$slot_index][0]) . '
' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '
 
'; - $schedule .= strftime('%H:%M', $intervals[$slot_index][0]) . ' - ' . strftime('%H:%M', $intervals[$slot_index][1]); + $schedule .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); $schedule .= '
'; From 46d9f93ac3dc8a0e68a54dd63cfdc4b6b95d199e Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 24 Oct 2016 00:34:15 +0300 Subject: [PATCH 18/18] Fix filtering by event type --- schedule/parse.php | 57 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 3bca53c..4c38906 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -99,6 +99,7 @@ function parseData($config, $data) { $found = true; $hall_data[] = [ 'event_id' => $slot['event_id'], + 'hall_id' => $slot['hall_id'], 'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1], ]; break; @@ -112,6 +113,21 @@ function parseData($config, $data) { $events[] = $hall_data; } + + // Remove halls with no events after filtering + $count = count($events); + for ($i = 0; $i < $count; ++$i) { + $hasEvents = false; + foreach ($events[$i] as $event_info) { + if (!is_null($event_info)) { + $hasEvents = true; + break; + } + } + if (!$hasEvents) { + unset($events[$i]); + } + } // Transpose the matrix // rows->halls, cols->timeslots ===> rows->timeslots, cols->halls @@ -192,28 +208,23 @@ function parseData($config, $data) { unset($events_data); // Build the HTML - $schedule = ''; - - foreach ($data['halls'] as $hall_id => $hall) { - $schedule .= ''; - } - - $schedule .= ''; + $schedule_body = ''; $lastTs = 0; $fulltalks = ''; + $hall_ids = []; foreach ($events as $slot_index => $events_data) { $columns = []; if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { - $schedule .= ''; + $schedule_body .= ''; } $lastTs = $microslots[$slot_index][0]; $lastEventId = 0; $colspan = 1; - foreach ($events_data as $hall_index => $event_info) { + foreach ($events_data as $event_info) { if ($event_info === false) { continue; } @@ -222,7 +233,11 @@ function parseData($config, $data) { $columns[] = ''; continue; } - + + if (!in_array($event_info['hall_id'], $hall_ids)) { + $hall_ids[] = $event_info['hall_id']; + } + $eid = &$event_info['event_id']; $event = &$data['events'][$eid]; @@ -288,13 +303,25 @@ function parseData($config, $data) { unset($eid, $event); } - $schedule .= ''; - $schedule .= implode('', $columns); - $schedule .= ''; + $schedule_body .= ''; + $schedule_body .= implode('', $columns); + $schedule_body .= ''; } + $schedule = '
' . $hall['bg'] . '
' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '
' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '
 
'; - $schedule .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); - $schedule .= '
'; + $schedule_body .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); + $schedule_body .= '
'; + + foreach ($data['halls'] as $hall_id => $hall) { + if (!in_array($hall_id, $hall_ids)) { + continue; + } + + $schedule .= ''; + } + + $schedule .= ''; + $schedule .= $schedule_body; $schedule .= '
' . $hall['bg'] . '
'; // Create the legend