Skip to content

Commit

Permalink
MDL-71696 core_question: Changes for versioning
Browse files Browse the repository at this point in the history
This commit adds the changes in questiontype base
to work with new question tables and the new structure in the
databse. Also needed for versioning.
This implementation will also introduct the question status
which allows a question to be in draft and ready status.
I also introduces changes to the base view where it shows
the latest version of the questions. The view of versions
for a question is not implemented in this commit.
This implementation will also introduce changes in the core
qtype plugins to support versioning and the changed
db schema.
  • Loading branch information
guillogo authored and safatshahin committed Feb 3, 2022
1 parent 7547f3e commit c6cfca2
Show file tree
Hide file tree
Showing 118 changed files with 2,953 additions and 1,404 deletions.
46 changes: 38 additions & 8 deletions admin/qtypes.php
Expand Up @@ -42,25 +42,55 @@
$pluginmanager = core_plugin_manager::instance();

// Get some data we will need - question counts and which types are needed.
$counts = $DB->get_records_sql("
SELECT qtype, COUNT(1) as numquestions, SUM(hidden) as numhidden
FROM {question} GROUP BY qtype", array());
$needed = array();
$hiddenstatus = \core_question\local\bank\constants::QUESTION_STATUS_HIDDEN;
$draftstatus = \core_question\local\bank\constants::QUESTION_STATUS_DRAFT;

$sql = "SELECT result.qtype,
SUM(result.numquestions) AS numquestions,
SUM(result.numhidden) AS numhidden,
SUM(result.numdraft) AS numdraft
FROM (
SELECT data.qtype,
COUNT(data.numquestions) AS numquestions,
(SELECT COUNT(qv.id)
FROM {question_versions} qv
WHERE qv.id = data.versionid
AND qv.status = :hiddenstatus) AS numhidden,
(SELECT COUNT(qv.id)
FROM {question_versions} qv
WHERE qv.id = data.versionid
AND qv.status = :draftstatus) AS numdraft
FROM (
SELECT q.qtype, qv.id AS versionid, 1 AS numquestions
FROM {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
AND qv.version = (SELECT MAX(v.version)
FROM {question_versions} v
JOIN {question_bank_entries} be ON be.id = v.questionbankentryid
WHERE be.id = qbe.id)) data
GROUP BY data.qtype, data.versionid) result
GROUP BY result.qtype";

$counts = $DB->get_records_sql($sql, ['hiddenstatus' => $hiddenstatus, 'draftstatus' => $draftstatus]);
$needed = [];
foreach ($qtypes as $qtypename => $qtype) {
if (!isset($counts[$qtypename])) {
$counts[$qtypename] = new stdClass;
$counts[$qtypename]->numquestions = 0;
$counts[$qtypename]->numhidden = 0;
$counts[$qtypename]->numdraft = 0;
}
$needed[$qtypename] = $counts[$qtypename]->numquestions > 0 ||
$pluginmanager->other_plugins_that_require($qtype->plugin_name());
$counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
$counts[$qtypename]->numquestions -= ($counts[$qtypename]->numhidden + $counts[$qtypename]->numdraft);
}
$needed['missingtype'] = true; // The system needs the missing question type.
foreach ($counts as $qtypename => $count) {
if (!isset($qtypes[$qtypename])) {
$counts['missingtype']->numquestions += $count->numquestions - $count->numhidden;
$counts['missingtype']->numquestions += $count->numquestions - ($count->numhidden + $count->numdraft);
$counts['missingtype']->numhidden += $count->numhidden;
$counts['missingtype']->numdraft += $count->numdraft;
}
}

Expand Down Expand Up @@ -153,8 +183,8 @@
$row[] = $icon . ' ' . $localname;

// Number of questions of this type.
if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden > 0) {
if ($counts[$qtypename]->numhidden > 0) {
if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden + $counts[$qtypename]->numdraft > 0) {
if ($counts[$qtypename]->numhidden + $counts[$qtypename]->numdraft > 0) {
$strcount = get_string('numquestionsandhidden', 'question', $counts[$qtypename]);
} else {
$strcount = $counts[$qtypename]->numquestions;
Expand Down
3 changes: 2 additions & 1 deletion lang/en/question.php
Expand Up @@ -257,7 +257,7 @@
$string['novirtualquestiontype'] = 'No virtual question type for question type {$a}';
$string['numqas'] = 'No. question attempts';
$string['numquestions'] = 'No. questions';
$string['numquestionsandhidden'] = '{$a->numquestions} (+{$a->numhidden} hidden)';
$string['numquestionsandhidden'] = '{$a->numquestions} (+{$a->numhidden} hidden +{$a->numdraft} draft)';
$string['page-question-x'] = 'Any question page';
$string['page-question-edit'] = 'Question editing page';
$string['page-question-category'] = 'Question category page';
Expand Down Expand Up @@ -498,3 +498,4 @@
$string['yougotnright'] = 'You have correctly selected {$a->num}.';
$string['qbanknotfound'] = 'The \'{$a}\' question bank plugin doesn\'t exist or is not recognised.';
$string['noquestionbanks'] = 'No question bank plugin found.';
$string['questionloaderror'] = 'Could not load the question options.';
1 change: 0 additions & 1 deletion lib/db/renamedclasses.php
Expand Up @@ -61,7 +61,6 @@
'core_question\\bank\\copy_action_column' => 'qbank_editquestion\\copy_action_column',
'core_question\\bank\\edit_action_column' => 'qbank_editquestion\\edit_action_column',
'core_question\\bank\\creator_name_column' => 'qbank_viewcreator\\creator_name_column',
'core_question\\bank\\modifier_name_column' => 'qbank_viewcreator\\modifier_name_column',
'core_question\\bank\\question_name_column' => 'qbank_viewquestionname\\viewquestionname_column_helper',
'core_question\\bank\\question_name_idnumber_tags_column' => 'qbank_viewquestionname\\question_name_idnumber_tags_column',
'core_question\\bank\\delete_action_column' => 'qbank_deletequestion\\delete_action_column',
Expand Down

0 comments on commit c6cfca2

Please sign in to comment.