| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class LP_Course_Utils |
| 4 |
* |
| 5 |
* @depecated 4.1.6.9 |
| 6 |
*/ |
| 7 |
class LP_Course_Utils { |
| 8 |
|
| 9 |
/** |
| 10 |
* Get section data from cache. |
| 11 |
* |
| 12 |
* @param int $course_id |
| 13 |
* @param string $return |
| 14 |
* |
| 15 |
* @return false|mixed |
| 16 |
* @since 4.0.0 |
| 17 |
*/ |
| 18 |
public static function get_cached_db_sections( $course_id, $return = '' ) { |
| 19 |
if ( $return === 'ids' ) { |
| 20 |
return LP_Object_Cache::get( $course_id, 'learn-press/course-sections-ids' ); |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
return LP_Object_Cache::get( 'course-' . $course_id, 'learn-press/course-sections' ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Set section data to cache. |
| 29 |
* |
| 30 |
* @param $course_id |
| 31 |
* @param $sections |
| 32 |
* |
| 33 |
* @return bool |
| 34 |
* @since 4.0.0 |
| 35 |
*/ |
| 36 |
public static function set_cache_db_sections( $course_id, $sections ) { |
| 37 |
if ( ! $sections ) { |
| 38 |
LP_Object_Cache::delete( $course_id, 'learn-press/course-sections' ); |
| 39 |
LP_Object_Cache::delete( $course_id, 'learn-press/course-sections-ids' ); |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
LP_Object_Cache::set( 'course-' . $course_id, $sections, 'learn-press/course-sections' ); |
| 45 |
LP_Object_Cache::set( $course_id, wp_list_pluck( $sections, 'section_id' ), 'learn-press/course-sections-ids' ); |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
public static function get_cached_section( $section_id ) { |
| 51 |
return LP_Object_Cache::get( $section_id, 'learn-press/course-sections-objects' ); |
| 52 |
} |
| 53 |
|
| 54 |
public static function set_cached_section( $section_id, $section_object ) { |
| 55 |
if ( $section_object === false ) { |
| 56 |
return LP_Object_Cache::delete( $section_id, 'learn-press/course-sections-objects' ); |
| 57 |
} |
| 58 |
LP_Object_Cache::set( $section_id, $section_object, 'learn-press/course-sections-objects' ); |
| 59 |
|
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Return ids of all items inside a course from cache. |
| 65 |
* |
| 66 |
* @param int $course_id |
| 67 |
* |
| 68 |
* @return false|mixed |
| 69 |
*/ |
| 70 |
public static function get_course_items( $course_id ) { |
| 71 |
return LP_Object_Cache::get( $course_id, 'learn-press/course-item-ids' ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Set ids of all items read from db of a course to cache. |
| 76 |
* |
| 77 |
* @param int $course_id |
| 78 |
* @param array $items |
| 79 |
*/ |
| 80 |
public static function set_course_items( $course_id, $items ) { |
| 81 |
LP_Object_Cache::set( $course_id, $items, 'learn-press/course-item-ids' ); |
| 82 |
} |
| 83 |
|
| 84 |
public static function set_course_item_types( $course_id, $items ) { |
| 85 |
LP_Object_Cache::set( 'course-' . $course_id, $items, 'learn-press/course-item-types' ); |
| 86 |
} |
| 87 |
|
| 88 |
public static function get_course_item_types( $course_id ) { |
| 89 |
return LP_Object_Cache::get( 'course-' . $course_id, 'learn-press/course-item-types' ); |
| 90 |
} |
| 91 |
|
| 92 |
public static function set_course_items_group_types( $course_id, $items ) { |
| 93 |
LP_Object_Cache::set( 'course-' . $course_id, $items, 'learn-press/course-item-group-types' ); |
| 94 |
} |
| 95 |
|
| 96 |
public static function get_course_items_group_types( $course_id ) { |
| 97 |
return LP_Object_Cache::set( 'course-' . $course_id, 'learn-press/course-item-group-types' ); |
| 98 |
} |
| 99 |
|
| 100 |
public static function set_section_items( $section_id, $items ) { |
| 101 |
LP_Object_Cache::set( 'section-' . $section_id, $items, 'learn-press/section-items' ); |
| 102 |
} |
| 103 |
|
| 104 |
public static function get_section_items( $section_id ) { |
| 105 |
return LP_Object_Cache::set( 'section-' . $section_id, 'learn-press/section-items' ); |
| 106 |
} |
| 107 |
} |
| 108 |
|