Skip to content

Exercise: Export exact combination questions to QTI2 - refs #2263 - #9482

Merged
christianbeeznest merged 1 commit into
chamilo:masterfrom
ybtbeez:fix/issue-2263-qti-exact-combination
Nov 17, 2026
Merged

christianbeeznest merged 1 commit into
chamilo:masterfrom
ybtbeez:fix/issue-2263-qti-exact-combination

Conversation

@ybtbeez

@ybtbeez ybtbeez commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #2263

What

Exact combination questions (type 9) were left out of the QTI 2 export. Both exporters now include them, and both importers read them back as Exact combination.

Export (legacy export_question_qti() and ExerciseQti2ExportService). Both use the new shared Qti2ExactCombinationWriter:

  • a choiceInteraction with maxChoices="0", so any number of choices can be ticked (the QTI default is 1);
  • a responseDeclaration with cardinality="multiple" and a correctResponse holding the correct choices. There is no <mapping>, so no partial credit;
  • a responseProcessing that sets SCORE to the question score when <match> compares the response with the correct response, and 0 otherwise. match compares multiple containers as sets, so this is all or nothing, as in Exercise::manage_answer(). The SCORM exporter uses the same logic;
  • the score is the weight of the first answer, which is where Chamilo stores it, falling back to the question score.

Import (legacy exercise_import.inc.php and ExerciseQti2ImportService):

  • A multiple-response item is read as Exact combination only when its responseProcessing is that exact-match condition setting SCORE.
  • The score goes on the first answer and the other answers weigh 0, as when the question is created in Chamilo. The question score is set to the same value.
  • Items with a template or a mapping, including the existing Multiple answer export, keep their current import.

Type 12 (Exact combination True/False/Don't know) is not exported. In QTI it would need a statement × True/False/Don't know matchInteraction. Those three options are interface strings, not stored data, and both importers read any matchInteraction as Matching (scored per pair). So it would not come back as type 12 without inventing an identifier convention. Type 12 extends the Exact combination class, so the legacy exporter now checks type 9 by its number, not by class, to keep type 12 out.

Tests

tests/CoreBundle/Service/Exercise/ExerciseQti2ExactCombinationTest.php: 8 tests, 86 assertions.

  • API export XML: maxChoices="0", multiple cardinality, the correct response holds only the correct choices, no mapping, and the score and 0 branches.
  • API export round trip: the export goes through both importers and comes back as type 9, with the same correct answers, the score on the first answer and the question score.
  • Legacy ImsAssessmentItem export: the same XML checks, plus the round trip through both importers.
  • Score fallback: the question score is used when the first answer has no weight.
  • Type 12 is not exported.
  • Escaping: answer text containing <script> and ]]> still gives well-formed XML.
  • Regression: a plain Multiple answer item using the map_response template is still imported as Multiple answer.
  • readScore(): it only accepts the exact-match processing, and a negative score is read as 0.

The existing QTI tests still pass: ExerciseQti2FillBlanksExportTest, ExerciseQti2ImportServiceTest and LegacyQti2ImportMatchingTest, 36 tests across the QTI filter. ExerciseAccessControlTest passes too (14).

Linters:

  • ECS and PHPStan (level 6) report no findings on the changed src and test files.
  • Psalm reports no errors on all changed files, legacy ones included.
  • php -l is clean on the legacy files.

Security (OWASP)

  • XXE: parsing is unchanged (no network access, no entity loading). readScore() only walks the DOM that is already parsed.
  • XSS / injection:
    • Answer and prompt text go through the existing formatExerciseQtiText()/CDATA path on export, and through the same HTML sanitising as Multiple answer on import.
    • The new XML attributes and values are escaped with htmlspecialchars(ENT_QUOTES | ENT_SUBSTITUTE | ENT_XML1). The identifiers are built from integer ids.
    • The imported score must be numeric and finite, and is clamped at 0 or more.
  • Access control / CSRF: the export and import controllers and their permission checks are unchanged.
  • Path traversal: no file handling changed.
  • DoS: no new loops beyond the elements of the parsed document.
  • Verdict: no new risk.

Notes for review

  • The existing Multiple answer export also has no maxChoices, so strict QTI players may limit it to one choice. I didn't change it here, to keep this PR to type 9.
  • An Exact combination question with no correct answer is exported without a correctResponse and scores 0. In Chamilo, ticking nothing would get the full score. This is an edge case I left as it is.
  • The legacy exporter identifies choices by answer position (answer_1) and the API exporter by answer iid. This was already the case for the other choice types.
  • Generic QTI items using the match_correct template are not mapped to Exact combination. Only the processing written by this exporter is recognised.

Release note

QTI 2 export now includes Exact combination questions, scored all or nothing, and importing that export brings them back as Exact combination questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exportación QTI ignora preguntas combinación exacta

2 participants