From 38f747f3410e9523de9df8e5ce8c40c3fc421af1 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 16:55:40 +0530 Subject: [PATCH 1/5] 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 = ''; From ac13a2c11af346980fea05bb0bb4d5404c6e4a6e Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 17:00:01 +0530 Subject: [PATCH 2/5] Added advance dropdown functionality --- php/template-variables/qsm-tempvar-question-answers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/template-variables/qsm-tempvar-question-answers.php b/php/template-variables/qsm-tempvar-question-answers.php index 3cd1f0069..04f519c45 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'; @@ -18,7 +18,7 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response, } 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'] ) { From 7872eb8dc0dbf778a9c9bdd33d7008930ef6a8a2 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 18:43:16 +0530 Subject: [PATCH 3/5] Added advance dropdown functionality --- php/question-types/qsm-question-type-dropdown.php | 7 +------ .../qsm-tempvar-question-answers.php | 14 +++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/php/question-types/qsm-question-type-dropdown.php b/php/question-types/qsm-question-type-dropdown.php index bddd14f33..a805a07f0 100644 --- a/php/question-types/qsm-question-type-dropdown.php +++ b/php/question-types/qsm-question-type-dropdown.php @@ -59,13 +59,8 @@ function qmn_drop_down_display( $id, $question, $answers ) { * @since 4.4.0 */ function qmn_drop_down_review( $id, $question, $answers ) { - global $mlwQuizMasterNext; - $inline_drop_down = $mlwQuizMasterNext->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 ); - } + $current_question = apply_filters( 'qmn_drop_down_review_before', $id, $question, $answers, $current_question ); $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 04f519c45..c1ff991c6 100644 --- a/php/template-variables/qsm-tempvar-question-answers.php +++ b/php/template-variables/qsm-tempvar-question-answers.php @@ -11,11 +11,10 @@ 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 ( 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 ( 1 === intval($single_answer[2]) ) { + $is_answer_correct = true; } + $is_answer_correct = apply_filters( 'qsm_is_answer_correct_choice_before', $single_answer, $user_answer_array, $single_answer_key, $answers_from_response, $grading_system, $question_settings, $form_type ); if ( in_array( $single_answer_key, $user_answer_keys, true ) ) { $is_user_answer = true; } @@ -35,11 +34,8 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response, $show_user_answer = ''; $image_class = 'qmn_image_option'; } else { - 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' ); - } + $show_user_answer = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ), 'answer-' . $single_answer[0], 'QSM Answers' ); + $show_user_answer = apply_filters( 'qsm_show_user_answer_before', $single_answer, $user_answer_array, $single_answer_key, $answers_from_response, $grading_system, $question_settings, $form_type, $show_user_answer ); $image_class = ''; } $close_span = ''; From 486d7c71ccff9d5deb6b280a77f60ae4b5caea27 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 19:29:53 +0530 Subject: [PATCH 4/5] Added advance dropdown functionality --- js/qsm-admin.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 4211bfb50..564107cf6 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2069,11 +2069,7 @@ 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 () { @@ -2161,9 +2157,7 @@ var import_button; }); model.set('answers', answers); model.set('required', required); - model.set('inline_drop_down', required); - model.set('drop_down_type', required); - + jQuery(document).trigger('qsm_save_question_before', [questionID, CurrentElement, model, advanced_option]); $('.questionElements .advanced-content > .qsm-row:not(.core-option)').each(function () { if ($(this).find('input[type="text"]').length > 0) { $($(this).find('input[type="text"]')).each(function () { From 9e78b04c922321b577ace2b9510fa77f43bc2336 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 12 Dec 2023 21:44:02 +0530 Subject: [PATCH 5/5] Added advance dropdown functionality --- js/qsm-admin.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 564107cf6..1b31bd3b2 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2487,10 +2487,8 @@ var import_button; if (index == 'matchAnswer') { $('#match-answer').val(value); } - if (index == 'drop-down-type') { - $('#drop-down-type').val(value); - } }); + jQuery(document).trigger('qsm_all_question_setting_after', [all_setting]); } CurrentElement.parents('.question').next('.questionElements').slideDown('slow'); $('#modal-1-content').html(questionElements);