MDL-46212 questions: add {} whenver vars are put into "" strings
authorTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 30 Jun 2014 18:09:54 +0000 (19:09 +0100)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 3 Jul 2014 13:02:39 +0000 (14:02 +0100)
Having had one subtle bug cased be this, I decided to do a search and
fix all of these.

40 files changed:
question/category_class.php
question/classes/bank/view.php
question/editlib.php
question/engine/bank.php
question/engine/datalib.php
question/engine/lib.php
question/engine/questionattempt.php
question/engine/questionusage.php
question/engine/tests/helpers.php
question/export.php
question/export_form.php
question/format.php
question/format/blackboard_six/formatbase.php
question/format/gift/format.php
question/format/webct/format.php
question/format/xhtml/format.php
question/format/xml/format.php
question/import_form.php
question/previewlib.php
question/question.php
question/tests/behat/behat_question.php
question/type/calculated/datasetdefinitions_form.php
question/type/calculated/datasetitems_form.php
question/type/calculated/edit_calculated_form.php
question/type/calculated/question.php
question/type/calculated/questiontype.php
question/type/calculatedmulti/edit_calculatedmulti_form.php
question/type/calculatedsimple/edit_calculatedsimple_form.php
question/type/calculatedsimple/questiontype.php
question/type/edit_question_form.php
question/type/essay/db/upgrade.php
question/type/match/question.php
question/type/multianswer/edit_multianswer_form.php
question/type/multianswer/questiontype.php
question/type/numerical/edit_numerical_form.php
question/type/numerical/questiontype.php
question/type/questiontypebase.php
question/type/random/questiontype.php
question/type/randomsamatch/questiontype.php
question/type/shortanswer/edit_shortanswer_form.php

index cd331b8..4684415 100644 (file)
@@ -290,7 +290,7 @@ class question_category_object {
         /// Interface for editing existing categories
         if ($category = $DB->get_record("question_categories", array("id" => $categoryid))) {
 
-            $category->parent = "$category->parent,$category->contextid";
+            $category->parent = "{$category->parent},{$category->contextid}";
             $category->submitbutton = get_string('savechanges');
             $category->categoryheader = $this->str->edit;
             $this->catform->set_data($category);
index d4018ac..579bd31 100644 (file)
@@ -724,7 +724,7 @@ class view {
                                               array('qperpage' => DEFAULT_QUESTIONS_PER_PAGE)));
                 $showall = '<a href="'.$url.'">'.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).'</a>';
             }
-            echo "<div class='paging'>$showall</div>";
+            echo "<div class='paging'>{$showall}</div>";
         }
         echo '</div>';
 
@@ -743,13 +743,13 @@ class view {
 
             if ($canmoveall && count($addcontexts)) {
                 echo '<input type="submit" name="move" value="'.get_string('moveto', 'question')."\" />\n";
-                question_category_select_menu($addcontexts, false, 0, "$category->id,$category->contextid");
+                question_category_select_menu($addcontexts, false, 0, "{$category->id},{$category->contextid}");
             }
 
             if (function_exists('module_specific_controls') && $canuseall) {
                 $modulespecific = module_specific_controls($totalnumber, $recurse, $category, $this->cm->id, $cmoptions);
                 if (!empty($modulespecific)) {
-                    echo "<hr />$modulespecific";
+                    echo "<hr />{$modulespecific}";
                 }
             }
         }
@@ -835,13 +835,13 @@ class view {
                         SELECT q.*, c.contextid
                         FROM {question} q
                         JOIN {question_categories} c ON c.id = q.category
-                        WHERE q.id $usql", $params);
+                        WHERE q.id {$usql}", $params);
                 foreach ($questions as $question) {
                     question_require_capability_on($question, 'move');
                 }
                 question_move_questions_to_category($questionids, $tocategory->id);
                 redirect($this->baseurl->out(false,
-                        array('category' => "$tocategoryid,$contextid")));
+                        array('category' => "{$tocategoryid},{$contextid}")));
             }
         }
 
index 2739700..cb7348e 100644 (file)
@@ -75,7 +75,7 @@ function get_questions_category( $category, $noparent=false, $recurse=true, $exp
 
     // Get the list of questions for the category
     list($usql, $params) = $DB->get_in_or_equal($categorylist);
-    $questions = $DB->get_records_select('question', "category $usql $npsql", $params, 'qtype, name');
+    $questions = $DB->get_records_select('question', "category {$usql} {$npsql}", $params, 'qtype, name');
 
     // Iterate through questions, getting stuff we need
     $qresults = array();
@@ -346,7 +346,7 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
 
     $contextlistarr = array();
     foreach ($contexts->having_one_edit_tab_cap($edittab) as $context){
-        $contextlistarr[] = "'$context->id'";
+        $contextlistarr[] = "'{$context->id}'";
     }
     $contextlist = join($contextlistarr, ' ,');
     if (!empty($pagevars['cat'])){
@@ -357,7 +357,7 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
         }
     } else {
         $category = $defaultcategory;
-        $pagevars['cat'] = "$category->id,$category->contextid";
+        $pagevars['cat'] = "{$category->id},{$category->contextid}";
     }
 
     // Display options.
index 5950af6..11e3ddc 100644 (file)
@@ -100,7 +100,7 @@ abstract class question_bank {
         include_once($file);
         $class = 'qtype_' . $qtypename;
         if (!class_exists($class)) {
-            throw new coding_exception("Class $class must be defined in $file");
+            throw new coding_exception("Class {$class} must be defined in {$file}.");
         }
         self::$questiontypes[$qtypename] = new $class();
         return self::$questiontypes[$qtypename];
@@ -381,8 +381,8 @@ abstract class question_bank {
         // The the positive grades in descending order.
         foreach ($rawfractions as $fraction) {
             $percentage = format_float(100 * $fraction, 5, true, true) . '%';
-            self::$fractionoptions["$fraction"] = $percentage;
-            self::$fractionoptionsfull["$fraction"] = $percentage;
+            self::$fractionoptions["{$fraction}"] = $percentage;
+            self::$fractionoptionsfull["{$fraction}"] = $percentage;
         }
 
         // The the negative grades in descending order.
@@ -499,10 +499,10 @@ class question_finder implements cache_data_source {
         }
 
         return $DB->get_records_select_menu('question',
-                "category $qcsql
+                "category {$qcsql}
                  AND parent = 0
                  AND hidden = 0
-                 $extraconditions", $qcparams + $extraparams, '', 'id,id AS id2');
+                 {$extraconditions}", $qcparams + $extraparams, '', 'id,id AS id2');
     }
 
     /* See cache_data_source::load_for_cache. */
index 7b0685c..daaa0f6 100644 (file)
@@ -651,7 +651,7 @@ $sqlorderby
         if (!empty($slots)) {
             list($slottest, $slotsparams) = $this->db->get_in_or_equal(
                     $slots, SQL_PARAMS_NAMED, 'slot');
-            $slotwhere = " AND qa.slot $slottest";
+            $slotwhere = " AND qa.slot {$slottest}";
         } else {
             $slotwhere = '';
             $slotsparams = array();
@@ -879,9 +879,9 @@ ORDER BY
         $this->delete_response_files($context->id, $test, $params);
 
         $this->db->delete_records_select('question_attempt_step_data',
-                "attemptstepid $test", $params);
+                "attemptstepid {$test}", $params);
         $this->db->delete_records_select('question_attempt_steps',
-                "id $test", $params);
+                "id {$test}", $params);
     }
 
     /**
@@ -942,7 +942,7 @@ ORDER BY
     protected function full_states_to_summary_state_sql() {
         $sql = '';
         foreach (question_state::get_all() as $state) {
-            $sql .= "WHEN '$state' THEN '{$state->get_summary_state()}'\n";
+            $sql .= "WHEN '{$state}' THEN '{$state->get_summary_state()}'\n";
         }
         return $sql;
     }
@@ -1043,7 +1043,7 @@ ORDER BY
                   JOIN {question_attempt_steps} {$alias}qas ON {$alias}qas.questionattemptid = {$alias}qa.id
                             AND {$alias}qas.sequencenumber = {$this->latest_step_for_qa_subquery($alias . 'qa.id')}
                  WHERE {$qubaids->where()}
-            ) $alias", $qubaids->from_where_params());
+            ) {$alias}", $qubaids->from_where_params());
     }
 
     protected function latest_step_for_qa_subquery($questionattemptid = 'qa.id') {
@@ -1658,7 +1658,7 @@ class qubaid_join extends qubaid_condition {
     }
 
     public function from_question_attempts($alias) {
-        return "$this->from
+        return "{$this->from}
                 JOIN {question_attempts} {$alias} ON " .
                         "{$alias}.questionusageid = $this->usageidcolumn";
     }
@@ -1672,7 +1672,7 @@ class qubaid_join extends qubaid_condition {
     }
 
     public function usage_id_in() {
-        return "IN (SELECT $this->usageidcolumn FROM $this->from WHERE $this->where)";
+        return "IN (SELECT {$this->usageidcolumn} FROM {$this->from} WHERE {$this->where})";
     }
 
     public function usage_id_in_params() {
index c96659b..ef06426 100644 (file)
@@ -656,7 +656,7 @@ abstract class question_flags {
         $qid = $qa->get_question()->id;
         $slot = $qa->get_slot();
         $checksum = self::get_toggle_checksum($qubaid, $qid, $qaid, $slot);
-        return "qaid=$qaid&qubaid=$qubaid&qid=$qid&slot=$slot&checksum=$checksum&sesskey=" .
+        return "qaid={$qaid}&qubaid={$qubaid}&qid={$qid}&slot={$slot}&checksum={$checksum}&sesskey=" .
                 sesskey() . '&newstate=';
     }
 
@@ -735,7 +735,7 @@ class question_out_of_sequence_exception extends moodle_exception {
             $postdata = data_submitted();
         }
         parent::__construct('submissionoutofsequence', 'question', '', null,
-                "QUBAid: $qubaid, slot: $slot, post data: " . print_r($postdata, true));
+                "QUBAid: {$qubaid}, slot: {$slot}, post data: " . print_r($postdata, true));
     }
 }
 
index bce0465..3d1c55b 100644 (file)
@@ -1351,7 +1351,7 @@ class question_attempt {
         while ($record->questionattemptid != $questionattemptid) {
             $record = $records->next();
             if (!$records->valid()) {
-                throw new coding_exception("Question attempt $questionattemptid not found in the database.");
+                throw new coding_exception("Question attempt {$questionattemptid} not found in the database.");
             }
             $record = $records->current();
         }
index 7a4d5ed..20d0a6a 100644 (file)
@@ -837,7 +837,7 @@ class question_usage_by_activity {
         while ($record->qubaid != $qubaid) {
             $records->next();
             if (!$records->valid()) {
-                throw new coding_exception("Question usage $qubaid not found in the database.");
+                throw new coding_exception("Question usage {$qubaid} not found in the database.");
             }
             $record = $records->current();
         }
index fc97d58..5516338 100644 (file)
@@ -545,10 +545,10 @@ abstract class question_testcase extends advanced_testcase {
             $compare = (array)$compare;
             foreach ($expect as $k=>$v) {
                 if (!array_key_exists($k, $compare)) {
-                    $this->fail("Property $k does not exist");
+                    $this->fail("Property {$k} does not exist");
                 }
                 if ($v != $compare[$k]) {
-                    $this->fail("Property $k is different");
+                    $this->fail("Property {$k} is different");
                 }
             }
             $this->assertTrue(true);
index 8f2396e..892cf75 100644 (file)
@@ -50,7 +50,7 @@ $export_form = new question_export_form($thispageurl,
 
 if ($from_form = $export_form->get_data()) {
     $thiscontext = $contexts->lowest();
-    if (!is_readable("format/$from_form->format/format.php")) {
+    if (!is_readable("format/{$from_form->format}/format.php")) {
         print_error('unknowformat', '', '', $from_form->format);
     }
     $withcategories = 'nocategories';
index 547abf2..006e334 100644 (file)
@@ -51,10 +51,10 @@ class question_export_form extends moodleform {
         foreach ($fileformatnames as $shortname => $fileformatname) {
             $currentgrp1 = array();
             $currentgrp1[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
-            $mform->addGroup($currentgrp1, "formathelp[$i]", '', array('<br />'), false);
+            $mform->addGroup($currentgrp1, "formathelp[{$i}]", '', array('<br />'), false);
 
             if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
-                $mform->addHelpButton("formathelp[$i]", 'pluginname', 'qformat_' . $shortname);
+                $mform->addHelpButton("formathelp[{$i}]", 'pluginname', 'qformat_' . $shortname);
             }
 
             $i++ ;
index 51b4672..e284d8c 100644 (file)
@@ -222,12 +222,12 @@ class qformat_default {
         $importerrorquestion = get_string('importerrorquestion', 'question');
 
         echo "<div class=\"importerror\">\n";
-        echo "<strong>$importerrorquestion $questionname</strong>";
+        echo "<strong>{$importerrorquestion} {$questionname}</strong>";
         if (!empty($text)) {
             $text = s($text);
-            echo "<blockquote>$text</blockquote>\n";
+            echo "<blockquote>{$text}</blockquote>\n";
         }
-        echo "<strong>$message</strong>\n";
+        echo "<strong>{$message}</strong>\n";
         echo "</div>";
 
          $this->importerrors++;
@@ -247,7 +247,7 @@ class qformat_default {
 
         // work out what format we are using
         $formatname = substr(get_class($this), strlen('qformat_'));
-        $methodname = "import_from_$formatname";
+        $methodname = "import_from_{$formatname}";
 
         //first try importing using a hint from format
         if (!empty($qtypehint)) {
@@ -377,7 +377,7 @@ class qformat_default {
 
             $count++;
 
-            echo "<hr /><p><b>$count</b>. ".$this->format_question_text($question)."</p>";
+            echo "<hr /><p><b>{$count}</b>. ".$this->format_question_text($question)."</p>";
 
             $question->category = $this->category->id;
             $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
@@ -691,7 +691,7 @@ class qformat_default {
     protected function readquestion($lines) {
 
         $formatnotimplemented = get_string('formatnotimplemented', 'question');
-        echo "<p>$formatnotimplemented</p>";
+        echo "<p>{$formatnotimplemented}</p>";
 
         return null;
     }
@@ -719,7 +719,7 @@ class qformat_default {
     protected function try_exporting_using_qtypes($name, $question, $extra=null) {
         // work out the name of format in use
         $formatname = substr(get_class($this), strlen('qformat_'));
-        $methodname = "export_to_$formatname";
+        $methodname = "export_to_{$formatname}";
 
         $qtype = question_bank::get_qtype($name, false);
         if (method_exists($qtype, $methodname)) {
@@ -819,7 +819,7 @@ class qformat_default {
 
         // continue path for following error checks
         $course = $this->course;
-        $continuepath = "$CFG->wwwroot/question/export.php?courseid=$course->id";
+        $continuepath = "{$CFG->wwwroot}/question/export.php?courseid={$course->id}";
 
         // did we actually process anything
         if ($count==0) {
@@ -924,7 +924,7 @@ class qformat_default {
     protected function writequestion($question) {
         // if not overidden, then this is an error.
         $formatnotimplemented = get_string('formatnotimplemented', 'question');
-        echo "<p>$formatnotimplemented</p>";
+        echo "<p>{$formatnotimplemented}</p>";
         return null;
     }
 
index 75f6368..5033827 100644 (file)
@@ -134,7 +134,7 @@ class qformat_blackboard_six_base extends qformat_based_on_xml {
                 $dirpath = dirname($path);
                 $filename = basename($path);
                 $newfilename = $this->store_file_for_text_field($data, $this->filebase, $dirpath, $filename);
-                $text = preg_replace("|$path|", "@@PLUGINFILE@@/" . $newfilename, $text);
+                $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text);
                 $filepaths[] = $path;
             }
 
index 156d4a8..5b3ca64 100644 (file)
@@ -416,7 +416,7 @@ class qformat_gift extends qformat_default {
                 list($answer, $wrongfeedback, $rightfeedback) =
                         $this->split_truefalse_comment($answertext, $question->questiontextformat);
 
-                if ($answer['text'] == "T" OR $answer['text'] == "TRUE") {
+                if ($answer['text'] == "T" || $answer['text'] == "TRUE") {
                     $question->correctanswer = 1;
                     $question->feedbacktrue = $rightfeedback;
                     $question->feedbackfalse = $wrongfeedback;
@@ -634,7 +634,7 @@ class qformat_gift extends qformat_default {
         global $OUTPUT;
 
         // Start with a comment.
-        $expout = "// question: $question->id  name: $question->name\n";
+        $expout = "// question: {$question->id}  name: {$question->name}\n";
 
         // Output depends on question type.
         switch($question->qtype) {
index 4e184bc..57c3175 100644 (file)
@@ -150,7 +150,7 @@ function qformat_webct_convert_formula($formula) {
         }
 
         // Replace it!
-        $formula = "$splits[0]pow($base,$exp)$splits[1]";
+        $formula = "{$splits[0]}pow({$base},{$exp}){$splits[1]}";
     }
 
     // Nothing more is known to need to be converted.
@@ -239,7 +239,7 @@ class qformat_webct extends qformat_default {
                 $dirpath = dirname($path);
                 $filename = basename($path);
                 $newfilename = $this->store_file_for_text_field($data, $this->tempdir, $dirpath, $filename);
-                $text = preg_replace("|$path|", "@@PLUGINFILE@@/" . $newfilename, $text);
+                $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text);
                 $filepaths[] = $path;
             }
 
@@ -497,7 +497,7 @@ class qformat_webct extends qformat_default {
                             case 'shortanswer':
                                 if ($maxfraction != 1) {
                                     $maxfraction = $maxfraction * 100;
-                                    $errors[] = "'$question->name': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
+                                    $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
                                             .' '.get_string('fractionsnomax', 'question', $maxfraction);
                                     $questionok = false;
                                 }
@@ -509,7 +509,7 @@ class qformat_webct extends qformat_default {
                                 if ($question->single) {
                                     if ($maxfraction != 1) {
                                         $maxfraction = $maxfraction * 100;
-                                        $errors[] = "'$question->name': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
+                                        $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
                                                 .' '.get_string('fractionsnomax', 'question', $maxfraction);
                                         $questionok = false;
                                     }
@@ -517,7 +517,7 @@ class qformat_webct extends qformat_default {
                                     $totalfraction = round($totalfraction, 2);
                                     if ($totalfraction != 1) {
                                         $totalfraction = $totalfraction * 100;
-                                        $errors[] = "'$question->name': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
+                                        $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter)
                                                 .' '.get_string('fractionsaddwrong', 'question', $totalfraction);
                                         $questionok = false;
                                     }
@@ -527,7 +527,7 @@ class qformat_webct extends qformat_default {
                             case 'calculated':
                                 foreach ($question->answers as $answer) {
                                     if ($formulaerror = qtype_calculated_find_formula_errors($answer)) {
-                                        $warnings[] = "'$question->name': ". $formulaerror;
+                                        $warnings[] = "'{$question->name}': ". $formulaerror;
                                         $questionok = false;
                                     }
                                 }
@@ -687,7 +687,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
             if (isset($question->qtype ) && 'calculated' == $question->qtype && preg_match(
-                    "~^:([[:lower:]].*|::.*)-(MIN|MAX|DEC|VAL([0-9]+))::?:?($webctnumberregex)~", $line, $webctoptions)) {
+                    "~^:([[:lower:]].*|::.*)-(MIN|MAX|DEC|VAL([0-9]+))::?:?({$webctnumberregex})~", $line, $webctoptions)) {
                 $datasetname = preg_replace('/^::/', '', $webctoptions[1]);
                 $datasetvalue = qformat_webct_convert_formula($webctoptions[4]);
                 switch ($webctoptions[2]) {
@@ -803,7 +803,7 @@ class qformat_webct extends qformat_default {
             }
 
             if (isset($question->qtype )&& 'calculated' == $question->qtype
-                    && preg_match("~^:TOL:($webctnumberregex)~i", $line, $webctoptions)) {
+                    && preg_match("~^:TOL:({$webctnumberregex})~i", $line, $webctoptions)) {
                 // We can but hope that this always appear before the TOL property.
                 $question->tolerance[$currentchoice] =
                         qformat_webct_convert_formula($webctoptions[1]);
@@ -858,7 +858,7 @@ class qformat_webct extends qformat_default {
         if (count($errors) > 0) {
             echo '<p>'.get_string('errorsdetected', 'qformat_webct', count($errors)).'</p><ul>';
             foreach ($errors as $error) {
-                echo "<li>$error</li>";
+                echo "<li>{$error}</li>";
             }
             echo '</ul>';
             unset($questions);     // No questions imported.
@@ -867,7 +867,7 @@ class qformat_webct extends qformat_default {
         if (count($warnings) > 0) {
             echo '<p>'.get_string('warningsdetected', 'qformat_webct', count($warnings)).'</p><ul>';
             foreach ($warnings as $warning) {
-                echo "<li>$warning</li>";
+                echo "<li>{$warning}</li>";
             }
             echo '</ul>';
         }
index 0c62588..bb54d80 100644 (file)
@@ -59,11 +59,11 @@ class qformat_xhtml extends qformat_default {
         $id = $question->id;
 
         // Add comment and div tags.
-        $expout .= "<!-- question: $id  name: $question->name -->\n";
+        $expout .= "<!-- question: {$id}  name: {$question->name} -->\n";
         $expout .= "<div class=\"question\">\n";
 
         // Add header.
-        $expout .= "<h3>$question->name</h3>\n";
+        $expout .= "<h3>{$question->name}</h3>\n";
 
         // Format and add the question text.
         $text = question_rewrite_question_preview_urls($question->questiontext, $question->id,
@@ -78,8 +78,8 @@ class qformat_xhtml extends qformat_default {
                 $sttrue = get_string('true', 'qtype_truefalse');
                 $stfalse = get_string('false', 'qtype_truefalse');
                 $expout .= "<ul class=\"truefalse\">\n";
-                $expout .= "  <li><input name=\"quest_$id\" type=\"radio\" value=\"$sttrue\" />$sttrue</li>\n";
-                $expout .= "  <li><input name=\"quest_$id\" type=\"radio\" value=\"$stfalse\" />$stfalse</li>\n";
+                $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$sttrue}\" />{$sttrue}</li>\n";
+                $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$stfalse}\" />{$stfalse}</li>\n";
                 $expout .= "</ul>\n";
                 break;
             case 'multichoice':
@@ -87,11 +87,11 @@ class qformat_xhtml extends qformat_default {
                 foreach ($question->options->answers as $answer) {
                     $answertext = $this->repchar( $answer->answer );
                     if ($question->options->single) {
-                        $expout .= "  <li><input name=\"quest_$id\" type=\"radio\" value=\""
-                                . s($answertext) . "\" />$answertext</li>\n";
+                        $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\""
+                                . s($answertext) . "\" />{$answertext}</li>\n";
                     } else {
-                        $expout .= "  <li><input name=\"quest_$id\" type=\"checkbox\" value=\""
-                                . s($answertext) . "\" />$answertext</li>\n";
+                        $expout .= "  <li><input name=\"quest_{$id}\" type=\"checkbox\" value=\""
+                                . s($answertext) . "\" />{$answertext}</li>\n";
                     }
                 }
                 $expout .= "</ul>\n";
@@ -100,7 +100,7 @@ class qformat_xhtml extends qformat_default {
                 $expout .= html_writer::start_tag('ul', array('class' => 'shortanswer'));
                 $expout .= html_writer::start_tag('li');
                 $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide'));
-                $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text'));
+                $expout .= html_writer::empty_tag('input', array('id' => "quest_{$id}", 'name' => "quest_{$id}", 'type' => 'text'));
                 $expout .= html_writer::end_tag('li');
                 $expout .= html_writer::end_tag('ul');
                 break;
@@ -108,7 +108,7 @@ class qformat_xhtml extends qformat_default {
                 $expout .= html_writer::start_tag('ul', array('class' => 'numerical'));
                 $expout .= html_writer::start_tag('li');
                 $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide'));
-                $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text'));
+                $expout .= html_writer::empty_tag('input', array('id' => "quest_{$id}", 'name' => "quest_{$id}", 'type' => 'text'));
                 $expout .= html_writer::end_tag('li');
                 $expout .= html_writer::end_tag('ul');
                 break;
@@ -149,7 +149,7 @@ class qformat_xhtml extends qformat_default {
                 break;
             case 'multianswer':
             default:
-                $expout .= "<!-- export of $question->qtype type is not supported  -->\n";
+                $expout .= "<!-- export of {$question->qtype} type is not supported  -->\n";
         }
         // Close off div.
         $expout .= "</div>\n\n\n";
@@ -163,7 +163,7 @@ class qformat_xhtml extends qformat_default {
         global $CFG;
 
         // Get css bit.
-        $csslines = file( "$CFG->dirroot/question/format/xhtml/xhtml.css" );
+        $csslines = file( "{$CFG->dirroot}/question/format/xhtml/xhtml.css" );
         $css = implode( ' ', $csslines );
 
         $xp =  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
index 304d379..3fc9b13 100644 (file)
@@ -1072,9 +1072,9 @@ class qformat_xml extends qformat_default {
         $raw = $this->xml_escape($raw);
 
         if ($short) {
-            $xml = "$indent<text>$raw</text>\n";
+            $xml = "{$indent}<text>{$raw}</text>\n";
         } else {
-            $xml = "$indent<text>\n$raw\n$indent</text>\n";
+            $xml = "{$indent}<text>\n{$raw}\n{$indent}</text>\n";
         }
 
         return $xml;
@@ -1137,7 +1137,7 @@ class qformat_xml extends qformat_default {
         $expout = '';
 
         // Add a comment linking this to the original question id.
-        $expout .= "<!-- question: $question->id  -->\n";
+        $expout .= "<!-- question: {$question->id}  -->\n";
 
         // Check question type.
         $questiontype = $this->get_qtype($question->qtype);
@@ -1147,7 +1147,7 @@ class qformat_xml extends qformat_default {
             $categorypath = $this->writetext($question->category);
             $expout .= "  <question type=\"category\">\n";
             $expout .= "    <category>\n";
-            $expout .= "        $categorypath\n";
+            $expout .= "        {$categorypath}\n";
             $expout .= "    </category>\n";
             $expout .= "  </question>\n";
             return $expout;
@@ -1155,7 +1155,7 @@ class qformat_xml extends qformat_default {
 
         // Now we know we are are handing a real question.
         // Output the generic information.
-        $expout .= "  <question type=\"$questiontype\">\n";
+        $expout .= "  <question type=\"{$questiontype}\">\n";
         $expout .= "    <name>\n";
         $expout .= $this->writetext($question->name, 3);
         $expout .= "    </name>\n";
@@ -1209,7 +1209,7 @@ class qformat_xml extends qformat_default {
             case 'numerical':
                 foreach ($question->options->answers as $answer) {
                     $expout .= $this->write_answer($answer,
-                            "      <tolerance>$answer->tolerance</tolerance>\n");
+                            "      <tolerance>{$answer->tolerance}</tolerance>\n");
                 }
 
                 $units = $question->options->units;
@@ -1333,7 +1333,7 @@ class qformat_xml extends qformat_default {
 
                 foreach ($question->options->answers as $answer) {
                     $percent = 100 * $answer->fraction;
-                    $expout .= "<answer fraction=\"$percent\">\n";
+                    $expout .= "<answer fraction=\"{$percent}\">\n";
                     // The "<text/>" tags are an added feature, old files won't have them.
                     $expout .= "    <text>{$answer->answer}</text>\n";
                     $expout .= "    <tolerance>{$answer->tolerance}</tolerance>\n";
@@ -1412,7 +1412,7 @@ class qformat_xml extends qformat_default {
                                 "</maximum>\n";
                         $expout .= "    <decimals>" . $this->writetext($def->decimals) .
                                 "</decimals>\n";
-                        $expout .= "    <itemcount>$def->itemcount</itemcount>\n";
+                        $expout .= "    <itemcount>{$def->itemcount}</itemcount>\n";
                         if ($def->itemcount > 0) {
                             $expout .= "    <dataset_items>\n";
                             foreach ($def->items as $item) {
@@ -1479,7 +1479,7 @@ class qformat_xml extends qformat_default {
     public function write_answer($answer, $extra = '') {
         $percent = $answer->fraction * 100;
         $output = '';
-        $output .= "    <answer fraction=\"$percent\" {$this->format($answer->answerformat)}>\n";
+        $output .= "    <answer fraction=\"{$percent}\" {$this->format($answer->answerformat)}>\n";
         $output .= $this->writetext($answer->answer, 3);
         $output .= $this->write_files($answer->answerfiles);
         $output .= "      <feedback {$this->format($answer->feedbackformat)}>\n";
index 7112db5..323aea7 100644 (file)
@@ -53,10 +53,10 @@ class question_import_form extends moodleform {
         foreach ($fileformatnames as $shortname => $fileformatname) {
             $currentgrp1 = array();
             $currentgrp1[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
-            $mform->addGroup($currentgrp1, "formathelp[$i]", '', array('<br />'), false);
+            $mform->addGroup($currentgrp1, "formathelp[{$i}]", '', array('<br />'), false);
 
             if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
-                $mform->addHelpButton("formathelp[$i]", 'pluginname', 'qformat_' . $shortname);
+                $mform->addHelpButton("formathelp[{$i}]", 'pluginname', 'qformat_' . $shortname);
             }
 
             $i++ ;
index c4aa54f..00c8d23 100644 (file)
@@ -259,7 +259,7 @@ function question_preview_question_pluginfile($course, $context, $component,
 
     $fs = get_file_storage();
     $relativepath = implode('/', $args);
-    $fullpath = "/$context->id/$component/$filearea/$relativepath";
+    $fullpath = "/{$context->id}/{$component}/{$filearea}/{$relativepath}";
     if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
         send_file_not_found();
     }
index 45cf3e6..a11f971 100644 (file)
@@ -188,7 +188,7 @@ if ($wizardnow !== '') {
     $mform = $qtypeobj->create_editing_form('question.php', $question, $category, $contexts, $formeditable);
 }
 $toform = fullclone($question); // send the question object and a few more parameters to the form
-$toform->category = "$category->id,$category->contextid";
+$toform->category = "{$category->id},{$category->contextid}";
 $toform->scrollpos = $scrollpos;
 if ($formeditable && $id){
     $toform->categorymoveto = $toform->category;
@@ -317,7 +317,7 @@ if ($mform->is_cancelled()) {
         $streditingmodule = get_string('editinga', 'moodle', $strmodule);
         $PAGE->navbar->add(get_string('modulenameplural', $cm->modname), new moodle_url('/mod/'.$cm->modname.'/index.php', array('id'=>$cm->course)));
         $PAGE->navbar->add(format_string($module->name), new moodle_url('/mod/'.$cm->modname.'/view.php', array('id'=>$cm->id)));
-        if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0){
+        if (stripos($returnurl, "{$CFG->wwwroot}/mod/{$cm->modname}/view.php")!== 0){
             //don't need this link if returnurl returns to view.php
             $PAGE->navbar->add($streditingmodule, $returnurl);
         }
index 00e0e38..0214f51 100644 (file)
@@ -75,12 +75,12 @@ class behat_question extends behat_question_base {
 
         // Split in two checkings to give more feedback in case of exception.
         $exception = new ElementNotFoundException($this->getSession(), 'Question "' . $questiondescription . '" ');
-        $questionxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' qtext ')][contains(., $questiondescriptionliteral)]";
+        $questionxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' qtext ')][contains(., {$questiondescriptionliteral})]";
         $this->find('xpath', $questionxpath, $exception);
 
         $exception = new ExpectationException('Question "' . $questiondescription . '" state is not "' . $state . '"', $this->getSession());
         $xpath = $questionxpath . "/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]" .
-            "/descendant::div[@class='state'][contains(., $stateliteral)]";
+            "/descendant::div[@class='state'][contains(., {$stateliteral})]";
         $this->find('xpath', $xpath, $exception);
     }
 }
index a5fdac3..67334c3 100644 (file)
@@ -104,14 +104,14 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
                         $this->qtypeobj->dataset_options($this->question, $datasetname);
                 unset($options['0']); // Mandatory...
                 $label = get_string('wildcard', 'qtype_calculated', $datasetname);
-                $mform->addElement('select', "dataset[$key]", $label, $options);
+                $mform->addElement('select', "dataset[{$key}]", $label, $options);
                 if (isset($datadefscat[$datasetname])) {
                     $mform->addElement('static', "there is a category",
                             get_string('sharedwildcard', 'qtype_calculated', $datasetname),
                             get_string('dataitemdefined', 'qtype_calculated',
                             $datadefscat[$datasetname]));
                 }
-                $mform->setDefault("dataset[$key]", $selected);
+                $mform->setDefault("dataset[{$key}]", $selected);
                 $datasetmenus[$datasetname] = '';
                 $key++;
             }
@@ -123,7 +123,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
                 list($options, $selected) = $this->qtypeobj->dataset_options(
                         $this->question, $datasetname, false);
                 $label = get_string('wildcard', 'qtype_calculated', $datasetname);
-                $mform->addElement('select', "dataset[$key]", $label, $options);
+                $mform->addElement('select', "dataset[{$key}]", $label, $options);
                 if (isset($datadefscat[$datasetname])) {
                     $mform->addElement('static', "there is a category",
                             get_string('sharedwildcard', 'qtype_calculated', $datasetname),
@@ -131,7 +131,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
                                     $datadefscat[$datasetname]));
                 }
 
-                $mform->setDefault("dataset[$key]", $selected);
+                $mform->setDefault("dataset[{$key}]", $selected);
                 $datasetmenus[$datasetname] = '';
                 $key++;
             }
index 4fba8f3..3482894 100644 (file)
@@ -146,16 +146,16 @@ class question_dataset_dependent_items_form extends question_wizard_form {
             } else {
                 $name = get_string('wildcard', 'qtype_calculated', $datasetdef->name);
             }
-            $mform->addElement('text', "number[$j]", $name);
-            $mform->setType("number[$j]", PARAM_RAW); // This parameter will be validated in validation().
+            $mform->addElement('text', "number[{$j}]", $name);
+            $mform->setType("number[{$j}]", PARAM_RAW); // This parameter will be validated in validation().
             $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
             $idx++;
-            $mform->addElement('hidden', "definition[$j]");
-            $mform->setType("definition[$j]", PARAM_RAW);
-            $mform->addElement('hidden', "itemid[$j]");
-            $mform->setType("itemid[$j]", PARAM_RAW);
-            $mform->addElement('static', "divider[$j]", '', '<hr />');
-            $mform->setType("divider[$j]", PARAM_RAW);
+            $mform->addElement('hidden', "definition[{$j}]");
+            $mform->setType("definition[{$j}]", PARAM_RAW);
+            $mform->addElement('hidden', "itemid[{$j}]");
+            $mform->setType("itemid[{$j}]", PARAM_RAW);
+            $mform->addElement('static', "divider[{$j}]", '', '<hr />');
+            $mform->setType("divider[{$j}]", PARAM_RAW);
             $j++;
         }
 
@@ -218,14 +218,14 @@ class question_dataset_dependent_items_form extends question_wizard_form {
         $addremoveoptions = array();
         $addremoveoptions['1']='1';
         for ($i=10; $i<=100; $i+=10) {
-             $addremoveoptions["$i"]="$i";
+             $addremoveoptions["{$i}"] = "{$i}";
         }
         $showoptions = Array();
         $showoptions['1']='1';
         $showoptions['2']='2';
         $showoptions['5']='5';
         for ($i=10; $i<=100; $i+=10) {
-             $showoptions["$i"]="$i";
+             $showoptions["{$i}"] = "{$i}";
         }
         $mform->addElement('header', 'addhdr', get_string('add', 'moodle'));
         $mform->closeHeaderBefore('addhdr');
@@ -287,35 +287,35 @@ class question_dataset_dependent_items_form extends question_wizard_form {
             foreach ($this->datasetdefs as $defkey => $datasetdef) {
                 if ($k > 0) {
                     if ($datasetdef->category == 0 ) {
-                        $mform->addElement('text', "number[$j]",
+                        $mform->addElement('text', "number[{$j}]",
                                 get_string('wildcard', 'qtype_calculated', $datasetdef->name));
                     } else {
-                        $mform->addElement('text', "number[$j]", get_string(
+                        $mform->addElement('text', "number[{$j}]", get_string(
                                 'sharedwildcard', 'qtype_calculated', $datasetdef->name));
                     }
 
                 } else {
-                    $mform->addElement('hidden', "number[$j]" , '');
+                    $mform->addElement('hidden', "number[{$j}]" , '');
                 }
-                $mform->setType("number[$j]", PARAM_RAW); // This parameter will be validated in validation().
-                $mform->addElement('hidden', "itemid[$j]");
-                $mform->setType("itemid[$j]", PARAM_INT);
+                $mform->setType("number[{$j}]", PARAM_RAW); // This parameter will be validated in validation().
+                $mform->addElement('hidden', "itemid[{$j}]");
+                $mform->setType("itemid[{$j}]", PARAM_INT);
 
-                $mform->addElement('hidden', "definition[$j]");
-                $mform->setType("definition[$j]", PARAM_NOTAGS);
+                $mform->addElement('hidden', "definition[{$j}]");
+                $mform->setType("definition[{$j}]", PARAM_NOTAGS);
                 $data[$datasetdef->name] =$datasetdef->items[$i]->value;
 
                 $j--;
             }
             if ('' != $strquestionlabel && ($k > 0 )) {
                 // ... $this->outsidelimit || !empty($this->numbererrors ).
-                $repeated[] = $mform->addElement('static', "answercomment[$i]", $strquestionlabel);
+                $repeated[] = $mform->addElement('static', "answercomment[{$i}]", $strquestionlabel);
                 // Decode equations in question text.
                 $qtext = $this->qtypeobj->substitute_variables(
                         $this->question->questiontext, $data);
                 $textequations = $this->qtypeobj->find_math_equations($qtext);
                 if ($textequations != '' && count($textequations) > 0 ) {
-                    $mform->addElement('static', "divider1[$j]", '',
+                    $mform->addElement('static', "divider1[{$j}]", '',
                             'Formulas {=..} in question text');
                     foreach ($textequations as $key => $equation) {
                         if ($formulaerrors = qtype_calculated_find_formula_errors($equation)) {
@@ -324,7 +324,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
                             eval('$str = '.$equation.';');
                         }
                         $equation = shorten_text($equation, 17, true);
-                        $mform->addElement('static', "textequation", "{=$equation}", "=".$str);
+                        $mform->addElement('static', "textequation", "{={$equation}}", "=".$str);
                     }
                 }
 
@@ -408,9 +408,9 @@ class question_dataset_dependent_items_form extends question_wizard_form {
             $data = array();
             foreach ($this->datasetdefs as $defid => $datasetdef) {
                 if (isset($datasetdef->items[$itemnumber])) {
-                    $formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
-                    $formdata["definition[$j]"] = $defid;
-                    $formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
+                    $formdata["number[{$j}]"] = $datasetdef->items[$itemnumber]->value;
+                    $formdata["definition[{$j}]"] = $defid;
+                    $formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id;
                     $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
                 }
                 $j--;
@@ -438,15 +438,15 @@ class question_dataset_dependent_items_form extends question_wizard_form {
             foreach ($this->datasetdefs as $defid => $datasetdef) {
                 if (!optional_param('updatedatasets', false, PARAM_BOOL) &&
                         !optional_param('updateanswers', false, PARAM_BOOL)) {
-                    $formdata["number[$j]"] = $this->qtypeobj->generate_dataset_item(
+                    $formdata["number[{$j}]"] = $this->qtypeobj->generate_dataset_item(
                             $datasetdef->options);
                 } else {
-                    $formdata["number[$j]"] = $this->_form->getElementValue("number[$j]");
+                    $formdata["number[{$j}]"] = $this->_form->getElementValue("number[{$j}]");
                 }
-                $formdata["definition[$j]"] = $defid;
-                $formdata["itemid[$j]"] = isset($datasetdef->items[$itemnumber]) ?
+                $formdata["definition[{$j}]"] = $defid;
+                $formdata["itemid[{$j}]"] = isset($datasetdef->items[$itemnumber]) ?
                         $datasetdef->items[$itemnumber]->id : 0;
-                $data[$datasetdef->name] = $formdata["number[$j]"];
+                $data[$datasetdef->name] = $formdata["number[{$j}]"];
                 $j++;
             }
         }
@@ -459,9 +459,9 @@ class question_dataset_dependent_items_form extends question_wizard_form {
             $itemnumber = $this->noofitems + 1;
             foreach ($this->datasetdefs as $defid => $datasetdef) {
                 if (isset($datasetdef->items[$itemnumber])) {
-                    $formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
-                    $formdata["definition[$j]"] = $defid;
-                    $formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
+                    $formdata["number[{$j}]"] = $datasetdef->items[$itemnumber]->value;
+                    $formdata["definition[{$j}]"] = $defid;
+                    $formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id;
                     $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
                 }
                 $j++;
index 853030d..3113c39 100644 (file)
@@ -199,9 +199,9 @@ class qtype_calculated_edit_form extends qtype_numerical_edit_form {
         $key = 0;
         foreach ($question->options->answers as $answer) {
             // See comment in the parent method about this hack.
-            unset($this->_form->_defaultValues["tolerancetype[$key]"]);
-            unset($this->_form->_defaultValues["correctanswerlength[$key]"]);
-            unset($this->_form->_defaultValues["correctanswerformat[$key]"]);
+            unset($this->_form->_defaultValues["tolerancetype[{$key}]"]);
+            unset($this->_form->_defaultValues["correctanswerlength[{$key}]"]);
+            unset($this->_form->_defaultValues["correctanswerformat[{$key}]"]);
 
             $question->tolerancetype[$key]       = $answer->tolerancetype;
             $question->correctanswerlength[$key] = $answer->correctanswerlength;
index 71b25a6..bef1253 100644 (file)
@@ -384,8 +384,8 @@ class qtype_calculated_variable_substituter {
                     }
                 } else {
                     // Stick to plain numeric format.
-                    $answer *= "1e$p10";
-                    if (0.1 <= $answer / "1e$length") {
+                    $answer *= "1e{$p10}";
+                    if (0.1 <= $answer / "1e{$length}") {
                         $x = $sign.$answer;
                     } else {
                         // Could be an idea to add some zeros here.
@@ -492,10 +492,10 @@ class qtype_calculated_variable_substituter {
         $formula = strtolower(str_replace(' ', '', $formula));
 
         $safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
-        $operatorornumber = "[$safeoperatorchar.0-9eE]";
+        $operatorornumber = "[{$safeoperatorchar}.0-9eE]";
 
-        while (preg_match("~(^|[$safeoperatorchar,(])([a-z0-9_]*)" .
-                "\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
+        while (preg_match("~(^|[{$safeoperatorchar},(])([a-z0-9_]*)" .
+                "\\(({$operatorornumber}+(,{$operatorornumber}+((,{$operatorornumber}+)+)?)?)?\\)~",
             $formula, $regs)) {
             switch ($regs[2]) {
                 // Simple parenthesis.
@@ -558,11 +558,11 @@ class qtype_calculated_variable_substituter {
                 $formula = str_replace($regs[0], $regs[1] . '1', $formula);
             } else {
                 // The function call starts the formula.
-                $formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
+                $formula = preg_replace("~^{$regs[2]}\\([^)]*\\)~", '1', $formula);
             }
         }
 
-        if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
+        if (preg_match("~[^{$safeoperatorchar}.0-9eE]+~", $formula, $regs)) {
             return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
         } else {
             // Formula just might be valid.
index b2e3b2a..abb8a6e 100644 (file)
@@ -119,7 +119,7 @@ class qtype_calculated extends question_type {
                             $def->number_of_items = $n;
                         }
                     }
-                    $datasetdefs["1-$r->category-$r->name"] = $def;
+                    $datasetdefs["1-{$r->category}-{$r->name}"] = $def;
                 }
             }
         }
@@ -404,11 +404,11 @@ class qtype_calculated extends question_type {
         // See where we're coming from.
         switch($form->wizardpage) {
             case 'question':
-                require("$CFG->dirroot/question/type/calculated/datasetdefinitions.php");
+                require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions.php");
                 break;
             case 'datasetdefinitions':
             case 'datasetitems':
-                require("$CFG->dirroot/question/type/calculated/datasetitems.php");
+                require("{$CFG->dirroot}/question/type/calculated/datasetitems.php");
                 break;
             default:
                 print_error('invalidwizardpage', 'question');
@@ -432,15 +432,15 @@ class qtype_calculated extends question_type {
         // See where we're coming from.
         switch($wizardnow) {
             case 'datasetdefinitions':
-                require("$CFG->dirroot/question/type/calculated/datasetdefinitions_form.php");
+                require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions_form.php");
                 $mform = new question_dataset_dependent_definitions_form(
-                        "$submiturl?wizardnow=datasetdefinitions", $question);
+                        "{$submiturl}?wizardnow=datasetdefinitions", $question);
                 break;
             case 'datasetitems':
-                require("$CFG->dirroot/question/type/calculated/datasetitems_form.php");
+                require("{$CFG->dirroot}/question/type/calculated/datasetitems_form.php");
                 $regenerate = optional_param('forceregeneration', false, PARAM_BOOL);
                 $mform = new question_dataset_dependent_items_form(
-                        "$submiturl?wizardnow=datasetitems", $question, $regenerate);
+                        "{$submiturl}?wizardnow=datasetitems", $question, $regenerate);
                 break;
             default:
                 print_error('invalidwizardpage', 'question');
@@ -706,22 +706,22 @@ class qtype_calculated extends question_type {
     public function custom_generator_tools_part($mform, $idx, $j) {
 
         $minmaxgrp = array();
-        $minmaxgrp[] = $mform->createElement('text', "calcmin[$idx]",
+        $minmaxgrp[] = $mform->createElement('text', "calcmin[{$idx}]",
                 get_string('calcmin', 'qtype_calculated'));
-        $minmaxgrp[] = $mform->createElement('text', "calcmax[$idx]",
+        $minmaxgrp[] = $mform->createElement('text', "calcmax[{$idx}]",
                 get_string('calcmax', 'qtype_calculated'));
         $mform->addGroup($minmaxgrp, 'minmaxgrp',
                 get_string('minmax', 'qtype_calculated'), ' - ', false);
-        $mform->setType("calcmin[$idx]", PARAM_FLOAT);
-        $mform->setType("calcmax[$idx]", PARAM_FLOAT);
+        $mform->setType("calcmin[{$idx}]", PARAM_FLOAT);
+        $mform->setType("calcmax[{$idx}]", PARAM_FLOAT);
 
         $precisionoptions = range(0, 10);
-        $mform->addElement('select', "calclength[$idx]",
+        $mform->addElement('select', "calclength[{$idx}]",
                 get_string('calclength', 'qtype_calculated'), $precisionoptions);
 
         $distriboptions = array('uniform' => get_string('uniform', 'qtype_calculated'),
                 'loguniform' => get_string('loguniform', 'qtype_calculated'));
-        $mform->addElement('select', "calcdistribution[$idx]",
+        $mform->addElement('select', "calcdistribution[{$idx}]",
                 get_string('calcdistribution', 'qtype_calculated'), $distriboptions);
     }
 
@@ -730,11 +730,11 @@ class qtype_calculated extends question_type {
         foreach ($datasetdefs as $datasetdef) {
             if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~',
                     $datasetdef->options, $regs)) {
-                $defid = "$datasetdef->type-$datasetdef->category-$datasetdef->name";
-                $formdata["calcdistribution[$idx]"] = $regs[1];
-                $formdata["calcmin[$idx]"] = $regs[2];
-                $formdata["calcmax[$idx]"] = $regs[3];
-                $formdata["calclength[$idx]"] = $regs[4];
+                $defid = "{$datasetdef->type}-{$datasetdef->category}-{$datasetdef->name}";
+                $formdata["calcdistribution[{$idx}]"] = $regs[1];
+                $formdata["calcmin[{$idx}]"] = $regs[2];
+                $formdata["calcmax[{$idx}]"] = $regs[3];
+                $formdata["calclength[{$idx}]"] = $regs[4];
             }
             $idx++;
         }
@@ -745,7 +745,7 @@ class qtype_calculated extends question_type {
         global $OUTPUT;
         if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~',
                 $datasetdef->options, $regs)) {
-            $defid = "$datasetdef->type-$datasetdef->category-$datasetdef->name";
+            $defid = "{$datasetdef->type}-{$datasetdef->category}-{$datasetdef->name}";
             for ($i = 0; $i<10; ++$i) {
                 $lengthoptions[$i] = get_string(($regs[1] == 'uniform'
                     ? 'decimals'
@@ -761,10 +761,10 @@ class qtype_calculated extends question_type {
                 'menucalcdistribution', false, array('class' => 'accesshide'));
             $menu2 .= html_writer::select($options, 'calcdistribution[]', $regs[1], null);
             return '<input type="submit" onclick="'
-                . "getElementById('addform').regenerateddefid.value='$defid'; return true;"
+                . "getElementById('addform').regenerateddefid.value='{$defid}'; return true;"
                 .'" value="'. get_string('generatevalue', 'qtype_calculated') . '"/><br/>'
                 . '<input type="text" size="3" name="calcmin[]" '
-                . " value=\"$regs[2]\"/> &amp; <input name=\"calcmax[]\" "
+                . " value=\"{$regs[2]}\"/> &amp; <input name=\"calcmax[]\" "
                 . ' type="text" size="3" value="' . $regs[3] .'"/> '
                 . $menu1 . '<br/>'
                 . $menu2;
@@ -940,7 +940,7 @@ class qtype_calculated extends question_type {
                 // Fix regenerate for this datadefs.
                 $defregenerate = 0;
                 if ($synchronize &&
-                        !empty ($fromform->nextpageparam["datasetregenerate[$datasetdef->name"])) {
+                        !empty ($fromform->nextpageparam["datasetregenerate[{$datasetdef->name}"])) {
                     $defregenerate = 1;
                 } else if (!$synchronize &&
                         (($regenerate == 1 && $datasetdef->category == 0) ||$regenerate == 2)) {
@@ -1075,7 +1075,7 @@ class qtype_calculated extends question_type {
             }
             if ($answer->min === '') {
                 // This should mean that something is wrong.
-                $comment->stranswers[$key] = " $formattedanswer->answer".'<br/><br/>';
+                $comment->stranswers[$key] = " {$formattedanswer->answer}".'<br/><br/>';
             } else if ($formula === '*') {
                 $comment->stranswers[$key] = $formula . ' = ' .
                         get_string('anyvalue', 'qtype_calculated') . '<br/><br/><br/>';
@@ -1130,7 +1130,7 @@ class qtype_calculated extends question_type {
         }
         if (!$selected) {
             if ($mandatory) {
-                $selected =  "1-0-$name"; // Default.
+                $selected =  "1-0-{$name}"; // Default.
             } else {
                 $selected = '0'; // Default.
             }
@@ -1222,7 +1222,7 @@ class qtype_calculated extends question_type {
                   ORDER BY i.id";
             if ($records = $DB->get_records_sql($sql, array($questionid))) {
                 foreach ($records as $r) {
-                    $datasetdefs["$r->type-$r->category-$r->name"] = $r;
+                    $datasetdefs["{$r->type}-{$r->category}-{$r->name}"] = $r;
                 }
             }
         }
@@ -1465,8 +1465,8 @@ class qtype_calculated extends question_type {
         $options['0'] = get_string($prefix.'nodataset', $langfile);
         // New question no local.
         if (!isset($form->id) || $form->id == 0) {
-            $key = "$type-0-$name";
-            $options[$key] = get_string($prefix."newlocal$type", $langfile);
+            $key = "{$type}-0-{$name}";
+            $options[$key] = get_string($prefix."newlocal{$type}", $langfile);
             $currentdatasetdef = new stdClass();
             $currentdatasetdef->type = '0';
         } else {
@@ -1479,12 +1479,12 @@ class qtype_calculated extends question_type {
                 $currentdatasetdef = new stdClass();
                 $currentdatasetdef->type = '0';
             }
-            $key = "$type-0-$name";
+            $key = "{$type}-0-{$name}";
             if ($currentdatasetdef->type == $type
                     and $currentdatasetdef->category == 0) {
-                $options[$key] = get_string($prefix."keptlocal$type", $langfile);
+                $options[$key] = get_string($prefix."keptlocal{$type}", $langfile);
             } else {
-                $options[$key] = get_string($prefix."newlocal$type", $langfile);
+                $options[$key] = get_string($prefix."newlocal{$type}", $langfile);
             }
         }
         // Construct question category options.
@@ -1497,21 +1497,21 @@ class qtype_calculated extends question_type {
             AND a.category = ?
             AND a.name = ?", array($form->category, $name));
         $type = 1;
-        $key = "$type-$form->category-$name";
+        $key = "{$type}-{$form->category}-{$name}";
         if (!empty($categorydatasetdefs)) {
             // There is at least one with the same name.
             if (isset($form->id) && isset($categorydatasetdefs[$form->id])) {
                 // It is already used by this question.
-                $options[$key] = get_string($prefix."keptcategory$type", $langfile);
+                $options[$key] = get_string($prefix."keptcategory{$type}", $langfile);
             } else {
-                $options[$key] = get_string($prefix."existingcategory$type", $langfile);
+                $options[$key] = get_string($prefix."existingcategory{$type}", $langfile);
             }
         } else {
-            $options[$key] = get_string($prefix."newcategory$type", $langfile);
+            $options[$key] = get_string($prefix."newcategory{$type}", $langfile);
         }
         // All done!
         return array($options, $currentdatasetdef->type
-            ? "$currentdatasetdef->type-$currentdatasetdef->category-$name"
+            ? "{$currentdatasetdef->type}-{$currentdatasetdef->category}-{$name}"
             : '');
     }
 
@@ -1541,8 +1541,8 @@ class qtype_calculated extends question_type {
                      WHERE i.id = d.datasetdefinition AND i.category = ?";
             if ($records = $DB->get_records_sql($sql, array($form->category))) {
                 foreach ($records as $r) {
-                    if (!isset ($datasetdefs["$r->name"])) {
-                        $datasetdefs["$r->name"] = $r->itemcount;
+                    if (!isset ($datasetdefs["{$r->name}"])) {
+                        $datasetdefs["{$r->name}"] = $r->itemcount;
                     }
                 }
             }
@@ -1578,14 +1578,14 @@ class qtype_calculated extends question_type {
                     $sql1 = "SELECT q.*
                                FROM {question} q
                               WHERE q.id = ?";
-                    if (!isset ($datasetdefs["$r->type-$r->category-$r->name"])) {
-                        $datasetdefs["$r->type-$r->category-$r->name"] = $r;
+                    if (!isset ($datasetdefs["{$r->type}-{$r->category}-{$r->name}"])) {
+                        $datasetdefs["{$r->type}-{$r->category}-{$r->name}"] = $r;
                     }
                     if ($questionb = $DB->get_records_sql($sql1, array($r->question))) {
-                        if (!isset ($datasetdefs["$r->type-$r->category-$r->name"]->questions[$r->question])) {
-                            $datasetdefs["$r->type-$r->category-$r->name"]->questions[$r->question] = new stdClass();
+                        if (!isset ($datasetdefs["{$r->type}-{$r->category}-{$r->name}"]->questions[$r->question])) {
+                            $datasetdefs["{$r->type}-{$r->category}-{$r->name}"]->questions[$r->question] = new stdClass();
                         }
-                        $datasetdefs["$r->type-$r->category-$r->name"]->questions[
+                        $datasetdefs["{$r->type}-{$r->category}-{$r->name}"]->questions[
                                 $r->question]->name = $questionb[$r->question]->name;
                     }
                 }
@@ -1595,20 +1595,20 @@ class qtype_calculated extends question_type {
 
             $text = "<table width=\"100%\" border=\"1\"><tr>
                     <th style=\"white-space:nowrap;\" class=\"header\"
-                            scope=\"col\">$namestr</th>
+                            scope=\"col\">{$namestr}</th>
                     <th style=\"white-space:nowrap;\" class=\"header\"
-                            scope=\"col\">$rangeofvaluestr</th>
+                            scope=\"col\">{$rangeofvaluestr}</th>
                     <th style=\"white-space:nowrap;\" class=\"header\"
-                            scope=\"col\">$itemscountstr</th>
+                            scope=\"col\">{$itemscountstr}</th>
                     <th style=\"white-space:nowrap;\" class=\"header\"
-                            scope=\"col\">$questionusingstr</th>
+                            scope=\"col\">{$questionusingstr}</th>
                     </tr>";
             foreach ($datasetdefs as $datasetdef) {
                 list($distribution, $min, $max, $dec) = explode(':', $datasetdef->options, 4);
                 $text .= "<tr>
-                        <td valign=\"top\" align=\"center\">$datasetdef->name</td>
-                        <td align=\"center\" valign=\"top\">$min <strong>-</strong> $max</td>
-                        <td align=\"right\" valign=\"top\">$datasetdef->itemcount&nbsp;&nbsp;</td>
+                        <td valign=\"top\" align=\"center\">{$datasetdef->name}</td>
+                        <td align=\"center\" valign=\"top\">{$min} <strong>-</strong> $max</td>
+                        <td align=\"right\" valign=\"top\">{$datasetdef->itemcount}&nbsp;&nbsp;</td>
                         <td align=\"left\">";
                 foreach ($datasetdef->questions as $qu) {
                     // Limit the name length displayed.
@@ -1618,7 +1618,7 @@ class qtype_calculated extends question_type {
                     } else {
                         $qu->name = '';
                     }
-                    $text .= " &nbsp;&nbsp; $qu->name <br/>";
+                    $text .= " &nbsp;&nbsp; {$qu->name} <br/>";
                 }
                 $text .= "</td></tr>";
             }
@@ -1653,7 +1653,7 @@ class qtype_calculated extends question_type {
                      WHERE i.id = d.datasetdefinition AND i.category = ?";
             if ($records = $DB->get_records_sql($sql, array($category))) {
                 foreach ($records as $r) {
-                    $key = "$r->type-$r->category-$r->name";
+                    $key = "{$r->type}-{$r->category}-{$r->name}";
                     $sql1 = "SELECT q.*
                                FROM {question} q
                               WHERE q.id = ?";
@@ -1674,11 +1674,11 @@ class qtype_calculated extends question_type {
 
             $text  = "<table width=\"100%\" border=\"1\"><tr>
                     <th style=\"white-space:nowrap;\" class=\"header\"
-                            scope=\"col\">$namestr</th>";
+                            scope=\"col\">{$namestr}</th>";
             $text .= "<th style=\"white-space:nowrap;\" class=\"header\"
-                    scope=\"col\">$itemscountstr</th>";
+                    scope=\"col\">{$itemscountstr}</th>";
             $text .= "<th style=\"white-space:nowrap;\" class=\"header\"
-                    scope=\"col\">&nbsp;&nbsp;$questionusingstr &nbsp;&nbsp;</th>";
+                    scope=\"col\">&nbsp;&nbsp;{$questionusingstr} &nbsp;&nbsp;</th>";
             $text .= "<th style=\"white-space:nowrap;\" class=\"header\"
                     scope=\"col\">Quiz</th>";
             $text .= "<th style=\"white-space:nowrap;\" class=\"header\"
@@ -1688,9 +1688,9 @@ class qtype_calculated extends question_type {
                 $count = count($datasetdef->questions);
                 $text .= "<tr>
                         <td style=\"white-space:nowrap;\" valign=\"top\"
-                                align=\"center\" rowspan=\"$count\"> $datasetdef->name </td>
+                                align=\"center\" rowspan=\"{$count}\"> {$datasetdef->name} </td>
                         <td align=\"right\" valign=\"top\"
-                                rowspan=\"$count\">$datasetdef->itemcount</td>";
+                                rowspan=\"{$count}\">{$datasetdef->itemcount}</td>";
                 $line = 0;
                 foreach ($datasetdef->questions as $qu) {
                     // Limit the name length displayed.
@@ -1704,7 +1704,7 @@ class qtype_calculated extends question_type {
                         $text .= "<tr>";
                     }
                     $line++;
-                    $text .= "<td align=\"left\" style=\"white-space:nowrap;\">$qu->name</td>";
+                    $text .= "<td align=\"left\" style=\"white-space:nowrap;\">{$qu->name}</td>";
                     // TODO MDL-43779 should not have quiz-specific code here.
                     $nbofquiz = $DB->count_records('quiz_slots', array('questionid' => $qu->id));
                     $nbofattempts = $DB->count_records_sql("
@@ -1714,8 +1714,8 @@ class qtype_calculated extends question_type {
                              WHERE slot.questionid = ?
                                AND quiza.preview = 0", array($qu->id));
                     if ($nbofquiz > 0) {
-                        $text .= "<td align=\"center\">$nbofquiz</td>";
-                        $text .= "<td align=\"center\">$nbofattempts";
+                        $text .= "<td align=\"center\">{$nbofquiz}</td>";
+                        $text .= "<td align=\"center\">{$nbofattempts}";
                     } else {
                         $text .= "<td align=\"center\">0</td>";
                         $text .= "<td align=\"left\"><br/>";
@@ -1866,8 +1866,8 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
             }
         } else {
             // Stick to plain numeric format.
-            $answer *= "1e$p10";
-            if (0.1 <= $answer / "1e$answerlength") {
+            $answer *= "1e{$p10}";
+            if (0.1 <= $answer / "1e{$answerlength}") {
                 $calculated->answer = $sign.$answer;
             } else {
                 // Could be an idea to add some zeros here.
@@ -1903,11 +1903,11 @@ function qtype_calculated_find_formula_errors($formula) {
     $formula = strtolower(str_replace(' ', '', $formula));
 
     $safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
-    $operatorornumber = "[$safeoperatorchar.0-9eE]";
+    $operatorornumber = "[{$safeoperatorchar}.0-9eE]";
 
-    while (preg_match("~(^|[$safeoperatorchar,(])([a-z0-9_]*)" .
-            "\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
-        $formula, $regs)) {
+    while (preg_match("~(^|[{$safeoperatorchar},(])([a-z0-9_]*)" .
+            "\\(({$operatorornumber}+(,{$operatorornumber}+((,{$operatorornumber}+)+)?)?)?\\)~",
+            $formula, $regs)) {
         switch ($regs[2]) {
             // Simple parenthesis.
             case '':
@@ -1968,11 +1968,11 @@ function qtype_calculated_find_formula_errors($formula) {
             $formula = str_replace($regs[0], $regs[1] . '1', $formula);
         } else {
             // The function call starts the formula.
-            $formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
+            $formula = preg_replace("~^{$regs[2]}\\([^)]*\\)~", '1', $formula);
         }
     }
 
-    if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
+    if (preg_match("~[^{$safeoperatorchar}.0-9eE]+~", $formula, $regs)) {
         return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
     } else {
         // Formula just might be valid.
index 400a1df..e18d989 100644 (file)
@@ -167,12 +167,12 @@ class qtype_calculatedmulti_edit_form extends question_edit_form {
         $mform->setType('nounits', PARAM_INT);
         $mform->setConstants(array('nounits'=>$nounits));
         for ($i = 0; $i < $nounits; $i++) {
-            $mform->addElement('hidden', 'unit'."[$i]",
-                    optional_param("unit[$i]", '', PARAM_NOTAGS));
-            $mform->setType('unit'."[$i]", PARAM_NOTAGS);
-            $mform->addElement('hidden', 'multiplier'."[$i]",
-                    optional_param("multiplier[$i]", '', PARAM_FLOAT));
-            $mform->setType("multiplier[$i]", PARAM_FLOAT);
+            $mform->addElement('hidden', 'unit'."[{$i}]",
+                    optional_param("unit[{$i}]", '', PARAM_NOTAGS));
+            $mform->setType('unit'."[{$i}]", PARAM_NOTAGS);
+            $mform->addElement('hidden', 'multiplier'."[{$i}]",
+                    optional_param("multiplier[{$i}]", '', PARAM_FLOAT));
+            $mform->setType("multiplier[{$i}]", PARAM_FLOAT);
         }
 
         $this->add_combined_feedback_fields(true);
@@ -217,10 +217,10 @@ class qtype_calculatedmulti_edit_form extends question_edit_form {
         $key = 0;
         foreach ($question->options->answers as $answer) {
             // See comment in the parent method about this hack.
-            unset($this->_form->_defaultValues["tolerance[$key]"]);
-            unset($this->_form->_defaultValues["tolerancetype[$key]"]);
-            unset($this->_form->_defaultValues["correctanswerlength[$key]"]);
-            unset($this->_form->_defaultValues["correctanswerformat[$key]"]);
+            unset($this->_form->_defaultValues["tolerance[{$key}]"]);
+            unset($this->_form->_defaultValues["tolerancetype[{$key}]"]);
+            unset($this->_form->_defaultValues["correctanswerlength[{$key}]"]);
+            unset($this->_form->_defaultValues["correctanswerformat[{$key}]"]);
 
             $question->tolerance[$key]           = $answer->tolerance;
             $question->tolerancetype[$key]       = $answer->tolerancetype;
index 87f6c80..54fb4f4 100644 (file)
@@ -202,8 +202,8 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
                 // Detect new datasets.
                 $newdataset = false;
                 foreach ($mandatorydatasets as $datasetname) {
-                    if (!isset($this->datasetdefs["1-0-$datasetname"])) {
-                        $key = "1-0-$datasetname";
+                    if (!isset($this->datasetdefs["1-0-{$datasetname}"])) {
+                        $key = "1-0-{$datasetname}";
                         $this->datasetdefs[$key] = new stdClass();
                         $this->datasetdefs[$key]->type = 1;
                         $this->datasetdefs[$key]->category = 0;
@@ -211,7 +211,7 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
                         $this->datasetdefs[$key]->options = "uniform:1.0:10.0:1";
                         $newdataset = true;
                     } else {
-                        $this->datasetdefs["1-0-$datasetname"]->name = $datasetname;
+                        $this->datasetdefs["1-0-{$datasetname}"]->name = $datasetname;
                     }
                 }
                 // Remove obsolete datasets.
@@ -332,15 +332,15 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
             if (!empty($this->datasetdefs)) {// Unnecessary test.
                 $j = (($this->noofitems) * count($this->datasetdefs))+1;//
                 foreach ($this->datasetdefs as $defkey => $datasetdef) {
-                    $mform->addElement('static', "na[$j]",
+                    $mform->addElement('static', "na[{$j}]",
                             get_string('param', 'qtype_calculated', $datasetdef->name));
                     $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
-                    $mform->addElement('hidden', "datasetdef[$idx]");
-                    $mform->setType("datasetdef[$idx]", PARAM_RAW);
-                    $mform->addElement('hidden', "defoptions[$idx]");
-                    $mform->setType("defoptions[$idx]", PARAM_RAW);
+                    $mform->addElement('hidden', "datasetdef[{$idx}]");
+                    $mform->setType("datasetdef[{$idx}]", PARAM_RAW);
+                    $mform->addElement('hidden', "defoptions[{$idx}]");
+                    $mform->setType("defoptions[{$idx}]", PARAM_RAW);
                     $idx++;
-                    $mform->addElement('static', "divider[$j]", '', '<hr />');
+                    $mform->addElement('static', "divider[{$j}]", '', '<hr />');
                     $j++;
                 }
             }
@@ -362,23 +362,23 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
 
                     foreach ($this->datasetdefs as $defid => $datasetdef) {
                         if (isset($datasetdef->items[$itemnumber])) {
-                            $this->formdata["definition[$j]"] = $defid;
-                            $this->formdata["itemid[$j]"] =
+                            $this->formdata["definition[{$j}]"] = $defid;
+                            $this->formdata["itemid[{$j}]"] =
                                     $datasetdef->items[$itemnumber]->id;
                             $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
-                            $this->formdata["number[$j]"] = $number =
+                            $this->formdata["number[{$j}]"] = $number =
                                     $datasetdef->items[$itemnumber]->value;
                             if (! is_numeric($number)) {
                                 $a = new stdClass();
                                 $a->name = '{'.$datasetdef->name.'}';
                                 $a->value = $datasetdef->items[$itemnumber]->value;
                                 if (stristr($number, ',')) {
-                                    $this->numbererrors["number[$j]"] =
+                                    $this->numbererrors["number[{$j}]"] =
                                             get_string('nocommaallowed', 'qtype_calculated');
                                     $numbererrors .= $this->numbererrors['number['.$j.']']."<br />";
 
                                 } else {
-                                    $this->numbererrors["number[$j]"] =
+                                    $this->numbererrors["number[{$j}]"] =
                                             get_string('notvalidnumber', 'qtype_calculated', $a);
                                     $numbererrors .= $this->numbererrors['number['.$j.']']."<br />";
                                 }
@@ -393,7 +393,7 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
                                 $a = new stdClass();
                                 $a->name = '{'.$datasetdef->name.'}';
                                 $a->value = $datasetdef->items[$itemnumber]->value;
-                                $this->numbererrors["number[$j]"] =
+                                $this->numbererrors["number[{$j}]"] =
                                         get_string('notvalidnumber', 'qtype_calculated', $a);
                                 $numbererrors .= $this->numbererrors['number['.$j.']']."<br />";
                             }
@@ -430,7 +430,7 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
                 $data = array(); // Data for comment_on_datasetitems later.
                 $idx = 1;
                 foreach ($this->datasetdefs as $defid => $datasetdef) {
-                    $this->formdata["datasetdef[$idx]"] = $defid;
+                    $this->formdata["datasetdef[{$idx}]"] = $defid;
                     $idx++;
                 }
                 $this->formdata = $this->qtypeobj->custom_generator_set_data(
@@ -440,14 +440,14 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
             $addoptions = Array();
             $addoptions['1'] = '1';
             for ($i = 10; $i <= 100; $i += 10) {
-                $addoptions["$i"] = "$i";
+                $addoptions["{$i}"] = "{$i}";
             }
             $showoptions = Array();
             $showoptions['1'] = '1';
             $showoptions['2'] = '2';
             $showoptions['5'] = '5';
             for ($i = 10; $i <= 100; $i += 10) {
-                $showoptions["$i"] = "$i";
+                $showoptions["{$i}"] = "{$i}";
             }
             $mform->closeHeaderBefore('additemhdr');
             $addgrp = array();
@@ -495,38 +495,38 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
                 for ($i = $this->noofitems; $i >= 1; $i--) {
                     foreach ($this->datasetdefs as $defkey => $datasetdef) {
                         if ($k > 0 ||  $this->outsidelimit || !empty($this->numbererrors)) {
-                            $mform->addElement('text', "number[$j]", get_string(
+                            $mform->addElement('text', "number[{$j}]", get_string(
                                     'wildcard', 'qtype_calculatedsimple', $datasetdef->name));
-                            $mform->setAdvanced("number[$j]", true);
+                            $mform->setAdvanced("number[{$j}]", true);
                             if (!empty($this->numbererrors['number['.$j.']'])) {
-                                $mform->addElement('static', "numbercomment[$j]", '',
+                                $mform->addElement('static', "numbercomment[{$j}]", '',
                                         '<span class="error">' .
                                         $this->numbererrors['number['.$j.']'] . '</span>');
-                                $mform->setAdvanced("numbercomment[$j]", true);
+                                $mform->setAdvanced("numbercomment[{$j}]", true);
                             }
                         } else {
-                            $mform->addElement('hidden', "number[$j]", get_string(
+                            $mform->addElement('hidden', "number[{$j}]", get_string(
                                     'wildcard', 'qtype_calculatedsimple', $datasetdef->name));
                         }
-                        $mform->setType("number[$j]", PARAM_RAW); // This parameter will be validated in validation().
+                        $mform->setType("number[{$j}]", PARAM_RAW); // This parameter will be validated in validation().
 
-                        $mform->addElement('hidden', "itemid[$j]");
-                        $mform->setType("itemid[$j]", PARAM_INT);
+                        $mform->addElement('hidden', "itemid[{$j}]");
+                        $mform->setType("itemid[{$j}]", PARAM_INT);
 
-                        $mform->addElement('hidden', "definition[$j]");
-                        $mform->setType("definition[$j]", PARAM_NOTAGS);
+                        $mform->addElement('hidden', "definition[{$j}]");
+                        $mform->setType("definition[{$j}]", PARAM_NOTAGS);
 
                         $j--;
                     }
                     if (!empty($strquestionlabel) && ($k > 0 ||  $this->outsidelimit ||
                             !empty($this->numbererrors))) {
-                        $mform->addElement('static', "answercomment[$i]", "<b>" .
+                        $mform->addElement('static', "answercomment[{$i}]", "<b>" .
                                 get_string('setno', 'qtype_calculatedsimple', $i) .
                                 "</b>&nbsp;&nbsp;" . $strquestionlabel);
 
                     }
                     if ($k > 0 ||  $this->outsidelimit || !empty($this->numbererrors)) {
-                        $mform->addElement('static', "divider1[$j]", '', '<hr />');
+                        $mform->addElement('static', "divider1[{$j}]", '', '<hr />');
 
                     }
                     $k--;
index 8a0a264..a58a172 100644 (file)
@@ -243,23 +243,23 @@ class qtype_calculatedsimple extends qtype_calculated {
     public function custom_generator_tools_part($mform, $idx, $j) {
 
         $minmaxgrp = array();
-        $minmaxgrp[] = $mform->createElement('text', "calcmin[$idx]",
+        $minmaxgrp[] = $mform->createElement('text', "calcmin[{$idx}]",
                 get_string('calcmin', 'qtype_calculated'));
-        $minmaxgrp[] = $mform->createElement('text', "calcmax[$idx]",
+        $minmaxgrp[] = $mform->createElement('text', "calcmax[{$idx}]",
                 get_string('calcmax', 'qtype_calculated'));
         $mform->addGroup($minmaxgrp, 'minmaxgrp',
                 get_string('minmax', 'qtype_calculated'), ' - ', false);
-        $mform->setType("calcmin[$idx]", PARAM_FLOAT);
-        $mform->setType("calcmax[$idx]", PARAM_FLOAT);
+        $mform->setType("calcmin[{$idx}]", PARAM_FLOAT);
+        $mform->setType("calcmax[{$idx}]", PARAM_FLOAT);
 
         $precisionoptions = range(0, 10);
-        $mform->addElement('select', "calclength[$idx]",
+        $mform->addElement('select', "calclength[{$idx}]",
                 get_string('calclength', 'qtype_calculated'), $precisionoptions);
 
         $distriboptions = array('uniform' => get_string('uniform', 'qtype_calculated'),
                 'loguniform' => get_string('loguniform', 'qtype_calculated'));
-        $mform->addElement('hidden', "calcdistribution[$idx]", 'uniform');
-        $mform->setType("calcdistribution[$idx]", PARAM_INT);
+        $mform->addElement('hidden', "calcdistribution[{$idx}]", 'uniform');
+        $mform->setType("calcdistribution[{$idx}]", PARAM_INT);
     }
 
     public function comment_header($answers) {
@@ -296,7 +296,7 @@ class qtype_calculatedsimple extends qtype_calculated {
         }
         if (!$selected) {
             if ($mandatory) {
-                $selected =  "1-0-$name"; // Default.
+                $selected =  "1-0-{$name}"; // Default.
             } else {
                 $selected = "0"; // Default.
             }
index 16058ad..147e4f8 100644 (file)
@@ -124,7 +124,7 @@ abstract class question_edit_form extends question_wizard_form {
         global $COURSE, $CFG, $DB, $PAGE;
 
         $qtype = $this->qtype();
-        $langfile = "qtype_$qtype";
+        $langfile = "qtype_{$qtype}";
 
         $mform = $this->_form;
 
@@ -418,7 +418,7 @@ abstract class question_edit_form extends question_wizard_form {
         }
         $penaltyoptions = array();
         foreach ($penalties as $penalty) {
-            $penaltyoptions["$penalty"] = (100 * $penalty) . '%';
+            $penaltyoptions["{$penalty}"] = (100 * $penalty) . '%';
         }
         $mform->addElement('select', 'penalty',
                 get_string('penaltyforeachincorrecttry', 'question'), $penaltyoptions);
@@ -560,7 +560,7 @@ abstract class question_edit_form extends question_wizard_form {
             // are using object notation here, so we will be setting
             // ->_defaultValues['fraction'][0]. That does not work, so we have
             // to unset ->_defaultValues['fraction[0]'].
-            unset($this->_form->_defaultValues["fraction[$key]"]);
+            unset($this->_form->_defaultValues["fraction[{$key}]"]);
 
             // Prepare the feedback editor to display files in draft area.
             $draftitemid = file_get_submitted_draft_itemid('feedback['.$key.']');
index e473ae7..ee8e8bc 100644 (file)
@@ -64,7 +64,7 @@ function xmldb_qtype_essay_upgrade($oldversion) {
                     $sql");
 
             foreach ($toupdate as $data) {
-                $progressbar->update($done, $count, "Updating essay feedback ($done/$count).");
+                $progressbar->update($done, $count, "Updating essay feedback ({$done}/{$count}).");
                 upgrade_set_timeout(60);
                 if ($data->generalfeedbackformat == $data->feedbackformat) {
                     $DB->set_field('question', 'generalfeedback',
index b5edea2..5ed2b5f 100644 (file)
@@ -202,7 +202,7 @@ class qtype_match_question extends question_graded_automatically_with_countback
             } else if ($choicetochoiceno[$choice]) {
                 $choiceselectvalue = $choicenotochoiceselectvalue[$choicetochoiceno[$choice]];
             } else {
-                throw new coding_exception("Unknown choice $choice in matching question - {$this->name}.");
+                throw new coding_exception("Unknown choice {$choice} in matching question - {$this->name}.");
             }
             $postdata[$this->field($shuffledstemno)] = $choiceselectvalue;
         }
index 178733f..5f45ff5 100644 (file)
@@ -296,7 +296,7 @@ class qtype_multianswer_edit_form extends question_edit_form {
                                 unset($wrapped->options->tolerance);
                             }
                             if ($subanswer->feedback) {
-                                $parsableanswerdef .= "#$subanswer->feedback";
+                                $parsableanswerdef .= "#{$subanswer->feedback}";
                             }
                             $separator = '~';
                         }
index 40a82b6..00c412d 100644 (file)
@@ -396,23 +396,23 @@ function qtype_multianswer_extract_question($text) {
         $remainingalts = $answerregs[ANSWER_REGEX_ALTERNATIVES];
         while (preg_match('/~?'.ANSWER_ALTERNATIVE_REGEX.'/s', $remainingalts, $altregs)) {
             if ('=' == $altregs[ANSWER_ALTERNATIVE_REGEX_FRACTION]) {
-                $wrapped->fraction["$answerindex"] = '1';
+                $wrapped->fraction["{$answerindex}"] = '1';
             } else if ($percentile = $altregs[ANSWER_ALTERNATIVE_REGEX_PERCENTILE_FRACTION]) {
-                $wrapped->fraction["$answerindex"] = .01 * $percentile;
+                $wrapped->fraction["{$answerindex}"] = .01 * $percentile;
             } else {
-                $wrapped->fraction["$answerindex"] = '0';
+                $wrapped->fraction["{$answerindex}"] = '0';
             }
             if (isset($altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK])) {
                 $feedback = html_entity_decode(
                         $altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK], ENT_QUOTES, 'UTF-8');
                 $feedback = str_replace('\}', '}', $feedback);
-                $wrapped->feedback["$answerindex"]['text'] = str_replace('\#', '#', $feedback);
-                $wrapped->feedback["$answerindex"]['format'] = FORMAT_HTML;
-                $wrapped->feedback["$answerindex"]['itemid'] = '';
+                $wrapped->feedback["{$answerindex}"]['text'] = str_replace('\#', '#', $feedback);
+                $wrapped->feedback["{$answerindex}"]['format'] = FORMAT_HTML;
+                $wrapped->feedback["{$answerindex}"]['itemid'] = '';
             } else {
-                $wrapped->feedback["$answerindex"]['text'] = '';
-                $wrapped->feedback["$answerindex"]['format'] = FORMAT_HTML;
-                $wrapped->feedback["$answerindex"]['itemid'] = '';
+                $wrapped->feedback["{$answerindex}"]['text'] = '';
+                $wrapped->feedback["{$answerindex}"]['format'] = FORMAT_HTML;
+                $wrapped->feedback["{$answerindex}"]['itemid'] = '';
 
             }
             if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])
@@ -420,20 +420,20 @@ function qtype_multianswer_extract_question($text) {
                             $altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER], $numregs)) {
                 $wrapped->answer[] = $numregs[NUMERICAL_CORRECT_ANSWER];
                 if (array_key_exists(NUMERICAL_ABS_ERROR_MARGIN, $numregs)) {
-                    $wrapped->tolerance["$answerindex"] =
+                    $wrapped->tolerance["{$answerindex}"] =
                     $numregs[NUMERICAL_ABS_ERROR_MARGIN];
                 } else {
-                    $wrapped->tolerance["$answerindex"] = 0;
+                    $wrapped->tolerance["{$answerindex}"] = 0;
                 }
             } 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');
                 $answer = str_replace('\}', '}', $answer);
-                $wrapped->answer["$answerindex"] = str_replace('\#', '#', $answer);
+                $wrapped->answer["{$answerindex}"] = str_replace('\#', '#', $answer);
                 if ($wrapped->qtype == 'multichoice') {
-                    $wrapped->answer["$answerindex"] = array(
-                            'text' => $wrapped->answer["$answerindex"],
+                    $wrapped->answer["{$answerindex}"] = array(
+                            'text' => $wrapped->answer["{$answerindex}"],
                             'format' => FORMAT_HTML,
                             'itemid' => '');
                 }
index e99cdd6..1d89550 100644 (file)
@@ -210,7 +210,7 @@ class qtype_numerical_edit_form extends question_edit_form {
         $key = 0;
         foreach ($question->options->answers as $answer) {
             // See comment in the parent method about this hack.
-            unset($this->_form->_defaultValues["tolerance[$key]"]);
+            unset($this->_form->_defaultValues["tolerance[{$key}]"]);
 
             $question->tolerance[$key] = $answer->tolerance;
             $key++;
index 2d290aa..f1b2a86 100644 (file)
@@ -433,7 +433,7 @@ class qtype_numerical extends question_type {
                 $ans = new qtype_numerical_answer($answer->id, $answer->answer, $answer->fraction,
                         $answer->feedback, $answer->feedbackformat, $answer->tolerance);
                 list($min, $max) = $ans->get_tolerance_interval();
-                $responseclass .= " ($min..$max)";
+                $responseclass .= " ({$min}..{$max})";
             }
 
             $responses[$aid] = new question_possible_response($responseclass,
@@ -569,12 +569,12 @@ class qtype_numerical_answer_processor {
         $decimalsre = $decsep . '(\d*)';
         $exponentre = '(?:e|E|(?:x|\*|×)10(?:\^|\*\*))([+-]?\d+)';
 
-        $numberbit = "$beforepointre(?:$decimalsre)?(?:$exponentre)?";
+        $numberbit = "{$beforepointre}(?:{$decimalsre})?(?:{$exponentre})?";
 
         if ($this->unitsbefore) {
-            $this->regex = "/$numberbit$/";
+            $this->regex = "/{$numberbit}$/";
         } else {
-            $this->regex = "/^$numberbit/";
+            $this->regex = "/^{$numberbit}/";
         }
         return $this->regex;
     }
@@ -645,9 +645,9 @@ class qtype_numerical_answer_processor {
 
         $regex = '[+-]?(?:\d+(?:\\.\d*)?|\\.\d+)(?:e[-+]?\d+)?';
         if ($this->unitsbefore) {
-            $regex = "/$regex$/";
+            $regex = "/{$regex}$/";
         } else {
-            $regex = "/^$regex/";
+            $regex = "/^{$regex}/";
         }
         if (!preg_match($regex, $response, $matches)) {
             return array(null, null, null);
index c0cfbac..256ebe5 100644 (file)
@@ -417,7 +417,7 @@ class question_type {
         }
 
         if (!empty($result->notice)) {
-            notice($result->notice, "question.php?id=$question->id");
+            notice($result->notice, "question.php?id={$question->id}");
         }
 
         if (!empty($result->noticeyesno)) {
@@ -1181,7 +1181,7 @@ class question_type {
         $expout='';
         foreach ($extraquestionfields as $field) {
             $exportedvalue = $format->xml_escape($question->options->$field);
-            $expout .= "    <$field>{$exportedvalue}</$field>\n";
+            $expout .= "    <{$field}>{$exportedvalue}</{$field}>\n";
         }
 
         $extraanswersfields = $this->extra_answer_fields();
index 97ea6e2..3d1f0b7 100644 (file)
@@ -86,7 +86,7 @@ class qtype_random extends question_type {
         list($qcsql, $qcparams) = $DB->get_in_or_equal($categorylist);
         // TODO use in_or_equal for $otherquestionsinuse and $this->manualqtypes.
         return $DB->record_exists_select('question',
-                "category $qcsql
+                "category {$qcsql}
                      AND parent = 0
                      AND hidden = 0
                      AND id NOT IN ($otherquestionsinuse)
index c05c263..5c11f9c 100644 (file)
@@ -227,7 +227,7 @@ class qtype_randomsamatch extends question_type {
         $extraquestionfields = $this->extra_question_fields();
         array_shift($extraquestionfields);
         foreach ($extraquestionfields as $extra) {
-            $expout .= "    <$extra>" . $question->options->$extra . "</$extra>\n";
+            $expout .= "    <{$extra}>" . $question->options->$extra . "</{$extra}>\n";
         }
         return $expout;
     }
index c707749..50971ec 100644 (file)
@@ -80,7 +80,7 @@ class qtype_shortanswer_edit_form extends question_edit_form {
                 }
             } else if ($data['fraction'][$key] != 0 ||
                     !html_is_blank($data['feedback'][$key]['text'])) {
-                $errors["answeroptions[$key]"] = get_string('answermustbegiven', 'qtype_shortanswer');
+                $errors["answeroptions[{$key}]"] = get_string('answermustbegiven', 'qtype_shortanswer');
                 $answercount++;
             }
         }