From 312072a34de4a8b63c42361e00f4b3a8a7d4d7e3 Mon Sep 17 00:00:00 2001 From: manandeep singh Date: Thu, 17 Oct 2024 13:06:15 +0530 Subject: [PATCH 01/48] Fix legacy timer count up --- js/qsm-quiz.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index bbd87c64..125b4e41 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -170,9 +170,12 @@ var qsmTimerInterval = []; } var secondsRemaining = qmn_quiz_data[quizID].timerRemaning; var secondsConsumed = qmn_quiz_data[quizID].timerConsumed; - jQuery(document).trigger('qmn_timer_consumed_seconds', [quizID, qmn_quiz_data, qsm_timer_consumed_obj]); if (localStorage.getItem('mlw_time_quiz' + quizID) != null ) { secondsRemaining = (parseFloat(qmn_quiz_data[quizID].timer_limit) * 60) - secondsConsumed + 1; + if(qsm_timer_consumed_obj.qmn_count_upward_status){ + secondsConsumed = qmn_quiz_data[quizID].timerConsumed - 1; + secondsRemaining = (parseFloat(qmn_quiz_data[quizID].timer_limit) * 60) - secondsConsumed; + } if(secondsRemaining < 0) { secondsRemaining = 0; } From 311d2e156fcbacbafceb6ee056661ead67663f76 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 18 Oct 2024 11:49:53 +0530 Subject: [PATCH 02/48] added index to response_data --- php/classes/class-qsm-results-pages.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php/classes/class-qsm-results-pages.php b/php/classes/class-qsm-results-pages.php index 2f7d6e46..d74b6615 100644 --- a/php/classes/class-qsm-results-pages.php +++ b/php/classes/class-qsm-results-pages.php @@ -180,6 +180,7 @@ public static function generate_pages( $response_data ) { // variables, and then outputs the text. $page = wp_kses_post( htmlspecialchars_decode( $content, ENT_QUOTES) ); + $response_data['result_page_index'] = $index; //last chance to filter $page $page = apply_filters( 'qsm_template_variable_results_page', $page, $response_data ); From c095ba79070d8ae2a61934d61179e533ca5ab6fd Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 18 Oct 2024 12:34:02 +0530 Subject: [PATCH 03/48] Override the individual quiz text data in quiz options --- php/classes/class-qsm-settings.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 5046ca6e..25be0d6b 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -471,13 +471,7 @@ public function get_quiz_options() { } $text = $this->get_setting('quiz_text'); - if ( is_array($text) ) { - foreach ( $text as $key => $value ) { - if ( ! empty($value) ) { - $quiz_options[ $key ] = $value; - } - } - } + $quiz_options = array_merge( $quiz_options, $text ); // Return as old object model return (object) $quiz_options; From 2bcb27df2b31825f46ec163045d6d63c41a36e7e Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 18 Oct 2024 13:13:55 +0530 Subject: [PATCH 04/48] added previous condition --- php/classes/class-qsm-settings.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 25be0d6b..2053d265 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -471,6 +471,13 @@ public function get_quiz_options() { } $text = $this->get_setting('quiz_text'); + if ( is_array($text) ) { + foreach ( $text as $key => $value ) { + if ( ! empty($value) ) { + $quiz_options[ $key ] = $value; + } + } + } $quiz_options = array_merge( $quiz_options, $text ); // Return as old object model From 2e22491457d72375a073f660b34b08c59c28f950 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 18 Oct 2024 16:00:58 +0530 Subject: [PATCH 05/48] fix condition to merge text array --- php/classes/class-qsm-settings.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 2053d265..916afe61 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -472,13 +472,8 @@ public function get_quiz_options() { $text = $this->get_setting('quiz_text'); if ( is_array($text) ) { - foreach ( $text as $key => $value ) { - if ( ! empty($value) ) { - $quiz_options[ $key ] = $value; - } - } + $quiz_options = array_merge( $quiz_options, $text ); } - $quiz_options = array_merge( $quiz_options, $text ); // Return as old object model return (object) $quiz_options; From 817dbe8347d5e1a2264d63b62245e5f52b632335 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 22 Oct 2024 19:12:09 +0530 Subject: [PATCH 06/48] fixed quiz label color issue --- templates/qmn_primary.css | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/qmn_primary.css b/templates/qmn_primary.css index 850335df..fcc54b91 100644 --- a/templates/qmn_primary.css +++ b/templates/qmn_primary.css @@ -108,6 +108,7 @@ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; + color: #222; } .quiz_section>.quiz-cat { From fd8282a91a1fb137f776096c4a55d94949d9fe48 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Wed, 23 Oct 2024 16:45:49 +0530 Subject: [PATCH 07/48] Modified permissions on pages --- php/admin/about-page.php | 2 +- php/admin/addons-page.php | 2 +- php/admin/admin-dashboard.php | 2 +- php/admin/stats-page.php | 2 +- php/admin/tools-page.php | 2 +- php/rest-api.php | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/php/admin/about-page.php b/php/admin/about-page.php index b54d9cc2..60fd7985 100644 --- a/php/admin/about-page.php +++ b/php/admin/about-page.php @@ -18,7 +18,7 @@ function qsm_generate_about_page() { global $mlwQuizMasterNext; $version = $mlwQuizMasterNext->version; - if ( ! current_user_can( 'moderate_comments' ) ) { + if ( ! current_user_can( 'delete_others_qsm_quizzes' ) ) { return; } $tab_array = [ diff --git a/php/admin/addons-page.php b/php/admin/addons-page.php index 6c055261..00c81c5b 100644 --- a/php/admin/addons-page.php +++ b/php/admin/addons-page.php @@ -10,7 +10,7 @@ * @since 4.4.0 */ function qmn_addons_page() { - if ( ! current_user_can( 'moderate_comments' ) ) { + if ( ! current_user_can( 'delete_others_qsm_quizzes' ) ) { return; } diff --git a/php/admin/admin-dashboard.php b/php/admin/admin-dashboard.php index b4f2eb7c..21895a48 100644 --- a/php/admin/admin-dashboard.php +++ b/php/admin/admin-dashboard.php @@ -102,7 +102,7 @@ function qsm_dashboard_screen_options( $status, $args ) { */ function qsm_generate_dashboard_page() { // Only let admins and editors see this page. - if ( ! current_user_can( 'edit_posts' ) ) { + if ( ! current_user_can( 'edit_qsm_quizzes' ) ) { return; } global $mlwQuizMasterNext; diff --git a/php/admin/stats-page.php b/php/admin/stats-page.php index 243d74fe..211dcd2d 100644 --- a/php/admin/stats-page.php +++ b/php/admin/stats-page.php @@ -16,7 +16,7 @@ * @return void */ function qmn_generate_stats_page() { - if ( ! current_user_can('moderate_comments') ) { + if ( ! current_user_can('delete_others_qsm_quizzes') ) { return; } global $mlwQuizMasterNext; diff --git a/php/admin/tools-page.php b/php/admin/tools-page.php index 472ede5e..70951f6b 100644 --- a/php/admin/tools-page.php +++ b/php/admin/tools-page.php @@ -15,7 +15,7 @@ * @since 6.2.0 */ function qsm_generate_quiz_tools() { - if ( ! current_user_can( 'moderate_comments' ) ) { + if ( ! current_user_can( 'delete_others_qsm_quizzes' ) ) { return; } add_meta_box( 'qsm_restore_box', 'Restore Quiz', 'qsm_restore_function', 'quiz_wpss' ); diff --git a/php/rest-api.php b/php/rest-api.php index bbb612a1..07c626cf 100644 --- a/php/rest-api.php +++ b/php/rest-api.php @@ -30,7 +30,7 @@ function qsm_register_rest_routes() { 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'qsm_rest_create_question', 'permission_callback' => function () { - return current_user_can( 'edit_posts' ); + return current_user_can( 'edit_qsm_quizzes' ); }, ) ); @@ -41,7 +41,7 @@ function qsm_register_rest_routes() { 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'qsm_rest_save_question', 'permission_callback' => function () { - return current_user_can( 'edit_posts' ); + return current_user_can( 'edit_qsm_quizzes' ); }, ) ); @@ -70,7 +70,7 @@ function qsm_register_rest_routes() { 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'qsm_rest_save_results', 'permission_callback' => function () { - return current_user_can( 'edit_posts' ); + return current_user_can( 'edit_qsm_quizzes' ); }, ) ); @@ -90,7 +90,7 @@ function qsm_register_rest_routes() { 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'qsm_rest_save_emails', 'permission_callback' => function () { - return current_user_can( 'edit_posts' ); + return current_user_can( 'edit_qsm_quizzes' ); }, ) ); @@ -123,7 +123,7 @@ function qsm_register_rest_routes() { 'methods' => WP_REST_Server::READABLE, 'callback' => 'qsm_rest_get_bank_questions', 'permission_callback' => function () { - return current_user_can( 'edit_posts' ); + return current_user_can( 'edit_qsm_quizzes' ); }, ) ); From 963a837c5bb45bdb784baa9cef4d273ebd074db3 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Thu, 24 Oct 2024 12:14:42 +0530 Subject: [PATCH 08/48] modified permission for global settings page --- mlw_quizmaster2.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 2a6e8e6b..7a0a4266 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -840,6 +840,7 @@ public function setup_admin_menu() { 'manage_qsm_quiz_categories', 'manage_qsm_quiz_answer_label', 'view_qsm_quiz_result', + 'manage_options', ); add_menu_page( 'Quiz And Survey Master', __( 'QSM', 'quiz-master-next' ), $capabilities[1], 'qsm_dashboard', 'qsm_generate_dashboard_page', 'dashicons-feedback', $menu_position ); @@ -862,7 +863,7 @@ public function setup_admin_menu() { add_submenu_page( 'qsm_dashboard', __( 'Failed DB Queries', 'quiz-master-next' ), __( 'Failed Database Queries', 'quiz-master-next' ), $capabilities[2], 'qsm-database-failed-queries', array( $this, 'qsm_database_failed_queries' ) ); } add_submenu_page( 'options.php', __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), $capabilities[5], 'qsm_quiz_result_details', 'qsm_generate_result_details' ); - add_submenu_page( 'qsm_dashboard', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), $capabilities[2], 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) ); + add_submenu_page( 'qsm_dashboard', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), $capabilities[6], 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) ); add_submenu_page( 'qsm_dashboard', __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), $capabilities[2], 'qsm_quiz_tools', 'qsm_generate_quiz_tools' ); add_submenu_page( 'qsm_dashboard', __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), $capabilities[2], 'qmn_stats', 'qmn_generate_stats_page' ); add_submenu_page( 'qsm_dashboard', __( 'About', 'quiz-master-next' ), __( 'About', 'quiz-master-next' ), $capabilities[2], 'qsm_quiz_about', 'qsm_generate_about_page' ); From 0b8442a447f57413239559f1c3623e041ac63030 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Sat, 26 Oct 2024 15:39:56 +0530 Subject: [PATCH 09/48] fixed string intiger issue --- php/template-variables.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/php/template-variables.php b/php/template-variables.php index 5a561122..ff047bc8 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -496,7 +496,10 @@ function mlw_qmn_variable_user_email( $content, $mlw_quiz_array ) { function qsm_contact_field_variable( $content, $results_array ) { preg_match_all( '~%CONTACT_(.*?)%~i', $content, $matches ); for ( $i = 0; $i < count( $matches[0] ); $i++ ) { - $content = str_replace( '%CONTACT_' . $matches[1][ $i ] . '%', $results_array['contact'][ $matches[1][ $i ] - 1 ]['value'], $content ); + $contact_index = intval($matches[1][ $i ]) - 1; + if ( isset($results_array['contact'][ $contact_index ]['value']) ) { + $content = str_replace('%CONTACT_' . $matches[1][ $i ] . '%', $results_array['contact'][ $contact_index ]['value'], $content); + } } return $content; } From f3fc08662193c0f374bef4de1261fed29bff5774 Mon Sep 17 00:00:00 2001 From: manandeep singh Date: Mon, 28 Oct 2024 10:43:52 +0530 Subject: [PATCH 10/48] Fix Completion time is doubled in user dashboard --- js/qsm-quiz.js | 2 -- php/template-variables.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 125b4e41..31000d6e 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -52,8 +52,6 @@ var qsmTimerInterval = []; if (quiz.hasOwnProperty('timer_limit') && 0 != quiz.timer_limit) { QSM.initTimer(quizID); quizType = 'timer'; - } else { - qsmTimerInterval[quizID] = setInterval(function () { qmnTimeTakenTimer(quizID) }, 1000); } if (jQuery('.qsm-quiz-container-' + quizID + ' .qsm-submit-btn').is(':visible') && !jQuery('.qsm-quiz-container-' + quizID).hasClass('qsm_auto_pagination_enabled') ) { jQuery('.qsm-quiz-container-' + quizID + ' .qsm-quiz-comment-section').fadeIn(); diff --git a/php/template-variables.php b/php/template-variables.php index 5a561122..de3bb42e 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -1597,7 +1597,7 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) { * @since 7.3.3 */ function qmn_sanitize_input_data( $data, $strip = false ) { - if ( $strip ) { + if ( $strip && is_string( $data ) ) { $data = stripslashes( $data ); } return maybe_unserialize( $data ); From 6221a68d5a459d334ce75d52752d344fd2ff873f Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Mon, 28 Oct 2024 11:38:24 +0530 Subject: [PATCH 11/48] added option to deactivate question --- css/qsm-admin.css | 9 ++++++++ js/qsm-admin.js | 20 +++++++++++++++++ php/admin/options-page-questions-tab.php | 9 +++++--- php/classes/class-qmn-plugin-helper.php | 28 +++++++++++++++++++++++- php/classes/class-qmn-quiz-manager.php | 7 ++++++ php/classes/class-qsm-questions.php | 14 ++++++++---- php/rest-api.php | 5 +++-- 7 files changed, 82 insertions(+), 10 deletions(-) diff --git a/css/qsm-admin.css b/css/qsm-admin.css index f15f72b6..fae45f1a 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -1250,6 +1250,10 @@ h3.addon_category_name { width: 60px; height: 34px; } +.switch.small-switch { + width: 50px; + height: 22px; +} /* Hide default HTML checkbox */ .switch input[type="checkbox"] { opacity: 0; @@ -1279,6 +1283,11 @@ h3.addon_category_name { -webkit-transition: 0.4s; transition: 0.4s; } +.switch.small-switch .slider:before { + height: 14px; + width: 15px; + left: 5px; +} input:checked+.slider { background-color: #2196f3; } diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 277e3378..460eed0c 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2346,6 +2346,7 @@ var import_button; var type = $("#question_type").val(); var comments = $("#comments").val(); let required = $(".questionElements input[name='required']").is(":checked") ? 0 : 1; + let isPublished = $(".questionElements input[name='question_status']").is(":checked") ? 1 : 0; advanced_option['required'] = required; var category = $(".category-radio:checked").val(); var type_arr = []; @@ -2434,6 +2435,7 @@ var import_button; }); model.set('answers', answers); model.set('required', required); + model.set('is_published', isPublished); 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) { @@ -2748,6 +2750,9 @@ var import_button; } //Append extra settings var all_setting = question.get('settings'); + if ((typeof all_setting === 'undefined') || (all_setting && typeof all_setting.isPublished === 'undefined')) { + $('#question-status').prop('checked', true).trigger('change'); + } if (all_setting === null || typeof all_setting === "undefined") { } else { $.each(all_setting, function (index, value) { if ($('#' + index + '_area').length > 0) { @@ -2765,6 +2770,13 @@ var import_button; if (index == 'matchAnswer') { $('#match-answer').val(value); } + if (index == 'isPublished') { + if ( all_setting.isPublished == 1 ) { + $('#question-status').prop('checked', true).trigger('change'); + } else { + $('#question-status').prop('checked', false).trigger('change'); + } + } }); jQuery(document).trigger('qsm_all_question_setting_after', [all_setting]); } @@ -3202,6 +3214,14 @@ var import_button; event.preventDefault(); $(this).parents('.questionElements').slideUp('slow'); }); + $(document).on('change', '#question-status', function (event) { + event.preventDefault(); + if($(this).is(':checked')){ + $(document).find('#question-status-text').html('Published'); + } else { + $(document).find('#question-status-text').html('Draft'); + } + }); $(document).on('click', '#save-popup-button', function (event) { event.preventDefault(); questionElements = $(this).parents('.questionElements'); diff --git a/php/admin/options-page-questions-tab.php b/php/admin/options-page-questions-tab.php index 33ceaa4f..10d18aea 100644 --- a/php/admin/options-page-questions-tab.php +++ b/php/admin/options-page-questions-tab.php @@ -54,8 +54,8 @@ function qsm_options_questions_tab_content() { $form_type = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'form_type' ); $quiz_system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system' ); $default_answers = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'default_answers' ); - $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() ); - $db_qpages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() ); + $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array(), 'admin' ); + $db_qpages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array(), 'admin' ); $qpages = array(); if ( ! empty( $pages ) ) { $defaultQPage = array( @@ -513,7 +513,10 @@ class="save-page-button button button-primary">

- + +

diff --git a/php/classes/class-qmn-plugin-helper.php b/php/classes/class-qmn-plugin-helper.php index d6c6ffae..286530e9 100644 --- a/php/classes/class-qmn-plugin-helper.php +++ b/php/classes/class-qmn-plugin-helper.php @@ -284,8 +284,34 @@ public function get_section_setting( $section, $setting, $default = false ) { * @param mixed $default What we need to return if no setting exists with given $setting * @return $mixed Value set for $setting or $default if setting does not exist */ - public function get_quiz_setting( $setting, $default = false ) { + public function get_quiz_setting( $setting, $default = false, $caller = '' ) { global $mlwQuizMasterNext; + if ( ( $setting === 'pages' || $setting === 'qpages' ) && empty( $caller ) ) { + $pages = $mlwQuizMasterNext->quiz_settings->get_setting( $setting, $default ); + $temp_pages = array(); + foreach ( $pages as $index => $page ) { + $page_should_display = array(); + $page = $setting === 'qpages' ? $page['questions'] : $page; + foreach ( $page as $key =>$question_id ) { + $isPublished = $mlwQuizMasterNext->pluginHelper->get_question_setting( $question_id, 'isPublished' ); + if ( '' == $isPublished || ( '' != $isPublished && 1 === intval( $isPublished ) ) ) { + $page_should_display[] = true; + } elseif ( '' != $isPublished && 0 === intval( $isPublished ) ) { + $page_should_display[] = false; + unset( $page[$key] ); + } + } + if ( in_array( true, $page_should_display, true ) ) { + if ( $setting === 'qpages' ) { + $pages[$index]['questions'] = $page; + $temp_pages[] = $pages[$index]; + } else { + $temp_pages[] = $page; + } + } + } + return $temp_pages; + } return $mlwQuizMasterNext->quiz_settings->get_setting( $setting, $default ); } diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 756641c2..c89cbec3 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -993,6 +993,13 @@ public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $questio question_settings ); + return ! isset( $question_settings['isPublished'] ) || $question_settings['isPublished'] !== '0'; + } + ); return apply_filters( 'qsm_load_questions_filter', $questions, $quiz_id, $quiz_options ); } diff --git a/php/classes/class-qsm-questions.php b/php/classes/class-qsm-questions.php index 52f6441e..b510429c 100644 --- a/php/classes/class-qsm-questions.php +++ b/php/classes/class-qsm-questions.php @@ -66,7 +66,7 @@ public static function load_question_data( $question_id, $question_data ) { * @param int $quiz_id The ID of the quiz. * @return array The array of questions. */ - public static function load_questions_by_pages( $quiz_id ) { + public static function load_questions_by_pages( $quiz_id, $caller = '' ) { // Prepares our variables. global $wpdb; global $mlwQuizMasterNext; @@ -77,7 +77,7 @@ public static function load_questions_by_pages( $quiz_id ) { // Gets the pages for the quiz. $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz_id ); - $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() ); + $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array(), $caller ); // Get all question IDs needed. if ( ! empty( $pages ) ) { @@ -125,7 +125,7 @@ public static function load_questions_by_pages( $quiz_id ) { } } else { // If we do not have pages on this quiz yet, use older load_questions and add page to them. - $questions = self::load_questions( $quiz_id ); + $questions = self::load_questions( $quiz_id, $caller ); foreach ( $questions as $key => $question ) { $questions[ $key ]['page'] = isset( $question['page'] ) ? $question['page'] : 0; } @@ -140,7 +140,7 @@ public static function load_questions_by_pages( $quiz_id ) { * @param int $quiz_id The ID of the quiz. * @return array The array of questions. */ - public static function load_questions( $quiz_id ) { + public static function load_questions( $quiz_id, $caller = '' ) { global $wpdb; $question_array = array(); @@ -178,6 +178,12 @@ public static function load_questions( $quiz_id ) { $question_array[ $question['question_id'] ] = $question; } + $question_array = ! empty( $caller ) ? $question_array : array_filter( + $question_array, + function ( $question ) { + return ! isset( $question['settings']['isPublished'] ) || $question['settings']['isPublished'] !== '0'; + } + ); return apply_filters( 'qsm_load_questions', $question_array, $quiz_id ); } diff --git a/php/rest-api.php b/php/rest-api.php index bbb612a1..8e3ca48d 100644 --- a/php/rest-api.php +++ b/php/rest-api.php @@ -533,9 +533,9 @@ function qsm_rest_get_questions( WP_REST_Request $request ) { if ( 0 !== $current_user ) { $quiz_id = isset( $request['quizID'] ) ? intval( $request['quizID'] ) : 0; if ( 0 !== $quiz_id ) { - $questions = QSM_Questions::load_questions_by_pages( $quiz_id ); + $questions = QSM_Questions::load_questions_by_pages( $quiz_id, 'admin' ); } else { - $questions = QSM_Questions::load_questions( 0 ); + $questions = QSM_Questions::load_questions( 0, 'admin' ); } global $wpdb; $question_array = array(); @@ -677,6 +677,7 @@ function qsm_rest_save_question( WP_REST_Request $request ) { $settings['featureImageID'] = sanitize_text_field( $request['featureImageID'] ); $settings['featureImageSrc'] = sanitize_text_field( $request['featureImageSrc'] ); $settings['matchAnswer'] = sanitize_text_field( $request['matchAnswer'] ); + $settings['isPublished'] = sanitize_text_field( $request['is_published'] ); if ( isset( $request['other_settings'] ) && is_array( $request['other_settings'] ) ) { foreach ( $request['other_settings'] as $setting_key => $setting_value ) { $settings[ $setting_key ] = $setting_value; From ab226dfd6d8fcdc98cd5023ab4f5f3cac050113c Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Mon, 28 Oct 2024 12:27:20 +0530 Subject: [PATCH 12/48] Modified class name --- css/qsm-admin.css | 22 +++++++++++----------- php/admin/options-page-questions-tab.php | 4 ++-- php/admin/settings-page.php | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/css/qsm-admin.css b/css/qsm-admin.css index 5fd2986e..6c64c879 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -1244,24 +1244,24 @@ h3.addon_category_name { margin-left: 15px; } /* The switch - the box around the slider */ -.switch { +.qsm-checkbox-switch { position: relative; display: inline-block; width: 60px; height: 34px; } -.switch.small-switch { +.qsm-checkbox-switch.small-switch { width: 50px; height: 22px; } /* Hide default HTML checkbox */ -.switch input[type="checkbox"] { +.qsm-checkbox-switch input[type="checkbox"] { opacity: 0; width: 0; height: 0; } /* The slider */ -.slider { +.qsm-switch-slider { position: absolute; cursor: pointer; top: 0; @@ -1272,7 +1272,7 @@ h3.addon_category_name { -webkit-transition: 0.4s; transition: 0.4s; } -.slider:before { +.qsm-switch-slider:before { position: absolute; content: ""; height: 26px; @@ -1283,27 +1283,27 @@ h3.addon_category_name { -webkit-transition: 0.4s; transition: 0.4s; } -.switch.small-switch .slider:before { +.qsm-checkbox-switch.small-switch .qsm-switch-slider:before { height: 14px; width: 15px; left: 5px; } -input:checked+.slider { +input:checked+.qsm-switch-slider { background-color: #2196f3; } -input:focus+.slider { +input:focus+.qsm-switch-slider { box-shadow: 0 0 1px #2196f3; } -input:checked+.slider:before { +input:checked+.qsm-switch-slider:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } /* Rounded sliders */ -.slider.round { +.qsm-switch-slider.round { border-radius: 34px; } -.slider.round:before { +.qsm-switch-slider.round:before { border-radius: 50%; } input#sc-shortcode-model-text, input#sc-shortcode-model-text-link { diff --git a/php/admin/options-page-questions-tab.php b/php/admin/options-page-questions-tab.php index 10d18aea..c87edd25 100644 --- a/php/admin/options-page-questions-tab.php +++ b/php/admin/options-page-questions-tab.php @@ -513,8 +513,8 @@ class="save-page-button button button-primary">

-

- +