Select Git revision
renderer.php
-
Chris Sangwin authoredChris Sangwin authored
renderer.php 20.05 KiB
<?php
// This file is part of Stack - http://stack.maths.ed.ac.uk/
//
// Stack is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Stack is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* Stack question renderer class.
*
* @package qtype_stack
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Generates the output for Stack questions.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_stack_renderer extends qtype_renderer {
public function formulation_and_controls(question_attempt $qa, question_display_options $options) {
/* Return type should be @var qtype_stack_question $question. */
$question = $qa->get_question();
$response = $qa->get_last_qt_data();
$questiontext = $question->questiontextinstantiated;
// Replace inputs.
$inputstovaldiate = array();
// Get the list of placeholders before format_text.
$originalinputplaceholders = array_unique(stack_utils::extract_placeholders($questiontext, 'input'));
sort($originalinputplaceholders);
$originalfeedbackplaceholders = array_unique(stack_utils::extract_placeholders($questiontext, 'feedback'));
sort($originalfeedbackplaceholders);
// Now format the questiontext.
$questiontext = $question->format_text(
stack_maths::process_display_castext($questiontext, $this),
$question->questiontextformat,
$qa, 'question', 'questiontext', $question->id);
// Get the list of placeholders after format_text.
$formatedinputplaceholders = stack_utils::extract_placeholders($questiontext, 'input');
sort($formatedinputplaceholders);
$formatedfeedbackplaceholders = stack_utils::extract_placeholders($questiontext, 'feedback');
sort($formatedfeedbackplaceholders);
// We need to check that if the list has changed.
// Have we lost some of the placeholders entirely?
// Duplicates may have been removed by multi-lang,
// No duplicates should remain.
if ($formatedinputplaceholders !== $originalinputplaceholders ||
$formatedfeedbackplaceholders !== $originalfeedbackplaceholders) {
throw new coding_exception('Inconsistent placeholders. Possibly due to multi-lang filtter not being active.');
}