| @@ -1,149 +1,149 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Class LP_Meta_Box_Quiz. | |
| 5 | - * | |
| 6 | - * Meta box for quiz settings. | |
| 7 | - */ | |
| 8 | -class LP_Meta_Box_Quiz extends LP_Meta_Box { | |
| 9 | - | |
| 10 | - private static $_instance = null; | |
| 11 | - | |
| 12 | - public $post_type = LP_QUIZ_CPT; | |
| 13 | - | |
| 14 | - public function add_meta_box() { | |
| 15 | - add_meta_box( 'quiz_settings', esc_html__( 'Quiz Settings', 'learnpress' ), array( $this, 'output' ), $this->post_type, 'normal', 'high' ); | |
| 16 | - } | |
| 17 | - | |
| 18 | - public function metabox( $post_id = 0 ) { | |
| 19 | - return apply_filters( | |
| 20 | - 'lp/metabox/quiz/lists', | |
| 21 | - array( | |
| 22 | - '_lp_duration' => new LP_Meta_Box_Duration_Field( | |
| 23 | - esc_html__( 'Duration', 'learnpress' ), | |
| 24 | - esc_html__( 'Set to 0 for no limit, greater than 0 for a limit.', 'learnpress' ), | |
| 25 | - '0', | |
| 26 | - array( | |
| 27 | - 'default_time' => 'minute', | |
| 28 | - 'custom_attributes' => array( | |
| 29 | - 'min' => '0', | |
| 30 | - 'step' => '1', | |
| 31 | - ), | |
| 32 | - ) | |
| 33 | - ), | |
| 34 | - '_lp_passing_grade' => new LP_Meta_Box_Text_Field( | |
| 35 | - esc_html__( 'Passing Grade(%)', 'learnpress' ), | |
| 36 | - esc_html__( 'The conditions that must be achieved in order to pass the quiz.', 'learnpress' ), | |
| 37 | - '80', | |
| 38 | - array( | |
| 39 | - 'type_input' => 'number', | |
| 40 | - 'custom_attributes' => array( | |
| 41 | - 'min' => '0', | |
| 42 | - 'step' => '1', | |
| 43 | - 'max' => '100', | |
| 44 | - ), | |
| 45 | - 'style' => 'width: 60px;', | |
| 46 | - ) | |
| 47 | - ), | |
| 48 | - '_lp_instant_check' => new LP_Meta_Box_Checkbox_Field( | |
| 49 | - esc_html__( 'Instant Check', 'learnpress' ), | |
| 50 | - esc_html__( 'Allow students to immediately check their answers while doing the quiz.', 'learnpress' ), | |
| 51 | - 'no' | |
| 52 | - ), | |
| 53 | - '_lp_negative_marking' => new LP_Meta_Box_Checkbox_Field( | |
| 54 | - esc_html__( 'Negative Marking', 'learnpress' ), | |
| 55 | - esc_html__( 'For each question that students answer wrongly, the total point is deducted exactly from the question\'s point.', 'learnpress' ), | |
| 56 | - 'no' | |
| 57 | - ), | |
| 58 | - '_lp_minus_skip_questions' => new LP_Meta_Box_Checkbox_Field( | |
| 59 | - esc_html__( 'Minus for skip', 'learnpress' ), | |
| 60 | - esc_html__( 'For each question that students answer skip, the total point is deducted exactly from the question\'s point.', 'learnpress' ), | |
| 61 | - 'no' | |
| 62 | - ), | |
| 63 | - '_lp_retake_count' => new LP_Meta_Box_Text_Field( | |
| 64 | - esc_html__( 'Retake', 'learnpress' ), | |
| 65 | - esc_html__( 'How many times can the user re-take this quiz? Set 0 to disable. Set -1 to infinite.', 'learnpress' ), | |
| 66 | - '', | |
| 67 | - array( | |
| 68 | - 'type_input' => 'number', | |
| 69 | - 'custom_attributes' => array( | |
| 70 | - 'min' => '-1', | |
| 71 | - 'step' => '1', | |
| 72 | - ), | |
| 73 | - 'style' => 'width: 60px;', | |
| 74 | - ) | |
| 75 | - ), | |
| 76 | - '_lp_pagination' => new LP_Meta_Box_Text_Field( | |
| 77 | - esc_html__( 'Pagination', 'learnpress' ), | |
| 78 | - esc_html__( 'The number of displayed questions on each page.', 'learnpress' ), | |
| 79 | - '1', | |
| 80 | - array( | |
| 81 | - 'type_input' => 'number', | |
| 82 | - 'custom_attributes' => array( | |
| 83 | - 'min' => '0', | |
| 84 | - 'step' => '1', | |
| 85 | - 'max' => '100', | |
| 86 | - ), | |
| 87 | - 'style' => 'width: 60px;', | |
| 88 | - ) | |
| 89 | - ), | |
| 90 | - '_lp_review' => new LP_Meta_Box_Checkbox_Field( | |
| 91 | - esc_html__( 'Review', 'learnpress' ), | |
| 92 | - esc_html__( 'Allow students to review this quiz after they finish the quiz.', 'learnpress' ), | |
| 93 | - 'yes' | |
| 94 | - ), | |
| 95 | - '_lp_show_correct_review' => new LP_Meta_Box_Checkbox_Field( | |
| 96 | - esc_html__( 'Show the correct answer', 'learnpress' ), | |
| 97 | - esc_html__( 'Allow students to view the correct answer to the question in reviewing this quiz.', 'learnpress' ), | |
| 98 | - 'yes' | |
| 99 | - ), | |
| 100 | - ), | |
| 101 | - $post_id | |
| 102 | - ); | |
| 103 | - } | |
| 104 | - | |
| 105 | - public function output( $post ) { | |
| 106 | - parent::output( $post ); | |
| 107 | - ?> | |
| 108 | - | |
| 109 | - <div class="lp-meta-box lp-meta-box--quiz"> | |
| 110 | - <div class="lp-meta-box__inner"> | |
| 111 | - <?php | |
| 112 | - do_action( 'learnpress/quiz-settings/before' ); | |
| 113 | - // Check if add_filter to old version. | |
| 114 | - $is_old = false; | |
| 115 | - | |
| 116 | - foreach ( $this->metabox( $post->ID ) as $key => $object ) { | |
| 117 | - if ( is_a( $object, 'LP_Meta_Box_Field' ) ) { | |
| 118 | - $object->id = $key; | |
| 119 | - $output = $object->output( $post->ID ); | |
| 120 | - if ( ! empty( $output ) ) { | |
| 121 | - echo wp_kses_post( $object->output( $post->ID ) ); | |
| 122 | - } | |
| 123 | - } elseif ( is_array( $object ) ) { | |
| 124 | - $is_old = true; | |
| 125 | - } | |
| 126 | - } | |
| 127 | - | |
| 128 | - if ( $is_old ) { | |
| 129 | - lp_meta_box_output( $this->metabox( $post->ID ) ); | |
| 130 | - } | |
| 131 | - | |
| 132 | - do_action( 'learnpress/quiz-settings/after' ); | |
| 133 | - ?> | |
| 134 | - </div> | |
| 135 | - </div> | |
| 136 | - | |
| 137 | - <?php | |
| 138 | - } | |
| 139 | - | |
| 140 | - public static function instance() { | |
| 141 | - if ( is_null( self::$_instance ) ) { | |
| 142 | - self::$_instance = new self(); | |
| 143 | - } | |
| 144 | - | |
| 145 | - return self::$_instance; | |
| 146 | - } | |
| 147 | -} | |
| 148 | - | |
| 149 | -LP_Meta_Box_Quiz::instance(); | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Class LP_Meta_Box_Quiz. | |
| 5 | + * | |
| 6 | + * Meta box for quiz settings. | |
| 7 | + */ | |
| 8 | +class LP_Meta_Box_Quiz extends LP_Meta_Box { | |
| 9 | + | |
| 10 | + private static $_instance = null; | |
| 11 | + | |
| 12 | + public $post_type = LP_QUIZ_CPT; | |
| 13 | + | |
| 14 | + public function add_meta_box() { | |
| 15 | + add_meta_box( 'quiz_settings', esc_html__( 'Quiz Settings', 'learnpress' ), array( $this, 'output' ), $this->post_type, 'normal', 'high' ); | |
| 16 | + } | |
| 17 | + | |
| 18 | + public function metabox( $post_id = 0 ) { | |
| 19 | + return apply_filters( | |
| 20 | + 'lp/metabox/quiz/lists', | |
| 21 | + array( | |
| 22 | + '_lp_duration' => new LP_Meta_Box_Duration_Field( | |
| 23 | + esc_html__( 'Duration', 'learnpress' ), | |
| 24 | + esc_html__( 'Set to 0 for no limit, greater than 0 for a limit.', 'learnpress' ), | |
| 25 | + '0', | |
| 26 | + array( | |
| 27 | + 'default_time' => 'minute', | |
| 28 | + 'custom_attributes' => array( | |
| 29 | + 'min' => '0', | |
| 30 | + 'step' => '1', | |
| 31 | + ), | |
| 32 | + ) | |
| 33 | + ), | |
| 34 | + '_lp_passing_grade' => new LP_Meta_Box_Text_Field( | |
| 35 | + esc_html__( 'Passing Grade(%)', 'learnpress' ), | |
| 36 | + esc_html__( 'The conditions that must be achieved in order to pass the quiz.', 'learnpress' ), | |
| 37 | + '80', | |
| 38 | + array( | |
| 39 | + 'type_input' => 'number', | |
| 40 | + 'custom_attributes' => array( | |
| 41 | + 'min' => '0', | |
| 42 | + 'step' => '1', | |
| 43 | + 'max' => '100', | |
| 44 | + ), | |
| 45 | + 'style' => 'width: 60px;', | |
| 46 | + ) | |
| 47 | + ), | |
| 48 | + '_lp_instant_check' => new LP_Meta_Box_Checkbox_Field( | |
| 49 | + esc_html__( 'Instant Check', 'learnpress' ), | |
| 50 | + esc_html__( 'Allow students to immediately check their answers while doing the quiz.', 'learnpress' ), | |
| 51 | + 'no' | |
| 52 | + ), | |
| 53 | + '_lp_negative_marking' => new LP_Meta_Box_Checkbox_Field( | |
| 54 | + esc_html__( 'Negative Marking', 'learnpress' ), | |
| 55 | + esc_html__( 'For each question that students answer wrongly, the total point is deducted exactly from the question\'s point.', 'learnpress' ), | |
| 56 | + 'no' | |
| 57 | + ), | |
| 58 | + '_lp_minus_skip_questions' => new LP_Meta_Box_Checkbox_Field( | |
| 59 | + esc_html__( 'Minus for skip', 'learnpress' ), | |
| 60 | + esc_html__( 'For each question that students answer skip, the total point is deducted exactly from the question\'s point.', 'learnpress' ), | |
| 61 | + 'no' | |
| 62 | + ), | |
| 63 | + '_lp_retake_count' => new LP_Meta_Box_Text_Field( | |
| 64 | + esc_html__( 'Retake', 'learnpress' ), | |
| 65 | + esc_html__( 'How many times can the user re-take this quiz? Set 0 to disable. Set -1 to infinite.', 'learnpress' ), | |
| 66 | + '', | |
| 67 | + array( | |
| 68 | + 'type_input' => 'number', | |
| 69 | + 'custom_attributes' => array( | |
| 70 | + 'min' => '-1', | |
| 71 | + 'step' => '1', | |
| 72 | + ), | |
| 73 | + 'style' => 'width: 60px;', | |
| 74 | + ) | |
| 75 | + ), | |
| 76 | + '_lp_pagination' => new LP_Meta_Box_Text_Field( | |
| 77 | + esc_html__( 'Pagination', 'learnpress' ), | |
| 78 | + esc_html__( 'The number of displayed questions on each page.', 'learnpress' ), | |
| 79 | + '1', | |
| 80 | + array( | |
| 81 | + 'type_input' => 'number', | |
| 82 | + 'custom_attributes' => array( | |
| 83 | + 'min' => '0', | |
| 84 | + 'step' => '1', | |
| 85 | + 'max' => '100', | |
| 86 | + ), | |
| 87 | + 'style' => 'width: 60px;', | |
| 88 | + ) | |
| 89 | + ), | |
| 90 | + '_lp_review' => new LP_Meta_Box_Checkbox_Field( | |
| 91 | + esc_html__( 'Review', 'learnpress' ), | |
| 92 | + esc_html__( 'Allow students to review this quiz after they finish the quiz.', 'learnpress' ), | |
| 93 | + 'yes' | |
| 94 | + ), | |
| 95 | + '_lp_show_correct_review' => new LP_Meta_Box_Checkbox_Field( | |
| 96 | + esc_html__( 'Show the correct answer', 'learnpress' ), | |
| 97 | + esc_html__( 'Allow students to view the correct answer to the question in reviewing this quiz.', 'learnpress' ), | |
| 98 | + 'yes' | |
| 99 | + ), | |
| 100 | + ), | |
| 101 | + $post_id | |
| 102 | + ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + public function output( $post ) { | |
| 106 | + parent::output( $post ); | |
| 107 | + ?> | |
| 108 | + | |
| 109 | + <div class="lp-meta-box lp-meta-box--quiz"> | |
| 110 | + <div class="lp-meta-box__inner"> | |
| 111 | + <?php | |
| 112 | + do_action( 'learnpress/quiz-settings/before' ); | |
| 113 | + // Check if add_filter to old version. | |
| 114 | + $is_old = false; | |
| 115 | + | |
| 116 | + foreach ( $this->metabox( $post->ID ) as $key => $object ) { | |
| 117 | + if ( is_a( $object, 'LP_Meta_Box_Field' ) ) { | |
| 118 | + $object->id = $key; | |
| 119 | + $output = $object->output( $post->ID ); | |
| 120 | + if ( ! empty( $output ) ) { | |
| 121 | + echo wp_kses_post( $object->output( $post->ID ) ); | |
| 122 | + } | |
| 123 | + } elseif ( is_array( $object ) ) { | |
| 124 | + $is_old = true; | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + if ( $is_old ) { | |
| 129 | + lp_meta_box_output( $this->metabox( $post->ID ) ); | |
| 130 | + } | |
| 131 | + | |
| 132 | + do_action( 'learnpress/quiz-settings/after' ); | |
| 133 | + ?> | |
| 134 | + </div> | |
| 135 | + </div> | |
| 136 | + | |
| 137 | + <?php | |
| 138 | + } | |
| 139 | + | |
| 140 | + public static function instance() { | |
| 141 | + if ( is_null( self::$_instance ) ) { | |
| 142 | + self::$_instance = new self(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + return self::$_instance; | |
| 146 | + } | |
| 147 | +} | |
| 148 | + | |
| 149 | +LP_Meta_Box_Quiz::instance(); | |