diff --git a/php/template-variables.php b/php/template-variables.php index b6e00b96c..2fa360758 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -167,8 +167,10 @@ function qsm_variable_single_answer( $content, $mlw_quiz_array ) { * @return string $content */ function qsm_variable_total_possible_points( $content, $mlw_quiz_array ) { - if ( isset( $mlw_quiz_array['total_possible_points'] ) ) { - $content = str_replace( '%MAXIMUM_POINTS%', $mlw_quiz_array['total_possible_points'], $content ); + if ( isset( $mlw_quiz_array['total_possible_points'] ) && qsm_is_allow_score_roundoff() ) { + $content = str_replace( '%MAXIMUM_POINTS%', round( $mlw_quiz_array['total_possible_points'] ), $content ); + } elseif ( isset( $mlw_quiz_array['total_possible_points'] ) ) { + $content = str_replace( '%MAXIMUM_POINTS%', round( $mlw_quiz_array['total_possible_points'], 2 ), $content ); } return $content; } @@ -325,6 +327,8 @@ function mlw_qmn_variable_point_score( $content, $mlw_quiz_array ) { $score_roundoff = $mlwQuizMasterNext->pluginHelper->get_section_setting('quiz_options', 'score_roundoff' ); if ( $score_roundoff && isset( $mlw_quiz_array['total_points'] ) ) { $mlw_quiz_array['total_points'] = round( $mlw_quiz_array['total_points'] ); + } elseif ( isset( $mlw_quiz_array['total_points'] ) ) { + $mlw_quiz_array['total_points'] = round( $mlw_quiz_array['total_points'], 2 ); } $content = str_replace( '%POINT_SCORE%', ( isset( $mlw_quiz_array['total_points'] ) ? $mlw_quiz_array['total_points'] : '' ), $content ); return $content; @@ -392,7 +396,9 @@ function mlw_qmn_variable_total_questions( $content, $mlw_quiz_array ) { } function mlw_qmn_variable_correct_score( $content, $mlw_quiz_array ) { - $content = str_replace( '%CORRECT_SCORE%', ( isset( $mlw_quiz_array['total_score'] ) ? round( $mlw_quiz_array['total_score'] ) : '' ), $content ); + $correct_score = isset( $mlw_quiz_array['total_score'] ) ? $mlw_quiz_array['total_score'] : ''; + $correct_score = qsm_is_allow_score_roundoff() ? round( $correct_score ) : round( $correct_score, 2 ); + $content = str_replace( '%CORRECT_SCORE%', $correct_score, $content ); return $content; } @@ -679,6 +685,7 @@ function qmn_variable_category_points( $content, $mlw_quiz_array ) { $return_points = 0; } $return_points = apply_filters( 'qsm_category_points', $return_points, $category_name, $mlw_quiz_array ); + $return_points = qsm_is_allow_score_roundoff() ? round( $return_points ) : round( $return_points, 2 ); $content = str_replace( '%CATEGORY_POINTS_' . $category_name . '%', $return_points, $content ); } return $content; @@ -860,6 +867,7 @@ function qmn_variable_category_average_points( $content, $mlw_quiz_array ) { $total_categories += 1; } $return_score = $total_points / $total_categories; + $return_score = qsm_is_allow_score_roundoff() ? round( $return_score ) : round( $return_score, 2 ); $content = str_replace( '%CATEGORY_AVERAGE_POINTS%', $return_score, $content ); } return $content; @@ -1425,16 +1433,7 @@ function qsm_get_question_maximum_points( $question = array() ) { */ function qsm_is_allow_score_roundoff() { global $mlwQuizMasterNext; - $score_roundoff = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'score_roundoff' ); - $form_type = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'form_type' ); - $system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system' ); - - // check if quiz type Quiz and Geading system Correct/Incorrect Or Both Type - if ( $score_roundoff && 0 == $form_type && ( 0 == $system || 3 == $system ) ) { - return 1; - } else { - return 0; - } + return $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'score_roundoff' ); } /** * Display Polor Question on Result page @@ -1574,7 +1573,9 @@ function qmn_sanitize_input_data( $data, $strip = false ) { */ function qsm_variable_minimum_points( $content, $mlw_quiz_array ) { if ( isset( $mlw_quiz_array['minimum_possible_points'] ) ) { - $content = str_replace( '%MINIMUM_POINTS%', $mlw_quiz_array['minimum_possible_points'], $content ); + $min_points = $mlw_quiz_array['minimum_possible_points']; + $min_points = qsm_is_allow_score_roundoff() ? round( $min_points ) : round( $min_points, 2 ); + $content = str_replace( '%MINIMUM_POINTS%', $min_points, $content ); } return $content; }