LLMS_Lesson::get_available_date( string $format = '' )

Get the date a lesson became or will become available according to element drip settings


Description Description

If there are no drip settings, the published date of the element will be returned.


Top ↑

Parameters Parameters

$format

(string) (Optional) Date format (passed to date_i18n()). Default is empty string.<br> When not specified the WP Core date + time formats will be used.

Default value: ''


Top ↑

Return Return

(string)


Top ↑

Source Source

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

	public function get_available_date( $format = '' ) {

		if ( ! $format ) {
			$format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
		}

		$drip_method = $this->get( 'drip_method' );

		$days = $this->get( 'days_before_available' ) * DAY_IN_SECONDS;

		// Default availability is the element's post date.
		$available = $this->get_date( 'date', 'U' );

		// get the course setting first, if any.
		$course = $this->get_course();
		if ( $course && 'yes' === $course->get( 'lesson_drip' ) ) {
			$course_drip_method = $course->get( 'drip_method' );

			switch ( $course_drip_method ) {
				case 'start':
					$ignore_lessons = intval( $course->get( 'ignore_lessons' ) );
					$course_lessons = $course->get_lessons( 'ids' );
					$lesson_number  = array_search( $this->get( 'id' ), $course_lessons ) + 1;

					$course_days            = $course->get( 'days_before_available' ) * DAY_IN_SECONDS;
					$course_start_date      = $course->get_date( 'start_date', 'U' );
					$course_enrollment_date = llms_get_student() ? llms_get_student()->get_enrollment_date( $course->get( 'id' ), 'enrolled', 'U' ) : false;

					// If it's one of the first X lessons in a course, return availability based on published date.
					if ( $lesson_number <= $ignore_lessons ) {
						return date_i18n( $format, $available );
					}

					if ( $course_start_date || $course_enrollment_date ) {
						$available = ( ( $lesson_number - $ignore_lessons ) * $course_days ) + ( $course_start_date ? $course_start_date : $course_enrollment_date );

						return date_i18n( $format, $available );
					}
					break;
			}
		}

		switch ( $drip_method ) {

			// Available on a specific date / time.
			case 'date':
				$date = $this->get( 'date_available' );
				$time = $this->get( 'time_available' );

				if ( ! $time ) {
					$time = '12:00 AM';
				}

				$available = strtotime( $date . ' ' . $time );

				break;

			// Available # of days after enrollment in course.
			case 'enrollment':
				$student = llms_get_student();
				if ( $student ) {
					$available = $days + $student->get_enrollment_date( $this->get( 'parent_course' ), 'enrolled', 'U' );
				}
				break;

			case 'prerequisite':
				if ( $this->has_prerequisite() ) {
					$student = llms_get_student();
					if ( $student ) {
						$date = $student->get_completion_date( $this->get( 'prerequisite' ), 'U' );
						if ( $date ) {
							$available = $days + $date;
						}
					}
				}

				break;

			// Available # of days after course start date.
			case 'start':
				$course            = $this->get_course();
				$course_start_date = $course ? $course->get_date( 'start_date', 'U' ) : '';

				if ( $course_start_date ) {
					$available = $days + $course_start_date;
				}

				break;

		}

		return date_i18n( $format, $available );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.7.0 Replaced the call to the deprecated LLMS_Lesson::get_parent_course() method with LLMS_Lesson::get( 'parent_course' ).
3.36.2 Add available number of days to the course start date only if there's a course start date.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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