Skip to content

Commit

Permalink
Merge pull request #7129 from Automattic/add/change-style-of-submitte…
Browse files Browse the repository at this point in the history
…d-quizzes

Update stylings of quiz questions in the submitted state in learning mode
  • Loading branch information
Imran92 authored Sep 11, 2023
2 parents 327c9e9 + 80e18cb commit 9daba73
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 29 deletions.
8 changes: 8 additions & 0 deletions assets/blocks/quiz/question-block/question.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ $question-input-border-color: var(--wp--preset--color--foreground, #155E65 );
line-height: 1;
}
}

.wp-block-sensei-lms-question-answers__filename {
margin-bottom: 20px;
}

.wp-block-sensei-lms-question-answers__preview {
max-height: 480px;
}
}

.wp-block-sensei-lms-question-answers {
Expand Down
14 changes: 14 additions & 0 deletions assets/css/3rd-party/themes/course/quiz.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
@import '../../../../shared/styles/variables';

.wp-block-sensei-lms-quiz {
.wp-block-sensei-lms-question-answers {
&__answer {
color: $gray-50;
}

&__preview {
border: 1px solid var(--wp--preset--color--foreground);
border-radius: 4px;
}
}
}
.quiz {
.sensei-course-theme__quiz {
&__main-content {
Expand Down
6 changes: 1 addition & 5 deletions assets/css/frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ a.sensei-certificate-link {
}
}

.submitted_file {
font-weight: bold;
}

.reupload_notice {
font-style: italic;
margin-bottom: 5px;
Expand Down Expand Up @@ -364,7 +360,7 @@ a.sensei-certificate-link {
list-style: none;

input {
margin: 0 .382em 0 0;
margin: 0 10px 0 0;
}

label {
Expand Down
16 changes: 16 additions & 0 deletions assets/css/sensei-course-theme/quiz-compat.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This file loads for all themes except Course. */
@import '../../shared/styles/variables';
@import '~@wordpress/base-styles/breakpoints';

$textColor: #1E1E1E;
Expand All @@ -23,6 +24,21 @@ $textColor: #1E1E1E;
& * {
font-size: 1.125rem;
}

&__filename {
color: $textColor;
font-size: 18px;
font-style: normal;
font-weight: 400;

a {
color: #155E65
}
}

&__answer {
color: $gray-50;
}
}

.wp-block-sensei-lms-quiz {
Expand Down
15 changes: 9 additions & 6 deletions assets/css/sensei-course-theme/quiz.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,30 @@ $vertical-spacing-desktop: 80px;
border: 6px solid var(--wp--preset--color--foreground, var(--sensei-secondary-color, #949494) );
}


input[type="radio"]:disabled:not(:checked),
input[type="radio"]:disabled:not(:checked) + label,
input[type="checkbox"]:disabled:not(:checked),
input[type="checkbox"]:disabled:not(:checked) + label {
opacity: 0.4;
}

.sensei-multiple-choice-answer-option-checkbox {
display: none;

& + label {
display: flex;
align-items: center;
gap: 10px;
}

& + label:before {
align-items: center;
border-radius: 2px;
content: "\00a0";
display: flex;
font-size: 1.1rem;
justify-content: center;
align-items: center;
margin-right: 10px;
padding: 0;
vertical-align: center;
border-radius: 2px;
margin-right: var(--wp--custom--comment-gap-small);
}

&:checked + label:before {
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-change-style-of-submitted-quizzes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Update style of quiz questions that have been submitted for grading
4 changes: 4 additions & 0 deletions changelog/template-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: development

Update question type templates
3 changes: 3 additions & 0 deletions includes/blocks/class-sensei-quiz-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function initialize_blocks() {
[ 'sensei-lms/quiz-question' ],
];
$post_type_object->template_lock = 'insert';

// The checkboxes look broken otherwise because the checkmark comes from dashicons.
wp_enqueue_style( 'dashicons' );
}


Expand Down
26 changes: 25 additions & 1 deletion includes/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,31 @@ function sensei_the_question_content() {
?>

<div class="wp-block-sensei-lms-question-answers">
<?php Sensei_Question::load_question_template( $question_type ); ?>
<?php
/**
* Fires before the question answers are displayed inside the answers block.
*
* @hook sensei_quiz_question_answers_inside_before
*
* @since $$next-version$$
*
* @param {int} $question_id The ID of the question.
*/
do_action( 'sensei_quiz_question_answers_inside_before', $sensei_question_loop['current_question']->ID );

Sensei_Question::load_question_template( $question_type );

/**
* Fires after the question answers are displayed inside the answers block.
*
* @hook sensei_quiz_question_answers_inside_after
*
* @since $$next-version$$
*
* @param {int} $question_id The ID of the question.
*/
do_action( 'sensei_quiz_question_answers_inside_after', $sensei_question_loop['current_question']->ID );
?>
</div>

<?php
Expand Down
10 changes: 8 additions & 2 deletions templates/single-quiz/question-type-file-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Automattic
* @package Sensei
* @category Templates
* @version 2.0.0
* @version $$next-version$$
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -22,6 +22,7 @@
*/
$question_data = Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );

$sensei_is_quiz_view_only_mode = $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available();
?>

<?php if ( $question_data['question_helptext'] ) { ?>
Expand All @@ -35,7 +36,7 @@

<?php if ( $question_data['answer_media_url'] && $question_data['answer_media_filename'] ) { ?>

<p class="submitted_file">
<p class="wp-block-sensei-lms-question-answers__filename">

<?php
printf(
Expand All @@ -48,6 +49,11 @@
?>

</p>

<?php if ( $sensei_is_quiz_view_only_mode && getimagesize( $question_data['answer_media_url'] ) ) { ?>
<img src="<?php echo esc_url( $question_data['answer_media_url'] ); ?>" class="wp-block-sensei-lms-question-answers__preview" />
<?php } ?>

<?php if ( ! $question_data['quiz_is_completed'] ) { ?>

<aside class="reupload_notice"><?php esc_html_e( 'Uploading a new file will replace your existing one:', 'sensei-lms' ); ?></aside>
Expand Down
22 changes: 15 additions & 7 deletions templates/single-quiz/question-type-gap-fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Automattic
* @package Sensei
* @category Templates
* @version 2.3.0
* @version $$next-version$$
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -19,18 +19,26 @@
* All data is loaded in this array to keep the template clean.
*/
$question_data = Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );

$sensei_is_quiz_view_only_mode = $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available();
?>


<p class="gapfill-answer">
<span class="gapfill-answer-pre">
<?php echo wp_kses_post( apply_filters( 'sensei_answer_text', esc_html( $question_data['gapfill_pre'] ) ) ); ?>
<input type="text" id="<?php echo esc_attr( 'question_' . $question_data['ID'] ); ?>"
name="<?php echo esc_attr( 'sensei_question[' . $question_data['ID'] . ']' ); ?>"
value="<?php echo esc_attr( $question_data['user_answer_entry'] ); ?>"
class="gapfill-answer-gap"
<?php echo $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available() ? 'disabled' : ''; ?>
/>
<?php if ( $sensei_is_quiz_view_only_mode ) { ?>
<span class="wp-block-sensei-lms-question-answers__answer">
<?php echo wp_kses_post( $question_data['user_answer_entry'] ); ?>
</span>
<?php } else { ?>
<input type="text" id="<?php echo esc_attr( 'question_' . $question_data['ID'] ); ?>"
name="<?php echo esc_attr( 'sensei_question[' . $question_data['ID'] . ']' ); ?>"
value="<?php echo esc_attr( $question_data['user_answer_entry'] ); ?>"
class="gapfill-answer-gap"
<?php echo $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available() ? 'disabled' : ''; ?>
/>
<?php } ?>
<span class="gapfill-answer-post">
<?php echo wp_kses_post( apply_filters( 'sensei_answer_text', esc_html( $question_data['gapfill_post'] ) ) ); ?>
</span>
Expand Down
21 changes: 15 additions & 6 deletions templates/single-quiz/question-type-multi-line.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Automattic
* @package Sensei
* @category Templates
* @version 2.0.0
* @version $$next-version$$
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -20,9 +20,18 @@
*/
$question_data = Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );

Sensei_Utils::sensei_text_editor(
$question_data['user_answer_entry'],
'textquestion' . $question_data['ID'],
'sensei_question[' . $question_data['ID'] . ']'
);
$sensei_is_quiz_view_only_mode = $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available();

if ( $sensei_is_quiz_view_only_mode ) {
?>
<div class="wp-block-sensei-lms-question-answers__answer">
<?php echo wp_kses_post( $question_data['user_answer_entry'] ); ?>
</div>
<?php
} else {
Sensei_Utils::sensei_text_editor(
$question_data['user_answer_entry'],
'textquestion' . $question_data['ID'],
'sensei_question[' . $question_data['ID'] . ']'
);
}
12 changes: 10 additions & 2 deletions templates/single-quiz/question-type-single-line.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Automattic
* @package Sensei
* @category Templates
* @version 2.0.0
* @version $$next-version$$
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -20,15 +20,23 @@
*/
$question_data = Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );

$sensei_is_quiz_view_only_mode = $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available();

?>

<div class="answer">

<input type="text" id="<?php echo esc_attr( 'question_' . $question_data['ID'] ); ?>"
<?php if ( $sensei_is_quiz_view_only_mode ) { ?>
<div class="wp-block-sensei-lms-question-answers__answer">
<?php echo wp_kses_post( $question_data['user_answer_entry'] ); ?>
</div>
<?php } else { ?>
<input type="text" id="<?php echo esc_attr( 'question_' . $question_data['ID'] ); ?>"
name="<?php echo esc_attr( 'sensei_question[' . $question_data['ID'] . ']' ); ?>"
placeholder="<?php echo esc_attr__( 'Your answer', 'sensei-lms' ); ?>"
value="<?php echo esc_attr( $question_data['user_answer_entry'] ); ?>"
<?php echo $question_data['quiz_is_completed'] || ! Sensei_Quiz::is_quiz_available() ? 'disabled' : ''; ?>
/>
<?php } ?>

</div>

0 comments on commit 9daba73

Please sign in to comment.