mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-77018' of https://github.com/timhunt/moodle
This commit is contained in:
commit
c7a1f4c748
2 changed files with 11 additions and 6 deletions
|
@ -6252,13 +6252,14 @@ class context_helper extends context {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preloads context information from db record and strips the cached info.
|
* Preloads context cache with information from db record and strips the cached info.
|
||||||
*
|
*
|
||||||
* The db request has to contain all columns from context_helper::get_preload_record_columns().
|
* The db request has to contain all columns from context_helper::get_preload_record_columns().
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param stdClass $rec
|
* @param stdClass $rec
|
||||||
* @return void (modifies $rec)
|
* @return void This is intentional. See MDL-37115. You will need to get the context
|
||||||
|
* in the normal way, but it is now cached, so that will be fast.
|
||||||
*/
|
*/
|
||||||
public static function preload_from_record(stdClass $rec) {
|
public static function preload_from_record(stdClass $rec) {
|
||||||
context::preload_from_record($rec);
|
context::preload_from_record($rec);
|
||||||
|
|
|
@ -51,11 +51,14 @@ class helper {
|
||||||
[$questionidcondition, $params] = $DB->get_in_or_equal($questionids);
|
[$questionidcondition, $params] = $DB->get_in_or_equal($questionids);
|
||||||
// The MIN(qu.id) is just to ensure that the rows have a unique key.
|
// The MIN(qu.id) is just to ensure that the rows have a unique key.
|
||||||
$places = $DB->get_records_sql("
|
$places = $DB->get_records_sql("
|
||||||
SELECT MIN(qu.id) AS somethingunique, qu.component, qu.contextid
|
SELECT MIN(qu.id) AS somethingunique, qu.component, qu.contextid, " .
|
||||||
|
\context_helper::get_preload_record_columns_sql('ctx') . "
|
||||||
FROM {question_usages} qu
|
FROM {question_usages} qu
|
||||||
JOIN {question_attempts} qatt ON qatt.questionusageid = qu.id
|
JOIN {question_attempts} qa ON qa.questionusageid = qu.id
|
||||||
WHERE qatt.questionid $questionidcondition
|
JOIN {context} ctx ON ctx.id = qu.contextid
|
||||||
GROUP BY qu.component, qu.contextid
|
WHERE qa.questionid $questionidcondition
|
||||||
|
GROUP BY qu.component, qu.contextid, " .
|
||||||
|
implode(', ', array_keys(\context_helper::get_preload_record_columns('ctx'))) . "
|
||||||
ORDER BY qu.contextid ASC
|
ORDER BY qu.contextid ASC
|
||||||
", $params);
|
", $params);
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ class helper {
|
||||||
$places = array_values($places);
|
$places = array_values($places);
|
||||||
foreach ($places as $place) {
|
foreach ($places as $place) {
|
||||||
unset($place->somethingunique);
|
unset($place->somethingunique);
|
||||||
|
\context_helper::preload_from_record($place);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $places;
|
return $places;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue