Skip to content

Commit

Permalink
Fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 14, 2024
1 parent d16b271 commit 14e04a9
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 251 deletions.
28 changes: 14 additions & 14 deletions backup/moodle2/backup_qtype_varnumunit_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ protected function define_question_plugin_structure() {
$this->add_question_qtype_varnumunit_units($pluginwrapper);

// Now create the qtype own structures.
$varnumunit = new backup_nested_element('varnumunit', array('id'), array(
'randomseed', 'recalculateeverytime', 'requirescinotation', 'unitfraction'));
$varnumunit = new backup_nested_element('varnumunit', ['id'], [
'randomseed', 'recalculateeverytime', 'requirescinotation', 'unitfraction']);

// Now the own qtype tree.
$pluginwrapper->add_child($varnumunit);

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

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

Expand All @@ -83,8 +83,8 @@ protected function add_question_qtype_varnumunit_vars($element) {

// Define the elements.
$vars = new backup_nested_element('vars');
$var = new backup_nested_element('var', array('id'),
array('varno', 'nameorassignment'));
$var = new backup_nested_element('var', ['id'],
['varno', 'nameorassignment']);

$this->add_question_qtype_varnumunit_variants($var);

Expand All @@ -94,7 +94,7 @@ protected function add_question_qtype_varnumunit_vars($element) {

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

protected function add_question_qtype_varnumunit_variants($element) {
Expand All @@ -106,16 +106,16 @@ protected function add_question_qtype_varnumunit_variants($element) {

// Define the elements.
$variants = new backup_nested_element('variants');
$variant = new backup_nested_element('variant', array('id'),
array('varid', 'variantno', 'value'));
$variant = new backup_nested_element('variant', ['id'],
['varid', 'variantno', 'value']);

// Build the tree.
$element->add_child($variants);
$variants->add_child($variant);

// Set source to populate the data.
$variant->set_source_table('qtype_varnumunit_variants',
array('varid' => backup::VAR_PARENTID));
['varid' => backup::VAR_PARENTID]);
}

protected function add_question_qtype_varnumunit_answers($element) {
Expand All @@ -127,9 +127,9 @@ protected function add_question_qtype_varnumunit_answers($element) {

// Define the elements.
$answers = new backup_nested_element('varnumunit_answers');
$answer = new backup_nested_element('varnumunit_answer', array('id'), array(
$answer = new backup_nested_element('varnumunit_answer', ['id'], [
'answerid', 'error', 'sigfigs', 'checknumerical', 'checkscinotation',
'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat'));
'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat']);

// Build the tree.
$element->add_child($answers);
Expand All @@ -142,7 +142,7 @@ protected function add_question_qtype_varnumunit_answers($element) {
JOIN {question_answers} ans ON ans.id = vans.answerid
WHERE ans.question = :question
ORDER BY id',
array('question' => backup::VAR_PARENTID));
['question' => backup::VAR_PARENTID]);
// Don't need to annotate ids or files.
}

Expand All @@ -164,7 +164,7 @@ protected function add_question_qtype_varnumunit_units($element) {

// Set source to populate the data.
$unit->set_source_table('qtype_varnumunit_units',
array('questionid' => backup::VAR_PARENTID), 'id ASC');
['questionid' => backup::VAR_PARENTID], 'id ASC');
}

/**
Expand All @@ -174,6 +174,6 @@ protected function add_question_qtype_varnumunit_units($element) {
* files to be processed both in backup and restore.
*/
public static function get_qtype_fileareas() {
return array('unitsfeedback' => 'qtype_varnumunit_unit');
return ['unitsfeedback' => 'qtype_varnumunit_unit'];
}
}
6 changes: 3 additions & 3 deletions backup/moodle2/restore_qtype_varnumunit_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class restore_qtype_varnumunit_plugin extends restore_qtype_plugin {
*/
protected function define_question_plugin_structure() {

$paths = array();
$paths = [];

// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);

$elements = array('qtype_varnumunit' => '/varnumunit',
$elements = ['qtype_varnumunit' => '/varnumunit',
'qtype_varnumunit_answer' => '/varnumunit_answers/varnumunit_answer',
'qtype_varnumunit_var' => '/vars/var',
'qtype_varnumunit_variant' => '/vars/var/variants/variant',
'qtype_varnumunit_unit' => '/units/unit');
'qtype_varnumunit_unit' => '/units/unit'];
foreach ($elements as $elename => $path) {
$elepath = $this->get_pathfor($path);
$paths[] = new restore_path_element($elename, $elepath);
Expand Down
4 changes: 2 additions & 2 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static function varnumunit_view() {
'templates' => [
[
'id' => 'main',
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumunit/mobile/varnumunit.html')
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumunit/mobile/varnumunit.html'),
],
],
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumunit/mobile/varnumunit.js')
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumunit/mobile/varnumunit.js'),
];
}
}
10 changes: 5 additions & 5 deletions db/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
'method' => 'varnumunit_view',
'styles' => [
'url' => $CFG->wwwroot . '/question/type/varnumericset/mobileapp.css',
'version' => 2019040200
'version' => 2019040200,
],
'init' => 'varnumunit_view'
'init' => 'varnumunit_view',
],
],
'lang' => [ // Language strings to be used.
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset']
]
]
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset'],
],
],
];
69 changes: 32 additions & 37 deletions edit_varnumunit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/question/type/varnumericset/edit_varnumericset_form_base.php');
Expand All @@ -43,18 +42,15 @@ public function qtype() {

/**
* Get list of form elements to repeat for each 'units' block.
* @param object $mform the form being built.
* @param $label the label to use for the header.
* @param $gradeoptions the possible grades for each answer.
* @param $repeatedoptions reference to array of repeated options to fill
* @param $unitoption reference to return the name of $question->options
* field holding an array of units
* @param MoodleQuickForm $mform the form being built.
* @param string $label the label to use for the header.
* @param array $gradeoptions the possible grades for each answer.
* @return array of form fields.
*/
protected function get_per_unit_fields($mform, $label, $gradeoptions) {
$repeated = array();
$repeated = [];
$repeated[] = $mform->createElement('textarea', 'units', $label,
array('rows' => '2', 'cols' => '60', 'class' => 'textareamonospace'));
['rows' => '2', 'cols' => '60', 'class' => 'textareamonospace']);

$spaceinunitoptions = qtype_varnumunit::spaceinunit_options();
$repeated[] = $mform->createElement('select', 'spaceinunit',
Expand All @@ -67,7 +63,7 @@ protected function get_per_unit_fields($mform, $label, $gradeoptions) {
get_string('gradenoun'), $gradeoptions);
$repeated[] = $mform->createElement('editor', 'unitsfeedback',
get_string('feedback', 'question'),
array('rows' => 5), $this->editoroptions);
['rows' => 5], $this->editoroptions);
return $repeated;
}

Expand All @@ -78,6 +74,7 @@ protected function data_preprocessing($question) {

/**
* Perform the necessary preprocessing for the unit fields.
*
* @param object $question the data being passed to the form.
* @return object $question the modified data.
*/
Expand All @@ -86,11 +83,11 @@ protected function data_preprocessing_units($question) {
return $question;
}

$question->units = array();
$question->unitsfraction = array();
$question->spaceinunit = array();
$question->units = [];
$question->unitsfraction = [];
$question->spaceinunit = [];
$question->spacesfeedback = [];
$question->replacedash = array();
$question->replacedash = [];

$key = 0;
foreach ($question->options->units as $unitid => $unit) {
Expand Down Expand Up @@ -129,7 +126,7 @@ protected function data_preprocessing_units($question) {

protected function unit_feedback_html_element_preprocess($draftitemidkey, $unitid, $feedback, $feedbackformat, $filearea) {
// Feedback field and attached files.
$formelementdata = array();
$formelementdata = [];
$draftitemid = file_get_submitted_draft_itemid($draftitemidkey);
$formelementdata['text'] = file_prepare_draft_area(
$draftitemid,
Expand All @@ -149,17 +146,17 @@ protected function unit_feedback_html_element_preprocess($draftitemidkey, $uniti
/**
* Add a set of form fields, obtained from get_per_answer_fields, to the form,
* one for each existing answer, with some blanks for some new ones.
* @param object $mform the form being built.
* @param $label the label to use for each option.
* @param $gradeoptions the possible grades for each answer.
* @param int|\the $minoptions the minimum number of answer blanks to display.
* @param MoodleQuickForm $mform the form being built.
* @param string $label the label to use for each option.
* @param array $gradeoptions the possible grades for each answer.
* @param int $minoptions the minimum number of answer blanks to display.
* Default QUESTION_NUMANS_START.
* @param int|\the $addoptions the number of answer blanks to add. Default QUESTION_NUMANS_ADD.
* @param int $addoptions the number of answer blanks to add. Default QUESTION_NUMANS_ADD.
* @return void
*/
protected function add_per_unit_fields(&$mform, $label, $gradeoptions,
$minoptions = QUESTION_NUMANS_START, $addoptions = QUESTION_NUMANS_ADD) {
global $DB;
protected function add_per_unit_fields($mform, $label, $gradeoptions,
$minoptions = QUESTION_NUMANS_START, $addoptions = QUESTION_NUMANS_ADD) {

$repeated = $this->get_per_unit_fields($mform, $label, $gradeoptions);

if (isset($this->question->options)) {
Expand All @@ -179,15 +176,15 @@ protected function add_per_unit_fields(&$mform, $label, $gradeoptions,
$repeatsatstart = $minoptions;
}

$repeatedoptions = array();
$repeatedoptions = [];
$repeatedoptions['units']['type'] = PARAM_RAW_TRIMMED;
$repeatedoptions["units"]['helpbutton'] = array('units', 'qtype_varnumunit');
$repeatedoptions["units"]['helpbutton'] = ['units', 'qtype_varnumunit'];
$repeatedoptions["spacesfeedback"]['helpbutton'] = ['spacingfeedback', 'qtype_varnumunit'];
// Wating for #257559 Mform disableif does not work on editor element [MDL-29701]. Once this merged, this should work.
$repeatedoptions["spacesfeedback"]['disabledif'] = ['spaceinunit', 'neq',
qtype_varnumunit::SPACEINUNIT_PRESERVE_SPACE_REQUIRE];
$repeatedoptions["spacesfeedback"]['default'] = [
'text' => get_string('spacingfeedback_default', 'qtype_varnumunit')
'text' => get_string('spacingfeedback_default', 'qtype_varnumunit'),
];
$this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions,
'nounits', 'addunits', $addoptions,
Expand All @@ -211,7 +208,7 @@ protected function add_other_unit_fields($mform) {
get_string('anyotherunit', 'qtype_varnumunit'));
$mform->addElement('static', 'otherunitfraction', get_string('gradenoun'), '0%');
$mform->addElement('editor', 'otherunitfeedback', get_string('feedback', 'question'),
array('rows' => 5), $this->editoroptions);
['rows' => 5], $this->editoroptions);
}

protected function add_answer_form_part($mform) {
Expand All @@ -238,16 +235,14 @@ protected function definition() {

$mform->removeElement('requirescinotation');

$requirescinotationoptions = array(
$requirescinotationoptions = [
qtype_varnumunit::SUPERSCRIPT_SCINOTATION_REQUIRED => get_string('superscriptscinotationrequired', 'qtype_varnumunit'),
qtype_varnumunit::SUPERSCRIPT_ALLOWED => get_string('superscriptallowed', 'qtype_varnumunit'),
qtype_varnumunit::SUPERSCRIPT_NONE => get_string('superscriptnone', 'qtype_varnumunit')
);
qtype_varnumunit::SUPERSCRIPT_NONE => get_string('superscriptnone', 'qtype_varnumunit'),
];

$requirescinotationel = $mform->createElement('select',
'requirescinotation',
get_string('superscripts', 'qtype_varnumunit'),
$requirescinotationoptions);
'requirescinotation', get_string('superscripts', 'qtype_varnumunit'), $requirescinotationoptions);

$mform->insertElementBefore($requirescinotationel, 'answersinstruct');
}
Expand All @@ -263,7 +258,7 @@ protected static function grade_weighting() {
// b. p/10 for 0 <= p <= 10
// c. 1/q for 1 <= q <= 10
// d. 1/20.
$rawfractions = array(
$rawfractions = [
1.0000000,
0.9000000,
0.8333333,
Expand All @@ -285,9 +280,9 @@ protected static function grade_weighting() {
0.1000000,
0.0500000,

);
];

$fractionoptions = array();
$fractionoptions = [];

foreach ($rawfractions as $fraction) {
$a = new stdClass();
Expand All @@ -304,7 +299,7 @@ public function validation($data, $files) {
$units = $data['units'];
$unitcount = 0;
$maxgrade = false;
$trimmedunits = array();
$trimmedunits = [];
foreach ($units as $key => $unit) {
$trimmedunit = trim($unit);
if ($trimmedunit !== '') {
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Checks file access for varnumunit questions.
*/
function qtype_varnumunit_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
function qtype_varnumunit_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_varnumunit', $filearea, $args, $forcedownload, $options);
Expand Down
12 changes: 6 additions & 6 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function grade_response(array $response) {
$gradenumerical = $this->grade_numeric_part_of_response($response);
$gradeunit = $this->grade_unit_part_of_response($response);
$overallgrade = $this->weight_grades_for_num_and_unit_part($gradenumerical, $gradeunit);
return array($overallgrade, question_state::graded_state_for_fraction($overallgrade));
return [$overallgrade, question_state::graded_state_for_fraction($overallgrade)];
}

protected function weight_grades_for_num_and_unit_part($gradenumerical, $gradeunit) {
Expand Down Expand Up @@ -157,7 +157,7 @@ protected function split_response_into_num_and_unit($response) {
$num = new qtype_varnumericset_number_interpreter_number_with_optional_sci_notation($this->usesupeditor);
$num->match($response);
$numeric = $num->get_normalised();
return array($numeric, $num->get_postfix());
return [$numeric, $num->get_postfix()];
}

protected function feedback_for_post_prefix_parts($prefix, $postfix) {
Expand All @@ -166,10 +166,10 @@ protected function feedback_for_post_prefix_parts($prefix, $postfix) {

public function compute_final_grade($responses, $totaltries) {
// Remove non numeric part of response to pass numeric part to parent class.
$numericresponses = array();
$numericresponses = [];
foreach ($responses as $responseno => $response) {
list($numericpartofresponse, ) = $this->split_response_into_num_and_unit($response['answer']);
$numericresponses[] = array('answer' => $numericpartofresponse);
$numericresponses[] = ['answer' => $numericpartofresponse];
}

$numerictotaltries = $totaltries;
Expand Down Expand Up @@ -230,7 +230,7 @@ public function classify_response(array $response) {
$unitclassifiedresponse = new question_classified_response($unit->unit, $unitpart, $unit->fraction);
}

return array("unitpart" => $unitclassifiedresponse,
"numericpart" => $numericclassifiedresponse);
return ["unitpart" => $unitclassifiedresponse,
"numericpart" => $numericclassifiedresponse];
}
}
Loading

0 comments on commit 14e04a9

Please sign in to comment.