| 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.0 |
| 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_asnwers( 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 |
// Question ids |
| 48 |
if ( ! empty( $filter->question_ids ) ) { |
| 49 |
$question_ids_format = LP_Helper::db_format_array( $filter->question_ids, '%d' ); |
| 50 |
$filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_id IN (" . $question_ids_format . ')', $filter->question_ids ); |
| 51 |
} |
| 52 |
|
| 53 |
// question_answer_ids |
| 54 |
if ( ! empty( $filter->question_answer_ids ) ) { |
| 55 |
$question_answer_ids_format = LP_Helper::db_format_array( $filter->question_answer_ids, '%d' ); |
| 56 |
$filter->where[] = $this->wpdb->prepare( "AND {$filter->collection_alias}.question_answer_id IN (" . $question_answer_ids_format . ')', $filter->question_answer_ids ); |
| 57 |
} |
| 58 |
|
| 59 |
return $this->execute( $filter, $total_rows ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|