diff --git a/question.php b/question.php index 211da96..0b88a0c 100755 --- a/question.php +++ b/question.php @@ -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); diff --git a/questiontype.php b/questiontype.php index 9d98369..ec48161 100755 --- a/questiontype.php +++ b/questiontype.php @@ -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 @@ -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); } @@ -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; @@ -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']; @@ -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 @@ -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); } @@ -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'), - ); + ]; } /** @@ -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'), - ); + ]; } /** @@ -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'), - ); + ]; } /** @@ -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', + ]; } /** @@ -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; @@ -354,7 +360,7 @@ public function get_text_fields() { 'responsesample', 'correctfeedback', 'incorrectfeedback', - 'partiallycorrectfeedback' + 'partiallycorrectfeedback', ]; } /**