Skip to content

Commit

Permalink
MDL-46212 questions: add {} whenver vars are put into "" strings
Browse files Browse the repository at this point in the history
Having had one subtle bug cased be this, I decided to do a search and
fix all of these.
  • Loading branch information
timhunt committed Jul 3, 2014
1 parent 0e30442 commit f4fe396
Show file tree
Hide file tree
Showing 40 changed files with 273 additions and 273 deletions.
2 changes: 1 addition & 1 deletion question/category_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function edit_single_category($categoryid) {
/// 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);
Expand Down
10 changes: 5 additions & 5 deletions question/classes/bank/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ protected function display_question_list($contexts, $pageurl, $categoryandcontex
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>';

Expand All @@ -743,13 +743,13 @@ protected function display_question_list($contexts, $pageurl, $categoryandcontex

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}";
}
}
}
Expand Down Expand Up @@ -835,13 +835,13 @@ public function process_actions() {
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}")));
}
}

Expand Down
6 changes: 3 additions & 3 deletions question/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'])){
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions question/engine/bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function get_qtype($qtypename, $mustexist = true) {
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];
Expand Down Expand Up @@ -381,8 +381,8 @@ protected static function ensure_fraction_options_initialised() {
// 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.
Expand Down Expand Up @@ -499,10 +499,10 @@ public function get_questions_from_categories($categoryids, $extraconditions,
}

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. */
Expand Down
14 changes: 7 additions & 7 deletions question/engine/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public function load_average_marks(qubaid_condition $qubaids, $slots = null) {
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();
Expand Down Expand Up @@ -879,9 +879,9 @@ public function delete_steps($stepids, $context) {
$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);
}

/**
Expand Down Expand Up @@ -942,7 +942,7 @@ public function update_question_attempt_flag($qubaid, $questionid, $qaid, $slot,
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;
}
Expand Down Expand Up @@ -1043,7 +1043,7 @@ public function question_attempt_latest_state_view($alias, qubaid_condition $qub
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') {
Expand Down Expand Up @@ -1658,7 +1658,7 @@ public function __construct($from, $usageidcolumn, $where = '', $params = array(
}

public function from_question_attempts($alias) {
return "$this->from
return "{$this->from}
JOIN {question_attempts} {$alias} ON " .
"{$alias}.questionusageid = $this->usageidcolumn";
}
Expand All @@ -1672,7 +1672,7 @@ public function from_where_params() {
}

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() {
Expand Down
4 changes: 2 additions & 2 deletions question/engine/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public static function get_postdata(question_attempt $qa) {
$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=';
}

Expand Down Expand Up @@ -735,7 +735,7 @@ public function __construct($qubaid, $slot, $postdata) {
$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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion question/engine/questionattempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ public static function load_from_records($records, $questionattemptid,
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();
}
Expand Down
2 changes: 1 addition & 1 deletion question/engine/questionusage.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public static function load_from_records($records, $qubaid) {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions question/engine/tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,10 @@ public function assert($expectation, $compare, $notused = '') {
$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);
Expand Down
2 changes: 1 addition & 1 deletion question/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

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';
Expand Down
4 changes: 2 additions & 2 deletions question/export_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ protected function definition() {
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++ ;
Expand Down
18 changes: 9 additions & 9 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ protected function error($message, $text='', $questionname='') {
$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++;
Expand All @@ -247,7 +247,7 @@ public function try_importing_using_qtypes($data, $question = null, $extra = nul

// 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)) {
Expand Down Expand Up @@ -377,7 +377,7 @@ public function importprocess($category) {

$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)
Expand Down Expand Up @@ -691,7 +691,7 @@ protected function add_blank_combined_feedback($question) {
protected function readquestion($lines) {

$formatnotimplemented = get_string('formatnotimplemented', 'question');
echo "<p>$formatnotimplemented</p>";
echo "<p>{$formatnotimplemented}</p>";

return null;
}
Expand Down Expand Up @@ -719,7 +719,7 @@ public function importpostprocess() {
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)) {
Expand Down Expand Up @@ -819,7 +819,7 @@ public function exportprocess() {

// 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) {
Expand Down Expand Up @@ -924,7 +924,7 @@ protected function exportpostprocess() {
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;
}

Expand Down
2 changes: 1 addition & 1 deletion question/format/blackboard_six/formatbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function text_field($text) {
$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;
}

Expand Down
4 changes: 2 additions & 2 deletions question/format/gift/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function readquestion($lines) {
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;
Expand Down Expand Up @@ -634,7 +634,7 @@ public function writequestion($question) {
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) {
Expand Down
Loading

0 comments on commit f4fe396

Please sign in to comment.