| 1 |
<?php |
| 2 |
/** |
| 3 |
* LP_Question_Single_Choice |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @package LearnPress/Templates |
| 7 |
* @version 3.0.0 |
| 8 |
* @extends LP_Question |
| 9 |
*/ |
| 10 |
|
| 11 |
/** |
| 12 |
* Prevent loading this file directly |
| 13 |
*/ |
| 14 |
defined( 'ABSPATH' ) || exit(); |
| 15 |
|
| 16 |
if ( ! class_exists( 'LP_Question_Single_Choice' ) ) { |
| 17 |
|
| 18 |
/** |
| 19 |
* Class LP_Question_Single_Choice |
| 20 |
*/ |
| 21 |
class LP_Question_Single_Choice extends LP_Question { |
| 22 |
|
| 23 |
/** |
| 24 |
* Type of this question. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
protected $_question_type = 'single_choice'; |
| 29 |
|
| 30 |
/** |
| 31 |
* LP_Question_Single_Choice constructor. |
| 32 |
* |
| 33 |
* @param null $the_question |
| 34 |
* @param null $args |
| 35 |
* |
| 36 |
* @throws Exception |
| 37 |
*/ |
| 38 |
public function __construct( $the_question = null, $args = null ) { |
| 39 |
parent::__construct( $the_question, $args ); |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Check user answer. |
| 45 |
* |
| 46 |
* @param null $user_answer |
| 47 |
* |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
public function check( $user_answer = null ) { |
| 51 |
$return = parent::check(); |
| 52 |
$answers = $this->get_answers(); |
| 53 |
|
| 54 |
if ( $answers ) { |
| 55 |
foreach ( $answers as $key => $option ) { |
| 56 |
if ( ( $option['is_true'] == 'yes' ) && ( $this->is_selected_option( $option, $user_answer ) ) ) { |
| 57 |
$return['correct'] = true; |
| 58 |
$return['mark'] = floatval( $this->get_mark() ); |
| 59 |
break; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return $return; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|