| @@ -1,122 +1,122 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class LP_Lesson_DB | |
| 4 | - * | |
| 5 | - * @author tungnx | |
| 6 | - * @since 3.2.7.8 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; // Exit if accessed directly | |
| 11 | -} | |
| 12 | - | |
| 13 | -class LP_Lesson_DB extends LP_Database { | |
| 14 | - private static $_instance; | |
| 15 | - | |
| 16 | - protected function __construct() { | |
| 17 | - parent::__construct(); | |
| 18 | - } | |
| 19 | - | |
| 20 | - public static function getInstance() { | |
| 21 | - if ( is_null( self::$_instance ) ) { | |
| 22 | - self::$_instance = new self(); | |
| 23 | - } | |
| 24 | - | |
| 25 | - return self::$_instance; | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Get section id by lesson id | |
| 30 | - * | |
| 31 | - * @param int $lesson_id | |
| 32 | - * | |
| 33 | - * @return string|null | |
| 34 | - */ | |
| 35 | - public function get_section_by_lesson_id( $lesson_id = 0 ) { | |
| 36 | - $query = $this->wpdb->prepare( | |
| 37 | - " | |
| 38 | - SELECT section_id FROM $this->tb_lp_section_items | |
| 39 | - WHERE item_type = %s | |
| 40 | - AND item_id = %d", | |
| 41 | - LP_LESSON_CPT, | |
| 42 | - $lesson_id | |
| 43 | - ); | |
| 44 | - | |
| 45 | - $result = $this->wpdb->get_var( $query ); | |
| 46 | - | |
| 47 | - return $result; | |
| 48 | - } | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Get total lessons set preview | |
| 52 | - * | |
| 53 | - * @return string|null | |
| 54 | - */ | |
| 55 | - public function get_total_preview_items() { | |
| 56 | - $query = $this->wpdb->prepare( | |
| 57 | - " | |
| 58 | - SELECT COUNT(ID) FROM $this->tb_posts p | |
| 59 | - INNER JOIN {$this->tb_postmeta} pm | |
| 60 | - ON p.ID = pm.post_id | |
| 61 | - AND pm.meta_key = %s | |
| 62 | - WHERE pm.meta_value = %s | |
| 63 | - AND p.post_type = %s", | |
| 64 | - '_lp_preview', | |
| 65 | - 'yes', | |
| 66 | - LP_LESSON_CPT | |
| 67 | - ); | |
| 68 | - | |
| 69 | - return $this->wpdb->get_var( $query ); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Get total lessons no set preview | |
| 74 | - * | |
| 75 | - * @param int $total_preview_items | |
| 76 | - * | |
| 77 | - * @return string|null | |
| 78 | - */ | |
| 79 | - public function get_total_no_preview_items( $total_preview_items = 0 ) { | |
| 80 | - global $wpdb; | |
| 81 | - $query = $wpdb->prepare( | |
| 82 | - " | |
| 83 | - SELECT COUNT(ID) | |
| 84 | - FROM {$wpdb->posts} p | |
| 85 | - WHERE p.post_type = %s | |
| 86 | - AND p.post_status NOT LIKE 'auto-draft' | |
| 87 | - AND p.post_status NOT LIKE 'trash' | |
| 88 | - ", | |
| 89 | - LP_LESSON_CPT | |
| 90 | - ); | |
| 91 | - | |
| 92 | - return $wpdb->get_var( $query ) - $total_preview_items; | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Get preview lesson in Courses database. | |
| 97 | - * | |
| 98 | - * @param int $course_id | |
| 99 | - * @return void | |
| 100 | - * | |
| 101 | - * @todo Set cache or save when save_course. | |
| 102 | - */ | |
| 103 | - public function get_count_preview_in_course( $course_id ) { | |
| 104 | - $query = $this->wpdb->prepare( | |
| 105 | - "SELECT COUNT(ID) FROM $this->tb_posts AS p | |
| 106 | - INNER JOIN {$this->tb_postmeta} AS pm ON p.ID = pm.post_id AND pm.meta_key = %s | |
| 107 | - INNER JOIN {$this->tb_lp_section_items} AS section_items ON section_items.item_id = p.ID | |
| 108 | - INNER JOIN {$this->tb_lp_sections} AS sections ON sections.section_course_id = %d AND sections.section_id = section_items.section_id | |
| 109 | - WHERE pm.meta_value = %s | |
| 110 | - AND p.post_type = %s", | |
| 111 | - '_lp_preview', | |
| 112 | - $course_id, | |
| 113 | - 'yes', | |
| 114 | - LP_LESSON_CPT | |
| 115 | - ); | |
| 116 | - | |
| 117 | - return $this->wpdb->get_var( $query ); | |
| 118 | - } | |
| 119 | -} | |
| 120 | - | |
| 121 | -LP_Lesson_DB::getInstance(); | |
| 122 | - | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class LP_Lesson_DB | |
| 4 | + * | |
| 5 | + * @author tungnx | |
| 6 | + * @since 3.2.7.8 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; // Exit if accessed directly | |
| 11 | +} | |
| 12 | + | |
| 13 | +class LP_Lesson_DB extends LP_Database { | |
| 14 | + private static $_instance; | |
| 15 | + | |
| 16 | + protected function __construct() { | |
| 17 | + parent::__construct(); | |
| 18 | + } | |
| 19 | + | |
| 20 | + public static function getInstance() { | |
| 21 | + if ( is_null( self::$_instance ) ) { | |
| 22 | + self::$_instance = new self(); | |
| 23 | + } | |
| 24 | + | |
| 25 | + return self::$_instance; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get section id by lesson id | |
| 30 | + * | |
| 31 | + * @param int $lesson_id | |
| 32 | + * | |
| 33 | + * @return string|null | |
| 34 | + */ | |
| 35 | + public function get_section_by_lesson_id( $lesson_id = 0 ) { | |
| 36 | + $query = $this->wpdb->prepare( | |
| 37 | + " | |
| 38 | + SELECT section_id FROM $this->tb_lp_section_items | |
| 39 | + WHERE item_type = %s | |
| 40 | + AND item_id = %d", | |
| 41 | + LP_LESSON_CPT, | |
| 42 | + $lesson_id | |
| 43 | + ); | |
| 44 | + | |
| 45 | + $result = $this->wpdb->get_var( $query ); | |
| 46 | + | |
| 47 | + return $result; | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Get total lessons set preview | |
| 52 | + * | |
| 53 | + * @return string|null | |
| 54 | + */ | |
| 55 | + public function get_total_preview_items() { | |
| 56 | + $query = $this->wpdb->prepare( | |
| 57 | + " | |
| 58 | + SELECT COUNT(ID) FROM $this->tb_posts p | |
| 59 | + INNER JOIN {$this->tb_postmeta} pm | |
| 60 | + ON p.ID = pm.post_id | |
| 61 | + AND pm.meta_key = %s | |
| 62 | + WHERE pm.meta_value = %s | |
| 63 | + AND p.post_type = %s", | |
| 64 | + '_lp_preview', | |
| 65 | + 'yes', | |
| 66 | + LP_LESSON_CPT | |
| 67 | + ); | |
| 68 | + | |
| 69 | + return $this->wpdb->get_var( $query ); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Get total lessons no set preview | |
| 74 | + * | |
| 75 | + * @param int $total_preview_items | |
| 76 | + * | |
| 77 | + * @return string|null | |
| 78 | + */ | |
| 79 | + public function get_total_no_preview_items( $total_preview_items = 0 ) { | |
| 80 | + global $wpdb; | |
| 81 | + $query = $wpdb->prepare( | |
| 82 | + " | |
| 83 | + SELECT COUNT(ID) | |
| 84 | + FROM {$wpdb->posts} p | |
| 85 | + WHERE p.post_type = %s | |
| 86 | + AND p.post_status NOT LIKE 'auto-draft' | |
| 87 | + AND p.post_status NOT LIKE 'trash' | |
| 88 | + ", | |
| 89 | + LP_LESSON_CPT | |
| 90 | + ); | |
| 91 | + | |
| 92 | + return $wpdb->get_var( $query ) - $total_preview_items; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Get preview lesson in Courses database. | |
| 97 | + * | |
| 98 | + * @param int $course_id | |
| 99 | + * @return void | |
| 100 | + * | |
| 101 | + * @todo Set cache or save when save_course. | |
| 102 | + */ | |
| 103 | + public function get_count_preview_in_course( $course_id ) { | |
| 104 | + $query = $this->wpdb->prepare( | |
| 105 | + "SELECT COUNT(ID) FROM $this->tb_posts AS p | |
| 106 | + INNER JOIN {$this->tb_postmeta} AS pm ON p.ID = pm.post_id AND pm.meta_key = %s | |
| 107 | + INNER JOIN {$this->tb_lp_section_items} AS section_items ON section_items.item_id = p.ID | |
| 108 | + INNER JOIN {$this->tb_lp_sections} AS sections ON sections.section_course_id = %d AND sections.section_id = section_items.section_id | |
| 109 | + WHERE pm.meta_value = %s | |
| 110 | + AND p.post_type = %s", | |
| 111 | + '_lp_preview', | |
| 112 | + $course_id, | |
| 113 | + 'yes', | |
| 114 | + LP_LESSON_CPT | |
| 115 | + ); | |
| 116 | + | |
| 117 | + return $this->wpdb->get_var( $query ); | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +LP_Lesson_DB::getInstance(); | |
| 122 | + | |