MPC_MARKCOURSEDONE::mark_lesson_completed( $user_id,  $course_id,  $lesson_id,  $section )


Parameters Parameters

$user_id

(Required)

$course_id

(Required) $ @param $lesson_id


Source Source

File: src/integrations/memberpress-courses/actions/mpc-markcoursedone.php

	public function mark_lesson_completed( $user_id, $course_id, $lesson_id, $section ) {

		if ( empty( $section_id ) && empty( $course_id ) ) {
			return;
		}

		if ( models\UserProgress::has_completed_course( $user_id, $course_id ) ) {
			return;
		}

		$has_started_course  = models\UserProgress::has_started_course( $user_id, $course_id );
		$has_started_section = models\UserProgress::has_started_section( $user_id, $section );

		$user_progress               = new models\UserProgress();
		$user_progress->lesson_id    = $lesson_id;
		$user_progress->course_id    = $course_id;
		$user_progress->user_id      = $user_id;
		$user_progress->created_at   = lib\Utils::ts_to_mysql_date( time() );
		$user_progress->completed_at = lib\Utils::ts_to_mysql_date( time() );
		$user_progress->store();

		do_action( base\SLUG_KEY . '_completed_lesson', $user_progress );

		if ( models\UserProgress::has_completed_course( $user_id, $course_id ) ) {
			do_action( base\SLUG_KEY . '_completed_course', $user_progress );
		}

		if ( models\UserProgress::has_completed_section( $user_id, $section ) ) {
			do_action( base\SLUG_KEY . '_completed_section', $user_progress );
		}
	}