Skip to content

Commit

Permalink
MDL-38792 Update question/type in-line comments to codechecker standards
Browse files Browse the repository at this point in the history
Correct bad formated infiles in question/type directories
  • Loading branch information
ppichet committed Apr 8, 2013
1 parent 422f68f commit 3d9645a
Show file tree
Hide file tree
Showing 68 changed files with 605 additions and 627 deletions.
11 changes: 5 additions & 6 deletions question/type/calculated/backup/moodle1/lib.php
@@ -1,5 +1,4 @@
<?php <?php

// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -47,12 +46,12 @@ public function get_question_subpaths() {
*/ */
public function process_question(array $data, array $raw) { public function process_question(array $data, array $raw) {


// convert and write the answers first // Convert and write the answers first.
if (isset($data['answers'])) { if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname); $this->write_answers($data['answers'], $this->pluginname);
} }


// convert and write the numerical units and numerical options // Convert and write the numerical units and numerical options.
if (isset($data['calculated'][0]['numerical_units'])) { if (isset($data['calculated'][0]['numerical_units'])) {
$numericalunits = $data['calculated'][0]['numerical_units']; $numericalunits = $data['calculated'][0]['numerical_units'];
} else { } else {
Expand All @@ -64,15 +63,15 @@ public function process_question(array $data, array $raw) {
$this->write_numerical_units($numericalunits); $this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions); $this->write_numerical_options($numericaloptions);


// write dataset_definitions // Write dataset_definitions.
if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) { if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) {
$datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition']; $datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition'];
} else { } else {
$datasetdefinitions = array(); $datasetdefinitions = array();
} }
$this->write_dataset_definitions($datasetdefinitions); $this->write_dataset_definitions($datasetdefinitions);


