diff --git a/css/qsm-admin.css b/css/qsm-admin.css index dcc71bd4..f15f72b6 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -1459,91 +1459,6 @@ td.scheduled_time_start { box-sizing: border-box; } -#post-body-content .qsm-popup-upgrade-warning img { - width: auto; - height: 15px; - margin-right: 8px; -} - -.qsm-linked-list-div-block { - padding: 4px; - margin: 5px 0; - margin-top: -20px; - width: max-content; - background-color: #ffe684; - border-radius: 2px; -} - -span.qsm-linked-list-view-button { - cursor: pointer; - color: #135e96; - text-decoration: underline; - font-weight: 500; -} - -span.qsm-linked-list-item { - margin: 0 0 5px 0; - padding: 5px; - background: #f0f0f1; -} - -div.qsm-linked-list-inside span.qsm-unlink-the-question { - color: #DC3232; - font-weight: 500; - max-width: 60px; - cursor: pointer; -} - -.qsm-linked-list-div-block p { - margin: 0; - font-size: 13px; - color: #856404; -} - -.qsm-linked-list-container { - position: absolute; -} - -.qsm-linked-list-div-block .qsm-linked-list-inside { - position: relative; - right: -155px; - top: 20px; - z-index: 999; - width: 350px; - padding: 10px; - box-sizing: border-box; - border-radius: 4px; - background: #ffffff; - border: 1px solid #dfd4d4; - box-shadow: 0 0 6px 2px #ddd; - display: grid; - grid-template-columns: 1fr; -} - -.qsm-linked-list-div-block .qsm-linked-list-inside:before { - content: " "; - position: absolute; - top: -24px; - left: 28%; - margin-left: -12px; - border-width: 12px; - border-style: solid; - border-color: transparent transparent #ffffff transparent; - z-index: 1; -} - -.qsm-linked-list-div-block .qsm-linked-list-inside:after { - content: " "; - position: absolute; - top: -26px; - left: 28%; - margin-left: -12px; - border-width: 12px; - border-style: solid; - border-color: transparent transparent #dfd4d4 transparent; - z-index: 0; -} - .qsm-text-main-wrap #postbox-container-1 { position: relative; diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 2cd08aab..277e3378 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -1899,7 +1899,6 @@ var QSMContact; */ var QSMQuestion; var import_button; -var qsm_link_button; (function ($) { if (jQuery('body').hasClass('admin_page_mlw_quiz_options')) { if (window.location.href.indexOf('&tab') == -1 || window.location.href.indexOf('tab=questions') > 0) { @@ -2042,22 +2041,19 @@ var qsm_link_button; type: question.type, question: questionText, category: question.category, - quiz_name: question.quiz_name, - linked_question: question.linked_question.join(',') + quiz_name: question.quiz_name })); }, - addQuestionFromQuestionBank: function (questionID, is_linking = 0) { + addQuestionFromQuestionBank: function (questionID) { QSMAdmin.displayAlert(qsm_admin_messages.adding_question, 'info'); - let isLinkingData = is_linking == 1 ? questionID : 0; var model = new QSMQuestion.question({ - id: questionID, - is_linking: isLinkingData + id: questionID }); model.fetch({ headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce }, - url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID + '?is_linking=' + isLinkingData, + url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID, success: QSMQuestion.questionBankSuccess, error: QSMAdmin.displayError }); @@ -2249,18 +2245,10 @@ var qsm_link_button; if(import_button){ import_button.html(qsm_admin_messages.add_question); } - if(qsm_link_button) { - qsm_link_button.html(qsm_admin_messages.link_question); - } if(import_button){ import_button.attr("onclick", "return confirm('" + qsm_admin_messages.confirm_message + " " + qsm_admin_messages.import_question_again + "');"); } QSMQuestion.openEditPopup(model.id, $('.question[data-question-id=' + model.id + ']').find('.edit-question-button')); - console.log(qsm_link_button); - if(qsm_link_button == ''){ - $(document).find('.qsm-linked-list-inside').hide().empty(); - $(document).find('.qsm-linked-list-div-block').hide(); - } // $('#save-popup-button').trigger('click'); }, addNewQuestion: function (model) { @@ -2796,31 +2784,6 @@ var qsm_link_button; $('#image_size_area').show(); } - let link_quizzes_array = question.get('link_quizzes'); - - $('.qsm-linked-list-inside').hide().empty(); - $('.qsm-linked-list-div-block').hide(); - if (typeof link_quizzes_array == 'object' && link_quizzes_array != null && Object.keys(link_quizzes_array).length > 0) { - Object.values(link_quizzes_array).forEach(function(quizName) { - // Ensure each quizName is a valid non-empty string - if (quizName && typeof quizName == 'string' && quizName.trim().length > 0) { - let link = $('') - .attr('class', 'qsm-linked-list-item') - .attr('title', quizName) - .text(quizName.length > 25 ? quizName.substring(0, 25) + '...' : quizName); - - $('.qsm-linked-list-div-block').show(); - $('.qsm-linked-list-inside').append(link); - } - }); - - // Add an "Unlink" link at the end - let unlink = $('') - .attr('class', 'qsm-unlink-the-question button button-danger') - .attr('data-question-id', questionID) - .text(qsm_admin_messages.unlink_question); - $('.qsm-linked-list-inside').append(unlink); - } jQuery(document).trigger('qsm_open_edit_popup', [questionID, CurrentElement]); }, openEditPagePopup: function (pageID) { @@ -3297,7 +3260,6 @@ var qsm_link_button; $(document).on('click', '.qsm-popup-bank .import-button', function (event) { event.preventDefault(); - qsm_link_button = ''; $(this).text(qsm_admin_messages.adding_question); import_button = $(this); $('.import-button').addClass('disable_import'); @@ -3305,42 +3267,9 @@ var qsm_link_button; MicroModal.close('modal-2'); }); - - $(document).on('click', '.qsm-popup-bank .link-question', function (event) { - event.preventDefault(); - $(this).text(qsm_admin_messages.linking_question); - qsm_link_button = $(this); - $('.link-question').addClass('disable_import'); - // 1 for the linking the questions default is 0 - QSMQuestion.addQuestionFromQuestionBank($(this).data('question-id'), 1); - MicroModal.close('modal-2'); - }); - - jQuery(document).on('click', '.qsm-linked-list-div-block .qsm-linked-list-view-button', function () { - let $this = jQuery(this); - let $inside = $this.parents('.qsm-linked-list-div-block').find('.qsm-linked-list-inside'); - $inside.toggle(); - $inside.is(':visible') ? $this.text(qsmQuestionSettings.linked_close) : $this.text(qsmQuestionSettings.linked_view); - }); - - jQuery(document).on('click', '.qsm-linked-list-div-block .qsm-unlink-the-question', function () { - $.ajax({ - url: ajaxurl, - method: 'POST', - data: { - action: 'qsm_unlink_question_from_list', - question_id: jQuery(this).data('question-id'), - nonce: qsmQuestionSettings.unlinkNonce - }, - success: function (response) { - $(document).find('.qsm-linked-list-div-block').remove(); - } - }); - }); //Click on selected question button. $('.qsm-popup-bank').on('click', '#qsm-import-selected-question', function (event) { var $total_selction = $('#question-bank').find('[name="qsm-question-checkbox[]"]:checked').length; - qsm_link_button = ''; if ($total_selction === 0) { alert(qsm_admin_messages.no_question_selected); } else { diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 57d77da8..ce63fc21 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -525,13 +525,8 @@ public function qsm_admin_scripts_style( $hook ) { 'results_page_saved' => __('Results pages were saved!', 'quiz-master-next'), 'results_page_save_error' => __('There was an error when saving the results pages.', 'quiz-master-next'), 'all_categories' => __('All Categories', 'quiz-master-next'), - 'add_question' => __('Add', 'quiz-master-next'), 'question_created' => __('Question created!', 'quiz-master-next'), 'new_question' => __('Your new question!', 'quiz-master-next'), - 'unlink_question' => __('Unlink', 'quiz-master-next'), - 'adding_question' => __('Adding...', 'quiz-master-next'), - 'linking_question' => __('Linking...', 'quiz-master-next'), - 'link_question' => __('Link', 'quiz-master-next'), 'creating_question' => __('Creating question...', 'quiz-master-next'), 'duplicating_question' => __('Duplicating question...', 'quiz-master-next'), 'saving_question' => __('Saving question...', 'quiz-master-next'), diff --git a/php/admin/options-page-questions-tab.php b/php/admin/options-page-questions-tab.php index 5139748c..4ad17e24 100644 --- a/php/admin/options-page-questions-tab.php +++ b/php/admin/options-page-questions-tab.php @@ -88,14 +88,11 @@ function qsm_options_questions_tab_content() { $json_data = array( 'quizID' => $quiz_id, 'answerText' => __( 'Answer', 'quiz-master-next' ), - 'linked_view' => __( 'View', 'quiz-master-next' ), - 'linked_close' => __( 'Close', 'quiz-master-next' ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'pages' => $pages, 'qpages' => $qpages, 'qsm_user_ve' => get_user_meta( $user_id, 'rich_editing', true ), 'saveNonce' => wp_create_nonce( 'ajax-nonce-sandy-page' ), - 'unlinkNonce' => wp_create_nonce( 'ajax-nonce-unlink-question' ), 'categories' => $question_categories, 'form_type' => $form_type, 'quiz_system' => $quiz_system, @@ -283,12 +280,6 @@ class="save-page-button button button-primary">
diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 7abd66c0..134d91bc 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -2038,15 +2038,6 @@ public function update() { } update_option( 'mlw_quiz_master_version', $data ); - - // Update 9.1.3 - $mlw_questions_table = $wpdb->prefix . 'mlw_questions'; - if ( 'linked_question' != $wpdb->get_var( "SHOW COLUMNS FROM $mlw_questions_table LIKE 'linked_question'" ) ) { - $sql = 'ALTER TABLE ' . $mlw_questions_table . ' ADD linked_question TEXT NULL DEFAULT \'\' AFTER category'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); - $update_sql = 'UPDATE ' . $mlw_questions_table . ' SET linked_question = \'\' WHERE linked_question IS NULL'; - $results = $mlwQuizMasterNext->wpdb_alter_table_query( $update_sql ); - } } if ( ! get_option( 'mlw_advert_shows' ) ) { add_option( 'mlw_advert_shows', 'true' ); diff --git a/php/classes/class-qsm-questions.php b/php/classes/class-qsm-questions.php index a0cabf38..52f6441e 100644 --- a/php/classes/class-qsm-questions.php +++ b/php/classes/class-qsm-questions.php @@ -270,7 +270,6 @@ private static function create_save_question( $data, $answers, $settings, $is_cr 'order' => 1, 'category' => '', 'multicategories' => '', - 'linked_question' => '', ); $data = wp_parse_args( $data, $defaults ); @@ -298,14 +297,6 @@ private static function create_save_question( $data, $answers, $settings, $is_cr if ( $trim_question_description ) { $question_name = trim( preg_replace( '/\s+/', ' ', $question_name ) ); } - $linked_question = sanitize_text_field( $data['linked_question'] ); - if ( $is_creating && isset($data['is_linking']) ) { - if ( 1 <= $data['is_linking'] ) { - $linked_question = $data['is_linking']; - }elseif ( 0 == $data['is_linking'] ) { - $linked_question = ''; - } - } $values = array( 'quiz_id' => intval( $data['quiz_id'] ), @@ -318,11 +309,10 @@ private static function create_save_question( $data, $answers, $settings, $is_cr 'question_type_new' => sanitize_text_field( $data['type'] ), 'question_settings' => maybe_serialize( $settings ), 'category' => sanitize_text_field( $data['category'] ), - 'linked_question' => $linked_question, 'deleted' => 0, ); $values = apply_filters( 'qsm_save_question_data', $values ); - + $types = array( '%d', '%s', @@ -334,7 +324,6 @@ private static function create_save_question( $data, $answers, $settings, $is_cr '%s', '%s', '%s', - '%s', '%d', ); @@ -362,74 +351,44 @@ private static function create_save_question( $data, $answers, $settings, $is_cr throw new Exception( $msg ); } - $base_question_id = $question_id; - $quiz_questions_array = array(); - $quiz_questions_array[ intval( $data['quiz_id'] ) ] = $question_id; - $linked_questions_array[] = $question_id; - if ( isset($linked_question) && "" != $linked_question ) { - $expolded_question_array = explode(',', $linked_question); - $linked_questions_array = array_merge($expolded_question_array, $linked_questions_array); - // preparing array for quiz question id - $imploded_question_ids = implode( ',', array_unique($linked_questions_array) ); - if ( ! empty($linked_questions_array) ) { - $quiz_results = $wpdb->get_results( "SELECT `quiz_id`, `question_id` FROM `{$wpdb->prefix}mlw_questions` WHERE `question_id` IN (" . $imploded_question_ids . ")" ); - foreach ( $quiz_results as $key => $value ) { - $quiz_questions_array[ $value->quiz_id ] = $value->question_id; - } - } - $values['linked_question'] = $imploded_question_ids; - } + /** + * Process Question Categories + */ $question_terms_table = $wpdb->prefix . 'mlw_question_terms'; - foreach ( $quiz_questions_array as $quiz_id => $question_id_loop ) { - $values['quiz_id'] = intval( $quiz_id ); - $wpdb->update( - $wpdb->prefix . 'mlw_questions', - $values, - array( 'question_id' => intval($question_id_loop) ), - $types, - array( '%d' ) - ); - - /** - * Process Question Categories - */ - - $wpdb->delete( - $question_terms_table, - array( - 'question_id' => $question_id_loop, + $wpdb->delete( + $question_terms_table, + array( + 'question_id' => $question_id, + 'taxonomy' => 'qsm_category', + ) + ); + if ( ! empty( $data['multicategories'] ) ) { + foreach ( $data['multicategories'] as $term_id ) { + $term_rel_data = array( + 'question_id' => $question_id, + 'quiz_id' => intval( $data['quiz_id'] ), + 'term_id' => $term_id, 'taxonomy' => 'qsm_category', - ) - ); - if ( ! empty( $data['multicategories'] ) ) { - foreach ( $data['multicategories'] as $term_id ) { - $term_rel_data = array( - 'question_id' => $question_id_loop, - 'quiz_id' => intval( $quiz_id ), - 'term_id' => $term_id, - 'taxonomy' => 'qsm_category', - ); - // Check if the data already exists in the table - $data_exists = $wpdb->get_row($wpdb->prepare("SELECT * FROM $question_terms_table WHERE question_id = %s AND quiz_id = %s AND term_id = %s AND taxonomy = %s", $question_id_loop, intval( $quiz_id ), $term_id, 'qsm_category' )); - if ( ! $data_exists ) { - $wpdb->insert( $question_terms_table, $term_rel_data ); - } + ); + // Check if the data already exists in the table + $data_exists = $wpdb->get_row($wpdb->prepare("SELECT * FROM $question_terms_table WHERE question_id = %s AND quiz_id = %s AND term_id = %s AND taxonomy = %s", $question_id, intval( $data['quiz_id'] ), $term_id, 'qsm_category' )); + if ( ! $data_exists ) { + $wpdb->insert( $question_terms_table, $term_rel_data ); } } + } - /** - * Hook after saving question - */ - - if ( $is_creating && $base_question_id == $question_id_loop ) { - do_action( 'qsm_question_added', $question_id_loop, $values ); - } else { - do_action( 'qsm_question_updated', $question_id_loop, $values ); - } - do_action( 'qsm_saved_question', $question_id_loop, $values ); - + /** + * Hook after saving question + */ + if ( $is_creating ) { + do_action( 'qsm_question_added', $question_id, $values ); + } else { + do_action( 'qsm_question_updated', $question_id, $values ); } - return $base_question_id; + do_action( 'qsm_saved_question', $question_id, $values ); + + return $question_id; } /** diff --git a/php/rest-api.php b/php/rest-api.php index d59d4d80..53f1bd93 100644 --- a/php/rest-api.php +++ b/php/rest-api.php @@ -271,7 +271,6 @@ function qsm_rest_get_bank_questions( WP_REST_Request $request ) { 'file_upload_type' => isset( $question['settings']['file_upload_type'] ) ? $question['settings']['file_upload_type'] : '', 'quiz_name' => isset( $quiz_name['quiz_name'] ) ? $quiz_name['quiz_name'] : '', 'question_title' => isset( $question['settings']['question_title'] ) ? $question['settings']['question_title'] : '', - 'linked_question' => array_filter( isset( $question['linked_question'] ) ? explode(',', $question['linked_question']) : array() ), ); $question_data = apply_filters( 'qsm_rest_api_filter_question_data', $question_data, $question, $request ); $question_array['questions'][] = $question_data; @@ -488,33 +487,11 @@ function qsm_rest_save_results( WP_REST_Request $request ) { function qsm_rest_get_question( WP_REST_Request $request ) { // Makes sure user is logged in. if ( is_user_logged_in() ) { - global $wpdb; $current_user = wp_get_current_user(); if ( 0 !== $current_user ) { $question = QSM_Questions::load_question( $request['id'] ); $categorysArray = QSM_Questions::get_question_categories( $question['question_id'] ); if ( ! empty( $question ) ) { - $is_linking = $request['is_linking']; - $comma_seprated_ids = ''; - if ( 1 <= $is_linking ) { - if ( isset( $question['linked_question'] ) && '' == $question['linked_question'] ) { - $comma_seprated_ids = $is_linking; - } else { - $expolded_question_array = explode(',', $question['linked_question']); - $expolded_question_array[] = $is_linking; - $comma_seprated_ids = implode( ',', array_unique($expolded_question_array) ); - } - } - - $quiz_name_by_question = array(); - if ( ! empty($comma_seprated_ids) ) { - $quiz_results = $wpdb->get_results( "SELECT `quiz_id`, `question_id` FROM `{$wpdb->prefix}mlw_questions` WHERE `question_id` IN (" .$comma_seprated_ids. ")" ); - foreach ( $quiz_results as $value ) { - $quiz_name_in_loop = $wpdb->get_row( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $value->quiz_id ), ARRAY_A ); - $quiz_name_in_loop = isset( $quiz_name_in_loop['quiz_name'] ) ? $quiz_name_in_loop['quiz_name'] : ''; - $quiz_name_by_question[] = $quiz_name_in_loop; - } - } $question['page'] = isset( $question['page'] ) ? $question['page'] : 0; $question = array( 'id' => $question['question_id'], @@ -531,8 +508,6 @@ function qsm_rest_get_question( WP_REST_Request $request ) { 'answers' => $question['answers'], 'page' => $question['page'], 'question_title' => isset( $question['settings']['question_title'] ) ? $question['settings']['question_title'] : '', - 'link_quizzes' => $quiz_name_by_question, - 'merged_question' => $comma_seprated_ids, ); } return $question; @@ -563,31 +538,12 @@ function qsm_rest_get_questions( WP_REST_Request $request ) { $questions = QSM_Questions::load_questions( 0 ); } global $wpdb; - $stored_quiz_names = $procesed_question_ids = $question_array = array(); + $question_array = array(); foreach ( $questions as $question ) { $quiz_name = $wpdb->get_row( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $question['quiz_id'] ), ARRAY_A ); $question['page'] = isset( $question['page'] ) ? $question['page'] : 0; $categorysArray = QSM_Questions::get_question_categories( $question['question_id'] ); - $quiz_name = isset( $quiz_name['quiz_name'] ) ? $quiz_name['quiz_name'] : ''; - $quiz_name_by_question = array(); - $procesed_question_ids[] = $question['question_id']; - $stored_quiz_names[ $question['question_id'] ] = $quiz_name; - $linked_question_ids = array_filter( isset( $question['linked_question'] ) ? explode(',', $question['linked_question']) : array() ); - if ( ! empty($linked_question_ids) ) { - $quiz_results = $wpdb->get_results( "SELECT `quiz_id`, `question_id` FROM `{$wpdb->prefix}mlw_questions` WHERE `question_id` IN (" . implode( ',', $linked_question_ids ) . ")" ); - foreach ( $quiz_results as $value ) { - if ( ! in_array($value->question_id, $procesed_question_ids) ) { - $quiz_name_in_loop = $wpdb->get_row( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $value->quiz_id ), ARRAY_A ); - $quiz_name_in_loop = isset( $quiz_name_in_loop['quiz_name'] ) ? $quiz_name_in_loop['quiz_name'] : ''; - $quiz_name_by_question[] = $quiz_name_in_loop; - $procesed_question_ids[] = $value->question_id; - $stored_quiz_names[ $value->question_id ] = $quiz_name_in_loop; - } else { - $quiz_name_by_question[] = $stored_quiz_names[ $value->question_id ]; - } - } - } - $quiz_name_by_question = array_diff($quiz_name_by_question, [ $quiz_name ]); // remove current quiz id from the list + $question_data = array( 'id' => $question['question_id'], 'quizID' => $question['quiz_id'], @@ -610,13 +566,11 @@ function qsm_rest_get_questions( WP_REST_Request $request ) { 'limit_multiple_response' => isset( $question['settings']['limit_multiple_response'] ) ? $question['settings']['limit_multiple_response'] : 0, 'file_upload_limit' => isset( $question['settings']['file_upload_limit'] ) ? $question['settings']['file_upload_limit'] : 0, 'file_upload_type' => isset( $question['settings']['file_upload_type'] ) ? $question['settings']['file_upload_type'] : '', - 'quiz_name' => $quiz_name, + 'quiz_name' => isset( $quiz_name['quiz_name'] ) ? $quiz_name['quiz_name'] : '', 'question_title' => isset( $question['settings']['question_title'] ) ? $question['settings']['question_title'] : '', 'featureImageID' => isset( $question['settings']['featureImageID'] ) ? $question['settings']['featureImageID'] : '', 'featureImageSrc' => isset( $question['settings']['featureImageSrc'] ) ? $question['settings']['featureImageSrc'] : '', 'settings' => $question['settings'], - 'link_quizzes' => $quiz_name_by_question, - 'merged_question' => implode(",", $linked_question_ids), ); $question_data = apply_filters( 'qsm_rest_api_filter_question_data', $question_data, $question, $request ); $question_array[] = $question_data; @@ -654,8 +608,6 @@ function qsm_rest_create_question( WP_REST_Request $request ) { 'order' => 1, 'category' => $request['category'], 'multicategories' => $request['multicategories'], - 'linked_question' => $request['merged_question'], - 'is_linking' => $request['is_linking'], ); $settings = array( 'required' => $request['required'], @@ -719,7 +671,6 @@ function qsm_rest_save_question( WP_REST_Request $request ) { 'order' => 1, 'category' => $request['category'], 'multicategories' => $request['multicategories'], - 'linked_question' => $request['merged_question'], ); $settings = array(); $settings['answerEditor'] = $request['answerEditor'];