PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 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 All 142 releases
← All changes | inc/curds/class-lp-quiz-curd.php +42 -90 4.1.7 → 4.4.10 View file →
@@ -25,9 +25,9 @@
25 25 * LP_Quiz_CURD constructor.
26 26 */
27 27 public function __construct() {
28 28 $this->_error_messages = array(
29 - 'QUIZ_NOT_EXISTS' => __( 'Quiz does not exist.', 'learnpress' ),
29 + 'QUIZ_NOT_EXISTS' => __( 'The quiz does not exist.', 'learnpress' ),
30 30 );
31 31 }
32 32
33 33 /**
@@ -44,31 +44,26 @@
44 44 }
45 45
46 46 // LP_Helper_CURD::update_meta_cache( $quiz->get_id() );
47 47
48 - $quiz->set_data_via_methods(
49 - array(
50 - // 'show_result' => get_post_meta( $quiz->get_id(), '_lp_show_result', true ),
51 - 'passing_grade_type' => get_post_meta( $quiz->get_id(), '_lp_passing_grade_type', true ),
52 - 'passing_grade' => get_post_meta( $quiz->get_id(), '_lp_passing_grade', true ),
53 - // 'show_check_answer' => get_post_meta( $quiz->get_id(), '_lp_show_check_answer', true ),
54 - // 'count_check_answer' => get_post_meta( $quiz->get_id(), '_lp_check_answer_count', true ),
55 - // 'show_hint' => get_post_meta( $quiz->get_id(), '_lp_show_hint', true ),
56 - // 'archive_history' => get_post_meta( $quiz->get_id(), '_lp_archive_history', true ),
57 - // 'count_hint' => get_post_meta( $quiz->get_id(), '_lp_hint_count', true ),
58 - 'pagination' => get_post_meta( $quiz->get_id(), '_lp_pagination', true ),
59 - 'review_questions' => get_post_meta( $quiz->get_id(), '_lp_review', true ),
60 - 'show_correct_review' => get_post_meta( $quiz->get_id(), '_lp_show_correct_review', true ),
61 - 'preview' => get_post_meta( $quiz->get_id(), '_lp_preview', true ),
62 - // 'minus_points' => get_post_meta( $quiz->get_id(), '_lp_minus_points', true ),
63 - 'minus_skip_questions' => get_post_meta( $quiz->get_id(), '_lp_minus_skip_questions', true ),
48 + // 'show_result' => get_post_meta( $quiz->get_id(), '_lp_show_result', true ),
49 + // 'show_check_answer' => get_post_meta( $quiz->get_id(), '_lp_show_check_answer', true ),
50 + // 'count_check_answer' => get_post_meta( $quiz->get_id(), '_lp_check_answer_count', true ),
51 + // 'show_hint' => get_post_meta( $quiz->get_id(), '_lp_show_hint', true ),
52 + // 'archive_history' => get_post_meta( $quiz->get_id(), '_lp_archive_history', true ),
53 + // 'count_hint' => get_post_meta( $quiz->get_id(), '_lp_hint_count', true ),
54 + // 'minus_points' => get_post_meta( $quiz->get_id(), '_lp_minus_points', true ),
55 + $quiz->set_passing_grade_type( get_post_meta( $quiz->get_id(), '_lp_passing_grade_type', true ) );
56 + $quiz->set_passing_grade( get_post_meta( $quiz->get_id(), '_lp_passing_grade', true ) );
57 + $quiz->set_pagination( get_post_meta( $quiz->get_id(), '_lp_pagination', true ) );
58 + $quiz->set_review_questions( get_post_meta( $quiz->get_id(), '_lp_review', true ) );
59 + $quiz->set_show_correct_review( get_post_meta( $quiz->get_id(), '_lp_show_correct_review', true ) );
60 + $quiz->set_preview( get_post_meta( $quiz->get_id(), '_lp_preview', true ) );
61 + $quiz->set_minus_skip_questions( get_post_meta( $quiz->get_id(), '_lp_minus_skip_questions', true ) );
62 + $quiz->set_instant_check( get_post_meta( $quiz->get_id(), '_lp_instant_check', true ) );
63 + $quiz->set_negative_marking( get_post_meta( $quiz->get_id(), '_lp_negative_marking', true ) );
64 + $quiz->set_retake_count( get_post_meta( $quiz->get_id(), '_lp_retake_count', true ) );
64 65
65 - 'instant_check' => get_post_meta( $quiz->get_id(), '_lp_instant_check', true ),
66 - 'negative_marking' => get_post_meta( $quiz->get_id(), '_lp_negative_marking', true ),
67 - 'retake_count' => get_post_meta( $quiz->get_id(), '_lp_retake_count', true ),
68 - )
69 - );
70 -
71 66 return $quiz;
72 67 }
73 68
74 69 /**
@@ -201,9 +196,9 @@
201 196 if ( ! $quiz_origin ) {
202 197 return;
203 198 }
204 199
205 - $questions_origin = $quiz_origin->get_questions();
200 + $questions_origin = $quiz_origin->get_question_ids();
206 201
207 202 foreach ( $questions_origin as $question_id_origin ) {
208 203 $can_clone = true;
209 204 $args = compact( 'question_id_origin', 'quiz_origin', 'quiz_id_new' );
@@ -230,9 +225,9 @@
230 225
231 226 /**
232 227 * @param LP_Quiz $quiz
233 228 *
234 - * @depecated 4.1.7
229 + * @deprecated 4.1.7
235 230 */
236 231 /*protected function _load_questions( &$quiz ) {
237 232 $id = $quiz->get_id();
238 233 $questions = LP_Object_Cache::get( 'questions-' . $id, 'learn-press/quizzes' );
@@ -266,34 +261,39 @@
266 261 * @param int $quiz_id
267 262 * @param string $context
268 263 *
269 264 * @return array
270 - * @throws Exception
271 265 */
272 - public function read_question_ids( int $quiz_id = 0, string $context = 'display' ) :array {
273 - $quiz = learn_press_get_quiz( $quiz_id );
266 + public function read_question_ids( int $quiz_id = 0, string $context = 'display' ): array {
267 + $lp_question_db = LP_Question_DB::getInstance();
268 + $question_ids = [];
274 269
275 - if ( ! $quiz ) {
276 - return array();
277 - }
270 + try {
271 + $quiz = learn_press_get_quiz( $quiz_id );
272 + if ( ! $quiz ) {
273 + return array();
274 + }
278 275
279 - $lp_question_db = LP_Question_DB::getInstance();
276 + if ( $context === 'display' ) {
277 + $statuses = array( 'publish' );
278 + } else {
279 + $statuses = array( 'publish', 'draft', 'auto-draft' );
280 + }
280 281
281 - if ( $context === 'display' ) {
282 - $statuses = array( 'publish' );
283 - } else {
284 - $statuses = array( 'publish', 'draft', 'auto-draft' );
282 + $filter = new LP_Question_Filter();
283 + $filter->ID = $quiz_id;
284 + $filter->post_status = $statuses;
285 +
286 + $question_ids = $lp_question_db->get_list_question_ids_of_quiz( $filter );
287 + } catch ( Throwable $e ) {
288 + error_log( $e->getMessage() );
285 289 }
286 290
287 - $filter = new LP_Question_Filter();
288 - $filter->quiz_id = $quiz_id;
289 - $filter->statues = $statuses;
290 -
291 - return $lp_question_db->get_list_question_ids_of_quiz( $filter );
291 + return $question_ids;
292 292 }
293 293
294 294 /**
295 - * @depecated 4.1.7
295 + * @deprecated 4.1.7
296 296 */
297 297 /*public function update_question_ids( $quiz_id ) {
298 298 wp_cache_delete( 'quiz-' . $quiz_id, 'quiz-questions' );
299 299
@@ -374,56 +374,8 @@
374 374
375 375 // LP_Helper_CURD::cache_posts( $question_ids );
376 376 $question_factory = new LP_Question_CURD();
377 377 $question_factory->load_answer_options( $question_ids );
378 - }
379 -
380 - /**
381 - * @param LP_Quiz $quiz
382 - * @depecated 4.1.6.4
383 - */
384 - protected function _update_meta_cache( &$quiz ) {
385 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
386 - $meta_ids = LP_Object_Cache::get( 'questions-' . $quiz->get_id(), 'learn-press/quizzes' );
387 -
388 - if ( false === $meta_ids ) {
389 - $meta_ids = array( $quiz->get_id() );
390 - } else {
391 - $meta_ids[] = $quiz->get_id();
392 - }
393 - // LP_Helper_CURD::update_meta_cache( $meta_ids );
394 - }
395 -
396 - /**
397 - * @depecated 4.1.6.4
398 - */
399 - protected function _load_question_answer_meta( $meta_ids ) {
400 - global $wpdb;
401 -
402 - $format = array_fill( 0, sizeof( $meta_ids ), '%d' );
403 - $query = $wpdb->prepare(
404 - "
405 - SELECT *
406 - FROM {$wpdb->learnpress_question_answermeta}
407 - WHERE learnpress_question_answer_id IN(" . join( ',', $format ) . ')
408 - ',
409 - $meta_ids
410 - );
411 -
412 - $metas = $wpdb->get_results( $query );
413 -
414 - if ( $metas ) {
415 - foreach ( $metas as $meta ) {
416 - $key = $meta->meta_key;
417 - $option_key = $meta->learnpress_question_answer_id;
418 - if ( ! empty( $answer_options[ $option_key ] ) ) {
419 - if ( $key == 'checked' ) {
420 - $key = 'is_true';
421 - }
422 - $answer_options[ $option_key ][ $key ] = $meta->meta_value;
423 - }
424 - }
425 - }
426 378 }
427 379
428 380 /**
429 381 * Sort questions by order.