LLMS_Quiz_Attempt::delete()

Delete the object from the database


Description Description

Overrides the parent method to perform other actions before deletion.


Top ↑

Return Return

(bool) true on success, false otherwise.


Top ↑

Source Source

File: includes/models/model.llms.quiz.attempt.php

	public function delete() {

		if ( ! $this->id ) {
			return false;
		}

		$lesson = llms_get_post( $this->get( 'lesson_id' ) );

		// No lesson, or lesson incomplete, nothing special to do here.
		if ( ! $lesson || ! ( $lesson instanceof LLMS_Lesson ) || ! llms_is_complete( $this->get( 'student_id' ), $this->get( 'lesson_id' ), 'lesson' ) ) {
			return parent::delete();
		}

		/**
		 * Prepare the query args to retrieve at least another sibling attempt,
		 * excluding the current one.
		 */
		$sibling_query_args = array(
			'exclude'  => $this->get_id( 'id' ),
			'per_page' => 1,
		);

		/**
		 * If this lesson requires a passing grade, then retrieve only the possible passed sibling
		 * that might have been triggered the lesson completion.
		 */
		if ( llms_parse_bool( $lesson->get( 'require_passing_grade' ) ) ) {
			$sibling_query_args['status'] = array(
				'pass',
			);
		}

		$sibling_attempts = $this->get_siblings( $sibling_query_args, 'ids' );

		// If this is the only one relevant left attempt.
		if ( empty( $sibling_attempts ) ) {
			llms_mark_incomplete(
				$this->get( 'student_id' ),
				$this->get( 'lesson_id' ),
				'lesson',
				'quiz_' . $this->get( 'quiz_id' )
			);
		}

		return parent::delete();
	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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