Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions amd/build/formatcheck.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions amd/build/formatcheck.min.js.map

Large diffs are not rendered by default.

646 changes: 448 additions & 198 deletions script/formatcheck.js → amd/src/formatcheck.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions edit_formulas_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ protected function definition_inner($mform) {
global $PAGE;
$config = get_config('qtype_formulas');
$PAGE->requires->js_call_amd('qtype_formulas/editform', 'init', [get_config('qtype_formulas')->defaultcorrectness]);
$PAGE->requires->js('/question/type/formulas/script/formatcheck.js');
$PAGE->requires->js_call_amd('qtype_formulas/formatcheck', 'init', [get_string('decsep', 'langconfig'), get_string('unit', 'qtype_formulas')]);
$PAGE->requires->css('/question/type/formulas/styles.css');
$PAGE->requires->css('/question/type/formulas/tabulator.css');
// Legacy, needed until formatcheck.js is refactored.
$PAGE->requires->string_for_js('unit', 'qtype_formulas');
// Hide the unused form fields.
$mform->removeElement('defaultmark');
$mform->addElement('hidden', 'defaultmark');
Expand Down
8 changes: 8 additions & 0 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ public function apply_attempt_state(question_attempt_step $step) {
*/
public function formulas_format_text($vars, $text, $format, $qa, $component, $filearea, $itemid,
$clean = false) {
$vars = clone $vars;
foreach($vars->all as $key => $var) {
if($var->type == 'n') {
$vars->all[$key] = clone $var;
$vars->all[$key]->value = str_replace('.', get_string('decsep', 'langconfig'), $var->value);
}
}
return $this->format_text($this->qv->substitute_variables_in_text($vars, $text),
$format, $qa, $component, $filearea, $itemid, $clean);
}
Expand Down Expand Up @@ -639,6 +646,7 @@ public function compute_response_difference(&$vars, &$a, &$r, $cfactor, $grading
if (!$res->is_number) { // Unit has no meaning for algebraic format, so do nothing for it.
$res->diff = $this->qv->compute_algebraic_formula_difference($vars, $a, $r);
} else {
$r = str_replace(get_string('decsep', 'langconfig'), '.', $r);
$res->diff = $this->qv->compute_numerical_formula_difference($a, $r, $cfactor, $gradingtype);
}
} catch (Exception $e) { // @codingStandardsIgnoreLine
Expand Down
15 changes: 14 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_formulas_renderer extends qtype_with_combined_feedback_renderer {

// there currently is an error in Moodle in mod/quiz/attempt.php (line 130and 139)
// to call this twice, so check this
static $headerjsadded = false;

/**
* Generate the display of the formulation part of the question. This is the
* area that contains the question text, and the controls for students to
Expand Down Expand Up @@ -88,7 +93,12 @@ public function formulation_and_controls(question_attempt $qa,
}

public function head_code(question_attempt $qa) {
$this->page->requires->js('/question/type/formulas/script/formatcheck.js');
// there currently is an error in Moodle in mod/quiz/attempt.php (line 130and 139)
// to call this twice, so check this
if(!self::$headerjsadded) {
$this->page->requires->js_call_amd('qtype_formulas/formatcheck', 'init', [get_string('decsep', 'langconfig'), get_string('unit', 'qtype_formulas')]);
self::$headerjsadded = true;
}
}

// Return the part text, controls, grading details and feedbacks.
Expand Down Expand Up @@ -265,6 +275,9 @@ public function get_part_formulation(question_attempt $qa, question_display_opti
$placeholder = ($j == $part->numbox) ? "_u" : "_$j"; // The last one is unit.
$variablename = "{$i}_$j";
$currentanswer = $qa->get_last_qt_var($variablename);
if(!empty($currentanswer)) {
$currentanswer = str_replace('.', get_string('decsep', 'langconfig'), $currentanswer);
}
$inputname = $qa->get_qt_field_name($variablename);
$inputattributes = array(
'name' => $inputname,
Expand Down