MDL-85070 qbank: Dialogue question move into category with comma
This commit is contained in:
@@ -61,10 +61,17 @@ class question_bank_helper {
|
||||
protected const RECENTLY_VIEWED = 'recently_viewed_open_banks';
|
||||
|
||||
/**
|
||||
* Category delimiter used by the SQL to group concatenate question category data.
|
||||
* Category delimiter used by the SQL to group concatenate question category data i.e.
|
||||
* category_id<->category_name<->context_id.
|
||||
*/
|
||||
private const CATEGORY_DELIMITER = '<->';
|
||||
|
||||
/**
|
||||
* Category separator used by the SQL for group concatenation of those category triplets
|
||||
* from above.
|
||||
*/
|
||||
private const CATEGORY_SEPARATOR = '<,>';
|
||||
|
||||
/**
|
||||
* Maximum length for the question bank name database field.
|
||||
*/
|
||||
@@ -207,7 +214,7 @@ class question_bank_helper {
|
||||
"'" . self::CATEGORY_DELIMITER . "'",
|
||||
'qc.contextid'
|
||||
);
|
||||
$groupconcat = $DB->sql_group_concat($concat, ',');
|
||||
$groupconcat = $DB->sql_group_concat($concat, self::CATEGORY_SEPARATOR);
|
||||
$select = "SELECT cm.id, cm.course, {$groupconcat} AS cats";
|
||||
$catsql = ' JOIN {context} c ON c.instanceid = cm.id AND c.contextlevel = ' . CONTEXT_MODULE .
|
||||
' JOIN {question_categories} qc ON qc.contextid = c.id AND qc.parent <> 0';
|
||||
@@ -371,7 +378,7 @@ class question_bank_helper {
|
||||
private static function get_formatted_bank(stdClass $cm, int $currentbankid = 0): stdClass {
|
||||
|
||||
$cminfo = cm_info::create($cm);
|
||||
$concatedcats = !empty($cm->cats) ? explode(',', $cm->cats) : [];
|
||||
$concatedcats = !empty($cm->cats) ? explode(self::CATEGORY_SEPARATOR, $cm->cats) : [];
|
||||
$categories = array_map(static function($concatedcategory) use ($cminfo, $currentbankid) {
|
||||
$values = explode(self::CATEGORY_DELIMITER, $concatedcategory);
|
||||
$cat = new stdClass();
|
||||
|
||||
@@ -85,6 +85,11 @@ final class question_bank_helper_test extends \advanced_testcase {
|
||||
$sharedmod1context = \context_module::instance($sharedmod1->cmid);
|
||||
$sharedmod1qcat1 = $qgen->create_question_category(['contextid' => $sharedmod1context->id]);
|
||||
$sharedmod1qcat2 = $qgen->create_question_category(['contextid' => $sharedmod1context->id]);
|
||||
$sharedmod1qcat2child = $qgen->create_question_category([
|
||||
'contextid' => $sharedmod1context->id,
|
||||
'parent' => $sharedmod1qcat2->id,
|
||||
'name' => 'A, B, C',
|
||||
]);
|
||||
$privatemod1 = $privatemodgen->create_instance(['course' => $course1]);
|
||||
$privatemod1context = \context_module::instance($privatemod1->cmid);
|
||||
$privatemod1qcat1 = $qgen->create_question_category(['contextid' => $privatemod1context->id]);
|
||||
@@ -95,6 +100,10 @@ final class question_bank_helper_test extends \advanced_testcase {
|
||||
$sharedmod2context = \context_module::instance($sharedmod2->cmid);
|
||||
$sharedmod2qcat1 = $qgen->create_question_category(['contextid' => $sharedmod2context->id]);
|
||||
$sharedmod2qcat2 = $qgen->create_question_category(['contextid' => $sharedmod2context->id]);
|
||||
$sharedmod2qcat2child = $qgen->create_question_category([
|
||||
'contextid' => $sharedmod2context->id,
|
||||
'parent' => $sharedmod2qcat2->id,
|
||||
]);
|
||||
$privatemod2 = $privatemodgen->create_instance(['course' => $course2]);
|
||||
$privatemod2context = \context_module::instance($privatemod2->cmid);
|
||||
$privatemod1qcat1 = $qgen->create_question_category(['contextid' => $privatemod2context->id]);
|
||||
@@ -121,7 +130,7 @@ final class question_bank_helper_test extends \advanced_testcase {
|
||||
// Must all be mod_qbanks.
|
||||
$this->assertEquals('qbank', $courseinstance->cminfo->modname);
|
||||
// Must have 2 categories each bank.
|
||||
$this->assertCount(2, $courseinstance->questioncategories);
|
||||
$this->assertCount(3, $courseinstance->questioncategories);
|
||||
// Must not include the bank the user does not have access to.
|
||||
$this->assertNotEquals($sharedmod3->name, $courseinstance->name);
|
||||
$this->assertNotEquals($privatemod3->name, $courseinstance->name);
|
||||
|
||||
Reference in New Issue
Block a user