mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-62708 question: Add idnumbers to question and question category
This commit is contained in:
parent
6902f39141
commit
6189fda47f
24 changed files with 502 additions and 13 deletions
|
@ -2211,7 +2211,7 @@ class backup_questions_structure_step extends backup_structure_step {
|
|||
$qcategory = new backup_nested_element('question_category', array('id'), array(
|
||||
'name', 'contextid', 'contextlevel', 'contextinstanceid',
|
||||
'info', 'infoformat', 'stamp', 'parent',
|
||||
'sortorder'));
|
||||
'sortorder', 'idnumber'));
|
||||
|
||||
$questions = new backup_nested_element('questions');
|
||||
|
||||
|
@ -2219,7 +2219,7 @@ class backup_questions_structure_step extends backup_structure_step {
|
|||
'parent', 'name', 'questiontext', 'questiontextformat',
|
||||
'generalfeedback', 'generalfeedbackformat', 'defaultmark', 'penalty',
|
||||
'qtype', 'length', 'stamp', 'version',
|
||||
'hidden', 'timecreated', 'timemodified', 'createdby', 'modifiedby'));
|
||||
'hidden', 'timecreated', 'timemodified', 'createdby', 'modifiedby', 'idnumber'));
|
||||
|
||||
// attach qtype plugin structure to $question element, only one allowed
|
||||
$this->add_plugin_structure('qtype', $question, false);
|
||||
|
|
|
@ -4434,6 +4434,12 @@ class restore_create_categories_and_questions extends restore_structure_step {
|
|||
$data->stamp = make_unique_id_code();
|
||||
}
|
||||
|
||||
// The idnumber if it exists also needs to be unique within a context or reset it to null.
|
||||
if (!empty($data->idnumber) && $DB->record_exists('question_categories',
|
||||
['idnumber' => $data->idnumber, 'contextid' => $data->contextid])) {
|
||||
unset($data->idnumber);
|
||||
}
|
||||
|
||||
// Let's create the question_category and save mapping.
|
||||
$newitemid = $DB->insert_record('question_categories', $data);
|
||||
$this->set_mapping('question_category', $oldid, $newitemid);
|
||||
|
@ -4479,6 +4485,13 @@ class restore_create_categories_and_questions extends restore_structure_step {
|
|||
|
||||
// With newitemid = 0, let's create the question
|
||||
if (!$questionmapping->newitemid) {
|
||||
|
||||
// The idnumber if it exists also needs to be unique within a category or reset it to null.
|
||||
if (!empty($data->idnumber) && $DB->record_exists('question',
|
||||
['idnumber' => $data->idnumber, 'category' => $data->category])) {
|
||||
unset($data->idnumber);
|
||||
}
|
||||
|
||||
$newitemid = $DB->insert_record('question', $data);
|
||||
$this->set_mapping('question', $oldid, $newitemid);
|
||||
// Also annotate them as question_created, we need
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue