Good day.
I'm trying to add a new dropdown menu on the page where we edit a question. This dropdown menu is used for my local plugin. I didn't manage to modify the page and add the select tag.
It should look like this. (I used 'Inspect element' in achieving this)
I created a table that will contain the question id
and obe category
for the question since it's not a good practice to modify Moodle's defined tables.
I manually created the table but I will use XMLDB Editor soon. I'm still reading on it, will apply it later on.
Sample table structure with content.
mdl_question_obe
id question obe_category
1 1 FI
2 2 FI
3 3 S
4 4 S
question
is the id of the question, obe_category
is the category of the question.
I think that there are other modifications to be done once this is achieved because the mdl_question_obe
table will be populated after the question is saved.
How can I achieve this? Any insights will do!
And please leave a comment if I missed something.
Something like this
In /question/question.php
before $mform->set_data($toform);
add this to get the current obe category
if ($id) {
$toform->obe_category = $DB->get_field('question_obe', 'obe_category', array('question' => $id));
}
Then in /question/type/edit_question_form.php
before $mform->addElement('editor', 'questiontext', get_string('questiontext', 'question'),
add this
$obe_options('FI' => 'FI', 'S' => 'S', 'M' => 'M');
or if the values are stored in a database table then use this, assuming the table is called obe_category and the text field is called obe_category
$obe_options = $DB->get_records_menu('obe_category', array(), 'obe_category', 'obe_category, obe_category');
then
$mform->addElement('select', 'obe_category',
get_string('selectobecategory', 'local_obe_category'), $obe_options);
$mform->setType('obe_category', PARAM_ALPHA);
Then back in /question/question.php
just after $question = $qtypeobj->save_question($question, $fromform);
add an update / insert
if ($question_obe = $DB->get_record('question_obe', array('question' => $question->id)) {
$question_obe->obe_category = $fromform->obe_category;
$DB->update_record('question_obe', $question_obe);
} else {
$question_obe = new stdClass();
$question_obe->question = $question->id;
$question_obe->obe_category = $fromform->obe_category;
$DB->insert_record('question_obe', $question_obe);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.