HEX
Server: LiteSpeed
System: Linux dune179.sitesanctuary.org 5.14.0-427.40.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 16 07:08:17 EDT 2024 x86_64
User: h278792 (1197)
PHP: 8.1.29
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/h278792/www/wp-content/plugins/learnpress/inc/course/class-lp-course-utils.php
<?php
/**
 * Class LP_Course_Utils
 */
class LP_Course_Utils {

	/**
	 * Get section data from cache.
	 *
	 * @param int    $course_id
	 * @param string $return
	 *
	 * @return false|mixed
	 * @since 4.0.0
	 */
	public static function get_cached_db_sections( $course_id, $return = '' ) {
		if ( $return === 'ids' ) {
			return LP_Object_Cache::get( $course_id, 'learn-press/course-sections-ids' );

		}

		return LP_Object_Cache::get( 'course-' . $course_id, 'learn-press/course-sections' );
	}

	/**
	 * Set section data to cache.
	 *
	 * @param $course_id
	 * @param $sections
	 *
	 * @return bool
	 * @since 4.0.0
	 */
	public static function set_cache_db_sections( $course_id, $sections ) {
		if ( ! $sections ) {
			LP_Object_Cache::delete( $course_id, 'learn-press/course-sections' );
			LP_Object_Cache::delete( $course_id, 'learn-press/course-sections-ids' );

			return false;
		}

		LP_Object_Cache::set( 'course-' . $course_id, $sections, 'learn-press/course-sections' );
		LP_Object_Cache::set( $course_id, wp_list_pluck( $sections, 'section_id' ), 'learn-press/course-sections-ids' );

		return true;
	}

	public static function get_cached_section( $section_id ) {
		return LP_Object_Cache::get( $section_id, 'learn-press/course-sections-objects' );
	}

	public static function set_cached_section( $section_id, $section_object ) {
		if ( $section_object === false ) {
			return LP_Object_Cache::delete( $section_id, 'learn-press/course-sections-objects' );
		}
		LP_Object_Cache::set( $section_id, $section_object, 'learn-press/course-sections-objects' );

		return true;
	}

	/**
	 * Return ids of all items inside a course from cache.
	 *
	 * @param int $course_id
	 *
	 * @return false|mixed
	 */
	public static function get_course_items( $course_id ) {
		return LP_Object_Cache::get( $course_id, 'learn-press/course-item-ids' );
	}

	/**
	 * Set ids of all items read from db of a course to cache.
	 *
	 * @param int   $course_id
	 * @param array $items
	 */
	public static function set_course_items( $course_id, $items ) {
		LP_Object_Cache::set( $course_id, $items, 'learn-press/course-item-ids' );
	}

	public static function set_course_item_types( $course_id, $items ) {
		LP_Object_Cache::set( 'course-' . $course_id, $items, 'learn-press/course-item-types' );
	}

	public static function get_course_item_types( $course_id ) {
		return LP_Object_Cache::get( 'course-' . $course_id, 'learn-press/course-item-types' );
	}

	public static function set_course_items_group_types( $course_id, $items ) {
		LP_Object_Cache::set( 'course-' . $course_id, $items, 'learn-press/course-item-group-types' );
	}

	public static function get_course_items_group_types( $course_id ) {
		return LP_Object_Cache::set( 'course-' . $course_id, 'learn-press/course-item-group-types' );
	}

	public static function set_section_items( $section_id, $items ) {
		LP_Object_Cache::set( 'section-' . $section_id, $items, 'learn-press/section-items' );
	}

	public static function get_section_items( $section_id ) {
		return LP_Object_Cache::set( 'section-' . $section_id, 'learn-press/section-items' );
	}
}