From 38f747f3410e9523de9df8e5ce8c40c3fc421af1 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 16:55:40 +0530 Subject: [PATCH] Added advance dropdown functionality --- js/qsm-admin.js | 11 +++++++++++ mlw_quizmaster2.php | 1 + php/admin/options-page-questions-tab.php | 2 +- php/question-types/qsm-question-title.php | 4 +++- .../qsm-question-type-dropdown.php | 10 ++++++++++ .../qsm-tempvar-question-answers.php | 16 +++++++++++----- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 54ba5d0e0..4211bfb50 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2069,7 +2069,11 @@ var import_button; var type = $("#question_type").val(); var comments = $("#comments").val(); let required = $(".questionElements input[name='required']").is(":checked") ? 0 : 1; + let inline_drop_down = $(".questionElements input[name='inline-drop-down']").is(":checked") ? 0 : 1; + let drop_down_type = $(".questionElements select[name='drop-down-type']").val(); advanced_option['required'] = required; + advanced_option['inline-drop-down'] = inline_drop_down; + advanced_option['drop-down-type'] = drop_down_type; var category = $(".category-radio:checked").val(); var type_arr = []; $.each($("input[name='file_upload_type[]']:checked"), function () { @@ -2157,6 +2161,8 @@ var import_button; }); model.set('answers', answers); model.set('required', required); + model.set('inline_drop_down', required); + model.set('drop_down_type', required); $('.questionElements .advanced-content > .qsm-row:not(.core-option)').each(function () { if ($(this).find('input[type="text"]').length > 0) { @@ -2487,6 +2493,9 @@ var import_button; if (index == 'matchAnswer') { $('#match-answer').val(value); } + if (index == 'drop-down-type') { + $('#drop-down-type').val(value); + } }); } CurrentElement.parents('.question').next('.questionElements').slideDown('slow'); @@ -2818,6 +2827,7 @@ var import_button; QSMQuestion.saveQuestion($(this).parents('.questionElements').children('#edit_question_id').val(), $(this)); $('.save-page-button').trigger('click'); $('#modal-1-content').html(model_html); + jQuery(document).trigger('qsm_save_popup_button_after', [questionElements]); }); $(document).on('click', '#new-answer-button', function (event) { event.preventDefault(); @@ -3056,6 +3066,7 @@ var import_button; if ('image' === answerType) { $('#image_size_area').show(); } + jQuery(document).trigger('qsm_question_type_change_after', [question_val]); }); diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index e67e1c8c0..a87de8afd 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -450,6 +450,7 @@ public function qsm_admin_scripts_style( $hook ) { 'add_more' => __("Add", 'quiz-master-next'), '_X_validation_fails' => __("Please enter an appropriate value for 'X'", 'quiz-master-next'), ); + $qsm_admin_messages = apply_filters( 'qsm_admin_messages_after', $qsm_admin_messages ); wp_localize_script( 'qsm_admin_js', 'qsm_admin_messages', $qsm_admin_messages ); } diff --git a/php/admin/options-page-questions-tab.php b/php/admin/options-page-questions-tab.php index 5c7de6350..c433b2a28 100644 --- a/php/admin/options-page-questions-tab.php +++ b/php/admin/options-page-questions-tab.php @@ -599,7 +599,7 @@ class="save-page-button button button-primary"> array( 'label' => __( 'Required?', 'quiz-master-next' ), 'type' => 'single_checkbox', - 'priority' => '2', + 'priority' => '3', 'options' => array( '0' => __( 'Yes', 'quiz-master-next' ), ), diff --git a/php/question-types/qsm-question-title.php b/php/question-types/qsm-question-title.php index 1210b7af6..ad866eeae 100644 --- a/php/question-types/qsm-question-title.php +++ b/php/question-types/qsm-question-title.php @@ -41,7 +41,9 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_ } ?>
- pluginHelper->get_question_setting( $id, 'question_title' ); qsm_question_title_func( $question, '', $new_question_title, $id ); + $show = true; + $show = apply_filters( 'qsm_check_show_answer_drop_down', $id, $question, $answers ); + if ( $show ) { ?> pluginHelper->get_question_setting( $id, 'inline-drop-down' ); + $drop_down_type = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'drop-down-type' ); $current_question = new QSM_Question_Review_Choice( $id, $question, $answers ); + if ( class_exists( 'QSM_Advance_Question_Review_Choice' ) && 0 == $inline_drop_down && 'multiple' == $drop_down_type ) { + $current_question = new QSM_Advance_Question_Review_Choice( $id, $question, $answers ); + } $user_text_array = $current_question->get_user_answer(); $correct_text_array = $current_question->get_correct_answer(); $return_array['user_text'] = ! empty( $user_text_array ) ? implode( ', ', $user_text_array ) : '' ; diff --git a/php/template-variables/qsm-tempvar-question-answers.php b/php/template-variables/qsm-tempvar-question-answers.php index c8050557f..3cd1f0069 100644 --- a/php/template-variables/qsm-tempvar-question-answers.php +++ b/php/template-variables/qsm-tempvar-question-answers.php @@ -2,7 +2,7 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response, $grading_system, $question_settings, $form_type = 0 ) { global $mlwQuizMasterNext; $question_with_answer_text = ''; - $class = ''; + $class = ''; foreach ( $total_answers as $single_answer_key => $single_answer ) { if ( 8 == $answers_from_response['question_type'] && 'not-opted' == $answers_from_response['user_compare_text'] ) { $class = 'not-opted'; @@ -11,12 +11,14 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response, $user_answer_keys = ! empty( $user_answer_array ) ? array_keys( $user_answer_array ) : array(); $is_answer_correct = false; $is_user_answer = false; - if ( 1 === intval( $single_answer[2] ) ) { - $is_answer_correct = true; + if ( 2 == $answers_from_response['question_type'] && 0 == $question_settings['inline-drop-down'] && 'multiple' == $question_settings['drop-down-type'] ) { + $is_answer_correct = ($single_answer[0] === $user_answer_array[$single_answer_key]); + } else { + $is_answer_correct = (1 === intval($single_answer[2])); } if ( in_array( $single_answer_key, $user_answer_keys, true ) ) { $is_user_answer = true; - } + } $image_class = ''; $caption = ''; if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) { @@ -33,7 +35,11 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response, $show_user_answer = ''; $image_class = 'qmn_image_option'; } else { - $show_user_answer = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ), 'answer-' . $single_answer[0], 'QSM Answers' ); + if ( 2 == $answers_from_response['question_type'] && 0 == $question_settings['inline-drop-down'] && 'multiple' == $question_settings['drop-down-type'] ) { + $show_user_answer = !empty($user_answer_array[$single_answer_key]) ? htmlspecialchars_decode( $user_answer_array[$single_answer_key], ENT_QUOTES ) : $single_answer[0]; + } else { + $show_user_answer = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ), 'answer-' . $single_answer[0], 'QSM Answers' ); + } $image_class = ''; } $close_span = '';