// write calculated_records // Write calculated_records.
$this->xmlwriter->begin_tag('calculated_records'); $this->xmlwriter->begin_tag('calculated_records');
foreach ($data['calculated'] as $calculatedrecord) { foreach ($data['calculated'] as $calculatedrecord) {
$record = array( $record = array(
Expand All @@ -87,7 +86,7 @@ public function process_question(array $data, array $raw) {
} }
$this->xmlwriter->end_tag('calculated_records'); $this->xmlwriter->end_tag('calculated_records');


// write calculated_options // Write calculated_options.
$options = array( $options = array(
'calculate_option' => array( 'calculate_option' => array(
'id' => $this->converter->get_nextid(), 'id' => $this->converter->get_nextid(),
Expand Down
Expand Up @@ -38,31 +38,31 @@ class backup_qtype_calculated_plugin extends backup_qtype_plugin {
*/ */
protected function define_question_plugin_structure() { 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 // 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); $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()); $pluginwrapper = new backup_nested_element($this->get_recommended_name());


// connect the visible container ASAP // Connect the visible container ASAP.
$plugin->add_child($pluginwrapper); $plugin->add_child($pluginwrapper);


// This qtype uses standard question_answers, add them here // 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->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->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->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); $this->add_question_datasets($pluginwrapper);


// Now create the qtype own structures // Now create the qtype own structures.
$calculatedrecords = new backup_nested_element('calculated_records'); $calculatedrecords = new backup_nested_element('calculated_records');
$calculatedrecord = new backup_nested_element('calculated_record', array('id'), array( $calculatedrecord = new backup_nested_element('calculated_record', array('id'), array(
'answer', 'tolerance', 'tolerancetype', 'correctanswerlength', 'answer', 'tolerance', 'tolerancetype', 'correctanswerlength',
Expand All @@ -74,20 +74,20 @@ protected function define_question_plugin_structure() {
'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', 'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering')); 'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering'));


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


$pluginwrapper->add_child($calculatedoptions); $pluginwrapper->add_child($calculatedoptions);
$calculatedoptions->add_child($calculatedoption); $calculatedoptions->add_child($calculatedoption);


// set source to populate the data // Set source to populate the data.
$calculatedrecord->set_source_table('question_calculated', $calculatedrecord->set_source_table('question_calculated',
array('question' => backup::VAR_PARENTID)); array('question' => backup::VAR_PARENTID));
$calculatedoption->set_source_table('question_calculated_options', $calculatedoption->set_source_table('question_calculated_options',
array('question' => backup::VAR_PARENTID)); array('question' => backup::VAR_PARENTID));


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


return $plugin; return $plugin;
} }
Expand Down
Expand Up @@ -41,17 +41,17 @@ protected function define_question_plugin_structure() {


$paths = array(); $paths = array();


// This qtype uses question_answers, add them // This qtype uses question_answers, add them.
$this->add_question_question_answers($paths); $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_options($paths);
$this->add_question_numerical_units($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); $this->add_question_datasets($paths);


// Add own qtype stuff // Add own qtype stuff.
$elename = 'calculated_record'; $elename = 'calculated_record';
$elepath = $this->get_pathfor('/calculated_records/calculated_record'); $elepath = $this->get_pathfor('/calculated_records/calculated_record');
$paths[] = new restore_path_element($elename, $elepath); $paths[] = new restore_path_element($elename, $elepath);
Expand All @@ -60,7 +60,7 @@ protected function define_question_plugin_structure() {
$elepath = $this->get_pathfor('/calculated_options/calculated_option'); $elepath = $this->get_pathfor('/calculated_options/calculated_option');
$paths[] = new restore_path_element($elename, $elepath); $paths[] = new restore_path_element($elename, $elepath);


return $paths; // And we return the interesting paths return $paths; // And we return the interesting paths.
} }


/** /**
Expand All @@ -72,19 +72,19 @@ public function process_calculated_record($data) {
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $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'); $oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question'); $newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
true : false; true : false;


// If the question has been created by restore, we need to create its // If the question has been created by restore, we need to create its
// question_calculated too // question_calculated too.
if ($questioncreated) { if ($questioncreated) {
// Adjust some columns // Adjust some columns.
$data->question = $newquestionid; $data->question = $newquestionid;
$data->answer = $this->get_mappingid('question_answer', $data->answer); $data->answer = $this->get_mappingid('question_answer', $data->answer);
// Insert record // Insert record.
$newitemid = $DB->insert_record('question_calculated', $data); $newitemid = $DB->insert_record('question_calculated', $data);
} }
} }
Expand All @@ -98,18 +98,18 @@ public function process_calculated_option($data) {
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $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'); $oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question'); $newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ?
true : false; true : false;


// If the question has been created by restore, we need to create its // If the question has been created by restore, we need to create its
// question_calculated too // question_calculated too.
if ($questioncreated) { if ($questioncreated) {
// Adjust some columns // Adjust some columns.
$data->question = $newquestionid; $data->question = $newquestionid;
// Insert record // Insert record.
$newitemid = $DB->insert_record('question_calculated_options', $data); $newitemid = $DB->insert_record('question_calculated_options', $data);
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions question/type/calculated/datasetdefinitions_form.php
Expand Up @@ -92,7 +92,7 @@ protected function definition() {
$datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question); $datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question);
$datasetmenus = array(); $datasetmenus = array();
$label = "<div class='mdl-align'>".get_string('datasetrole', 'qtype_calculated')."</div>"; $label = "<div class='mdl-align'>".get_string('datasetrole', 'qtype_calculated')."</div>";
// explaining the role of datasets so other strings can be shortened // Explaining the role of datasets so other strings can be shortened.
$mform->addElement('html', $label); $mform->addElement('html', $label);
$mform->addElement('header', 'mandatoryhdr', $mform->addElement('header', 'mandatoryhdr',
get_string('mandatoryhdr', 'qtype_calculated')); get_string('mandatoryhdr', 'qtype_calculated'));
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function definition() {
$key++; $key++;
} }
} }
// temporary strings // Temporary strings.
$mform->addElement('header', 'synchronizehdr', $mform->addElement('header', 'synchronizehdr',
get_string('synchronize', 'qtype_calculated')); get_string('synchronize', 'qtype_calculated'));
$mform->addElement('radio', 'synchronize', '', $mform->addElement('radio', 'synchronize', '',
Expand Down
27 changes: 13 additions & 14 deletions question/type/calculated/datasetitems_form.php
Expand Up @@ -80,7 +80,7 @@ public function __construct($submiturl, $question, $regenerate) {
} }
$this->category = $category; $this->category = $category;
$this->categorycontext = context::instance_by_id($category->contextid); $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)) { if (empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions( $this->datasetdefs = $this->qtypeobj->get_dataset_definitions(
$question->id, $SESSION->calculated->definitionform->dataset); $question->id, $SESSION->calculated->definitionform->dataset);
Expand All @@ -93,7 +93,7 @@ public function __construct($submiturl, $question, $regenerate) {
} }


foreach ($this->datasetdefs as $datasetdef) { foreach ($this->datasetdefs as $datasetdef) {
// Get maxnumber // Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) { if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount; $this->maxnumber = $datasetdef->itemcount;
} }
Expand All @@ -108,8 +108,7 @@ public function __construct($submiturl, $question, $regenerate) {
} }


protected function definition() { protected function definition() {
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated"); $labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");

$mform =& $this->_form; $mform =& $this->_form;
$mform->setDisableShortforms(); $mform->setDisableShortforms();


Expand All @@ -124,7 +123,7 @@ protected function definition() {
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared( $html2 = $this->qtypeobj->print_dataset_definitions_category_shared(
$this->question, $this->datasetdefs); $this->question, $this->datasetdefs);
$mform->addElement('static', 'listcategory', $label, $html2); $mform->addElement('static', 'listcategory', $label, $html2);
//---------------------------------------------------------------------- // ...----------------------------------------------------------------------.
$mform->addElement('submit', 'updatedatasets', $mform->addElement('submit', 'updatedatasets',
get_string('updatedatasetparam', 'qtype_calculated')); get_string('updatedatasetparam', 'qtype_calculated'));
$mform->registerNoSubmitButton('updatedatasets'); $mform->registerNoSubmitButton('updatedatasets');
Expand Down Expand Up @@ -269,7 +268,7 @@ protected function definition() {
$mform->addGroup($addgrp1, 'addgrp1', '', ' ', false); $mform->addGroup($addgrp1, 'addgrp1', '', ' ', false);
$mform->registerNoSubmitButton('showbutton'); $mform->registerNoSubmitButton('showbutton');
$mform->closeHeaderBefore('addgrp1'); $mform->closeHeaderBefore('addgrp1');
//---------------------------------------------------------------------- // ...----------------------------------------------------------------------.
$j = $this->noofitems * count($this->datasetdefs); $j = $this->noofitems * count($this->datasetdefs);
$k = optional_param('selectshow', 1, PARAM_INT); $k = optional_param('selectshow', 1, PARAM_INT);
for ($i = $this->noofitems; $i >= 1; $i--) { for ($i = $this->noofitems; $i >= 1; $i--) {
Expand Down Expand Up @@ -301,9 +300,9 @@ protected function definition() {
$j--; $j--;
} }
if ('' != $strquestionlabel && ($k > 0 )) { if ('' != $strquestionlabel && ($k > 0 )) {
//|| $this->outsidelimit || !empty($this->numbererrors ) // ... $this->outsidelimit || !empty($this->numbererrors ).
$repeated[] = $mform->addElement('static', "answercomment[$i]", $strquestionlabel); $repeated[] = $mform->addElement('static', "answercomment[$i]", $strquestionlabel);
// decode equations in question text // Decode equations in question text.
$qtext = $this->qtypeobj->substitute_variables( $qtext = $this->qtypeobj->substitute_variables(
$this->question->questiontext, $data); $this->question->questiontext, $data);
$textequations = $this->qtypeobj->find_math_equations($qtext); $textequations = $this->qtypeobj->find_math_equations($qtext);
Expand All @@ -326,8 +325,8 @@ protected function definition() {


} }
$mform->addElement('static', 'outsidelimit', '', ''); $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) ) { if (!($this->noofitems==0) ) {
$mform->addElement('submit', 'savechanges', get_string('savechanges')); $mform->addElement('submit', 'savechanges', get_string('savechanges'));
$mform->closeHeaderBefore('savechanges'); $mform->closeHeaderBefore('savechanges');
Expand Down Expand Up @@ -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); $j = $this->noofitems * count($this->datasetdefs);
for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) { for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) {
$data = array(); $data = array();
Expand Down Expand Up @@ -416,8 +415,8 @@ public function set_data($question) {
$formdata['selectdelete'] = '1'; $formdata['selectdelete'] = '1';
$formdata['selectadd'] = '1'; $formdata['selectadd'] = '1';
$j = $this->noofitems * count($this->datasetdefs)+1; $j = $this->noofitems * count($this->datasetdefs)+1;
$data = array(); // data for comment_on_datasetitems later $data = array(); // Data for comment_on_datasetitems later.
//dataset generation dafaults // Dataset generation defaults.
if ($this->qtypeobj->supports_dataset_item_generation()) { if ($this->qtypeobj->supports_dataset_item_generation()) {
$itemnumber = $this->noofitems+1; $itemnumber = $this->noofitems+1;
foreach ($this->datasetdefs as $defid => $datasetdef) { foreach ($this->datasetdefs as $defid => $datasetdef) {
Expand All @@ -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; $j = $this->noofitems * count($this->datasetdefs) + 1;
if (!$this->regenerate && !optional_param('updatedatasets', false, PARAM_BOOL) && if (!$this->regenerate && !optional_param('updatedatasets', false, PARAM_BOOL) &&
!optional_param('updateanswers', false, PARAM_BOOL)) { !optional_param('updateanswers', false, PARAM_BOOL)) {
Expand Down
9 changes: 3 additions & 6 deletions question/type/calculated/db/upgrade.php
Expand Up @@ -36,17 +36,14 @@ function xmldb_qtype_calculated_upgrade($oldversion) {


$dbman = $DB->get_manager(); $dbman = $DB->get_manager();



// Moodle v2.2.0 release upgrade line // 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 // 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 // Moodle v2.4.0 release upgrade line
// Put any upgrade step following this // Put any upgrade step following this.



return true; return true;
} }
Expand Down
6 changes: 3 additions & 3 deletions question/type/calculated/db/upgradelib.php
Expand Up @@ -83,7 +83,7 @@ public function right_answer() {
protected function parse_response($state) { protected function parse_response($state) {
if (strpos($state->answer, '-') < 7) { if (strpos($state->answer, '-') < 7) {
// Broken state, skip it. // 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."); question {$state->question}. (It did not specify a dataset.");
} }
list($datasetbit, $realanswer) = explode('-', $state->answer, 2); list($datasetbit, $realanswer) = explode('-', $state->answer, 2);
Expand All @@ -92,7 +92,7 @@ protected function parse_response($state) {
if (is_null($this->selecteditem)) { if (is_null($this->selecteditem)) {
$this->load_dataset($selecteditem); $this->load_dataset($selecteditem);
} else if ($this->selecteditem != $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 {$state->question} used different dataset items. Ignoring the change
in state {$state->id} and coninuting to use item {$this->selecteditem}."); in state {$state->id} and coninuting to use item {$this->selecteditem}.");
} }
Expand Down Expand Up @@ -248,7 +248,7 @@ public function calculate($expression) {
* @return float the computed result. * @return float the computed result.
*/ */
protected function calculate_raw($expression) { 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 . ';')) { if (!@eval('return true; $result = ' . $expression . ';')) {
return '[Invalid expression ' . $expression . ']'; return '[Invalid expression ' . $expression . ']';
} }
Expand Down
2 changes: 1 addition & 1 deletion question/type/calculated/edit_calculated_form.php
Expand Up @@ -146,7 +146,7 @@ protected function definition_inner($mform) {
$mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $mform->createElement('submit', $addfieldsname, $addstring), 'listcategory');
$mform->registerNoSubmitButton('createoptionbutton'); $mform->registerNoSubmitButton('createoptionbutton');


// Editing as regular. // Editing as regular question.
$mform->setType('single', PARAM_INT); $mform->setType('single', PARAM_INT);


$mform->addElement('hidden', 'shuffleanswers', '1'); $mform->addElement('hidden', 'shuffleanswers', '1');
Expand Down

0 comments on commit 3d9645a

Please sign in to comment.