mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
Merge branch 'MDL-72099-master' of https://github.com/aanabit/moodle
This commit is contained in:
commit
e95aee50cc
13 changed files with 511 additions and 86 deletions
|
@ -429,4 +429,39 @@ class get_user_capability_course_helper {
|
|||
return self::create_sql($root);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Map fieldnames to get ready for the SQL query.
|
||||
*
|
||||
* @param string $fieldsexceptid A comma-separated list of the fields you require, not including id.
|
||||
* Add ctxid, ctxpath, ctxdepth etc to return course context information for preloading.
|
||||
* @return string Mapped field list for the SQL query.
|
||||
*/
|
||||
public static function map_fieldnames(string $fieldsexceptid = ''): string {
|
||||
// Convert fields list and ordering.
|
||||
$fieldlist = '';
|
||||
if ($fieldsexceptid) {
|
||||
$fields = array_map('trim', explode(',', $fieldsexceptid));
|
||||
foreach ($fields as $field) {
|
||||
// Context fields have a different alias.
|
||||
if (strpos($field, 'ctx') === 0) {
|
||||
switch($field) {
|
||||
case 'ctxlevel' :
|
||||
$realfield = 'contextlevel';
|
||||
break;
|
||||
case 'ctxinstance' :
|
||||
$realfield = 'instanceid';
|
||||
break;
|
||||
default:
|
||||
$realfield = substr($field, 3);
|
||||
break;
|
||||
}
|
||||
$fieldlist .= ',x.' . $realfield . ' AS ' . $field;
|
||||
} else {
|
||||
$fieldlist .= ',c.'.$field;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fieldlist;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue