Rewrite the schedule generation script #31

Merged
user890104 merged 19 commits from schedule-rewrite into master 2016-10-24 00:52:04 +03:00
1 changed files with 14 additions and 8 deletions
Showing only changes of commit ca4f0e0f73 - Show all commits

View File

@ -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;