Skip to content
Draft
11 changes: 11 additions & 0 deletions assets/core/scss/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@
padding: $tutor-spacing-5 $tutor-spacing-7;
border-top: 1px solid $tutor-border-idle;
}

&-confirmation-actions {
display: flex;
flex-wrap: wrap;

> * {
flex: 1 1 calc(50% - #{$tutor-spacing-4 * 0.5});
max-width: 100%;
white-space: nowrap;
}
}
}

@include tutor-breakpoint-down(md) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const NegativeMarkTypeMismatchModalContent = ({
const descriptionHtml = isSwitchingToPoints
? sprintf(
// translators: 1: current penalty percentage (e.g. 15%), 2: new penalty placeholder ({new penalty})
__('The penalty per wrong answer will change from %1$s to <strong>%2$s</strong> points.', 'tutor'),
__('The penalty per question will change from %1$s to <strong>%2$s</strong> points.', 'tutor'),
`${currentPenalty}%`,
adminNegativeMarkValue,
)
: sprintf(
// translators: 1: current penalty points (e.g. 15), 2: new penalty placeholder ({new penalty})
__('The penalty per wrong answer will change from %1$s points to <strong>%2$s</strong>%%.', 'tutor'),
__('The penalty per question will change from %1$s points to <strong>%2$s</strong>%%.', 'tutor'),
currentPenalty,
adminNegativeMarkValue,
);
Expand Down Expand Up @@ -80,15 +80,12 @@ const NegativeMarkTypeMismatchNotice = () => {
const mismatchNoticeText = isSwitchingToPoints
? sprintf(
// translators: %s is the current percentage penalty, e.g. 15
__('The default penalty unit is now points. This quiz still uses a %s%% penalty per wrong answer.', 'tutor'),
__('The default penalty unit is now points. This quiz still uses a %s%% penalty per question.', 'tutor'),
negativeMarkValue ?? 0,
)
: sprintf(
// translators: %s is the current points penalty, e.g. 15
__(
'The default penalty unit is now percentage. This quiz still uses a %s pts penalty per wrong answer.',
'tutor',
),
__('The default penalty unit is now percentage. This quiz still uses a %s pts penalty per question.', 'tutor'),
negativeMarkValue ?? 0,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,10 @@ const AssignmentModal = ({
{...controllerProps}
type="number"
label={__('Maximum Resubmission Attempts', 'tutor')}
helpText={__('Set how many times students can resubmit even after the deadline.', 'tutor')}
helpText={__(
'Set the resubmission limit. Failed learners can retry even after the deadline.',
'tutor',
)}
selectOnFocus
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,16 @@
overflow: hidden;

&:has(.tutor-quiz-review-item-title) {
@include tutor-flex(column, flex-start, center);
@include tutor-flex(column, flex-start, flex-start);

gap: $tutor-spacing-none;

.tutor-quiz-review-item-text {
@include tutor-flex(row, center);

flex: 1;
width: 100%;
}
}

.tutor-quiz-review-item-title {
Expand Down
1 change: 1 addition & 0 deletions assets/src/scss/frontend/components/_quiz-attempts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
gap: $tutor-spacing-1;

.tutor-quiz-marks-correct,
.tutor-quiz-marks-partial,
.tutor-quiz-marks-incorrect {
@include tutor-badge-base();

Expand Down
10 changes: 8 additions & 2 deletions assets/src/scss/frontend/dashboard/_billing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@

gap: $tutor-spacing-4;
color: $tutor-text-secondary;

@include tutor-breakpoint-down(sm) {
flex-wrap: wrap;
row-gap: $tutor-spacing-2;
}
}

&-id {
Expand All @@ -173,13 +178,14 @@

&-payment-method {
@include tutor-breakpoint-down(sm) {
.tutor-badge {
.tutor-badge:has(img, svg) {
font-size: 0;
line-height: 0;
gap: 0;
padding: $tutor-spacing-2;

img {
img,
svg {
display: block;
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/Quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -2807,7 +2807,7 @@ public static function render_quiz_actions( $quiz_id ) {
->id( $retry_modal_id )
->title( __( 'Retry Quiz?', 'tutor' ) )
->icon( tutor_utils()->get_themed_svg( 'images/illustrations/quiz-retry.svg' ), 80, 80, ConfirmationModal::ICON_TYPE_HTML )
->message( __( 'Retrying this quiz will reset your current attempt. Your answers and score from this attempt will be lost.', 'tutor' ) )
->message( __( 'You can take this quiz again. Your earlier attempts stay on your record.', 'tutor' ) )
->confirm_handler( 'retryMutation?.mutate({...payload?.data})' )
->confirm_text( __( 'Retry Quiz', 'tutor' ) )
->mutation_state( 'retryMutation' )
Expand Down
80 changes: 76 additions & 4 deletions classes/Quiz_Attempts_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,60 @@ public static function render_quiz_attempt_marks_percentage( $attempt_result = '
->render();
}

/**
* Render quiz attempt stats items.
*
* @since 4.3.0
*
* @param array $attempt Formatted quiz attempt data.
*
* @return void
*/
public static function render_quiz_attempt_stats( array $attempt ): void {
$correct_answers = (int) ( $attempt['correct_answers'] ?? 0 );
$incorrect_answers = (int) ( $attempt['incorrect_answers'] ?? 0 );

$items = array(
'correct' => array(
'class' => 'tutor-quiz-marks-correct',
'label' => sprintf(
/* translators: %d: number of correct answers */
_n( '%d correct', '%d correct', $correct_answers, 'tutor' ),
$correct_answers
),
),
'incorrect' => array(
'class' => 'tutor-quiz-marks-incorrect',
'label' => sprintf(
/* translators: %d: number of incorrect answers */
_n( '%d incorrect', '%d incorrect', $incorrect_answers, 'tutor' ),
$incorrect_answers
),
),
);

/**
* Filters the stats items rendered in quiz attempt history.
*
* @since 4.3.0
*
* @param array $items Associative array of `key => [ 'class' => string, 'label' => string ]`.
* @param array $attempt Formatted quiz attempt data.
*/
$items = apply_filters( 'tutor_quiz_attempt_stats', $items, $attempt );
?>
<div class="tutor-quiz-marks-breakdown">
<?php foreach ( $items as $item ) : ?>
<?php if ( is_array( $item ) && ! empty( $item['label'] ) ) : ?>
<div class="<?php echo esc_attr( $item['class'] ?? '' ); ?>">
<?php echo esc_html( $item['label'] ); ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php
}

/**
* Get quiz attempt summary statics in render order.
*
Expand All @@ -651,7 +705,9 @@ public static function render_quiz_attempt_marks_percentage( $attempt_result = '
* @return array
*/
public static function get_quiz_attempt_summary_statics( $attempt_data, $answers ) {
$answer_counts = QuizModel::get_attempt_answer_counts( $answers );
$total_questions = is_object( $attempt_data ) ? (int) ( $attempt_data->total_questions ?? 0 ) : 0;
$answer_counts = QuizModel::get_attempt_answer_counts( $answers, $total_questions );
$skipped_count = (int) ( $answer_counts['skipped'] ?? 0 );

/**
* Build a count label with the number wrapped in markup,
Expand Down Expand Up @@ -686,11 +742,20 @@ public static function get_quiz_attempt_summary_statics( $attempt_data, $answers
),
'count' => (int) $answer_counts['incorrect'],
),
'skipped' => array(
'class' => 'skipped',
'label' => $format_count_label(
$skipped_count,
/* translators: %1$s: number of skipped questions, wrapped in markup. */
_n( '%1$s skipped', '%1$s skipped', $skipped_count, 'tutor' )
),
'count' => $skipped_count,
),
'total' => array(
'class' => 'total',
/* translators: %1$s: total number of questions, wrapped in markup. */
'label' => $format_count_label( $attempt_data->total_questions, __( '%1$s total', 'tutor' ) ),
'count' => (int) $attempt_data->total_questions,
'label' => $format_count_label( $total_questions, __( '%1$s total', 'tutor' ) ),
'count' => $total_questions,
),
);

Expand Down Expand Up @@ -721,7 +786,14 @@ public static function get_quiz_attempt_summary_statics( $attempt_data, $answers
*
* @return array Ordered associative array of `key => item` pairs.
*/
return apply_filters( 'tutor_quiz_attempt_summary_statics', $static_items, $attempt_data, $answers );
$static_items = apply_filters( 'tutor_quiz_attempt_summary_statics', $static_items, $attempt_data, $answers );

return array_filter(
$static_items,
static function ( $item ) {
return is_array( $item ) && (int) ( $item['count'] ?? 0 ) > 0;
}
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion components/ConfirmationModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class="tutor-btn tutor-btn-secondary tutor-btn-small"
</p>
</div>

<div class="tutor-grid tutor-grid-cols-2 tutor-gap-4 tutor-px-7 tutor-pb-6">
<div class="tutor-modal-confirmation-actions tutor-gap-4 tutor-px-7 tutor-pb-6">
%s
%s
</div>
Expand Down
24 changes: 20 additions & 4 deletions models/QuizModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public static function format_quiz_attempts( array $quiz_attempts, string $resul
'marks_percent' => $earned_percent ?? 0,
'correct_answers' => $correct_answers,
'incorrect_answers' => $incorrect_answers,
'answer_counts' => $answer_counts,
'time_taken' => $attempt_time ?? '',
'date' => self::get_attempt_date( $quiz_attempt ),
'quiz_title' => $quiz_title,
Expand Down Expand Up @@ -1285,30 +1286,45 @@ public static function render_attempt_answer_badge( $attempt_answer, array $opti
/**
* Get attempt answer counts categorized by status.
*
* Fully correct answers are counted under 'correct' and incorrect answers under 'incorrect'.
* Pending, graded, and skipped answers are excluded.
* Fully correct answers are counted under 'correct', incorrect answers under 'incorrect',
* and skipped answers under 'skipped'. When total quiz questions is provided and exceeds
* non-skipped answer rows (e.g. when skipped rows were filtered out or not inserted),
* remaining questions are counted as 'skipped'. Pending and graded answers are excluded
* unless extended via the `tutor_quiz_attempt_answer_counts` filter.
*
* @since 4.1.0
* @since 4.3.0 Added skipped count and optional `$total_questions` parameter.
*
* @param array|null $answers List of answer objects.
* @param array|null $answers List of answer objects.
* @param int $total_questions Optional total questions in the quiz attempt.
*
* @return array Associative array with answer status counts.
*/
public static function get_attempt_answer_counts( $answers ): array {
public static function get_attempt_answer_counts( $answers, int $total_questions = 0 ): array {
$counts = array(
'correct' => 0,
'incorrect' => 0,
'skipped' => 0,
);

$answered_count = 0;

if ( is_array( $answers ) ) {
foreach ( $answers as $answer ) {
$status = self::get_attempt_answer_status( $answer );
if ( 'skipped' !== $status ) {
++$answered_count;
}
if ( isset( $counts[ $status ] ) ) {
++$counts[ $status ];
}
}
}

if ( $total_questions > $answered_count ) {
$counts['skipped'] = max( $counts['skipped'], $total_questions - $answered_count );
}

return apply_filters( 'tutor_quiz_attempt_answer_counts', $counts, $answers );
}

Expand Down
14 changes: 8 additions & 6 deletions templates/dashboard/account/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* template: templates/account.php
*
* @var string $back_url
* @var string|null $close_url
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -92,7 +93,7 @@ function ( $tab ) {

return {
...tabs,
backUrl: <?php echo esc_attr( tutor_json_encode( $back_url ) ); ?>,
closeUrl: <?php echo esc_attr( tutor_json_encode( $close_url ?? $back_url ) ); ?>,
viewportWidth: window.innerWidth,
hasInitialUrlTab: tabs.tabs.some((tab) => tab.id === initialTab),
handleViewportResize() {
Expand Down Expand Up @@ -126,13 +127,14 @@ function ( $tab ) {

return tabs.selectTab.call(this, tabId);
},
handleClose() {
if (window.innerWidth < 768 && this.activeTab !== 'none') {
handleBack(event) {
if (window.innerWidth <= 768 && this.activeTab !== 'none') {
event?.preventDefault();
this.selectTab('none');
return;
}

window.location.href = this.backUrl;
},
handleClose() {
window.location.href = this.closeUrl;
},
};
})()"
Expand Down
1 change: 1 addition & 0 deletions templates/dashboard/account/settings/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class="tutor-profile-header-left tutor-flex tutor-items-center"
->icon_only()
->flip_rtl()
->attr( 'href', esc_url( $back_url ) )
->attr( '@click', 'handleBack($event)' )
->render();
?>
<h4
Expand Down
30 changes: 2 additions & 28 deletions templates/dashboard/components/quiz-attempt-row.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Tutor\Components\PreviewTrigger;
use TUTOR\Icon;
use TUTOR\Quiz_Attempts_List;
use Tutor\Components\SvgIcon;
use Tutor\Components\Constants\Color;

Expand Down Expand Up @@ -51,34 +52,7 @@
<div x-data="tutorStatics({ value: <?php echo (float) ( $attempt['marks_percent'] ?? 0 ); ?>, type: 'progress' })">
<div x-html="render()"></div>
</div>
<div class="tutor-quiz-marks-breakdown">
<div class="tutor-quiz-marks-correct">
<?php
$correct_answers = $attempt['correct_answers'] ?? 0;

echo esc_html(
sprintf(
/* translators: %d: number of correct answers */
_n( '%d correct', '%d correct', $correct_answers, 'tutor' ),
$correct_answers
)
);
?>
</div>
<div class="tutor-quiz-marks-incorrect">
<?php
$incorrect_answers = $attempt['incorrect_answers'] ?? 0;

echo esc_html(
sprintf(
/* translators: %d: number of incorrect answers */
_n( '%d incorrect', '%d incorrect', $incorrect_answers, 'tutor' ),
$incorrect_answers
)
);
?>
</div>
</div>
<?php Quiz_Attempts_List::render_quiz_attempt_stats( $attempt ); ?>
</div>

<div class="tutor-quiz-item-time">
Expand Down
Loading
Loading