LLMS_Question::grade( array $answer )

Attempt to grade a question


Description Description


Parameters Parameters

$answer

(array) (Required) selected answer(s)


Top ↑

Return Return

(mixed) yes = correct no = incorrect null = not auto gradable


Top ↑

Source Source

File: includes/models/model.llms.question.php

	public function grade( $answer ) {

		/**
		 * Allow 3rd parties to do custom grading
		 * If filter returns non-null will bypass core grading
		 */
		$grade = apply_filters( 'llms_' . $this->get( 'question_type' ) . '_question_pre_grade', null, $answer, $this );

		if ( is_null( $grade ) ) {

			if ( $this->get( 'points' ) >= 1 ) {

				$grading_type = $this->get_auto_grade_type();

				if ( 'choices' === $grading_type ) {

					sort( $answer );
					$grade = ( $answer === $this->get_correct_choice() ) ? 'yes' : 'no';

				} elseif ( 'conditional' === $grading_type ) {

					$correct = $this->get_conditional_correct_value();

					// allow case sensitivity to be enabled if required
					if ( false === apply_filters( 'llms_quiz_grading_case_sensitive', false, $answer, $correct, $this ) ) {

						$answer = array_map( 'strtolower', $answer );
						$correct = array_map( 'strtolower', $correct );

					}

					$grade = ( $answer === $correct ) ? 'yes' : 'no';

				}
			}
		}

		return apply_filters( 'llms_' . $this->get( 'question_type' ) . '_question_grade', $grade, $answer, $this );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: