Skip to content

Commit

Permalink
Added advance dropdown functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed Dec 12, 2023
1 parent 9da76b4 commit 38f747f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
11 changes: 11 additions & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3056,6 +3066,7 @@ var import_button;
if ('image' === answerType) {
$('#image_size_area').show();
}
jQuery(document).trigger('qsm_question_type_change_after', [question_val]);
});


Expand Down
1 change: 1 addition & 0 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}
Expand Down
2 changes: 1 addition & 1 deletion php/admin/options-page-questions-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class="save-page-button button button-primary"><?php esc_html_e( 'Save Questions
'required' => array(
'label' => __( 'Required?', 'quiz-master-next' ),
'type' => 'single_checkbox',
'priority' => '2',
'priority' => '3',
'options' => array(
'0' => __( 'Yes', 'quiz-master-next' ),
),
Expand Down
4 changes: 3 additions & 1 deletion php/question-types/qsm-question-title.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_
}
?>
<div class='mlw_qmn_question <?php echo esc_attr( $title_extra_classes ); ?>' >
<?php do_action('qsm_before_question_title',$question, $question_type, $new_question_title, $question_id );
<?php
$question_title = apply_filters( 'qsm_question_title_func_before', $question, $question_type, $new_question_title, $question_id );
do_action('qsm_before_question_title',$question, $question_type, $new_question_title, $question_id );
$allow_html = wp_kses_allowed_html('post');
$allow_html['input']['autocomplete'] = 1;
$allow_html['input']['name'] = 1;
Expand Down
10 changes: 10 additions & 0 deletions php/question-types/qsm-question-type-dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function qmn_drop_down_display( $id, $question, $answers ) {
}
$new_question_title = $mlwQuizMasterNext->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 ) {
?>
<select class="qsm_select qsm_dropdown <?php echo esc_attr( $require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>">
<option disabled selected value><?php echo esc_html__( 'Please select your answer', 'quiz-master-next' ); ?></option>
Expand All @@ -42,6 +45,7 @@ function qmn_drop_down_display( $id, $question, $answers ) {
?>
</select>
<?php
}
echo apply_filters( 'qmn_drop_down_display_front', '', $id, $question, $answers );
}

Expand All @@ -55,7 +59,13 @@ 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 );
}
$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 ) : '' ;
Expand Down
16 changes: 11 additions & 5 deletions php/template-variables/qsm-tempvar-question-answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'] ) {
Expand All @@ -33,7 +35,11 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response,
$show_user_answer = '<img src="' . $mlwQuizMasterNext->pluginHelper->qsm_language_support( $single_answer[0], 'answer-' . $single_answer[0], 'QSM Answers' ) . '" style="' . esc_attr( $size_style ) . '" />';
$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 = '</span>';
Expand Down

0 comments on commit 38f747f

Please sign in to comment.