diff --git a/question/type/calculated/backup/moodle1/lib.php b/question/type/calculated/backup/moodle1/lib.php
index f2ad04e24cfee..a00a4fee7b137 100644
--- a/question/type/calculated/backup/moodle1/lib.php
+++ b/question/type/calculated/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
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(),
diff --git a/question/type/calculated/backup/moodle2/backup_qtype_calculated_plugin.class.php b/question/type/calculated/backup/moodle2/backup_qtype_calculated_plugin.class.php
index 3a302bc02f5f3..58d20e53c06c1 100644
--- a/question/type/calculated/backup/moodle2/backup_qtype_calculated_plugin.class.php
+++ b/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;
}
diff --git a/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php b/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php
index c645a11b0548a..f9afd70ac6828 100644
--- a/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php
+++ b/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);
}
}
diff --git a/question/type/calculated/datasetdefinitions_form.php b/question/type/calculated/datasetdefinitions_form.php
index 6e1158ce50823..a5fdac391a35e 100644
--- a/question/type/calculated/datasetdefinitions_form.php
+++ b/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 = "
".get_string('datasetrole', 'qtype_calculated')."
";
- // 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', '',
diff --git a/question/type/calculated/datasetitems_form.php b/question/type/calculated/datasetitems_form.php
index f1f4a7b17bff1..317ac6f6f6d1c 100644
--- a/question/type/calculated/datasetitems_form.php
+++ b/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)) {
diff --git a/question/type/calculated/db/upgrade.php b/question/type/calculated/db/upgrade.php
index 974cf91b13978..2d9c7d18e9d38 100644
--- a/question/type/calculated/db/upgrade.php
+++ b/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;
}
diff --git a/question/type/calculated/db/upgradelib.php b/question/type/calculated/db/upgradelib.php
index fbc597ec2b305..22d87107f476e 100644
--- a/question/type/calculated/db/upgradelib.php
+++ b/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 . ']';
}
diff --git a/question/type/calculated/edit_calculated_form.php b/question/type/calculated/edit_calculated_form.php
index 19bc26a7a72f3..0778c7b946896 100644
--- a/question/type/calculated/edit_calculated_form.php
+++ b/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');
diff --git a/question/type/calculated/question.php b/question/type/calculated/question.php
index 3ecbc9d0f7be8..b3246855d7037 100644
--- a/question/type/calculated/question.php
+++ b/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;
}
}
diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php
index 80b01a044eebb..3e9143ebe94ef 100644
--- a/question/type/calculated/questiontype.php
+++ b/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 '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".'
';
} 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) {
$datasetdef->itemcount
";
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
";
$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;
}
}
diff --git a/question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php b/question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php
index 95cd9a9cc33d9..cc5b9ba1a706b 100644
--- a/question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php
+++ b/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');
diff --git a/question/type/calculatedmulti/db/upgradelib.php b/question/type/calculatedmulti/db/upgradelib.php
index d2b131c024088..53bf09dd44a7d 100644
--- a/question/type/calculatedmulti/db/upgradelib.php
+++ b/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 . ']';
}
diff --git a/question/type/calculatedmulti/edit_calculatedmulti_form.php b/question/type/calculatedmulti/edit_calculatedmulti_form.php
index b0060b145bb5f..57b674249c01d 100644
--- a/question/type/calculatedmulti/edit_calculatedmulti_form.php
+++ b/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);
diff --git a/question/type/calculatedmulti/questiontype.php b/question/type/calculatedmulti/questiontype.php
index 220d1bcaf8f68..2235145855ac8 100644
--- a/question/type/calculatedmulti/questiontype.php
+++ b/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.
$update = true;
$options = $DB->get_record('question_calculated_options',
array('question' => $question->id));
@@ -61,7 +61,7 @@ public function save_question_options($question) {
$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 @@ public function save_question_options($question) {
$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 @@ public function save_question_options($question) {
}
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 @@ 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();
}
@@ -121,17 +121,17 @@ 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));
@@ -220,7 +220,7 @@ public function comment_on_datasetitems($qtypeobj, $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)) {
diff --git a/question/type/calculatedmulti/tests/helper.php b/question/type/calculatedmulti/tests/helper.php
index 9ccbcb82bf3c7..6fd63d752ecd9 100644
--- a/question/type/calculatedmulti/tests/helper.php
+++ b/question/type/calculatedmulti/tests/helper.php
@@ -46,7 +46,7 @@ public function get_test_questions() {
* @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);
diff --git a/question/type/calculatedsimple/edit_calculatedsimple_form.php b/question/type/calculatedsimple/edit_calculatedsimple_form.php
index e12a7119c204d..f74a2ed8bd6ce 100644
--- a/question/type/calculatedsimple/edit_calculatedsimple_form.php
+++ b/question/type/calculatedsimple/edit_calculatedsimple_form.php
@@ -74,15 +74,15 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$this->question = $question;
$this->qtypeobj = question_bank::get_qtype($this->question->qtype);
- // get the dataset definitions for this question
- // coming here everytime even when using a NoSubmitButton
- // so this will only set the values to the actual question database content
- // which is not what we want so this should be removed from here
- // get priority to paramdatasets
+ // Get the dataset definitions for this question.
+ // Coming here everytime even when using a NoSubmitButton.
+ // This will only set the values to the actual question database content
+ // which is not what we want, so this should be removed from here.
+ // Get priority to paramdatasets.
$this->reload = optional_param('reload', false, PARAM_BOOL);
- if (!$this->reload) { // use database data as this is first pass
- // question->id == 0 so no stored datasets
+ if (!$this->reload) { // Use database data as this is first pass
+ // Question->id == 0 so no stored datasets.
if (!empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions(
@@ -90,7 +90,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
if (!empty($this->datasetdefs)) {
foreach ($this->datasetdefs as $defid => $datasetdef) {
- // first get the items in case their number does not correspond to itemcount
+ // First get the items in case their number does not correspond to itemcount.
if (isset($datasetdef->id)) {
$this->datasetdefs[$defid]->items =
$this->qtypeobj->get_database_dataset_items($datasetdef->id);
@@ -100,7 +100,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$datasetdef->itemcount = 0;
}
}
- // Get maxnumber
+ // Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount;
}
@@ -118,34 +118,34 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$newdatasetvalues = false;
$newdataset = false;
} else {
- // handle reload to get values from the form-elements
+ // Handle reload to get values from the form-elements
// answers, datasetdefs and data_items. In any case the validation
// step will warn the user of any error in settings the values.
// Verification for the specific dataset values as the other parameters
- // unints, feeedback etc are handled elsewhere
- // handle request buttons :
- // 'analyzequestion' (Identify the wild cards {x..} present in answers)
- // 'addbutton' (create new set of datatitems)
- // 'updatedatasets' is handled automatically on each reload
+ // units, feeedback etc are handled elsewhere.
+ // Handle request buttons :
+ // 'analyzequestion' (Identify the wild cards {x..} present in answers).
+ // 'addbutton' (create new set of datatitems).
+ // 'updatedatasets' is handled automatically on each reload.
// The analyzequestion is done every time on reload
// to detect any new wild cards so that the current display reflects
- // the mandatory (i.e. in answers) datasets
- // to implement : don't do any changes if the question is used in a quiz.
+ // the mandatory (i.e. in answers) datasets.
+ // To implement : don't do any changes if the question is used in a quiz.
// If new datadef, new properties should erase items.
- // Most of the data
+ // most of the data.
$datasettoremove = false;
$newdatasetvalues = false;
$newdataset = false;
$dummyform = new stdClass();
$mandatorydatasets = array();
- // should not test on adding a new answer
- // should test if there are already olddatasets or if the 'analyzequestion'
- // submit button has been clicked
+ // Should not test on adding a new answer.
+ // Should test if there are already olddatasets or if the 'analyzequestion'.
+ // submit button has been clicked.
if (optional_param_array('datasetdef', false, PARAM_BOOL) ||
optional_param('analyzequestion', false, PARAM_BOOL)) {
if ($dummyform->answer = optional_param_array('answer', '', PARAM_NOTAGS)) {
- // there is always at least one answer...
+ // There is always at least one answer...
$fraction = optional_param_array('fraction', '', PARAM_FLOAT);
$tolerance = optional_param_array('tolerance', '', PARAM_FLOAT);
$tolerancetype = optional_param_array('tolerancetype', '', PARAM_FLOAT);
@@ -153,7 +153,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$correctanswerformat = optional_param_array('correctanswerformat', '', PARAM_INT);
foreach ($dummyform->answer as $key => $answer) {
- if (trim($answer) != '') { // just look for non-empty
+ if (trim($answer) != '') { // Just look for non-empty.
$this->answer[$key] = new stdClass();
$this->answer[$key]->answer = $answer;
$this->answer[$key]->fraction = $fraction[$key];
@@ -167,7 +167,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
}
}
$this->datasetdefs = array();
- // rebuild datasetdefs from old values
+ // Rebuild datasetdefs from old values.
if ($olddef = optional_param_array('datasetdef', '', PARAM_RAW)) {
$calcmin = optional_param_array('calcmin', '', PARAM_FLOAT);
$calclength = optional_param_array('calclength', '', PARAM_INT);
@@ -184,7 +184,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$this->datasetdefs[$def]->calcmin = $calcmin[$key];
$this->datasetdefs[$def]->calcmax = $calcmax[$key];
$this->datasetdefs[$def]->calclength = $calclength[$key];
- //then compare with new values
+ // Then compare with new values.
if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~',
$this->datasetdefs[$def]->options, $regs)) {
if ($this->datasetdefs[$def]->calcmin != $regs[2]||
@@ -199,7 +199,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$this->datasetdefs[$def]->calclength;
}
}
- // detect new datasets
+ // Detect new datasets.
$newdataset = false;
foreach ($mandatorydatasets as $datasetname) {
if (!isset($this->datasetdefs["1-0-$datasetname"])) {
@@ -214,7 +214,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
$this->datasetdefs["1-0-$datasetname"]->name = $datasetname;
}
}
- // remove obsolete datasets
+ // Remove obsolete datasets.
$datasettoremove = false;
foreach ($this->datasetdefs as $defkey => $datasetdef) {
if (!isset($datasetdef->name)) {
@@ -223,10 +223,10 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
}
}
}
- } // handle reload
- // create items if $newdataset and noofitems > 0 and !$newdatasetvalues
- // eliminate any items if $newdatasetvalues
- // eliminate any items if $datasettoremove, $newdataset, $newdatasetvalues
+ } // Handle reload.
+ // Create items if $newdataset and noofitems > 0 and !$newdatasetvalues.
+ // Eliminate any items if $newdatasetvalues.
+ // Eliminate any items if $datasettoremove, $newdataset, $newdatasetvalues.
if ($datasettoremove ||$newdataset ||$newdatasetvalues) {
foreach ($this->datasetdefs as $defkey => $datasetdef) {
$datasetdef->itemcount = 0;
@@ -235,7 +235,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
}
$maxnumber = -1;
if (optional_param('addbutton', false, PARAM_BOOL)) {
- $maxnumber = optional_param('selectadd', '', PARAM_INT); //FIXME: sloppy coding
+ $maxnumber = optional_param('selectadd', '', PARAM_INT); // FIXME: sloppy coding.
foreach ($this->datasetdefs as $defid => $datasetdef) {
$datasetdef->itemcount = $maxnumber;
unset($datasetdef->items);
@@ -250,7 +250,7 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
}
$this->maxnumber = $maxnumber;
} else {
- // Handle reload dataset items
+ // Handle reload dataset items.
if (optional_param_array('definition', '', PARAM_NOTAGS) &&
!($datasettoremove ||$newdataset ||$newdatasetvalues)) {
$i = 1;
@@ -309,7 +309,7 @@ protected function definition_inner($mform) {
$label = "
");
- // 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('submit', 'analyzequestion',
@@ -322,13 +322,13 @@ protected function definition_inner($mform) {
} else {
$this->noofitems = 0;
}
- if (!empty($this->datasetdefs)) {//So there are some datadefs
- // we put them on the page
+ if (!empty($this->datasetdefs)) {// So there are some datadefs.
+ // We put them on the page.
$key = 0;
$mform->addElement('header', 'additemhdr',
get_string('wildcardparam', 'qtype_calculatedsimple'));
$idx = 1;
- if (!empty($this->datasetdefs)) {// unnecessary test
+ if (!empty($this->datasetdefs)) {// Unnecessary test.
$j = (($this->noofitems) * count($this->datasetdefs))+1;//
foreach ($this->datasetdefs as $defkey => $datasetdef) {
$mform->addElement('static', "na[$j]",
@@ -343,8 +343,8 @@ protected function definition_inner($mform) {
$j++;
}
}
- //this should be done before the elements are created and stored as $this->formdata;
- //fill out all data sets and also the fields for the next item to add.
+ // This should be done before the elements are created and stored as $this->formdata.
+ // Fill out all data sets and also the fields for the next item to add.
/*Here we do already the values error analysis so that
* we could force all wild cards values display if there is an error in values.
* as using a , in a number */
@@ -381,7 +381,7 @@ protected function definition_inner($mform) {
get_string('notvalidnumber', 'qtype_calculated', $a);
$numbererrors .= $this->numbererrors['number['.$j.']']." ";
}
- } else if (stristr($number, 'x')) { // hexa will pass the test
+ } else if (stristr($number, 'x')) { // Hexa will pass the test.
$a = new stdClass();
$a->name = '{'.$datasetdef->name.'}';
$a->value = $datasetdef->items[$itemnumber]->value;
@@ -426,7 +426,7 @@ protected function definition_inner($mform) {
$this->formdata['selectdelete'] = '1';
$this->formdata['selectadd'] = '1';
$j = $this->noofitems * count($this->datasetdefs)+1;
- $data = array(); // data for comment_on_datasetitems later
+ $data = array(); // Data for comment_on_datasetitems later.
$idx = 1;
foreach ($this->datasetdefs as $defid => $datasetdef) {
$this->formdata["datasetdef[$idx]"] = $defid;
@@ -487,7 +487,7 @@ protected function definition_inner($mform) {
$mform->registerNoSubmitButton('updatedatasets');
$mform->setAdvanced("updatedatasets", true);
- //--------------------------------------------------------------
+ // ...--------------------------------------------------------------.
$j = $this->noofitems * count($this->datasetdefs);
$k = optional_param('selectshow', 1, PARAM_INT);
@@ -537,9 +537,9 @@ protected function definition_inner($mform) {
$mform->closeHeaderBefore('warningnowildcards');
}
- //----------------------------------------------------------------------
- // Non standard name for button element needed so not using add_action_buttons
- // hidden elements
+ // ...----------------------------------------------------------------------.
+ // Non standard name for button element needed so not using add_action_buttons.
+ // Hidden elements.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
diff --git a/question/type/calculatedsimple/questiontype.php b/question/type/calculatedsimple/questiontype.php
index 035df5cd2dd5c..c98f307dbe8eb 100644
--- a/question/type/calculatedsimple/questiontype.php
+++ b/question/type/calculatedsimple/questiontype.php
@@ -37,19 +37,19 @@
*/
class qtype_calculatedsimple extends qtype_calculated {
- // Used by the function custom_generator_tools:
+ // Used by the function custom_generator_tools.
public $wizard_pages_number = 1;
public function save_question_options($question) {
global $CFG, $DB;
$context = $question->context;
- // Get old answers:
+ // Get old answers.
if (isset($question->answer) && !isset($question->answers)) {
$question->answers = $question->answer;
}
- // 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();
@@ -68,7 +68,7 @@ public function save_question_options($question) {
} else {
$units = &$result->units;
}
- // Insert all the new answers
+ // Insert all the new answers.
if (isset($question->answer) && !isset($question->answers)) {
$question->answers = $question->answer;
}
@@ -98,7 +98,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();
}
@@ -109,24 +109,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));
@@ -136,10 +136,10 @@ public function save_question_options($question) {
if (isset($question->import_process) && $question->import_process) {
$this->import_datasets($question);
} else {
- //save datasets and datatitems from form i.e in question
+ // Save datasets and datatitems from form i.e in question.
$question->dataset = $question->datasetdef;
- // Save datasets
+ // Save datasets.
$datasetdefinitions = $this->get_dataset_definitions($question->id, $question->dataset);
$tmpdatasets = array_flip($question->dataset);
$defids = array_keys($datasetdefinitions);
@@ -148,7 +148,7 @@ public function save_question_options($question) {
$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' => $question->id,
'datasetdefinition' => $datasetdef->id));
$DB->delete_records('question_dataset_definitions',
@@ -156,7 +156,7 @@ public function save_question_options($question) {
$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;
}
@@ -169,12 +169,12 @@ public function save_question_options($question) {
unset($datasetdefinitions[$defid]);
}
// 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' => $question->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',
@@ -183,7 +183,7 @@ public function save_question_options($question) {
}
}
$datasetdefs = $this->get_dataset_definitions($question->id, $question->dataset);
- // Handle adding and removing of dataset items
+ // Handle adding and removing of dataset items.
$i = 1;
ksort($question->definition);
foreach ($question->definition as $key => $defid) {
@@ -192,7 +192,7 @@ public function save_question_options($question) {
$addeditem->value = $question->number[$i];
$addeditem->itemnumber = ceil($i / count($datasetdefs));
if (empty($question->makecopy) && $question->itemid[$i]) {
- // Reuse any previously used record
+ // Reuse any previously used record.
$addeditem->id = $question->itemid[$i];
$DB->update_record('question_dataset_items', $addeditem);
} else {
@@ -206,7 +206,7 @@ public function save_question_options($question) {
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);
}
}
@@ -282,9 +282,9 @@ 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
+ // $renameabledatasets not implemented anywhere.
list($options, $selected) = $this->dataset_options_from_database(
$form, $name, '', 'qtype_calculated');
@@ -295,9 +295,9 @@ public function dataset_options($form, $name, $mandatory = true, $renameabledata
}
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);
diff --git a/question/type/description/questiontype.php b/question/type/description/questiontype.php
index 78040d5136f6a..5498361b8e78b 100644
--- a/question/type/description/questiontype.php
+++ b/question/type/description/questiontype.php
@@ -56,11 +56,10 @@ public function save_question($question, $form) {
}
public function actual_number_of_questions($question) {
- /// Used for the feature number-of-questions-per-page
- /// to determine the actual number of questions wrapped
- /// by this question.
- /// The question type description is not even a question
- /// in itself so it will return ZERO!
+ // Used for the feature number-of-questions-per-page
+ // to determine the actual number of questions wrapped by this question.
+ // The question type description is not even a question
+ // in itself so it will return ZERO!
return 0;
}
diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php
index 0d2671910336a..99ef870dc6b55 100644
--- a/question/type/edit_question_form.php
+++ b/question/type/edit_question_form.php
@@ -542,13 +542,13 @@ protected function data_preprocessing_answers($question, $withanswerfiles = fals
// Prepare the feedback editor to display files in draft area.
$draftitemid = file_get_submitted_draft_itemid('answer['.$key.']');
$question->answer[$key]['text'] = file_prepare_draft_area(
- $draftitemid, // draftid
+ $draftitemid, // Draftid
$this->context->id, // context
'question', // component
'answer', // filarea
!empty($answer->id) ? (int) $answer->id : null, // itemid
$this->fileoptions, // options
- $answer->answer // text
+ $answer->answer // text.
);
$question->answer[$key]['itemid'] = $draftitemid;
$question->answer[$key]['format'] = $answer->answerformat;
@@ -573,13 +573,13 @@ protected function data_preprocessing_answers($question, $withanswerfiles = fals
// Prepare the feedback editor to display files in draft area.
$draftitemid = file_get_submitted_draft_itemid('feedback['.$key.']');
$question->feedback[$key]['text'] = file_prepare_draft_area(
- $draftitemid, // draftid
+ $draftitemid, // Draftid
$this->context->id, // context
'question', // component
'answerfeedback', // filarea
!empty($answer->id) ? (int) $answer->id : null, // itemid
$this->fileoptions, // options
- $answer->feedback // text
+ $answer->feedback // text.
);
$question->feedback[$key]['itemid'] = $draftitemid;
$question->feedback[$key]['format'] = $answer->feedbackformat;
@@ -605,13 +605,13 @@ protected function data_preprocessing_combined_feedback($question,
$draftid = file_get_submitted_draft_itemid($feedbackname);
$feedback = array();
$feedback['text'] = file_prepare_draft_area(
- $draftid, // draftid
+ $draftid, // Draftid
$this->context->id, // context
'question', // component
$feedbackname, // filarea
!empty($question->id) ? (int) $question->id : null, // itemid
$this->fileoptions, // options
- $question->options->$feedbackname // text
+ $question->options->$feedbackname // text.
);
$feedbackformat = $feedbackname . 'format';
$feedback['format'] = $question->options->$feedbackformat;
@@ -645,13 +645,13 @@ protected function data_preprocessing_hints($question, $withclearwrong = false,
// Prepare feedback editor to display files in draft area.
$draftitemid = file_get_submitted_draft_itemid('hint['.$key.']');
$question->hint[$key]['text'] = file_prepare_draft_area(
- $draftitemid, // draftid
+ $draftitemid, // Draftid
$this->context->id, // context
'question', // component
'hint', // filarea
!empty($hint->id) ? (int) $hint->id : null, // itemid
$this->fileoptions, // options
- $hint->hint // text
+ $hint->hint // text.
);
$question->hint[$key]['itemid'] = $draftitemid;
$question->hint[$key]['format'] = $hint->hintformat;
diff --git a/question/type/essay/backup/moodle1/lib.php b/question/type/essay/backup/moodle1/lib.php
index b2399e7e099c9..47a29c6c60fce 100644
--- a/question/type/essay/backup/moodle1/lib.php
+++ b/question/type/essay/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
write_xml('essay', array(
'id' => $this->converter->get_nextid(),
'responseformat' => 'editor',
diff --git a/question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php b/question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php
index 4da324b61acea..b53753cb0ec93 100644
--- a/question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php
+++ b/question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php
@@ -38,29 +38,29 @@ class backup_qtype_essay_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'essay');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$essay = new backup_nested_element('essay', array('id'), array(
'responseformat', 'responsefieldlines', 'attachments',
'graderinfo', 'graderinfoformat', 'responsetemplate',
'responsetemplateformat'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($essay);
- // set source to populate the data
+ // Set source to populate the data.
$essay->set_source_table('qtype_essay_options',
array('questionid' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php b/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php
index 2a401b8571e05..7a56430c40dad 100644
--- a/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php
+++ b/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php
@@ -59,12 +59,12 @@ public function process_essay($data) {
$data->responsetemplateformat = FORMAT_HTML;
}
- // Detect if the question is created or mapped
+ // Detect if the question is created or mapped.
$questioncreated = $this->get_mappingid('question_created',
$this->get_old_parentid('question')) ? true : false;
// If the question has been created by restore, we need to create its
- // qtype_essay too
+ // qtype_essay too.
if ($questioncreated) {
$data->questionid = $this->get_new_parentid('question');
$newitemid = $DB->insert_record('qtype_essay_options', $data);
diff --git a/question/type/essay/db/upgrade.php b/question/type/essay/db/upgrade.php
index f56535b61d793..845550b21f5d9 100644
--- a/question/type/essay/db/upgrade.php
+++ b/question/type/essay/db/upgrade.php
@@ -36,9 +36,8 @@ function xmldb_qtype_essay_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.
if ($oldversion < 2011102701) {
$sql = "
@@ -47,7 +46,7 @@ function xmldb_qtype_essay_upgrade($oldversion) {
WHERE q.qtype = 'essay'
AND " . $DB->sql_isnotempty('question_answers', 'feedback', false, true);
- // In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback.
+ // In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback
// This was silly, and in Moodel >= 2.1 only question.generalfeedback. To avoid
// dataloss, we concatenate question_answers.feedback onto the end of question.generalfeedback.
$count = $DB->count_records_sql("
@@ -101,11 +100,10 @@ function xmldb_qtype_essay_upgrade($oldversion) {
}
// 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.
if ($oldversion < 2013011800) {
// Then we delete the old question_answers rows for essay questions.
diff --git a/question/type/essay/edit_essay_form.php b/question/type/essay/edit_essay_form.php
index 2fbddadaee9df..edccbe5f88b62 100644
--- a/question/type/essay/edit_essay_form.php
+++ b/question/type/essay/edit_essay_form.php
@@ -72,13 +72,13 @@ protected function data_preprocessing($question) {
$draftid = file_get_submitted_draft_itemid('graderinfo');
$question->graderinfo = array();
$question->graderinfo['text'] = file_prepare_draft_area(
- $draftid, // draftid
+ $draftid, // Draftid
$this->context->id, // context
'qtype_essay', // component
'graderinfo', // filarea
!empty($question->id) ? (int) $question->id : null, // itemid
$this->fileoptions, // options
- $question->options->graderinfo // text
+ $question->options->graderinfo // text.
);
$question->graderinfo['format'] = $question->options->graderinfoformat;
$question->graderinfo['itemid'] = $draftid;
diff --git a/question/type/multianswer/backup/moodle1/lib.php b/question/type/multianswer/backup/moodle1/lib.php
index 0fd991b46bb01..931c594d7b4f3 100644
--- a/question/type/multianswer/backup/moodle1/lib.php
+++ b/question/type/multianswer/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
write_answers($data['answers'], $this->pluginname);
}
- // convert and write the multianswer extra fields
+ // Convert and write the multianswer extra fields.
foreach ($data['multianswers'] as $multianswers) {
foreach ($multianswers as $multianswer) {
$this->write_xml('multianswer', $multianswer, array('/multianswer/id'));
diff --git a/question/type/multianswer/backup/moodle2/backup_qtype_multianswer_plugin.class.php b/question/type/multianswer/backup/moodle2/backup_qtype_multianswer_plugin.class.php
index e236c572602eb..afe1b64c8f1aa 100644
--- a/question/type/multianswer/backup/moodle2/backup_qtype_multianswer_plugin.class.php
+++ b/question/type/multianswer/backup/moodle2/backup_qtype_multianswer_plugin.class.php
@@ -38,31 +38,31 @@ class backup_qtype_multianswer_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'multianswer');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$multianswer = new backup_nested_element('multianswer', array('id'), array(
'question', 'sequence'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($multianswer);
- // set source to populate the data
+ // Set source to populate the data.
$multianswer->set_source_table('question_multianswer',
array('question' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php b/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php
index 8e28b0137993d..b8daa034d254c 100644
--- a/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php
+++ b/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php
@@ -40,15 +40,15 @@ class restore_qtype_multianswer_plugin extends restore_qtype_plugin {
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);
- // Add own qtype stuff
+ // Add own qtype stuff.
$elename = 'multianswer';
$elepath = $this->get_pathfor('/multianswer');
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -60,23 +60,23 @@ public function process_multianswer($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_multianswer too
+ // question_multianswer too.
if ($questioncreated) {
- // Adjust some columns
+ // Adjust some columns.
$data->question = $newquestionid;
// Note: multianswer->sequence is a list of question->id values. We aren't
// recoding them here (because some questions can be missing yet). Instead
// we'll perform the recode in the {@link after_execute} method of the plugin
- // that gets executed once all questions have been created
- // Insert record
+ // that gets executed once all questions have been created.
+ // Insert record.
$newitemid = $DB->insert_record('question_multianswer', $data);
- // Create mapping (need it for after_execute recode of sequence)
+ // Create mapping (need it for after_execute recode of sequence).
$this->set_mapping('question_multianswer', $oldid, $newitemid);
}
}
@@ -93,7 +93,7 @@ public function process_multianswer($data) {
public function after_execute_question() {
global $DB;
// Now that all the questions have been restored, let's process
- // the created question_multianswer sequences (list of question ids)
+ // the created question_multianswer sequences (list of question ids).
$rs = $DB->get_recordset_sql("
SELECT qma.id, qma.sequence
FROM {question_multianswer} qma
@@ -152,21 +152,21 @@ public function recode_legacy_state_answer($state) {
global $DB;
$answer = $state->answer;
$resultarr = array();
- // Get sequence of questions
+ // Get sequence of questions.
$sequence = $DB->get_field('question_multianswer', 'sequence',
array('question' => $state->question));
$sequencearr = explode(',', $sequence);
- // Let's process each pair
+ // Let's process each pair.
foreach (explode(',', $answer) as $pair) {
$pairarr = explode('-', $pair);
$sequenceid = $pairarr[0];
$subanswer = $pairarr[1];
- // Calculate the questionid based on sequenceid
- // Note it is already one *new* questionid that doesn't need mapping
+ // Calculate the questionid based on sequenceid.
+ // Note it is already one *new* questionid that doesn't need mapping.
$questionid = $sequencearr[$sequenceid-1];
- // Fetch qtype of the question (needed for delegation)
+ // Fetch qtype of the question (needed for delegation).
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
- // Delegate subanswer recode to proper qtype, faking one question_states record
+ // Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $questionid;
$substate->answer = $subanswer;
diff --git a/question/type/multianswer/db/upgrade.php b/question/type/multianswer/db/upgrade.php
index 16e63905d218b..d99c424125c84 100644
--- a/question/type/multianswer/db/upgrade.php
+++ b/question/type/multianswer/db/upgrade.php
@@ -36,17 +36,14 @@ function xmldb_qtype_multianswer_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;
}
diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php
index 7df126e4936da..5df9f2cce59e9 100644
--- a/question/type/multianswer/questiontype.php
+++ b/question/type/multianswer/questiontype.php
@@ -44,30 +44,30 @@ public function can_analyse_responses() {
public function get_question_options($question) {
global $DB, $OUTPUT;
- // Get relevant data indexed by positionkey from the multianswers table
+ // Get relevant data indexed by positionkey from the multianswers table.
$sequence = $DB->get_field('question_multianswer', 'sequence',
array('question' => $question->id), '*', MUST_EXIST);
$wrappedquestions = $DB->get_records_list('question', 'id',
explode(',', $sequence), 'id ASC');
- // We want an array with question ids as index and the positions as values
+ // We want an array with question ids as index and the positions as values.
$sequence = array_flip(explode(',', $sequence));
array_walk($sequence, create_function('&$val', '$val++;'));
// If a question is lost, the corresponding index is null
// so this null convention is used to test $question->options->questions
// before using the values.
- // first all possible questions from sequence are nulled
- // then filled with the data if available in $wrappedquestions
+ // First all possible questions from sequence are nulled
+ // then filled with the data if available in $wrappedquestions.
foreach ($sequence as $seq) {
$question->options->questions[$seq] = '';
}
foreach ($wrappedquestions as $wrapped) {
question_bank::get_qtype($wrapped->qtype)->get_question_options($wrapped);
- // for wrapped questions the maxgrade is always equal to the defaultmark,
- // there is no entry in the question_instances table for them
+ // For wrapped questions the maxgrade is always equal to the defaultmark,
+ // there is no entry in the question_instances table for them.
$wrapped->maxmark = $wrapped->defaultmark;
$question->options->questions[$sequence[$wrapped->id]] = $wrapped;
}
@@ -84,12 +84,12 @@ public function save_question_options($question) {
// This function needs to be able to handle the case where the existing set of wrapped
// questions does not match the new set of wrapped questions so that some need to be
- // created, some modified and some deleted
+ // created, some modified and some deleted.
// Unfortunately the code currently simply overwrites existing ones in sequence. This
// will make re-marking after a re-ordering of wrapped questions impossible and
// will also create difficulties if questiontype specific tables reference the id.
- // First we get all the existing wrapped questions
+ // First we get all the existing wrapped questions.
if (!$oldwrappedids = $DB->get_field('question_multianswer', 'sequence',
array('question' => $question->id))) {
$oldwrappedquestions = array();
@@ -101,7 +101,7 @@ public function save_question_options($question) {
$sequence = array();
foreach ($question->options->questions as $wrapped) {
if (!empty($wrapped)) {
- // if we still have some old wrapped question ids, reuse the next of them
+ // If we still have some old wrapped question ids, reuse the next of them.
if (is_array($oldwrappedquestions) &&
$oldwrappedquestion = array_shift($oldwrappedquestions)) {
@@ -133,19 +133,19 @@ public function save_question_options($question) {
$wrapped->name = $question->name;
$wrapped->parent = $question->id;
$previousid = $wrapped->id;
- // save_question strips this extra bit off the category again.
+ // Save_question strips this extra bit off the category again.
$wrapped->category = $question->category . ',1';
$wrapped = question_bank::get_qtype($wrapped->qtype)->save_question(
$wrapped, clone($wrapped));
$sequence[] = $wrapped->id;
if ($previousid != 0 && $previousid != $wrapped->id) {
- // for some reasons a new question has been created
- // so delete the old one
+ // For some reasons a new question has been created
+ // so delete the old one.
question_delete_question($previousid);
}
}
- // Delete redundant wrapped questions
+ // Delete redundant wrapped questions.
if (is_array($oldwrappedquestions) && count($oldwrappedquestions)) {
foreach ($oldwrappedquestions as $oldwrappedquestion) {
question_delete_question($oldwrappedquestion->id);
@@ -240,10 +240,10 @@ protected function delete_files($questionid, $contextid) {
}
-// ANSWER_ALTERNATIVE regexes
+// ANSWER_ALTERNATIVE regexes.
define('ANSWER_ALTERNATIVE_FRACTION_REGEX',
'=|%(-?[0-9]+)%');
-// for the syntax '(?qtype = 'multianswer';
$question->questiontext = $text;
@@ -305,7 +305,7 @@ function qtype_multianswer_extract_question($text) {
$question->options = new stdClass();
$question->options->questions = array();
- $question->defaultmark = 0; // Will be increased for each answer norm
+ $question->defaultmark = 0; // Will be increased for each answer norm.
for ($positionkey = 1;
preg_match('/'.ANSWER_REGEX.'/s', $question->questiontext['text'], $answerregs);
@@ -384,7 +384,7 @@ function qtype_multianswer_extract_question($text) {
// Each $wrapped simulates a $form that can be processed by the
// respective save_question and save_question_options methods of the
- // wrapped questiontypes
+ // wrapped questiontypes.
$wrapped->answer = array();
$wrapped->fraction = array();
$wrapped->feedback = array();
@@ -425,7 +425,7 @@ function qtype_multianswer_extract_question($text) {
} else {
$wrapped->tolerance["$answerindex"] = 0;
}
- } else { // Tolerance can stay undefined for non numerical questions
+ } else { // Tolerance can stay undefined for non numerical questions.
// Undo quoting done by the HTML editor.
$answer = html_entity_decode(
$altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER], ENT_QUOTES, 'UTF-8');
diff --git a/question/type/multichoice/backup/moodle1/lib.php b/question/type/multichoice/backup/moodle1/lib.php
index 9913c9c8e714f..b31c80ba193e7 100644
--- a/question/type/multichoice/backup/moodle1/lib.php
+++ b/question/type/multichoice/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
write_answers($data['answers'], $this->pluginname);
}
- // convert and write the multichoice
+ // Convert and write the multichoice.
if (!isset($data['multichoice'])) {
// This should never happen, but it can do if the 1.9 site contained
- // corrupt data/
+ // corrupt data.
$data['multichoice'] = array(array(
'single' => 1,
'shuffleanswers' => 1,
@@ -78,13 +77,13 @@ public function process_question(array $data, array $raw) {
protected function write_multichoice(array $multichoices, $oldquestiontextformat, $questionid) {
global $CFG;
- // the grouped array is supposed to have just one element - let us use foreach anyway
- // just to be sure we do not loose anything
+ // The grouped array is supposed to have just one element - let us use foreach anyway
+ // just to be sure we do not loose anything.
foreach ($multichoices as $multichoice) {
- // append an artificial 'id' attribute (is not included in moodle.xml)
+ // Append an artificial 'id' attribute (is not included in moodle.xml).
$multichoice['id'] = $this->converter->get_nextid();
- // replay the upgrade step 2009021801
+ // Replay the upgrade step 2009021801.
$multichoice['correctfeedbackformat'] = 0;
$multichoice['partiallycorrectfeedbackformat'] = 0;
$multichoice['incorrectfeedbackformat'] = 0;
diff --git a/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php b/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php
index 70724e00e52bc..930b97189c5bc 100644
--- a/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php
+++ b/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php
@@ -38,34 +38,34 @@ class backup_qtype_multichoice_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'multichoice');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$multichoice = new backup_nested_element('multichoice', array('id'), array(
'layout', 'answers', 'single', 'shuffleanswers',
'correctfeedback', 'correctfeedbackformat',
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering', 'shownumcorrect'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($multichoice);
- // set source to populate the data
+ // Set source to populate the data.
$multichoice->set_source_table('question_multichoice',
array('question' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php b/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
index 230ef75d73a79..c9f0247e09a59 100644
--- a/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
+++ b/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
@@ -41,16 +41,16 @@ 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);
- // Add own qtype stuff
+ // Add own qtype stuff.
$elename = 'multichoice';
- // we used get_recommended_name() so this works
+ // We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/multichoice');
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -62,17 +62,17 @@ public function process_multichoice($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 = (bool) $this->get_mappingid('question_created', $oldquestionid);
// If the question has been created by restore, we need to create its
- // question_multichoice too
+ // question_multichoice too.
if ($questioncreated) {
- // Adjust some columns
+ // Adjust some columns.
$data->question = $newquestionid;
- // Map sequence of question_answer ids
+ // Map sequence of question_answer ids.
if ($data->answers) {
$answersarr = explode(',', $data->answers);
} else {
@@ -82,9 +82,9 @@ public function process_multichoice($data) {
$answersarr[$key] = $this->get_mappingid('question_answer', $answer);
}
$data->answers = implode(',', $answersarr);
- // Insert record
+ // Insert record.
$newitemid = $DB->insert_record('question_multichoice', $data);
- // Create mapping (needed for decoding links)
+ // Create mapping (needed for decoding links).
$this->set_mapping('question_multichoice', $oldid, $newitemid);
}
}
@@ -124,12 +124,12 @@ public function recode_legacy_state_answer($state) {
$orderarr = array();
$responsesarr = array();
$lists = explode(':', $answer);
- // if only 1 list, answer is missing the order list, adjust
+ // If only 1 list, answer is missing the order list, adjust.
if (count($lists) == 1) {
- $lists[1] = $lists[0]; // here we have the responses
- $lists[0] = ''; // here we have the order
+ $lists[1] = $lists[0]; // Here we have the responses.
+ $lists[0] = ''; // Here we have the order.
}
- // Map order
+ // Map order.
if (!empty($lists[0])) {
foreach (explode(',', $lists[0]) as $id) {
if ($newid = $this->get_mappingid('question_answer', $id)) {
@@ -137,7 +137,7 @@ public function recode_legacy_state_answer($state) {
}
}
}
- // Map responses
+ // Map responses.
if (!empty($lists[1])) {
foreach (explode(',', $lists[1]) as $id) {
if ($newid = $this->get_mappingid('question_answer', $id)) {
@@ -145,7 +145,7 @@ public function recode_legacy_state_answer($state) {
}
}
}
- // Build the final answer, if not order, only responses
+ // Build the final answer, if not order, only responses.
$result = '';
if (empty($orderarr)) {
$result = implode(',', $responsesarr);
diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php
index c0230c2cffa8c..256a3afb015d7 100644
--- a/question/type/multichoice/db/upgrade.php
+++ b/question/type/multichoice/db/upgrade.php
@@ -38,14 +38,14 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
// 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;
diff --git a/question/type/multichoice/db/upgradelib.php b/question/type/multichoice/db/upgradelib.php
index 0b9b2e7bcf0a0..dde94218c6dfc 100644
--- a/question/type/multichoice/db/upgradelib.php
+++ b/question/type/multichoice/db/upgradelib.php
@@ -40,7 +40,7 @@ class qtype_multichoice_qe2_attempt_updater extends question_qtype_attempt_updat
protected $order;
public function is_blank_answer($state) {
- // blank multichoice answers are not empty strings, they rather end in a colon
+ // Blank multichoice answers are not empty strings, they rather end in a colon.
return empty($state->answer) || substr($state->answer, -1) == ':';
}
diff --git a/question/type/multichoice/edit_multichoice_form.php b/question/type/multichoice/edit_multichoice_form.php
index 1e2bd0d7084e2..fa1f551d5a406 100644
--- a/question/type/multichoice/edit_multichoice_form.php
+++ b/question/type/multichoice/edit_multichoice_form.php
@@ -106,7 +106,7 @@ public function validation($data, $files) {
$maxfraction = -1;
foreach ($answers as $key => $answer) {
- //check no of choices
+ // Check no of choices.
$trimmedanswer = trim($answer['text']);
$fraction = (float) $data['fraction'][$key];
if ($trimmedanswer === '' && empty($fraction)) {
@@ -118,7 +118,7 @@ public function validation($data, $files) {
$answercount++;
- //check grades
+ // Check grades.
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
@@ -135,7 +135,7 @@ public function validation($data, $files) {
}
- /// Perform sanity checks on fractional grades
+ // Perform sanity checks on fractional grades.
if ($data['single']) {
if ($maxfraction != 1) {
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice',
diff --git a/question/type/multichoice/question.php b/question/type/multichoice/question.php
index 8dd7086116034..c3ac2cab55215 100644
--- a/question/type/multichoice/question.php
+++ b/question/type/multichoice/question.php
@@ -97,11 +97,11 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $
return $this->check_combined_feedback_file_access($qa, $options, $filearea);
} else if ($component == 'question' && $filearea == 'answer') {
- $answerid = reset($args); // itemid is answer id.
+ $answerid = reset($args); // Itemid is answer id.
return in_array($answerid, $this->order);
} else if ($component == 'question' && $filearea == 'answerfeedback') {
- $answerid = reset($args); // itemid is answer id.
+ $answerid = reset($args); // Itemid is answer id.
$response = $this->get_response($qa);
$isselected = false;
foreach ($this->order as $value => $ansid) {
@@ -110,7 +110,7 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $
break;
}
}
- // $options->suppresschoicefeedback is a hack specific to the
+ // Param $options->suppresschoicefeedback is a hack specific to the
// oumultiresponse question type. It would be good to refactor to
// avoid refering to it here.
return $options->feedback && empty($options->suppresschoicefeedback) &&
diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php
index 27dfd331523e3..5a15f8b9f170b 100644
--- a/question/type/multichoice/questiontype.php
+++ b/question/type/multichoice/questiontype.php
@@ -52,19 +52,19 @@ public function save_question_options($question) {
$oldanswers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC');
- // following hack to check at least two answers exist
+ // Following hack to check at least two answers exist.
$answercount = 0;
foreach ($question->answer as $key => $answer) {
if ($answer != '') {
$answercount++;
}
}
- if ($answercount < 2) { // check there are at lest 2 answers for multiple choice
+ if ($answercount < 2) { // Check there are at lest 2 answers for multiple choice.
$result->notice = get_string('notenoughanswers', 'qtype_multichoice', '2');
return $result;
}
- // Insert all the new answers
+ // Insert all the new answers.
$totalfraction = 0;
$maxfraction = -1;
$answers = array();
@@ -83,7 +83,7 @@ public function save_question_options($question) {
$answer->id = $DB->insert_record('question_answers', $answer);
}
- // Doing an import
+ // Doing an import.
$answer->answer = $this->import_or_save_files($answerdata,
$context, 'question', 'answer', $answer->id);
$answer->answerformat = $answerdata['format'];
@@ -132,7 +132,7 @@ public function save_question_options($question) {
$this->save_hints($question, true);
- // Perform sanity checks on fractional grades
+ // Perform sanity checks on fractional grades.
if ($options->single) {
if ($maxfraction != 1) {
$result->noticeyesno = get_string('fractionsnomax', 'qtype_multichoice',
diff --git a/question/type/multichoice/renderer.php b/question/type/multichoice/renderer.php
index 99e4f8e5207da..03e0991771f21 100644
--- a/question/type/multichoice/renderer.php
+++ b/question/type/multichoice/renderer.php
@@ -99,7 +99,7 @@ public function formulation_and_controls(question_attempt $qa,
$qa, 'question', 'answer', $ansid)),
array('for' => $inputattributes['id']));
- // $options->suppresschoicefeedback is a hack specific to the
+ // Param $options->suppresschoicefeedback is a hack specific to the
// oumultiresponse question type. It would be good to refactor to
// avoid refering to it here.
if ($options->feedback && empty($options->suppresschoicefeedback) &&
@@ -134,9 +134,9 @@ public function formulation_and_controls(question_attempt $qa,
$result .= html_writer::tag('div', $radio . ' ' . $feedbackimg[$key] . $feedback[$key],
array('class' => $classes[$key])) . "\n";
}
- $result .= html_writer::end_tag('div'); // answer
+ $result .= html_writer::end_tag('div'); // Answer.
- $result .= html_writer::end_tag('div'); // ablock
+ $result .= html_writer::end_tag('div'); // Ablock.
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
diff --git a/question/type/numerical/backup/moodle1/lib.php b/question/type/numerical/backup/moodle1/lib.php
index 06b56983f47d4..cdaed8b6018e5 100644
--- a/question/type/numerical/backup/moodle1/lib.php
+++ b/question/type/numerical/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
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['numerical'][0]['numerical_units'])) {
$numericalunits = $data['numerical'][0]['numerical_units'];
} else {
@@ -62,10 +61,10 @@ public function process_question(array $data, array $raw) {
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
- // and finally numerical_records
+ // And finally numerical_records.
$this->xmlwriter->begin_tag('numerical_records');
foreach ($data['numerical'] as $numericalrecord) {
- // we do not use write_xml() here because $numericalrecords contains more than we want
+ // We do not use write_xml() here because $numericalrecords contains more than we want.
$this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid()));
$this->xmlwriter->full_tag('answer', $numericalrecord['answer']);
$this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']);
diff --git a/question/type/numerical/backup/moodle2/backup_qtype_numerical_plugin.class.php b/question/type/numerical/backup/moodle2/backup_qtype_numerical_plugin.class.php
index 79ee6dcac3197..51e31cf0ec044 100644
--- a/question/type/numerical/backup/moodle2/backup_qtype_numerical_plugin.class.php
+++ b/question/type/numerical/backup/moodle2/backup_qtype_numerical_plugin.class.php
@@ -38,39 +38,39 @@ class backup_qtype_numerical_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'numerical');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$numericalrecords = new backup_nested_element('numerical_records');
$numericalrecord = new backup_nested_element('numerical_record', array('id'), array(
'answer', 'tolerance'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($numericalrecords);
$numericalrecords->add_child($numericalrecord);
- // set source to populate the data
+ // Set source to populate the data.
$numericalrecord->set_source_table('question_numerical',
array('question' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/numerical/backup/moodle2/restore_qtype_numerical_plugin.class.php b/question/type/numerical/backup/moodle2/restore_qtype_numerical_plugin.class.php
index ef63583bd42ba..34c6acf4a9fc8 100644
--- a/question/type/numerical/backup/moodle2/restore_qtype_numerical_plugin.class.php
+++ b/question/type/numerical/backup/moodle2/restore_qtype_numerical_plugin.class.php
@@ -41,19 +41,19 @@ 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);
- // Add own qtype stuff
+ // Add own qtype stuff.
$elename = 'numerical';
$elepath = $this->get_pathfor('/numerical_records/numerical_record');
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -65,7 +65,7 @@ public function process_numerical($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;
@@ -73,10 +73,10 @@ public function process_numerical($data) {
// If the question has been created by restore, we need to create its
// question_numerical 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_numerical', $data);
}
}
diff --git a/question/type/numerical/db/upgrade.php b/question/type/numerical/db/upgrade.php
index ea8c65885844e..7dfc77fb68248 100644
--- a/question/type/numerical/db/upgrade.php
+++ b/question/type/numerical/db/upgrade.php
@@ -36,14 +36,11 @@ function xmldb_qtype_numerical_upgrade($oldversion) {
$dbman = $DB->get_manager();
-
// 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;
}
diff --git a/question/type/numerical/question.php b/question/type/numerical/question.php
index 0e48155c6deec..8df2ce93486e3 100644
--- a/question/type/numerical/question.php
+++ b/question/type/numerical/question.php
@@ -287,7 +287,7 @@ public function check_file_access($qa, $options, $component, $filearea, $args,
list($value, $unit, $multiplier) = $this->ap->apply_units(
$currentanswer, $selectedunit);
$answer = $this->get_matching_answer($value, $multiplier);
- $answerid = reset($args); // itemid is answer id.
+ $answerid = reset($args); // Itemid is answer id.
return $options->feedback && $answer && $answerid == $answer->id;
} else if ($component == 'question' && $filearea == 'hint') {
diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php
index c02e91f6a7267..2d290aacb57fc 100644
--- a/question/type/numerical/questiontype.php
+++ b/question/type/numerical/questiontype.php
@@ -75,8 +75,8 @@ public function get_question_options($question) {
array('questionid' => $question->id), 'id ASC');
$this->get_numerical_units($question);
- // get_numerical_options() need to know if there are units
- // to set correctly default values
+ // Get_numerical_options() need to know if there are units
+ // to set correctly default values.
$this->get_numerical_options($question);
// If units are defined we strip off the default unit from the answer, if
@@ -153,7 +153,7 @@ public function save_question_options($question) {
global $DB;
$context = $question->context;
- // Get old versions of the objects
+ // Get old versions of the objects.
$oldanswers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC');
$oldoptions = $DB->get_records('question_numerical',
@@ -167,7 +167,7 @@ public function save_question_options($question) {
$units = $result->units;
}
- // Insert all the new answers
+ // Insert all the new answers.
foreach ($question->answer as $key => $answerdata) {
// Check for, and ingore, completely blank answer from the form.
if (trim($answerdata) == '' && $question->fraction[$key] == 0 &&
@@ -200,7 +200,7 @@ public function save_question_options($question) {
$answer->feedbackformat = $question->feedback[$key]['format'];
$DB->update_record('question_answers', $answer);
- // Set up the options object
+ // Set up the options object.
if (!$options = array_shift($oldoptions)) {
$options = new stdClass();
}
@@ -323,7 +323,7 @@ public function save_units($question) {
$units = array();
$unitalreadyinsert = array();
foreach ($question->multiplier as $i => $multiplier) {
- // Discard any unit which doesn't specify the unit or the multiplier
+ // Discard any unit which doesn't specify the unit or the multiplier.
if (!empty($question->multiplier[$i]) && !empty($question->unit[$i]) &&
!array_key_exists($question->unit[$i], $unitalreadyinsert)) {
$unitalreadyinsert[$question->unit[$i]] = 1;
@@ -655,7 +655,7 @@ public function apply_units($response, $separateunit = null) {
$numberstring = $matches[0];
if ($this->unitsbefore) {
- // substr returns false when it means '', so cast back to string.
+ // Substr returns false when it means '', so cast back to string.
$unit = (string) substr($response, 0, -strlen($numberstring));
} else {
$unit = (string) substr($response, strlen($numberstring));
@@ -671,7 +671,7 @@ public function apply_units($response, $separateunit = null) {
$multiplier = null;
}
- return array($numberstring + 0, $unit, $multiplier); // + 0 to convert to number.
+ return array($numberstring + 0, $unit, $multiplier); // The + 0 is to convert to number.
}
/**
diff --git a/question/type/questionbase.php b/question/type/questionbase.php
index f2d0a06b9c1eb..e7b14ca1f98d5 100644
--- a/question/type/questionbase.php
+++ b/question/type/questionbase.php
@@ -610,7 +610,7 @@ protected function check_hint_file_access($qa, $options, $args) {
return false;
}
$hint = $qa->get_applicable_hint();
- $hintid = reset($args); // itemid is hint id.
+ $hintid = reset($args); // Itemid is hint id.
return $hintid == $hint->id;
}
diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php
index 0ab59f851c1f4..6d619715f5923 100644
--- a/question/type/questiontypebase.php
+++ b/question/type/questiontypebase.php
@@ -333,7 +333,7 @@ public function save_question($question, $form) {
// This default implementation is suitable for most
// question types.
- // First, save the basic question itself
+ // First, save the basic question itself.
$question->name = trim($form->name);
$question->parent = isset($form->parent) ? $form->parent : 0;
$question->length = $this->actual_number_of_questions($question);
@@ -372,7 +372,7 @@ public function save_question($question, $form) {
// If the question is new, create it.
if (empty($question->id)) {
- // Set the unique code
+ // Set the unique code.
$question->stamp = make_unique_id_code();
$question->createdby = $USER->id;
$question->timecreated = time();
@@ -381,7 +381,7 @@ public function save_question($question, $form) {
// Now, whether we are updating a existing question, or creating a new
// one, we have to do the files processing and update the record.
- /// Question already exists, update.
+ // Question already exists, update.
$question->modifiedby = $USER->id;
$question->timemodified = time();
@@ -398,13 +398,13 @@ public function save_question($question, $form) {
}
$DB->update_record('question', $question);
- // Now to save all the answers and type-specific options
+ // Now to save all the answers and type-specific options.
$form->id = $question->id;
$form->qtype = $question->qtype;
$form->category = $question->category;
$form->questiontext = $question->questiontext;
$form->questiontextformat = $question->questiontextformat;
- // current context
+ // Current context.
$form->context = $context;
$result = $this->save_question_options($form);
@@ -422,7 +422,7 @@ public function save_question($question, $form) {
'$result->noticeyesno no longer supported in save_question.');
}
- // Give the question a unique version stamp determined by question_hash()
+ // Give the question a unique version stamp determined by question_hash().
$DB->set_field('question', 'version', question_hash($question),
array('id' => $question->id));
@@ -679,12 +679,12 @@ protected function initialise_question_instance(question_definition $question, $
$question->createdby = $questiondata->createdby;
$question->modifiedby = $questiondata->modifiedby;
- //Fill extra question fields values
+ // Fill extra question fields values.
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
- //omit table name
+ // Omit table name.
array_shift($extraquestionfields);
- foreach($extraquestionfields as $field) {
+ foreach ($extraquestionfields as $field) {
$question->$field = $questiondata->options->$field;
}
}
@@ -805,7 +805,7 @@ public function delete_question($questionid, $contextid) {
* Question type specific information is included.
*/
public function actual_number_of_questions($question) {
- // By default, each question is given one number
+ // By default, each question is given one number.
return 1;
}
@@ -885,11 +885,11 @@ public function find_standard_scripts() {
* @return bool Whether the wizard's last page was submitted or not.
*/
public function finished_edit_wizard($form) {
- //In the default case there is only one edit page.
+ // In the default case there is only one edit page.
return true;
}
- /// IMPORT/EXPORT FUNCTIONS /////////////////
+ // IMPORT/EXPORT FUNCTIONS --------------------------------- .
/*
* Imports question from the Moodle XML format
@@ -908,7 +908,7 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
return false;
}
- //omit table name
+ // Omit table name.
array_shift($extraquestionfields);
$qo = $format->import_headers($data);
$qo->qtype = $question_type;
@@ -917,7 +917,7 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
$qo->$field = $format->getpath($data, array('#', $field, 0, '#'), '');
}
- // run through the answers
+ // Run through the answers.
$answers = $data['#']['answer'];
$a_count = 0;
$extraanswersfields = $this->extra_answer_fields();
@@ -956,7 +956,7 @@ public function export_to_xml($question, qformat_xml $format, $extra=null) {
return false;
}
- //omit table name
+ // Omit table name.
array_shift($extraquestionfields);
$expout='';
foreach ($extraquestionfields as $field) {
diff --git a/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php b/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
index 3ae3681daf0b2..7418cd174ebce 100644
--- a/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
+++ b/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
@@ -49,20 +49,20 @@ public function recode_legacy_state_answer($state) {
$answer = $state->answer;
$result = '';
- // randomxx-yy answer format
+ // Randomxx-yy answer format.
if (preg_match('~^random([0-9]+)-(.*)$~', $answer, $matches)) {
$questionid = $matches[1];
$subanswer = $matches[2];
$newquestionid = $this->get_mappingid('question', $questionid);
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $newquestionid));
- // Delegate subanswer recode to proper qtype, faking one question_states record
+ // Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $newquestionid;
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
$result = 'random' . $newquestionid . '-' . $newanswer;
- // simple question id format
+ // Simple question id format.
} else {
$newquestionid = $this->get_mappingid('question', $answer);
$result = $newquestionid;
diff --git a/question/type/random/edit_random_form.php b/question/type/random/edit_random_form.php
index 5d0d80bfd09e4..6f771a0aee756 100644
--- a/question/type/random/edit_random_form.php
+++ b/question/type/random/edit_random_form.php
@@ -72,8 +72,8 @@ public function set_data($question) {
}
public function validation($fromform, $files) {
- //validation of category
- //is not relevant for this question type
+ // Validation of category is not relevant for this question type.
+
return array();
}
diff --git a/question/type/random/questiontype.php b/question/type/random/questiontype.php
index 7ef7de2a449bc..2a4955f16e9a4 100644
--- a/question/type/random/questiontype.php
+++ b/question/type/random/questiontype.php
@@ -84,7 +84,7 @@ public function is_question_manual_graded($question, $otherquestionsinuse) {
$categorylist = array($question->category);
}
list($qcsql, $qcparams) = $DB->get_in_or_equal($categorylist);
- // TODO use in_or_equal for $otherquestionsinuse and $this->manualqtypes
+ // TODO use in_or_equal for $otherquestionsinuse and $this->manualqtypes.
return $DB->record_exists_select('question',
"category $qcsql
AND parent = 0
diff --git a/question/type/randomsamatch/backup/moodle2/backup_qtype_randomsamatch_plugin.class.php b/question/type/randomsamatch/backup/moodle2/backup_qtype_randomsamatch_plugin.class.php
index ca1cce36a0b6e..aaa0acfccf920 100644
--- a/question/type/randomsamatch/backup/moodle2/backup_qtype_randomsamatch_plugin.class.php
+++ b/question/type/randomsamatch/backup/moodle2/backup_qtype_randomsamatch_plugin.class.php
@@ -38,23 +38,23 @@ class backup_qtype_randomsamatch_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'randomsamatch');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$randomsamatch = new backup_nested_element('randomsamatch', array('id'), array(
'choose'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($randomsamatch);
- // set source to populate the data
+ // Set source to populate the data.
$randomsamatch->set_source_table('question_randomsamatch',
array('question' => backup::VAR_PARENTID));
diff --git a/question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php b/question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php
index cc416453e08ca..4e3961c8b2464 100644
--- a/question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php
+++ b/question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php
@@ -46,7 +46,7 @@ protected function define_question_plugin_structure() {
$elepath = $this->get_pathfor('/randomsamatch');
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -58,19 +58,19 @@ public function process_randomsamatch($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_randomsamatch too
+ // question_randomsamatch too.
if ($questioncreated) {
- // Adjust some columns
+ // Adjust some columns.
$data->question = $newquestionid;
- // Insert record
+ // Insert record.
$newitemid = $DB->insert_record('question_randomsamatch', $data);
- // Create mapping
+ // Create mapping.
$this->set_mapping('question_randomsamatch', $oldid, $newitemid);
}
}
diff --git a/question/type/randomsamatch/questiontype.php b/question/type/randomsamatch/questiontype.php
index a9641035c9e41..b54bac147e55e 100644
--- a/question/type/randomsamatch/questiontype.php
+++ b/question/type/randomsamatch/questiontype.php
@@ -54,7 +54,7 @@ public function get_question_options($question) {
// This could be included as a flag in the database. It's already
// supported by the code.
- // Recurse subcategories: 0 = no recursion, 1 = recursion
+ // Recurse subcategories: 0 = no recursion, 1 = recursion .
$question->options->subcats = 1;
return true;
@@ -95,14 +95,14 @@ public function create_session_and_responses(&$question, &$state, $cmoptions, $a
// quiz. Therfore the following need to be excluded:
// 1. All questions that are explicitly assigned to the quiz
// 2. All random questions
- // 3. All questions that are already chosen by an other random question
+ // 3. All questions that are already chosen by an other random question.
global $QTYPES, $OUTPUT, $USER;
if (!isset($cmoptions->questionsinuse)) {
$cmoptions->questionsinuse = $cmoptions->questions;
}
if ($question->options->subcats) {
- // recurse into subcategories
+ // Recurse into subcategories.
$categorylist = question_categorylist($question->category);
} else {
$categorylist = array($question->category);
@@ -117,13 +117,13 @@ public function create_session_and_responses(&$question, &$state, $cmoptions, $a
$question->questiontext = "Insufficient selection options are
available for this question, therefore it is not available in this
quiz. Please inform your teacher.";
- // Treat this as a description from this point on
+ // Treat this as a description from this point on.
$question->qtype = 'description';
return true;
}
$saquestions =
- draw_rand_array($saquestions, $question->options->choose); // from bug 1889
+ draw_rand_array($saquestions, $question->options->choose); // From bug 1889.
foreach ($saquestions as $key => $wrappedquestion) {
if (!$QTYPES[$wrappedquestion->qtype]
@@ -155,12 +155,12 @@ public function create_session_and_responses(&$question, &$state, $cmoptions, $a
$state->options->subquestions[$key] = clone($wrappedquestion);
}
- // Shuffle the answers (Do this always because this is a random question type)
+ // Shuffle the answers (Do this always because this is a random question type).
$subquestionids = array_values(array_map(create_function('$val',
'return $val->id;'), $state->options->subquestions));
$subquestionids = swapshuffle($subquestionids);
- // Create empty responses
+ // Create empty responses.
foreach ($subquestionids as $val) {
$state->responses[$val] = '';
}
@@ -175,14 +175,14 @@ function restore_session_and_responses(&$question, &$state) {
$question->questiontext = "Insufficient selection options are
available for this question, therefore it is not available in this
quiz. Please inform your teacher.";
- // Treat this as a description from this point on
+ // Treat this as a description from this point on.
$question->qtype = 'description';
} else {
$responses = explode(',', $state->responses['']);
$responses = array_map(create_function('$val',
'return explode("-", $val);'), $responses);
- // Restore the previous responses
+ // Restore the previous responses.
$state->responses = array();
foreach ($responses as $response) {
$wqid = $response[0];
diff --git a/question/type/shortanswer/backup/moodle1/lib.php b/question/type/shortanswer/backup/moodle1/lib.php
index 6c553b3c35565..314c78ace6641 100644
--- a/question/type/shortanswer/backup/moodle1/lib.php
+++ b/question/type/shortanswer/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
write_answers($data['answers'], $this->pluginname);
}
- // convert and write the shortanswer extra fields
+ // Convert and write the shortanswer extra fields.
foreach ($data['shortanswer'] as $shortanswer) {
$shortanswer['id'] = $this->converter->get_nextid();
$this->write_xml('shortanswer', $shortanswer, array('/shortanswer/id'));
diff --git a/question/type/shortanswer/backup/moodle2/backup_qtype_shortanswer_plugin.class.php b/question/type/shortanswer/backup/moodle2/backup_qtype_shortanswer_plugin.class.php
index 39570e2e94318..79713c4de10c0 100644
--- a/question/type/shortanswer/backup/moodle2/backup_qtype_shortanswer_plugin.class.php
+++ b/question/type/shortanswer/backup/moodle2/backup_qtype_shortanswer_plugin.class.php
@@ -38,30 +38,30 @@ class backup_qtype_shortanswer_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'shortanswer');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$shortanswer = new backup_nested_element('shortanswer', array('id'), array('usecase'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($shortanswer);
- // set source to populate the data
+ // Set source to populate the data.
$shortanswer->set_source_table('qtype_shortanswer_options',
array('questionid' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php b/question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php
index 665a5cdd522bb..c74178b3133f4 100644
--- a/question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php
+++ b/question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php
@@ -41,16 +41,16 @@ 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);
- // Add own qtype stuff
+ // Add own qtype stuff.
$elename = 'shortanswer';
- // we used get_recommended_name() so this works
+ // We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/shortanswer');
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -62,7 +62,7 @@ public function process_shortanswer($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;
diff --git a/question/type/shortanswer/db/upgrade.php b/question/type/shortanswer/db/upgrade.php
index cadf88a29f52e..65463d1a06f4e 100644
--- a/question/type/shortanswer/db/upgrade.php
+++ b/question/type/shortanswer/db/upgrade.php
@@ -36,8 +36,8 @@ function xmldb_qtype_shortanswer_upgrade($oldversion) {
$dbman = $DB->get_manager();
- // Moodle v2.4.0 release upgrade line
- // Put any upgrade step following this
+ // Moodle v2.4.0 release upgrade line.
+ // Put any upgrade step following this.
if ($oldversion < 2013011800) {
@@ -56,14 +56,14 @@ function xmldb_qtype_shortanswer_upgrade($oldversion) {
if ($oldversion < 2013011801) {
- // Define key question (foreign) to be dropped form question_shortanswer
+ // Define key question (foreign) to be dropped form question_shortanswer.
$table = new xmldb_table('question_shortanswer');
$key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
- // Launch drop key question
+ // Launch drop key question.
$dbman->drop_key($table, $key);
- // shortanswer savepoint reached
+ // Shortanswer savepoint reached.
upgrade_plugin_savepoint(true, 2013011801, 'qtype', 'shortanswer');
}
@@ -82,26 +82,26 @@ function xmldb_qtype_shortanswer_upgrade($oldversion) {
if ($oldversion < 2013011803) {
- // Define key questionid (foreign-unique) to be added to question_shortanswer
+ // Define key questionid (foreign-unique) to be added to question_shortanswer.
$table = new xmldb_table('question_shortanswer');
$key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id'));
- // Launch add key questionid
+ // Launch add key questionid.
$dbman->add_key($table, $key);
- // shortanswer savepoint reached
+ // Shortanswer savepoint reached.
upgrade_plugin_savepoint(true, 2013011803, 'qtype', 'shortanswer');
}
if ($oldversion < 2013011804) {
- // Define table qtype_shortanswer_options to be renamed to qtype_shortanswer_options
+ // Define table qtype_shortanswer_options to be renamed to qtype_shortanswer_options.
$table = new xmldb_table('question_shortanswer');
- // Launch rename table for qtype_shortanswer_options
+ // Launch rename table for qtype_shortanswer_options.
$dbman->rename_table($table, 'qtype_shortanswer_options');
- // shortanswer savepoint reached
+ // Shortanswer savepoint reached.
upgrade_plugin_savepoint(true, 2013011804, 'qtype', 'shortanswer');
}
diff --git a/question/type/shortanswer/question.php b/question/type/shortanswer/question.php
index 07b1ab00fb61a..df200fff3f17d 100644
--- a/question/type/shortanswer/question.php
+++ b/question/type/shortanswer/question.php
@@ -162,7 +162,7 @@ public function check_file_access($qa, $options, $component, $filearea,
if ($component == 'question' && $filearea == 'answerfeedback') {
$currentanswer = $qa->get_last_qt_var('answer');
$answer = $this->get_matching_answer(array('answer' => $currentanswer));
- $answerid = reset($args); // itemid is answer id.
+ $answerid = reset($args); // Itemid is answer id.
return $options->feedback && $answer && $answerid == $answer->id;
} else if ($component == 'question' && $filearea == 'hint') {
diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php
index 5aa5d3da70d93..da66d12b98cea 100644
--- a/question/type/shortanswer/questiontype.php
+++ b/question/type/shortanswer/questiontype.php
@@ -65,7 +65,7 @@ public function save_question_options($question) {
$maxfraction = -1;
- // Insert all the new answers
+ // Insert all the new answers.
foreach ($question->answer as $key => $answerdata) {
// Check for, and ignore, completely blank answer from the form.
if (trim($answerdata) == '' && $question->fraction[$key] == 0 &&
@@ -97,7 +97,7 @@ public function save_question_options($question) {
$parentresult = parent::save_question_options($question);
if ($parentresult !== null) {
- // Parent function returns null if all is OK
+ // Parent function returns null if all is OK.
return $parentresult;
}
diff --git a/question/type/shortanswer/tests/question_test.php b/question/type/shortanswer/tests/question_test.php
index 5dc15ee694a3e..49b753c53191d 100644
--- a/question/type/shortanswer/tests/question_test.php
+++ b/question/type/shortanswer/tests/question_test.php
@@ -103,12 +103,12 @@ public function test_compare_string_with_wildcard() {
$this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard(
'\{}/', '\{}/', true));
- // See http://moodle.org/mod/forum/discuss.php?d=120557
+ // See http://moodle.org/mod/forum/discuss.php?d=120557.
$this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard(
'ITÁLIE', 'Itálie', true));
if (function_exists('normalizer_normalize')) {
- // Test ambiguous unicode representations
+ // Test ambiguous unicode representations.
$this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard(
'départ', 'DÉPART', true));
$this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard(
diff --git a/question/type/truefalse/backup/moodle1/lib.php b/question/type/truefalse/backup/moodle1/lib.php
index 5d45d5ff926e2..7505c8d3a01dd 100644
--- a/question/type/truefalse/backup/moodle1/lib.php
+++ b/question/type/truefalse/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
write_answers($data['answers'], $this->pluginname);
}
- // convert and write the truefalse extra fields
+ // Convert and write the truefalse extra fields.
foreach ($data['truefalse'] as $truefalse) {
$truefalse['id'] = $this->converter->get_nextid();
$this->write_xml('truefalse', $truefalse, array('/truefalse/id'));
diff --git a/question/type/truefalse/backup/moodle2/backup_qtype_truefalse_plugin.class.php b/question/type/truefalse/backup/moodle2/backup_qtype_truefalse_plugin.class.php
index d657ff3485f3f..e3482f1215fc2 100644
--- a/question/type/truefalse/backup/moodle2/backup_qtype_truefalse_plugin.class.php
+++ b/question/type/truefalse/backup/moodle2/backup_qtype_truefalse_plugin.class.php
@@ -38,31 +38,31 @@ class backup_qtype_truefalse_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.
$plugin = $this->get_plugin_element(null, '../../qtype', 'truefalse');
- // 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);
- // Now create the qtype own structures
+ // Now create the qtype own structures.
$truefalse = new backup_nested_element('truefalse', array('id'), array(
'trueanswer', 'falseanswer'));
- // Now the own qtype tree
+ // Now the own qtype tree.
$pluginwrapper->add_child($truefalse);
- // set source to populate the data
+ // Set source to populate the data.
$truefalse->set_source_table('question_truefalse',
array('question' => backup::VAR_PARENTID));
- // don't need to annotate ids nor files
+ // Don't need to annotate ids nor files.
return $plugin;
}
diff --git a/question/type/truefalse/backup/moodle2/restore_qtype_truefalse_plugin.class.php b/question/type/truefalse/backup/moodle2/restore_qtype_truefalse_plugin.class.php
index d2bdbbe9cb1f3..39e5352d3cf04 100644
--- a/question/type/truefalse/backup/moodle2/restore_qtype_truefalse_plugin.class.php
+++ b/question/type/truefalse/backup/moodle2/restore_qtype_truefalse_plugin.class.php
@@ -41,15 +41,15 @@ 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);
- // Add own qtype stuff
+ // Add own qtype stuff.
$elename = 'truefalse';
- $elepath = $this->get_pathfor('/truefalse'); // we used get_recommended_name() so this works
+ $elepath = $this->get_pathfor('/truefalse'); // We used get_recommended_name() so this works.
$paths[] = new restore_path_element($elename, $elepath);
- return $paths; // And we return the interesting paths
+ return $paths; // And we return the interesting paths.
}
/**
@@ -61,20 +61,20 @@ public function process_truefalse($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_truefalse too
+ // If the question has been created by restore, we need to create its question_truefalse too.
if ($questioncreated) {
- // Adjust some columns
+ // Adjust some columns.
$data->question = $newquestionid;
$data->trueanswer = $this->get_mappingid('question_answer', $data->trueanswer);
$data->falseanswer = $this->get_mappingid('question_answer', $data->falseanswer);
- // Insert record
+ // Insert record.
$newitemid = $DB->insert_record('question_truefalse', $data);
- // Create mapping
+ // Create mapping.
$this->set_mapping('question_truefalse', $oldid, $newitemid);
}
}
diff --git a/question/type/truefalse/edit_truefalse_form.php b/question/type/truefalse/edit_truefalse_form.php
index 9e6f930362f1b..4a1777698a631 100644
--- a/question/type/truefalse/edit_truefalse_form.php
+++ b/question/type/truefalse/edit_truefalse_form.php
@@ -79,13 +79,13 @@ public function data_preprocessing($question) {
$question->feedbacktrue = array();
$question->feedbacktrue['format'] = $trueanswer->feedbackformat;
$question->feedbacktrue['text'] = file_prepare_draft_area(
- $draftid, // draftid
+ $draftid, // Draftid
$this->context->id, // context
'question', // component
'answerfeedback', // filarea
!empty($answerid) ? (int) $answerid : null, // itemid
$this->fileoptions, // options
- $trueanswer->feedback // text
+ $trueanswer->feedback // text.
);
$question->feedbacktrue['itemid'] = $draftid;
}
@@ -99,13 +99,13 @@ public function data_preprocessing($question) {
$question->feedbackfalse = array();
$question->feedbackfalse['format'] = $falseanswer->feedbackformat;
$question->feedbackfalse['text'] = file_prepare_draft_area(
- $draftid, // draftid
+ $draftid, // Draftid
$this->context->id, // context
'question', // component
'answerfeedback', // filarea
!empty($answerid) ? (int) $answerid : null, // itemid
$this->fileoptions, // options
- $falseanswer->feedback // text
+ $falseanswer->feedback // text.
);
$question->feedbackfalse['itemid'] = $draftid;
}
diff --git a/question/type/truefalse/question.php b/question/type/truefalse/question.php
index 60f3ba029fed0..5dd77d7b6621a 100644
--- a/question/type/truefalse/question.php
+++ b/question/type/truefalse/question.php
@@ -101,7 +101,7 @@ public function grade_response(array $response) {
public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'question' && $filearea == 'answerfeedback') {
- $answerid = reset($args); // itemid is answer id.
+ $answerid = reset($args); // Itemid is answer id.
$response = $qa->get_last_qt_var('answer', '');
return $options->feedback && (
($answerid == $this->trueanswerid && $response) ||
diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php
index 4254ce9f7befc..c883a4c82839a 100644
--- a/question/type/truefalse/questiontype.php
+++ b/question/type/truefalse/questiontype.php
@@ -41,7 +41,7 @@ public function save_question_options($question) {
$result = new stdClass();
$context = $question->context;
- // Fetch old answer ids so that we can reuse them
+ // Fetch old answer ids so that we can reuse them.
$oldanswers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC');
@@ -88,10 +88,10 @@ public function save_question_options($question) {
$DB->delete_records('question_answers', array('id' => $oldanswer->id));
}
- // Save question options in question_truefalse table
+ // Save question options in question_truefalse table.
if ($options = $DB->get_record('question_truefalse', array('question' => $question->id))) {
// No need to do anything, since the answer IDs won't have changed
- // But we'll do it anyway, just for robustness
+ // But we'll do it anyway, just for robustness.
$options->trueanswer = $trueid;
$options->falseanswer = $falseid;
$DB->update_record('question_truefalse', $options);
@@ -114,13 +114,13 @@ public function save_question_options($question) {
public function get_question_options($question) {
global $DB, $OUTPUT;
// Get additional information from database
- // and attach it to the question object
+ // and attach it to the question object.
if (!$question->options = $DB->get_record('question_truefalse',
array('question' => $question->id))) {
echo $OUTPUT->notification('Error: Missing question options!');
return false;
}
- // Load the answers
+ // Load the answers.
if (!$question->options->answers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC')) {
echo $OUTPUT->notification('Error: Missing question answers for truefalse question ' .
diff --git a/question/type/truefalse/renderer.php b/question/type/truefalse/renderer.php
index b0e47b1e85bb3..61828ba06de80 100644
--- a/question/type/truefalse/renderer.php
+++ b/question/type/truefalse/renderer.php
@@ -59,7 +59,7 @@ public function formulation_and_controls(question_attempt $qa,
$falseattributes['disabled'] = 'disabled';
}
- // Work out which radio button to select (if any)
+ // Work out which radio button to select (if any).
$truechecked = false;
$falsechecked = false;
$responsearray = array();
@@ -108,9 +108,9 @@ public function formulation_and_controls(question_attempt $qa,
array('class' => 'r0' . $trueclass));
$result .= html_writer::tag('div', $radiofalse . ' ' . $falsefeedbackimg,
array('class' => 'r1' . $falseclass));
- $result .= html_writer::end_tag('div'); // answer
+ $result .= html_writer::end_tag('div'); // Answer.
- $result .= html_writer::end_tag('div'); // ablock
+ $result .= html_writer::end_tag('div'); // Ablock.
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
diff --git a/question/type/truefalse/tests/question_test.php b/question/type/truefalse/tests/question_test.php
index b0a914b967d3d..4d68b4b072655 100644
--- a/question/type/truefalse/tests/question_test.php
+++ b/question/type/truefalse/tests/question_test.php
@@ -65,11 +65,11 @@ public function test_grading() {
public function test_get_correct_response() {
$question = test_question_maker::make_question('truefalse', 'true');
- // true
+ // True.
$this->assertSame(array('answer' => 1),
$question->get_correct_response());
- // false
+ // False.
$question->rightanswer = false;
$this->assertSame(array('answer' => 0),
$question->get_correct_response());
diff --git a/question/type/truefalse/tests/upgradelibnewqe_test.php b/question/type/truefalse/tests/upgradelibnewqe_test.php
index e4cce5bca269e..315ec369387a1 100644
--- a/question/type/truefalse/tests/upgradelibnewqe_test.php
+++ b/question/type/truefalse/tests/upgradelibnewqe_test.php
@@ -966,7 +966,7 @@ public function test_truefalse_adaptive_qsession120() {
$this->compare_qas($expectedqa, $qa);
}
- public function test_truefalse_adaptive_qsession3() {
+ public function test_truefalse_adaptive_qsession3() {
$quiz = (object) array(
'id' => '1',
'course' => '2',