I have the issue that attachments which are included in a Moodle questiontype custom plugin are not generated in HTML Template after copying the course.
All attachments are saved via “backup_qtype_…plugin.class.php” and restored via “restore_qtype…_plugin.class.php”. The attachments are also visible in the copied course but to make them visible in the answer attempt I need to manually open the question settings and just press save before someone tries to solve it.
Restore file:
<?php
defined('MOODLE_INTERNAL') || die();
class restore_qtype_qtype_name_plugin extends restore_qtype_plugin
{
/**
* Returns the paths to be handled by the plugin at question level
*/
protected function define_question_plugin_structure()
{
return array(
new restore_path_element('name', $this->get_pathfor('/name'))
);
}
public function process_name($data)
{
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')
) ? true : false;
if ($questioncreated) {
$data->question = $this->get_new_parentid('question');
$newitemid = $DB->insert_record('qtype_options', $data);
$this->set_mapping('qtype_options', $oldid, $newitemid);
}
}
// Return the contents of the questions stuff that must be processed by the links decoder
static public function define_plugin_decode_contents()
{
$contents = array();
$contents[] = new restore_decode_content('qtype_options', 'attachment_1', 'qtype_name');
$contents[] = new restore_decode_content('qtype_options', 'attachment_2', 'qtype_name');
return $contents;
}
I believe that the issue could be either on:
- backupmoodle2restore… — That I’m just missing the function that renders attachments (pdf files)
- edit_form — the function data_preprocessing is only triggert with pressing on the save button. Therefor it is not possible to include attachment files in exam directly after copying the course.
Has anyone an idea where my error lies or could anyone confirm that my guess is correct and it is simple not possible to add an attachment file directly after copying the course without saving the settings first.
Thank you very much beforehand!
Greetings,
Eduard