Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added roundoff feature in percentage & points variable #2478

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Loading