Skip to content

✨ Build v4 learning-area quiz foundation#2370

Merged
shewa12 merged 161 commits into4.0.0-devfrom
v4-quiz
Mar 11, 2026
Merged

✨ Build v4 learning-area quiz foundation#2370
shewa12 merged 161 commits into4.0.0-devfrom
v4-quiz

Conversation

@b-l-i-n-d
Copy link
Collaborator

@b-l-i-n-d b-l-i-n-d commented Feb 18, 2026

Issue

The v4 quiz flow had two maintainability and behavior risks:

  • Question field naming logic was distributed across templates with repeated string construction.
  • Quiz auto-start could trigger duplicate start requests in v4, causing multiple start attempts under some conditions.

User impact

  • Distributed field naming made template updates error-prone and increased the chance of inconsistent payload structures across question types.
  • Duplicate auto-start requests could create more than one quiz attempt and produce confusing behavior for learners.

Root cause

  • Field-name construction was not centered around a single canonical base.
  • In the v4 quiz action form, auto-start initialization was redundantly invoked by both Alpine component lifecycle and explicit template init wiring.

Fix

1) Centralized field-name composition model

  • Introduced a shared base field name in the question wrapper and passed it into question templates.
  • Templates now compose their own suffixes ([], [answers][], [answer_id][id], etc.) from that base.
  • This keeps one source of truth for the prefix while preserving per-template clarity for shape-specific keys.

2) Prevent duplicate auto-start requests (v4)

  • Removed redundant x-init="init()" from the v4 quiz auto-start form.
  • The component init() lifecycle now runs once as intended, preventing duplicate start mutations.

Validation

  • PHP lint checks run on all modified quiz wrapper/question template files and classes/Quiz.php.
  • All checked files reported no syntax errors.

Commits in this PR update

  • refactor(quiz): centralize question defaults and validation context
  • refactor(quiz): compose field names from shared base
  • fix(quiz): prevent duplicate auto-start requests in v4

…d update TypeScript module resolution settings.
…r template and improved image attachment handling.
…us and improve form input handling for multiple-choice and true-false questions.
… question types and introduce new input component for open-ended questions.
…ntax and update form component dynamic name access.
…ring questions and integrate enhanced quiz form submission.
…iz ordering and matching questions, adding clear drop zone functionality.
…oving redundant helper methods and refining order retrieval.
…nt object instead of direct element argument.
@b-l-i-n-d b-l-i-n-d requested a review from harunollyo March 9, 2026 07:18
*/
public static function render_quiz_attempts( $quiz_id ) {
// @TODO.
$quiz_id = tutor_utils()->get_post_id( $quiz_id );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not required.

* @return void
*/
public static function render_quiz_actions( $quiz_id ) {
$quiz_id = tutor_utils()->get_post_id( $quiz_id );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.

<div class="tutor-input-field <?php echo $has_image( $answer ) ? 'tutor-hidden' : ''; ?>">
<div class="tutor-input-wrapper">
<!-- @TODO: Disable checkbox when viewing quiz attempt -->
<input
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the InputField component

data-option="<?php echo esc_attr( $is_correct( $answer ) ); ?>"
<?php endif; ?>
>
<input
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the InputField component

</div>

<div class="tutor-surface-l1">
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.summary' ); ?>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why loading the demo components?


<div class="tutor-surface-l1">
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.summary' ); ?>
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the string is missing the text-domain and loading components from demo files.

@shewa12 shewa12 merged commit eff765e into 4.0.0-dev Mar 11, 2026
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0.0 Tutor v4.w0w

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants