MDL-61132 Quiz: "Random" question from "Top" categories

* Support for adding ranodm questions from "Top" categories
This commit is contained in:
Shamim Rezaie 2018-01-30 13:46:39 +11:00
parent 9275220de3
commit 3b8f3198de
6 changed files with 68 additions and 7 deletions

View file

@ -1030,6 +1030,23 @@ function question_get_top_category($contextid, $create = false) {
return $category;
}
/**
* Gets the list of top categories in the given contexts in the array("categoryid,categorycontextid") format.
*
* @param array $contextids List of context ids
* @return array
*/
function question_get_top_categories_for_contexts($contextids) {
global $DB;
$concatsql = $DB->sql_concat_join("','", ['id', 'contextid']);
list($insql, $params) = $DB->get_in_or_equal($contextids);
$sql = "SELECT $concatsql FROM {question_categories} WHERE contextid $insql AND parent = 0";
$topcategories = $DB->get_fieldset_sql($sql, $params);
return $topcategories;
}
/**
* Gets the default category in the most specific context.
* If no categories exist yet then default ones are created in all contexts.