PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.1
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 4.2.0 All 139 releases
learnpress / inc / question / class-lp-question-multi-choice.php

class-lp-question-multi-choice.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.1, at inc/question/class-lp-question-multi-choice.php

89 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Question_Multi_Choice
4 *
5 * @author ThimPress
6 * @package LearnPress/Classes
7 * @version 3.0.0
8 * @extend LP_Question
9 */
10
11 defined( 'ABSPATH' ) || exit();
12
13 if ( ! class_exists( 'LP_Question_Multi_Choice' ) ) {
14 /**
15 * Class LP_Question_Multi_Choice
16 */
17 class LP_Question_Multi_Choice extends LP_Question {
18
19 /**
20 * Type of this question.
21 *
22 * @var string
23 */
24 public $_question_type = 'multi_choice';
25
26 /**
27 * LP_Question_Multi_Choice constructor.
28 *
29 * @param null $the_question
30 * @param null $options
31 *
32 * @throws Exception
33 */
34 public function __construct( $the_question = null, $options = null ) {
35 parent::__construct( $the_question, $options );
36 }
37
38 /**
39 * Allow check answer.
40 *
41 * @return bool
42 */
43 public function can_check_answer() {
44 return true;
45 }
46
47 /**
48 * Check user answer.
49 *
50 * @param null $user_answer
51 *
52 * @return array
53 */
54 public function check( $user_answer = null ) {
55 $return = parent::check();
56 settype( $user_answer, 'array' );
57 $answers = $this->get_answers();
58
59 if ( $answers ) {
60 $correct = true;
61 foreach ( $answers as $key => $option ) {
62 $data = $option->get_data();
63 $selected = $this->is_selected_option( $data, $user_answer );
64
65 if ( $selected && ! $option->is_true() ) {
66 $correct = false;
67 } elseif ( ! $selected && $option->is_true() ) {
68 $correct = false;
69 }
70
71 // Only one option is selected wrong will wrong the answer.
72 if ( ! $correct ) {
73 break;
74 }
75 }
76
77 if ( $correct ) {
78 $return = array(
79 'correct' => true,
80 'mark' => floatval( $this->get_mark() ),
81 );
82 }
83 }
84
85 return $return;
86 }
87 }
88 }
89