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
Description Description
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 ) { $remarks = isset( $_POST['remarks'] ) ? $_POST['remarks'] : array(); $points = isset( $_POST['points'] ) ? $_POST['points'] : 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' ) ) ) { $attempt->do_completion_actions(); } do_action( 'llms_quiz_graded', $attempt->get_student()->get_id(), $attempt->get( 'quiz_id' ), $attempt ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.30.3 | Strip slashes on remarks. |
3.16.0 | Introduced. |