Skip to content

Commit 1c99346

Browse files
committed
feat: Display current question number and quiz attempt progress in the learning area.
1 parent a7b7da1 commit 1c99346

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

assets/src/scss/frontend/learning-area/components/quiz/_quiz.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ $tutor-quiz-footer-offset: 96px;
255255
}
256256
}
257257

258+
&-question-meta {
259+
@include tutor-flex(row, center, space-between);
260+
@include tutor-container(792px);
261+
padding-inline: 0;
262+
263+
@include tutor-breakpoint-down(sm) {
264+
padding-inline: $tutor-spacing-6;
265+
}
266+
}
267+
268+
&-question-indicator,
269+
&-attempt-progress {
270+
@include tutor-typography('small');
271+
272+
strong {
273+
@include tutor-typography('small', 'bold');
274+
}
275+
}
276+
258277
&-questions-pagination {
259278
@include tutor-flex(row, center, center);
260279
margin-bottom: $tutor-spacing-5;

templates/learning-area/quiz/attempt.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
$reveal_wait_ms = 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' );
3737
$is_linear_layout = in_array( $question_layout_view, array( 'single_question', 'question_pagination' ), true );
3838
$show_previous_button = (bool) tutor_utils()->get_option( 'quiz_previous_button_enabled', true );
39+
$attempts_allowed = (int) tutor_utils()->get_quiz_option( $tutor_is_started_quiz->quiz_id, 'attempts_allowed', 0 );
40+
$previous_attempts = tutor_utils()->quiz_attempts();
41+
$current_attempt_number = ( is_array( $previous_attempts ) ? count( $previous_attempts ) : 0 ) + 1;
3942

4043
$reveal_question_types = array( 'true_false', 'single_choice', 'multiple_choice' );
4144
$quiz_answers = array();
@@ -152,6 +155,40 @@ class="tutor-quiz-question-paginate-item"
152155
</ul>
153156
</div>
154157
<?php endif; ?>
158+
159+
<?php if ( $is_linear_layout ) : ?>
160+
<div class="tutor-quiz-question-meta">
161+
<div class="tutor-quiz-question-indicator">
162+
<?php
163+
echo wp_kses(
164+
sprintf(
165+
/* translators: %s: question number indicator (e.g. 01/15) */
166+
__( 'Question No: %s', 'tutor' ),
167+
'<strong x-text="String(currentIndex).padStart(2, \'0\') + \'/\' + String(totalQuestions).padStart(2, \'0\')"></strong>'
168+
),
169+
array(
170+
'strong' => array(
171+
'x-text' => true,
172+
),
173+
)
174+
);
175+
?>
176+
</div>
177+
<div class="tutor-quiz-attempt-progress">
178+
<?php
179+
echo wp_kses(
180+
sprintf(
181+
/* translators: %s: allowed attempts (number or ∞) */
182+
__( 'Total Attempt: %s', 'tutor' ),
183+
'<strong>' . esc_html( $current_attempt_number ) . '/' . ( 0 === $attempts_allowed ? '&infin;' : esc_html( $attempts_allowed ) ) . '</strong>'
184+
),
185+
array( 'strong' => array() )
186+
);
187+
?>
188+
</div>
189+
</div>
190+
<?php endif; ?>
191+
155192
<?php
156193
foreach ( $questions as $index => $question ) {
157194
$question_settings = maybe_unserialize( $question->question_settings );

0 commit comments

Comments
 (0)