From b4cc1a9b9b16ea980221cb6c4143d901338b330e Mon Sep 17 00:00:00 2001 From: Marcus Green Date: Tue, 14 May 2024 22:07:15 +0100 Subject: [PATCH] Model can be selected for each question --- classes/external.php | 2 +- db/install.xml | 3 ++- db/upgrade.php | 16 ++++++++++++++++ edit_aitext_form.php | 10 +++++++++- question.php | 18 ++++++++++++++++-- questiontype.php | 10 ++++++++-- renderer.php | 1 + version.php | 2 +- 8 files changed, 54 insertions(+), 8 deletions(-) diff --git a/classes/external.php b/classes/external.php index e182052..a8a4ddf 100644 --- a/classes/external.php +++ b/classes/external.php @@ -18,7 +18,7 @@ * External * * @package qtype_aitext - * @author Justin Hunt - poodll.com + * @copyright Justin Hunt - poodll.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/install.xml b/db/install.xml index d25b862..9b43000 100755 --- a/db/install.xml +++ b/db/install.xml @@ -20,7 +20,8 @@ - + + diff --git a/db/upgrade.php b/db/upgrade.php index 0d53c44..6468b74 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -18,6 +18,7 @@ * AI Text question type upgrade code. * * @package qtype_aitext + * @copyright Marcus Green 2024 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -46,5 +47,20 @@ function xmldb_qtype_aitext_upgrade($oldversion) { } + if ($oldversion < 2024051100) { + + // Define field model to be added to qtype_aitext. + $table = new xmldb_table('qtype_aitext'); + $field = new xmldb_field('model', XMLDB_TYPE_CHAR, '60', null, null, null, null, 'sampleanswer'); + + // Conditionally launch add field model. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Aitext savepoint reached. + upgrade_plugin_savepoint(true, 2024051100, 'qtype', 'aitext'); + } + return true; } diff --git a/edit_aitext_form.php b/edit_aitext_form.php index 089f0dc..869ea17 100755 --- a/edit_aitext_form.php +++ b/edit_aitext_form.php @@ -57,7 +57,16 @@ protected function definition_inner($mform) { $mform->setType('markscheme', PARAM_RAW); $mform->setDefault('markscheme', get_config('qtype_aitext', 'defaultmarksscheme')); $mform->addHelpButton('markscheme', 'markscheme', 'qtype_aitext'); + $models = explode(",", get_config('tool_aiconnect', 'model')); + if (count($models) > 1 ) { + $models = array_combine($models, $models); + $mform->addElement('select', 'model', 'Models', $models); + } else { + $mform->addElement('hidden', 'model', $models[0]); + } + $mform->setType('model', PARAM_RAW); + // The question_edit_form that this class extends expects a general feedback field. $mform->addElement('html', '