| @@ -1,68 +1,68 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | - exit; // Exit if accessed directly | |
| 5 | -} | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Class LP_Lesson_DB | |
| 9 | - * | |
| 10 | - * @since 3.2.7.4 | |
| 11 | - * @author tungnx | |
| 12 | - * @version 1.0.0 | |
| 13 | - */ | |
| 14 | -class LP_Quiz_DB extends LP_Database { | |
| 15 | - private static $_instance; | |
| 16 | - | |
| 17 | - protected function __construct() { | |
| 18 | - parent::__construct(); | |
| 19 | - } | |
| 20 | - | |
| 21 | - public static function getInstance() { | |
| 22 | - if ( is_null( self::$_instance ) ) { | |
| 23 | - self::$_instance = new self(); | |
| 24 | - } | |
| 25 | - | |
| 26 | - return self::$_instance; | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * Get quiz_id of question | |
| 31 | - * | |
| 32 | - * @param int $question_id | |
| 33 | - * | |
| 34 | - * @return int | |
| 35 | - */ | |
| 36 | - public function get_quiz_id_by_question( int $question_id = 0 ) : int { | |
| 37 | - $query = $this->wpdb->prepare( | |
| 38 | - " | |
| 39 | - SELECT quiz_id | |
| 40 | - FROM $this->tb_lp_quiz_questions | |
| 41 | - WHERE question_id = %d", | |
| 42 | - $question_id | |
| 43 | - ); | |
| 44 | - | |
| 45 | - return (int) $this->wpdb->get_var( $query ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Get total questions assign for Quiz | |
| 50 | - * | |
| 51 | - * @param int $quiz_id | |
| 52 | - * @author tungnx | |
| 53 | - * @since 4.1.4.1 | |
| 54 | - * @version 1.0.0 | |
| 55 | - * @return int | |
| 56 | - */ | |
| 57 | - public function get_total_question( int $quiz_id = 0 ) : int { | |
| 58 | - $query = $this->wpdb->prepare( | |
| 59 | - "SELECT COUNT(question_id) AS total | |
| 60 | - FROM $this->tb_lp_quiz_questions | |
| 61 | - WHERE quiz_id = %d", | |
| 62 | - $quiz_id | |
| 63 | - ); | |
| 64 | - | |
| 65 | - return (int) $this->wpdb->get_var( $query ); | |
| 66 | - } | |
| 67 | -} | |
| 68 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit; // Exit if accessed directly | |
| 5 | +} | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Class LP_Lesson_DB | |
| 9 | + * | |
| 10 | + * @since 3.2.7.4 | |
| 11 | + * @author tungnx | |
| 12 | + * @version 1.0.0 | |
| 13 | + */ | |
| 14 | +class LP_Quiz_DB extends LP_Database { | |
| 15 | + private static $_instance; | |
| 16 | + | |
| 17 | + protected function __construct() { | |
| 18 | + parent::__construct(); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public static function getInstance() { | |
| 22 | + if ( is_null( self::$_instance ) ) { | |
| 23 | + self::$_instance = new self(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + return self::$_instance; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Get quiz_id of question | |
| 31 | + * | |
| 32 | + * @param int $question_id | |
| 33 | + * | |
| 34 | + * @return int | |
| 35 | + */ | |
| 36 | + public function get_quiz_id_by_question( int $question_id = 0 ) : int { | |
| 37 | + $query = $this->wpdb->prepare( | |
| 38 | + " | |
| 39 | + SELECT quiz_id | |
| 40 | + FROM $this->tb_lp_quiz_questions | |
| 41 | + WHERE question_id = %d", | |
| 42 | + $question_id | |
| 43 | + ); | |
| 44 | + | |
| 45 | + return (int) $this->wpdb->get_var( $query ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Get total questions assign for Quiz | |
| 50 | + * | |
| 51 | + * @param int $quiz_id | |
| 52 | + * @author tungnx | |
| 53 | + * @since 4.1.4.1 | |
| 54 | + * @version 1.0.0 | |
| 55 | + * @return int | |
| 56 | + */ | |
| 57 | + public function get_total_question( int $quiz_id = 0 ) : int { | |
| 58 | + $query = $this->wpdb->prepare( | |
| 59 | + "SELECT COUNT(question_id) AS total | |
| 60 | + FROM $this->tb_lp_quiz_questions | |
| 61 | + WHERE quiz_id = %d", | |
| 62 | + $quiz_id | |
| 63 | + ); | |
| 64 | + | |
| 65 | + return (int) $this->wpdb->get_var( $query ); | |
| 66 | + } | |
| 67 | +} | |
| 68 | + | |