-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding import/export functionality and behat test
- Loading branch information
Showing
13 changed files
with
600 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Provides the information to backup drawlines questions. | ||
* | ||
* @package qtype_drawlines | ||
* @copyright 2024 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class backup_qtype_drawlines_plugin extends backup_qtype_plugin { | ||
/** | ||
* Returns the qtype name. | ||
* | ||
* @return string The type name | ||
*/ | ||
protected static function qtype_name() { | ||
return 'drawlines'; | ||
} | ||
|
||
/** | ||
* Returns the qtype information to attach to question element. | ||
*/ | ||
protected function define_question_plugin_structure() { | ||
|
||
$plugin = $this->get_plugin_element(null, '../../qtype', self::qtype_name()); | ||
|
||
$pluginwrapper = new backup_nested_element($this->get_recommended_name()); | ||
|
||
$plugin->add_child($pluginwrapper); | ||
|
||
$options = new backup_nested_element('drawlines', ['id'], ['grademethod', | ||
'correctfeedback', 'correctfeedbackformat', | ||
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', | ||
'incorrectfeedback', 'incorrectfeedbackformat', | ||
'shownumcorrect', 'showmisplaced', | ||
]); | ||
$pluginwrapper->add_child($options); | ||
|
||
$lines = new backup_nested_element('lines'); | ||
$line = new backup_nested_element('line', ['id'], ['number', 'type', | ||
'labelstart', 'labelmiddle', 'labelend', 'zonestart', 'zoneend']); | ||
$pluginwrapper->add_child($lines); | ||
$lines->add_child($line); | ||
|
||
$options->set_source_table('qtype_drawlines_options', ['questionid' => backup::VAR_PARENTID]); | ||
$lines->set_source_table('qtype_drawlines_lines', ['questionid' => backup::VAR_PARENTID]); | ||
|
||
return $plugin; | ||
} | ||
|
||
/** | ||
* Returns one array with filearea => mappingname elements for the qtype | ||
* | ||
* Used by {@link get_components_and_fileareas} to know about all the qtype | ||
* files to be processed both in backup and restore. | ||
*/ | ||
public static function get_qtype_fileareas() { | ||
return | ||
[ | ||
'bgimage' => 'question_created', | ||
'correctfeedback' => 'question_created', | ||
'partiallycorrectfeedback' => 'question_created', | ||
'incorrectfeedback' => 'question_created', | ||
]; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
backup/moodle2/restore_qtype_drawlines_plugin.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Restore code for qtype_drawlines. | ||
* | ||
* @package qtype_drawlines | ||
* @copyright 2024 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
class restore_qtype_drawlines_plugin extends restore_qtype_plugin { | ||
/** | ||
* Returns the qtype name. | ||
* | ||
* @return string The type name | ||
*/ | ||
protected static function qtype_name() { | ||
return 'drawlines'; | ||
} | ||
|
||
/** | ||
* Returns the paths to be handled by the plugin at question level. | ||
* | ||
* @return array | ||
*/ | ||
protected function define_question_plugin_structure() { | ||
|
||
$paths = []; | ||
|
||
$elements = ['qtype_drawlines' => '/drawlines', 'qtype_drawlines_lines' => '/lines/line']; | ||
|
||
foreach ($elements as $elename => $path) { | ||
$elepath = $this->get_pathfor($path); | ||
$paths[] = new restore_path_element($elename, $elepath); | ||
} | ||
|
||
return $paths; | ||
} | ||
|
||
/** | ||
* | ||
* Process the qtype_drawlines element. | ||
* | ||
* @param array $data | ||
*/ | ||
public function process_qtype_drawlines(array $data): void { | ||
self::process_qtype_drawlines_data_with_table_name($data, 'qtype_drawlines_options'); | ||
} | ||
|
||
/** | ||
* | ||
* Process the qtype_drawlines_lines element. | ||
* | ||
* @param array $data | ||
*/ | ||
public function process_qtype_drawlines_lines(array $data): void { | ||
self::process_qtype_drawlines_data_with_table_name($data, 'qtype_drawlines_lines'); | ||
} | ||
|
||
/** | ||
* Process the qtype drawlines data with the table name. | ||
* | ||
* @param array $data XML data. | ||
* @param string $tablename Table name | ||
*/ | ||
private function process_qtype_drawlines_data_with_table_name(array $data, string $tablename): void { | ||
global $DB; | ||
$data = (object)$data; | ||
$oldid = $data->id; | ||
|
||
// Detect if the question is created or mapped. | ||
$questioncreated = $this->get_mappingid('question_created', | ||
$this->get_old_parentid('question')); | ||
|
||
// If the question has been created by restore, we need to create its question_drawlines too. | ||
if ($questioncreated) { | ||
// Adjust some columns. | ||
$data->questionid = $this->get_new_parentid('question'); | ||
// Insert record. | ||
$newitemid = $DB->insert_record($tablename, $data); | ||
// Create mapping. | ||
$this->set_mapping($tablename, $oldid, $newitemid); | ||
} | ||
} | ||
|
||
/** | ||
* Return the contents of this qtype to be processed by the links decoder. | ||
*/ | ||
public static function define_decode_contents(): array { | ||
$contents = []; | ||
$contents[] = new restore_decode_content('qtype_drawlines_options', | ||
['correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'], 'qtype_drawlines_options'); | ||
return $contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Serve question type files. | ||
* | ||
* @package qtype_drawlines | ||
* @copyright 2024 The Open University | ||
* @author The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Checks file access for drawlines questions. | ||
* | ||
* @param object $course The course we are in | ||
* @param object $cm Course module | ||
* @param object $context The context object | ||
* @param string $filearea the name of the file area. | ||
* @param array $args the remaining bits of the file path. | ||
* @param bool $forcedownload whether the user must be forced to download the file. | ||
* @param array $options additional options affecting the file serving | ||
*/ | ||
function qtype_drawlines_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { | ||
global $CFG; | ||
require_once($CFG->libdir . '/questionlib.php'); | ||
question_pluginfile($course, $context, 'qtype_drawlines', $filearea, $args, $forcedownload, $options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.