Skip to content

Commit

Permalink
MBS-9255: Fix coding styles
Browse files Browse the repository at this point in the history
  • Loading branch information
PM84 committed Jul 18, 2024
1 parent fdee5f8 commit b0c25c8
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 121 deletions.
6 changes: 3 additions & 3 deletions backup/moodle2/backup_qtype_aitext_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function define_question_plugin_structure() {

// Set source to populate the data.
$aitext->set_source_table('qtype_aitext',
array('questionid' => backup::VAR_PARENTID));
['questionid' => backup::VAR_PARENTID]);

// Don't need to annotate ids nor files.

Expand All @@ -71,8 +71,8 @@ protected function define_question_plugin_structure() {
* files to be processed both in backup and restore.
*/
public static function get_qtype_fileareas() {
return array(
return [
'graderinfo' => 'question_created',
);
];
}
}
6 changes: 3 additions & 3 deletions backup/moodle2/restore_qtype_aitext_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public function process_aitext($data) {
* Return the contents of this qtype to be processed by the links decoder
*/
public static function define_decode_contents() {
return array(
return [
new restore_decode_content('qtype_aitext', 'graderinfo', 'qtype_aitext'),
);
];
}

/**
Expand All @@ -112,7 +112,7 @@ protected function after_execute_question() {
AND qeo.id IS NULL
AND bi.backupid = ?
AND bi.itemname = ?
", array('aitext', $this->get_restoreid(), 'question_created'));
", ['aitext', $this->get_restoreid(), 'question_created']);

foreach ($aitextswithoutoptions as $q) {
$defaultoptions = new stdClass();
Expand Down
2 changes: 1 addition & 1 deletion classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function fetch_ai_grade_parameters(): external_function_parameters
['response' => new external_value(PARAM_TEXT, 'The students response to question'),
'defaultmark' => new external_value(PARAM_INT, 'The total possible score'),
'prompt' => new external_value(PARAM_TEXT, 'The AI Prompt'),
'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme')
'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme'),
]
);

Expand Down
6 changes: 3 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

namespace qtype_aitext\privacy;

use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\writer;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\writer;

/**
* Privacy Subsystem for qtype_aitext implementing user_preference_provider.
Expand All @@ -45,7 +45,7 @@ class provider implements
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$collection->add_user_preference('qtype_aitext_defaultmark', 'privacy:preference:defaultmark');
$collection->add_user_preference('qtype_aitext_responseformat', 'privacy:preference:responseformat');
$collection->add_user_preference('qtype_aitext_responsefieldlines', 'privacy:preference:responsefieldlines');
Expand Down
2 changes: 1 addition & 1 deletion db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
$definitions = [
'stringdata' => [
'mode' => cache_store::MODE_SESSION,
]
],
];
8 changes: 4 additions & 4 deletions db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
*/
defined('MOODLE_INTERNAL') || die();

$functions = array(
'qtype_aitext_fetch_ai_grade' => array(
$functions = [
'qtype_aitext_fetch_ai_grade' => [
'classname' => 'qtype_aitext_external',
'methodname' => 'fetch_ai_grade',
'description' => 'checks a response with the AI grader' ,
'capabilities' => 'mod/quiz:grade',
'type' => 'read',
'ajax' => true,
),
);
],
];
2 changes: 1 addition & 1 deletion db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
'month' => '*'
'month' => '*',
],
];
6 changes: 3 additions & 3 deletions edit_aitext_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function definition_inner($mform) {
$mform->addElement('header', 'graderinfoheader', get_string('graderinfoheader', 'qtype_aitext'));
$mform->setExpanded('graderinfoheader');
$mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_aitext'),
array('rows' => 10), $this->editoroptions);
['rows' => 10], $this->editoroptions);

