LLMS_REST_Courses_Controller::get_item_schema()

Get the Course’s schema, conforming to JSON Schema.


Return Return

(array)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/class-llms-rest-courses-controller.php

	 * Retrieve an ID from the object.
	 *
	 * @since 1.0.0-beta.7
	 *
	 * @param LLMS_Course $object LLMS_Course object.
	 * @return int
	 */
	protected function get_object_id( $object ) {

		// For example.
		return $object->get( 'id' );

	}

	/**
	 * Get the Course's schema, conforming to JSON Schema.
	 *
	 * @since 1.0.0-beta.27
	 *
	 * @return array
	 */
	protected function get_item_schema_base() {

		$schema = (array) parent::get_item_schema_base();

		$course_properties = array(
			'catalog_visibility'        => array(
				'description' => __( 'Visibility of the course in catalogs and search results.', 'lifterlms' ),
				'type'        => 'string',
				'enum'        => array_keys( llms_get_product_visibility_options() ),
				'default'     => 'catalog_search',
				'context'     => array( 'view', 'edit' ),
			),
			// consider to move tags and cats in the posts controller abstract.
			'categories'                => array(
				'description' => __( 'List of course categories.', 'lifterlms' ),
				'type'        => 'array',
				'items'       => array(
					'type' => 'integer',
				),
				'context'     => array( 'view', 'edit' ),
			),
			'tags'                      => array(
				'description' => __( 'List of course tags.', 'lifterlms' ),
				'type'        => 'array',
				'items'       => array(
					'type' => 'integer',
				),
				'context'     => array( 'view', 'edit' ),
			),
			'difficulties'              => array(
				'description' => __( 'List of course difficulties.', 'lifterlms' ),
				'type'        => 'array',
				'items'       => array(
					'type' => 'integer',
				),
				'context'     => array( 'view', 'edit' ),
			),
			'tracks'                    => array(
				'description' => __( 'List of course tracks.', 'lifterlms' ),
				'type'        => 'array',
				'items'       => array(
					'type' => 'integer',
				),
				'context'     => array( 'view', 'edit' ),
			),
			'instructors'               => array(
				'description' => __( 'List of course instructors. Defaults to current user when creating a new post.', 'lifterlms' ),
				'type'        => 'array',
				'items'       => array(
					'type' => 'integer',
				),
				'arg_options' => array(
					'validate_callback' => 'llms_validate_instructors',
				),
				'context'     => array( 'view', 'edit' ),
			),
			'audio_embed'               => array(
				'description' => __( 'URL to an oEmbed enable audio URL.', 'lifterlms' ),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
				'format'      => 'uri',
				'arg_options' => array(
					'sanitize_callback' => 'esc_url_raw',
				),
			),
			'video_embed'               => array(
				'description' => __( 'URL to an oEmbed enable video URL.', 'lifterlms' ),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
				'format'      => 'uri',
				'arg_options' => array(
					'sanitize_callback' => 'esc_url_raw',
				),
			),
			'capacity_enabled'          => array(
				'description' => __( 'Determines if an enrollment capacity limit is enabled.', 'lifterlms' ),
				'type'        => 'boolean',
				'default'     => false,
			),
			'capacity_limit'            => array(
				'description' => __( 'Number of students who can be enrolled in the course before enrollment closes.', 'lifterlms' ),
				'type'        => 'integer',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => 'absint',
				),
			),
			'capacity_message'          => array(
				'description' => __( 'Message displayed when enrollment capacity has been reached.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
			),
			'prerequisite'              => array(
				'description' => __( 'Course ID of the prerequisite course.', 'lifterlms' ),
				'type'        => 'integer',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => 'absint',
				),
			),
			'prerequisite_track'        => array(
				'description' => __( 'Term ID of a prerequisite track.', 'lifterlms' ),
				'type'        => 'integer',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => 'absint',
				),
			),
			'length'                    => array(
				'description' => __( 'User defined course length.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw length description.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered length description.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
			),
			'restricted_message'        => array(
				'description' => __( 'Message displayed when non-enrolled visitors try to access restricted course content (lessons, quizzes, etc..) directly.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'default'     => __( 'You must enroll in this course to access course content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
				'default'     => __( 'You must enroll in this course to access course content.', 'lifterlms' ),
			),
			'access_closes_date'        => array(
				'description' => __(
					'Date when the course closes. After this date enrolled students may no longer view and interact with the restricted course content.
					If blank the course is open indefinitely after the the access_opens_date has passed.
					Does not affect course enrollment, see enrollment_opens_date to control the course enrollment close date.
					Format: Y-m-d H:i:s.',
					'lifterlms'
				),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
			),
			'access_closes_message'     => array(
				'description' => __( 'Message displayed to enrolled students when the course is accessed after the access_closes_date has passed.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
				'default'     => __( 'This course closed on [lifterlms_course_info id="{{course_id}}" key="end_date"].', 'lifterlms' ),
			),
			'access_opens_date'         => array(
				'description' => __(
					'Date when the course opens, allowing enrolled students to begin to view and interact with the restricted course content.
					If blank the course is open until after the access_closes_date has passed.
					Does not affect course enrollment, see enrollment_opens_date to control the course enrollment start date.
					Format: Y-m-d H:i:s.',
					'lifterlms'
				),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
			),
			'access_opens_message'      => array(
				'description' => __( 'Message displayed to enrolled students when the course is accessed before the access_opens_date has passed.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
				'default'     => __( 'This course opens on [lifterlms_course_info id="{{course_id}}" key="start_date"].', 'lifterlms' ),
			),
			'enrollment_closes_date'    => array(
				'description' => __(
					'Date when the course enrollment closes.
					If blank course enrollment is open indefinitely after the the enrollment_opens_date has passed.
					Does not affect course content access, see access_opens_date to control course access close date.
					Format: Y-m-d H:i:s.',
					'lifterlms'
				),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
			),
			'enrollment_closes_message' => array(
				'description' => __( 'Message displayed to visitors when attempting to enroll into a course after the enrollment_closes_date has passed.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
				'default'     => __( 'Enrollment in this course closed on [lifterlms_course_info id="{{course_id}}" key="enrollment_end_date"].', 'lifterlms' ),
			),
			'enrollment_opens_date'     => array(
				'description' => __(
					'Date when the course enrollment opens.
					If blank course enrollment is open until after the enrollment_closes_date has passed.
					Does not affect course content access, see access_opens_date to control course access start date.
					Format: Y-m-d H:i:s.',
					'lifterlms'
				),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
			),
			'enrollment_opens_message'  => array(
				'description' => __( 'Message displayed to visitors when attempting to enroll into a course before the enrollment_opens_date has passed.', 'lifterlms' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
				),
				'properties'  => array(
					'raw'      => array(
						'description' => __( 'Raw message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'edit' ),
					),
					'rendered' => array(
						'description' => __( 'Rendered message content.', 'lifterlms' ),
						'type'        => 'string',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
				),
				'default'     => __( 'Enrollment in this course opens on [lifterlms_course_info id="{{course_id}}" key="enrollment_start_date"].', 'lifterlms' ),
			),
			'sales_page_page_id'        => array(
				'description' => __(
					'The WordPress page ID of the sales page. Required when sales_page_type equals page. Only returned when the sales_page_type equals page.',
					'lifterlms'
				),
				'type'        => 'integer',
				'context'     => array( 'view', 'edit' ),
				'arg_options' => array(
					'sanitize_callback' => 'absint',
				),
			),
			'sales_page_type'           => array(
				'description' => __(
					'Determines the type of sales page content to display.<br> - <code>none</code> displays the course content.<br> - <code>content</code> displays alternate content from the <code>excerpt</code> property.<br> - <code>page</code> redirects to the WordPress page defined in <code>content_page_id</code>.<br> - <code>url</code> redirects to the URL defined in <code>content_page_url</code>',
					'lifterlms'
				),
				'type'        => 'string',
				'default'     => 'none',
				'enum'        => array_keys( llms_get_sales_page_types() ),
				'context'     => array( 'view', 'edit' ),
			),
			'sales_page_url'            => array(
				'description' => __(
					'The URL of the sales page content. Required when <code>content_type</code> equals <code>url</code>. Only returned when the <code>content_type</code> equals <code>url</code>.',
					'lifterlms'
				),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
				'format'      => 'uri',
				'arg_options' => array(
					'sanitize_callback' => 'esc_url_raw',
				),


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.9 Make sure instructors list is either not empty and composed by real user ids. Added llms_rest_course_item_schema filter hook.
1.0.0-beta.8 Renamed sales_page_page_type and sales_page_page_url properties, respectively to sales_page_type and sales_page_url according to the specs. Add missing quotes in enrollment/access default messages shortcodes.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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