get_question_types( $answer->question_type ); ?> | question_title ) ); ?> |
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; } } } } 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(); 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 ); } ?> |
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
);
}
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 ); ?> |
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; } } ?> |