Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Correct bad formated infiles in question/type directories
  • Loading branch information...
commit 3d9645ae6e75ef29f7fdb3a3da5129bc980b24c8 1 parent 422f68f
@ppichet ppichet authored
Showing with 605 additions and 627 deletions.
  1. +5 −6 question/type/calculated/backup/moodle1/lib.php
  2. +12 −12 question/type/calculated/backup/moodle2/backup_qtype_calculated_plugin.class.php
  3. +13 −13 question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php
  4. +2 −2 question/type/calculated/datasetdefinitions_form.php
  5. +13 −14 question/type/calculated/datasetitems_form.php
  6. +3 −6 question/type/calculated/db/upgrade.php
  7. +3 −3 question/type/calculated/db/upgradelib.php
  8. +1 −1  question/type/calculated/edit_calculated_form.php
  9. +17 −17 question/type/calculated/question.php
  10. +181 −182 question/type/calculated/questiontype.php
  11. +2 −2 question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php
  12. +1 −1  question/type/calculatedmulti/db/upgradelib.php
  13. +0 −1  question/type/calculatedmulti/edit_calculatedmulti_form.php
  14. +11 −11 question/type/calculatedmulti/questiontype.php
  15. +1 −1  question/type/calculatedmulti/tests/helper.php
  16. +45 −45 question/type/calculatedsimple/edit_calculatedsimple_form.php
  17. +24 −24 question/type/calculatedsimple/questiontype.php
  18. +4 −5 question/type/description/questiontype.php
  19. +8 −8 question/type/edit_question_form.php
  20. +1 −2  question/type/essay/backup/moodle1/lib.php
  21. +7 −7 question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php
  22. +2 −2 question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php
  23. +4 −6 question/type/essay/db/upgrade.php
  24. +2 −2 question/type/essay/edit_essay_form.php
  25. +2 −3 question/type/multianswer/backup/moodle1/lib.php
  26. +8 −8 question/type/multianswer/backup/moodle2/backup_qtype_multianswer_plugin.class.php
  27. +16 −16 question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php
  28. +3 −6 question/type/multianswer/db/upgrade.php
  29. +24 −24 question/type/multianswer/questiontype.php
  30. +7 −8 question/type/multichoice/backup/moodle1/lib.php
  31. +8 −8 question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php
  32. +16 −16 question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
  33. +3 −3 question/type/multichoice/db/upgrade.php
  34. +1 −1  question/type/multichoice/db/upgradelib.php
  35. +3 −3 question/type/multichoice/edit_multichoice_form.php
  36. +3 −3 question/type/multichoice/question.php
  37. +5 −5 question/type/multichoice/questiontype.php
  38. +3 −3 question/type/multichoice/renderer.php
  39. +4 −5 question/type/numerical/backup/moodle1/lib.php
  40. +10 −10 question/type/numerical/backup/moodle2/backup_qtype_numerical_plugin.class.php
  41. +7 −7 question/type/numerical/backup/moodle2/restore_qtype_numerical_plugin.class.php
  42. +2 −5 question/type/numerical/db/upgrade.php
  43. +1 −1  question/type/numerical/question.php
  44. +8 −8 question/type/numerical/questiontype.php
  45. +1 −1  question/type/questionbase.php
  46. +15 −15 question/type/questiontypebase.php
  47. +3 −3 question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
  48. +2 −2 question/type/random/edit_random_form.php
  49. +1 −1  question/type/random/questiontype.php
  50. +6 −6 question/type/randomsamatch/backup/moodle2/backup_qtype_randomsamatch_plugin.class.php
  51. +6 −6 question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php
  52. +9 −9 question/type/randomsamatch/questiontype.php
  53. +2 −3 question/type/shortanswer/backup/moodle1/lib.php
  54. +8 −8 question/type/shortanswer/backup/moodle2/backup_qtype_shortanswer_plugin.class.php
  55. +5 −5 question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php
  56. +11 −11 question/type/shortanswer/db/upgrade.php
  57. +1 −1  question/type/shortanswer/question.php
  58. +2 −2 question/type/shortanswer/questiontype.php
  59. +2 −2 question/type/shortanswer/tests/question_test.php
  60. +2 −3 question/type/truefalse/backup/moodle1/lib.php
  61. +8 −8 question/type/truefalse/backup/moodle2/backup_qtype_truefalse_plugin.class.php
  62. +9 −9 question/type/truefalse/backup/moodle2/restore_qtype_truefalse_plugin.class.php
  63. +4 −4 question/type/truefalse/edit_truefalse_form.php
  64. +1 −1  question/type/truefalse/question.php
  65. +5 −5 question/type/truefalse/questiontype.php
  66. +3 −3 question/type/truefalse/renderer.php
  67. +2 −2 question/type/truefalse/tests/question_test.php
  68. +1 −1  question/type/truefalse/tests/upgradelibnewqe_test.php