// Load any JS that we need to make things happen, specifically the prompt tester.
$PAGE->requires->js_call_amd('qtype_aitext/editformhelper', 'init', []);
Expand All @@ -149,10 +149,10 @@ protected function data_preprocessing($question) {
$question->maxwordlimit = $question->options->maxwordlimit;
$question->aiprompt = $question->options->aiprompt;

$question->responsetemplate = array(
$question->responsetemplate = [
'text' => $question->options->responsetemplate,
'format' => $question->options->responsetemplateformat,
);
];

return $question;
}
Expand Down
30 changes: 15 additions & 15 deletions lang/en/qtype_aitext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
$string['cachedef_stringdata'] = 'Cachedef stringdata';
$string['defaultmarksscheme'] = 'Marks scheme';
$string['defaultmarksscheme_setting'] = 'This will be the default marks scheme for new questions. Questions authors should alter this to suit the question.';
$string['thedefaultmarksscheme'] = 'Deduct a point from the total score for each grammar or spelling mistake.';
$string['defaultprompt'] = 'AI Prompt';
$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.';
$string['thedefaultprompt'] = 'Explain if there is anything wrong with the grammar and spelling in the text.';
$string['disclaimer'] = 'Disclaimer';
$string['disclaimer_setting'] = 'Text appended to each response indicating feedback is from a Large Language Model and not a human';
$string['err_maxminmismatch'] = 'Maximum word limit must be greater than minimum word limit';
Expand All @@ -49,9 +47,11 @@
$string['formatmonospaced'] = 'Plain text, monospaced font';
$string['formatnoinline'] = 'No online text';
$string['formatplain'] = 'Plain text';
$string['graderinfo'] = 'Information for graders';
$string['get_llmmfeedback'] = 'Get LLM feedback';
$string['graderinfo'] = 'Information for graders';
$string['graderinfoheader'] = 'Grader information';
$string['jsonprompt'] = 'JSon prompt';
$string['jsonprompt_setting'] = 'Instructions sent to convert the returned value into json';
$string['markscheme'] = 'Mark scheme';
$string['markscheme_help'] = 'This will tell the AI grader how to give a numerical grade to the student response. The total possible score is this question\'s \'Default mark\'';
$string['maxwordlimit'] = 'Maximum word limit';
Expand All @@ -62,38 +62,38 @@
$string['minwordlimitboundary'] = 'This question requires a response of at least {$a->limit} words and you are attempting to submit {$a->count} words. Please expand your response and try again.';
$string['model'] = 'Model';
$string['nlines'] = '{$a} lines';
$string['prompt'] = 'Prompt';
$string['prompt_setting'] = 'Wrapper text for the prompt set to the AI System, [responsetext] is whatever the student typed as an answer. The ai prompt value from the question will be appended to this';
$string['jsonprompt'] = 'JSon prompt';
$string['jsonprompt_setting'] = 'Instructions sent to convert the returned value into json';
$string['pluginname'] = 'AI Text';
$string['pluginname_help'] = 'In response to a question, the respondent enters text. A response template may be provided. Responses are given a preliminary grade by an AI system (e.g. ChatGPT) then can be graded manually.';
$string['pluginname_link'] = 'question/type/AI Text';
$string['pluginnameadding'] = 'Adding an AI Text question';
$string['pluginnameediting'] = 'Editing an AI Text question';
$string['pluginnamesummary'] = 'Allows a response of a file upload and/or online text. The student response is processed by the configured AI/Large language model which returns feedback and optionally a grade..';
$string['privacy:metadata'] = 'AI Text question type plugin allows question authors to set default options as user preferences.';
$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.';
$string['privacy:preference:disclaimer'] = 'Text to indicate the feedback and/or marking is from a LLM';
$string['privacy:preference:responseformat'] = 'What is the response format (HTML editor, plain text, etc.)?';
$string['privacy::responsefieldlines'] = 'Number of lines indicating the size of the input box (textarea).';
$string['privacy:metadata'] = 'AI Text question type plugin allows question authors to set default options as user preferences.';
$string['privacy:preference:attachments'] = 'Number of allowed attachments.';
$string['privacy:preference:attachmentsrequired'] = 'Number of required attachments.';
$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.';
$string['privacy:preference:disclaimer'] = 'Text to indicate the feedback and/or marking is from a LLM';
$string['privacy:preference:maxbytes'] = 'Maximum file size.';
$string['privacy:preference:responseformat'] = 'What is the response format (HTML editor, plain text, etc.)?';
$string['prompt'] = 'Prompt';
$string['prompt_setting'] = 'Wrapper text for the prompt set to the AI System, [responsetext] is whatever the student typed as an answer. The ai prompt value from the question will be appended to this';
$string['prompttester'] = 'Prompt Tester';
$string['responsefieldlines'] = 'Input box size';
$string['responseformat'] = 'Response format';
$string['responseoptions'] = 'Response options';
$string['responsenotrequired'] = 'Text input is optional';
$string['responseisrequired'] = 'Require the student to enter text';
$string['responsenotrequired'] = 'Text input is optional';
$string['responseoptions'] = 'Response options';
$string['responsetemplate'] = 'Response template';
$string['responsetemplateheader'] = 'Response template';
$string['responsetemplate_help'] = 'Any text entered here will be displayed in the response input box when a new attempt at the question starts.';
$string['showprompt'] = 'Show prompt';
$string['responsetemplateheader'] = 'Response template';
$string['sampleanswer'] = 'Sample Answer';
$string['sampleanswer_help'] = 'The sample answer can be used to test how the AI grader will respond to a given response.';
$string['sampleanswerempty'] = 'Make sure that you have an AI prompt and sample answer before testing.';
$string['sampleanswerevaluate'] = 'Evaluate Sample Answer';
$string['showprompt'] = 'Show prompt';
$string['thedefaultmarksscheme'] = 'Deduct a point from the total score for each grammar or spelling mistake.';
$string['thedefaultprompt'] = 'Explain if there is anything wrong with the grammar and spelling in the text.';
$string['untestedquestionbehaviour'] = 'Untested question behaviour';
$string['wordcount'] = 'Word count: {$a}';
$string['wordcounttoofew'] = 'Word count: {$a->count}, less than the required {$a->limit} words.';
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_aitext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
function qtype_aitext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_aitext', $filearea, $args, $forcedownload, $options);
Expand Down
10 changes: 5 additions & 5 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function apply_attempt_state(question_attempt_step $step) {
* @param array $response
* @return void
*/
public function grade_response(array $response) : array {
public function grade_response(array $response): array {
if (!$this->is_complete_response($response)) {
$grade = [0 => 0, question_state::$needsgrading];
return $grade;
Expand Down Expand Up @@ -224,7 +224,7 @@ public function process_feedback(string $feedback) {
$contentobject = json_decode($feedback);
if (json_last_error() === JSON_ERROR_NONE) {
$contentobject->feedback = trim($contentobject->feedback);
$contentobject->feedback = preg_replace(array('/\[\[/', '/\]\]/'), '"', $contentobject->feedback);
$contentobject->feedback = preg_replace(['/\[\[/', '/\]\]/'], '"', $contentobject->feedback);
$disclaimer = get_config('qtype_aitext', 'disclaimer');
$disclaimer = str_replace("[[model]]", $this->model, $disclaimer);
$contentobject->feedback .= ' '.$this->llm_translate($disclaimer);
Expand All @@ -244,7 +244,7 @@ public function process_feedback(string $feedback) {
* @param string $text
* @return string
*/
protected function llm_translate(string $text) :string {
protected function llm_translate(string $text): string {
if (current_language() == 'en') {
return $text;
}
Expand All @@ -266,12 +266,12 @@ protected function llm_translate(string $text) :string {
* @param string $value
* @return void
*/
protected function insert_attempt_step_data(string $name, string $value ) :void {
protected function insert_attempt_step_data(string $name, string $value ): void {
global $DB;
$data = [
'attemptstepid' => $this->step->get_id(),
'name' => $name,
'value' => $value
'value' => $value,
];
$DB->insert_record('question_attempt_step_data', $data);
}
Expand Down
38 changes: 19 additions & 19 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function formulation_and_controls(question_attempt $qa,

if (!$step->has_qt_var('answer') && empty($options->readonly)) {
// Question has never been answered, fill it with response template.
$step = new question_attempt_step(array('answer' => $question->responsetemplate));
$step = new question_attempt_step(['answer' => $question->responsetemplate]);
}

if (empty($options->readonly)) {
Expand Down Expand Up @@ -94,17 +94,17 @@ public function formulation_and_controls(question_attempt $qa,

$result = '';
$result .= html_writer::tag('div', $question->format_questiontext($qa),
array('class' => 'qtext'));
['class' => 'qtext']);

$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::tag('div', $answer, array('class' => 'answer'));
$result .= html_writer::start_tag('div', ['class' => 'ablock']);
$result .= html_writer::tag('div', $answer, ['class' => 'answer']);

// If there is a response and min/max word limit is set in the form then check the response word count.
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
$question->get_validation_error($step->get_qt_data()), ['class' => 'validationerror']);
}
$result .= html_writer::tag('div', $files, array('class' => 'attachments'));
$result .= html_writer::tag('div', $files, ['class' => 'attachments']);
$result .= html_writer::end_tag('div');

return $result;
Expand Down Expand Up @@ -152,7 +152,7 @@ public function files_read_only(question_attempt $qa, question_display_options $
foreach ($files as $file) {
$out = html_writer::link($qa->get_response_file_url($file),
$this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()));
'moodle', ['class' => 'icon']) . ' ' . s($file->get_filename()));
if (!empty($CFG->enableplagiarism)) {
require_once($CFG->libdir . '/plagiarismlib.php');

Expand Down Expand Up @@ -373,16 +373,16 @@ public function response_area_input($name, $qa, $step, $lines, $context) {
'class' => 'sr-only',
'for' => $id,
]);
$output .= html_writer::start_tag('div', array('class' =>
$this->class_name() . ' qtype_aitext_response'));
$output .= html_writer::start_tag('div', ['class' =>
$this->class_name() . ' qtype_aitext_response']);
$output .= html_writer::tag('div', html_writer::tag('textarea', s($response),
array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60, 'class' => 'form-control')));
['id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60, 'class' => 'form-control']));

$output .= html_writer::start_tag('div');
if (count($formats) == 1) {
reset($formats);
$output .= html_writer::empty_tag('input', array('type' => 'hidden',
'name' => $inputname . 'format', 'value' => key($formats)));
$output .= html_writer::empty_tag('input', ['type' => 'hidden',
'name' => $inputname . 'format', 'value' => key($formats)]);

} else {
$output .= html_writer::label(get_string('format'), 'menu' . $inputname . 'format', false);
Expand Down Expand Up @@ -438,7 +438,7 @@ protected function prepare_response_for_editing($name,
*/
protected function get_editor_options($context) {
// Disable the text-editor autosave because quiz has it's own auto save function.
return array('context' => $context, 'autosave' => false);
return ['context' => $context, 'autosave' => false];
}

/**
Expand All @@ -451,7 +451,7 @@ protected function get_editor_options($context) {
* @return array filepicker options for the editor.
*/
protected function get_filepicker_options($context, $draftitemid) {
return array('return_types' => FILE_INTERNAL | FILE_EXTERNAL);
return ['return_types' => FILE_INTERNAL | FILE_EXTERNAL];
}

/**
Expand Down Expand Up @@ -580,21 +580,21 @@ protected function get_filepicker_options($context, $draftitemid) {
* @return string
*/
protected function filepicker_html($inputname, $draftitemid) {
$nonjspickerurl = new moodle_url('/repository/draftfiles_manager.php', array(
$nonjspickerurl = new moodle_url('/repository/draftfiles_manager.php', [
'action' => 'browse',
'env' => 'editor',
'itemid' => $draftitemid,
'subdirs' => false,
'maxfiles' => -1,
'sesskey' => sesskey(),
));
]);

return html_writer::empty_tag('input', array('type' => 'hidden',
'name' => $inputname . ':itemid', 'value' => $draftitemid)) .
return html_writer::empty_tag('input', ['type' => 'hidden',
'name' => $inputname . ':itemid', 'value' => $draftitemid]) .
html_writer::tag('noscript', html_writer::tag('div',
html_writer::tag('object', '', array('type' => 'text/html',
html_writer::tag('object', '', ['type' => 'text/html',
'data' => $nonjspickerurl, 'height' => 160, 'width' => 600,
'style' => 'border: 1px solid #000;'))));
'style' => 'border: 1px solid #000;'])));
}
}

Expand Down
Loading

0 comments on commit b0c25c8

Please sign in to comment.