Skip to content

Commit

Permalink
Merge pull request #2737 from QuizandSurveyMaster/CU-86cxan40f-total-…
Browse files Browse the repository at this point in the history
…question-variable-count-issue

Cu 86cxan40f total question variable count issue
  • Loading branch information
zubairraeen authored Dec 16, 2024
2 parents 56cf6d5 + cb80ba1 commit 854b1a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 0 additions & 2 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,6 @@ var QSM_Quiz_Broadcast_Channel;
}
CurrentElement.parents('.question').next('.questionElements').slideDown('slow');
$('#modal-1-content').html(questionElements);
//MicroModal.show( 'modal-1' );
$('.questions').sortable('disable');
$('.page').sortable('disable');

Expand Down Expand Up @@ -4144,7 +4143,6 @@ var QSM_Quiz_Broadcast_Channel;
.fail(QSMAdmin.displayjQueryError);
},
loadResults: function () {
//QSMAdmin.displayAlert( 'Loading results pages...', 'info' );
$.ajax({
url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmResultsObject.quizID + '/results',
headers: { 'X-WP-Nonce': qsmResultsObject.nonce },
Expand Down
8 changes: 4 additions & 4 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1875,10 +1875,10 @@ jQuery(document).ready(function () {
let captchaElement = jQuery('#mlw_code_captcha');
if (captchaElement.length !== 0) {
mlw_code = '';
var mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var mlw_code_length = 5;
for (var i = 0; i < mlw_code_length; i++) {
var rnum = Math.floor(Math.random() * mlw_chars.length);
let mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
let mlw_code_length = 5;
for (let i = 0; i < mlw_code_length; i++) {
let rnum = Math.floor(Math.random() * mlw_chars.length);
mlw_code += mlw_chars.substring(rnum, rnum + 1);
}
var captchaCanvas = document.getElementById('mlw_captcha');
Expand Down
11 changes: 9 additions & 2 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,20 @@ function mlw_qmn_variable_amount_incorrect( $content, $mlw_quiz_array ) {

function mlw_qmn_variable_total_questions( $content, $mlw_quiz_array ) {
global $wp_current_filter;
if ( ! empty( $wp_current_filter[1] ) && 'mlw_qmn_template_variable_quiz_page' == $wp_current_filter[1] ) {
if ( is_array( $wp_current_filter ) && ! empty( $wp_current_filter ) && in_array( 'mlw_qmn_template_variable_quiz_page', $wp_current_filter, true ) ) {
global $wpdb;
$table_name = $wpdb->prefix . 'mlw_quizzes';
$quiz_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE quiz_id=%d", $mlw_quiz_array['quiz_id'] ) );
$quiz_settings = maybe_unserialize($quiz_data->quiz_settings);
$quiz_questions = ! empty( $quiz_settings['pages'] ) ? maybe_unserialize( $quiz_settings['pages'] ) : array();
$total_questions = isset( $quiz_questions[0] ) ? count( $quiz_questions[0] ) : 0;
$total_questions = 0;
if ( ! empty( $quiz_questions ) && isset( $quiz_questions[0] ) ) {
foreach ( $quiz_questions as $sub_questions ) {
if ( is_array( $sub_questions ) ) {
$total_questions += count( $sub_questions );
}
}
}
$content = str_replace( '%TOTAL_QUESTIONS%', $total_questions, $content );
return $content;
}
Expand Down

0 comments on commit 854b1a2

Please sign in to comment.