Skip to content

Commit 5754ce3

Browse files
committed
Add delete buttons
1 parent a3ecbc5 commit 5754ce3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

edit_aitext_form.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ protected function definition_inner($mform) {
8686
, ['rows' => 10], $this->editoroptions);
8787
$mform->addElement('html', '</div>');
8888

89+
// Add repeated sample answer options along with the field for returned responses.
8990
$mform->addElement('header', 'prompttester', get_string('prompttester', 'qtype_aitext'));
9091

9192
$answeroptions = ['maxlen' => 50, 'rows' => 6, 'size' => 30];
@@ -95,13 +96,16 @@ protected function definition_inner($mform) {
9596
$mform->createElement('textarea', 'sampleanswers', get_string('sampleanswer', 'qtype_aitext'), $answeroptions),
9697
$mform->createElement('textarea', 'sampleanswereval', get_string('sampleanswereval', 'qtype_aitext'), $evaloptions),
9798
$mform->createelement('button', 'sampleanswerbtn', get_string('sampleanswerevaluate', 'qtype_aitext')),
99+
$mform->createElement('submit', 'delete', 'Delete sample',0),
98100
$mform->createElement('html', '<hr/>'),
99101
];
100102

101103
$repeateloptions = [];
102104
$mform->setType('sampleanswereval', PARAM_CLEANHTML);
103105
$mform->setType('optionid', PARAM_INT);
104106
$samplecount = $this->get_sample_count();
107+
$mform->registerNoSubmitButton('delete');
108+
105109
$this->repeat_elements(
106110
$repeatarray,
107111
$samplecount,
@@ -114,6 +118,7 @@ protected function definition_inner($mform) {
114118
'delete',
115119
);
116120

121+
117122
$mform->setType('option', PARAM_CLEANHTML);
118123

119124
$mform->addElement('header', 'responseoptions', get_string('responseoptions', 'qtype_aitext'));
@@ -164,11 +169,13 @@ protected function definition_inner($mform) {
164169
}
165170
protected function get_sample_count() {
166171
if (isset($this->question->id)) {
167-
if(isset($this->question->options->sampleanswers)) {
168-
return count($this->question->options->sampleanswers);
172+
if (isset($this->question->options->sampleanswers)) {
173+
if(count($this->question->options->sampleanswers) > 0) {
174+
return count($this->question->options->sampleanswers);
175+
}
169176
}
170177
}
171-
return 0;
178+
return 1;
172179
}
173180

174181
/**
@@ -195,7 +202,7 @@ protected function data_preprocessing($question) {
195202
$question->spellcheck = $question->options->spellcheck;
196203
// Make the count start from 0 like the repeat array elements.
197204
$question->sampleanswers = [];
198-
foreach($question->options->sampleanswers as $sampleanswer) {
205+
foreach ($question->options->sampleanswers as $sampleanswer) {
199206
$question->sampleanswers[] = $sampleanswer->response;
200207
}
201208

questiontype.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ protected function initialise_question_instance(question_definition $question, $
173173
$question->aiprompt = $questiondata->options->aiprompt;
174174
$question->markscheme = $questiondata->options->markscheme;
175175
parent::get_question_options($question);
176+
xdebug_break();
177+
$question->options->sampleanswers = $this->get_sampleanswers($question);
176178

177179
/* Legacy quesitons may not have a model set, so assign the first in the settings */
178180
if (empty($question->model)) {

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
$plugin->component = 'qtype_aitext';
28-
$plugin->version = 2024071895;
28+
$plugin->version = 2024111900;
2929
$plugin->requires = 2020110900;
3030
$plugin->release = '0.02';
3131
$plugin->maturity = MATURITY_BETA;

0 commit comments

Comments
 (0)