Skip to content

Commit

Permalink
Give legacy questions a default model if it is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed May 23, 2024
1 parent e60f1c2 commit 7d6ee8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion question.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function grade_response(array $response) : array {
* @param string $aiprompt
* @param number $defaultmark
* @param string $markscheme
* @return void
* @return string;
*/
public function build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme) {
$responsetext = strip_tags($response);
Expand Down
44 changes: 25 additions & 19 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function is_manual_graded() {
* @return array
*/
public function response_file_areas() {
return array('attachments', 'answer');
return ['attachments', 'answer'];
}
/**
* Loads the question type specific options for the question
Expand All @@ -63,7 +63,7 @@ public function response_file_areas() {
public function get_question_options($question) {
global $DB;
$question->options = $DB->get_record('qtype_aitext',
array('questionid' => $question->id), '*', MUST_EXIST);
['questionid' => $question->id], '*', MUST_EXIST);
parent::get_question_options($question);
}

Expand All @@ -90,7 +90,7 @@ public function save_defaults_for_new_questions(stdClass $fromform): void {
public function save_question_options($formdata) {
global $DB;
$context = $formdata->context;
$options = $DB->get_record('qtype_aitext', array('questionid' => $formdata->id));
$options = $DB->get_record('qtype_aitext', ['questionid' => $formdata->id]);
if (!$options) {
$options = new stdClass();
$options->questionid = $formdata->id;
Expand All @@ -110,7 +110,7 @@ public function save_question_options($formdata) {
// TODO find out what it should save and ensure it is available as text not arrays.
$formdata->graderinfo = [
'text' => '',
'format' => FORMAT_HTML
'format' => FORMAT_HTML,
];
$options->responsetemplate = $formdata->responsetemplate['text'];
$options->responsetemplateformat = $formdata->responsetemplate['format'];
Expand Down Expand Up @@ -147,7 +147,13 @@ protected function initialise_question_instance(question_definition $question, $
$question->aiprompt = $questiondata->options->aiprompt;
$question->markscheme = $questiondata->options->markscheme;
$question->sampleanswer = $questiondata->options->sampleanswer;
$question->model = $questiondata->options->model;
/* Legacy quesitons may not have a model set, so assign the first in the settings */
if (empty($question->model)) {
$model = explode(",", get_config('tool_aiconnect', 'model'))[0];
$question->model = $model;
} else {
$question->model = $questiondata->options->model;
}
}
/**
* Delete a question from the database
Expand All @@ -159,7 +165,7 @@ protected function initialise_question_instance(question_definition $question, $
public function delete_question($questionid, $contextid) {
global $DB;

$DB->delete_records('qtype_aitext', array('questionid' => $questionid));
$DB->delete_records('qtype_aitext', ['questionid' => $questionid]);
parent::delete_question($questionid, $contextid);
}

Expand All @@ -170,11 +176,11 @@ public function delete_question($questionid, $contextid) {
* @return array
*/
public function response_formats() {
return array(
return [
'editor' => get_string('formateditor', 'qtype_aitext'),
'plain' => get_string('formatplain', 'qtype_aitext'),
'monospaced' => get_string('formatmonospaced', 'qtype_aitext'),
);
];
}

/**
Expand All @@ -183,10 +189,10 @@ public function response_formats() {
* @return array
*/
public function response_required_options() {
return array(
return [
1 => get_string('responseisrequired', 'qtype_aitext'),
0 => get_string('responsenotrequired', 'qtype_aitext'),
);
];
}

/**
Expand All @@ -212,13 +218,13 @@ public function response_sizes() {
* @return array
*/
public function attachment_options() {
return array(
return [
0 => get_string('no'),
1 => '1',
2 => '2',
3 => '3',
-1 => get_string('unlimited'),
);
];
}

/**
Expand All @@ -228,12 +234,12 @@ public function attachment_options() {
* @return array
*/
public function attachments_required_options() {
return array(
return [
0 => get_string('attachmentsoptional', 'qtype_aitext'),
1 => '1',
2 => '2',
3 => '3'
);
3 => '3',
];
}

/**
Expand Down Expand Up @@ -283,13 +289,13 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
$qo->qtype = $questiontype;

foreach ($extraquestionfields as $field) {
$qo->$field = $format->getpath($data, array('#', $field, 0, '#'), '');
$qo->$field = $format->getpath($data, ['#', $field, 0, '#'], '');
}
// TODO add in other text fields.
$textfields = ['responsetemplate'];
foreach ($textfields as $field) {
$fmt = $format->get_format($format->getpath($data, array('#', $field.'format', 0, '#'), 0));
$qo->$field = $format->import_text_with_files($data, array('#', $field, 0), '', $fmt);
$fmt = $format->get_format($format->getpath($data, ['#', $field.'format', 0, '#'], 0));
$qo->$field = $format->import_text_with_files($data, ['#', $field, 0], '', $fmt);
}
if (isset($qo->maxwordlimit) && $qo->maxwordlimit > "") {
$qo->maxwordenabled = true;
Expand Down Expand Up @@ -354,7 +360,7 @@ public function get_text_fields() {
'responsesample',
'correctfeedback',
'incorrectfeedback',
'partiallycorrectfeedback'
'partiallycorrectfeedback',
];
}
/**
Expand Down

0 comments on commit 7d6ee8b

Please sign in to comment.