mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
restore: MDL-17480 Potentially expensive function user_can_create_courses called repeatedly from restore UI.
This commit is contained in:
parent
77f60b432a
commit
df73f8d4e1
3 changed files with 20 additions and 47 deletions
|
@ -2255,37 +2255,19 @@ function xmldb_debug($message, $object) {
|
|||
}
|
||||
|
||||
/**
|
||||
* true or false function to see if user can create any courses at all
|
||||
* @return bool
|
||||
* @return boolean Whether the user can create courses in any category in the system.
|
||||
*/
|
||||
function user_can_create_courses() {
|
||||
global $USER;
|
||||
// if user has course creation capability at any site or course cat, then return true;
|
||||
|
||||
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
return true;
|
||||
} else {
|
||||
return (bool) count(get_creatable_categories());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of categories the current user can create courses in
|
||||
* @return array
|
||||
*/
|
||||
function get_creatable_categories() {
|
||||
global $DB;
|
||||
|
||||
$creatablecats = array();
|
||||
if ($cats = $DB->get_records('course_categories')) {
|
||||
foreach ($cats as $cat) {
|
||||
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $cat->id))) {
|
||||
$creatablecats[$cat->id] = $cat->name;
|
||||
}
|
||||
$catsrs = $DB->get_recordset('course_categories');
|
||||
foreach ($cats as $cat) {
|
||||
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $cat->id))) {
|
||||
$catsrs->close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return $creatablecats;
|
||||
$catsrs->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue