PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9.1
4.4.8 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 All 139 releases
learnpress / inc / Databases / class-lp-question-answers-db.php

class-lp-question-answers-db.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9.1, at inc/Databases/class-lp-question-answers-db.php

77 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Class LP_Quiz_Questions_DB
9 *
10 * @since 4.1.7
11 * @version 1.0.1
12 */
13 class LP_Question_Answers_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 question answers
30 *
31 * @throws Exception
32 */
33 public function get_question_answers( LP_Question_Answers_Filter $filter, &$total_rows = 0 ) {
34 $default_fields = $this->get_cols_of_table( $this->tb_lp_question_answers );
35 $filter->fields = array_merge( $default_fields, $filter->fields );
36 $filter->exclude_fields[] = 'order';
37 $filter->fields[] = '`order`';
38
39 if ( empty( $filter->collection ) ) {
40 $filter->collection = $this->tb_lp_question_answers;
41 }
42
43 if ( empty( $filter->collection_alias ) ) {
44 $filter->collection_alias = 'qa';
45 }
46
47 // By question answer id
48 if ( ! empty( $filter->question_answer_id ) ) {
49 $filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_answer_id = %d", $filter->question_answer_id );
50 }
51
52 // By question id
53 if ( ! empty( $filter->question_id ) ) {
54 $filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_id = %d", $filter->question_id );
55 }
56
57 // By title
58 if ( ! empty( $filter->title ) ) {
59 $filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.title LIKE %s", '%' . $this->wpdb->esc_like( $filter->title ) . '%' );
60 }
61
62 // Question ids
63 if ( ! empty( $filter->question_ids ) ) {
64 $question_ids_format = LP_Helper::db_format_array( $filter->question_ids, '%d' );
65 $filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_id IN (" . $question_ids_format . ')', $filter->question_ids );
66 }
67
68 // question_answer_ids
69 if ( ! empty( $filter->question_answer_ids ) ) {
70 $question_answer_ids_format = LP_Helper::db_format_array( $filter->question_answer_ids, '%d' );
71 $filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_answer_id IN (" . $question_answer_ids_format . ')', $filter->question_answer_ids );
72 }
73
74 return $this->execute( $filter, $total_rows );
75 }
76 }
77