Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
84a92511
Commit
84a92511
authored
3 years ago
by
Jan-Hendrik Willms
Committed by
David Siegfried
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fixes #380
parent
7e06f181
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/functions.php
+32
-48
32 additions, 48 deletions
lib/functions.php
with
32 additions
and
48 deletions
lib/functions.php
+
32
−
48
View file @
84a92511
...
...
@@ -197,60 +197,44 @@ function get_object_type($id, $check_only = [])
// Initialize cache array
if
(
$cache
===
null
)
{
$cache
=
new
StudipCachedArray
(
'/StudipObjectTypes'
);
}
// Read from cache if available
if
(
isset
(
$cache
[
$id
])
&&
is_string
(
$cache
[
$id
]))
{
return
$cache
[
$id
];
}
// Tests for specific types
$tests
=
[
'sem'
=>
"SELECT 1 FROM seminare WHERE Seminar_id = ?"
,
'date'
=>
"SELECT 1 FROM termine WHERE termin_id = ?"
,
'user'
=>
"SELECT 1 FROM auth_user_md5 WHERE user_id = ?"
,
'group'
=>
"SELECT 1 FROM statusgruppen WHERE statusgruppe_id = ?"
,
'dokument'
=>
"SELECT 1 FROM file_refs WHERE id = ?"
,
'range_tree'
=>
"SELECT 1 FROM range_tree WHERE item_id = ?"
,
];
$cache
=
new
StudipCachedArray
(
'/Studip/ObjectTypes'
);
}
// No cached entry available? Go ahead and determine type
if
(
!
isset
(
$cache
[
$id
]))
{
// Tests for specific types
$tests
=
[
"SELECT 'sem' FROM `seminare` WHERE `Seminar_id` = ?"
=>
[
'sem'
],
"SELECT IF(`Institut_id` = `fakultaets_id`, 'fak', 'inst') FROM `Institute` WHERE `Institut_id` = ?"
=>
[
'inst'
,
'fak'
],
"SELECT 'date' FROM `termine` WHERE `termin_id` = ?"
=>
[
'date'
],
"SELECT 'user' FROM `auth_user_md5` WHERE `user_id` = ?"
=>
[
'user'
],
"SELECT 'group' FROM `statusgruppen` WHERE `statusgruppe_id` = ?"
=>
[
'group'
],
"SELECT 'dokument' FROM `file_refs` WHERE `id` = ?"
=>
[
'dokument'
],
"SELECT 'range_tree' FROM `range_tree` WHERE `item_id` = ?"
=>
[
'range_tree'
],
];
// Test for every type if no specific types are provided
$check_all
=
!
count
(
$check_only
);
// Loop through tests
foreach
(
$tests
as
$key
=>
$query
)
{
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
;
}
// If we want to check only for a specific type, order the tests so that
// these tests will be executed first
if
(
$check_only
)
{
uasort
(
$tests
,
function
(
$a
,
$b
)
use
(
$check_only
)
{
return
count
(
array_intersect
(
$b
,
$check_only
))
-
count
(
array_intersect
(
$a
,
$check_only
));
});
}
$present
=
DBManager
::
get
()
->
fetchColumn
(
$query
,
[
$id
]);
if
(
$present
)
{
return
$cache
[
$id
]
=
$key
;
// Actually determine type
$type
=
null
;
foreach
(
$tests
as
$query
=>
$types
)
{
$type
=
DBManager
::
get
()
->
fetchColumn
(
$query
,
[
$id
]);
if
(
$type
!==
null
)
{
break
;
}
}
}
// Institute or faculty?
if
(
$check_all
||
in_array
(
'inst'
,
$check_only
)
||
in_array
(
'fak'
,
$check_only
))
{
$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
;
// Store type
$cache
[
$id
]
=
$type
??
false
;
}
return
(
!
$check_only
||
in_array
(
$cache
[
$id
],
$check_only
))
?
$cache
[
$id
]
:
false
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment