Commit 3d9645ae authored by ppichet's avatar ppichet
Browse files

MDL-38792 Update question/type in-line comments to codechecker standards

Correct bad formated infiles in question/type directories
parent 422f68fb
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -47,12 +46,12 @@ class moodle1_qtype_calculated_handler extends moodle1_qtype_handler {
*/
public function process_question(array $data, array $raw) {
// convert and write the answers first
// Convert and write the answers first.
if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname);
}
// convert and write the numerical units and numerical options
// Convert and write the numerical units and numerical options.
if (isset($data['calculated'][0]['numerical_units'])) {
$numericalunits = $data['calculated'][0]['numerical_units'];
} else {
......@@ -64,7 +63,7 @@ class moodle1_qtype_calculated_handler extends moodle1_qtype_handler {
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
// write dataset_definitions
// Write dataset_definitions.
if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) {
$datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition'];
} else {
......@@ -72,7 +71,7 @@ class moodle1_qtype_calculated_handler extends moodle1_qtype_handler {
}
$this->write_dataset_definitions($datasetdefinitions);
// write calculated_records
// Write calculated_records.
$this->xmlwriter->begin_tag('calculated_records');
foreach ($data['calculated'] as $calculatedrecord) {
$record = array(
......@@ -87,7 +86,7 @@ class moodle1_qtype_calculated_handler extends moodle1_qtype_handler {
}
$this->xmlwriter->end_tag('calculated_records');
// write calculated_options
// Write calculated_options.
$options = array(
'calculate_option' => array(
'id' => $this->converter->get_nextid(),
......
......@@ -38,31 +38,31 @@ class backup_qtype_calculated_plugin extends backup_qtype_plugin {
*/
protected function define_question_plugin_structure() {
// Define the virtual plugin element with the condition to fulfill
// Define the virtual plugin element with the condition to fulfill.
// Note: we use $this->pluginname so for extended plugins this will work
// automatically: calculatedsimple and calculatedmulti
// automatically: calculatedsimple and calculatedmulti.
$plugin = $this->get_plugin_element(null, '../../qtype', $this->pluginname);
// Create one standard named plugin element (the visible container)
// Create one standard named plugin element (the visible container).
$pluginwrapper = new backup_nested_element($this->get_recommended_name());
// connect the visible container ASAP
// Connect the visible container ASAP.
$plugin->add_child($pluginwrapper);
// This qtype uses standard question_answers, add them here
// to the tree before any other information that will use them
// to the tree before any other information that will use them.
$this->add_question_question_answers($pluginwrapper);
// This qtype uses standard numerical units, add them here
// This qtype uses standard numerical units, add them here.
$this->add_question_numerical_units($pluginwrapper);
// This qtype uses standard numerical options, add them here
// This qtype uses standard numerical options, add them here.
$this->add_question_numerical_options($pluginwrapper);
// This qtype uses standard datasets, add them here
// This qtype uses standard datasets, add them here.
$this->add_question_datasets($pluginwrapper);
// Now create the qtype own structures
// Now create the qtype own structures.
$calculatedrecords = new backup_nested_element('calculated_records');
$calculatedrecord = new backup_nested_element('calculated_record', array('id'), array(
'answer', 'tolerance', 'tolerancetype', 'correctanswerlength',
......@@ -74,20 +74,20 @@ class backup_qtype_calculated_plugin extends backup_qtype_plugin {
'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering'));
// Now the own qtype tree
// Now the own qtype tree.
$pluginwrapper->add_child($calculatedrecords);
$calculatedrecords->add_child($calculatedrecord);
$pluginwrapper->add_child($calculatedoptions);
$calculatedoptions->add_child($calculatedoption);
// set source to populate the data
// Set source to populate the data.
$calculatedrecord->set_source_table('question_calculated',
array('question' => backup::VAR_PARENTID));
$calculatedoption->set_source_table('question_calculated_options',
array('question' => backup::VAR_PARENTID));
// don't need to annotate ids nor files
// Don't need to annotate ids nor files.
return $plugin;
}
......
......@@ -41,17 +41,17 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
$paths = array();
// This qtype uses question_answers, add them
// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);
// This qtype uses question_numerical_options and question_numerical_units, add them
// This qtype uses question_numerical_options and question_numerical_units, add them.
$this->add_question_numerical_options($paths);
$this->add_question_numerical_units($paths);
// This qtype uses question datasets, add them
// This qtype uses question datasets, add them.
$this->add_question_datasets($paths);
// Add own qtype stuff
// Add own qtype stuff.
$elename = 'calculated_record';
$elepath = $this->get_pathfor('/calculated_records/calculated_record');
$paths[] = new restore_path_element($elename, $elepath);
......@@ -60,7 +60,7 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
$elepath = $this->get_pathfor('/calculated_options/calculated_option');
$paths[] = new restore_path_element($elename, $elepath);
return $paths; // And we return the interesting paths
return $paths; // And we return the interesting paths.
}
/**
......@@ -72,19 +72,19 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
$data = (object)$data;
$oldid = $data->id;
// Detect if the question is created or mapped
// Detect if the question is created or mapped.
$oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
true : false;
// If the question has been created by restore, we need to create its
// question_calculated too
// question_calculated too.
if ($questioncreated) {
// Adjust some columns
// Adjust some columns.
$data->question = $newquestionid;
$data->answer = $this->get_mappingid('question_answer', $data->answer);
// Insert record
// Insert record.
$newitemid = $DB->insert_record('question_calculated', $data);
}
}
......@@ -98,18 +98,18 @@ class restore_qtype_calculated_plugin extends restore_qtype_plugin {
$data = (object)$data;
$oldid = $data->id;
// Detect if the question is created or mapped
// Detect if the question is created or mapped.
$oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
true : false;
// If the question has been created by restore, we need to create its
// question_calculated too
// question_calculated too.
if ($questioncreated) {
// Adjust some columns
// Adjust some columns.
$data->question = $newquestionid;
// Insert record
// Insert record.
$newitemid = $DB->insert_record('question_calculated_options', $data);
}
}
......
......@@ -92,7 +92,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
$datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question);
$datasetmenus = array();
$label = "<div class='mdl-align'>".get_string('datasetrole', 'qtype_calculated')."</div>";
// explaining the role of datasets so other strings can be shortened
// Explaining the role of datasets so other strings can be shortened.
$mform->addElement('html', $label);
$mform->addElement('header', 'mandatoryhdr',
get_string('mandatoryhdr', 'qtype_calculated'));
......@@ -136,7 +136,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
$key++;
}
}
// temporary strings
// Temporary strings.
$mform->addElement('header', 'synchronizehdr',
get_string('synchronize', 'qtype_calculated'));
$mform->addElement('radio', 'synchronize', '',
......
......@@ -80,7 +80,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
$this->category = $category;
$this->categorycontext = context::instance_by_id($category->contextid);
//get the dataset defintions for this question
// Get the dataset defintions for this question.
if (empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions(
$question->id, $SESSION->calculated->definitionform->dataset);
......@@ -93,7 +93,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
foreach ($this->datasetdefs as $datasetdef) {
// Get maxnumber
// Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount;
}
......@@ -108,8 +108,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
protected function definition() {
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
$mform =& $this->_form;
$mform->setDisableShortforms();
......@@ -124,7 +123,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared(
$this->question, $this->datasetdefs);
$mform->addElement('static', 'listcategory', $label, $html2);
//----------------------------------------------------------------------
// ...----------------------------------------------------------------------.
$mform->addElement('submit', 'updatedatasets',
get_string('updatedatasetparam', 'qtype_calculated'));
$mform->registerNoSubmitButton('updatedatasets');
......@@ -269,7 +268,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
$mform->addGroup($addgrp1, 'addgrp1', '', ' ', false);
$mform->registerNoSubmitButton('showbutton');
$mform->closeHeaderBefore('addgrp1');
//----------------------------------------------------------------------
// ...----------------------------------------------------------------------.
$j = $this->noofitems * count($this->datasetdefs);
$k = optional_param('selectshow', 1, PARAM_INT);
for ($i = $this->noofitems; $i >= 1; $i--) {
......@@ -301,9 +300,9 @@ class question_dataset_dependent_items_form extends question_wizard_form {
$j--;
}
if ('' != $strquestionlabel && ($k > 0 )) {
//|| $this->outsidelimit || !empty($this->numbererrors )
// ... $this->outsidelimit || !empty($this->numbererrors ).
$repeated[] = $mform->addElement('static', "answercomment[$i]", $strquestionlabel);
// decode equations in question text
// Decode equations in question text.
$qtext = $this->qtypeobj->substitute_variables(
$this->question->questiontext, $data);
$textequations = $this->qtypeobj->find_math_equations($qtext);
......@@ -326,8 +325,8 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
$mform->addElement('static', 'outsidelimit', '', '');
//----------------------------------------------------------------------
// Non standard name for button element needed so not using add_action_buttons
// ...----------------------------------------------------------------------
// Non standard name for button element needed so not using add_action_buttons.
if (!($this->noofitems==0) ) {
$mform->addElement('submit', 'savechanges', get_string('savechanges'));
$mform->closeHeaderBefore('savechanges');
......@@ -387,7 +386,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
}
}
//fill out all data sets and also the fields for the next item to add.
// Fill out all data sets and also the fields for the next item to add.
$j = $this->noofitems * count($this->datasetdefs);
for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) {
$data = array();
......@@ -416,8 +415,8 @@ class question_dataset_dependent_items_form extends question_wizard_form {
$formdata['selectdelete'] = '1';
$formdata['selectadd'] = '1';
$j = $this->noofitems * count($this->datasetdefs)+1;
$data = array(); // data for comment_on_datasetitems later
//dataset generation dafaults
$data = array(); // Data for comment_on_datasetitems later.
// Dataset generation defaults.
if ($this->qtypeobj->supports_dataset_item_generation()) {
$itemnumber = $this->noofitems+1;
foreach ($this->datasetdefs as $defid => $datasetdef) {
......@@ -436,7 +435,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
}
}
//existing records override generated data depending on radio element
// Existing records override generated data depending on radio element.
$j = $this->noofitems * count($this->datasetdefs) + 1;
if (!$this->regenerate && !optional_param('updatedatasets', false, PARAM_BOOL) &&
!optional_param('updateanswers', false, PARAM_BOOL)) {
......
......@@ -36,17 +36,14 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Put any upgrade step following this.
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
// Put any upgrade step following this.
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
// Put any upgrade step following this.
return true;
}
......
......@@ -83,7 +83,7 @@ class qtype_calculated_qe2_attempt_updater extends question_qtype_attempt_update
protected function parse_response($state) {
if (strpos($state->answer, '-') < 7) {
// Broken state, skip it.
throw new coding_exception("Brokes state {$state->id} for calcluated
throw new coding_exception("Brokes state {$state->id} for calculated
question {$state->question}. (It did not specify a dataset.");
}
list($datasetbit, $realanswer) = explode('-', $state->answer, 2);
......@@ -92,7 +92,7 @@ class qtype_calculated_qe2_attempt_updater extends question_qtype_attempt_update
if (is_null($this->selecteditem)) {
$this->load_dataset($selecteditem);
} else if ($this->selecteditem != $selecteditem) {
$this->logger->log_assumption("Different states for calcluated question
$this->logger->log_assumption("Different states for calculated question
{$state->question} used different dataset items. Ignoring the change
in state {$state->id} and coninuting to use item {$this->selecteditem}.");
}
......@@ -248,7 +248,7 @@ class qtype_calculated_qe2_attempt_updater extends question_qtype_attempt_update
* @return float the computed result.
*/
protected function calculate_raw($expression) {
// This validation trick from http://php.net/manual/en/function.eval.php
// This validation trick from http://php.net/manual/en/function.eval.php.
if (!@eval('return true; $result = ' . $expression . ';')) {
return '[Invalid expression ' . $expression . ']';
}
......
......@@ -146,7 +146,7 @@ class qtype_calculated_edit_form extends qtype_numerical_edit_form {
$mform->createElement('submit', $addfieldsname, $addstring), 'listcategory');
$mform->registerNoSubmitButton('createoptionbutton');
// Editing as regular.
// Editing as regular question.
$mform->setType('single', PARAM_INT);
$mform->addElement('hidden', 'shuffleanswers', '1');
......
......@@ -315,7 +315,7 @@ class qtype_calculated_variable_substituter {
*/
public function format_float($x, $length = null, $format = null) {
if (!is_null($length) && !is_null($format)) {
if ($format == 1) {
if ($format == '1' ) { // Answer is to have $length decimals.
// Decimal places.
$x = sprintf('%.' . $length . 'F', $x);
} else if ($format == 2) {
......@@ -351,7 +351,7 @@ class qtype_calculated_variable_substituter {
* @return float the computed result.
*/
protected function calculate_raw($expression) {
// This validation trick from http://php.net/manual/en/function.eval.php
// This validation trick from http://php.net/manual/en/function.eval.php .
if (!@eval('return true; $result = ' . $expression . ';')) {
throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $expression);
}
......@@ -404,14 +404,14 @@ class qtype_calculated_variable_substituter {
*/
public function get_formula_errors($formula) {
// Validates the formula submitted from the question edit page.
// Returns false if everything is alright.
// Otherwise it constructs an error message
// Strip away dataset names
// Returns false if everything is alright
// otherwise it constructs an error message.
// Strip away dataset names.
while (preg_match('~\\{[[:alpha:]][^>} <{"\']*\\}~', $formula, $regs)) {
$formula = str_replace($regs[0], '1', $formula);
}
// Strip away empty space and lowercase it
// Strip away empty space and lowercase it.
$formula = strtolower(str_replace(' ', '', $formula));
$safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
......@@ -421,21 +421,21 @@ class qtype_calculated_variable_substituter {
"\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
$formula, $regs)) {
switch ($regs[2]) {
// Simple parenthesis
// Simple parenthesis.
case '':
if ((isset($regs[4]) && $regs[4]) || strlen($regs[3]) == 0) {
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
}
break;
// Zero argument functions
// Zero argument functions.
case 'pi':
if ($regs[3]) {
return get_string('functiontakesnoargs', 'qtype_calculated', $regs[2]);
}
break;
// Single argument functions (the most common case)
// Single argument functions (the most common case).
case 'abs': case 'acos': case 'acosh': case 'asin': case 'asinh':
case 'atan': case 'atanh': case 'bindec': case 'ceil': case 'cos':
case 'cosh': case 'decbin': case 'decoct': case 'deg2rad':
......@@ -448,7 +448,7 @@ class qtype_calculated_variable_substituter {
}
break;
// Functions that take one or two arguments
// Functions that take one or two arguments.
case 'log': case 'round':
if (!empty($regs[5]) || empty($regs[3])) {
return get_string('functiontakesoneortwoargs', 'qtype_calculated',
......@@ -456,14 +456,14 @@ class qtype_calculated_variable_substituter {
}
break;
// Functions that must have two arguments
// Functions that must have two arguments.
case 'atan2': case 'fmod': case 'pow':
if (!empty($regs[5]) || empty($regs[4])) {
return get_string('functiontakestwoargs', 'qtype_calculated', $regs[2]);
}
break;
// Functions that take two or more arguments
// Functions that take two or more arguments.
case 'min': case 'max':
if (empty($regs[4])) {
return get_string('functiontakesatleasttwo', 'qtype_calculated', $regs[2]);
......@@ -474,13 +474,13 @@ class qtype_calculated_variable_substituter {
return get_string('unsupportedformulafunction', 'qtype_calculated', $regs[2]);
}
// Exchange the function call with '1' and then chack for
// another function call...
// Exchange the function call with '1' and then check for another function call.
if ($regs[1]) {
// The function call is proceeded by an operator
// The function call is proceeded by an operator.
$formula = str_replace($regs[0], $regs[1] . '1', $formula);
} else {
// The function call starts the formula
// The function call starts the formula.
$formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
}
}
......@@ -488,7 +488,7 @@ class qtype_calculated_variable_substituter {
if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
} else {
// Formula just might be valid
// Formula just might be valid.
return false;
}
}
......
This diff is collapsed.
......@@ -57,11 +57,11 @@ class restore_qtype_calculatedmulti_plugin extends restore_qtype_calculated_plug
public function recode_legacy_state_answer($state) {
$answer = $state->answer;
$result = '';
// datasetxx-yy:zz format
// Datasetxx-yy:zz format.
if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) {
$itemid = $matches[1];
$subanswer = $matches[2];
// Delegate subanswer recode to multichoice qtype, faking one question_states record
// Delegate subanswer recode to multichoice qtype, faking one question_states record.
$substate = new stdClass();
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice');
......
......@@ -272,7 +272,7 @@ class qtype_calculatedmulti_qe2_attempt_updater extends question_qtype_attempt_u
* @return float the computed result.
*/
protected function calculate_raw($expression) {
// This validation trick from http://php.net/manual/en/function.eval.php
// This validation trick from http://php.net/manual/en/function.eval.php.
if (!@eval('return true; $result = ' . $expression . ';')) {
return '[Invalid expression ' . $expression . ']';
}
......
......@@ -156,7 +156,6 @@ class qtype_calculatedmulti_edit_form extends question_edit_form {
$mform->addHelpButton('answeroptions[0]', 'answeroptions', 'qtype_calculatedmulti');
$repeated = array();
// if ($this->editasmultichoice == 1) {
$nounits = optional_param('nounits', 1, PARAM_INT);
$mform->addElement('hidden', 'nounits', $nounits);
$mform->setType('nounits', PARAM_INT);
......
......@@ -42,7 +42,7 @@ class qtype_calculatedmulti extends qtype_calculated {
global $CFG, $DB;
$context = $question->context;
// Calculated options
// Calculated options.
$update = true;
$options = $DB->get_record('question_calculated_options',
array('question' => $question->id));
......@@ -61,7 +61,7 @@ class qtype_calculatedmulti extends qtype_calculated {
$options = $this->save_combined_feedback_helper($options, $question, $context, true);
$DB->update_record('question_calculated_options', $options);
// Get old versions of the objects
// Get old versions of the objects.
if (!$oldanswers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC')) {
$oldanswers = array();
......@@ -71,7 +71,7 @@ class qtype_calculatedmulti extends qtype_calculated {
$oldoptions = array();
}
// Insert all the new answers
// Insert all the new answers.
if (isset($question->answer) && !isset($question->answers)) {
$question->answers = $question->answer;
}
......@@ -94,12 +94,12 @@ class qtype_calculatedmulti extends qtype_calculated {
}
if (is_array($answerdata)) {
// Doing an import
// Doing an import.
$answer->answer = $this->import_or_save_files($answerdata,
$context, 'question', 'answer', $answer->id);
$answer->answerformat = $answerdata['format'];
} else {
// Saving the form
// Saving the form.
$answer->answer = $answerdata;
$answer->answerformat = FORMAT_HTML;
}
......@@ -110,7 +110,7 @@ class qtype_calculatedmulti extends qtype_calculated {
$DB->update_record("question_answers", $answer);
// Set up the options object
// Set up the options object.
if (!$options = array_shift($oldoptions)) {
$options = new stdClass();
}
......@@ -121,17 +121,17 @@ class qtype_calculatedmulti extends qtype_calculated {
$options->correctanswerlength = trim($question->correctanswerlength[$key]);
$options->correctanswerformat = trim($question->correctanswerformat[$key]);
// Save options
// Save options.
if (isset($options->id)) {
// reusing existing record
// Reusing existing record.
$DB->update_record('question_calculated', $options);
} else {
// new options
// New options.
$DB->insert_record('question_calculated', $options);
}
}
// delete old answer records
// Delete old answer records.
if (!empty($oldanswers)) {
foreach ($oldanswers as $oa) {
$DB->delete_records('question_answers', array('id' => $oa->id));
......@@ -220,7 +220,7 @@ class qtype_calculatedmulti extends qtype_calculated {
$delimiter = ': ';
foreach ($answers as $key => $answer) {
$answer->answer = $this->substitute_variables($answer->answer, $data);
//evaluate the equations i.e {=5+4)
// Evaluate the equations i.e {=5+4).
$qtext = '';
$qtextremaining = $answer->answer;
while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
......
......@@ -46,7 +46,7 @@ class qtype_calculatedmulti_test_helper extends question_test_helper {
* @return qtype_calculatedmulti_question
*/
public function make_calculatedmulti_question_sum() {
// TODO
// TODO.
question_bank::load_question_definition_classes('calculated');
$q = new qtype_calculatedmulti_question();
test_question_maker::initialise_a_question($q);
......