View
11 question/type/calculated/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
<?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 @@ public function get_question_subpaths() {
*/
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 @@ public function process_question(array $data, array $raw) {
$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 @@ public function process_question(array $data, array $raw) {
}
$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 @@ public function process_question(array $data, array $raw) {
}
$this->xmlwriter->end_tag('calculated_records');
- // write calculated_options
+ // Write calculated_options.
$options = array(
'calculate_option' => array(
'id' => $this->converter->get_nextid(),
View
24 question/type/calculated/backup/moodle2/backup_qtype_calculated_plugin.class.php
@@ -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 @@ protected function define_question_plugin_structure() {
'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;
}
View
26 question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php
@@ -41,17 +41,17 @@ protected function define_question_plugin_structure() {
$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 @@ protected function define_question_plugin_structure() {
$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 @@ public function process_calculated_record($data) {
$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 @@ public function process_calculated_option($data) {
$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);
}
}
View
4 question/type/calculated/datasetdefinitions_form.php
@@ -92,7 +92,7 @@ protected function definition() {
$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 @@ protected function definition() {
$key++;
}
}
- // temporary strings
+ // Temporary strings.
$mform->addElement('header', 'synchronizehdr',
get_string('synchronize', 'qtype_calculated'));
$mform->addElement('radio', 'synchronize', '',
View
27 question/type/calculated/datasetitems_form.php
@@ -80,7 +80,7 @@ public function __construct($submiturl, $question, $regenerate) {
}
$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 @@ public function __construct($submiturl, $question, $regenerate) {
}
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 @@ public function __construct($submiturl, $question, $regenerate) {
}
protected function definition() {
- $labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
-
+ $labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
$mform =& $this->_form;
$mform->setDisableShortforms();
@@ -124,7 +123,7 @@ protected function definition() {
$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 @@ protected function definition() {
$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 @@ protected function definition() {
$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 @@ protected function definition() {
}
$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 @@ public function set_data($question) {
}
}
}
- //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 @@ public function set_data($question) {
$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 @@ public function set_data($question) {
}
}
- //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)) {
View
9 question/type/calculated/db/upgrade.php
@@ -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;
}
View
6 question/type/calculated/db/upgradelib.php
@@ -83,7 +83,7 @@ public function right_answer() {
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 @@ protected function parse_response($state) {
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 @@ public function calculate($expression) {
* @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 . ']';
}
View
2  question/type/calculated/edit_calculated_form.php
@@ -146,7 +146,7 @@ protected function definition_inner($mform) {
$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');
View
34 question/type/calculated/question.php
@@ -315,7 +315,7 @@ public function __construct(array $values, $decimalpoint) {
*/
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 @@ public function calculate($expression) {
* @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 @@ function ($matches) use ($vs, $format, $length) {
*/
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 @@ public function get_formula_errors($formula) {
"\\(($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 @@ public function get_formula_errors($formula) {
}
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 @@ public function get_formula_errors($formula) {
}
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 @@ public function get_formula_errors($formula) {
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 @@ public function get_formula_errors($formula) {
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;
}
}
View
363 question/type/calculated/questiontype.php
@@ -42,8 +42,8 @@ class qtype_calculated extends question_type {
public $wizardpagesnumber = 3;
public function get_question_options($question) {
- // First get the datasets and default options
- // the code is used for calculated, calculatedsimple and calculatedmulti qtypes
+ // First get the datasets and default options.
+ // The code is used for calculated, calculatedsimple and calculatedmulti qtypes.
global $CFG, $DB, $OUTPUT;
if (!$question->options = $DB->get_record('question_calculated_options',
array('question' => $question->id))) {
@@ -106,7 +106,7 @@ public function get_datasets_for_export($question) {
$def->maximum = $max;
$def->decimals = $dec;
if ($def->itemcount > 0) {
- // get the datasetitems
+ // Get the datasetitems.
$def->items = array();
if ($items = $this->get_database_dataset_items($def->id)) {
$n = 0;
@@ -128,12 +128,12 @@ public function get_datasets_for_export($question) {
public function save_question_options($question) {
global $CFG, $DB;
- // the code is used for calculated, calculatedsimple and calculatedmulti qtypes
+ // The code is used for calculated, calculatedsimple and calculatedmulti qtypes.
$context = $question->context;
if (isset($question->answer) && !isset($question->answers)) {
$question->answers = $question->answer;
}
- // calculated options
+ // Calculated options.
$update = true;
$options = $DB->get_record('question_calculated_options',
array('question' => $question->id));
@@ -142,7 +142,7 @@ public function save_question_options($question) {
$options = new stdClass();
$options->question = $question->id;
}
- // as used only by calculated
+ // As used only by calculated.
if (isset($question->synchronize)) {
$options->synchronize = $question->synchronize;
} else {
@@ -165,7 +165,7 @@ public function save_question_options($question) {
$DB->insert_record('question_calculated_options', $options);
}
- // Get old versions of the objects
+ // Get old versions of the objects.
$oldanswers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC');
@@ -182,7 +182,7 @@ public function save_question_options($question) {
$units = $result->units;
}
- // Insert all the new answers
+ // Insert all the new answers.
if (isset($question->answer) && !isset($question->answers)) {
$question->answers = $question->answer;
}
@@ -212,7 +212,7 @@ public function save_question_options($question) {
$DB->update_record("question_answers", $answer);
- // Set up the options object
+ // Set up the options object.
if (!$options = array_shift($oldoptions)) {
$options = new stdClass();
}
@@ -223,24 +223,24 @@ public function save_question_options($question) {
$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));
}
}
- // delete old answer records
+ // Delete old answer records.
if (!empty($oldoptions)) {
foreach ($oldoptions as $oo) {
$DB->delete_records('question_calculated', array('id' => $oo->id));
@@ -268,7 +268,7 @@ public function import_datasets($question) {
global $DB;
$n = count($question->dataset);
foreach ($question->dataset as $dataset) {
- // name, type, option,
+ // Name, type, option.
$datasetdef = new stdClass();
$datasetdef->name = $dataset->name;
$datasetdef->type = 1;
@@ -285,16 +285,16 @@ public function import_datasets($question) {
AND name = ?
AND category = ?
ORDER BY id DESC ", array($dataset->name, $question->category)
- )) { // so there is at least one
+ )) { // So there is at least one.
$sharedatasetdef = array_shift($sharedatasetdefs);
- if ($sharedatasetdef->options == $datasetdef->options) {// identical so use it
+ if ($sharedatasetdef->options == $datasetdef->options) {// Identical so use it.
$todo = 'useit';
$datasetdef = $sharedatasetdef;
- } else { // different so create a private one
+ } else { // Different so create a private one.
$datasetdef->category = 0;
$todo = 'create';
}
- } else { // no so create one
+ } else { // No so create one.
$datasetdef->category = $question->category;
$todo = 'create';
}
@@ -302,13 +302,13 @@ public function import_datasets($question) {
if ($todo == 'create') {
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
}
- // Create relation to the dataset:
+ // Create relation to the dataset.
$questiondataset = new stdClass();
$questiondataset->question = $question->id;
$questiondataset->datasetdefinition = $datasetdef->id;
$DB->insert_record('question_datasets', $questiondataset);
if ($todo == 'create') {
- // add the items
+ // Add the items.
foreach ($dataset->datasetitem as $dataitem) {
$datasetitem = new stdClass();
$datasetitem->definition = $datasetdef->id;
@@ -353,7 +353,7 @@ public function validate_form($form) {
if (empty($form->questiontext)) {
$calculatedmessages[] = get_string('missingquestiontext', 'qtype_calculated');
}
- // Verify formulas
+ // Verify formulas.
foreach ($form->answers as $key => $answer) {
if ('' === trim($answer)) {
$calculatedmessages[] = get_string(
@@ -392,16 +392,16 @@ public function finished_edit_wizard($form) {
public function wizardpagesnumber() {
return 3;
}
- // This gets called by editquestion.php after the standard question is saved
+ // This gets called by editquestion.php after the standard question is saved.
public function print_next_wizard_page($question, $form, $course) {
global $CFG, $SESSION, $COURSE;
- // Catch invalid navigation & reloads
+ // Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid='.$COURSE->id, 'The page you are loading has expired.', 3);
}
- // See where we're coming from
+ // See where we're coming from.
switch($form->wizardpage) {
case 'question':
require("$CFG->dirroot/question/type/calculated/datasetdefinitions.php");
@@ -416,11 +416,11 @@ public function print_next_wizard_page($question, $form, $course) {
}
}
- // This gets called by question2.php after the standard question is saved
+ // This gets called by question2.php after the standard question is saved.
public function &next_wizard_form($submiturl, $question, $wizardnow) {
global $CFG, $SESSION, $COURSE;
- // Catch invalid navigation & reloads
+ // Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid=' . $COURSE->id,
'The page you are loading has expired. Cannot get next wizard form.', 3);
@@ -429,7 +429,7 @@ public function &next_wizard_form($submiturl, $question, $wizardnow) {
$question = $SESSION->calculated->questionform;
}
- // See where we're coming from
+ // See where we're coming from.
switch($wizardnow) {
case 'datasetdefinitions':
require("$CFG->dirroot/question/type/calculated/datasetdefinitions_form.php");
@@ -485,32 +485,32 @@ public function display_question_editing_page($mform, $question, $wizardnow) {
* This method prepare the $datasets in a format similar to dadatesetdefinitions_form.php
* so that they can be saved
* using the function save_dataset_definitions($form)
- * when creating a new calculated question or
- * whenediting an already existing calculated question
+ * when creating a new calculated question or
+ * when editing an already existing calculated question
* or by function save_as_new_dataset_definitions($form, $initialid)
- * when saving as new an already existing calculated question
+ * when saving as new an already existing calculated question.
*
* @param object $form
* @param int $questionfromid default = '0'
*/
public function preparedatasets($form , $questionfromid = '0') {
- // the dataset names present in the edit_question_form and edit_calculated_form
- // are retrieved
+ // The dataset names present in the edit_question_form and edit_calculated_form
+ // are retrieved.
$possibledatasets = $this->find_dataset_names($form->questiontext);
$mandatorydatasets = array();
foreach ($form->answers as $answer) {
$mandatorydatasets += $this->find_dataset_names($answer);
}
- // if there are identical datasetdefs already saved in the original question.
- // either when editing a question or saving as new
- // they are retrieved using $questionfromid
+ // If there are identical datasetdefs already saved in the original question
+ // either when editing a question or saving as new,
+ // they are retrieved using $questionfromid.
if ($questionfromid != '0') {
$form->id = $questionfromid;
}
$datasets = array();
$key = 0;
- // always prepare the mandatorydatasets present in the answers
- // the $options are not used here
+ // Always prepare the mandatorydatasets present in the answers.
+ // The $options are not used here.
foreach ($mandatorydatasets as $datasetname) {
if (!isset($datasets[$datasetname])) {
list($options, $selected) =
@@ -520,9 +520,9 @@ public function preparedatasets($form , $questionfromid = '0') {
$key++;
}
}
- // do not prepare possibledatasets when creating a question
- // they will defined and stored with datasetdefinitions_form.php
- // the $options are not used here
+ // Do not prepare possibledatasets when creating a question.
+ // They will defined and stored with datasetdefinitions_form.php.
+ // The $options are not used here.
if ($questionfromid != '0') {
foreach ($possibledatasets as $datasetname) {
@@ -554,7 +554,7 @@ public function addnamecategory(&$question) {
};
if (!empty($categorydatasetdefs)) {
- // there is at least one with the same name
+ // There is at least one with the same name.
$questionname = '#' . $questionname;
foreach ($categorydatasetdefs as $def) {
if (strlen($def->name) + strlen($questionname) < 250) {
@@ -593,22 +593,22 @@ public function save_question($question, $form) {
}
$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
- $id = optional_param('id', 0, PARAM_INT); // question id
- // in case 'question'
- // for a new question $form->id is empty
- // when saving as new question
- // $question->id = 0, $form is $data from question2.php
- // and $data->makecopy is defined as $data->id is the initial question id
- // edit case. If it is a new question we don't necessarily need to
- // return a valid question object
-
- // See where we're coming from
+ $id = optional_param('id', 0, PARAM_INT); // Question id.
+ // In case 'question':
+ // For a new question $form->id is empty
+ // when saving as new question.
+ // The $question->id = 0, $form is $data from question2.php
+ // and $data->makecopy is defined as $data->id is the initial question id.
+ // Edit case. If it is a new question we don't necessarily need to
+ // return a valid question object.
+
+ // See where we're coming from.
switch($wizardnow) {
case '' :
- case 'question': // coming from the first page, creating the second
- if (empty($form->id)) { // for a new question $form->id is empty
+ case 'question': // Coming from the first page, creating the second.
+ if (empty($form->id)) { // or a new question $form->id is empty.
$question = parent::save_question($question, $form);
- //prepare the datasets using default $questionfromid
+ // Prepare the datasets using default $questionfromid.
$this->preparedatasets($form);
$form->id = $question->id;
$this->save_dataset_definitions($form);
@@ -618,7 +618,7 @@ public function save_question($question, $form) {
} else if (!empty($form->makecopy)) {
$questionfromid = $form->id;
$question = parent::save_question($question, $form);
- //prepare the datasets
+ // Prepare the datasets.
$this->preparedatasets($form, $questionfromid);
$form->id = $question->id;
$this->save_as_new_dataset_definitions($form, $questionfromid);
@@ -626,9 +626,9 @@ public function save_question($question, $form) {
$this->addnamecategory($question);
}
} else {
- // editing a question
+ // Editing a question.
$question = parent::save_question($question, $form);
- //prepare the datasets
+ // Prepare the datasets.
$this->preparedatasets($form, $question->id);
$form->id = $question->id;
$this->save_dataset_definitions($form);
@@ -638,10 +638,10 @@ public function save_question($question, $form) {
}
break;
case 'datasetdefinitions':
- // calculated options
- // it cannot go here without having done the first page
- // so the question_calculated_options should exist
- // only need to update the synchronize field
+ // Calculated options.
+ // It cannot go here without having done the first page,
+ // so the question_calculated_options should exist.
+ // We only need to update the synchronize field.
if (isset($form->synchronize)) {
$optionssynchronize = $form->synchronize;
} else {
@@ -699,7 +699,7 @@ public function get_random_guess_score($questiondata) {
}
public function supports_dataset_item_generation() {
- // Calcualted support generation of randomly distributed number data
+ // Calculated support generation of randomly distributed number data.
return true;
}
@@ -751,12 +751,14 @@ public function custom_generator_tools($datasetdef) {
? 'decimals'
: 'significantfigures'), 'qtype_calculated', $i);
}
- $menu1 = html_writer::label(get_string('lengthoption', 'qtype_calculated'), 'menucalclength', false, array('class' => 'accesshide'));
+ $menu1 = html_writer::label(get_string('lengthoption', 'qtype_calculated'),
+ 'menucalclength', false, array('class' => 'accesshide'));
$menu1 .= html_writer::select($lengthoptions, 'calclength[]', $regs[4], null);
$options = array('uniform' => get_string('uniformbit', 'qtype_calculated'),
- 'loguniform' => get_string('loguniformbit', 'qtype_calculated'));
- $menu2 = html_writer::label(get_string('distributionoption', 'qtype_calculated'), 'menucalcdistribution', false, array('class' => 'accesshide'));
+ 'loguniform' => get_string('loguniformbit', 'qtype_calculated'));
+ $menu2 = html_writer::label(get_string('distributionoption', 'qtype_calculated'),
+ 'menucalcdistribution', false, array('class' => 'accesshide'));
$menu2 .= html_writer::select($options, 'calcdistribution[]', $regs[1], null);
return '<input type="submit" onclick="'
. "getElementById('addform').regenerateddefid.value='$defid'; return true;"
@@ -774,14 +776,14 @@ public function custom_generator_tools($datasetdef) {
public function update_dataset_options($datasetdefs, $form) {
global $OUTPUT;
- // Do we have information about new options???
+ // Do we have information about new options ?
if (empty($form->definition) || empty($form->calcmin)
- || empty($form->calcmax) || empty($form->calclength)
+ ||empty($form->calcmax) || empty($form->calclength)
|| empty($form->calcdistribution)) {
- // I guess not
+ // I guess not.
} else {
- // Looks like we just could have some new information here
+ // Looks like we just could have some new information here.
$uniquedefs = array_values(array_unique($form->definition));
foreach ($uniquedefs as $key => $defid) {
if (isset($datasetdefs[$defid])
@@ -804,7 +806,7 @@ public function update_dataset_options($datasetdefs, $form) {
}
}
- // Look for empty options, on which we set default values
+ // Look for empty options, on which we set default values.
foreach ($datasetdefs as $defid => $def) {
if (empty($def->options)) {
$datasetdefs[$defid]->options = 'uniform:1.0:10.0:1';
@@ -865,7 +867,7 @@ public function save_dataset_items($question, $fromform) {
$synchronize = true;
}
- //get the old datasets for this question
+ // Get the old datasets for this question.
$datasetdefs = $this->get_dataset_definitions($question->id, array());
// Handle generator options...
$olddatasetdefs = fullclone($datasetdefs);
@@ -874,16 +876,16 @@ public function save_dataset_items($question, $fromform) {
foreach ($datasetdefs as $defid => $datasetdef) {
if (isset($datasetdef->id)
&& $datasetdef->options != $olddatasetdefs[$defid]->options) {
- // Save the new value for options
+ // Save the new value for options.
$DB->update_record('question_dataset_definitions', $datasetdef);
}
- // Get maxnumber
+ // Get maxnumber.
if ($maxnumber == -1 || $datasetdef->itemcount < $maxnumber) {
$maxnumber = $datasetdef->itemcount;
}
}
- // Handle adding and removing of dataset items
+ // Handle adding and removing of dataset items.
$i = 1;
if ($maxnumber > self::MAX_DATASET_ITEMS) {
$maxnumber = self::MAX_DATASET_ITEMS;
@@ -891,8 +893,8 @@ public function save_dataset_items($question, $fromform) {
ksort($fromform->definition);
foreach ($fromform->definition as $key => $defid) {
- //if the delete button has not been pressed then skip the datasetitems
- //in the 'add item' part of the form.
+ // If the delete button has not been pressed then skip the datasetitems
+ // in the 'add item' part of the form.
if ($i > count($datasetdefs)*$maxnumber) {
break;
}
@@ -902,7 +904,7 @@ public function save_dataset_items($question, $fromform) {
$addeditem->itemnumber = ceil($i / count($datasetdefs));
if ($fromform->itemid[$i]) {
- // Reuse any previously used record
+ // Reuse any previously used record.
$addeditem->id = $fromform->itemid[$i];
$DB->update_record('question_dataset_items', $addeditem);
} else {
@@ -917,12 +919,12 @@ public function save_dataset_items($question, $fromform) {
foreach ($datasetdefs as $key => $newdef) {
if (isset($newdef->id) && $newdef->itemcount <= $maxnumber) {
$newdef->itemcount = $maxnumber;
- // Save the new value for options
+ // Save the new value for options.
$DB->update_record('question_dataset_definitions', $newdef);
}
}
}
- // adding supplementary items
+ // Adding supplementary items.
$numbertoadd = 0;
if (isset($fromform->addbutton) && $fromform->selectadd > 0 &&
$maxnumber < self::MAX_DATASET_ITEMS) {
@@ -930,12 +932,12 @@ public function save_dataset_items($question, $fromform) {
if (self::MAX_DATASET_ITEMS - $maxnumber < $numbertoadd) {
$numbertoadd = self::MAX_DATASET_ITEMS - $maxnumber;
}
- //add the other items.
- // Generate a new dataset item (or reuse an old one)
+ // Add the other items.
+ // Generate a new dataset item (or reuse an old one).
foreach ($datasetdefs as $defid => $datasetdef) {
- // in case that for category datasets some new items has been added
- // get actual values
- // fix regenerate for this datadefs
+ // In case that for category datasets some new items has been added,
+ // get actual values.
+ // Fix regenerate for this datadefs.
$defregenerate = 0;
if ($synchronize &&
!empty ($fromform->nextpageparam["datasetregenerate[$datasetdef->name"])) {
@@ -948,10 +950,9 @@ public function save_dataset_items($question, $fromform) {
$datasetdefs[$defid]->items =
$this->get_database_dataset_items($datasetdef->id);
}
- for ($numberadded = $maxnumber+1; $numberadded <= $maxnumber + $numbertoadd;
- $numberadded++) {
+ for ($numberadded = $maxnumber+1; $numberadded <= $maxnumber + $numbertoadd; $numberadded++) {
if (isset($datasetdefs[$defid]->items[$numberadded])) {
- // in case of regenerate it modifies the already existing record
+ // In case of regenerate it modifies the already existing record.
if ($defregenerate) {
$datasetitem = new stdClass();
$datasetitem->id = $datasetdefs[$defid]->items[$numberadded]->id;
@@ -961,7 +962,7 @@ public function save_dataset_items($question, $fromform) {
$this->generate_dataset_item($datasetdef->options);
$DB->update_record('question_dataset_items', $datasetitem);
}
- //if not regenerate do nothing as there is already a record
+ // If not regenerate do nothing as there is already a record.
} else {
$datasetitem = new stdClass();
$datasetitem->definition = $datasetdef->id;
@@ -974,13 +975,13 @@ public function save_dataset_items($question, $fromform) {
}
$DB->insert_record('question_dataset_items', $datasetitem);
}
- }//for number added
- }// datasetsdefs end
+ }// For number added.
+ }// Datasetsdefs end.
$maxnumber += $numbertoadd;
foreach ($datasetdefs as $key => $newdef) {
if (isset($newdef->id) && $newdef->itemcount <= $maxnumber) {
$newdef->itemcount = $maxnumber;
- // Save the new value for options
+ // Save the new value for options.
$DB->update_record('question_dataset_definitions', $newdef);
}
}
@@ -1014,7 +1015,7 @@ public function generate_dataset_item($options) {
return sprintf("%.".$regs[4].'f', $nbr);
} else if ($regs[1] == 'loguniform') {
- $log0 = log(abs($regs[2])); // It would have worked the other way to
+ $log0 = log(abs($regs[2])); // It would have worked the other way to.
$nbr = exp($log0 + (log(abs($regs[3])) - $log0)*mt_rand()/mt_getrandmax());
return sprintf("%.".$regs[4].'f', $nbr);
@@ -1048,7 +1049,7 @@ public function comment_on_datasetitems($qtypeobj, $questionid, $questiontext,
$comment->stranswers = array();
$comment->outsidelimit = false;
$comment->answers = array();
- // Find a default unit:
+ // Find a default unit.
if (!empty($questionid) && $unit = $DB->get_record('question_numerical_units',
array('question' => $questionid, 'multiplier' => 1.0))) {
$unit = $unit->unit;
@@ -1076,7 +1077,7 @@ public function comment_on_datasetitems($qtypeobj, $questionid, $questiontext,
list($answer->min, $answer->max) = $ans->get_tolerance_interval($answer);
}
if ($answer->min === '') {
- // This should mean that something is wrong
+ // This should mean that something is wrong.
$comment->stranswers[$key] = " $formattedanswer->answer".'<br/><br/>';
} else if ($formula === '*') {
$comment->stranswers[$key] = $formula . ' = ' .
@@ -1112,7 +1113,7 @@ public function multichoice_comment_on_datasetitems($questionid, $questiontext,
$comment->stranswers = array();
$comment->outsidelimit = false;
$comment->answers = array();
- // Find a default unit:
+ // Find a default unit.
if (!empty($questionid) && $unit = $DB->get_record('question_numerical_units',
array('question' => $questionid, 'multiplier' => 1.0))) {
$unit = $unit->unit;
@@ -1125,7 +1126,7 @@ public function multichoice_comment_on_datasetitems($questionid, $questiontext,
$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)) {
@@ -1168,9 +1169,10 @@ public function tolerance_types() {
public function dataset_options($form, $name, $mandatory = true,
$renameabledatasets = false) {
// Takes datasets from the parent implementation but
- // filters options that are currently not accepted by calculated
- // It also determines a default selection...
- // $renameabledatasets not implemented anmywhere
+ // filters options that are currently not accepted by calculated.
+ // It also determines a default selection.
+ // Param $renameabledatasets not implemented anywhere.
+
list($options, $selected) = $this->dataset_options_from_database(
$form, $name, '', 'qtype_calculated');
@@ -1181,9 +1183,9 @@ public function dataset_options($form, $name, $mandatory = true,
}
if (!$selected) {
if ($mandatory) {
- $selected = "1-0-$name"; // Default
+ $selected = "1-0-$name"; // Default.
} else {
- $selected = '0'; // Default
+ $selected = '0'; // Default.
}
}
return array($options, $selected);
@@ -1215,8 +1217,8 @@ public function construct_dataset_menus($form, $mandatorydatasets,
public function substitute_variables($str, $dataset) {
global $OUTPUT;
- // testing for wrong numerical values
- // all calculations used this function so testing here should be OK
+ // Testing for wrong numerical values.
+ // All calculations used this function so testing here should be OK.
foreach ($dataset as $name => $value) {
$val = $value;
@@ -1227,7 +1229,7 @@ public function substitute_variables($str, $dataset) {
echo $OUTPUT->notification(get_string('notvalidnumber', 'qtype_calculated', $a));
$val = 1.0;
}
- if ($val <= 0) { // MDL-36025 Use parentheses for "-0"
+ if ($val <= 0) { // MDL-36025 Use parentheses for "-0" .
$str = str_replace('{'.$name.'}', '('.$val.')', $str);
} else {
$str = str_replace('{'.$name.'}', $val, $str);
@@ -1249,7 +1251,7 @@ public function substitute_variables_and_eval($str, $dataset) {
if ($error = qtype_calculated_find_formula_errors($formula)) {
return $error;
}
- // Calculate the correct answer
+ // Calculate the correct answer.
if (empty($formula)) {
$str = '';
} else if ($formula === '*') {
@@ -1263,7 +1265,7 @@ public function substitute_variables_and_eval($str, $dataset) {
public function get_dataset_definitions($questionid, $newdatasets) {
global $DB;
- //get the existing datasets for this question
+ // Get the existing datasets for this question.
$datasetdefs = array();
if (!empty($questionid)) {
global $CFG;
@@ -1284,7 +1286,7 @@ public function get_dataset_definitions($questionid, $newdatasets) {
}
if (!isset($datasetdefs[$dataset])) {
- //make new datasetdef
+ // Make new datasetdef.
list($type, $category, $name) = explode('-', $dataset, 3);
$datasetdef = new stdClass();
$datasetdef->type = $type;
@@ -1300,12 +1302,12 @@ public function get_dataset_definitions($questionid, $newdatasets) {
public function save_dataset_definitions($form) {
global $DB;
- // save synchronize
+ // Save synchronize.
if (empty($form->dataset)) {
$form->dataset = array();
}
- // Save datasets
+ // Save datasets.
$datasetdefinitions = $this->get_dataset_definitions($form->id, $form->dataset);
$tmpdatasets = array_flip($form->dataset);
$defids = array_keys($datasetdefinitions);
@@ -1313,18 +1315,18 @@ public function save_dataset_definitions($form) {
$datasetdef = &$datasetdefinitions[$defid];
if (isset($datasetdef->id)) {
if (!isset($tmpdatasets[$defid])) {
- // This dataset is not used any more, delete it
+ // This dataset is not used any more, delete it.
$DB->delete_records('question_datasets',
array('question' => $form->id, 'datasetdefinition' => $datasetdef->id));
if ($datasetdef->category == 0) {
- // Question local dataset
+ // Question local dataset.
$DB->delete_records('question_dataset_definitions',
array('id' => $datasetdef->id));
$DB->delete_records('question_dataset_items',
array('definition' => $datasetdef->id));
}
}
- // This has already been saved or just got deleted
+ // This has already been saved or just got deleted.
unset($datasetdefinitions[$defid]);
continue;
}
@@ -1332,11 +1334,10 @@ public function save_dataset_definitions($form) {
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
- // We need to look for already existing
- // datasets in the category.
- // By first creating the datasetdefinition above we
- // can manage to automatically take care of
- // some possible realtime concurrence
+ // We need to look for already existing datasets in the category.
+ // First creating the datasetdefinition above
+ // then we can manage to automatically take care of some possible realtime concurrence.
+
if ($olderdatasetdefs = $DB->get_records_select('question_dataset_definitions',
'type = ? AND name = ? AND category = ? AND id < ?
ORDER BY id DESC',
@@ -1351,7 +1352,7 @@ public function save_dataset_definitions($form) {
}
}
- // Create relation to this dataset:
+ // Create relation to this dataset.
$questiondataset = new stdClass();
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
@@ -1360,13 +1361,13 @@ public function save_dataset_definitions($form) {
}
// Remove local obsolete datasets as well as relations
- // to datasets in other categories:
+ // to datasets in other categories.
if (!empty($datasetdefinitions)) {
foreach ($datasetdefinitions as $def) {
$DB->delete_records('question_datasets',
array('question' => $form->id, 'datasetdefinition' => $def->id));
- if ($def->category == 0) { // Question local dataset
+ if ($def->category == 0) { // Question local dataset.
$DB->delete_records('question_dataset_definitions',
array('id' => $def->id));
$DB->delete_records('question_dataset_items',
@@ -1382,28 +1383,28 @@ public function save_dataset_definitions($form) {
*/
public function save_as_new_dataset_definitions($form, $initialid) {
global $CFG, $DB;
- // Get the datasets from the intial question
+ // Get the datasets from the intial question.
$datasetdefinitions = $this->get_dataset_definitions($initialid, $form->dataset);
- // $tmpdatasets contains those of the new question
+ // Param $tmpdatasets contains those of the new question.
$tmpdatasets = array_flip($form->dataset);
- $defids = array_keys($datasetdefinitions);// new datasets
+ $defids = array_keys($datasetdefinitions);// New datasets.
foreach ($defids as $defid) {
$datasetdef = &$datasetdefinitions[$defid];
if (isset($datasetdef->id)) {
- // This dataset exist in the initial question
+ // This dataset exist in the initial question.
if (!isset($tmpdatasets[$defid])) {
- // do not exist in the new question so ignore
+ // Do not exist in the new question so ignore.
unset($datasetdefinitions[$defid]);
continue;
}
- // create a copy but not for category one
+ // Create a copy but not for category one.
if (0 == $datasetdef->category) {
$olddatasetid = $datasetdef->id;
$olditemcount = $datasetdef->itemcount;
$datasetdef->itemcount = 0;
$datasetdef->id = $DB->insert_record('question_dataset_definitions',
$datasetdef);
- //copy the dataitems
+ // Copy the dataitems.
$olditems = $this->get_database_dataset_items($olddatasetid);
if (count($olditems) > 0) {
$itemcount = 0;
@@ -1412,26 +1413,26 @@ public function save_as_new_dataset_definitions($form, $initialid) {
$DB->insert_record('question_dataset_items', $item);
$itemcount++;
}
- //update item count to olditemcount if
- // at least this number of items has been recover from the database
+ // Update item count to olditemcount if
+ // at least this number of items has been recover from the database.
if ($olditemcount <= $itemcount) {
$datasetdef->itemcount = $olditemcount;
} else {
$datasetdef->itemcount = $itemcount;
}
$DB->update_record('question_dataset_definitions', $datasetdef);
- } // end of copy the dataitems
- }// end of copy the datasetdef
+ } // End of copy the dataitems.
+ }// End of copy the datasetdef.
// Create relation to the new question with this
- // copy as new datasetdef from the initial question
+ // copy as new datasetdef from the initial question.
$questiondataset = new stdClass();
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
$DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
continue;
- }// end of datasetdefs from the initial question
- // really new one code similar to save_dataset_definitions()
+ }// End of datasetdefs from the initial question.
+ // Really new one code similar to save_dataset_definitions().
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
@@ -1439,7 +1440,7 @@ public function save_as_new_dataset_definitions($form, $initialid) {
// datasets in the category.
// By first creating the datasetdefinition above we
// can manage to automatically take care of
- // some possible realtime concurrence
+ // some possible realtime concurrence.
if ($olderdatasetdefs = $DB->get_records_select('question_dataset_definitions',
"type = ? AND name = ? AND category = ? AND id < ?
ORDER BY id DESC",
@@ -1454,7 +1455,7 @@ public function save_as_new_dataset_definitions($form, $initialid) {
}
}
- // Create relation to this dataset:
+ // Create relation to this dataset.
$questiondataset = new stdClass();
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
@@ -1463,13 +1464,13 @@ public function save_as_new_dataset_definitions($form, $initialid) {
}
// Remove local obsolete datasets as well as relations
- // to datasets in other categories:
+ // to datasets in other categories.
if (!empty($datasetdefinitions)) {
foreach ($datasetdefinitions as $def) {
$DB->delete_records('question_datasets',
array('question' => $form->id, 'datasetdefinition' => $def->id));
- if ($def->category == 0) { // Question local dataset
+ if ($def->category == 0) { // Question local dataset.
$DB->delete_records('question_dataset_definitions',
array('id' => $def->id));
$DB->delete_records('question_dataset_items',
@@ -1479,11 +1480,11 @@ public function save_as_new_dataset_definitions($form, $initialid) {
}
}
- // Dataset functionality
+ // Dataset functionality.
public function pick_question_dataset($question, $datasetitem) {
// Select a dataset in the following format:
- // An array indexed by the variable names (d.name) pointing to the value
- // to be substituted
+ // an array indexed by the variable names (d.name) pointing to the value
+ // to be substituted.
global $CFG, $DB;
if (!$dataitems = $DB->get_records_sql(
"SELECT i.id, d.name, i.value
@@ -1512,19 +1513,17 @@ public function pick_question_dataset($question, $datasetitem) {
public function dataset_options_from_database($form, $name, $prefix = '',
$langfile = 'qtype_calculated') {
global $CFG, $DB;
- $type = 1; // only type = 1 (i.e. old 'LITERAL') has ever been used
-
+ $type = 1; // Only type = 1 (i.e. old 'LITERAL') has ever been used.
// First options - it is not a dataset...
$options['0'] = get_string($prefix.'nodataset', $langfile);
- // new question no local
+ // New question no local.
if (!isset($form->id) || $form->id == 0) {
$key = "$type-0-$name";
$options[$key] = get_string($prefix."newlocal$type", $langfile);
$currentdatasetdef = new stdClass();
$currentdatasetdef->type = '0';
} else {
-
- // Construct question local options
+ // Construct question local options.
$sql = "SELECT a.*
FROM {question_dataset_definitions} a, {question_datasets} b
WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND a.name = ?";
@@ -1541,7 +1540,7 @@ public function dataset_options_from_database($form, $name, $prefix = '',
$options[$key] = get_string($prefix."newlocal$type", $langfile);
}
}
- // Construct question category options
+ // Construct question category options.
$categorydatasetdefs = $DB->get_records_sql(
"SELECT b.question, a.*
FROM {question_datasets} b,
@@ -1553,9 +1552,9 @@ public function dataset_options_from_database($form, $name, $prefix = '',
$type = 1;
$key = "$type-$form->category-$name";
if (!empty($categorydatasetdefs)) {
- // there is at least one with the same name
+ // There is at least one with the same name.
if (isset($form->id) && isset($categorydatasetdefs[$form->id])) {
- // it is already used by this question
+ // It is already used by this question.
$options[$key] = get_string($prefix."keptcategory$type", $langfile);
} else {
$options[$key] = get_string($prefix."existingcategory$type", $langfile);
@@ -1570,8 +1569,8 @@ public function dataset_options_from_database($form, $name, $prefix = '',
}
public function find_dataset_names($text) {
- // Returns the possible dataset names found in the text as an array
- // The array has the dataset name for both key and value
+ // Returns the possible dataset names found in the text as an array.
+ // The array has the dataset name for both key and value.
$datasetnames = array();
while (preg_match('~\\{([[:alpha:]][^>} <{"\']*)\\}~', $text, $regs)) {
$datasetnames[$regs[1]] = $regs[1];
@@ -1665,7 +1664,7 @@ public function print_dataset_definitions_category($form) {
<td align=\"right\" valign=\"top\">$datasetdef->itemcount&nbsp;&nbsp;</td>
<td align=\"left\">";
foreach ($datasetdef->questions as $qu) {
- //limit the name length displayed
+ // Limit the name length displayed.
if (!empty($qu->name)) {
$qu->name = (strlen($qu->name) > $lnamemax) ?
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
@@ -1747,7 +1746,7 @@ public function print_dataset_definitions_category_shared($question, $datasetdef
rowspan=\"$count\">$datasetdef->itemcount</td>";
$line = 0;
foreach ($datasetdef->questions as $qu) {
- //limit the name length displayed
+ // Limit the name length displayed.
if (!empty($qu->name)) {
$qu->name = (strlen($qu->name) > $lnamemax) ?
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
@@ -1795,8 +1794,8 @@ public function print_dataset_definitions_category_shared($question, $datasetdef
}
public function find_math_equations($text) {
- // Returns the possible dataset names found in the text as an array
- // The array has the dataset name for both key and value
+ // Returns the possible dataset names found in the text as an array.
+ // The array has the dataset name for both key and value.
$equations = array();
while (preg_match('~\{=([^[:space:]}]*)}~', $text, $regs)) {
$equations[] = $regs[1];
@@ -1866,10 +1865,10 @@ protected function delete_files($questionid, $contextid) {
function qtype_calculated_calculate_answer($formula, $individualdata,
$tolerance, $tolerancetype, $answerlength, $answerformat = '1', $unit = '') {
- // The return value has these properties:
+ // The return value has these properties: .
// ->answer the correct answer
// ->min the lower bound for an acceptable response
- // ->max the upper bound for an accetpable response
+ // ->max the upper bound for an accetpable response.
$calculated = new stdClass();
// Exchange formula variables with the correct values...
$answer = question_bank::get_qtype('calculated')->substitute_variables_and_eval(
@@ -1906,7 +1905,7 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
$calculated->answer .= $unit;
}
- } else if ($answer) { // Significant figures does only apply if the result is non-zero
+ } else if ($answer) { // Significant figures does only apply if the result is non-zero.
// Convert to positive answer...
if ($answer < 0) {
@@ -1926,37 +1925,37 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
++$p10;
$answer /= 10;
}
- // ... and have the answer rounded of to the correct length
+ // ... and have the answer rounded of to the correct length.
$answer = round($answer, $answerlength);
- //if we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format
+ // If we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format.
if ($answer >= 1) {
++$p10;
$answer /= 10;
}
- // Have the answer written on a suitable format,
- // Either scientific or plain numeric
+ // Have the answer written on a suitable format:
+ // either scientific or plain numeric.
if (-2 > $p10 || 4 < $p10) {
- // Use scientific format:
+ // Use scientific format.
$exponent = 'e'.--$p10;
$answer *= 10;
if (1 == $answerlength) {
$calculated->answer = $sign.$answer.$exponent.$unit;
} else {
- // Attach additional zeros at the end of $answer,
+ // Attach additional zeros at the end of $answer.
$answer .= (1 == strlen($answer) ? '.' : '')
. '00000000000000000000000000000000000000000x';
$calculated->answer = $sign
.substr($answer, 0, $answerlength +1).$exponent.$unit;
}
} else {
- // Stick to plain numeric format
+ // Stick to plain numeric format.
$answer *= "1e$p10";
if (0.1 <= $answer / "1e$answerlength") {
$calculated->answer = $sign.$answer.$unit;
} else {
- // Could be an idea to add some zeros here
+ // Could be an idea to add some zeros here.
$answer .= (preg_match('~^[0-9]*$~', $answer) ? '.' : '')
. '00000000000000000000000000000000000000000x';
$oklen = $answerlength + ($p10 < 1 ? 2-$p10 : 1);
@@ -1968,21 +1967,21 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
$calculated->answer = 0.0;
}
- // Return the result
+ // Return the result.
return $calculated;
}
function qtype_calculated_find_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 = '-+/*%>:^\~<?=&|!'; /* */
@@ -1992,21 +1991,21 @@ function qtype_calculated_find_formula_errors($formula) {
"\\(($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':
@@ -2019,21 +2018,21 @@ function qtype_calculated_find_formula_errors($formula) {
}
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', $regs[2]);
}
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]);
@@ -2044,13 +2043,13 @@ function qtype_calculated_find_formula_errors($formula) {
return get_string('unsupportedformulafunction', 'qtype_calculated', $regs[2]);
}
- // Exchange the function call with '1' and then chack for
+ // 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);
}
}
@@ -2058,7 +2057,7 @@ function qtype_calculated_find_formula_errors($formula) {
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;
}
}
View
4 question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php
@@ -57,11 +57,11 @@ public function recode_response($questionid, $sequencenumber, array $response) {
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');
View
2  question/type/calculatedmulti/db/upgradelib.php
@@ -272,7 +272,7 @@ public function calculate($expression) {
* @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 . ']';
}
View
1  question/type/calculatedmulti/edit_calculatedmulti_form.php
@@ -156,7 +156,6 @@ protected function definition_inner($mform) {
$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);
View
22 question/type/calculatedmulti/questiontype.php
@@ -42,7 +42,7 @@ public function save_question_options($question) {
global $CFG, $DB;
$context = $question->context;
- // Calculated options
+ // Calculated options.