Skip to content
Snippets Groups Projects
Commit 84a92511 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

fixes #380

parent 7e06f181
No related branches found
No related tags found
No related merge requests found
...@@ -197,60 +197,44 @@ function get_object_type($id, $check_only = []) ...@@ -197,60 +197,44 @@ function get_object_type($id, $check_only = [])
// Initialize cache array // Initialize cache array
if ($cache === null) { if ($cache === null) {
$cache = new StudipCachedArray('/StudipObjectTypes'); $cache = new StudipCachedArray('/Studip/ObjectTypes');
} }
// Read from cache if available // No cached entry available? Go ahead and determine type
if (isset($cache[$id]) && is_string($cache[$id])) { if (!isset($cache[$id])) {
return $cache[$id]; // Tests for specific types
} $tests = [
"SELECT 'sem' FROM `seminare` WHERE `Seminar_id` = ?" => ['sem'],
// Tests for specific types "SELECT IF(`Institut_id` = `fakultaets_id`, 'fak', 'inst') FROM `Institute` WHERE `Institut_id` = ?" => ['inst', 'fak'],
$tests = [ "SELECT 'date' FROM `termine` WHERE `termin_id` = ?" => ['date'],
'sem' => "SELECT 1 FROM seminare WHERE Seminar_id = ?", "SELECT 'user' FROM `auth_user_md5` WHERE `user_id` = ?" => ['user'],
'date' => "SELECT 1 FROM termine WHERE termin_id = ?", "SELECT 'group' FROM `statusgruppen` WHERE `statusgruppe_id` = ?" => ['group'],
'user' => "SELECT 1 FROM auth_user_md5 WHERE user_id = ?", "SELECT 'dokument' FROM `file_refs` WHERE `id` = ?" => ['dokument'],
'group' => "SELECT 1 FROM statusgruppen WHERE statusgruppe_id = ?", "SELECT 'range_tree' FROM `range_tree` WHERE `item_id` = ?" => ['range_tree'],
'dokument' => "SELECT 1 FROM file_refs WHERE id = ?", ];
'range_tree' => "SELECT 1 FROM range_tree WHERE item_id = ?",
];
// Test for every type if no specific types are provided // If we want to check only for a specific type, order the tests so that
$check_all = !count($check_only); // these tests will be executed first
if ($check_only) {
// Loop through tests uasort($tests, function ($a, $b) use ($check_only) {
foreach ($tests as $key => $query) { return count(array_intersect($b, $check_only)) - count(array_intersect($a, $check_only));
if ($check_all || in_array($key, $check_only)) { });
if (!$check_all }
&& isset($cache[$id])
&& is_array($cache[$id])
&& in_array($key, $cache[$id])
) {
return false;
}
$present = DBManager::get()->fetchColumn($query, [$id]); // Actually determine type
if ($present) { $type = null;
return $cache[$id] = $key; foreach ($tests as $query => $types) {
$type = DBManager::get()->fetchColumn($query, [$id]);
if ($type !== null) {
break;
} }
} }
}
// Institute or faculty? // Store type
if ($check_all || in_array('inst', $check_only) || in_array('fak', $check_only)) { $cache[$id] = $type ?? false;
$query = "SELECT Institut_id = fakultaets_id FROM Institute WHERE Institut_id = ?";
$is_fak = DBManager::get()->fetchColumn($query, [$id]);
if ($is_fak !== false) {
return $cache[$id] = $is_fak ? 'fak' : 'inst';
}
}
if ($check_all) {
// None of the above
return $cache[$id] = false;
} else {
$cache[$id] = $check_only;
return false;
} }
return (!$check_only || in_array($cache[$id], $check_only)) ? $cache[$id] : false;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment