PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
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 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/quiz/class-lp-quiz.php +103 -104 4.1.7.2 → 4.4.9 View file →
@@ -13,9 +13,9 @@
13 13
14 14 /**
15 15 * Class LP_Quiz
16 16 */
17 - class LP_Quiz extends LP_Course_Item implements ArrayAccess {
17 + class LP_Quiz extends LP_Course_Item {
18 18
19 19
20 20 /**
21 21 * @var array
@@ -264,9 +264,12 @@
264 264 * @return array|mixed
265 265 */
266 266 public function get_passing_grade() {
267 267 $type = $this->get_passing_grade_type();
268 - $value = $this->get_data( 'passing_grade', 0 );
268 + $value = get_post_meta( $this->get_id(), '_lp_passing_grade', true );
269 + if ( empty( $value ) ) {
270 + $value = 80;
271 + }
269 272
270 273 switch ( $type ) {
271 274 case 'point':
272 275 break;
@@ -398,17 +401,15 @@
398 401 *
399 402 * @return int
400 403 */
401 404 public function get_mark() {
402 - $mark = $this->get_data( 'mark' );
403 -
405 + $mark = $this->get_data( 'mark', false );
404 406 if ( false === $mark || '' === $mark ) {
405 - $questions = $this->get_questions();
407 + $questions = $this->get_question_ids();
406 408 $mark = 0;
407 409
408 410 foreach ( $questions as $question_id ) {
409 411 $question = LP_Question::get_question( $question_id );
410 -
411 412 if ( $question ) {
412 413 $mark += $question->get_mark();
413 414 }
414 415 }
@@ -436,15 +437,16 @@
436 437 * @param string $context
437 438 *
438 439 * @return mixed
439 440 * @editor tungnx
440 - * @throws Exception
441 441 * @since 3.x.x
442 442 * @version 1.0.1
443 + * @deprecated 4.2.0
443 444 */
444 445 public function get_questions( $context = 'display' ) {
446 + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '4.2.0' );
445 447 $questions = array();
446 - $ids = $this->_curd->read_question_ids( $this->get_id(), $context );
448 + $ids = $this->_curd->read_question_ids( $this->get_id() );
447 449
448 450 if ( $ids ) {
449 451 foreach ( $ids as $id ) {
450 452 $questions[ $id ] = $id;
@@ -450,9 +452,9 @@
450 452 $questions[ $id ] = $id;
451 453 }
452 454 }
453 455
454 - return apply_filters( 'learn-press/quiz/questions', $questions, $this->get_id(), $context );
456 + return apply_filters( 'learn-press/quiz/questions', $questions, $this->get_id(), $this->get_course_id(), $context );
455 457 }
456 458
457 459 /**
458 460 * Quiz editor get questions.
@@ -460,50 +462,48 @@
460 462 * @return mixed
461 463 */
462 464 public function quiz_editor_get_questions() {
463 465 // list questions
464 - $questions = $this->get_questions( 'edit' );
466 + $questions = $this->get_question_ids( 'edit' );
465 467 // order questions in quiz
466 468 $question_order = learn_press_quiz_get_questions_order( $questions );
467 469
468 470 $result = array();
469 - if ( is_array( $questions ) ) {
470 - foreach ( $questions as $index => $id ) {
471 471
472 - $question = LP_Question::get_question( $id );
472 + foreach ( $questions as $id ) {
473 + $question = LP_Question::get_question( $id );
473 474
474 - $answers = array();
475 - // handle question answer
476 - if ( is_array( $question->get_data( 'answer_options' ) ) ) {
477 - foreach ( $question->get_data( 'answer_options' ) as $answer ) {
478 - $answers[] = $answer;
479 - }
475 + $answers = array();
476 + // handle question answer
477 + if ( is_array( $question->get_data( 'answer_options' ) ) ) {
478 + foreach ( $question->get_data( 'answer_options' ) as $answer ) {
479 + $answers[] = $answer;
480 480 }
481 + }
481 482
482 - $post = get_post( $id );
483 - $result[] = apply_filters(
484 - 'learn-press/quiz-editor/question-data',
485 - array(
486 - 'id' => $id,
487 - 'open' => false,
488 - 'title' => $post->post_title,
489 - 'type' => array(
490 - 'key' => $question->get_type(),
491 - 'label' => $question->get_type_label(),
492 - ),
493 - 'answers' => apply_filters( 'learn-press/quiz-editor/question-answers-data', $answers, $id, $this->get_id() ),
494 - 'settings' => array(
495 - 'content' => $post->post_content,
496 - 'mark' => get_post_meta( $id, '_lp_mark', true ),
497 - 'explanation' => get_post_meta( $id, '_lp_explanation', true ),
498 - 'hint' => get_post_meta( $id, '_lp_hint', true ),
499 - ),
500 - 'order' => $question_order[ $index ],
483 + $post = get_post( $id );
484 + $result[] = apply_filters(
485 + 'learn-press/quiz-editor/question-data',
486 + array(
487 + 'id' => $id,
488 + 'open' => false,
489 + 'title' => $post->post_title,
490 + 'type' => array(
491 + 'key' => $question->get_type(),
492 + 'label' => $question->get_type_label(),
501 493 ),
502 - $id,
503 - $this->get_id()
504 - );
505 - }
494 + 'answers' => apply_filters( 'learn-press/quiz-editor/question-answers-data', $answers, $id, $this->get_id() ),
495 + 'settings' => array(
496 + 'content' => $post->post_content,
497 + 'mark' => get_post_meta( $id, '_lp_mark', true ),
498 + 'explanation' => get_post_meta( $id, '_lp_explanation', true ),
499 + 'hint' => get_post_meta( $id, '_lp_hint', true ),
500 + ),
501 + 'order' => $question_order[ $id ],
502 + ),
503 + $id,
504 + $this->get_id()
505 + );
506 506 }
507 507
508 508 return apply_filters( 'learn-press/quiz/quiz_editor_questions', $result, $this->get_id() );
509 509 }
@@ -528,17 +528,17 @@
528 528 * Get number questions in quiz.
529 529 *
530 530 * @return int
531 531 */
532 - public function count_questions() {
532 + public function count_questions(): int {
533 533 $size = 0;
534 - $questions = $this->get_questions();
534 + $questions = $this->get_question_ids();
535 535
536 536 if ( $questions ) {
537 537 $size = sizeof( $questions );
538 538 }
539 539
540 - return apply_filters( 'learn-press/quiz/count-questions', $size, $this->get_id() );
540 + return (int) apply_filters( 'learn-press/quiz/count-questions', $size, $this->get_id() );
541 541 }
542 542
543 543 /**
544 544 * Get all question's ids of the quiz.
@@ -546,20 +546,31 @@
546 546 * @param string $context
547 547 *
548 548 * @return int[]
549 549 * @editor tungnx
550 - * @throws Exception
551 550 * @version 1.0.1
552 551 * @since 3.2.0
553 - *
554 552 */
555 553 public function get_question_ids( string $context = 'display' ): array {
556 - $ids = $this->_curd->read_question_ids( $this->get_id(), $context );
554 + $question_ids = $this->_curd->read_question_ids( $this->get_id(), $context );
555 + $question_ids = apply_filters( 'learn-press/quiz/get-question-ids', $question_ids, $this->get_id(), $this->get_course_id(), $context );
556 + if ( ! is_array( $question_ids ) ) {
557 + $question_ids = array();
558 + }
557 559
558 - return apply_filters( 'learn-press/quiz/get-question-ids', $ids, $this->get_id(), $this->get_course_id(), $context );
560 + return $question_ids;
559 561 }
560 562
561 563 /**
564 + * Get number questions for user do it.
565 + *
566 + * @return mixed|null
567 + */
568 + public function get_number_questions_to_do() {
569 + return apply_filters( 'learn-press/quiz/number-questions-show', $this->count_questions(), $this );
570 + }
571 +
572 + /**
562 573 * This quiz has any question?
563 574 *
564 575 * @return bool
565 576 */
@@ -583,9 +594,9 @@
583 594 'message' => __( 'Are you sure you want to retake this quiz?', 'learnpress' ),
584 595 ),
585 596 'quiz_time_is_over' => array(
586 597 'title' => __( 'Time\'s up!', 'learnpress' ),
587 - 'message' => __( 'The time is up! Your quiz will automate come to finish', 'learnpress' ),
598 + 'message' => __( 'The time is up! Your quiz will automatically come to an end', 'learnpress' ),
588 599 ),
589 600 'finished_quiz' => __( 'Congrats! You have finished this quiz', 'learnpress' ),
590 601 'retaken_quiz' => __( 'Congrats! You have re-taken this quiz. Please wait a moment and the page will reload', 'learnpress' ),
591 602 );
@@ -609,14 +620,16 @@
609 620 *
610 621 * @param string $key
611 622 *
612 623 * @return mixed
624 + * @deprecated 4.0.8
613 625 */
614 626 public function __get( $key ) {
615 - echo '@deprecated[' . $key . ']';
627 + _deprecated_function( __METHOD__, '4.0.8' );
628 + /*echo '@deprecated[' . $key . ']';
616 629 learn_press_debug( debug_backtrace() );
617 630
618 - return false;
631 + return false;*/
619 632 }
620 633
621 634 /**
622 635 * @param $feature
@@ -622,8 +635,9 @@
622 635 * @param $feature
623 636 *
624 637 * @return mixed
625 638 * @throws Exception
639 + * @deprecated 3.0.8
626 640 */
627 641 public function has( $feature ) {
628 642 _deprecated_function( __FUNCTION__, '3.0.8' );
629 643
@@ -645,11 +659,11 @@
645 659 *
646 660 * @return bool
647 661 */
648 662 public function has_question( $question_id ) {
649 - $questions = $this->get_questions();
663 + $questions = $this->get_question_ids();
650 664
651 - return apply_filters( 'learn-press/quiz/has-question', is_array( $questions ) && ( false !== array_search( $question_id, $questions ) ), $question_id, $this->get_id() );
665 + return apply_filters( 'learn-press/quiz/has-question', in_array( $question_id, $questions ), $question_id, $this->get_id() );
652 666 }
653 667
654 668 /**
655 669 * Get question permalink from it's ID.
@@ -659,11 +673,13 @@
659 673 *
660 674 * @param int $question_id
661 675 *
662 676 * @return string
677 + * @deprecated 4.2.0
663 678 */
664 679 public function get_question_link( $question_id = null ) {
665 - $course = learn_press_get_course();
680 + _deprecated_function( __METHOD__, '4.2.0' );
681 + /*$course = learn_press_get_course();
666 682 if ( ! $course ) {
667 683 return '';
668 684 }
669 685
@@ -684,9 +700,9 @@
684 700
685 701 // @deprecated
686 702 $permalink = apply_filters( 'learn_press_quiz_question_permalink', $permalink, $question_id, $this );
687 703
688 - return apply_filters( 'learn-press/quiz/question-permalink', $permalink, $question_id, $this->get_id() );
704 + return apply_filters( 'learn-press/quiz/question-permalink', $permalink, $question_id, $this->get_id() );*/
689 705 }
690 706
691 707 /**
692 708 * @param int $at
@@ -691,9 +707,9 @@
691 707 /**
692 708 * @param int $at
693 709 *
694 710 * @return bool
695 - * @depecated 4.1.6.9
711 + * @deprecated 4.1.6.9
696 712 */
697 713 /*public function get_question_at( $at = 0 ) {
698 714 $questions = $this->get_questions();
699 715
@@ -711,9 +727,9 @@
711 727 *
712 728 * @param int $id
713 729 *
714 730 * @return bool
715 - * @depecated 4.1.6.9
731 + * @deprecated 4.1.6.9
716 732 */
717 733 /*public function get_prev_question( $id ) {
718 734 $prev = false;
719 735 $questions = $this->get_questions();
@@ -735,9 +751,9 @@
735 751 *
736 752 * @param int $id
737 753 *
738 754 * @return bool
739 - * @depecated 4.1.6.9
755 + * @deprecated 4.1.6.9
740 756 */
741 757 /*public function get_next_question( $id ) {
742 758 $next = false;
743 759 $questions = $this->get_questions();
@@ -760,9 +776,9 @@
760 776 * @param int $id
761 777 * @param int $start
762 778 *
763 779 * @return bool|mixed
764 - * @depecated 4.1.6.9
780 + * @deprecated 4.1.6.9
765 781 */
766 782 /*public function get_question_index( $id, $start = 0 ) {
767 783 $index = 0;
768 784 $questions = $this->get_questions();
@@ -781,11 +797,13 @@
781 797 * @param $question_id
782 798 * @param $user_id
783 799 *
784 800 * @return bool
801 + * @deprecated 4.2.0
785 802 */
786 803 public function check_question( $question_id, $user_id ) {
787 - $question = LP_Question::get_question( $question_id );
804 + _deprecated_function( __METHOD__, '4.2.0' );
805 + /*$question = LP_Question::get_question( $question_id );
788 806
789 807 if ( ! $question ) {
790 808 return false;
791 809 }
@@ -804,9 +822,9 @@
804 822 if ( ! in_array( $question_id, $checked ) ) {
805 823 $checked[] = $question_id;
806 824 }
807 825
808 - return true;
826 + return true;*/
809 827
810 828 }
811 829
812 830 /**
@@ -815,11 +833,13 @@
815 833 * @param $question
816 834 * @param int $user_id
817 835 *
818 836 * @return false|int|string
837 + * @deprecated 4.2.0
819 838 */
820 839 public function get_question_position( $question, $user_id = 0 ) {
821 - if ( ! $user_id ) {
840 + _deprecated_function( __METHOD__, '4.2.0' );
841 + /*if ( ! $user_id ) {
822 842 $user_id = learn_press_get_current_user_id();
823 843 }
824 844
825 845 $user = learn_press_get_user( $user_id );
@@ -828,15 +848,14 @@
828 848 if ( $user && $results ) {
829 849 $questions = (array) $results->questions;
830 850
831 851 } else {
832 - $questions = (array) $this->get_questions();
833 - $questions = array_keys( $questions );
852 + $questions = $this->get_question_ids();
834 853 }
835 854
836 855 $position = array_search( $question, $questions );
837 856
838 - return $position;
857 + return $position;*/
839 858 }
840 859
841 860 /**
842 861 * @param int $user_id
@@ -842,16 +861,17 @@
842 861 * @param int $user_id
843 862 * @param int $course_id
844 863 *
845 864 * @return bool|LP_Question
865 + * @deprecated 4.0.0
846 866 */
847 867 public function get_current_question( $user_id = 0, $course_id = 0 ) {
848 868 _deprecated_function( sprintf( '%s::%s', __CLASS__, __FUNCTION__ ), '4.0.0' );
849 869
850 - $user = learn_press_get_user( $user_id );
870 + /*$user = learn_press_get_user( $user_id );
851 871 $id = $user->get_current_quiz_question( $this->get_id(), $course_id );
852 872
853 - return LP_Question::get_question( $id );
873 + return LP_Question::get_question( $id );*/
854 874 }
855 875
856 876 /**
857 877 * @param string $return
@@ -870,9 +890,8 @@
870 890 *
871 891 * @return LP_Quiz|bool
872 892 */
873 893 public static function get_quiz( $the_quiz = false, $args = array() ) {
874 -
875 894 if ( is_numeric( $the_quiz ) && isset( LP_Global::$quizzes[ $the_quiz ] ) ) {
876 895 return LP_Global::$quizzes[ $the_quiz ];
877 896 }
878 897
@@ -975,18 +994,18 @@
975 994 public function set_show_hide_question( $show_or_hide ) {
976 995 $this->_set_data( 'show_hide_question', $show_or_hide );
977 996 }
978 997
998 + /**
999 + * Set quiz is preview or not.
1000 + * using
1001 + */
979 1002 public function set_preview( $preview ) {
980 1003 $this->_set_data( 'preview', $preview );
981 1004 }
982 1005
983 - // public function set_minus_points( $points ) {
984 - // $this->_set_data( 'minus_points', $points );
985 - // }
986 -
987 1006 /**
988 - * @deprecated
1007 + * Set option skip question will be minus points
989 1008 *
990 1009 * @param $skip
991 1010 */
992 1011 public function set_minus_skip_questions( $skip ) {
@@ -992,23 +1011,16 @@
992 1011 public function set_minus_skip_questions( $skip ) {
993 1012 $this->_set_data( 'minus_skip_questions', $skip );
994 1013 }
995 1014
1015 + /**
1016 + * Get quiz is preview or not.
1017 + * using
1018 + */
996 1019 public function get_preview() {
997 1020 return 'yes' === $this->get_data( 'preview' );
998 1021 }
999 1022
1000 - /**
1001 - * @deprecated
1002 - *
1003 - * @return bool
1004 - */
1005 - public function get_show_hide_question() {
1006 - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '4.0.0' );
1007 -
1008 - return 'yes' === $this->get_data( 'show_hide_question' );
1009 - }
1010 -
1011 1023 // public function get_minus_points() {
1012 1024 // return $this->get_data( 'minus_points' );
1013 1025 // }
1014 1026
@@ -1027,9 +1039,9 @@
1027 1039 * @param int $question_id
1028 1040 * @param null $position
1029 1041 *
1030 1042 * @return array
1031 - * @depecated 4.1.6.9
1043 + * @deprecated 4.1.6.9
1032 1044 */
1033 1045 /*public function get_question_number_class( $question_id, $position = null ) {
1034 1046 if ( null === $position ) {
1035 1047 $position = $this->get_question_index( $question_id );
@@ -1053,30 +1065,15 @@
1053 1065 return $class;
1054 1066 }*/
1055 1067
1056 1068 /**
1057 - * Implement ArrayAccess functions.
1058 - *
1059 1069 * @param mixed $offset
1060 - * @param mixed $value
1061 - */
1062 - public function offsetSet( $offset, $value ) {
1063 - // Do not allow to set value directly!
1064 - }
1065 -
1066 - /**
1067 - * @param mixed $offset
1068 - */
1069 - public function offsetUnset( $offset ) {
1070 - // Do not allow to unset value directly!
1071 - }
1072 -
1073 - /**
1074 - * @param mixed $offset
1075 1070 *
1076 1071 * @return bool|mixed
1072 + * @deprecated 4.2.0
1077 1073 */
1078 1074 public function offsetGet( $offset ) {
1075 + _deprecated_function( __CLASS__ . '::' . __METHOD__, '4.2.0' );
1079 1076 return $this->offsetExists( $offset ) ? $this->_questions[ $offset ] : false;
1080 1077 }
1081 1078
1082 1079 /**
@@ -1082,10 +1079,12 @@
1082 1079 /**
1083 1080 * @param mixed $offset
1084 1081 *
1085 1082 * @return bool
1083 + * @deprecated 4.2.0
1086 1084 */
1087 1085 public function offsetExists( $offset ) {
1088 - return array_key_exists( $offset, $this->_questions );
1086 + _deprecated_function( __CLASS__ . '::' . __METHOD__, '4.2.0' );
1087 + /*return array_key_exists( $offset, $this->_questions );*/
1089 1088 }
1090 1089 }
1091 1090 }