Skip to content

Commit

Permalink
Fixed issue with importing quetoins
Browse files Browse the repository at this point in the history
  • Loading branch information
etchirag committed Oct 7, 2024
1 parent 8c92590 commit 283360f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,26 @@ var qsm_link_button;
}
if ( 1 > questions.length ) {
$('#question-bank').append('<div style="margin-top: 70px;text-align: center;" >' + qsm_admin_messages.questions_not_found + '</div>');
} else {
$('.question-bank-question').each(function () {
let questionId = $(this).data('question-id');
if (QSMQuestion.questions.some(q => q.get('id') == questionId)) {
let $linkButton = $(this).find('.link-question');
if ($linkButton.length) {
$linkButton.prop('disabled', true).addClass('disabled');
}
}
QSMQuestion.questions.each(function (question) {
let merged_questions = question.get('merged_question');
let questionsArray = merged_questions ? merged_questions.split(',').map(q => q.trim()) : [];
questionsArray.forEach(function (id) {
let parentElement = $('.question-bank-question[data-question-id="' + id + '"]');
if (parentElement.length) {
parentElement.remove(); // Remove the element if it exists
}
});
});
});
}
},
addQuestionToQuestionBank: function (question) {
Expand Down Expand Up @@ -3324,6 +3344,7 @@ var qsm_link_button;
});

jQuery(document).on('click', '.qsm-linked-list-div-block .qsm-unlink-the-question', function () {
var to_be_unlink_question = jQuery(this).data('question-id');
$.ajax({
url: ajaxurl,
method: 'POST',
Expand All @@ -3334,6 +3355,8 @@ var qsm_link_button;
},
success: function (response) {
$(document).find('.qsm-linked-list-div-block').remove();
let question = QSMQuestion.questions.get(to_be_unlink_question);
question.set('merged_question', '');
}
});
});
Expand Down
3 changes: 2 additions & 1 deletion php/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ function qsm_rest_get_question( WP_REST_Request $request ) {
if ( isset( $question['linked_question'] ) && '' == $question['linked_question'] ) {
$comma_seprated_ids = $is_linking;
} else {
$expolded_question_array = explode(',', $question['linked_question']);
$linked_question = isset($question['linked_question']) ? $question['linked_question'] : '';
$exploded_question_array = explode(',', $linked_question);
$expolded_question_array[] = $is_linking;
$comma_seprated_ids = implode( ',', array_unique($expolded_question_array) );
}
Expand Down

0 comments on commit 283360f

Please sign in to comment.