diff --git a/edit_wq_form.php b/edit_wq_form.php index c11d8d4e..60ad939d 100644 --- a/edit_wq_form.php +++ b/edit_wq_form.php @@ -20,7 +20,6 @@ class qtype_wq_edit_form extends question_edit_form { protected $base; - public function __construct($base, $submiturl, $question, $category, $contexts, $formeditable) { // TODO: remove all but $base function parameters. @@ -60,15 +59,21 @@ protected function definition_inner($mform) { if (isset($this->question->wirisquestion)) { $program = $this->question->wirisquestion->serialize(); } else { - if (!empty($this->question->id)) { - $wiris = $DB->get_record('qtype_wq', array('question' => $this->question->id)); - } - if (!empty($wiris)) { - // Existing question. - $program = $wiris->xml; - } else { + if (empty($this->question->id)) { // New question. $program = ''; + } else { + // Existing question. + $wiris = $DB->get_record('qtype_wq', array('question' => $this->question->id)); + if (empty($wiris)) { + // Corrupted question + $corruptwarning = $mform->createElement('html', '
' . get_string('corruptquestion_edit', 'qtype_wq') .'insertElementBefore($corruptwarning, 'generalheader'); + $program = ''; + } else { + // Happy path + $program = $wiris->xml; + } } } @@ -85,6 +90,7 @@ protected function definition_inner($mform) { $defaultvalues = array(); $defaultvalues['wirisquestion'] = $program; $mform->setDefaults($defaultvalues); + } public function set_data($question) { $this->base->set_data($question); diff --git a/lang/ca/qtype_wq.php b/lang/ca/qtype_wq.php index f80196c0..519c13f5 100644 --- a/lang/ca/qtype_wq.php +++ b/lang/ca/qtype_wq.php @@ -74,7 +74,7 @@ $string['cachedir'] = 'CACHE_DIR:'; $string['serviceurl'] = 'SERVICE_URL:'; $string['wqsummary'] = 'This adds a generic Wiris Quizzes question. Only for test purpose. It will be hide from here.'; -$string['wirisquestionincorrect'] = 'Sorry! The system can not generate one of the questions of the quiz.
Maybe there is a temporary connection problem right now.
Maybe the question algorithm has a bug, and fails sometimes.
Maybe it will fail always.
Don\'t panic...
You can retry the quiz, without penalty, just clicking Continue.
You can also tell the Teachers that there is an issue with the question titled: \'{$a->questionname}\''; +$string['wirisquestionincorrect'] = 'El sistema no ha pogut generar una de les preguntes del qüestionari. Potser és un problema de connexió temporal, o que hi ha un problema en la configuració de la pregunta. Pots tornar a intentar aquest qüestionari sense cap penalització clicant Continuar. Si aquest error persisteix, pots dir als teus professors que hi ha un problema amb la pregunta {$a->questionname}'; $string['wirisquizzeserror'] = 'Sorry! There was an error in Wiris Quizzes.'; $string['failedtoloadwirisquizzesfromxml'] = 'Failed to load Wiris Quizzes XML definition for question id'; $string['connectionsettings'] = 'Connection settings'; @@ -95,3 +95,6 @@ $string['privacy:metadata:qtype_wq:xml'] = 'Wiris Quizzes Question XML'; $string['auxiliar_text'] = 'Escriviu un raonament opcional per a la vostra resposta:'; + +$string['corruptquestion_edit'] = 'AVÍS: Aquesta pregunta ha sigut corrompuda i se n\' perdut la informació matemàtica. Hem intentat refer tot el què hem pogut, però cal que reescriguis de nou l\'algorisme de CalcMe si la teva pregunta en tenia un, i que tornis a desar les opcions d\'entrada i validació personalitzades. Contacta amb el teu administrador per a més detalls.'; +$string['corruptquestion_attempt'] = 'La pregunta {a->questionname} ha sigut corrompuda i no s\'ha pogut carregar. Si us plau, contacta amb els teus professors perquè ho puguin arreglar.'; diff --git a/lang/en/qtype_wq.php b/lang/en/qtype_wq.php index 9498ddc7..3257f944 100644 --- a/lang/en/qtype_wq.php +++ b/lang/en/qtype_wq.php @@ -74,7 +74,7 @@ $string['cachedir'] = 'CACHE_DIR:'; $string['serviceurl'] = 'SERVICE_URL:'; $string['wqsummary'] = 'This adds a generic Wiris Quizzes question. Only for test purpose. It will be hide from here.'; -$string['wirisquestionincorrect'] = 'Sorry! The system can not generate one of the questions of the quiz.
Maybe there is a temporary connection problem right now.
Maybe the question algorithm has a bug, and fails sometimes.
Maybe it will fail always.
Don\'t panic...
You can retry the quiz, without penalty, just clicking Continue.
You can also tell the Teachers that there is an issue with the question titled: \'{$a->questionname}\''; +$string['wirisquestionincorrect'] = 'Sorry! The system can not generate one of the questions of the quiz. Maybe there is a temporary connection problem right now, or there is a problem with how the question is set up. You can retry the quiz, without penalty, just clicking Continue. If this error persists, you can tell your teachers that there is an issue with the question {$a->questionname}.'; $string['wirisquizzeserror'] = 'Sorry! There was an error in Wiris Quizzes.'; $string['failedtoloadwirisquizzesfromxml'] = 'Failed to load Wiris Quizzes XML definition for question id'; $string['connectionsettings'] = 'Connection settings'; @@ -108,3 +108,6 @@ $string['log_server_errors'] = 'Log server errors'; $string['log_server_errors_help'] = 'Extensively log errors coming from the WirisQuizzes service and other errors occurred when processing WirisQuizzes questions to your server logs. This might cause an increase in the size of your log files but might help the Wiris team troubleshoot issues.'; + +$string['corruptquestion_edit'] = 'WARNING: This question was corrupted and its mathematical data was lost from the database. We have tried to restore everything we could, but you need to rebuild the CalcMe algorithm if your question had one, and any custom input options and validation options. Contact with your administrator for further information.'; +$string['corruptquestion_attempt'] = 'The question {$a->questionname} was corrupted and could not be loaded. Please contact with your teacher so they can fix it.'; diff --git a/lang/es/qtype_wq.php b/lang/es/qtype_wq.php index d369e5a7..76ed2dad 100644 --- a/lang/es/qtype_wq.php +++ b/lang/es/qtype_wq.php @@ -74,7 +74,7 @@ $string['cachedir'] = 'CACHE_DIR:'; $string['serviceurl'] = 'SERVICE_URL:'; $string['wqsummary'] = 'This adds a generic Wiris Quizzes question. Only for test purpose. It will be hide from here.'; -$string['wirisquestionincorrect'] = 'Sorry! The system can not generate one of the questions of the quiz.
Maybe there is a temporary connection problem right now.
Maybe the question algorithm has a bug, and fails sometimes.
Maybe it will fail always.
Don\'t panic...
You can retry the quiz, without penalty, just clicking Continue.
You can also tell the Teachers that there is an issue with the question titled: \'{$a->questionname}\''; +$string['wirisquestionincorrect'] = 'El sistema no ha podido generar una de las preguntas del cuestionario. Quizá es un problema temporal de conexión, pero también puede ser que haya un problema con la configuración de la pregunta. Puedes reintentar el cuestionario sin penalización apretando Continuar. Si este error persiste, contacta con tus profesores para notificarles que hay un problema con la pregunta {$a->questionname}.'; $string['wirisquizzeserror'] = 'Sorry! There was an error in Wiris Quizzes.'; $string['failedtoloadwirisquizzesfromxml'] = 'Failed to load Wiris Quizzes XML definition for question id'; $string['connectionsettings'] = 'Connection settings'; @@ -105,3 +105,6 @@ $string['compatibility_settings_text'] = ''; $string['filtercodes_compatibility_enabled'] = 'Compatibilidad con el filtro Filter Codes'; $string['filtercodes_compatibility_enabled_help'] = 'El filtro Filter Codes no es compatible con WirisQuizzes por defecto cuando la opción "Escape Tags" está activada. Esta opción de WirisQuizzes soluciona estos problemas. No se debe activar excepto en dicha situación.'; + +$string['corruptquestion_edit'] = 'AVISO: Esta pregunta ha sido corrompida y se ha perdido su información matemática. Hemos tratado de recuperar todo lo posible, pero debes reescribir el algoritmo de CalcMe si tu pregunta tenía uno y que vuelvas a guardar las opciones de entrada y validación personalizadas. Contacta con tu administrador para más detalles.'; +$string['corruptquestion_attempt'] = 'La pregunta {a->questionname} ha sido corrompida y no se ha podido cargar. Por favor, contacta con tus profesores para que la puedan arreglar.'; diff --git a/question.php b/question.php index 0b02ac27..da95af3b 100644 --- a/question.php +++ b/question.php @@ -44,6 +44,12 @@ class qtype_wq_question extends question_graded_automatically { */ public $auxiliartextfieldlines = 10; + /** + * @var bool + * Whether this question is corrupt and its wirisquestion was removed from the database. + */ + public $corrupt = false; + public function __construct(question_definition $base = null) { $this->base = $base; } @@ -59,6 +65,13 @@ public function __construct(question_definition $base = null) { * **/ public function start_attempt(question_attempt_step $step, $variant) { global $USER; + + if ($this->corrupt) { + $a = new stdClass(); + $a->questionname = $this->name; + throw new moodle_exception('corruptquestion_attempt', 'qtype_wq', '', $a); + } + $this->base->start_attempt($step, $variant); // Get variables from Wiris Quizzes service. diff --git a/questiontype.php b/questiontype.php index 6746cd4a..98273526 100644 --- a/questiontype.php +++ b/questiontype.php @@ -101,6 +101,7 @@ protected function make_question_instance($questiondata) { protected function initialise_question_instance(question_definition $question, $questiondata) { global $CFG; + /** @var qtype_wq_question $question */ $this->base->initialise_question_instance($question->base, $questiondata); $question->id = &$question->base->id; @@ -135,10 +136,14 @@ protected function initialise_question_instance(question_definition $question, $ // Load question xml into Wiris Quizzes API question object. if (empty($question->parent)) { $builder = com_wiris_quizzes_api_Quizzes::getInstance(); - $question->wirisquestion = $builder->readQuestion($questiondata->options->wirisquestion); + if (isset($questiondata->options->wirisquestion)) { + $question->wirisquestion = $builder->readQuestion($questiondata->options->wirisquestion); + } else { + $question->wirisquestion = $builder->newQuestion(); + $question->corrupt = true; + } } } - // This method has to be overriden in each real question. public function menu_name() { // Include JavaScript Hack to modify question chooser. diff --git a/step.php b/step.php index e3355720..ec35f895 100644 --- a/step.php +++ b/step.php @@ -17,15 +17,7 @@ /* * Class used to store information in the question attempt step data - */ - -/** - * Description of step * - * @author dani - */ - -/** * This class is useful for: * - No intentar avaluar una pregunta si ha fallat en 3 intents seguits * en les mateixes condicions. Útil en exàmens. @@ -38,7 +30,8 @@ class qtype_wirisstep { const MAX_ATTEMPS_SHORTANSWER_WIRIS = 5; - private ?question_attempt_step $step; + /** @var ?question_attempt_step */ + private $step; private $stepid; private $extraprefix; diff --git a/version.php b/version.php index 7ae1a1b5..a1bcf4be 100644 --- a/version.php +++ b/version.php @@ -16,11 +16,11 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024032205; +$plugin->version = 2024032206; $plugin->requires = 2015111600; // Moodle 3.0. -$plugin->release = '4.11.5'; +$plugin->release = '4.11.6'; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'qtype_wq'; $plugin->dependencies = array( - 'filter_wiris' => 2024100700 + 'filter_wiris' => 2024110400 );