+ case 'type':
+ ?>
+
+
+ |
+ question_type ) {
- $ordering_ids = maybe_unserialize( $answer->given_answer );
- foreach ( $ordering_ids as $ordering_id ) {
- $get_answers = tutor_utils()->get_answer_by_id( $ordering_id );
- tutor_render_answer_list( $get_answers );
- }
- }
-
- // Matching.
- elseif ( 'matching' === $answer->question_type ) {
-
- $ordering_ids = maybe_unserialize( $answer->given_answer );
- $original_saved_answers = QuizModel::get_answers_by_quiz_question( $answer->question_id );
-
- $answers = array();
-
- foreach ( $original_saved_answers as $key => $original_saved_answer ) {
- $provided_answer_order_id = isset( $ordering_ids[ $key ] ) ? $ordering_ids[ $key ] : 0;
- $provided_answer_order = tutor_utils()->get_answer_by_id( $provided_answer_order_id );
- if ( tutor_utils()->count( $provided_answer_order ) ) {
- foreach ( $provided_answer_order as $provided_answer_order ) {
- if ( $is_image_matching ) {
- $original_saved_answer->answer_view_format = 'text_image';
- $original_saved_answer->answer_title = $provided_answer_order->answer_title;
- $original_saved_answer->answer_two_gap_match = '';
- $answers[] = $original_saved_answer;
- } else {
- $original_saved_answer->answer_two_gap_match = $provided_answer_order->answer_two_gap_match;
- $answers[] = $original_saved_answer;
- }
- }
- }
- }
-
- tutor_render_answer_list( $answers );
- } elseif ( 'image_matching' === $answer->question_type ) {
-
- $ordering_ids = maybe_unserialize( $answer->given_answer );
- $original_saved_answers = QuizModel::get_answers_by_quiz_question( $answer->question_id );
-
- $answers = array();
-
- foreach ( $original_saved_answers as $key => $original_saved_answer ) {
- $provided_answer_order_id = isset( $ordering_ids[ $key ] ) ? $ordering_ids[ $key ] : 0;
- $provided_answer_order = tutor_utils()->get_answer_by_id( $provided_answer_order_id );
- foreach ( $provided_answer_order as $p_answer ) {
- if ( $p_answer->answer_title ) {
- $original_saved_answer->answer_view_format = 'text_image';
- $original_saved_answer->answer_title = $p_answer->answer_title;
- $answers[] = $original_saved_answer;
- }
- }
- }
-
- tutor_render_answer_list( $answers );
- } elseif ( 'image_answering' === $answer->question_type ) {
-
- $ordering_ids = maybe_unserialize( $answer->given_answer );
-
- $answers = array();
+ case 'questions':
+ ?>
+
+
+ question_title ) ); ?>
+
+ |
+ $image_answer ) {
- $db_answers = tutor_utils()->get_answer_by_id( $answer_id );
- foreach ( $db_answers as $db_answer ) {
+ case 'given_answer':
+ ?>
+
+
+ question_type ) {
+ $get_answers = tutor_utils()->get_answer_by_id( $answer->given_answer );
+ tutor_render_answer_list( $get_answers );
+ }
+
+
+ // True false or single choice.
+ if ( 'true_false' === $answer->question_type ) {
+ $get_answers = tutor_utils()->get_answer_by_id( $answer->given_answer );
+ $answer_titles = wp_list_pluck( $get_answers, 'answer_title' );
+ $answer_titles = array_map( 'stripslashes', $answer_titles );
+
+ echo ' ' .
+ implode( '', $answer_titles ) . //phpcs:ignore
+ ' ';
+ }
+
+ // Multiple choice.
+ elseif ( 'multiple_choice' === $answer->question_type ) {
+ $get_answers = tutor_utils()->get_answer_by_id( maybe_unserialize( $answer->given_answer ) );
+ tutor_render_answer_list( $get_answers );
+ }
+
+ // Fill in the blank.
+ elseif ( 'fill_in_the_blank' === $answer->question_type ) {
+ $answer_titles = maybe_unserialize( $answer->given_answer );
+ $get_db_answers_by_question = QuizModel::get_answers_by_quiz_question( $answer->question_id );
+
+ echo tutor_render_fill_in_the_blank_answer( $get_db_answers_by_question, $answer_titles ); //phpcs:ignore --contain safe data
+ }
+
+ // Open ended or short answer.
+ elseif ( 'open_ended' === $answer->question_type || 'short_answer' === $answer->question_type ) {
+ if ( $answer->given_answer ) {
+ echo wp_kses(
+ wpautop( stripslashes( $answer->given_answer ) ),
+ array(
+ 'p' => true,
+ 'span' => true,
+ )
+ );
+ }
+ }
+
+ // Ordering.
+ elseif ( 'ordering' === $answer->question_type ) {
+ $ordering_ids = maybe_unserialize( $answer->given_answer );
+ foreach ( $ordering_ids as $ordering_id ) {
+ $get_answers = tutor_utils()->get_answer_by_id( $ordering_id );
+ tutor_render_answer_list( $get_answers );
+ }
+ }
+
+ // Matching.
+ elseif ( 'matching' === $answer->question_type ) {
+
+ $ordering_ids = maybe_unserialize( $answer->given_answer );
+ $original_saved_answers = QuizModel::get_answers_by_quiz_question( $answer->question_id );
+
+ $answers = array();
+
+ foreach ( $original_saved_answers as $key => $original_saved_answer ) {
+ $provided_answer_order_id = isset( $ordering_ids[ $key ] ) ? $ordering_ids[ $key ] : 0;
+ $provided_answer_order = tutor_utils()->get_answer_by_id( $provided_answer_order_id );
+ if ( tutor_utils()->count( $provided_answer_order ) ) {
+ foreach ( $provided_answer_order as $provided_answer_order ) {
+ if ( $is_image_matching ) {
+ $original_saved_answer->answer_view_format = 'text_image';
+ $original_saved_answer->answer_title = $provided_answer_order->answer_title;
+ $original_saved_answer->answer_two_gap_match = '';
+ $answers[] = $original_saved_answer;
+ } else {
+ $original_saved_answer->answer_two_gap_match = $provided_answer_order->answer_two_gap_match;
+ $answers[] = $original_saved_answer;
}
- $db_answer->answer_title = $image_answer;
- $db_answer->answer_view_format = 'text_image';
- $answers[] = $db_answer;
-
}
-
- tutor_render_answer_list( $answers );
- } else {
- /**
- * Allow Pro and add-ons to render given answer for custom question types.
- * Pro handles draw_image and pin_image via this action.
- *
- * @param object $answer Answer object.
- */
- do_action( 'tutor_quiz_render_given_answer_for_question_type', $answer );
}
- ?>
-
- |
-
-
-
- question_type != 'open_ended' && $answer->question_type != 'short_answer' ) ) {
-
- global $wpdb;
-
- // True false.
- if ( 'true_false' === $answer->question_type ) {
- $correct_answer = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT answer_title FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='true_false'
- AND is_correct = 1",
- $answer->question_id
- )
- );
+ }
- echo '' .
- esc_html( $correct_answer ) .
- '';
- }
+ tutor_render_answer_list( $answers );
+ } elseif ( 'image_matching' === $answer->question_type ) {
- // Single choice.
- elseif ( 'single_choice' === $answer->question_type ) {
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_view_format
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='single_choice' AND
- is_correct = 1",
- $answer->question_id
- )
- );
+ $ordering_ids = maybe_unserialize( $answer->given_answer );
+ $original_saved_answers = QuizModel::get_answers_by_quiz_question( $answer->question_id );
- tutor_render_answer_list( $correct_answer );
- }
+ $answers = array();
- // Multiple choice.
- elseif ( 'multiple_choice' === $answer->question_type ) {
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_view_format
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='multiple_choice'
- AND is_correct = 1 ;",
- $answer->question_id
- )
- );
-
- tutor_render_answer_list( $correct_answer );
+ foreach ( $original_saved_answers as $key => $original_saved_answer ) {
+ $provided_answer_order_id = isset( $ordering_ids[ $key ] ) ? $ordering_ids[ $key ] : 0;
+ $provided_answer_order = tutor_utils()->get_answer_by_id( $provided_answer_order_id );
+ foreach ( $provided_answer_order as $p_answer ) {
+ if ( $p_answer->answer_title ) {
+ $original_saved_answer->answer_view_format = 'text_image';
+ $original_saved_answer->answer_title = $p_answer->answer_title;
+ $answers[] = $original_saved_answer;
}
+ }
+ }
- // Fill in the blanks.
- elseif ( 'fill_in_the_blank' === $answer->question_type ) {
- $correct_answer = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT answer_two_gap_match FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='fill_in_the_blank'",
- $answer->question_id
- )
- );
+ tutor_render_answer_list( $answers );
+ } elseif ( 'image_answering' === $answer->question_type ) {
- $answer_titles = explode( '|', stripslashes( $correct_answer ) );
- $get_db_answers_by_question = QuizModel::get_answers_by_quiz_question( $answer->question_id );
+ $ordering_ids = maybe_unserialize( $answer->given_answer );
- echo tutor_render_fill_in_the_blank_answer( $get_db_answers_by_question, $answer_titles ); //phpcs:ignore --contain safe data
- }
+ $answers = array();
- // Ordering.
- elseif ( 'ordering' === $answer->question_type ) {
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_view_format
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='ordering'
- ORDER BY answer_order ASC;",
- $answer->question_id
- )
- );
+ foreach ( $ordering_ids as $answer_id => $image_answer ) {
+ $db_answers = tutor_utils()->get_answer_by_id( $answer_id );
+ foreach ( $db_answers as $db_answer ) {
+ }
+ $db_answer->answer_title = $image_answer;
+ $db_answer->answer_view_format = 'text_image';
+ $answers[] = $db_answer;
+
+ }
+
+ tutor_render_answer_list( $answers );
+ } else {
+ /**
+ * Allow Pro and add-ons to render given answer for custom question types.
+ * Pro handles draw_image and pin_image via this action.
+ *
+ * @param object $answer Answer object.
+ */
+ do_action( 'tutor_quiz_render_given_answer_for_question_type', $answer );
+ }
+ ?>
+
+ |
+
+
+
+ question_type != 'open_ended' && $answer->question_type != 'short_answer' ) ) {
+
+ global $wpdb;
+
+ // True false.
+ if ( 'true_false' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT answer_title FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='true_false'
+ AND is_correct = 1",
+ $answer->question_id
+ )
+ );
+
+ echo ' ' .
+ esc_html( $correct_answer ) .
+ '';
+ }
+
+ // Single choice.
+ elseif ( 'single_choice' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_view_format
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='single_choice' AND
+ is_correct = 1",
+ $answer->question_id
+ )
+ );
+
+ tutor_render_answer_list( $correct_answer );
+ }
+
+ // Multiple choice.
+ elseif ( 'multiple_choice' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_view_format
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='multiple_choice'
+ AND is_correct = 1 ;",
+ $answer->question_id
+ )
+ );
+
+ tutor_render_answer_list( $correct_answer );
+ }
+
+ // Fill in the blanks.
+ elseif ( 'fill_in_the_blank' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT answer_two_gap_match FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='fill_in_the_blank'",
+ $answer->question_id
+ )
+ );
+
+ $answer_titles = explode( '|', stripslashes( $correct_answer ) );
+ $get_db_answers_by_question = QuizModel::get_answers_by_quiz_question( $answer->question_id );
+
+ echo tutor_render_fill_in_the_blank_answer( $get_db_answers_by_question, $answer_titles ); //phpcs:ignore --contain safe data
+ }
+
+ // Ordering.
+ elseif ( 'ordering' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_view_format
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='ordering'
+ ORDER BY answer_order ASC;",
+ $answer->question_id
+ )
+ );
+
+ foreach ( $correct_answer as $ans ) {
+ tutor_render_answer_list( array( $ans ) );
+ }
+ }
+
+ // Matching.
+ elseif ( 'matching' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_two_gap_match, answer_view_format
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='matching'
+ ORDER BY answer_order ASC;",
+ $answer->question_id
+ )
+ );
+
+ if ( $is_image_matching ) {
+ array_map(
+ function ( $ans ) {
+ $ans->answer_view_format = 'text_image';
+ $ans->answer_two_gap_match = '';
+ },
+ $correct_answer
+ );
+ }
- // Matching.
- elseif ( 'matching' === $answer->question_type ) {
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_two_gap_match, answer_view_format
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='matching'
- ORDER BY answer_order ASC;",
- $answer->question_id
- )
- );
+ tutor_render_answer_list( $correct_answer );
+ }
+
+ // Image matching.
+ elseif ( 'image_matching' === $answer->question_type ) {
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_two_gap_match
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='image_matching'
+ ORDER BY answer_order ASC;",
+ $answer->question_id
+ )
+ );
+
+ tutor_render_answer_list( $correct_answer, true );
+ }
+
+ // Image Answering.
+ elseif ( 'image_answering' === $answer->question_type ) {
+
+ $correct_answer = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT answer_title, image_id, answer_two_gap_match
+ FROM {$wpdb->prefix}tutor_quiz_question_answers
+ WHERE belongs_question_id = %d
+ AND belongs_question_type='image_answering'
+ ORDER BY answer_order ASC;",
+ $answer->question_id
+ )
+ );
+
+ ! is_array( $correct_answer ) ? $correct_answer = array() : 0;
+
+ echo ' ';
+ foreach ( $correct_answer as $image_answer ) {
+ ?>
+
+
+ answer_title ); ?>
+
+ ';
+ } else {
+ /**
+ * Allow Pro and add-ons to render correct answer for custom question types.
+ * Pro handles draw_image and pin_image via this action.
+ *
+ * @param object $answer Answer object.
+ */
+ do_action( 'tutor_quiz_render_correct_answer_for_question_type', $answer );
+ }
+ }
+ ?>
+
+ |
+ answer_view_format = 'text_image';
- $ans->answer_two_gap_match = '';
- },
- $correct_answer
- );
+ case 'result':
+ ?>
+
+
+
+
+
+ question_type ) {
+ $achieved_val = (float) ( $answer->achieved_mark ?? 0 );
+ $question_mark = (float) ( $answer->question_mark ?? 0 );
+ $qmark_str = ( floor( $question_mark ) === $question_mark ) ? (string) (int) $question_mark : (string) round( $question_mark, 2 );
+ $achieved_str = (string) round( $achieved_val, 2 );
+ if ( floor( $achieved_val ) === $achieved_val ) {
+ $achieved_str = number_format( $achieved_val, 1, '.', '' );
}
-
- tutor_render_answer_list( $correct_answer );
- }
-
- // Image matching.
- elseif ( 'image_matching' === $answer->question_type ) {
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_two_gap_match
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='image_matching'
- ORDER BY answer_order ASC;",
- $answer->question_id
- )
+ $score_label = sprintf(
+ /* translators: 1: achieved marks, 2: total marks. */
+ esc_html__( 'Score: %1$s/%2$s', 'tutor' ),
+ $achieved_str,
+ $qmark_str
);
- tutor_render_answer_list( $correct_answer, true );
- }
+ $badge_info = QuizModel::get_attempt_answer_badge( $answer );
+ $badge_class = $badge_info['class'] ?? 'label-default';
- // Image Answering.
- elseif ( 'image_answering' === $answer->question_type ) {
-
- $correct_answer = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT answer_title, image_id, answer_two_gap_match
- FROM {$wpdb->prefix}tutor_quiz_question_answers
- WHERE belongs_question_id = %d
- AND belongs_question_type='image_answering'
- ORDER BY answer_order ASC;",
- $answer->question_id
- )
- );
+ echo ' ' . esc_html( $badge_info['label'] ?? '' ) . '';
- ! is_array( $correct_answer ) ? $correct_answer = array() : 0;
+ do_action( 'tutor_quiz_attempt_details_result_badge_after', $answer, $answer_status );
- echo ' ';
- foreach ( $correct_answer as $image_answer ) {
- ?>
-
-
- answer_title ); ?>
-
- ' . esc_html( $score_label ) . ' ';
}
- echo ' ';
- } else {
- /**
- * Allow Pro and add-ons to render correct answer for custom question types.
- * Pro handles draw_image and pin_image via this action.
- *
- * @param object $answer Answer object.
- */
- do_action( 'tutor_quiz_render_correct_answer_for_question_type', $answer );
}
- }
- ?>
+ ?>
- |
-
-
-
-
-
- question_type ) {
- switch ( $answer_status ) {
- case 'correct':
- echo '' . esc_html__( 'Correct', 'tutor' ) . '';
- break;
-
- case 'pending':
- echo '' . esc_html__( 'Pending', 'tutor' ) . '';
- break;
-
- case 'wrong':
- echo '' . esc_html__( 'Incorrect', 'tutor' ) . '';
- break;
- }
- }
- ?>
-
-
-
- |
-
+
+
+
+
+
+
+
+