From ca4f0e0f73870445a1184d505578780c93adfc2a Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sun, 16 Oct 2016 21:13:25 +0300 Subject: [PATCH] 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;