| @@ -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; |
| @@ -526,9 +528,9 @@ | ||
| 526 | 528 | * Get number questions in quiz. |
| 527 | 529 | * |
| 528 | 530 | * @return int |
| 529 | 531 | */ |
| 530 | - public function count_questions() { | |
| 532 | + public function count_questions(): int { | |
| 531 | 533 | $size = 0; |
| 532 | 534 | $questions = $this->get_question_ids(); |
| 533 | 535 | |
| 534 | 536 | if ( $questions ) { |
| @@ -534,9 +536,9 @@ | ||
| 534 | 536 | if ( $questions ) { |
| 535 | 537 | $size = sizeof( $questions ); |
| 536 | 538 | } |
| 537 | 539 | |
| 538 | - 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() ); | |
| 539 | 541 | } |
| 540 | 542 | |
| 541 | 543 | /** |
| 542 | 544 | * Get all question's ids of the quiz. |
| @@ -548,14 +550,27 @@ | ||
| 548 | 550 | * @version 1.0.1 |
| 549 | 551 | * @since 3.2.0 |
| 550 | 552 | */ |
| 551 | 553 | public function get_question_ids( string $context = 'display' ): array { |
| 552 | - $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 | + } | |
| 553 | 559 | |
| 554 | - return apply_filters( 'learn-press/quiz/get-question-ids', $ids, $this->get_id(), $this->get_course_id(), $context ); | |
| 560 | + return $question_ids; | |
| 555 | 561 | } |
| 556 | 562 | |
| 557 | 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 | + /** | |
| 558 | 573 | * This quiz has any question? |
| 559 | 574 | * |
| 560 | 575 | * @return bool |
| 561 | 576 | */ |
| @@ -605,14 +620,16 @@ | ||
| 605 | 620 | * |
| 606 | 621 | * @param string $key |
| 607 | 622 | * |
| 608 | 623 | * @return mixed |
| 624 | + * @deprecated 4.0.8 | |
| 609 | 625 | */ |
| 610 | 626 | public function __get( $key ) { |
| 611 | - echo '@deprecated[' . $key . ']'; | |
| 627 | + _deprecated_function( __METHOD__, '4.0.8' ); | |
| 628 | + /*echo '@deprecated[' . $key . ']'; | |
| 612 | 629 | learn_press_debug( debug_backtrace() ); |
| 613 | 630 | |
| 614 | - return false; | |
| 631 | + return false;*/ | |
| 615 | 632 | } |
| 616 | 633 | |
| 617 | 634 | /** |
| 618 | 635 | * @param $feature |
| @@ -618,8 +635,9 @@ | ||
| 618 | 635 | * @param $feature |
| 619 | 636 | * |
| 620 | 637 | * @return mixed |
| 621 | 638 | * @throws Exception |
| 639 | + * @deprecated 3.0.8 | |
| 622 | 640 | */ |
| 623 | 641 | public function has( $feature ) { |
| 624 | 642 | _deprecated_function( __FUNCTION__, '3.0.8' ); |
| 625 | 643 | |
| @@ -655,11 +673,13 @@ | ||
| 655 | 673 | * |
| 656 | 674 | * @param int $question_id |
| 657 | 675 | * |
| 658 | 676 | * @return string |
| 677 | + * @deprecated 4.2.0 | |
| 659 | 678 | */ |
| 660 | 679 | public function get_question_link( $question_id = null ) { |
| 661 | - $course = learn_press_get_course(); | |
| 680 | + _deprecated_function( __METHOD__, '4.2.0' ); | |
| 681 | + /*$course = learn_press_get_course(); | |
| 662 | 682 | if ( ! $course ) { |
| 663 | 683 | return ''; |
| 664 | 684 | } |
| 665 | 685 | |
| @@ -680,9 +700,9 @@ | ||
| 680 | 700 | |
| 681 | 701 | // @deprecated |
| 682 | 702 | $permalink = apply_filters( 'learn_press_quiz_question_permalink', $permalink, $question_id, $this ); |
| 683 | 703 | |
| 684 | - 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() );*/ | |
| 685 | 705 | } |
| 686 | 706 | |
| 687 | 707 | /** |
| 688 | 708 | * @param int $at |
| @@ -777,11 +797,13 @@ | ||
| 777 | 797 | * @param $question_id |
| 778 | 798 | * @param $user_id |
| 779 | 799 | * |
| 780 | 800 | * @return bool |
| 801 | + * @deprecated 4.2.0 | |
| 781 | 802 | */ |
| 782 | 803 | public function check_question( $question_id, $user_id ) { |
| 783 | - $question = LP_Question::get_question( $question_id ); | |
| 804 | + _deprecated_function( __METHOD__, '4.2.0' ); | |
| 805 | + /*$question = LP_Question::get_question( $question_id ); | |
| 784 | 806 | |
| 785 | 807 | if ( ! $question ) { |
| 786 | 808 | return false; |
| 787 | 809 | } |
| @@ -800,9 +822,9 @@ | ||
| 800 | 822 | if ( ! in_array( $question_id, $checked ) ) { |
| 801 | 823 | $checked[] = $question_id; |
| 802 | 824 | } |
| 803 | 825 | |
| 804 | - return true; | |
| 826 | + return true;*/ | |
| 805 | 827 | |
| 806 | 828 | } |
| 807 | 829 | |
| 808 | 830 | /** |
| @@ -811,11 +833,13 @@ | ||
| 811 | 833 | * @param $question |
| 812 | 834 | * @param int $user_id |
| 813 | 835 | * |
| 814 | 836 | * @return false|int|string |
| 837 | + * @deprecated 4.2.0 | |
| 815 | 838 | */ |
| 816 | 839 | public function get_question_position( $question, $user_id = 0 ) { |
| 817 | - if ( ! $user_id ) { | |
| 840 | + _deprecated_function( __METHOD__, '4.2.0' ); | |
| 841 | + /*if ( ! $user_id ) { | |
| 818 | 842 | $user_id = learn_press_get_current_user_id(); |
| 819 | 843 | } |
| 820 | 844 | |
| 821 | 845 | $user = learn_press_get_user( $user_id ); |
| @@ -829,9 +853,9 @@ | ||
| 829 | 853 | } |
| 830 | 854 | |
| 831 | 855 | $position = array_search( $question, $questions ); |
| 832 | 856 | |
| 833 | - return $position; | |
| 857 | + return $position;*/ | |
| 834 | 858 | } |
| 835 | 859 | |
| 836 | 860 | /** |
| 837 | 861 | * @param int $user_id |
| @@ -837,16 +861,17 @@ | ||
| 837 | 861 | * @param int $user_id |
| 838 | 862 | * @param int $course_id |
| 839 | 863 | * |
| 840 | 864 | * @return bool|LP_Question |
| 865 | + * @deprecated 4.0.0 | |
| 841 | 866 | */ |
| 842 | 867 | public function get_current_question( $user_id = 0, $course_id = 0 ) { |
| 843 | 868 | _deprecated_function( sprintf( '%s::%s', __CLASS__, __FUNCTION__ ), '4.0.0' ); |
| 844 | 869 | |
| 845 | - $user = learn_press_get_user( $user_id ); | |
| 870 | + /*$user = learn_press_get_user( $user_id ); | |
| 846 | 871 | $id = $user->get_current_quiz_question( $this->get_id(), $course_id ); |
| 847 | 872 | |
| 848 | - return LP_Question::get_question( $id ); | |
| 873 | + return LP_Question::get_question( $id );*/ | |
| 849 | 874 | } |
| 850 | 875 | |
| 851 | 876 | /** |
| 852 | 877 | * @param string $return |
| @@ -865,9 +890,8 @@ | ||
| 865 | 890 | * |
| 866 | 891 | * @return LP_Quiz|bool |
| 867 | 892 | */ |
| 868 | 893 | public static function get_quiz( $the_quiz = false, $args = array() ) { |
| 869 | - | |
| 870 | 894 | if ( is_numeric( $the_quiz ) && isset( LP_Global::$quizzes[ $the_quiz ] ) ) { |
| 871 | 895 | return LP_Global::$quizzes[ $the_quiz ]; |
| 872 | 896 | } |
| 873 | 897 | |
| @@ -970,18 +994,18 @@ | ||
| 970 | 994 | public function set_show_hide_question( $show_or_hide ) { |
| 971 | 995 | $this->_set_data( 'show_hide_question', $show_or_hide ); |
| 972 | 996 | } |
| 973 | 997 | |
| 998 | + /** | |
| 999 | + * Set quiz is preview or not. | |
| 1000 | + * using | |
| 1001 | + */ | |
| 974 | 1002 | public function set_preview( $preview ) { |
| 975 | 1003 | $this->_set_data( 'preview', $preview ); |
| 976 | 1004 | } |
| 977 | 1005 | |
| 978 | - // public function set_minus_points( $points ) { | |
| 979 | - // $this->_set_data( 'minus_points', $points ); | |
| 980 | - // } | |
| 981 | - | |
| 982 | 1006 | /** |
| 983 | - * @deprecated | |
| 1007 | + * Set option skip question will be minus points | |
| 984 | 1008 | * |
| 985 | 1009 | * @param $skip |
| 986 | 1010 | */ |
| 987 | 1011 | public function set_minus_skip_questions( $skip ) { |
| @@ -987,23 +1011,16 @@ | ||
| 987 | 1011 | public function set_minus_skip_questions( $skip ) { |
| 988 | 1012 | $this->_set_data( 'minus_skip_questions', $skip ); |
| 989 | 1013 | } |
| 990 | 1014 | |
| 1015 | + /** | |
| 1016 | + * Get quiz is preview or not. | |
| 1017 | + * using | |
| 1018 | + */ | |
| 991 | 1019 | public function get_preview() { |
| 992 | 1020 | return 'yes' === $this->get_data( 'preview' ); |
| 993 | 1021 | } |
| 994 | 1022 | |
| 995 | - /** | |
| 996 | - * @deprecated | |
| 997 | - * | |
| 998 | - * @return bool | |
| 999 | - */ | |
| 1000 | - public function get_show_hide_question() { | |
| 1001 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '4.0.0' ); | |
| 1002 | - | |
| 1003 | - return 'yes' === $this->get_data( 'show_hide_question' ); | |
| 1004 | - } | |
| 1005 | - | |
| 1006 | 1023 | // public function get_minus_points() { |
| 1007 | 1024 | // return $this->get_data( 'minus_points' ); |
| 1008 | 1025 | // } |
| 1009 | 1026 | |
| @@ -1048,30 +1065,15 @@ | ||
| 1048 | 1065 | return $class; |
| 1049 | 1066 | }*/ |
| 1050 | 1067 | |
| 1051 | 1068 | /** |
| 1052 | - * Implement ArrayAccess functions. | |
| 1053 | - * | |
| 1054 | 1069 | * @param mixed $offset |
| 1055 | - * @param mixed $value | |
| 1056 | - */ | |
| 1057 | - public function offsetSet( $offset, $value ) { | |
| 1058 | - // Do not allow to set value directly! | |
| 1059 | - } | |
| 1060 | - | |
| 1061 | - /** | |
| 1062 | - * @param mixed $offset | |
| 1063 | - */ | |
| 1064 | - public function offsetUnset( $offset ) { | |
| 1065 | - // Do not allow to unset value directly! | |
| 1066 | - } | |
| 1067 | - | |
| 1068 | - /** | |
| 1069 | - * @param mixed $offset | |
| 1070 | 1070 | * |
| 1071 | 1071 | * @return bool|mixed |
| 1072 | + * @deprecated 4.2.0 | |
| 1072 | 1073 | */ |
| 1073 | 1074 | public function offsetGet( $offset ) { |
| 1075 | + _deprecated_function( __CLASS__ . '::' . __METHOD__, '4.2.0' ); | |
| 1074 | 1076 | return $this->offsetExists( $offset ) ? $this->_questions[ $offset ] : false; |
| 1075 | 1077 | } |
| 1076 | 1078 | |
| 1077 | 1079 | /** |
| @@ -1077,10 +1079,12 @@ | ||
| 1077 | 1079 | /** |
| 1078 | 1080 | * @param mixed $offset |
| 1079 | 1081 | * |
| 1080 | 1082 | * @return bool |
| 1083 | + * @deprecated 4.2.0 | |
| 1081 | 1084 | */ |
| 1082 | 1085 | public function offsetExists( $offset ) { |
| 1083 | - return array_key_exists( $offset, $this->_questions ); | |
| 1086 | + _deprecated_function( __CLASS__ . '::' . __METHOD__, '4.2.0' ); | |
| 1087 | + /*return array_key_exists( $offset, $this->_questions );*/ | |
| 1084 | 1088 | } |
| 1085 | 1089 | } |
| 1086 | 1090 | } |