Skip to content

Commit 89c0d50

Browse files
committed
Add delete buttons
1 parent a3ecbc5 commit 89c0d50

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

backup/moodle2/restore_qtype_aitext_plugin.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ public static function define_decode_contents() {
102102
*/
103103
protected function after_execute_question() {
104104
global $DB;
105-
106-
$aitextswithoutoptions = $DB->get_records_sql("
105+
$qwithoutoptions = $DB->get_records_sql("
107106
SELECT q.*
108107
FROM {question} q
109108
JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
@@ -114,7 +113,7 @@ protected function after_execute_question() {
114113
AND bi.itemname = ?
115114
", ['aitext', $this->get_restoreid(), 'question_created']);
116115

117-
foreach ($aitextswithoutoptions as $q) {
116+
foreach ($qwithoutoptions as $q) {
118117
$defaultoptions = new stdClass();
119118
$defaultoptions->questionid = $q->id;
120119
$defaultoptions->aiprompt = '';

edit_aitext_form.php

Lines changed: 17 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', get_string('deletesample', 'qtype_aitext'),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,
@@ -162,13 +166,22 @@ protected function definition_inner($mform) {
162166
$PAGE->requires->js_call_amd('qtype_aitext/responserun', 'init', [$this->context->id]);
163167

164168
}
169+
170+
/**
171+
* retrieved from function get_sampleanswers in class quesitontype
172+
*
173+
* @return int count of sample answers
174+
*/
165175
protected function get_sample_count() {
166176
if (isset($this->question->id)) {
167-
if(isset($this->question->options->sampleanswers)) {
168-
return count($this->question->options->sampleanswers);
177+
if (isset($this->question->options->sampleanswers)) {
178+
if (count($this->question->options->sampleanswers) > 0) {
179+
return count($this->question->options->sampleanswers);
180+
}
169181
}
170182
}
171-
return 0;
183+
// Always have one empty sample answer set of fields.
184+
return 1;
172185
}
173186

174187
/**
@@ -195,7 +208,7 @@ protected function data_preprocessing($question) {
195208
$question->spellcheck = $question->options->spellcheck;
196209
// Make the count start from 0 like the repeat array elements.
197210
$question->sampleanswers = [];
198-
foreach($question->options->sampleanswers as $sampleanswer) {
211+
foreach ($question->options->sampleanswers as $sampleanswer) {
199212
$question->sampleanswers[] = $sampleanswer->response;
200213
}
201214

lang/en/qtype_aitext.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
$string['defaultmarksscheme_setting'] = 'This will be the default marks scheme for new questions. Questions authors should alter this to suit the question.';
4040
$string['defaultprompt'] = 'AI Prompt';
4141
$string['defaultprompt_setting'] = 'This will be the default AI prompt for new questions. It tells the AI grader how to analyse the student response. It is the guideline that AI uses to give feedback on the student response. Question authors should alter this to suit the question.';
42+
$string['deletesample'] = 'Delete sample';
4243
$string['disclaimer'] = 'Disclaimer';
4344
$string['disclaimer_setting'] = 'Text appended to each response indicating feedback is from a Large Language Model and not a human';
4445
$string['err_invalidbackend'] = 'Err invalidbackend;';
@@ -105,17 +106,17 @@
105106
$string['sampleanswer'] = 'Sample Answer';
106107
$string['sampleanswer_help'] = 'The sample answer can be used to test how the AI grader will respond to a given response.';
107108
$string['sampleanswerempty'] = 'Make sure that you have an AI prompt and sample answer before testing.';
108-
$string['sampleanswerevaluate'] = 'Evaluate Sample Answer';
109109
$string['sampleanswereval'] = 'Sample Answer Evaluation';
110+
$string['sampleanswerevaluate'] = 'Evaluate Sample Answer';
110111
$string['showprompt'] = 'Show prompt';
111112
$string['spellcheck_editor_desc'] = 'This is the text in which the spelling mistakes have been corrected by AI. You can edit this suggested correction.';
112113
$string['spellcheck_prompt'] = 'Reproduce the text 1:1. Give no feedback!. But correct all spelling mistakes in the following text: ';
113114
$string['spellcheck_student_anser_desc'] = 'This is the original student\'s answer';
114115
$string['spellcheckedit'] = 'Edit spellcheck';
115116
$string['spellcheckeditor'] = 'Edit the ai based spellcheck';
117+
$string['testresponses'] = 'Test responses';
116118
$string['thedefaultmarksscheme'] = 'Deduct a point from the total score for each grammar or spelling mistake.';
117119
$string['thedefaultprompt'] = 'Explain if there is anything wrong with the grammar and spelling in the text.';
118-
$string['testresponses'] = 'Test responses';
119120
$string['toolaimanager'] = 'Tool AI Manager';
120121
$string['translatepostfix'] = 'Translate postfix';
121122
$string['translatepostfix_text'] = 'The end of the prompt has &quot;translate the feedback to the language .current_language()&quot; appended';

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)