2015-10-19 02:04:49 +03:00
|
|
|
<?php
|
2016-10-16 21:13:25 +03:00
|
|
|
function compareKeys($a, $b, $key) {
|
|
|
|
$valA = &$a[$key];
|
|
|
|
$valB = &$b[$key];
|
|
|
|
|
|
|
|
return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2016-10-16 21:50:09 +03:00
|
|
|
function loadData($config) {
|
|
|
|
$filenames = [
|
|
|
|
'events' => 'events.json',
|
|
|
|
'speakers' => 'speakers.json',
|
|
|
|
'tracks' => 'tracks.json',
|
|
|
|
'event_types' => 'event_types.json',
|
|
|
|
'halls' => 'halls.json',
|
|
|
|
'slots' => 'slots.json',
|
|
|
|
];
|
2015-10-19 02:04:49 +03:00
|
|
|
|
2016-10-16 21:50:09 +03:00
|
|
|
$data = [];
|
2016-10-19 21:49:50 +03:00
|
|
|
$curl = new SmartCurl($config['cfp_url'] . '/api/conferences/');
|
|
|
|
|
2016-10-16 21:50:09 +03:00
|
|
|
foreach ($filenames as $name => $filename) {
|
2016-10-19 21:49:50 +03:00
|
|
|
$json = $curl->getUrl($config['conferenceId'] . '/' . $filename);
|
2016-10-16 21:50:09 +03:00
|
|
|
|
|
|
|
if ($json === false) {
|
2018-09-11 17:08:39 +03:00
|
|
|
#echo 'get failed: ', $filename, PHP_EOL;
|
|
|
|
return false;
|
2016-10-16 21:50:09 +03:00
|
|
|
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;
|
2015-10-19 02:04:49 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 21:50:09 +03:00
|
|
|
uasort($data['slots'], function($a, $b) {
|
|
|
|
return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id');
|
|
|
|
});
|
2015-10-19 02:04:49 +03:00
|
|
|
|
2016-10-16 21:50:09 +03:00
|
|
|
return $data;
|
|
|
|
}
|