Skip to content

Commit

Permalink
Fixed sonar cloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
etchirag committed Oct 4, 2024
1 parent 8169a2d commit 705193b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
6 changes: 4 additions & 2 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2246,9 +2246,11 @@ var qsm_link_button;

$('.import-button, .link-question').removeClass('disable_import');
QSMQuestion.countTotal();
import_button ? import_button.html('').html(qsm_admin_messages.add_question) : "";
if(import_button){
import_button.html(qsm_admin_messages.add_question);
}
if(qsm_link_button) {
qsm_link_button.html('').html(qsm_admin_messages.link_question);
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 + "');");
Expand Down
14 changes: 6 additions & 8 deletions php/admin/options-page-questions-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ function qsm_process_unlink_question_from_list_by_question_id( $question_id ) {
$updated_linked_list = implode(',', array_filter($current_links));
$linked_ids = explode(',', $updated_linked_list);
foreach ( $linked_ids as $linked_id ) {
$result = $wpdb->update(
$wpdb->update(
$wpdb->prefix . 'mlw_questions',
array( 'linked_question' => $updated_linked_list ),
array( 'question_id' => intval($linked_id) ),
Expand Down Expand Up @@ -1248,7 +1248,7 @@ function qsm_bulk_delete_question_from_database() {
$update_qpages_after_delete = array();
$dependent_question_ids = qsm_get_unique_linked_question_ids_to_remove($question_id);
if ( ! empty($dependent_question_ids) ) {
$dependent_question_ids = array_diff($dependent_question_ids, [ $base_question_id ] );
$dependent_question_ids = array_diff($dependent_question_ids, [ $base_question_ids ] );
$update_qpages_after_delete = qsm_process_to_update_qpages_after_unlink($dependent_question_ids);
}
$question_id = array_merge($dependent_question_ids, $question_id);
Expand Down Expand Up @@ -1299,18 +1299,16 @@ function qsm_process_to_update_qpages_after_unlink( $dependent_question_ids ) {
global $wpdb, $mlwQuizMasterNext;
$quiz_results = $wpdb->get_results( "SELECT `quiz_id`, `question_id` FROM `{$wpdb->prefix}mlw_questions` WHERE `question_id` IN (" .$comma_seprated_ids. ")" );
if ( ! empty($quiz_results) ) {
foreach ( $quiz_results as $key => $single_quiz ) {
foreach ( $quiz_results as $single_quiz ) {
$quiz_id = $single_quiz->quiz_id;
$mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz_id );
$pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
$clone_qpages = $qpages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() );
if ( ! empty($clone_qpages) ) {
foreach ( $clone_qpages as $clonekey => $clonevalue ) {
if ( ! empty($clonevalue['questions']) ) {
if ( in_array($single_quiz->question_id, $clonevalue['questions']) ) {
$clone_qpages[ $clonekey ]['questions'] = array_diff($clonevalue['questions'], [ $single_quiz->question_id ]);
$pages[ $clonekey ] = array_diff($pages[ $clonekey ], [ $single_quiz->question_id ]);
}
if ( ! empty($clonevalue['questions']) && in_array($single_quiz->question_id, $clonevalue['questions']) ) {
$clone_qpages[ $clonekey ]['questions'] = array_diff($clonevalue['questions'], [ $single_quiz->question_id ]);
$pages[ $clonekey ] = array_diff($pages[ $clonekey ], [ $single_quiz->question_id ]);
}
}
$qpages = $clone_qpages;
Expand Down
3 changes: 1 addition & 2 deletions php/classes/class-qsm-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ private static function create_save_question( $data, $answers, $settings, $is_cr
$quiz_questions_array = array();
$quiz_questions_array[ intval( $data['quiz_id'] ) ] = $question_id;
$linked_questions_array[] = $question_id;
$imploded_question_ids = $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);
Expand All @@ -383,7 +382,7 @@ private static function create_save_question( $data, $answers, $settings, $is_cr
$question_terms_table = $wpdb->prefix . 'mlw_question_terms';
foreach ( $quiz_questions_array as $quiz_id => $question_id_loop ) {
$values['quiz_id'] = intval( $quiz_id );
$results = $wpdb->update(
$wpdb->update(
$wpdb->prefix . 'mlw_questions',
$values,
array( 'question_id' => intval($question_id_loop) ),
Expand Down
2 changes: 1 addition & 1 deletion php/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function qsm_rest_get_question( WP_REST_Request $request ) {
$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 $key => $value ) {
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;
Expand Down

0 comments on commit 705193b

Please sign in to comment.