| @@ -1,76 +1,76 @@ | ||
| 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 | -} | |
| 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 | +} | |