Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Controller_Admin_Quiz_Attempts::save_grade( LLMS_Quiz_Attempt $attempt )
Saves changes to a quiz
Parameters Parameters
- $attempt
-
(LLMS_Quiz_Attempt) (Required) Quiz attempt instance.
Return Return
(void)
Source Source
File: includes/controllers/class.llms.controller.admin.quiz.attempts.php
private function save_grade( $attempt ) { // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in `maybe_run_actions()` method. $remarks = isset( $_POST['remarks'] ) ? llms_filter_input_sanitize_string( INPUT_POST, 'remarks', array( FILTER_REQUIRE_ARRAY ) ) : array(); $points = isset( $_POST['points'] ) ? llms_filter_input_sanitize_string( INPUT_POST, 'points', array( FILTER_REQUIRE_ARRAY ) ) : array(); $questions = $attempt->get_questions(); foreach ( $questions as &$question ) { if ( isset( $remarks[ $question['id'] ] ) ) { $question['remarks'] = wp_kses_post( nl2br( stripslashes( $remarks[ $question['id'] ] ) ) ); } if ( isset( $points[ $question['id'] ] ) ) { $earned = absint( $points[ $question['id'] ] ); $question['earned'] = $earned; if ( ( $earned / $question['points'] ) >= 0.5 ) { $question['correct'] = 'yes'; } else { $question['correct'] = 'no'; } } } // Update the attempt with new questions. $attempt->set_questions( $questions, true ); // Attempt to calculate the grade. $attempt->calculate_grade()->save(); // If all questions were graded the grade will have been calculated and we can trigger completion actions. if ( in_array( $attempt->get( 'status' ), array( 'fail', 'pass' ), true ) ) { $attempt->do_completion_actions(); } do_action( 'llms_quiz_graded', $attempt->get_student()->get_id(), $attempt->get( 'quiz_id' ), $attempt ); // phpcs:enable }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.4.4 | Use strict type comparisons where needed. |
3.35.0 | Sanitize $_POST data. |
3.30.3 | Strip slashes on remarks. |
3.16.0 | Introduced. |