PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.7
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / Models / LessonPostModel.php

LessonPostModel.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.7, at inc/Models/LessonPostModel.php

94 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Lesson Post Model
5 *
6 * @package LearnPress/Classes
7 * @version 1.0.0
8 * @since 4.2.7.6
9 */
10
11 namespace LearnPress\Models;
12
13 use Exception;
14 use LP_Cache;
15 use LP_Post_Type_Filter;
16
17 class LessonPostModel extends PostModel {
18 /**
19 * @var string Post Type
20 */
21 public $post_type = LP_LESSON_CPT;
22
23 /**
24 * Const meta key
25 */
26 const META_KEY_DURATION = '_lp_duration';
27 const META_KEY_PREVIEW = '_lp_preview';
28
29 /**
30 * Get post assignment by ID
31 *
32 * @param int $post_id
33 * @param bool $check_cache
34 *
35 * @return false|static
36 */
37 public static function find( int $post_id, bool $check_cache = false ) {
38 $filter_post = new LP_Post_Type_Filter();
39 $filter_post->ID = $post_id;
40 $filter_post->post_type = LP_LESSON_CPT;
41
42 $key_cache = "lessonPostModel/find/{$post_id}";
43 $lpLessonCache = new LP_Cache();
44
45 // Check cache
46 if ( $check_cache ) {
47 $lessonPostModel = $lpLessonCache->get_cache( $key_cache );
48 if ( $lessonPostModel instanceof self ) {
49 return $lessonPostModel;
50 }
51 }
52
53 $lessonPostModel = self::get_item_model_from_db( $filter_post );
54 // Set cache
55 if ( $lessonPostModel instanceof LessonPostModel ) {
56 $lpLessonCache->set_cache( $key_cache, $lessonPostModel );
57 }
58
59 return $lessonPostModel;
60 }
61
62 /**
63 * Get duration lesson
64 *
65 * @return string
66 */
67 public function get_duration(): string {
68 return $this->get_meta_value_by_key( self::META_KEY_DURATION, '0 minute' );
69 }
70
71 /**
72 * Check lesson enable preview
73 *
74 * @return bool
75 */
76 public function has_preview(): bool {
77 return $this->get_meta_value_by_key( self::META_KEY_PREVIEW, 'no' ) === 'yes';
78 }
79
80 /**
81 * Set lesson is preview or not
82 *
83 * @param bool $enable
84 *
85 * @return void
86 * @throws Exception
87 * @version 1.0.1
88 * @since 4.2.8.6
89 */
90 public function set_preview( bool $enable = true ) {
91 $this->save_meta_value_by_key( LessonPostModel::META_KEY_PREVIEW, $enable ? 'yes' : 'no' );
92 }
93 }
94