UserData::complete_course_content( $content_id, string $scope = 'complete' )

Complete course content and save it to data


Description

long description

Example usage:

$completed_id = dozent_complete_content( $content_id , $user_id );

See also


Parameters

$content_id

(Required)

$scope

(string) (Optional) Scope of completion

Default value: 'complete'


Return

(int)


Source

File: classes/UserData.php

	public function complete_course_content( $content_id, $scope = 'complete' ) {
		global $wpdb;

		/**
		 * Complete the course content first
		 */

		$user_id = $this->user_id;

		if ( ! $user_id ) {
			return false;
		}

		$course_id = dozent_get_course_id_by_content( $content_id );

		$isCompleted
			= $wpdb->get_row( "SELECT * FROM {$wpdb->dozent_completes} WHERE course_id = {$course_id} AND content_id = {$content_id} AND user_id = {$user_id} " );

		if ( ! $isCompleted ) {

			$data = [
				'user_id'      => $user_id,
				'course_id'    => $course_id,
				'content_id'   => $content_id,
				'completed_at' => dozent_mysql_time(),
			];

			do_action( 'dozent/course_content/complete/before', $content_id, $data );

			$wpdb->insert( $wpdb->dozent_completes, $data );
			$complete_id = (int) $wpdb->insert_id;

			do_action( 'dozent/course_content/complete/after', $content_id, $data );

		} else {
			$complete_id = $isCompleted->complete->ID;
		}

		/**
		 * Then save all completed contents into the user data
		 */

		$this->_sync_complete_course_content_with_user_data( $course_id, $content_id, $scope);

		return $complete_id;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.